Blender V4.5
gpu_patch_table.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Foundation
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9#include <opensubdiv/version.h>
10
11#include <opensubdiv/osd/nonCopyable.h>
12#include <opensubdiv/osd/types.h>
13
14using OpenSubdiv::Far::PatchTable;
15using OpenSubdiv::Osd::NonCopyable;
16using OpenSubdiv::Osd::PatchArrayVector;
17
18namespace blender::opensubdiv {
19
20// TODO: use Blenlib NonCopyable.
21class GPUPatchTable : private NonCopyable<GPUPatchTable> {
22 public:
24
25 static GPUPatchTable *Create(PatchTable const *farPatchTable, void *deviceContext = NULL);
26
28 PatchArrayVector const &GetPatchArrays() const
29 {
30 return _patchArrays;
31 }
32
34 GPUStorageBuf *GetPatchIndexBuffer() const
35 {
36 return _patchIndexBuffer;
37 }
38
40 GPUStorageBuf *GetPatchParamBuffer() const
41 {
42 return _patchParamBuffer;
43 }
44
46 PatchArrayVector const &GetVaryingPatchArrays() const
47 {
49 }
50
52 GPUStorageBuf *GetVaryingPatchIndexBuffer() const
53 {
55 }
56
59 {
60 return (int)_fvarPatchArrays.size();
61 }
62
64 PatchArrayVector const &GetFVarPatchArrays(int fvarChannel = 0) const
65 {
66 return _fvarPatchArrays[fvarChannel];
67 }
68
70 GPUStorageBuf *GetFVarPatchIndexBuffer(int fvarChannel = 0) const
71 {
72 return _fvarIndexBuffers[fvarChannel];
73 }
74
76 GPUStorageBuf *GetFVarPatchParamBuffer(int fvarChannel = 0) const
77 {
78 return _fvarParamBuffers[fvarChannel];
79 }
80
81 protected:
83
84 // allocate buffers from patchTable
85 bool allocate(PatchTable const *farPatchTable);
86
87 PatchArrayVector _patchArrays;
88
89 GPUStorageBuf *_patchIndexBuffer = nullptr;
90 GPUStorageBuf *_patchParamBuffer = nullptr;
91
92 PatchArrayVector _varyingPatchArrays;
93 GPUStorageBuf *_varyingIndexBuffer = nullptr;
94
95 std::vector<PatchArrayVector> _fvarPatchArrays;
96 std::vector<GPUStorageBuf *> _fvarIndexBuffers;
97 std::vector<GPUStorageBuf *> _fvarParamBuffers;
98};
99
100} // namespace blender::opensubdiv
NonCopyable(const NonCopyable &other)=delete
std::vector< GPUStorageBuf * > _fvarParamBuffers
GPUStorageBuf * GetPatchParamBuffer() const
Returns the GL index buffer containing the patch parameter.
PatchArrayVector const & GetVaryingPatchArrays() const
Returns the patch arrays for varying index buffer data.
GPUStorageBuf * GetFVarPatchIndexBuffer(int fvarChannel=0) const
Returns the GL index buffer containing face-varying control vertices.
GPUStorageBuf * GetVaryingPatchIndexBuffer() const
Returns the GL index buffer containing the varying control vertices.
static GPUPatchTable * Create(PatchTable const *farPatchTable, void *deviceContext=NULL)
GPUStorageBuf * GetPatchIndexBuffer() const
Returns the GL index buffer containing the patch control vertices.
PatchArrayVector const & GetFVarPatchArrays(int fvarChannel=0) const
Returns the patch arrays for face-varying index buffer data.
PatchArrayVector const & GetPatchArrays() const
Returns the patch arrays for vertex index buffer data.
bool allocate(PatchTable const *farPatchTable)
std::vector< GPUStorageBuf * > _fvarIndexBuffers
std::vector< PatchArrayVector > _fvarPatchArrays
int GetNumFVarChannels() const
Returns the number of face-varying channel buffers.
GPUStorageBuf * GetFVarPatchParamBuffer(int fvarChannel=0) const
Returns the GL index buffer containing face-varying patch params.