]> git.tdb.fi Git - libs/gl.git/commitdiff
Rearrange vertex components
authorMikko Rasa <tdb@tdb.fi>
Sun, 2 Sep 2012 14:50:48 +0000 (17:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 2 Sep 2012 14:50:48 +0000 (17:50 +0300)
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.

source/vertexarray.cpp
source/vertexarraybuilder.cpp
source/vertexformat.cpp
source/vertexformat.h

index 6c037f9fd030de3f382335a16dc8c8d2cc69acff..e91062bbda60b0f309f06c98effda44f6065eccd 100644 (file)
@@ -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<ATTRIB1)
+               if(*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<get_component_type(ATTRIB1))
+                               glDisableVertexAttribArray(i);
                        else
                                glDisableVertexAttribArray(i-get_component_type(ATTRIB1));
                }
index a30c6e21183808a36a5c191b42953e5968180d68..55b2a6a821b80c001a3ff282ee339a3c69a02eaf 100644 (file)
@@ -42,10 +42,12 @@ void VertexArrayBuilder::vertex_(const Vector4 &ver)
                        const Vector4 *v = 0;
                        if(t==get_component_type(VERTEX3))
                                v = &ver;
-                       else if(*c>=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;
index ea5845c5fc10f56cca9b217a6db5c405e9b0028c..146fc68095be688e4c974c3aefbccf89c71b0b7e 100644 (file)
@@ -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
index 018d21f00e5176a322b8cbe262da5d355b762bb1..95e9b2c5bc42fd299283201ffa6a8c725697fb57 100644 (file)
@@ -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