| 159 | } |
| 160 | |
| 161 | void _GFXGLTextureTargetFBOImpl::applyState() |
| 162 | { |
| 163 | // REMINDER: When we implement MRT support, check against GFXGLDevice::getNumRenderTargets() |
| 164 | |
| 165 | PRESERVE_FRAMEBUFFER(); |
| 166 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 167 | glEnable(GL_FRAMEBUFFER_SRGB); |
| 168 | bool drawbufs[16]; |
| 169 | int bufsize = 0; |
| 170 | for (int i = 0; i < 16; i++) |
| 171 | drawbufs[i] = false; |
| 172 | bool hasColor = false; |
| 173 | for(int i = 0; i < GFXGL->getNumRenderTargets(); ++i) |
| 174 | { |
| 175 | _GFXGLTargetDesc* color = mTarget->getTargetDesc( static_cast<GFXTextureTarget::RenderSlot>(GFXTextureTarget::Color0+i )); |
| 176 | if(color) |
| 177 | { |
| 178 | hasColor = true; |
| 179 | const GLenum binding = color->getBinding(); |
| 180 | if( binding == GL_TEXTURE_2D || (binding >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && binding <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) ) |
| 181 | glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, color->getBinding( ), color->getHandle( ), color->getMipLevel( ) ); |
| 182 | else if( binding == GL_TEXTURE_1D ) |
| 183 | glFramebufferTexture1D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, color->getBinding( ), color->getHandle( ), color->getMipLevel( ) ); |
| 184 | else if( binding == GL_TEXTURE_3D ) |
| 185 | glFramebufferTexture3D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, color->getBinding( ), color->getHandle( ), color->getMipLevel( ), color->getZOffset( ) ); |
| 186 | else |
| 187 | Con::errorf("_GFXGLTextureTargetFBOImpl::applyState - Bad binding"); |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | // Clears the texture (note that the binding is irrelevent) |
| 192 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, GL_TEXTURE_2D, 0, 0); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | _GFXGLTargetDesc* depthStecil = mTarget->getTargetDesc(GFXTextureTarget::DepthStencil); |
| 197 | if(depthStecil) |
| 198 | { |
| 199 | // Certain drivers have issues with depth only FBOs. That and the next two asserts assume we have a color target. |
| 200 | AssertFatal(hasColor, "GFXGLTextureTarget::applyState() - Cannot set DepthStencil target without Color0 target!"); |
| 201 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, depthStecil->getBinding(), depthStecil->getHandle(), depthStecil->getMipLevel()); |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | // Clears the texture (note that the binding is irrelevent) |
| 206 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); |
| 207 | } |
| 208 | |
| 209 | GLenum *buf = new GLenum[bufsize]; |
| 210 | int count = 0; |
| 211 | for (int i = 0; i < bufsize; i++) |
| 212 | { |
| 213 | if (drawbufs[i]) |
| 214 | { |
| 215 | buf[count] = GL_COLOR_ATTACHMENT0 + i; |
| 216 | count++; |
| 217 | } |
| 218 | } |
no test coverage detected