mirror of
https://github.com/glest/glest-source.git
synced 2025-09-29 17:09:02 +02:00
- attempt to add "some" VBO rendering for static models (need to test if this improves performance in different environments)
This commit is contained in:
@@ -19,17 +19,12 @@
|
||||
#include "conversion.h"
|
||||
#include "util.h"
|
||||
#include "platform_common.h"
|
||||
|
||||
#if defined(ENABLE_VBO_CODE)
|
||||
|
||||
#include "opengl.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Platform;
|
||||
using namespace Shared::PlatformCommon;
|
||||
using namespace Shared::Graphics::Gl;
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -65,15 +60,12 @@ Mesh::Mesh() {
|
||||
twoSided= false;
|
||||
customColor= false;
|
||||
|
||||
#if defined(ENABLE_VBO_CODE)
|
||||
hasBuiltVBOs = false;
|
||||
// Vertex Buffer Object Names
|
||||
m_nVBOVertices = 0;
|
||||
m_nVBOTexCoords = 0;
|
||||
m_nVBONormals = 0;
|
||||
m_nVBOIndexes = 0;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Mesh::~Mesh() {
|
||||
@@ -88,10 +80,7 @@ void Mesh::init() {
|
||||
}
|
||||
|
||||
void Mesh::end() {
|
||||
|
||||
#if defined(ENABLE_VBO_CODE)
|
||||
void ReleaseVBOs();
|
||||
#endif
|
||||
ReleaseVBOs();
|
||||
|
||||
delete [] vertices;
|
||||
delete [] normals;
|
||||
@@ -127,61 +116,61 @@ void Mesh::updateInterpolationVertices(float t, bool cycle) {
|
||||
interpolationData->updateVertices(t, cycle);
|
||||
}
|
||||
|
||||
#if defined(ENABLE_VBO_CODE)
|
||||
|
||||
void Mesh::BuildVBOs() {
|
||||
if(hasBuiltVBOs == false) {
|
||||
//printf("In [%s::%s Line: %d] setting up a VBO...\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if(getVBOSupported() == true) {
|
||||
if(hasBuiltVBOs == false) {
|
||||
//printf("In [%s::%s Line: %d] setting up a VBO...\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
// Generate And Bind The Vertex Buffer
|
||||
glGenBuffersARB( 1, &m_nVBOVertices ); // Get A Valid Name
|
||||
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices ); // Bind The Buffer
|
||||
// Load The Data
|
||||
glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec3f)*frameCount*vertexCount, getInterpolationData()->getVertices(), GL_STATIC_DRAW_ARB );
|
||||
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
|
||||
// Generate And Bind The Vertex Buffer
|
||||
glGenBuffersARB( 1, &m_nVBOVertices ); // Get A Valid Name
|
||||
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices ); // Bind The Buffer
|
||||
// Load The Data
|
||||
glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec3f)*frameCount*vertexCount, getInterpolationData()->getVertices(), GL_STATIC_DRAW_ARB );
|
||||
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
|
||||
|
||||
// Generate And Bind The Texture Coordinate Buffer
|
||||
glGenBuffersARB( 1, &m_nVBOTexCoords ); // Get A Valid Name
|
||||
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords ); // Bind The Buffer
|
||||
// Load The Data
|
||||
glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec2f)*vertexCount, texCoords, GL_STATIC_DRAW_ARB );
|
||||
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
|
||||
// Generate And Bind The Texture Coordinate Buffer
|
||||
glGenBuffersARB( 1, &m_nVBOTexCoords ); // Get A Valid Name
|
||||
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords ); // Bind The Buffer
|
||||
// Load The Data
|
||||
glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec2f)*vertexCount, texCoords, GL_STATIC_DRAW_ARB );
|
||||
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
|
||||
|
||||
// Generate And Bind The Normal Buffer
|
||||
glGenBuffersARB( 1, &m_nVBONormals ); // Get A Valid Name
|
||||
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBONormals ); // Bind The Buffer
|
||||
// Load The Data
|
||||
glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec3f)*frameCount*vertexCount, getInterpolationData()->getNormals(), GL_STATIC_DRAW_ARB );
|
||||
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
|
||||
// Generate And Bind The Normal Buffer
|
||||
glGenBuffersARB( 1, &m_nVBONormals ); // Get A Valid Name
|
||||
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBONormals ); // Bind The Buffer
|
||||
// Load The Data
|
||||
glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof(Vec3f)*frameCount*vertexCount, getInterpolationData()->getNormals(), GL_STATIC_DRAW_ARB );
|
||||
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
|
||||
|
||||
// Generate And Bind The Index Buffer
|
||||
glGenBuffersARB( 1, &m_nVBOIndexes ); // Get A Valid Name
|
||||
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, m_nVBOIndexes ); // Bind The Buffer
|
||||
// Load The Data
|
||||
glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(uint32)*indexCount, indices, GL_STATIC_DRAW_ARB );
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
||||
// Generate And Bind The Index Buffer
|
||||
glGenBuffersARB( 1, &m_nVBOIndexes ); // Get A Valid Name
|
||||
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, m_nVBOIndexes ); // Bind The Buffer
|
||||
// Load The Data
|
||||
glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(uint32)*indexCount, indices, GL_STATIC_DRAW_ARB );
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
||||
|
||||
// Our Copy Of The Data Is No Longer Necessary, It Is Safe In The Graphics Card
|
||||
delete [] vertices; vertices = NULL;
|
||||
delete [] texCoords; texCoords = NULL;
|
||||
delete [] normals; normals = NULL;
|
||||
delete [] indices; indices = NULL;
|
||||
// Our Copy Of The Data Is No Longer Necessary, It Is Safe In The Graphics Card
|
||||
delete [] vertices; vertices = NULL;
|
||||
delete [] texCoords; texCoords = NULL;
|
||||
delete [] normals; normals = NULL;
|
||||
delete [] indices; indices = NULL;
|
||||
|
||||
hasBuiltVBOs = true;
|
||||
hasBuiltVBOs = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Mesh::ReleaseVBOs() {
|
||||
if(hasBuiltVBOs == true) {
|
||||
glDeleteBuffersARB( 1, &m_nVBOVertices ); // Get A Valid Name
|
||||
glDeleteBuffersARB( 1, &m_nVBOTexCoords ); // Get A Valid Name
|
||||
glDeleteBuffersARB( 1, &m_nVBONormals ); // Get A Valid Name
|
||||
glDeleteBuffersARB( 1, &m_nVBOIndexes ); // Get A Valid Name
|
||||
if(getVBOSupported() == true) {
|
||||
if(hasBuiltVBOs == true) {
|
||||
glDeleteBuffersARB( 1, &m_nVBOVertices ); // Get A Valid Name
|
||||
glDeleteBuffersARB( 1, &m_nVBOTexCoords ); // Get A Valid Name
|
||||
glDeleteBuffersARB( 1, &m_nVBONormals ); // Get A Valid Name
|
||||
glDeleteBuffersARB( 1, &m_nVBOIndexes ); // Get A Valid Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ==================== load ====================
|
||||
|
||||
void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) {
|
||||
@@ -457,18 +446,17 @@ void Mesh::deletePixels() {
|
||||
|
||||
// ==================== constructor & destructor ====================
|
||||
|
||||
Model::Model(){
|
||||
meshCount= 0;
|
||||
meshes= NULL;
|
||||
textureManager= NULL;
|
||||
Model::Model() {
|
||||
meshCount = 0;
|
||||
meshes = NULL;
|
||||
textureManager = NULL;
|
||||
lastTData = -1;
|
||||
lastCycleData = false;
|
||||
lastTVertex = -1;
|
||||
lastCycleVertex = false;
|
||||
isStaticModel = false;
|
||||
}
|
||||
|
||||
Model::~Model(){
|
||||
Model::~Model() {
|
||||
delete [] meshes;
|
||||
meshes = NULL;
|
||||
}
|
||||
@@ -483,40 +471,38 @@ void Model::buildInterpolationData() const{
|
||||
|
||||
void Model::updateInterpolationData(float t, bool cycle) {
|
||||
if(lastTData != t || lastCycleData != cycle) {
|
||||
for(unsigned int i=0; i<meshCount; ++i){
|
||||
for(unsigned int i = 0; i < meshCount; ++i) {
|
||||
meshes[i].updateInterpolationData(t, cycle);
|
||||
}
|
||||
//if(isStaticModel) printf("In [%s::%s Line: %d] filename [%s] t = [%f] cycle = [%d] lastTData = [%f] lastCycleData [%d]\n",__FILE__,__FUNCTION__,__LINE__,this->fileName.c_str(),t,cycle,lastTData,lastCycleData);
|
||||
lastTData = t;
|
||||
lastCycleData = cycle;
|
||||
lastTData = t;
|
||||
lastCycleData = cycle;
|
||||
}
|
||||
}
|
||||
|
||||
void Model::updateInterpolationVertices(float t, bool cycle) {
|
||||
if(lastTVertex != t || lastCycleVertex != cycle) {
|
||||
for(unsigned int i=0; i<meshCount; ++i){
|
||||
for(unsigned int i = 0; i < meshCount; ++i) {
|
||||
meshes[i].updateInterpolationVertices(t, cycle);
|
||||
}
|
||||
//if(isStaticModel) printf("In [%s::%s Line: %d] filename [%s] t = [%f] cycle = [%d] lastTData = [%f] lastCycleData [%d]\n",__FILE__,__FUNCTION__,__LINE__,this->fileName.c_str(),t,cycle,lastTData,lastCycleData);
|
||||
lastTVertex = t;
|
||||
lastTVertex = t;
|
||||
lastCycleVertex = cycle;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== get ====================
|
||||
|
||||
uint32 Model::getTriangleCount() const{
|
||||
uint32 Model::getTriangleCount() const {
|
||||
uint32 triangleCount= 0;
|
||||
for(uint32 i=0; i<meshCount; ++i){
|
||||
triangleCount+= meshes[i].getIndexCount()/3;
|
||||
for(uint32 i = 0; i < meshCount; ++i) {
|
||||
triangleCount += meshes[i].getIndexCount()/3;
|
||||
}
|
||||
return triangleCount;
|
||||
}
|
||||
|
||||
uint32 Model::getVertexCount() const {
|
||||
uint32 vertexCount= 0;
|
||||
for(uint32 i=0; i<meshCount; ++i){
|
||||
vertexCount+= meshes[i].getVertexCount();
|
||||
for(uint32 i = 0; i < meshCount; ++i) {
|
||||
vertexCount += meshes[i].getVertexCount();
|
||||
}
|
||||
return vertexCount;
|
||||
}
|
||||
@@ -620,15 +606,6 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
|
||||
meshes[i].load(dir, f, textureManager,deletePixMapAfterLoad);
|
||||
meshes[i].buildInterpolationData();
|
||||
}
|
||||
|
||||
//#if defined(ENABLE_VBO_CODE)
|
||||
// if(isStaticModel == true) {
|
||||
// this->updateInterpolationData(0.f, true);
|
||||
// for(uint32 i=0; i<meshCount; ++i){
|
||||
// meshes[i].BuildVBOs();
|
||||
// }
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
//version 3
|
||||
else if(fileHeader.version==3){
|
||||
@@ -639,15 +616,6 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
|
||||
meshes[i].loadV3(dir, f, textureManager,deletePixMapAfterLoad);
|
||||
meshes[i].buildInterpolationData();
|
||||
}
|
||||
|
||||
//#if defined(ENABLE_VBO_CODE)
|
||||
// if(isStaticModel == true) {
|
||||
// this->updateInterpolationData(0.f, true);
|
||||
// for(uint32 i=0; i<meshCount; ++i){
|
||||
// meshes[i].BuildVBOs();
|
||||
// }
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
//version 2
|
||||
else if(fileHeader.version==2) {
|
||||
@@ -657,15 +625,6 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
|
||||
meshes[i].loadV2(dir, f, textureManager,deletePixMapAfterLoad);
|
||||
meshes[i].buildInterpolationData();
|
||||
}
|
||||
|
||||
//#if defined(ENABLE_VBO_CODE)
|
||||
// if(isStaticModel == true) {
|
||||
// this->updateInterpolationData(0.f, true);
|
||||
// for(uint32 i=0; i<meshCount; ++i){
|
||||
// meshes[i].BuildVBOs();
|
||||
// }
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
else {
|
||||
throw runtime_error("Invalid model version: "+ intToStr(fileHeader.version));
|
||||
|
Reference in New Issue
Block a user