gs-vertexbuffer: Fix usage of gs_vertexbuffer_get_data()

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2018-04-29 03:00:40 +02:00
parent e200127595
commit 6057101f26

View file

@ -76,6 +76,7 @@ gs::vertex_buffer::vertex_buffer(uint32_t maximumVertices) {
// Assign limits. // Assign limits.
m_capacity = maximumVertices; m_capacity = maximumVertices;
m_size = m_capacity;
m_layers = MAXIMUM_UVW_LAYERS; m_layers = MAXIMUM_UVW_LAYERS;
// Allocate memory for data. // Allocate memory for data.
@ -110,7 +111,11 @@ gs::vertex_buffer::vertex_buffer(uint32_t maximumVertices) {
} }
gs::vertex_buffer::vertex_buffer(gs_vertbuffer_t* vb) { gs::vertex_buffer::vertex_buffer(gs_vertbuffer_t* vb) {
obs_enter_graphics();
gs_vb_data* vbd = gs_vertexbuffer_get_data(vb); gs_vb_data* vbd = gs_vertexbuffer_get_data(vb);
if (!vbd)
throw std::runtime_error("vertex buffer with no data");
vertex_buffer((uint32_t)vbd->num); vertex_buffer((uint32_t)vbd->num);
this->set_uv_layers((uint32_t)vbd->num_tex); this->set_uv_layers((uint32_t)vbd->num_tex);
@ -138,9 +143,9 @@ gs::vertex_buffer::vertex_buffer(gs_vertbuffer_t* vb) {
} }
} }
} }
obs_leave_graphics();
} }
gs::vertex_buffer::vertex_buffer(vertex_buffer const& other) : vertex_buffer(other.m_capacity) { gs::vertex_buffer::vertex_buffer(vertex_buffer const& other) : vertex_buffer(other.m_capacity) {
// Copy Constructor // Copy Constructor
std::memcpy(m_positions, other.m_positions, m_capacity * sizeof(vec3)); std::memcpy(m_positions, other.m_positions, m_capacity * sizeof(vec3));
@ -296,6 +301,7 @@ gs_vertbuffer_t* gs::vertex_buffer::update(bool refreshGPU) {
throw std::out_of_range("size is larger than capacity"); throw std::out_of_range("size is larger than capacity");
// Update VertexBuffer data. // Update VertexBuffer data.
obs_enter_graphics();
m_vertexbufferdata = gs_vertexbuffer_get_data(m_vertexbuffer); m_vertexbufferdata = gs_vertexbuffer_get_data(m_vertexbuffer);
std::memset(m_vertexbufferdata, 0, sizeof(gs_vb_data)); std::memset(m_vertexbufferdata, 0, sizeof(gs_vb_data));
m_vertexbufferdata->num = m_capacity; m_vertexbufferdata->num = m_capacity;
@ -311,7 +317,6 @@ gs_vertbuffer_t* gs::vertex_buffer::update(bool refreshGPU) {
} }
// Update GPU // Update GPU
obs_enter_graphics();
gs_vertexbuffer_flush(m_vertexbuffer); gs_vertexbuffer_flush(m_vertexbuffer);
obs_leave_graphics(); obs_leave_graphics();