mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:24:00 +02:00
Merge pull request #985 from ZappoMan/voxel_geo_shader
add support for use of Byte normals
This commit is contained in:
commit
1bd67d3243
5 changed files with 72 additions and 20 deletions
|
@ -1576,6 +1576,8 @@ void Application::init() {
|
|||
|
||||
// Set up VoxelSystem after loading preferences so we can get the desired max voxel count
|
||||
_voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels());
|
||||
_voxels.setUseVoxelShader(Menu::getInstance()->isOptionChecked(MenuOption::UseVoxelShader));
|
||||
_voxels.setUseByteNormals(Menu::getInstance()->isOptionChecked(MenuOption::UseByteNormals));
|
||||
_voxels.init();
|
||||
|
||||
|
||||
|
|
|
@ -253,6 +253,9 @@ Menu::Menu() :
|
|||
addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::AmbientOcclusion);
|
||||
addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::UseVoxelShader, 0,
|
||||
false, this, SLOT(switchVoxelShader()));
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(voxelOptionsMenu, MenuOption::UseByteNormals, 0,
|
||||
false, Application::getInstance()->getVoxels(), SLOT(setUseByteNormals(bool)));
|
||||
|
||||
QMenu* avatarOptionsMenu = developerMenu->addMenu("Avatar Options");
|
||||
|
||||
|
|
|
@ -206,6 +206,7 @@ namespace MenuOption {
|
|||
const QString UsePerlinFace = "Use Perlin's Face";
|
||||
const QString Quit = "Quit";
|
||||
const QString UseVoxelShader = "Use Voxel Shader";
|
||||
const QString UseByteNormals = "Use Byte Normals";
|
||||
const QString Voxels = "Voxels";
|
||||
const QString VoxelAddMode = "Add Voxel Mode";
|
||||
const QString VoxelColorMode = "Color Voxel Mode";
|
||||
|
|
|
@ -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,
|
|||
0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1,
|
||||
0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1 };
|
||||
|
||||
GLfloat identityNormals[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1,
|
||||
GLbyte identityNormals[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1,
|
||||
0,0,+1, 0,0,+1, 0,0,+1, 0,0,+1,
|
||||
0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0,
|
||||
0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0,
|
||||
|
@ -75,7 +75,9 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels)
|
|||
connect(_tree, SIGNAL(importSize(float,float,float)), SIGNAL(importSize(float,float,float)));
|
||||
connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int)));
|
||||
|
||||
_useVoxelShader = false;
|
||||
_useVoxelShader = false;
|
||||
_useByteNormals = false;
|
||||
|
||||
_writeVoxelShaderData = NULL;
|
||||
_readVoxelShaderData = NULL;
|
||||
|
||||
|
@ -139,6 +141,20 @@ VoxelSystem::~VoxelSystem() {
|
|||
VoxelNode::removeDeleteHook(this);
|
||||
}
|
||||
|
||||
void VoxelSystem::setUseByteNormals(bool useByteNormals) {
|
||||
pthread_mutex_lock(&_bufferWriteLock);
|
||||
bool wasInitialized = _initialized;
|
||||
if (wasInitialized) {
|
||||
cleanupVoxelMemory();
|
||||
}
|
||||
_useByteNormals = useByteNormals;
|
||||
if (wasInitialized) {
|
||||
init();
|
||||
}
|
||||
pthread_mutex_unlock(&_bufferWriteLock);
|
||||
}
|
||||
|
||||
|
||||
void VoxelSystem::setMaxVoxels(int maxVoxels) {
|
||||
pthread_mutex_lock(&_bufferWriteLock);
|
||||
bool wasInitialized = _initialized;
|
||||
|
@ -194,6 +210,7 @@ void VoxelSystem::cleanupVoxelMemory() {
|
|||
|
||||
void VoxelSystem::initVoxelMemory() {
|
||||
if (_useVoxelShader) {
|
||||
qDebug("Using Voxel Shader...\n");
|
||||
GLuint* indicesArray = new GLuint[_maxVoxels];
|
||||
|
||||
// populate the indicesArray
|
||||
|
@ -241,27 +258,55 @@ void VoxelSystem::initVoxelMemory() {
|
|||
}
|
||||
}
|
||||
|
||||
GLfloat* normalsArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
GLfloat* normalsArrayEndPointer = normalsArray;
|
||||
if (_useByteNormals) {
|
||||
qDebug("Using Byte Normals...\n");
|
||||
GLbyte* normalsArray = new GLbyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
GLbyte* 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];
|
||||
// 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(GLbyte) * _maxVoxels,
|
||||
normalsArray, GL_STATIC_DRAW);
|
||||
|
||||
// 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);
|
||||
|
||||
// delete the indices and normals arrays that are no longer needed
|
||||
delete[] normalsArray;
|
||||
}
|
||||
|
||||
|
||||
glGenBuffers(1, &_vboVerticesID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
|
||||
glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW);
|
||||
|
||||
// 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);
|
||||
|
||||
// VBO for colorsArray
|
||||
glGenBuffers(1, &_vboColorsID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
|
||||
|
@ -276,7 +321,6 @@ void VoxelSystem::initVoxelMemory() {
|
|||
|
||||
// delete the indices and normals arrays that are no longer needed
|
||||
delete[] indicesArray;
|
||||
delete[] normalsArray;
|
||||
|
||||
|
||||
// we will track individual dirty sections with these arrays of bools
|
||||
|
@ -890,7 +934,7 @@ void VoxelSystem::render(bool texture) {
|
|||
glVertexPointer(3, GL_FLOAT, 0, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID);
|
||||
glNormalPointer(GL_FLOAT, 0, 0);
|
||||
glNormalPointer((_useByteNormals ? GL_BYTE : GL_FLOAT), 0, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
|
||||
glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
|
||||
|
@ -1769,7 +1813,7 @@ void VoxelSystem::falseColorizeOccludedV2() {
|
|||
void VoxelSystem::nodeAdded(Node* node) {
|
||||
if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
|
||||
uint16_t nodeID = node->getNodeID();
|
||||
printf("VoxelSystem... voxel server %u added...\n", nodeID);
|
||||
qDebug("VoxelSystem... voxel server %u added...\n", nodeID);
|
||||
_voxelServerCount++;
|
||||
}
|
||||
}
|
||||
|
@ -1792,7 +1836,7 @@ void VoxelSystem::nodeKilled(Node* node) {
|
|||
if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
|
||||
_voxelServerCount--;
|
||||
uint16_t nodeID = node->getNodeID();
|
||||
printf("VoxelSystem... voxel server %u removed...\n", nodeID);
|
||||
qDebug("VoxelSystem... voxel server %u removed...\n", nodeID);
|
||||
|
||||
if (_voxelServerCount > 0) {
|
||||
// Kill any voxels from the local tree that match this nodeID
|
||||
|
|
|
@ -128,6 +128,7 @@ public slots:
|
|||
void falseColorizeBySource();
|
||||
|
||||
void cancelImport();
|
||||
void setUseByteNormals(bool useByteNormals);
|
||||
|
||||
protected:
|
||||
float _treeScale;
|
||||
|
@ -203,10 +204,11 @@ private:
|
|||
uint64_t _lastViewCulling;
|
||||
int _lastViewCullingElapsed;
|
||||
|
||||
bool getUseVoxelShader();
|
||||
void initVoxelMemory();
|
||||
void cleanupVoxelMemory();
|
||||
|
||||
bool _useByteNormals;
|
||||
|
||||
bool _useVoxelShader;
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue