| 51 | } |
| 52 | |
| 53 | void GL46DrawTarget::Enable() |
| 54 | { |
| 55 | // Save the current viewport settings so they can be restored when |
| 56 | // Disable is called. |
| 57 | std::array<GLint, 4> intVals{}; |
| 58 | std::array<GLdouble, 2> doubleVals{}; |
| 59 | glGetIntegerv(GL_VIEWPORT, intVals.data()); |
| 60 | glGetDoublev(GL_DEPTH_RANGE, doubleVals.data()); |
| 61 | mSaveViewportX = intVals[0]; |
| 62 | mSaveViewportY = intVals[1]; |
| 63 | mSaveViewportWidth = intVals[2]; |
| 64 | mSaveViewportHeight = intVals[3]; |
| 65 | mSaveViewportNear = doubleVals[0]; |
| 66 | mSaveViewportFar = doubleVals[1]; |
| 67 | |
| 68 | // Set viewport according to draw target; |
| 69 | auto viewportWidth = static_cast<GLsizei>(mTarget->GetWidth()); |
| 70 | auto viewportHeight = static_cast<GLsizei>(mTarget->GetHeight()); |
| 71 | glViewport(0, 0, viewportWidth, viewportHeight); |
| 72 | |
| 73 | // Set depth range to full. |
| 74 | glDepthRange(0.0, 1.0); |
| 75 | |
| 76 | // Bind the frame buffer. |
| 77 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFrameBuffer); |
| 78 | |
| 79 | // Attach depth buffer if there is one. |
| 80 | if (mDSTexture) |
| 81 | { |
| 82 | uint32_t format = mDSTexture->GetTexture()->GetFormat(); |
| 83 | GLenum attachment{}; |
| 84 | if (format == DF_D24_UNORM_S8_UINT) |
| 85 | { |
| 86 | attachment = GL_DEPTH_STENCIL_ATTACHMENT; |
| 87 | } |
| 88 | else // for now only DF_D24_UNORM_S8_UINT or DF_D32_FLOAT supported |
| 89 | { |
| 90 | attachment = GL_DEPTH_ATTACHMENT; |
| 91 | } |
| 92 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, GL_TEXTURE_2D, mDSTexture->GetGLHandle(), 0); |
| 93 | } |
| 94 | |
| 95 | // Attach each render target. Build list of attachments to use for |
| 96 | // drawing to. |
| 97 | auto const numTargets = mTarget->GetNumTargets(); |
| 98 | std::vector<GLenum> useDrawBuffers(numTargets); |
| 99 | for (uint32_t i = 0; i < numTargets; ++i) |
| 100 | { |
| 101 | auto colorTarget = GL_COLOR_ATTACHMENT0 + i; |
| 102 | |
| 103 | useDrawBuffers[i] = colorTarget; |
| 104 | |
| 105 | auto textureRT = mRTTextures[i]; |
| 106 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, colorTarget, GL_TEXTURE_2D, textureRT->GetGLHandle(), 0); |
| 107 | } |
| 108 | |
| 109 | // Set which draw buffers to use. |
| 110 | glDrawBuffers(static_cast<GLsizei>(useDrawBuffers.size()), useDrawBuffers.data()); |
nothing calls this directly
no test coverage detected