mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 03:43:33 +02:00
fix byte normals, fix crashes in switching between voxel shader and normal mode
This commit is contained in:
parent
2487a55be9
commit
eb6af1afbf
3 changed files with 65 additions and 15 deletions
|
@ -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,
|
||||||
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 };
|
||||||
|
|
||||||
GLbyte identityNormals[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1,
|
GLfloat 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,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,
|
||||||
0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0,
|
0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0,
|
||||||
|
@ -152,6 +152,10 @@ void VoxelSystem::setUseByteNormals(bool useByteNormals) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&_bufferWriteLock);
|
pthread_mutex_unlock(&_bufferWriteLock);
|
||||||
|
|
||||||
|
if (wasInitialized) {
|
||||||
|
forceRedrawEntireTree();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,12 +170,17 @@ void VoxelSystem::setMaxVoxels(int maxVoxels) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&_bufferWriteLock);
|
pthread_mutex_unlock(&_bufferWriteLock);
|
||||||
|
|
||||||
|
if (wasInitialized) {
|
||||||
|
forceRedrawEntireTree();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::setUseVoxelShader(bool useVoxelShader) {
|
void VoxelSystem::setUseVoxelShader(bool useVoxelShader) {
|
||||||
pthread_mutex_lock(&_bufferWriteLock);
|
pthread_mutex_lock(&_bufferWriteLock);
|
||||||
bool wasInitialized = _initialized;
|
bool wasInitialized = _initialized;
|
||||||
if (wasInitialized) {
|
if (wasInitialized) {
|
||||||
|
clearAllNodesBufferIndex();
|
||||||
cleanupVoxelMemory();
|
cleanupVoxelMemory();
|
||||||
}
|
}
|
||||||
_useVoxelShader = useVoxelShader;
|
_useVoxelShader = useVoxelShader;
|
||||||
|
@ -179,6 +188,10 @@ void VoxelSystem::setUseVoxelShader(bool useVoxelShader) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&_bufferWriteLock);
|
pthread_mutex_unlock(&_bufferWriteLock);
|
||||||
|
|
||||||
|
if (wasInitialized) {
|
||||||
|
forceRedrawEntireTree();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::cleanupVoxelMemory() {
|
void VoxelSystem::cleanupVoxelMemory() {
|
||||||
|
@ -266,7 +279,7 @@ void VoxelSystem::initVoxelMemory() {
|
||||||
// populate the normalsArray
|
// populate the normalsArray
|
||||||
for (int n = 0; n < _maxVoxels; n++) {
|
for (int n = 0; n < _maxVoxels; n++) {
|
||||||
for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) {
|
for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) {
|
||||||
*(normalsArrayEndPointer++) = identityNormals[i];
|
*(normalsArrayEndPointer++) = (identityNormals[i] * CHAR_MAX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,20 +763,24 @@ void VoxelSystem::updateNodeInArrays(glBufferIndex nodeIndex, const glm::vec3& s
|
||||||
float voxelScale, const nodeColor& color) {
|
float voxelScale, const nodeColor& color) {
|
||||||
|
|
||||||
if (_useVoxelShader) {
|
if (_useVoxelShader) {
|
||||||
VoxelShaderVBOData* writeVerticesAt = &_writeVoxelShaderData[nodeIndex];
|
if (_writeVoxelShaderData) {
|
||||||
writeVerticesAt->x = startVertex.x * TREE_SCALE;
|
VoxelShaderVBOData* writeVerticesAt = &_writeVoxelShaderData[nodeIndex];
|
||||||
writeVerticesAt->y = startVertex.y * TREE_SCALE;
|
writeVerticesAt->x = startVertex.x * TREE_SCALE;
|
||||||
writeVerticesAt->z = startVertex.z * TREE_SCALE;
|
writeVerticesAt->y = startVertex.y * TREE_SCALE;
|
||||||
writeVerticesAt->s = voxelScale * TREE_SCALE;
|
writeVerticesAt->z = startVertex.z * TREE_SCALE;
|
||||||
writeVerticesAt->r = color[RED_INDEX];
|
writeVerticesAt->s = voxelScale * TREE_SCALE;
|
||||||
writeVerticesAt->g = color[GREEN_INDEX];
|
writeVerticesAt->r = color[RED_INDEX];
|
||||||
writeVerticesAt->b = color[BLUE_INDEX];
|
writeVerticesAt->g = color[GREEN_INDEX];
|
||||||
|
writeVerticesAt->b = color[BLUE_INDEX];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) {
|
if (_writeVerticesArray && _writeColorsArray) {
|
||||||
GLfloat* writeVerticesAt = _writeVerticesArray + (nodeIndex * VERTEX_POINTS_PER_VOXEL);
|
for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) {
|
||||||
GLubyte* writeColorsAt = _writeColorsArray + (nodeIndex * VERTEX_POINTS_PER_VOXEL);
|
GLfloat* writeVerticesAt = _writeVerticesArray + (nodeIndex * VERTEX_POINTS_PER_VOXEL);
|
||||||
*(writeVerticesAt+j) = startVertex[j % 3] + (identityVertices[j] * voxelScale);
|
GLubyte* writeColorsAt = _writeColorsArray + (nodeIndex * VERTEX_POINTS_PER_VOXEL);
|
||||||
*(writeColorsAt +j) = color[j % 3];
|
*(writeVerticesAt+j) = startVertex[j % 3] + (identityVertices[j] * voxelScale);
|
||||||
|
*(writeColorsAt +j) = color[j % 3];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -995,6 +1012,34 @@ void VoxelSystem::killLocalVoxels() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool VoxelSystem::clearAllNodesBufferIndexOperation(VoxelNode* node, void* extraData) {
|
||||||
|
_nodeCount++;
|
||||||
|
node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoxelSystem::clearAllNodesBufferIndex() {
|
||||||
|
_nodeCount = 0;
|
||||||
|
_tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation);
|
||||||
|
qDebug("clearing buffer index of %d nodes\n", _nodeCount);
|
||||||
|
_tree->setDirtyBit();
|
||||||
|
setupNewVoxelsForDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VoxelSystem::forceRedrawEntireTreeOperation(VoxelNode* node, void* extraData) {
|
||||||
|
_nodeCount++;
|
||||||
|
node->setDirtyBit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoxelSystem::forceRedrawEntireTree() {
|
||||||
|
_nodeCount = 0;
|
||||||
|
_tree->recurseTreeWithOperation(forceRedrawEntireTreeOperation);
|
||||||
|
qDebug("forcing redraw of %d nodes\n", _nodeCount);
|
||||||
|
_tree->setDirtyBit();
|
||||||
|
setupNewVoxelsForDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
bool VoxelSystem::randomColorOperation(VoxelNode* node, void* extraData) {
|
bool VoxelSystem::randomColorOperation(VoxelNode* node, void* extraData) {
|
||||||
_nodeCount++;
|
_nodeCount++;
|
||||||
if (node->isColored()) {
|
if (node->isColored()) {
|
||||||
|
|
|
@ -126,6 +126,8 @@ public slots:
|
||||||
void falseColorizeOccluded();
|
void falseColorizeOccluded();
|
||||||
void falseColorizeOccludedV2();
|
void falseColorizeOccludedV2();
|
||||||
void falseColorizeBySource();
|
void falseColorizeBySource();
|
||||||
|
void forceRedrawEntireTree();
|
||||||
|
void clearAllNodesBufferIndex();
|
||||||
|
|
||||||
void cancelImport();
|
void cancelImport();
|
||||||
void setUseByteNormals(bool useByteNormals);
|
void setUseByteNormals(bool useByteNormals);
|
||||||
|
@ -172,6 +174,8 @@ private:
|
||||||
static bool falseColorizeOccludedV2Operation(VoxelNode* node, void* extraData);
|
static bool falseColorizeOccludedV2Operation(VoxelNode* node, void* extraData);
|
||||||
static bool falseColorizeBySourceOperation(VoxelNode* node, void* extraData);
|
static bool falseColorizeBySourceOperation(VoxelNode* node, void* extraData);
|
||||||
static bool killSourceVoxelsOperation(VoxelNode* node, void* extraData);
|
static bool killSourceVoxelsOperation(VoxelNode* node, void* extraData);
|
||||||
|
static bool forceRedrawEntireTreeOperation(VoxelNode* node, void* extraData);
|
||||||
|
static bool clearAllNodesBufferIndexOperation(VoxelNode* node, void* extraData);
|
||||||
|
|
||||||
int updateNodeInArraysAsFullVBO(VoxelNode* node);
|
int updateNodeInArraysAsFullVBO(VoxelNode* node);
|
||||||
int updateNodeInArraysAsPartialVBO(VoxelNode* node);
|
int updateNodeInArraysAsPartialVBO(VoxelNode* node);
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
void printDebugDetails(const char* label) const;
|
void printDebugDetails(const char* label) const;
|
||||||
bool isDirty() const { return _isDirty; }
|
bool isDirty() const { return _isDirty; }
|
||||||
void clearDirtyBit() { _isDirty = false; }
|
void clearDirtyBit() { _isDirty = false; }
|
||||||
|
void setDirtyBit() { _isDirty = true; }
|
||||||
bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); }
|
bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); }
|
||||||
void markWithChangedTime() { _lastChanged = usecTimestampNow(); }
|
void markWithChangedTime() { _lastChanged = usecTimestampNow(); }
|
||||||
uint64_t getLastChanged() const { return _lastChanged; }
|
uint64_t getLastChanged() const { return _lastChanged; }
|
||||||
|
|
Loading…
Reference in a new issue