From b14ff04f76d5fca3897f4ffc457dd6ddfd3c394d Mon Sep 17 00:00:00 2001 From: Michal Marcinkowski Date: Thu, 18 Dec 2014 12:00:27 -0500 Subject: [PATCH] wip - piping projection-to-texture to GPU. --- .../planets/renderableplanetprojection.h | 13 ++--- openspace-data | 2 +- .../planets/renderableplanetprojection.cpp | 51 ++++++++++++------- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/include/openspace/rendering/planets/renderableplanetprojection.h b/include/openspace/rendering/planets/renderableplanetprojection.h index 323ad3a097..44980c7f6a 100644 --- a/include/openspace/rendering/planets/renderableplanetprojection.h +++ b/include/openspace/rendering/planets/renderableplanetprojection.h @@ -24,6 +24,7 @@ #ifndef __RENDERABLEPLANETPROJECTION_H__ #define __RENDERABLEPLANETPROJECTION_H__ +#include // open space includes #include @@ -66,7 +67,6 @@ protected: void updateTex(); private: - void imageProject(); properties::StringProperty _colorTexturePath; @@ -81,17 +81,18 @@ private: glm::dmat3 _stateMatrix; glm::dmat3 _instrumentMatrix; - glm::mat4 _projectorMatrix; - glm::vec3 _boresight; - glm::vec2 _camScaling; - glm::mat4 _transform; - + glm::mat4 _projectorMatrix; + glm::vec3 _boresight; + glm::vec2 _camScaling; + glm::mat4 _transform; double _time; openspace::SceneGraphNode* _targetNode; std::string _target; + // FBO stuff + GLuint _fboID; }; } // namespace openspace diff --git a/openspace-data b/openspace-data index b32f08fe84..6c438c384d 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit b32f08fe84f3bbe28eb73a3196c9f39e59a8d58f +Subproject commit 6c438c384dd74171594e7edcfaa3714bf48b5d33 diff --git a/src/rendering/planets/renderableplanetprojection.cpp b/src/rendering/planets/renderableplanetprojection.cpp index 94ae882c2f..7da0e59555 100644 --- a/src/rendering/planets/renderableplanetprojection.cpp +++ b/src/rendering/planets/renderableplanetprojection.cpp @@ -28,7 +28,7 @@ #include #include -#include +//#include #include #include @@ -137,6 +137,18 @@ bool RenderablePlanetProjection::initialize(){ completeSuccess &= _geometry->initialize(this); + // setup FBO + glGenFramebuffers(1, &_fboID); + glBindFramebuffer(GL_FRAMEBUFFER, _fboID); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *_texture, 0); + // check FBO status + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + completeSuccess &= false; + + // switch back to window-system-provided framebuffer + glBindFramebuffer(GL_FRAMEBUFFER, 0); + return completeSuccess; } @@ -166,11 +178,11 @@ GLuint RenderablePlanetProjection::genComputeProg() { // gl_WorkGroupID is the work group's index const char *csSrc[] = { "#version 440\n", - "writeonly uniform image2D destTex;\ + "layout (binding = 0, rgba32f) uniform image2D destTex;\ layout (local_size_x = 16, local_size_y = 16) in;\ void main() {\ ivec2 storePos = ivec2(gl_GlobalInvocationID.xy);\ - imageStore(destTex, storePos, vec4(1.0,0.0,0.0,1.0));\ + imageStore(destTex, storePos, vec4(1.0,0,0,1.0));\ }" }; @@ -210,22 +222,25 @@ GLuint RenderablePlanetProjection::genComputeProg() { void RenderablePlanetProjection::updateTex(){ glUseProgram(_computeShader); + const GLint location = glGetUniformLocation(_computeShader, "destTex"); // if (location == -1){ printf("Could not locate uniform location for texture in CS"); } - ghoul::opengl::TextureUnit unit; - unit.activate(); + //ghoul::opengl::TextureUnit unit; + //unit.activate(); _texture->bind(); - //glUniform1i(location, unit); //GLint format = _texture->internalFormat(); - //glBindImageTexture(unit, *_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32UI); + //GLint format = _texture->format(); + //glUniform1i(location, 0); + glBindImageTexture(0, *_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F); glDispatchCompute(_texture->width() / 16, _texture->height() / 16, 1); - glUseProgram(0); - printOpenGLError(); + glUseProgram(0); + glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); + printOpenGLError(); } void RenderablePlanetProjection::render(const RenderData& data) @@ -233,6 +248,11 @@ void RenderablePlanetProjection::render(const RenderData& data) if (!_programObject) return; if (!_textureProj) return; + //updateTex(); + + // keep handle to the current bound FBO + GLint defaultFBO; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO); // activate shader _programObject->activate(); @@ -314,15 +334,13 @@ void RenderablePlanetProjection::render(const RenderData& data) _geometry->render(); // disable shader - //updateTex(); - _programObject->deactivate(); - + } void RenderablePlanetProjection::imageProject(){ - _textureProj->downloadTexture(); - _texture->downloadTexture(); + //_textureProj->downloadTexture(); + //_texture->downloadTexture(); auto uvToModel = [](float u, float v, float radius[2], float fsegments)->glm::vec4{ @@ -444,8 +462,8 @@ void RenderablePlanetProjection::imageProject(){ } // Upload textures - //_textureProj->uploadTexture(); - _texture->uploadTexture(); + _textureProj->uploadTexture(); + //_texture->uploadTexture(); } @@ -466,7 +484,6 @@ void RenderablePlanetProjection::loadTexture() if (_texture) { LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'"); _texture->uploadTexture(); - // Textures of planets looks much smoother with AnisotropicMipMap rather than linear _texture->setFilter(ghoul::opengl::Texture::FilterMode::Nearest); }