diff --git a/src/gpu/vertexbuffer.cpp b/src/gpu/vertexbuffer.cpp index 5b4acd60..ed2fdcdb 100644 --- a/src/gpu/vertexbuffer.cpp +++ b/src/gpu/vertexbuffer.cpp @@ -236,16 +236,20 @@ void VertexDeclaration::Unbind() if (FAILED(g_d3ddevice->SetVertexDeclaration(NULL))) Abort(); #elif !defined __CELLOS_LV2__ - /* FIXME: we need to unbind what we bound */ - //glDisableVertexAttribArray(m_attrib); - /* FIXME: temporary kludge */ - for (int i = 0; i < 12; i++) - glDisableVertexAttribArray(i); + for (int i = 0; i < m_count; i++) + { + if (m_streams[i].reg >= 0) + { + for (int j = i + 1; j < m_count; j++) + if (m_streams[j].reg == m_streams[i].reg) + m_streams[j].reg = -1; + + glDisableVertexAttribArray(m_streams[i].reg); + } + } glBindBuffer(GL_ARRAY_BUFFER, 0); - /* FIXME: only useful for VAOs */ + /* FIXME: only useful for VAOs? */ //glBindBuffer(GL_ARRAY_BUFFER, 0); - /* Or: */ - //glDisableVertexAttribArray(m_attrib); #else /* Or even: */ glDisableClientState(GL_VERTEX_ARRAY); @@ -346,6 +350,9 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1, for (int i = 0; i < m_count; i++) if (m_streams[i].index == m_streams[attr_index].index) { + /* Remember the register used for this stream */ + m_streams[i].reg = reg; + stride += m_streams[i].size; if (i < attr_index) offset += m_streams[i].size; @@ -522,6 +529,7 @@ void VertexDeclaration::AddStream(VertexStreamBase const &s) m_streams[m_count].usage = s.m_streams[i].usage; m_streams[m_count].size = s.m_streams[i].size; m_streams[m_count].index = index; + m_streams[m_count].reg = -1; m_count++; } } diff --git a/src/gpu/vertexbuffer.h b/src/gpu/vertexbuffer.h index a450c6aa..8055a0b2 100644 --- a/src/gpu/vertexbuffer.h +++ b/src/gpu/vertexbuffer.h @@ -123,6 +123,7 @@ private: static VertexStreamBase const Empty; }; +/* Specialise this template for "void" to act as a NOP */ template<> inline void VertexStreamBase::AddStream(int n, VertexUsage usage) { @@ -198,7 +199,7 @@ private: void Initialize(); void AddStream(VertexStreamBase const &); - struct { uint8_t stream_type, index, usage, size; } m_streams[12 + 1]; + struct { uint8_t stream_type, index, usage, size; int reg; } m_streams[12 + 1]; int m_count; void *m_data;