mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
only allow VBO re-transfer every 5 seconds for test
This commit is contained in:
parent
ebe11151f4
commit
793ac841f2
2 changed files with 11 additions and 5 deletions
|
@ -40,6 +40,8 @@ VoxelSystem::VoxelSystem() {
|
||||||
voxelsRendered = 0;
|
voxelsRendered = 0;
|
||||||
tree = new VoxelTree();
|
tree = new VoxelTree();
|
||||||
pthread_mutex_init(&bufferWriteLock, NULL);
|
pthread_mutex_init(&bufferWriteLock, NULL);
|
||||||
|
lastBufferCopy.tv_sec = 0;
|
||||||
|
lastBufferCopy.tv_usec = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelSystem::~VoxelSystem() {
|
VoxelSystem::~VoxelSystem() {
|
||||||
|
@ -185,11 +187,11 @@ VoxelSystem* VoxelSystem::clone() const {
|
||||||
|
|
||||||
void VoxelSystem::init() {
|
void VoxelSystem::init() {
|
||||||
// prep the data structures for incoming voxel data
|
// prep the data structures for incoming voxel data
|
||||||
writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
writeVerticesEndPointer = writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
||||||
readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
readVerticesEndPointer = readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
||||||
writeColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
writeColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
||||||
readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
||||||
|
|
||||||
GLuint *indicesArray = new GLuint[INDICES_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
GLuint *indicesArray = new GLuint[INDICES_PER_VOXEL * MAX_VOXELS_PER_SYSTEM];
|
||||||
|
|
||||||
// populate the indicesArray
|
// populate the indicesArray
|
||||||
|
@ -231,8 +233,9 @@ void VoxelSystem::render() {
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
|
double timeSinceLastDraw = usecTimestampNow() - usecTimestamp(&lastBufferCopy);
|
||||||
if (readVerticesEndPointer != readVerticesArray) {
|
if (readVerticesEndPointer != readVerticesArray && timeSinceLastDraw >= 5000 * 1000) {
|
||||||
|
printf("The time since the last draw was %f\n", timeSinceLastDraw);
|
||||||
// try to lock on the buffer write
|
// try to lock on the buffer write
|
||||||
// just avoid pulling new data if it is currently being written
|
// just avoid pulling new data if it is currently being written
|
||||||
if (pthread_mutex_trylock(&bufferWriteLock) == 0) {
|
if (pthread_mutex_trylock(&bufferWriteLock) == 0) {
|
||||||
|
@ -249,6 +252,8 @@ void VoxelSystem::render() {
|
||||||
|
|
||||||
pthread_mutex_unlock(&bufferWriteLock);
|
pthread_mutex_unlock(&bufferWriteLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gettimeofday(&lastBufferCopy, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// tell OpenGL where to find vertex and color information
|
// tell OpenGL where to find vertex and color information
|
||||||
|
|
|
@ -51,6 +51,7 @@ private:
|
||||||
GLuint vboColorsID;
|
GLuint vboColorsID;
|
||||||
GLuint vboIndicesID;
|
GLuint vboIndicesID;
|
||||||
pthread_mutex_t bufferWriteLock;
|
pthread_mutex_t bufferWriteLock;
|
||||||
|
timeval lastBufferCopy;
|
||||||
|
|
||||||
int treeToArrays(VoxelNode *currentNode, float nodePosition[3]);
|
int treeToArrays(VoxelNode *currentNode, float nodePosition[3]);
|
||||||
void setupNewVoxelsForDrawing();
|
void setupNewVoxelsForDrawing();
|
||||||
|
|
Loading…
Reference in a new issue