mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 05:17:24 +02:00
Merge pull request #994 from ZappoMan/voxel_geo_shader
removed old normal support from voxel system only using global normals
This commit is contained in:
commit
7a74432bef
5 changed files with 47 additions and 204 deletions
|
@ -1588,7 +1588,6 @@ void Application::init() {
|
||||||
// Set up VoxelSystem after loading preferences so we can get the desired max voxel count
|
// Set up VoxelSystem after loading preferences so we can get the desired max voxel count
|
||||||
_voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels());
|
_voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels());
|
||||||
_voxels.setUseVoxelShader(Menu::getInstance()->isOptionChecked(MenuOption::UseVoxelShader));
|
_voxels.setUseVoxelShader(Menu::getInstance()->isOptionChecked(MenuOption::UseVoxelShader));
|
||||||
_voxels.setUseByteNormals(Menu::getInstance()->isOptionChecked(MenuOption::UseByteNormals));
|
|
||||||
_voxels.init();
|
_voxels.init();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -254,12 +254,6 @@ Menu::Menu() :
|
||||||
addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::UseVoxelShader, 0,
|
addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::UseVoxelShader, 0,
|
||||||
false, this, SLOT(switchVoxelShader()));
|
false, this, SLOT(switchVoxelShader()));
|
||||||
|
|
||||||
addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::UseByteNormals, 0,
|
|
||||||
false, Application::getInstance()->getVoxels(), SLOT(setUseByteNormals(bool)));
|
|
||||||
|
|
||||||
addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::UseGlobalNormals, 0,
|
|
||||||
false, Application::getInstance()->getVoxels(), SLOT(setUseGlobalNormals(bool)));
|
|
||||||
|
|
||||||
QMenu* avatarOptionsMenu = developerMenu->addMenu("Avatar Options");
|
QMenu* avatarOptionsMenu = developerMenu->addMenu("Avatar Options");
|
||||||
|
|
||||||
addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::Avatars, 0, true);
|
addCheckableActionToQMenuAndActionHash(avatarOptionsMenu, MenuOption::Avatars, 0, true);
|
||||||
|
|
|
@ -85,9 +85,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels)
|
||||||
connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int)));
|
connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int)));
|
||||||
|
|
||||||
_useVoxelShader = false;
|
_useVoxelShader = false;
|
||||||
_useByteNormals = false;
|
|
||||||
_useGlobalNormals = false;
|
|
||||||
|
|
||||||
_writeVoxelShaderData = NULL;
|
_writeVoxelShaderData = NULL;
|
||||||
_readVoxelShaderData = NULL;
|
_readVoxelShaderData = NULL;
|
||||||
|
|
||||||
|
@ -151,42 +149,6 @@ VoxelSystem::~VoxelSystem() {
|
||||||
VoxelNode::removeDeleteHook(this);
|
VoxelNode::removeDeleteHook(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::setUseByteNormals(bool useByteNormals) {
|
|
||||||
pthread_mutex_lock(&_bufferWriteLock);
|
|
||||||
bool wasInitialized = _initialized;
|
|
||||||
if (wasInitialized) {
|
|
||||||
clearAllNodesBufferIndex();
|
|
||||||
cleanupVoxelMemory();
|
|
||||||
}
|
|
||||||
_useByteNormals = useByteNormals;
|
|
||||||
if (wasInitialized) {
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&_bufferWriteLock);
|
|
||||||
|
|
||||||
if (wasInitialized) {
|
|
||||||
forceRedrawEntireTree();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoxelSystem::setUseGlobalNormals(bool useGlobalNormals) {
|
|
||||||
pthread_mutex_lock(&_bufferWriteLock);
|
|
||||||
bool wasInitialized = _initialized;
|
|
||||||
if (wasInitialized) {
|
|
||||||
clearAllNodesBufferIndex();
|
|
||||||
cleanupVoxelMemory();
|
|
||||||
}
|
|
||||||
_useGlobalNormals = useGlobalNormals;
|
|
||||||
if (wasInitialized) {
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&_bufferWriteLock);
|
|
||||||
|
|
||||||
if (wasInitialized) {
|
|
||||||
forceRedrawEntireTree();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoxelSystem::setMaxVoxels(int maxVoxels) {
|
void VoxelSystem::setMaxVoxels(int maxVoxels) {
|
||||||
pthread_mutex_lock(&_bufferWriteLock);
|
pthread_mutex_lock(&_bufferWriteLock);
|
||||||
bool wasInitialized = _initialized;
|
bool wasInitialized = _initialized;
|
||||||
|
@ -237,17 +199,12 @@ void VoxelSystem::cleanupVoxelMemory() {
|
||||||
glDeleteBuffers(1, &_vboVerticesID);
|
glDeleteBuffers(1, &_vboVerticesID);
|
||||||
glDeleteBuffers(1, &_vboColorsID);
|
glDeleteBuffers(1, &_vboColorsID);
|
||||||
|
|
||||||
if (!_useGlobalNormals) {
|
glDeleteBuffers(1, &_vboIndicesTop);
|
||||||
glDeleteBuffers(1, &_vboNormalsID);
|
glDeleteBuffers(1, &_vboIndicesBottom);
|
||||||
glDeleteBuffers(1, &_vboIndicesID);
|
glDeleteBuffers(1, &_vboIndicesLeft);
|
||||||
} else {
|
glDeleteBuffers(1, &_vboIndicesRight);
|
||||||
glDeleteBuffers(1, &_vboIndicesTop);
|
glDeleteBuffers(1, &_vboIndicesFront);
|
||||||
glDeleteBuffers(1, &_vboIndicesBottom);
|
glDeleteBuffers(1, &_vboIndicesBack);
|
||||||
glDeleteBuffers(1, &_vboIndicesLeft);
|
|
||||||
glDeleteBuffers(1, &_vboIndicesRight);
|
|
||||||
glDeleteBuffers(1, &_vboIndicesFront);
|
|
||||||
glDeleteBuffers(1, &_vboIndicesBack);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete[] _readVerticesArray;
|
delete[] _readVerticesArray;
|
||||||
delete[] _writeVerticesArray;
|
delete[] _writeVerticesArray;
|
||||||
|
@ -332,94 +289,19 @@ void VoxelSystem::initVoxelMemory() {
|
||||||
_readVoxelShaderData = new VoxelShaderVBOData[_maxVoxels];
|
_readVoxelShaderData = new VoxelShaderVBOData[_maxVoxels];
|
||||||
_memoryUsageRAM += (sizeof(VoxelShaderVBOData) * _maxVoxels);
|
_memoryUsageRAM += (sizeof(VoxelShaderVBOData) * _maxVoxels);
|
||||||
} else {
|
} else {
|
||||||
if (_useGlobalNormals) {
|
|
||||||
// Global Normals mode uses a technique of not including normals on any voxel vertices, and instead
|
|
||||||
// rendering the voxel faces in 6 passes that use a global call to glNormal3f()
|
|
||||||
qDebug("Using Global Normals...\n");
|
|
||||||
setupFaceIndices(_vboIndicesTop, identityIndicesTop);
|
|
||||||
setupFaceIndices(_vboIndicesBottom, identityIndicesBottom);
|
|
||||||
setupFaceIndices(_vboIndicesLeft, identityIndicesLeft);
|
|
||||||
setupFaceIndices(_vboIndicesRight, identityIndicesRight);
|
|
||||||
setupFaceIndices(_vboIndicesFront, identityIndicesFront);
|
|
||||||
setupFaceIndices(_vboIndicesBack, identityIndicesBack);
|
|
||||||
} else {
|
|
||||||
if (_useByteNormals) {
|
|
||||||
qDebug("Using Byte Normals...\n");
|
|
||||||
GLbyte* normalsArray = new GLbyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
|
||||||
GLbyte* normalsArrayEndPointer = normalsArray;
|
|
||||||
|
|
||||||
// populate the normalsArray
|
// Global Normals mode uses a technique of not including normals on any voxel vertices, and instead
|
||||||
for (int n = 0; n < _maxVoxels; n++) {
|
// rendering the voxel faces in 6 passes that use a global call to glNormal3f()
|
||||||
for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) {
|
qDebug("Using Global Normals...\n");
|
||||||
*(normalsArrayEndPointer++) = (identityNormals[i] * CHAR_MAX);
|
setupFaceIndices(_vboIndicesTop, identityIndicesTop);
|
||||||
}
|
setupFaceIndices(_vboIndicesBottom, identityIndicesBottom);
|
||||||
}
|
setupFaceIndices(_vboIndicesLeft, identityIndicesLeft);
|
||||||
|
setupFaceIndices(_vboIndicesRight, identityIndicesRight);
|
||||||
// VBO for the normalsArray
|
setupFaceIndices(_vboIndicesFront, identityIndicesFront);
|
||||||
glGenBuffers(1, &_vboNormalsID);
|
setupFaceIndices(_vboIndicesBack, identityIndicesBack);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER,
|
|
||||||
VERTEX_POINTS_PER_VOXEL * sizeof(GLbyte) * _maxVoxels,
|
|
||||||
normalsArray, GL_STATIC_DRAW);
|
|
||||||
_memoryUsageVBO += VERTEX_POINTS_PER_VOXEL * sizeof(GLbyte) * _maxVoxels;
|
|
||||||
|
|
||||||
// delete the indices and normals arrays that are no longer needed
|
|
||||||
delete[] normalsArray;
|
|
||||||
} else {
|
|
||||||
qDebug("Using Float Normals...\n");
|
|
||||||
GLfloat* normalsArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
|
||||||
GLfloat* normalsArrayEndPointer = normalsArray;
|
|
||||||
|
|
||||||
// populate the normalsArray
|
|
||||||
for (int n = 0; n < _maxVoxels; n++) {
|
|
||||||
for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) {
|
|
||||||
*(normalsArrayEndPointer++) = identityNormals[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// VBO for the normalsArray
|
|
||||||
glGenBuffers(1, &_vboNormalsID);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER,
|
|
||||||
VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels,
|
|
||||||
normalsArray, GL_STATIC_DRAW);
|
|
||||||
_memoryUsageVBO += VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels;
|
|
||||||
|
|
||||||
// delete the indices and normals arrays that are no longer needed
|
|
||||||
delete[] normalsArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint* indicesArray = new GLuint[INDICES_PER_VOXEL * _maxVoxels];
|
|
||||||
|
|
||||||
// populate the indicesArray
|
|
||||||
// this will not change given new voxels, so we can set it all up now
|
|
||||||
for (int n = 0; n < _maxVoxels; n++) {
|
|
||||||
// fill the indices array
|
|
||||||
int voxelIndexOffset = n * INDICES_PER_VOXEL;
|
|
||||||
GLuint* currentIndicesPos = indicesArray + voxelIndexOffset;
|
|
||||||
int startIndex = (n * VERTICES_PER_VOXEL);
|
|
||||||
|
|
||||||
for (int i = 0; i < INDICES_PER_VOXEL; i++) {
|
|
||||||
// add indices for this side of the cube
|
|
||||||
currentIndicesPos[i] = startIndex + identityIndices[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// VBO for the indicesArray
|
|
||||||
glGenBuffers(1, &_vboIndicesID);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesID);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
|
|
||||||
INDICES_PER_VOXEL * sizeof(GLuint) * _maxVoxels,
|
|
||||||
indicesArray, GL_STATIC_DRAW);
|
|
||||||
_memoryUsageVBO += INDICES_PER_VOXEL * sizeof(GLuint) * _maxVoxels;
|
|
||||||
|
|
||||||
// delete the indices and normals arrays that are no longer needed
|
|
||||||
delete[] indicesArray;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Depending on if we're using per vertex normals, we will need more or less vertex points per voxel
|
// Depending on if we're using per vertex normals, we will need more or less vertex points per voxel
|
||||||
int vertexPointsPerVoxel = _useGlobalNormals ? GLOBAL_NORMALS_VERTEX_POINTS_PER_VOXEL : VERTEX_POINTS_PER_VOXEL;
|
int vertexPointsPerVoxel = GLOBAL_NORMALS_VERTEX_POINTS_PER_VOXEL;
|
||||||
glGenBuffers(1, &_vboVerticesID);
|
glGenBuffers(1, &_vboVerticesID);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
|
glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
|
||||||
glBufferData(GL_ARRAY_BUFFER, vertexPointsPerVoxel * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, vertexPointsPerVoxel * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW);
|
||||||
|
@ -730,7 +612,7 @@ void VoxelSystem::copyWrittenDataSegmentToReadArrays(glBufferIndex segmentStart,
|
||||||
memcpy(readDataAt, writeDataAt, segmentSizeBytes);
|
memcpy(readDataAt, writeDataAt, segmentSizeBytes);
|
||||||
} else {
|
} else {
|
||||||
// Depending on if we're using per vertex normals, we will need more or less vertex points per voxel
|
// Depending on if we're using per vertex normals, we will need more or less vertex points per voxel
|
||||||
int vertexPointsPerVoxel = _useGlobalNormals ? GLOBAL_NORMALS_VERTEX_POINTS_PER_VOXEL : VERTEX_POINTS_PER_VOXEL;
|
int vertexPointsPerVoxel = GLOBAL_NORMALS_VERTEX_POINTS_PER_VOXEL;
|
||||||
|
|
||||||
GLintptr segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLfloat);
|
GLintptr segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLfloat);
|
||||||
GLsizeiptr segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLfloat);
|
GLsizeiptr segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLfloat);
|
||||||
|
@ -880,17 +762,11 @@ void VoxelSystem::updateNodeInArrays(glBufferIndex nodeIndex, const glm::vec3& s
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_writeVerticesArray && _writeColorsArray) {
|
if (_writeVerticesArray && _writeColorsArray) {
|
||||||
int vertexPointsPerVoxel = _useGlobalNormals ? GLOBAL_NORMALS_VERTEX_POINTS_PER_VOXEL : VERTEX_POINTS_PER_VOXEL;
|
int vertexPointsPerVoxel = GLOBAL_NORMALS_VERTEX_POINTS_PER_VOXEL;
|
||||||
for (int j = 0; j < vertexPointsPerVoxel; j++ ) {
|
for (int j = 0; j < vertexPointsPerVoxel; j++ ) {
|
||||||
GLfloat* writeVerticesAt = _writeVerticesArray + (nodeIndex * vertexPointsPerVoxel);
|
GLfloat* writeVerticesAt = _writeVerticesArray + (nodeIndex * vertexPointsPerVoxel);
|
||||||
GLubyte* writeColorsAt = _writeColorsArray + (nodeIndex * vertexPointsPerVoxel);
|
GLubyte* writeColorsAt = _writeColorsArray + (nodeIndex * vertexPointsPerVoxel);
|
||||||
|
*(writeVerticesAt+j) = startVertex[j % 3] + (identityVerticesGlobalNormals[j] * voxelScale);
|
||||||
if (_useGlobalNormals) {
|
|
||||||
*(writeVerticesAt+j) = startVertex[j % 3] + (identityVerticesGlobalNormals[j] * voxelScale);
|
|
||||||
} else {
|
|
||||||
*(writeVerticesAt+j) = startVertex[j % 3] + (identityVertices[j] * voxelScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
*(writeColorsAt +j) = color[j % 3];
|
*(writeColorsAt +j) = color[j % 3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1002,7 +878,7 @@ void VoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferIndex seg
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vboVoxelsID);
|
glBindBuffer(GL_ARRAY_BUFFER, _vboVoxelsID);
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readVerticesFrom);
|
glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readVerticesFrom);
|
||||||
} else {
|
} else {
|
||||||
int vertexPointsPerVoxel = _useGlobalNormals ? GLOBAL_NORMALS_VERTEX_POINTS_PER_VOXEL : VERTEX_POINTS_PER_VOXEL;
|
int vertexPointsPerVoxel = GLOBAL_NORMALS_VERTEX_POINTS_PER_VOXEL;
|
||||||
int segmentLength = (segmentEnd - segmentStart) + 1;
|
int segmentLength = (segmentEnd - segmentStart) + 1;
|
||||||
GLintptr segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLfloat);
|
GLintptr segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLfloat);
|
||||||
GLsizeiptr segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLfloat);
|
GLsizeiptr segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLfloat);
|
||||||
|
@ -1065,57 +941,42 @@ void VoxelSystem::render(bool texture) {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
|
glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
|
||||||
glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
|
glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
|
||||||
|
|
||||||
if (!_useGlobalNormals) {
|
|
||||||
glEnableClientState(GL_NORMAL_ARRAY);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID);
|
|
||||||
glNormalPointer((_useByteNormals ? GL_BYTE : GL_FLOAT), 0, 0);
|
|
||||||
} else {
|
|
||||||
glNormal3f(0,1.0f,0); // hack for now
|
|
||||||
}
|
|
||||||
|
|
||||||
applyScaleAndBindProgram(texture);
|
applyScaleAndBindProgram(texture);
|
||||||
|
|
||||||
// for performance, enable backface culling
|
// for performance, enable backface culling
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
if (!_useGlobalNormals) {
|
// draw voxels in 6 passes
|
||||||
// draw the number of voxels we have
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesID);
|
|
||||||
glDrawRangeElementsEXT(GL_TRIANGLES, 0, VERTICES_PER_VOXEL * _voxelsInReadArrays - 1,
|
|
||||||
36 * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
|
||||||
} else {
|
|
||||||
// draw voxels in 6 passes
|
|
||||||
|
|
||||||
glNormal3f(0,1.0f,0);
|
glNormal3f(0,1.0f,0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesTop);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesTop);
|
||||||
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
||||||
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
glNormal3f(0,-1.0f,0);
|
glNormal3f(0,-1.0f,0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBottom);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBottom);
|
||||||
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
||||||
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
glNormal3f(-1.0f,0,0);
|
glNormal3f(-1.0f,0,0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesLeft);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesLeft);
|
||||||
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
||||||
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
glNormal3f(1.0f,0,0);
|
glNormal3f(1.0f,0,0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesRight);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesRight);
|
||||||
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
||||||
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
glNormal3f(0,0,-1.0f);
|
glNormal3f(0,0,-1.0f);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesFront);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesFront);
|
||||||
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
||||||
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
glNormal3f(0,0,1.0f);
|
glNormal3f(0,0,1.0f);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBack);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBack);
|
||||||
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
|
||||||
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
@ -1126,10 +987,6 @@ void VoxelSystem::render(bool texture) {
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
if (!_useGlobalNormals) {
|
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// bind with 0 to switch back to normal operation
|
// bind with 0 to switch back to normal operation
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
|
|
@ -134,8 +134,6 @@ public slots:
|
||||||
void clearAllNodesBufferIndex();
|
void clearAllNodesBufferIndex();
|
||||||
|
|
||||||
void cancelImport();
|
void cancelImport();
|
||||||
void setUseByteNormals(bool useByteNormals);
|
|
||||||
void setUseGlobalNormals(bool useGlobalNormals);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float _treeScale;
|
float _treeScale;
|
||||||
|
@ -218,9 +216,6 @@ private:
|
||||||
void initVoxelMemory();
|
void initVoxelMemory();
|
||||||
void cleanupVoxelMemory();
|
void cleanupVoxelMemory();
|
||||||
|
|
||||||
bool _useByteNormals;
|
|
||||||
bool _useGlobalNormals;
|
|
||||||
|
|
||||||
bool _useVoxelShader;
|
bool _useVoxelShader;
|
||||||
GLuint _vboVoxelsID; /// when using voxel shader, we'll use this VBO
|
GLuint _vboVoxelsID; /// when using voxel shader, we'll use this VBO
|
||||||
GLuint _vboVoxelsIndicesID; /// when using voxel shader, we'll use this VBO for our indexes
|
GLuint _vboVoxelsIndicesID; /// when using voxel shader, we'll use this VBO for our indexes
|
||||||
|
@ -228,9 +223,7 @@ private:
|
||||||
VoxelShaderVBOData* _readVoxelShaderData;
|
VoxelShaderVBOData* _readVoxelShaderData;
|
||||||
|
|
||||||
GLuint _vboVerticesID;
|
GLuint _vboVerticesID;
|
||||||
GLuint _vboNormalsID;
|
|
||||||
GLuint _vboColorsID;
|
GLuint _vboColorsID;
|
||||||
GLuint _vboIndicesID;
|
|
||||||
|
|
||||||
GLuint _vboIndicesTop;
|
GLuint _vboIndicesTop;
|
||||||
GLuint _vboIndicesBottom;
|
GLuint _vboIndicesBottom;
|
||||||
|
|
|
@ -443,7 +443,7 @@ void ViewFrustum::printDebugDetails() const {
|
||||||
|
|
||||||
glm::vec2 ViewFrustum::projectPoint(glm::vec3 point, bool& pointInView) const {
|
glm::vec2 ViewFrustum::projectPoint(glm::vec3 point, bool& pointInView) const {
|
||||||
|
|
||||||
glm::vec4 pointVec4 = glm::vec4(point,1) ;
|
glm::vec4 pointVec4 = glm::vec4(point,1);
|
||||||
glm::vec4 projectedPointVec4 = _ourModelViewProjectionMatrix * pointVec4;
|
glm::vec4 projectedPointVec4 = _ourModelViewProjectionMatrix * pointVec4;
|
||||||
pointInView = (projectedPointVec4.w > 0); // math! If the w result is negative then the point is behind the viewer
|
pointInView = (projectedPointVec4.w > 0); // math! If the w result is negative then the point is behind the viewer
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue