mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-29 11:01:23 +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) {}
|
||||
gs::vertex_buffer::vertex_buffer() : vertex_buffer(MAXIMUM_VERTICES, MAXIMUM_UVW_LAYERS) {}
|
||||
|
||||
gs::vertex_buffer::vertex_buffer(uint32_t maximumVertices)
|
||||
: 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),
|
||||
m_layerdata(nullptr)
|
||||
gs::vertex_buffer::vertex_buffer(uint32_t vertices) : vertex_buffer(vertices, MAXIMUM_UVW_LAYERS) {}
|
||||
|
||||
gs::vertex_buffer::vertex_buffer(uint32_t vertices, uint8_t uvlayers)
|
||||
: 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) {
|
||||
throw std::out_of_range("maximumVertices out of range");
|
||||
if (vertices > MAXIMUM_VERTICES) {
|
||||
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.
|
||||
|
@ -99,6 +102,7 @@ gs::vertex_buffer::vertex_buffer(uint32_t maximumVertices)
|
|||
std::memset(m_colors, 0, sizeof(uint32_t) * m_capacity);
|
||||
|
||||
m_vertexbufferdata->num_tex = m_layers;
|
||||
if (m_layers > 0) {
|
||||
m_vertexbufferdata->tvarray = m_layerdata =
|
||||
(gs_tvertarray*)util::malloc_aligned(16, sizeof(gs_tvertarray) * m_layers);
|
||||
for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) {
|
||||
|
@ -106,6 +110,9 @@ gs::vertex_buffer::vertex_buffer(uint32_t maximumVertices)
|
|||
m_layerdata[n].width = 4;
|
||||
std::memset(m_uvs[n], 0, sizeof(vec4) * m_capacity);
|
||||
}
|
||||
} else {
|
||||
m_vertexbufferdata->tvarray = nullptr;
|
||||
}
|
||||
|
||||
// Allocate GPU
|
||||
obs_enter_graphics();
|
||||
|
|
|
@ -45,9 +45,17 @@ namespace gs {
|
|||
/*!
|
||||
* \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
|
||||
|
|
Loading…
Reference in a new issue