History

add support for use of Byte normals

ZappoMan committed 13 years ago

Commit 2487a551 parent 0fbabe95 files · +72 −20Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+63−19
@@ -37,7 +37,7 @@ float identityVertices[] = { 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0, · 36 unmodified lines
3737 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1,
3838 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1 };
3939
40−GLfloat identityNormals[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1,
40+GLbyte identityNormals[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1,
4141 0,0,+1, 0,0,+1, 0,0,+1, 0,0,+1,
4242 0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0,
4343 0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0,
@@ -75,7 +75,9 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 31 unmodified lines
7575 connect(_tree, SIGNAL(importSize(float,float,float)), SIGNAL(importSize(float,float,float)));
7676 connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int)));
7777
78− _useVoxelShader = false;
78+ _useVoxelShader = false;
79+ _useByteNormals = false;
80+
7981 _writeVoxelShaderData = NULL;
8082 _readVoxelShaderData = NULL;
8183
@@ -139,6 +141,20 @@ VoxelSystem::~VoxelSystem() { · 57 unmodified lines
139141 VoxelNode::removeDeleteHook(this);
140142 }
141143
144+void VoxelSystem::setUseByteNormals(bool useByteNormals) {
145+ pthread_mutex_lock(&_bufferWriteLock);
146+ bool wasInitialized = _initialized;
147+ if (wasInitialized) {
148+ cleanupVoxelMemory();
149+ }
150+ _useByteNormals = useByteNormals;
151+ if (wasInitialized) {
152+ init();
153+ }
154+ pthread_mutex_unlock(&_bufferWriteLock);
155+}
156+
157+
142158 void VoxelSystem::setMaxVoxels(int maxVoxels) {
143159 pthread_mutex_lock(&_bufferWriteLock);
144160 bool wasInitialized = _initialized;
@@ -194,6 +210,7 @@ void VoxelSystem::cleanupVoxelMemory() { · 49 unmodified lines
194210
195211 void VoxelSystem::initVoxelMemory() {
196212 if (_useVoxelShader) {
213+ qDebug("Using Voxel Shader...\n");
197214 GLuint* indicesArray = new GLuint[_maxVoxels];
198215
199216 // populate the indicesArray
@@ -241,27 +258,55 @@ void VoxelSystem::initVoxelMemory() { · 41 unmodified lines
241258 }
242259 }
243260
244− GLfloat* normalsArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
245− GLfloat* normalsArrayEndPointer = normalsArray;
261+ if (_useByteNormals) {
262+ qDebug("Using Byte Normals...\n");
263+ GLbyte* normalsArray = new GLbyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
264+ GLbyte* normalsArrayEndPointer = normalsArray;
246265
247− // populate the normalsArray
248− for (int n = 0; n < _maxVoxels; n++) {
249− for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) {
250− *(normalsArrayEndPointer++) = identityNormals[i];
266+ // populate the normalsArray
267+ for (int n = 0; n < _maxVoxels; n++) {
268+ for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) {
269+ *(normalsArrayEndPointer++) = identityNormals[i];
270+ }
271+ }
272+
273+ // VBO for the normalsArray
274+ glGenBuffers(1, &_vboNormalsID);
275+ glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID);
276+ glBufferData(GL_ARRAY_BUFFER,
277+ VERTEX_POINTS_PER_VOXEL * sizeof(GLbyte) * _maxVoxels,
278+ normalsArray, GL_STATIC_DRAW);
279+
280+ // delete the indices and normals arrays that are no longer needed
281+ delete[] normalsArray;
282+ } else {
283+ qDebug("Using Float Normals...\n");
284+ GLfloat* normalsArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
285+ GLfloat* normalsArrayEndPointer = normalsArray;
286+
287+ // populate the normalsArray
288+ for (int n = 0; n < _maxVoxels; n++) {
289+ for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) {
290+ *(normalsArrayEndPointer++) = identityNormals[i];
291+ }
251292 }
293+
294+ // VBO for the normalsArray
295+ glGenBuffers(1, &_vboNormalsID);
296+ glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID);
297+ glBufferData(GL_ARRAY_BUFFER,
298+ VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels,
299+ normalsArray, GL_STATIC_DRAW);
300+
301+ // delete the indices and normals arrays that are no longer needed
302+ delete[] normalsArray;
252303 }
253304
305+
254306 glGenBuffers(1, &_vboVerticesID);
255307 glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
256308 glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW);
257309
258− // VBO for the normalsArray
259− glGenBuffers(1, &_vboNormalsID);
260− glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID);
261− glBufferData(GL_ARRAY_BUFFER,
262− VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels,
263− normalsArray, GL_STATIC_DRAW);
264−
265310 // VBO for colorsArray
266311 glGenBuffers(1, &_vboColorsID);
267312 glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
@@ -276,7 +321,6 @@ void VoxelSystem::initVoxelMemory() { · 8 unmodified lines
276321
277322 // delete the indices and normals arrays that are no longer needed
278323 delete[] indicesArray;
279− delete[] normalsArray;
280324
281325
282326 // we will track individual dirty sections with these arrays of bools
@@ -890,7 +934,7 @@ void VoxelSystem::render(bool texture) { · 607 unmodified lines
890934 glVertexPointer(3, GL_FLOAT, 0, 0);
891935
892936 glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID);
893− glNormalPointer(GL_FLOAT, 0, 0);
937+ glNormalPointer((_useByteNormals ? GL_BYTE : GL_FLOAT), 0, 0);
894938
895939 glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
896940 glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
@@ -1769,7 +1813,7 @@ void VoxelSystem::falseColorizeOccludedV2() { · 872 unmodified lines
17691813 void VoxelSystem::nodeAdded(Node* node) {
17701814 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
17711815 uint16_t nodeID = node->getNodeID();
1772− printf("VoxelSystem... voxel server %u added...\n", nodeID);
1816+ qDebug("VoxelSystem... voxel server %u added...\n", nodeID);
17731817 _voxelServerCount++;
17741818 }
17751819 }
@@ -1792,7 +1836,7 @@ void VoxelSystem::nodeKilled(Node* node) { · 16 unmodified lines
17921836 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
17931837 _voxelServerCount--;
17941838 uint16_t nodeID = node->getNodeID();
1795− printf("VoxelSystem... voxel server %u removed...\n", nodeID);
1839+ qDebug("VoxelSystem... voxel server %u removed...\n", nodeID);
17961840
17971841 if (_voxelServerCount > 0) {
17981842 // Kill any voxels from the local tree that match this nodeID

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t