History

Allow drawing cursor on dual contour surface, wired up material paint tool.

Andrzej Kapolka committed 12 years ago

Commit 60da0f11 parent 1911cfd8 files · +326 −19Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+52−9
@@ -454,10 +454,10 @@ float MetavoxelSystem::getHeightfieldHeight(const glm::vec3& location) { · 453 unmodified lines
454454 return visitor.height;
455455 }
456456
457−class HeightfieldCursorRenderVisitor : public MetavoxelVisitor {
457+class CursorRenderVisitor : public MetavoxelVisitor {
458458 public:
459459
460− HeightfieldCursorRenderVisitor(const Box& bounds);
460+ CursorRenderVisitor(const AttributePointer& attribute, const Box& bounds);
461461
462462 virtual int visit(MetavoxelInfo& info);
463463
@@ -466,13 +466,12 @@ private: · 2 unmodified lines
466466 Box _bounds;
467467 };
468468
469−HeightfieldCursorRenderVisitor::HeightfieldCursorRenderVisitor(const Box& bounds) :
470− MetavoxelVisitor(QVector<AttributePointer>() <<
471− Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute()),
469+CursorRenderVisitor::CursorRenderVisitor(const AttributePointer& attribute, const Box& bounds) :
470+ MetavoxelVisitor(QVector<AttributePointer>() << attribute),
472471 _bounds(bounds) {
473472 }
474473
475−int HeightfieldCursorRenderVisitor::visit(MetavoxelInfo& info) {
474+int CursorRenderVisitor::visit(MetavoxelInfo& info) {
476475 if (!info.getBounds().intersects(_bounds)) {
477476 return STOP_RECURSION;
478477 }
@@ -508,7 +507,8 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 29 unmodified lines
508507 glActiveTexture(GL_TEXTURE0);
509508
510509 glm::vec3 extents(radius, radius, radius);
511− HeightfieldCursorRenderVisitor visitor(Box(position - extents, position + extents));
510+ CursorRenderVisitor visitor(Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(),
511+ Box(position - extents, position + extents));
512512 guideToAugmented(visitor);
513513
514514 DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().release();
@@ -521,6 +521,42 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 6 unmodified lines
521521 glDepthFunc(GL_LESS);
522522 }
523523
524+void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius) {
525+ glDepthFunc(GL_LEQUAL);
526+ glEnable(GL_CULL_FACE);
527+ glEnable(GL_POLYGON_OFFSET_FILL);
528+ glPolygonOffset(-1.0f, -1.0f);
529+
530+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
531+
532+ glEnableClientState(GL_VERTEX_ARRAY);
533+
534+ DefaultMetavoxelRendererImplementation::getVoxelCursorProgram().bind();
535+
536+ glActiveTexture(GL_TEXTURE4);
537+ float scale = 1.0f / radius;
538+ glm::vec4 sCoefficients(scale, 0.0f, 0.0f, -scale * position.x);
539+ glm::vec4 tCoefficients(0.0f, scale, 0.0f, -scale * position.y);
540+ glm::vec4 rCoefficients(0.0f, 0.0f, scale, -scale * position.z);
541+ glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&sCoefficients);
542+ glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&tCoefficients);
543+ glTexGenfv(GL_R, GL_EYE_PLANE, (const GLfloat*)&rCoefficients);
544+ glActiveTexture(GL_TEXTURE0);
545+
546+ glm::vec3 extents(radius, radius, radius);
547+ CursorRenderVisitor visitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(),
548+ Box(position - extents, position + extents));
549+ guideToAugmented(visitor);
550+
551+ DefaultMetavoxelRendererImplementation::getVoxelCursorProgram().release();
552+
553+ glDisableClientState(GL_VERTEX_ARRAY);
554+
555+ glDisable(GL_POLYGON_OFFSET_FILL);
556+ glDisable(GL_CULL_FACE);
557+ glDepthFunc(GL_LESS);
558+}
559+
524560 void MetavoxelSystem::deleteTextures(int heightID, int colorID, int textureID) {
525561 glDeleteTextures(1, (GLuint*)&heightID);
526562 glDeleteTextures(1, (GLuint*)&colorID);
@@ -1170,7 +1206,7 @@ void VoxelBuffer::render(bool cursor) { · 643 unmodified lines
11701206
11711207 glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0);
11721208
1173− if (!_materials.isEmpty()) {
1209+ if (!(_materials.isEmpty() || cursor)) {
11741210 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);
11751211
11761212 glDepthFunc(GL_LEQUAL);
@@ -1252,7 +1288,7 @@ void VoxelBuffer::render(bool cursor) { · 75 unmodified lines
12521288 _vertexBuffer.release();
12531289 _indexBuffer.release();
12541290
1255− if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
1291+ if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData) && !cursor) {
12561292 if (!_hermiteBuffer.isCreated()) {
12571293 _hermiteBuffer.create();
12581294 _hermiteBuffer.bind();
@@ -1348,6 +1384,12 @@ void DefaultMetavoxelRendererImplementation::init() { · 89 unmodified lines
13481384 _baseVoxelProgram.link();
13491385
13501386 loadSplatProgram("voxel", _splatVoxelProgram, _splatVoxelLocations);
1387+
1388+ _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
1389+ "shaders/metavoxel_voxel_cursor.vert");
1390+ _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
1391+ "shaders/metavoxel_voxel_cursor.frag");
1392+ _voxelCursorProgram.link();
13511393 }
13521394 }
13531395
@@ -2577,6 +2619,7 @@ ProgramObject DefaultMetavoxelRendererImplementation::_heightfieldCursorProgram; · 1223 unmodified lines
25772619 ProgramObject DefaultMetavoxelRendererImplementation::_baseVoxelProgram;
25782620 ProgramObject DefaultMetavoxelRendererImplementation::_splatVoxelProgram;
25792621 DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatVoxelLocations;
2622+ProgramObject DefaultMetavoxelRendererImplementation::_voxelCursorProgram;
25802623
25812624 static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {
25822625 GLdouble coefficients[] = { x, y, z, w };