Exemple #1
0
 /** Send a normal to the rendersystem. */
 virtual void sendNormal(double x, double y, double z) { sendNormal(Vector3((float)x, (float)y, (float)z)); };
Exemple #2
0
// Finally, the actual calls to do something with all this data.  You can either choose to render
// it given the configuration, or generate a display list of rendering it with the given
// configuration (uses GL_COMPILE mode to build the list).  Fails if insufficient data has
// been given (i.e. if you don't give it an array for an enabled parameter, if you don't
// give it an array of indices when it needs them).
// Note that rendering with GLVERTEX_MODE currently involves a lot of CPU overhead to
// unpack the data and pass it to the GL; while the results will be correct, it would be
// unwise to use this method for rendering that is to be benchmarked, because it will
// underestimate performance significantly on some machines.
bool GeomRenderer::renderPrimitives(GLenum mode)
{
    if (!isReadyToRender())
    {
        return false;
    }

    // Okay, different sections here depending on what we're doing.
    if (drawMethod == GLVERTEX_MODE)
    {
        glBegin(mode);
        for (unsigned int x=0; x<indicesCount; x++)
        {
            int directIndex = getIndex(x);
            if (parameterBits & COLOR_BIT) sendColor(directIndex);
            if (parameterBits & TEXTURE_COORD_BIT) sendTexCoord(directIndex);
            if (parameterBits & NORMAL_BIT) sendNormal(directIndex);
            sendVertex(directIndex);
        }
        glEnd();
    }
    // Otherwise it has something to do with arrays; set up the arrays.
    else
    {
        if (parameterBits & COLOR_BIT)
        { 
            glEnableClientState(GL_COLOR_ARRAY);
            glColorPointer(colorData.size, colorData.type, colorData.stride, colorData.pointer);
//            std::cout << "Enabled color arrays, size [" << colorData.size << "], type [" << colorData.type 
//                      << "], stride [" << colorData.stride << "], pointer [" << colorData.pointer << "]" << std::endl;
        }
        if (parameterBits & TEXTURE_COORD_BIT)
        { 
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glTexCoordPointer(texCoordData.size, texCoordData.type, texCoordData.stride, texCoordData.pointer);
//            std::cout << "Enabled texCoord arrays, size [" << texCoordData.size << "], type [" << texCoordData.type 
//                      << "], stride [" << texCoordData.stride << "], pointer [" << texCoordData.pointer << "]" << std::endl;
        }
        if (parameterBits & NORMAL_BIT)
        { 
            glEnableClientState(GL_NORMAL_ARRAY);
            glNormalPointer(normalData.type, normalData.stride, normalData.pointer);
//            std::cout << "Enabled normal arrays, size [" << normalData.size << "], type [" << normalData.type 
//                      << "], stride [" << normalData.stride << "], pointer [" << normalData.pointer << "]" << std::endl;
        }
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(vertexData.size, vertexData.type, vertexData.stride, vertexData.pointer);
//        std::cout << "Enabled vertex arrays, size [" << vertexData.size << "], type [" << vertexData.type 
//                  << "], stride [" << vertexData.stride << "], pointer [" << vertexData.pointer << "]" << std::endl;

        // Should we lock?
        if (compileArrays)
        {
            assert(GLUtils::haveExtension("GL_EXT_compiled_vertex_array"));
            glLockArraysEXT(0, arrayLength);
        }

        // Okay, arrays configured; what exactly are we doing?
        if (drawMethod == GLARRAYELEMENT_MODE)
        {
            glBegin(mode);
            for (unsigned int x=0; x<indicesCount; x++)
            {
                glArrayElement(getIndex(x));
            }
            glEnd();
        }
        else if (drawMethod == GLDRAWARRAYS_MODE)
        {
            glDrawArrays(mode, 0, arrayLength);
            std::cout << "Called glDrawArrays, mode [" << mode << "], from 0 to " << arrayLength << std::endl;
        }
        else if (drawMethod == GLDRAWELEMENTS_MODE)
        {
            glDrawElements(mode, indicesCount, indicesType, indices);
        }

        // Done.  If we locked, unlock.
        if (compileArrays)
        {
            assert(GLUtils::haveExtension("GL_EXT_compiled_vertex_array"));
            glUnlockArraysEXT();
        }
    }

    return true;
}
Exemple #3
0
 /** Send a normal to the rendersystem. */
 virtual void sendNormal(float x, float y, float z) { sendNormal(Vector3(x, y, z)); }