From: Mikko Rasa Date: Sun, 2 Sep 2012 14:50:48 +0000 (+0300) Subject: Rearrange vertex components X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=40c364b04084d11573a9ff9f7be6f1c4cc521f4b Rearrange vertex components The first 16 component types are now reserved for the library. This leaves room for adding standard generic attributes, such as TBN vectors. To make further room, texcoords were limited to four indices. Generic attributes are limited to 24. Current implementations seem to only support 16 (the minimum allowed by the spec), so this is not a huge problem. There's also exactly enough room for another set of 24 generic integer attributes. --- diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index 6c037f9f..e91062bb 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -32,7 +32,7 @@ void VertexArray::reset(const VertexFormat &f) bool has_gen_attrs = false; for(const unsigned char *c=format.begin(); c!=format.end(); ++c) { - if(*c>=TEXCOORD1+4 && *c=TEXCOORD1+4 && *c<=TEXCOORD4+12) has_multitex = true; if(*c>=ATTRIB1) has_gen_attrs = true; @@ -140,7 +140,7 @@ void VertexArray::apply() const if(!en) glEnableClientState(GL_COLOR_ARRAY); } - else if(*c>=TEXCOORD1 && *c<=TEXCOORD4+28) + else if(*c>=TEXCOORD1 && *c<=TEXCOORD4+12) { t -= get_component_type(TEXCOORD1); if(t>0 || active_tex) @@ -154,7 +154,8 @@ void VertexArray::apply() const } else { - t -= get_component_type(ATTRIB1); + if(t>=get_component_type(ATTRIB1)) + t -= get_component_type(ATTRIB1); glVertexAttribPointer(t, sz, GL_FLOAT, false, bpv, base+offset); if(!en) glEnableVertexAttribArray(t); @@ -172,7 +173,7 @@ void VertexArray::apply() const glDisableClientState(GL_NORMAL_ARRAY); else if(i==get_component_type(COLOR4_FLOAT)) glDisableClientState(GL_COLOR_ARRAY); - else if(i>=get_component_type(TEXCOORD1) && i<=get_component_type(TEXCOORD1)+7) + else if(i>=get_component_type(TEXCOORD1) && i<=get_component_type(TEXCOORD1)+3) { unsigned j = i-get_component_type(TEXCOORD1); if(j>0 || active_tex) @@ -180,6 +181,8 @@ void VertexArray::apply() const glDisableClientState(GL_TEXTURE_COORD_ARRAY); active_tex = j; } + else if(i=TEXCOORD1 && *c<=TEXCOORD4+28) + else if(*c>=TEXCOORD1 && *c<=TEXCOORD4+12) v = &texc[t-get_component_type(TEXCOORD1)]; else if(*c>=ATTRIB1) v = &attr[t-get_component_type(ATTRIB1)]; + else + v = &attr[t]; *ptr++ = v->x; if(sz>=2) *ptr++ = v->y; if(sz>=3) *ptr++ = v->z; diff --git a/source/vertexformat.cpp b/source/vertexformat.cpp index ea5845c5..146fc680 100644 --- a/source/vertexformat.cpp +++ b/source/vertexformat.cpp @@ -120,7 +120,7 @@ VertexComponent make_indexed_component(VertexComponent comp, unsigned index) } else if(comp>=ATTRIB1 && comp<=ATTRIB4) { - if(index>=53) + if(index>=24) throw out_of_range("make_indexed_component"); } else diff --git a/source/vertexformat.h b/source/vertexformat.h index 018d21f0..95e9b2c5 100644 --- a/source/vertexformat.h +++ b/source/vertexformat.h @@ -6,20 +6,23 @@ namespace Msp { namespace GL { +/** A single vertex component. Nvidia drivers have aliasing between the +fixed-functions and generic vertex attributes, despite the standard not +allowing it. We use the same attribute indices here to avoid problems. */ enum VertexComponent { VERTEX2 = 1, VERTEX3, VERTEX4, - NORMAL3 = 6, - COLOR4_UBYTE = 8, - COLOR3_FLOAT = 10, + NORMAL3 = 10, + COLOR4_UBYTE = 12, + COLOR3_FLOAT = 14, COLOR4_FLOAT, - TEXCOORD1 = 12, + TEXCOORD1 = 32, TEXCOORD2, TEXCOORD3, TEXCOORD4, - ATTRIB1 = 44, + ATTRIB1 = 64, ATTRIB2, ATTRIB3, ATTRIB4