MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / applyState

Method applyState

Engine/source/gfx/gl/gfxGLTextureTarget.cpp:161–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161void _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 }

Callers 1

_updateRenderTargetsMethod · 0.80

Calls 8

getTargetDescMethod · 0.80
getMipLevelMethod · 0.80
getZOffsetMethod · 0.80
errorfFunction · 0.50
getNumRenderTargetsMethod · 0.45
getBindingMethod · 0.45
getHandleMethod · 0.45
isNullMethod · 0.45

Tested by

no test coverage detected