Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -56,12 +56,50 @@ MetavoxelSystem::~MetavoxelSystem() { · 55 unmodified lines | |||
| 56 | 56 | ||
| 57 | void MetavoxelSystem::init() { | 57 | void MetavoxelSystem::init() { |
| 58 | MetavoxelClientManager::init(); | 58 | MetavoxelClientManager::init(); |
| 59 | DefaultMetavoxelRendererImplementation::init(); | ||
| 60 | 59 | ||
| 61 | _voxelBufferAttribute = AttributeRegistry::getInstance()->registerAttribute( | 60 | _voxelBufferAttribute = AttributeRegistry::getInstance()->registerAttribute( |
| 62 | new BufferDataAttribute("voxelBuffer")); | 61 | new BufferDataAttribute("voxelBuffer")); |
| 63 | _voxelBufferAttribute->setLODThresholdMultiplier( | 62 | _voxelBufferAttribute->setLODThresholdMultiplier( |
| 64 | AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier()); | 63 | AttributeRegistry::getInstance()->getVoxelColorAttribute()->getLODThresholdMultiplier()); |
| 64 | |||
| 65 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 66 | "shaders/metavoxel_heightfield_base.vert"); | ||
| 67 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 68 | "shaders/metavoxel_heightfield_base.frag"); | ||
| 69 | _baseHeightfieldProgram.link(); | ||
| 70 | |||
| 71 | _baseHeightfieldProgram.bind(); | ||
| 72 | _baseHeightfieldProgram.setUniformValue("heightMap", 0); | ||
| 73 | _baseHeightfieldProgram.setUniformValue("diffuseMap", 1); | ||
| 74 | _baseHeightScaleLocation = _baseHeightfieldProgram.uniformLocation("heightScale"); | ||
| 75 | _baseColorScaleLocation = _baseHeightfieldProgram.uniformLocation("colorScale"); | ||
| 76 | _baseHeightfieldProgram.release(); | ||
| 77 | |||
| 78 | loadSplatProgram("heightfield", _splatHeightfieldProgram, _splatHeightfieldLocations); | ||
| 79 | |||
| 80 | _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 81 | "shaders/metavoxel_heightfield_cursor.vert"); | ||
| 82 | _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 83 | "shaders/metavoxel_cursor.frag"); | ||
| 84 | _heightfieldCursorProgram.link(); | ||
| 85 | |||
| 86 | _heightfieldCursorProgram.bind(); | ||
| 87 | _heightfieldCursorProgram.setUniformValue("heightMap", 0); | ||
| 88 | _heightfieldCursorProgram.release(); | ||
| 89 | |||
| 90 | _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 91 | "shaders/metavoxel_voxel_base.vert"); | ||
| 92 | _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 93 | "shaders/metavoxel_voxel_base.frag"); | ||
| 94 | _baseVoxelProgram.link(); | ||
| 95 | |||
| 96 | loadSplatProgram("voxel", _splatVoxelProgram, _splatVoxelLocations); | ||
| 97 | |||
| 98 | _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 99 | "shaders/metavoxel_voxel_cursor.vert"); | ||
| 100 | _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 101 | "shaders/metavoxel_cursor.frag"); | ||
| 102 | _voxelCursorProgram.link(); | ||
| 65 | } | 103 | } |
| 66 | 104 | ||
| 67 | MetavoxelLOD MetavoxelSystem::getLOD() { | 105 | MetavoxelLOD MetavoxelSystem::getLOD() { |
| @@ -175,7 +213,7 @@ void MetavoxelSystem::render() { · 107 unmodified lines | |||
| 175 | 213 | ||
| 176 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | 214 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |
| 177 | 215 | ||
| 178 | DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind(); | 216 | _baseHeightfieldProgram.bind(); |
| 179 | 217 | ||
| 180 | foreach (const HeightfieldBaseBatch& batch, _heightfieldBaseBatches) { | 218 | foreach (const HeightfieldBaseBatch& batch, _heightfieldBaseBatches) { |
| 181 | glPushMatrix(); | 219 | glPushMatrix(); |
| @@ -193,10 +231,8 @@ void MetavoxelSystem::render() { · 11 unmodified lines | |||
| 193 | 231 | ||
| 194 | glBindTexture(GL_TEXTURE_2D, batch.heightTextureID); | 232 | glBindTexture(GL_TEXTURE_2D, batch.heightTextureID); |
| 195 | 233 | ||
| 196 | DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniform( | 234 | _baseHeightfieldProgram.setUniform(_baseHeightScaleLocation, batch.heightScale); |
| 197 | DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), batch.heightScale); | 235 | _baseHeightfieldProgram.setUniform(_baseColorScaleLocation, batch.colorScale); |
| 198 | DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniform( | ||
| 199 | DefaultMetavoxelRendererImplementation::getBaseColorScaleLocation(), batch.colorScale); | ||
| 200 | 236 | ||
| 201 | glActiveTexture(GL_TEXTURE1); | 237 | glActiveTexture(GL_TEXTURE1); |
| 202 | glBindTexture(GL_TEXTURE_2D, batch.colorTextureID); | 238 | glBindTexture(GL_TEXTURE_2D, batch.colorTextureID); |
| @@ -208,12 +244,15 @@ void MetavoxelSystem::render() { · 5 unmodified lines | |||
| 208 | glActiveTexture(GL_TEXTURE0); | 244 | glActiveTexture(GL_TEXTURE0); |
| 209 | glBindTexture(GL_TEXTURE_2D, 0); | 245 | glBindTexture(GL_TEXTURE_2D, 0); |
| 210 | 246 | ||
| 247 | batch.vertexBuffer->release(); | ||
| 248 | batch.indexBuffer->release(); | ||
| 249 | |||
| 211 | glPopMatrix(); | 250 | glPopMatrix(); |
| 212 | } | 251 | } |
| 213 | 252 | ||
| 214 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false); | 253 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false); |
| 215 | 254 | ||
| 216 | DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().release(); | 255 | _baseHeightfieldProgram.release(); |
| 217 | 256 | ||
| 218 | glDisable(GL_ALPHA_TEST); | 257 | glDisable(GL_ALPHA_TEST); |
| 219 | glEnable(GL_BLEND); | 258 | glEnable(GL_BLEND); |
| @@ -224,10 +263,8 @@ void MetavoxelSystem::render() { · 4 unmodified lines | |||
| 224 | glEnable(GL_POLYGON_OFFSET_FILL); | 263 | glEnable(GL_POLYGON_OFFSET_FILL); |
| 225 | glPolygonOffset(-1.0f, -1.0f); | 264 | glPolygonOffset(-1.0f, -1.0f); |
| 226 | 265 | ||
| 227 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().bind(); | 266 | _splatHeightfieldProgram.bind(); |
| 228 | const DefaultMetavoxelRendererImplementation::SplatLocations& locations = | 267 | |
| 229 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldLocations(); | ||
| 230 | |||
| 231 | foreach (const HeightfieldSplatBatch& batch, _heightfieldSplatBatches) { | 268 | foreach (const HeightfieldSplatBatch& batch, _heightfieldSplatBatches) { |
| 232 | glPushMatrix(); | 269 | glPushMatrix(); |
| 233 | glTranslatef(batch.translation.x, batch.translation.y, batch.translation.z); | 270 | glTranslatef(batch.translation.x, batch.translation.y, batch.translation.z); |
| @@ -244,26 +281,22 @@ void MetavoxelSystem::render() { · 10 unmodified lines | |||
| 244 | 281 | ||
| 245 | glBindTexture(GL_TEXTURE_2D, batch.heightTextureID); | 282 | glBindTexture(GL_TEXTURE_2D, batch.heightTextureID); |
| 246 | 283 | ||
| 247 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( | 284 | _splatHeightfieldProgram.setUniformValue(_splatHeightfieldLocations.heightScale, |
| 248 | locations.heightScale, batch.heightScale.x, batch.heightScale.y); | 285 | batch.heightScale.x, batch.heightScale.y); |
| 249 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniform( | 286 | _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.textureScale, batch.textureScale); |
| 250 | locations.textureScale, batch.textureScale); | 287 | _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureOffset, batch.splatTextureOffset); |
| 251 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniform(locations.splatTextureOffset, | ||
| 252 | batch.splatTextureOffset); | ||
| 253 | 288 | ||
| 254 | const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL; | 289 | const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL; |
| 255 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniform( | 290 | _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesS, batch.splatTextureScalesS); |
| 256 | locations.splatTextureScalesS, batch.splatTextureScalesS); | 291 | _splatHeightfieldProgram.setUniform(_splatHeightfieldLocations.splatTextureScalesT, batch.splatTextureScalesT); |
| 257 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniform( | 292 | _splatHeightfieldProgram.setUniformValue( |
| 258 | locations.splatTextureScalesT, batch.splatTextureScalesT); | 293 | _splatHeightfieldLocations.textureValueMinima, |
| 259 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( | ||
| 260 | locations.textureValueMinima, | ||
| 261 | (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, | 294 | (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, |
| 262 | (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, | 295 | (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, |
| 263 | (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, | 296 | (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, |
| 264 | (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP); | 297 | (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP); |
| 265 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().setUniformValue( | 298 | _splatHeightfieldProgram.setUniformValue( |
| 266 | locations.textureValueMaxima, | 299 | _splatHeightfieldLocations.textureValueMaxima, |
| 267 | (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, | 300 | (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, |
| 268 | (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, | 301 | (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, |
| 269 | (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, | 302 | (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, |
| @@ -290,10 +323,13 @@ void MetavoxelSystem::render() { · 20 unmodified lines | |||
| 290 | glActiveTexture(GL_TEXTURE0); | 323 | glActiveTexture(GL_TEXTURE0); |
| 291 | glBindTexture(GL_TEXTURE_2D, 0); | 324 | glBindTexture(GL_TEXTURE_2D, 0); |
| 292 | 325 | ||
| 326 | batch.vertexBuffer->release(); | ||
| 327 | batch.indexBuffer->release(); | ||
| 328 | |||
| 293 | glPopMatrix(); | 329 | glPopMatrix(); |
| 294 | } | 330 | } |
| 295 | 331 | ||
| 296 | DefaultMetavoxelRendererImplementation::getSplatHeightfieldProgram().release(); | 332 | _splatHeightfieldProgram.release(); |
| 297 | 333 | ||
| 298 | glDisable(GL_POLYGON_OFFSET_FILL); | 334 | glDisable(GL_POLYGON_OFFSET_FILL); |
| 299 | glDepthMask(true); | 335 | glDepthMask(true); |
| @@ -310,6 +346,121 @@ void MetavoxelSystem::render() { · 10 unmodified lines | |||
| 310 | _heightfieldBaseBatches.clear(); | 346 | _heightfieldBaseBatches.clear(); |
| 311 | } | 347 | } |
| 312 | 348 | ||
| 349 | if (!_voxelBaseBatches.isEmpty()) { | ||
| 350 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true); | ||
| 351 | |||
| 352 | glEnableClientState(GL_VERTEX_ARRAY); | ||
| 353 | glDisable(GL_BLEND); | ||
| 354 | glEnable(GL_CULL_FACE); | ||
| 355 | glEnable(GL_ALPHA_TEST); | ||
| 356 | glAlphaFunc(GL_EQUAL, 0.0f); | ||
| 357 | |||
| 358 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||
| 359 | |||
| 360 | glEnableClientState(GL_COLOR_ARRAY); | ||
| 361 | glEnableClientState(GL_NORMAL_ARRAY); | ||
| 362 | |||
| 363 | _baseVoxelProgram.bind(); | ||
| 364 | |||
| 365 | foreach (const VoxelBaseBatch& batch, _voxelBaseBatches) { | ||
| 366 | batch.vertexBuffer->bind(); | ||
| 367 | batch.indexBuffer->bind(); | ||
| 368 | |||
| 369 | VoxelPoint* point = 0; | ||
| 370 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex); | ||
| 371 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VoxelPoint), &point->color); | ||
| 372 | glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal); | ||
| 373 | |||
| 374 | glDrawRangeElements(GL_QUADS, 0, batch.vertexCount - 1, batch.indexCount, GL_UNSIGNED_INT, 0); | ||
| 375 | |||
| 376 | batch.vertexBuffer->release(); | ||
| 377 | batch.indexBuffer->release(); | ||
| 378 | } | ||
| 379 | |||
| 380 | _baseVoxelProgram.release(); | ||
| 381 | |||
| 382 | glDisable(GL_ALPHA_TEST); | ||
| 383 | glEnable(GL_BLEND); | ||
| 384 | |||
| 385 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false); | ||
| 386 | |||
| 387 | if (!_voxelSplatBatches.isEmpty()) { | ||
| 388 | glDepthFunc(GL_LEQUAL); | ||
| 389 | glDepthMask(false); | ||
| 390 | glEnable(GL_POLYGON_OFFSET_FILL); | ||
| 391 | glPolygonOffset(-1.0f, -1.0f); | ||
| 392 | |||
| 393 | _splatVoxelProgram.bind(); | ||
| 394 | |||
| 395 | _splatVoxelProgram.enableAttributeArray(_splatVoxelLocations.materials); | ||
| 396 | _splatVoxelProgram.enableAttributeArray(_splatVoxelLocations.materialWeights); | ||
| 397 | |||
| 398 | foreach (const VoxelSplatBatch& batch, _voxelSplatBatches) { | ||
| 399 | batch.vertexBuffer->bind(); | ||
| 400 | batch.indexBuffer->bind(); | ||
| 401 | |||
| 402 | VoxelPoint* point = 0; | ||
| 403 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex); | ||
| 404 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VoxelPoint), &point->color); | ||
| 405 | glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal); | ||
| 406 | |||
| 407 | _splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materials, | ||
| 408 | GL_UNSIGNED_BYTE, (qint64)&point->materials, SPLAT_COUNT, sizeof(VoxelPoint)); | ||
| 409 | _splatVoxelProgram.setAttributeBuffer(_splatVoxelLocations.materialWeights, | ||
| 410 | GL_UNSIGNED_BYTE, (qint64)&point->materialWeights, SPLAT_COUNT, sizeof(VoxelPoint)); | ||
| 411 | |||
| 412 | const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL; | ||
| 413 | _splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesS, batch.splatTextureScalesS); | ||
| 414 | _splatVoxelProgram.setUniform(_splatVoxelLocations.splatTextureScalesT, batch.splatTextureScalesT); | ||
| 415 | _splatVoxelProgram.setUniformValue( | ||
| 416 | _splatVoxelLocations.textureValueMinima, | ||
| 417 | (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, | ||
| 418 | (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, | ||
| 419 | (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, | ||
| 420 | (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP); | ||
| 421 | _splatVoxelProgram.setUniformValue( | ||
| 422 | _splatVoxelLocations.textureValueMaxima, | ||
| 423 | (batch.materialIndex + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, | ||
| 424 | (batch.materialIndex + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, | ||
| 425 | (batch.materialIndex + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, | ||
| 426 | (batch.materialIndex + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP); | ||
| 427 | |||
| 428 | for (int i = 0; i < SPLAT_COUNT; i++) { | ||
| 429 | glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]); | ||
| 430 | glBindTexture(GL_TEXTURE_2D, batch.splatTextureIDs[i]); | ||
| 431 | } | ||
| 432 | |||
| 433 | glDrawRangeElements(GL_QUADS, 0, batch.vertexCount - 1, batch.indexCount, GL_UNSIGNED_INT, 0); | ||
| 434 | |||
| 435 | for (int i = 0; i < SPLAT_COUNT; i++) { | ||
| 436 | glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]); | ||
| 437 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 438 | } | ||
| 439 | |||
| 440 | glActiveTexture(GL_TEXTURE0); | ||
| 441 | |||
| 442 | batch.vertexBuffer->release(); | ||
| 443 | batch.indexBuffer->release(); | ||
| 444 | } | ||
| 445 | |||
| 446 | glDisable(GL_POLYGON_OFFSET_FILL); | ||
| 447 | glDepthMask(true); | ||
| 448 | glDepthFunc(GL_LESS); | ||
| 449 | |||
| 450 | _splatVoxelProgram.disableAttributeArray(_splatVoxelLocations.materials); | ||
| 451 | _splatVoxelProgram.disableAttributeArray(_splatVoxelLocations.materialWeights); | ||
| 452 | |||
| 453 | _voxelSplatBatches.clear(); | ||
| 454 | } | ||
| 455 | |||
| 456 | glDisableClientState(GL_VERTEX_ARRAY); | ||
| 457 | glDisableClientState(GL_COLOR_ARRAY); | ||
| 458 | glDisableClientState(GL_NORMAL_ARRAY); | ||
| 459 | glDisable(GL_CULL_FACE); | ||
| 460 | |||
| 461 | _voxelBaseBatches.clear(); | ||
| 462 | } | ||
| 463 | |||
| 313 | // give external parties a chance to join in | 464 | // give external parties a chance to join in |
| 314 | emit rendering(); | 465 | emit rendering(); |
| 315 | } | 466 | } |
| @@ -440,7 +591,7 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 124 unmodified lines | |||
| 440 | glEnableClientState(GL_VERTEX_ARRAY); | 591 | glEnableClientState(GL_VERTEX_ARRAY); |
| 441 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 592 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 442 | 593 | ||
| 443 | DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().bind(); | 594 | _heightfieldCursorProgram.bind(); |
| 444 | 595 | ||
| 445 | glActiveTexture(GL_TEXTURE4); | 596 | glActiveTexture(GL_TEXTURE4); |
| 446 | float scale = 1.0f / radius; | 597 | float scale = 1.0f / radius; |
| @@ -456,7 +607,7 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 9 unmodified lines | |||
| 456 | SpannerCursorRenderVisitor visitor(Box(position - extents, position + extents)); | 607 | SpannerCursorRenderVisitor visitor(Box(position - extents, position + extents)); |
| 457 | guide(visitor); | 608 | guide(visitor); |
| 458 | 609 | ||
| 459 | DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().release(); | 610 | _heightfieldCursorProgram.release(); |
| 460 | 611 | ||
| 461 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | 612 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 462 | glDisableClientState(GL_VERTEX_ARRAY); | 613 | glDisableClientState(GL_VERTEX_ARRAY); |
| @@ -504,7 +655,7 @@ void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius) · 41 unmodified lines | |||
| 504 | 655 | ||
| 505 | glEnableClientState(GL_VERTEX_ARRAY); | 656 | glEnableClientState(GL_VERTEX_ARRAY); |
| 506 | 657 | ||
| 507 | DefaultMetavoxelRendererImplementation::getVoxelCursorProgram().bind(); | 658 | _voxelCursorProgram.bind(); |
| 508 | 659 | ||
| 509 | glActiveTexture(GL_TEXTURE4); | 660 | glActiveTexture(GL_TEXTURE4); |
| 510 | float scale = 1.0f / radius; | 661 | float scale = 1.0f / radius; |
| @@ -521,16 +672,16 @@ void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius) · 10 unmodified lines | |||
| 521 | BufferCursorRenderVisitor voxelVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), bounds); | 672 | BufferCursorRenderVisitor voxelVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), bounds); |
| 522 | guideToAugmented(voxelVisitor); | 673 | guideToAugmented(voxelVisitor); |
| 523 | 674 | ||
| 524 | DefaultMetavoxelRendererImplementation::getVoxelCursorProgram().release(); | 675 | _voxelCursorProgram.release(); |
| 525 | 676 | ||
| 526 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 677 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 527 | 678 | ||
| 528 | DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().bind(); | 679 | _heightfieldCursorProgram.bind(); |
| 529 | 680 | ||
| 530 | SpannerCursorRenderVisitor spannerVisitor(bounds); | 681 | SpannerCursorRenderVisitor spannerVisitor(bounds); |
| 531 | guide(spannerVisitor); | 682 | guide(spannerVisitor); |
| 532 | 683 | ||
| 533 | DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().release(); | 684 | _heightfieldCursorProgram.release(); |
| 534 | 685 | ||
| 535 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | 686 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 536 | 687 | ||
| @@ -612,6 +763,29 @@ void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) { · 75 unmodified lines | |||
| 612 | } | 763 | } |
| 613 | } | 764 | } |
| 614 | 765 | ||
| 766 | void MetavoxelSystem::loadSplatProgram(const char* type, ProgramObject& program, SplatLocations& locations) { | ||
| 767 | program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 768 | "shaders/metavoxel_" + type + "_splat.vert"); | ||
| 769 | program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 770 | "shaders/metavoxel_" + type + "_splat.frag"); | ||
| 771 | program.link(); | ||
| 772 | |||
| 773 | program.bind(); | ||
| 774 | program.setUniformValue("heightMap", 0); | ||
| 775 | program.setUniformValue("textureMap", 1); | ||
| 776 | program.setUniformValueArray("diffuseMaps", SPLAT_TEXTURE_UNITS, SPLAT_COUNT); | ||
| 777 | locations.heightScale = program.uniformLocation("heightScale"); | ||
| 778 | locations.textureScale = program.uniformLocation("textureScale"); | ||
| 779 | locations.splatTextureOffset = program.uniformLocation("splatTextureOffset"); | ||
| 780 | locations.splatTextureScalesS = program.uniformLocation("splatTextureScalesS"); | ||
| 781 | locations.splatTextureScalesT = program.uniformLocation("splatTextureScalesT"); | ||
| 782 | locations.textureValueMinima = program.uniformLocation("textureValueMinima"); | ||
| 783 | locations.textureValueMaxima = program.uniformLocation("textureValueMaxima"); | ||
| 784 | locations.materials = program.attributeLocation("materials"); | ||
| 785 | locations.materialWeights = program.attributeLocation("materialWeights"); | ||
| 786 | program.release(); | ||
| 787 | } | ||
| 788 | |||
| 615 | Throttle::Throttle() : | 789 | Throttle::Throttle() : |
| 616 | _limit(INT_MAX), | 790 | _limit(INT_MAX), |
| 617 | _total(0) { | 791 | _total(0) { |
| @@ -946,10 +1120,12 @@ void VoxelBuffer::render(bool cursor) { · 328 unmodified lines | |||
| 946 | _vertexBuffer.create(); | 1120 | _vertexBuffer.create(); |
| 947 | _vertexBuffer.bind(); | 1121 | _vertexBuffer.bind(); |
| 948 | _vertexBuffer.allocate(_vertices.constData(), _vertices.size() * sizeof(VoxelPoint)); | 1122 | _vertexBuffer.allocate(_vertices.constData(), _vertices.size() * sizeof(VoxelPoint)); |
| 1123 | _vertexBuffer.release(); | ||
| 949 | 1124 | ||
| 950 | _indexBuffer.create(); | 1125 | _indexBuffer.create(); |
| 951 | _indexBuffer.bind(); | 1126 | _indexBuffer.bind(); |
| 952 | _indexBuffer.allocate(_indices.constData(), _indices.size() * sizeof(int)); | 1127 | _indexBuffer.allocate(_indices.constData(), _indices.size() * sizeof(int)); |
| 1128 | _indexBuffer.release(); | ||
| 953 | 1129 | ||
| 954 | if (!_materials.isEmpty()) { | 1130 | if (!_materials.isEmpty()) { |
| 955 | _networkTextures.resize(_materials.size()); | 1131 | _networkTextures.resize(_materials.size()); |
| @@ -961,101 +1137,62 @@ void VoxelBuffer::render(bool cursor) { · 5 unmodified lines | |||
| 961 | } | 1137 | } |
| 962 | } | 1138 | } |
| 963 | } | 1139 | } |
| 964 | } else { | 1140 | } |
| 1141 | |||
| 1142 | if (cursor) { | ||
| 965 | _vertexBuffer.bind(); | 1143 | _vertexBuffer.bind(); |
| 966 | _indexBuffer.bind(); | 1144 | _indexBuffer.bind(); |
| 1145 | |||
| 1146 | VoxelPoint* point = 0; | ||
| 1147 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex); | ||
| 1148 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VoxelPoint), &point->color); | ||
| 1149 | glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal); | ||
| 1150 | |||
| 1151 | glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0); | ||
| 1152 | |||
| 1153 | _vertexBuffer.release(); | ||
| 1154 | _indexBuffer.release(); | ||
| 1155 | return; | ||
| 967 | } | 1156 | } |
| 968 | 1157 | ||
| 969 | VoxelPoint* point = 0; | 1158 | VoxelBaseBatch baseBatch; |
| 970 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex); | 1159 | baseBatch.vertexBuffer = &_vertexBuffer; |
| 971 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VoxelPoint), &point->color); | 1160 | baseBatch.indexBuffer = &_indexBuffer; |
| 972 | glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal); | 1161 | baseBatch.vertexCount = _vertexCount; |
| 1162 | baseBatch.indexCount = _indexCount; | ||
| 1163 | Application::getInstance()->getMetavoxels()->addVoxelBaseBatch(baseBatch); | ||
| 973 | 1164 | ||
| 974 | glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0); | 1165 | if (!_materials.isEmpty()) { |
| 1166 | VoxelSplatBatch splatBatch; | ||
| 1167 | splatBatch.vertexBuffer = &_vertexBuffer; | ||
| 1168 | splatBatch.indexBuffer = &_indexBuffer; | ||
| 1169 | splatBatch.vertexCount = _vertexCount; | ||
| 1170 | splatBatch.indexCount = _indexCount; | ||
| 975 | 1171 | ||
| 976 | if (!(_materials.isEmpty() || cursor)) { | ||
| 977 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false); | ||
| 978 | |||
| 979 | glDepthFunc(GL_LEQUAL); | ||
| 980 | glDepthMask(false); | ||
| 981 | glEnable(GL_BLEND); | ||
| 982 | glDisable(GL_ALPHA_TEST); | ||
| 983 | glEnable(GL_POLYGON_OFFSET_FILL); | ||
| 984 | glPolygonOffset(-1.0f, -1.0f); | ||
| 985 | |||
| 986 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().bind(); | ||
| 987 | const DefaultMetavoxelRendererImplementation::SplatLocations& locations = | ||
| 988 | DefaultMetavoxelRendererImplementation::getSplatVoxelLocations(); | ||
| 989 | |||
| 990 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setAttributeBuffer(locations.materials, | ||
| 991 | GL_UNSIGNED_BYTE, (qint64)&point->materials, SPLAT_COUNT, sizeof(VoxelPoint)); | ||
| 992 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().enableAttributeArray(locations.materials); | ||
| 993 | |||
| 994 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setAttributeBuffer(locations.materialWeights, | ||
| 995 | GL_UNSIGNED_BYTE, (qint64)&point->materialWeights, SPLAT_COUNT, sizeof(VoxelPoint)); | ||
| 996 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().enableAttributeArray(locations.materialWeights); | ||
| 997 | |||
| 998 | for (int i = 0; i < _materials.size(); i += SPLAT_COUNT) { | 1172 | for (int i = 0; i < _materials.size(); i += SPLAT_COUNT) { |
| 999 | QVector4D scalesS, scalesT; | ||
| 1000 | |||
| 1001 | for (int j = 0; j < SPLAT_COUNT; j++) { | 1173 | for (int j = 0; j < SPLAT_COUNT; j++) { |
| 1002 | glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[j]); | ||
| 1003 | int index = i + j; | 1174 | int index = i + j; |
| 1004 | if (index < _networkTextures.size()) { | 1175 | if (index < _networkTextures.size()) { |
| 1005 | const NetworkTexturePointer& texture = _networkTextures.at(index); | 1176 | const NetworkTexturePointer& texture = _networkTextures.at(index); |
| 1006 | if (texture) { | 1177 | if (texture) { |
| 1007 | MaterialObject* material = static_cast<MaterialObject*>(_materials.at(index).data()); | 1178 | MaterialObject* material = static_cast<MaterialObject*>(_materials.at(index).data()); |
| 1008 | scalesS[j] = 1.0f / material->getScaleS(); | 1179 | splatBatch.splatTextureScalesS[j] = 1.0f / material->getScaleS(); |
| 1009 | scalesT[j] = 1.0f / material->getScaleT(); | 1180 | splatBatch.splatTextureScalesT[j] = 1.0f / material->getScaleT(); |
| 1010 | glBindTexture(GL_TEXTURE_2D, texture->getID()); | 1181 | splatBatch.splatTextureIDs[j] = texture->getID(); |
| 1182 | |||
| 1011 | } else { | 1183 | } else { |
| 1012 | glBindTexture(GL_TEXTURE_2D, 0); | 1184 | splatBatch.splatTextureIDs[j] = 0; |
| 1013 | } | 1185 | } |
| 1014 | } else { | 1186 | } else { |
| 1015 | glBindTexture(GL_TEXTURE_2D, 0); | 1187 | splatBatch.splatTextureIDs[j] = 0; |
| 1016 | } | 1188 | } |
| 1017 | } | 1189 | } |
| 1018 | const float QUARTER_STEP = 0.25f * EIGHT_BIT_MAXIMUM_RECIPROCAL; | 1190 | splatBatch.materialIndex = i; |
| 1019 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setUniformValue( | 1191 | Application::getInstance()->getMetavoxels()->addVoxelSplatBatch(splatBatch); |
| 1020 | locations.splatTextureScalesS, scalesS); | ||
| 1021 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setUniformValue( | ||
| 1022 | locations.splatTextureScalesT, scalesT); | ||
| 1023 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setUniformValue( | ||
| 1024 | locations.textureValueMinima, | ||
| 1025 | (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, | ||
| 1026 | (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL - QUARTER_STEP); | ||
| 1027 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().setUniformValue( | ||
| 1028 | locations.textureValueMaxima, | ||
| 1029 | (i + 1) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 2) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, | ||
| 1030 | (i + 3) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP, (i + 4) * EIGHT_BIT_MAXIMUM_RECIPROCAL + QUARTER_STEP); | ||
| 1031 | glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0); | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | for (int i = 0; i < SPLAT_COUNT; i++) { | ||
| 1035 | glActiveTexture(GL_TEXTURE0 + SPLAT_TEXTURE_UNITS[i]); | ||
| 1036 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 1037 | } | 1192 | } |
| 1038 | |||
| 1039 | glActiveTexture(GL_TEXTURE0); | ||
| 1040 | |||
| 1041 | glDisable(GL_POLYGON_OFFSET_FILL); | ||
| 1042 | glEnable(GL_ALPHA_TEST); | ||
| 1043 | glDisable(GL_BLEND); | ||
| 1044 | glDepthMask(true); | ||
| 1045 | glDepthFunc(GL_LESS); | ||
| 1046 | |||
| 1047 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true); | ||
| 1048 | |||
| 1049 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().disableAttributeArray(locations.materials); | ||
| 1050 | DefaultMetavoxelRendererImplementation::getSplatVoxelProgram().disableAttributeArray(locations.materialWeights); | ||
| 1051 | |||
| 1052 | DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind(); | ||
| 1053 | } | 1193 | } |
| 1054 | 1194 | ||
| 1055 | _vertexBuffer.release(); | 1195 | if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) { |
| 1056 | _indexBuffer.release(); | ||
| 1057 | |||
| 1058 | if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData) && !cursor) { | ||
| 1059 | if (!_hermiteBuffer.isCreated()) { | 1196 | if (!_hermiteBuffer.isCreated()) { |
| 1060 | _hermiteBuffer.create(); | 1197 | _hermiteBuffer.create(); |
| 1061 | _hermiteBuffer.bind(); | 1198 | _hermiteBuffer.bind(); |
| @@ -1066,9 +1203,6 @@ void VoxelBuffer::render(bool cursor) { · 4 unmodified lines | |||
| 1066 | _hermiteBuffer.bind(); | 1203 | _hermiteBuffer.bind(); |
| 1067 | } | 1204 | } |
| 1068 | 1205 | ||
| 1069 | glDisableClientState(GL_COLOR_ARRAY); | ||
| 1070 | glDisableClientState(GL_NORMAL_ARRAY); | ||
| 1071 | |||
| 1072 | glVertexPointer(3, GL_FLOAT, 0, 0); | 1206 | glVertexPointer(3, GL_FLOAT, 0, 0); |
| 1073 | 1207 | ||
| 1074 | Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind(); | 1208 | Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind(); |
| @@ -1080,10 +1214,7 @@ void VoxelBuffer::render(bool cursor) { · 5 unmodified lines | |||
| 1080 | 1214 | ||
| 1081 | glDrawArrays(GL_LINES, 0, _hermiteCount); | 1215 | glDrawArrays(GL_LINES, 0, _hermiteCount); |
| 1082 | 1216 | ||
| 1083 | DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind(); | 1217 | Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().release(); |
| 1084 | |||
| 1085 | glEnableClientState(GL_COLOR_ARRAY); | ||
| 1086 | glEnableClientState(GL_NORMAL_ARRAY); | ||
| 1087 | 1218 | ||
| 1088 | _hermiteBuffer.release(); | 1219 | _hermiteBuffer.release(); |
| 1089 | } | 1220 | } |
| @@ -1107,49 +1238,6 @@ AttributeValue BufferDataAttribute::inherit(const AttributeValue& parentValue) c · 17 unmodified lines | |||
| 1107 | return AttributeValue(parentValue.getAttribute()); | 1238 | return AttributeValue(parentValue.getAttribute()); |
| 1108 | } | 1239 | } |
| 1109 | 1240 | ||
| 1110 | void DefaultMetavoxelRendererImplementation::init() { | ||
| 1111 | if (!_baseHeightfieldProgram.isLinked()) { | ||
| 1112 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 1113 | "shaders/metavoxel_heightfield_base.vert"); | ||
| 1114 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 1115 | "shaders/metavoxel_heightfield_base.frag"); | ||
| 1116 | _baseHeightfieldProgram.link(); | ||
| 1117 | |||
| 1118 | _baseHeightfieldProgram.bind(); | ||
| 1119 | _baseHeightfieldProgram.setUniformValue("heightMap", 0); | ||
| 1120 | _baseHeightfieldProgram.setUniformValue("diffuseMap", 1); | ||
| 1121 | _baseHeightScaleLocation = _baseHeightfieldProgram.uniformLocation("heightScale"); | ||
| 1122 | _baseColorScaleLocation = _baseHeightfieldProgram.uniformLocation("colorScale"); | ||
| 1123 | _baseHeightfieldProgram.release(); | ||
| 1124 | |||
| 1125 | loadSplatProgram("heightfield", _splatHeightfieldProgram, _splatHeightfieldLocations); | ||
| 1126 | |||
| 1127 | _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 1128 | "shaders/metavoxel_heightfield_cursor.vert"); | ||
| 1129 | _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 1130 | "shaders/metavoxel_cursor.frag"); | ||
| 1131 | _heightfieldCursorProgram.link(); | ||
| 1132 | |||
| 1133 | _heightfieldCursorProgram.bind(); | ||
| 1134 | _heightfieldCursorProgram.setUniformValue("heightMap", 0); | ||
| 1135 | _heightfieldCursorProgram.release(); | ||
| 1136 | |||
| 1137 | _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 1138 | "shaders/metavoxel_voxel_base.vert"); | ||
| 1139 | _baseVoxelProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 1140 | "shaders/metavoxel_voxel_base.frag"); | ||
| 1141 | _baseVoxelProgram.link(); | ||
| 1142 | |||
| 1143 | loadSplatProgram("voxel", _splatVoxelProgram, _splatVoxelLocations); | ||
| 1144 | |||
| 1145 | _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 1146 | "shaders/metavoxel_voxel_cursor.vert"); | ||
| 1147 | _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 1148 | "shaders/metavoxel_cursor.frag"); | ||
| 1149 | _voxelCursorProgram.link(); | ||
| 1150 | } | ||
| 1151 | } | ||
| 1152 | |||
| 1153 | DefaultMetavoxelRendererImplementation::DefaultMetavoxelRendererImplementation() { | 1241 | DefaultMetavoxelRendererImplementation::DefaultMetavoxelRendererImplementation() { |
| 1154 | } | 1242 | } |
| 1155 | 1243 | ||
| @@ -1872,76 +1960,12 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 716 unmodified lines | |||
| 1872 | SpannerRenderVisitor spannerRenderVisitor(lod); | 1960 | SpannerRenderVisitor spannerRenderVisitor(lod); |
| 1873 | data.guide(spannerRenderVisitor); | 1961 | data.guide(spannerRenderVisitor); |
| 1874 | } | 1962 | } |
| 1875 | |||
| 1876 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true); | ||
| 1877 | |||
| 1878 | glEnableClientState(GL_VERTEX_ARRAY); | ||
| 1879 | glDisable(GL_BLEND); | ||
| 1880 | glEnable(GL_CULL_FACE); | ||
| 1881 | glEnable(GL_ALPHA_TEST); | ||
| 1882 | glAlphaFunc(GL_EQUAL, 0.0f); | ||
| 1883 | |||
| 1884 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||
| 1885 | |||
| 1886 | if (Menu::getInstance()->isOptionChecked(MenuOption::RenderDualContourSurfaces)) { | 1963 | if (Menu::getInstance()->isOptionChecked(MenuOption::RenderDualContourSurfaces)) { |
| 1887 | glEnableClientState(GL_COLOR_ARRAY); | ||
| 1888 | glEnableClientState(GL_NORMAL_ARRAY); | ||
| 1889 | |||
| 1890 | _baseVoxelProgram.bind(); | ||
| 1891 | |||
| 1892 | BufferRenderVisitor voxelRenderVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute()); | 1964 | BufferRenderVisitor voxelRenderVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute()); |
| 1893 | data.guide(voxelRenderVisitor); | 1965 | data.guide(voxelRenderVisitor); |
| 1894 | |||
| 1895 | _baseVoxelProgram.release(); | ||
| 1896 | |||
| 1897 | glDisableClientState(GL_COLOR_ARRAY); | ||
| 1898 | glDisableClientState(GL_NORMAL_ARRAY); | ||
| 1899 | } | 1966 | } |
| 1900 | |||
| 1901 | glDisable(GL_ALPHA_TEST); | ||
| 1902 | glDisable(GL_CULL_FACE); | ||
| 1903 | glEnable(GL_BLEND); | ||
| 1904 | |||
| 1905 | glDisableClientState(GL_VERTEX_ARRAY); | ||
| 1906 | |||
| 1907 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false); | ||
| 1908 | } | ||
| 1909 | |||
| 1910 | void DefaultMetavoxelRendererImplementation::loadSplatProgram(const char* type, | ||
| 1911 | ProgramObject& program, SplatLocations& locations) { | ||
| 1912 | program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 1913 | "shaders/metavoxel_" + type + "_splat.vert"); | ||
| 1914 | program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 1915 | "shaders/metavoxel_" + type + "_splat.frag"); | ||
| 1916 | program.link(); | ||
| 1917 | |||
| 1918 | program.bind(); | ||
| 1919 | program.setUniformValue("heightMap", 0); | ||
| 1920 | program.setUniformValue("textureMap", 1); | ||
| 1921 | program.setUniformValueArray("diffuseMaps", SPLAT_TEXTURE_UNITS, SPLAT_COUNT); | ||
| 1922 | locations.heightScale = program.uniformLocation("heightScale"); | ||
| 1923 | locations.textureScale = program.uniformLocation("textureScale"); | ||
| 1924 | locations.splatTextureOffset = program.uniformLocation("splatTextureOffset"); | ||
| 1925 | locations.splatTextureScalesS = program.uniformLocation("splatTextureScalesS"); | ||
| 1926 | locations.splatTextureScalesT = program.uniformLocation("splatTextureScalesT"); | ||
| 1927 | locations.textureValueMinima = program.uniformLocation("textureValueMinima"); | ||
| 1928 | locations.textureValueMaxima = program.uniformLocation("textureValueMaxima"); | ||
| 1929 | locations.materials = program.attributeLocation("materials"); | ||
| 1930 | locations.materialWeights = program.attributeLocation("materialWeights"); | ||
| 1931 | program.release(); | ||
| 1932 | } | 1967 | } |
| 1933 | 1968 | ||
| 1934 | ProgramObject DefaultMetavoxelRendererImplementation::_baseHeightfieldProgram; | ||
| 1935 | int DefaultMetavoxelRendererImplementation::_baseHeightScaleLocation; | ||
| 1936 | int DefaultMetavoxelRendererImplementation::_baseColorScaleLocation; | ||
| 1937 | ProgramObject DefaultMetavoxelRendererImplementation::_splatHeightfieldProgram; | ||
| 1938 | DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatHeightfieldLocations; | ||
| 1939 | ProgramObject DefaultMetavoxelRendererImplementation::_heightfieldCursorProgram; | ||
| 1940 | ProgramObject DefaultMetavoxelRendererImplementation::_baseVoxelProgram; | ||
| 1941 | ProgramObject DefaultMetavoxelRendererImplementation::_splatVoxelProgram; | ||
| 1942 | DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatVoxelLocations; | ||
| 1943 | ProgramObject DefaultMetavoxelRendererImplementation::_voxelCursorProgram; | ||
| 1944 | |||
| 1945 | SphereRenderer::SphereRenderer() { | 1969 | SphereRenderer::SphereRenderer() { |
| 1946 | } | 1970 | } |
| 1947 | 1971 | ||