------------------------------------------------------------------------------
| 28 | |
| 29 | //------------------------------------------------------------------------------ |
| 30 | void vtkPBRLUTTexture::Load(vtkRenderer* ren) |
| 31 | { |
| 32 | vtkOpenGLRenderWindow* renWin = vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow()); |
| 33 | if (!renWin) |
| 34 | { |
| 35 | vtkErrorMacro("No render window."); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | if (this->GetMTime() > this->LoadTime.GetMTime()) |
| 40 | { |
| 41 | if (this->TextureObject == nullptr) |
| 42 | { |
| 43 | this->TextureObject = vtkTextureObject::New(); |
| 44 | } |
| 45 | this->TextureObject->SetContext(renWin); |
| 46 | this->TextureObject->SetFormat(GL_RG); |
| 47 | this->TextureObject->SetWrapS(vtkTextureObject::ClampToEdge); |
| 48 | this->TextureObject->SetWrapT(vtkTextureObject::ClampToEdge); |
| 49 | this->TextureObject->SetMinificationFilter(vtkTextureObject::Linear); |
| 50 | this->TextureObject->SetMagnificationFilter(vtkTextureObject::Linear); |
| 51 | #ifdef GL_ES_VERSION_3_0 |
| 52 | this->TextureObject->SetInternalFormat(GL_RG8); |
| 53 | this->TextureObject->SetDataType(GL_UNSIGNED_BYTE); |
| 54 | this->TextureObject->Allocate2D(this->LUTSize, this->LUTSize, 2, VTK_UNSIGNED_CHAR); |
| 55 | #else |
| 56 | this->TextureObject->SetInternalFormat(GL_RG16); |
| 57 | this->TextureObject->SetDataType(GL_UNSIGNED_SHORT); |
| 58 | this->TextureObject->Allocate2D(this->LUTSize, this->LUTSize, 2, VTK_UNSIGNED_SHORT); |
| 59 | #endif |
| 60 | |
| 61 | this->RenderWindow = renWin; |
| 62 | |
| 63 | vtkOpenGLState* state = renWin->GetState(); |
| 64 | vtkOpenGLState::ScopedglViewport svp(state); |
| 65 | vtkOpenGLState::ScopedglEnableDisable sdepth(state, GL_DEPTH_TEST); |
| 66 | vtkOpenGLState::ScopedglEnableDisable sblend(state, GL_BLEND); |
| 67 | vtkOpenGLState::ScopedglEnableDisable sscissor(state, GL_SCISSOR_TEST); |
| 68 | |
| 69 | vtkNew<vtkOpenGLFramebufferObject> fbo; |
| 70 | fbo->SetContext(renWin); |
| 71 | renWin->GetState()->PushFramebufferBindings(); |
| 72 | fbo->Bind(); |
| 73 | |
| 74 | fbo->AddColorAttachment(0, this->TextureObject); |
| 75 | fbo->ActivateDrawBuffers(1); |
| 76 | fbo->Start(this->LUTSize, this->LUTSize); |
| 77 | |
| 78 | std::string FSSource = vtkOpenGLRenderUtilities::GetFullScreenQuadFragmentShaderTemplate(); |
| 79 | |
| 80 | vtkShaderProgram::Substitute(FSSource, "//VTK::FSQ::Decl", |
| 81 | "const float PI = 3.14159265359;\n" |
| 82 | "float RadicalInverse_VdC(uint bits)\n" |
| 83 | "{\n" |
| 84 | " bits = (bits << 16u) | (bits >> 16u);\n" |
| 85 | " bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);\n" |
| 86 | " bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);\n" |
| 87 | " bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);\n" |
nothing calls this directly
no test coverage detected