mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-14 07:45:06 +00:00
gs-vertexbuffer: Allow specifying amount of UV layers
This should reduce GPU memory usage for vertex buffers that need less UV information than the maximum allowed UV layers possible.
This commit is contained in:
parent
c3e67bad97
commit
cace17a817
2 changed files with 31 additions and 16 deletions
|
@ -70,16 +70,19 @@ gs::vertex_buffer::~vertex_buffer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cppcheck-suppress uninitMemberVar
|
gs::vertex_buffer::vertex_buffer() : vertex_buffer(MAXIMUM_VERTICES, MAXIMUM_UVW_LAYERS) {}
|
||||||
gs::vertex_buffer::vertex_buffer() : vertex_buffer(MAXIMUM_VERTICES) {}
|
|
||||||
|
|
||||||
gs::vertex_buffer::vertex_buffer(uint32_t maximumVertices)
|
gs::vertex_buffer::vertex_buffer(uint32_t vertices) : vertex_buffer(vertices, MAXIMUM_UVW_LAYERS) {}
|
||||||
: m_size(maximumVertices), m_capacity(maximumVertices), m_layers(MAXIMUM_UVW_LAYERS), m_positions(nullptr),
|
|
||||||
m_normals(nullptr), m_tangents(nullptr), m_colors(nullptr), m_vertexbufferdata(nullptr), m_vertexbuffer(nullptr),
|
gs::vertex_buffer::vertex_buffer(uint32_t vertices, uint8_t uvlayers)
|
||||||
m_layerdata(nullptr)
|
: m_size(vertices), m_capacity(vertices), m_layers(uvlayers), m_positions(nullptr), m_normals(nullptr),
|
||||||
|
m_tangents(nullptr), m_colors(nullptr), m_vertexbufferdata(nullptr), m_vertexbuffer(nullptr), m_layerdata(nullptr)
|
||||||
{
|
{
|
||||||
if (maximumVertices > MAXIMUM_VERTICES) {
|
if (vertices > MAXIMUM_VERTICES) {
|
||||||
throw std::out_of_range("maximumVertices out of range");
|
throw std::out_of_range("vertices out of range");
|
||||||
|
}
|
||||||
|
if (uvlayers > MAXIMUM_UVW_LAYERS) {
|
||||||
|
throw std::out_of_range("uvlayers out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate memory for data.
|
// Allocate memory for data.
|
||||||
|
@ -99,12 +102,16 @@ gs::vertex_buffer::vertex_buffer(uint32_t maximumVertices)
|
||||||
std::memset(m_colors, 0, sizeof(uint32_t) * m_capacity);
|
std::memset(m_colors, 0, sizeof(uint32_t) * m_capacity);
|
||||||
|
|
||||||
m_vertexbufferdata->num_tex = m_layers;
|
m_vertexbufferdata->num_tex = m_layers;
|
||||||
m_vertexbufferdata->tvarray = m_layerdata =
|
if (m_layers > 0) {
|
||||||
(gs_tvertarray*)util::malloc_aligned(16, sizeof(gs_tvertarray) * m_layers);
|
m_vertexbufferdata->tvarray = m_layerdata =
|
||||||
for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) {
|
(gs_tvertarray*)util::malloc_aligned(16, sizeof(gs_tvertarray) * m_layers);
|
||||||
m_layerdata[n].array = m_uvs[n] = (vec4*)util::malloc_aligned(16, sizeof(vec4) * m_capacity);
|
for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) {
|
||||||
m_layerdata[n].width = 4;
|
m_layerdata[n].array = m_uvs[n] = (vec4*)util::malloc_aligned(16, sizeof(vec4) * m_capacity);
|
||||||
std::memset(m_uvs[n], 0, sizeof(vec4) * m_capacity);
|
m_layerdata[n].width = 4;
|
||||||
|
std::memset(m_uvs[n], 0, sizeof(vec4) * m_capacity);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m_vertexbufferdata->tvarray = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate GPU
|
// Allocate GPU
|
||||||
|
|
|
@ -45,9 +45,17 @@ namespace gs {
|
||||||
/*!
|
/*!
|
||||||
* \brief Create a Vertex Buffer with a specific number of Vertices.
|
* \brief Create a Vertex Buffer with a specific number of Vertices.
|
||||||
*
|
*
|
||||||
* \param maximumVertices Maximum amount of vertices to store.
|
* \param vertices Number of vertices to store.
|
||||||
*/
|
*/
|
||||||
vertex_buffer(uint32_t maximumVertices);
|
vertex_buffer(uint32_t vertices);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Create a Vertex Buffer with a specific number of Vertices and uv layers.
|
||||||
|
*
|
||||||
|
* \param vertices Number of vertices to store.
|
||||||
|
* \param layers Number of uv layers to store.
|
||||||
|
*/
|
||||||
|
vertex_buffer(uint32_t vertices, uint8_t layers);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Create a copy of a Vertex Buffer
|
* \brief Create a copy of a Vertex Buffer
|
||||||
|
|
Loading…
Reference in a new issue