Example #1
0
/*
 * =================
 * RB_DrawArrays
 * =================
 */
void RB_DrawArrays(void)
{
    if ((rb_vertex == 0) || (rb_index == 0)) // nothing to render
    {
        return;
    }

    GL_LockArrays(rb_vertex);
    if (glConfig.drawRangeElements)
    {
        glDrawRangeElementsEXT(GL_TRIANGLES, 0, rb_vertex, rb_index, GL_UNSIGNED_INT, indexArray);
    }
    else
    {
        glDrawElements(GL_TRIANGLES, rb_index, GL_UNSIGNED_INT, indexArray);
    }
    GL_UnlockArrays();
}
Example #2
0
//Draw a mesh face
void BSP::DrawMeshFace(int meshFaceNumber)
{
	//skip this face if its texture was not loaded
	if(isTextureLoaded[meshFaces[meshFaceNumber].textureIndex]==false)
		return;

	//set array pointers
	glVertexPointer(	3, GL_FLOAT, sizeof(BSP_VERTEX),
						&vertices[meshFaces[meshFaceNumber].firstVertexIndex].position);
	glTexCoordPointer(	2, GL_FLOAT, sizeof(BSP_VERTEX),
						&vertices[meshFaces[meshFaceNumber].firstVertexIndex].decalS);

	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glTexCoordPointer(	2, GL_FLOAT, sizeof(BSP_VERTEX),
						&vertices[meshFaces[meshFaceNumber].firstVertexIndex].lightmapS);
	glClientActiveTextureARB(GL_TEXTURE0_ARB);


	//bind textures
	//unit 0 - decal texture
	glBindTexture(GL_TEXTURE_2D, decalTextures[meshFaces[meshFaceNumber].textureIndex]);

	//unit 1 - lightmap
	glActiveTextureARB(GL_TEXTURE1_ARB);
	if(meshFaces[meshFaceNumber].lightmapIndex>=0)	//only bind a lightmap if one exists
		glBindTexture(GL_TEXTURE_2D, lightmapTextures[meshFaces[meshFaceNumber].lightmapIndex]);
	else
		glBindTexture(GL_TEXTURE_2D, whiteTexture);
	glActiveTextureARB(GL_TEXTURE0_ARB);


	//draw the face, using meshIndices
	if(!EXT_draw_range_elements_supported)
	{
		glDrawElements(	GL_TRIANGLES, meshFaces[meshFaceNumber].numMeshIndices, GL_UNSIGNED_INT,
						&meshIndices[meshFaces[meshFaceNumber].firstMeshIndex]);
	}
	else
	{
		glDrawRangeElementsEXT(	GL_TRIANGLES, 0, meshFaces[meshFaceNumber].numVertices,
								meshFaces[meshFaceNumber].numMeshIndices, GL_UNSIGNED_INT,
								&meshIndices[meshFaces[meshFaceNumber].firstMeshIndex]);
	}
}
Example #3
0
void Draw_Mesh_simple(Mesh_t *mesh)
{
  int meshtype = mesh->meshtype;

  LUX_DEBUGASSERT(mesh);

  if (!mesh->numVertices)
    return;

  // draw mesh
  if (meshtype != MESH_DL){
    int n;
    ushort  *pointtri;
    uint  *pointtriI;
    uint  offsetTri;
    uint  vertexoffset;
    GLenum  rendertype = mesh->primtype;
    GLenum  indicestype = mesh->index16 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;

    LUX_DEBUGASSERT(!(mesh->meshtype == MESH_VBO && !mesh->vid.vbo));

    if (mesh->vid.ibo){
      pointtri  = NULL;
      pointtriI = NULL;
      offsetTri  = mesh->vid.ibooffset;
    }
    else{
      offsetTri = 0;
      pointtri  = mesh->indicesData16;
      pointtriI = mesh->indicesData32;
    }
    vidBindBufferIndex(mesh->vid.ibo);

    vertexoffset = mesh->vid.vbo ? mesh->vid.vbooffset : 0;


    // feed vertex attribs
    {
      int t;
      Mesh_setStandardAttribsGL(mesh,
        !(g_VID.state.renderflag & RENDER_NOVERTEXCOLOR),
        g_VID.drawsetup.lightCnt || g_VID.drawsetup.setnormals);

      for (t = 0; t < VID_MAX_TEXTURE_UNITS; t++){
        if (g_VID.state.texcoords[t].type < 0){
          Mesh_setTexCoordGL(mesh,t,g_VID.state.texcoords[t].channel);
        }
      }

      if (g_VID.drawsetup.attribs.needed & (1<<VERTEX_ATTRIB_TANGENT)){
        Mesh_setTangentGL(mesh);
      }
    }

    if (mesh->vid.ibo || mesh->indicesData){
      if (mesh->numGroups < 2){
        if (GLEW_EXT_draw_range_elements)
          glDrawRangeElementsEXT(rendertype,mesh->indexMin + vertexoffset,mesh->indexMax + vertexoffset, USED_INDICES(mesh->numIndices),  indicestype ,mesh->index16 ? (void*)(&pointtri[offsetTri]) : (void*)(&pointtriI[offsetTri]));
        else
          glDrawElements(rendertype, USED_INDICES(mesh->numIndices),  indicestype, mesh->index16 ? (void*)(&pointtri[offsetTri]) : (void*)(&pointtriI[offsetTri]));
      }
      else {
        for (n = 0; n < mesh->numGroups; n++){
          if (GLEW_EXT_draw_range_elements)
            glDrawRangeElementsEXT(rendertype,mesh->indexMin + vertexoffset,mesh->indexMax + vertexoffset, USED_INDICES(mesh->indicesGroupLength[n]),  indicestype ,mesh->index16 ? (void*)(&pointtri[offsetTri]) : (void*)(&pointtriI[offsetTri]));
          else
            glDrawElements(rendertype, USED_INDICES(mesh->indicesGroupLength[n]),  indicestype, mesh->index16 ? (void*)(&pointtri[offsetTri]) : (void*)(&pointtriI[offsetTri]));

          offsetTri += mesh->indicesGroupLength[n];
        }
      }
    }
    else{
      glDrawArrays(rendertype,vertexoffset,mesh->numVertices);
    }
  }
  else{
    vidBindBufferArray(NULL);
    vidBindBufferIndex(NULL);
    if (g_VID.gpuvendor == VID_VENDOR_ATI)
      if((g_VID.drawsetup.lightCnt || g_VID.drawsetup.setnormals) && (mesh->vertextype == VERTEX_32_NRM || mesh->vertextype == VERTEX_64_TEX4 || mesh->vertextype == VERTEX_64_SKIN || mesh->vertextype == VERTEX_32_FN))
        glEnableClientState(GL_NORMAL_ARRAY);
      else
        glDisableClientState(GL_NORMAL_ARRAY);

    glCallList(mesh->vid.glID);
    g_VID.state.activeTex = -1;
    g_VID.state.activeClientTex = -1;

    LUX_DEBUGASSERT(!glIsEnabled(GL_COLOR_ARRAY)==isFlagSet(g_VID.state.renderflag,RENDER_NOVERTEXCOLOR));

    //if (!glIsEnabled(GL_COLOR_ARRAY)) g_VID.state.renderflag |= RENDER_NOVERTEXCOLOR;
    //else                g_VID.state.renderflag &= ~RENDER_NOVERTEXCOLOR;

    vidResetPointer();
  }


#if 0
  glEnableClientState(GL_VERTEX_ARRAY);
  vidResetPointer();
  vidResetBuffers();
#endif

}
Example #4
0
        void draw() const
        {
            // Bail out if there's nothing to draw
            if (empty())
                return;

            // Pass all of our triangle data
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_NORMAL_ARRAY);

            assert((textureCount == 0
                 || _VertexArray.size() == _TexCoordArrays[0].size())
                && _VertexArray.size() == _NormalArray.size());

            // Pass the VertexArray
            _VertexArray.draw();
            _NormalArray.draw();

            // Pass texture data for all texture units
            /* NOTE: Although the single loop would suffice, to allow the
             *       compiler to optimise this code (by removing unreachable
             *       code in case of <= 1 texture) this switch statement is
             *       required.
             */
            switch (textureCount)
            {
                case 0:
                    break;

                case 1:
                    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
                    _TexCoordArrays[0].draw();
                    break;

                default:
                {
                    GLenum unit = GL_TEXTURE0;
                    for (size_t i = 0; i < textureCount; ++i)
                    {
                        if (GLEE_VERSION_1_3)
                            glClientActiveTexture(unit++);
                        else if (GLEE_ARB_multitexture)
                            glClientActiveTextureARB(unit++);
                        else
                            assert(!"Shouldn't ever get here!");

                        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
                        _TexCoordArrays[i].draw();
                    }
                    break;
                }
            }

            if (_indices)
            {
#ifndef NDEBUG
                if (_indices_modified)
                {
                    for (typename std::vector<IndexIntegerType>::const_iterator i = _indices->begin(); i != _indices->end(); ++i)
                        assert(*i < _VertexArray.size());
                    _indices_modified = false;
                }
#endif

                // Draw all contained triangles based on the array of indices
                if (GLEE_VERSION_1_2)
                    glDrawRangeElements(GL_TRIANGLES, 0, _VertexArray.size() - 1, _indices->size(), OpenGLTypeConstant<IndexIntegerType>::constant, &(*_indices)[0]);
                else if (GLEE_EXT_draw_range_elements)
                    glDrawRangeElementsEXT(GL_TRIANGLES, 0, _VertexArray.size() - 1, _indices->size(), OpenGLTypeConstant<IndexIntegerType>::constant, &(*_indices)[0]);
                else
                    glDrawElements(GL_TRIANGLES, _indices->size(), OpenGLTypeConstant<IndexIntegerType>::constant, &(*_indices)[0]);
            }
            else
            {
                glDrawArrays(GL_TRIANGLES, 0, _VertexArray.size());
            }

            // Disable the GL_VERTEX_ARRAY client state to prevent strange behaviour
            glDisableClientState(GL_NORMAL_ARRAY);
            glDisableClientState(GL_VERTEX_ARRAY);

            /* NOTE: Although the single loop would suffice, to allow the
             *       compiler to optimise this code (by removing unreachable
             *       code in case of <= 1 texture) this switch statement is
             *       required.
             */
            switch (textureCount)
            {
                case 0:
                    break;

                case 1:
                    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                    break;

                default:
                {
                    GLenum unit = GL_TEXTURE0;
                    for (size_t i = 0; i < textureCount; ++i)
                    {
                        if (GLEE_VERSION_1_3)
                            glClientActiveTexture(unit++);
                        else if (GLEE_ARB_multitexture)
                            glClientActiveTextureARB(unit++);
                        else
                            assert(!"Shouldn't ever get here!");
                        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                    }
                    if (GLEE_VERSION_1_3)
                        glClientActiveTexture(GL_TEXTURE0);
                    else if (GLEE_ARB_multitexture)
                        glClientActiveTextureARB(GL_TEXTURE0);
                    else
                        assert(!"Shouldn't ever get here!");
                    break;
                }
            }
        }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTDrawRangeElements_nglDrawRangeElementsEXT(JNIEnv *env, jclass clazz, jint mode, jint start, jint end, jint count, jint type, jobject pIndices, jint pIndices_position, jlong function_pointer) {
	const GLvoid *pIndices_address = ((const GLvoid *)(((char *)(*env)->GetDirectBufferAddress(env, pIndices)) + pIndices_position));
	glDrawRangeElementsEXTPROC glDrawRangeElementsEXT = (glDrawRangeElementsEXTPROC)((intptr_t)function_pointer);
	glDrawRangeElementsEXT(mode, start, end, count, type, pIndices_address);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTDrawRangeElements_nglDrawRangeElementsEXTBO(JNIEnv *env, jclass clazz, jint mode, jint start, jint end, jint count, jint type, jlong pIndices_buffer_offset, jlong function_pointer) {
	const GLvoid *pIndices_address = ((const GLvoid *)offsetToPointer(pIndices_buffer_offset));
	glDrawRangeElementsEXTPROC glDrawRangeElementsEXT = (glDrawRangeElementsEXTPROC)((intptr_t)function_pointer);
	glDrawRangeElementsEXT(mode, start, end, count, type, pIndices_address);
}