Przeglądaj źródła

Fixing a bug introduced with multiple vertex stream support for OGL backend. (#1072)

Dario Manesku 8 lat temu
rodzic
commit
72d98681bb
1 zmienionych plików z 16 dodań i 13 usunięć
  1. 16 13
      src/renderer_gl.cpp

+ 16 - 13
src/renderer_gl.cpp

@@ -7123,7 +7123,6 @@ namespace bgfx { namespace gl
 							for (size_t ii = 0; ii < BGFX_CONFIG_MAX_VERTEX_STREAMS; ++ii)
 							{
 								currentState.m_stream[ii].m_handle.idx = invalidHandle;
-								currentState.m_stream[ii].m_startVertex = 0;
 							}
 							currentState.m_indexBuffer.idx = invalidHandle;
 							bindAttribs = true;
@@ -7166,8 +7165,17 @@ namespace bgfx { namespace gl
 								streamMask >>= ntz;
 								idx         += ntz;
 
-								currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle;
-								currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex;
+								uint16_t handle = draw.m_stream[idx].m_handle.idx;
+								if (invalidHandle != handle)
+								{
+									VertexBufferGL& vb = m_vertexBuffers[handle];
+									GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) );
+									bindAttribs = true;
+								}
+								else
+								{
+									GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) );
+								}
 							}
 						}
 
@@ -7216,12 +7224,9 @@ namespace bgfx { namespace gl
 									streamMask >>= ntz;
 									idx         += ntz;
 
-									const Stream& stream = draw.m_stream[idx];
-
-									const VertexBufferGL& vb = m_vertexBuffers[stream.m_handle.idx];
-									uint16_t decl = !isValid(vb.m_decl) ? stream.m_decl.idx : vb.m_decl.idx;
-									GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) );
-									program.bindAttributes(m_vertexDecls[decl], stream.m_startVertex);
+									const VertexBufferGL& vb = m_vertexBuffers[draw.m_stream[idx].m_handle.idx];
+									uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx;
+									program.bindAttributes(m_vertexDecls[decl], draw.m_stream[idx].m_startVertex);
 								}
 								program.bindAttributesEnd();
 
@@ -7247,10 +7252,8 @@ namespace bgfx { namespace gl
 								streamMask >>= ntz;
 								idx         += ntz;
 
-								const Stream& stream = currentState.m_stream[idx];
-
-								const VertexBufferGL& vb = m_vertexBuffers[stream.m_handle.idx];
-								uint16_t decl = !isValid(vb.m_decl) ? stream.m_decl.idx : vb.m_decl.idx;
+								const VertexBufferGL& vb = m_vertexBuffers[currentState.m_stream[idx].m_handle.idx];
+								uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx;
 								const VertexDecl& vertexDecl = m_vertexDecls[decl];
 
 								numVertices = bx::uint32_min(numVertices, vb.m_size/vertexDecl.m_stride);