more optimizations of render pipeline

This commit is contained in:
ZappoMan 2013-05-02 22:26:56 -07:00
parent 771c604121
commit 34a059db9a
5 changed files with 30 additions and 5 deletions

View file

@ -154,6 +154,13 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
void VoxelSystem::setupNewVoxelsForDrawing() { void VoxelSystem::setupNewVoxelsForDrawing() {
double start = usecTimestampNow(); double start = usecTimestampNow();
double sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished);
if (sinceLastTime <= std::max(_setupNewVoxelsForDrawingLastElapsed,SIXTY_FPS_IN_MILLISECONDS)) {
return; // bail early, it hasn't been long enough since the last time we ran
}
if (_tree->isDirty()) { if (_tree->isDirty()) {
_callsToTreesToArrays++; _callsToTreesToArrays++;
_voxelsUpdated = newTreeToArrays(_tree->rootNode); _voxelsUpdated = newTreeToArrays(_tree->rootNode);
@ -164,6 +171,12 @@ void VoxelSystem::setupNewVoxelsForDrawing() {
if (_voxelsUpdated) { if (_voxelsUpdated) {
_voxelsDirty=true; _voxelsDirty=true;
} }
if (_voxelsDirty) {
// copy the newly written data to the arrays designated for reading
copyWrittenDataToReadArrays();
}
double end = usecTimestampNow(); double end = usecTimestampNow();
double elapsedmsec = (end - start)/1000.0; double elapsedmsec = (end - start)/1000.0;
if (_renderWarningsOn && elapsedmsec > 1) { if (_renderWarningsOn && elapsedmsec > 1) {
@ -175,10 +188,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() {
} }
} }
if (_voxelsDirty) { _setupNewVoxelsForDrawingLastFinished = end;
// copy the newly written data to the arrays designated for reading _setupNewVoxelsForDrawingLastElapsed = elapsedmsec;
copyWrittenDataToReadArrays();
}
} }
void VoxelSystem::copyWrittenDataToReadArrays() { void VoxelSystem::copyWrittenDataToReadArrays() {
@ -277,6 +288,8 @@ void VoxelSystem::init() {
_renderWarningsOn = false; _renderWarningsOn = false;
_callsToTreesToArrays = 0; _callsToTreesToArrays = 0;
_setupNewVoxelsForDrawingLastFinished = 0;
_setupNewVoxelsForDrawingLastElapsed = 0;
// When we change voxels representations in the arrays, we'll update this // When we change voxels representations in the arrays, we'll update this
_voxelsDirty = false; _voxelsDirty = false;

View file

@ -90,6 +90,10 @@ private:
unsigned long _voxelsUpdated; unsigned long _voxelsUpdated;
unsigned long _voxelsInArrays; unsigned long _voxelsInArrays;
double _setupNewVoxelsForDrawingLastElapsed;
double _setupNewVoxelsForDrawingLastFinished;
GLuint _vboVerticesID; GLuint _vboVerticesID;
GLuint _vboNormalsID; GLuint _vboNormalsID;
GLuint _vboColorsID; GLuint _vboColorsID;

View file

@ -24,4 +24,5 @@ const int COLOR_VALUES_PER_VOXEL = 3 * VERTICES_PER_VOXEL;
typedef unsigned long int glBufferIndex; typedef unsigned long int glBufferIndex;
const glBufferIndex GLBUFFER_INDEX_UNKNOWN = ULONG_MAX; const glBufferIndex GLBUFFER_INDEX_UNKNOWN = ULONG_MAX;
const double SIXTY_FPS_IN_MILLISECONDS = 1000.0/60;
#endif #endif

View file

@ -438,6 +438,12 @@ void VoxelTree::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) {
} }
} }
void VoxelTree::createVoxel(float x, float y, float z, float s, unsigned char red, unsigned char green, unsigned char blue) {
unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
this->readCodeColorBufferToTree(voxelData);
delete voxelData;
}
void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer) { void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer) {
// About the color of the sphere... we're going to make this sphere be a gradient // About the color of the sphere... we're going to make this sphere be a gradient
// between two RGB colors. We will do the gradient along the phi spectrum // between two RGB colors. We will do the gradient along the phi spectrum

View file

@ -46,6 +46,7 @@ public:
void reaverageVoxelColors(VoxelNode *startNode); void reaverageVoxelColors(VoxelNode *startNode);
void loadVoxelsFile(const char* fileName, bool wantColorRandomizer); void loadVoxelsFile(const char* fileName, bool wantColorRandomizer);
void createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer); void createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer);
void createVoxel(float x, float y, float z, float s, unsigned char red, unsigned char green, unsigned char blue);
void recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData=NULL); void recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData=NULL);