blob: 4606114ca4c64218af094fbee96dbdcd8708da75 [file] [log] [blame]
Geoff Langf9a6f082015-01-22 13:32:49 -05001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// FramebufferGL.cpp: Implements the class methods for FramebufferGL.
8
9#include "libANGLE/renderer/gl/FramebufferGL.h"
10
Jamie Madill60ec6ea2016-01-22 15:27:19 -050011#include "common/BitSetIterator.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050012#include "common/debug.h"
Jamie Madill9082b982016-04-27 15:21:51 -040013#include "libANGLE/ContextState.h"
Jamie Madill87de3622015-03-16 10:41:44 -040014#include "libANGLE/State.h"
Geoff Lang4ad17092015-03-10 16:47:44 -040015#include "libANGLE/FramebufferAttachment.h"
16#include "libANGLE/angletypes.h"
17#include "libANGLE/formatutils.h"
Jamie Madill8415b5f2016-04-26 13:41:39 -040018#include "libANGLE/renderer/ContextImpl.h"
Geoff Lang4ad17092015-03-10 16:47:44 -040019#include "libANGLE/renderer/gl/FunctionsGL.h"
Jacek Cabanfa60f692015-04-27 18:23:44 +020020#include "libANGLE/renderer/gl/RenderbufferGL.h"
Geoff Lang4ad17092015-03-10 16:47:44 -040021#include "libANGLE/renderer/gl/StateManagerGL.h"
22#include "libANGLE/renderer/gl/TextureGL.h"
Geoff Langafd7f0a2015-09-09 15:33:31 -040023#include "libANGLE/renderer/gl/WorkaroundsGL.h"
Jamie Madillcc86d642015-11-24 13:00:07 -050024#include "platform/Platform.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050025
Jamie Madill60ec6ea2016-01-22 15:27:19 -050026using namespace gl;
27
Geoff Langf9a6f082015-01-22 13:32:49 -050028namespace rx
29{
30
Jamie Madill48ef11b2016-04-27 15:21:52 -040031FramebufferGL::FramebufferGL(const FramebufferState &state,
Geoff Langafd7f0a2015-09-09 15:33:31 -040032 const FunctionsGL *functions,
33 StateManagerGL *stateManager,
34 const WorkaroundsGL &workarounds,
35 bool isDefault)
Jamie Madill48ef11b2016-04-27 15:21:52 -040036 : FramebufferImpl(state),
Geoff Lang4ad17092015-03-10 16:47:44 -040037 mFunctions(functions),
38 mStateManager(stateManager),
Geoff Langafd7f0a2015-09-09 15:33:31 -040039 mWorkarounds(workarounds),
Corentin Wallez6ab01b92015-08-03 10:16:36 -070040 mFramebufferID(0),
41 mIsDefault(isDefault)
Geoff Lang4ad17092015-03-10 16:47:44 -040042{
Corentin Wallez6ab01b92015-08-03 10:16:36 -070043 if (!mIsDefault)
Geoff Lang4ad17092015-03-10 16:47:44 -040044 {
45 mFunctions->genFramebuffers(1, &mFramebufferID);
46 }
47}
Geoff Langf9a6f082015-01-22 13:32:49 -050048
Corentin Wallez86f8dd72015-08-12 12:37:48 -070049FramebufferGL::FramebufferGL(GLuint id,
Jamie Madill48ef11b2016-04-27 15:21:52 -040050 const FramebufferState &state,
Corentin Wallez86f8dd72015-08-12 12:37:48 -070051 const FunctionsGL *functions,
Geoff Langafd7f0a2015-09-09 15:33:31 -040052 const WorkaroundsGL &workarounds,
Corentin Wallez86f8dd72015-08-12 12:37:48 -070053 StateManagerGL *stateManager)
Jamie Madill48ef11b2016-04-27 15:21:52 -040054 : FramebufferImpl(state),
Corentin Wallez86f8dd72015-08-12 12:37:48 -070055 mFunctions(functions),
56 mStateManager(stateManager),
Geoff Langafd7f0a2015-09-09 15:33:31 -040057 mWorkarounds(workarounds),
Corentin Wallez86f8dd72015-08-12 12:37:48 -070058 mFramebufferID(id),
59 mIsDefault(true)
60{
61}
62
Geoff Langf9a6f082015-01-22 13:32:49 -050063FramebufferGL::~FramebufferGL()
Geoff Lang4ad17092015-03-10 16:47:44 -040064{
Geoff Lang1eb708e2015-05-04 14:58:23 -040065 mStateManager->deleteFramebuffer(mFramebufferID);
66 mFramebufferID = 0;
Geoff Lang4ad17092015-03-10 16:47:44 -040067}
68
Jamie Madill60ec6ea2016-01-22 15:27:19 -050069static void BindFramebufferAttachment(const FunctionsGL *functions,
70 GLenum attachmentPoint,
71 const FramebufferAttachment *attachment)
Geoff Lang4ad17092015-03-10 16:47:44 -040072{
73 if (attachment)
74 {
75 if (attachment->type() == GL_TEXTURE)
76 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -050077 const Texture *texture = attachment->getTexture();
Geoff Lang4ad17092015-03-10 16:47:44 -040078 const TextureGL *textureGL = GetImplAs<TextureGL>(texture);
79
80 if (texture->getTarget() == GL_TEXTURE_2D)
81 {
82 functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D,
83 textureGL->getTextureID(), attachment->mipLevel());
84 }
85 else if (texture->getTarget() == GL_TEXTURE_CUBE_MAP)
86 {
87 functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, attachment->cubeMapFace(),
88 textureGL->getTextureID(), attachment->mipLevel());
89 }
90 else if (texture->getTarget() == GL_TEXTURE_2D_ARRAY || texture->getTarget() == GL_TEXTURE_3D)
91 {
92 functions->framebufferTextureLayer(GL_FRAMEBUFFER, attachmentPoint, textureGL->getTextureID(),
93 attachment->mipLevel(), attachment->layer());
94 }
95 else
96 {
97 UNREACHABLE();
98 }
99 }
100 else if (attachment->type() == GL_RENDERBUFFER)
101 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500102 const Renderbuffer *renderbuffer = attachment->getRenderbuffer();
Geoff Langcd69f1c2015-03-18 14:33:23 -0400103 const RenderbufferGL *renderbufferGL = GetImplAs<RenderbufferGL>(renderbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400104
Geoff Langcd69f1c2015-03-18 14:33:23 -0400105 functions->framebufferRenderbuffer(GL_FRAMEBUFFER, attachmentPoint, GL_RENDERBUFFER,
106 renderbufferGL->getRenderbufferID());
Geoff Lang4ad17092015-03-10 16:47:44 -0400107 }
108 else
109 {
110 UNREACHABLE();
111 }
112 }
113 else
114 {
115 // Unbind this attachment
116 functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, 0, 0);
117 }
118}
Geoff Langf9a6f082015-01-22 13:32:49 -0500119
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500120Error FramebufferGL::discard(size_t count, const GLenum *attachments)
Austin Kinross08332632015-05-05 13:35:47 -0700121{
122 UNIMPLEMENTED();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500123 return Error(GL_INVALID_OPERATION);
Austin Kinross08332632015-05-05 13:35:47 -0700124}
125
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500126Error FramebufferGL::invalidate(size_t count, const GLenum *attachments)
Geoff Langf9a6f082015-01-22 13:32:49 -0500127{
Geoff Lang64a72442015-04-01 14:43:11 -0400128 // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is available.
129 if (mFunctions->invalidateFramebuffer)
130 {
131 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700132 mFunctions->invalidateFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), attachments);
Geoff Lang64a72442015-04-01 14:43:11 -0400133 }
134
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500135 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500136}
137
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500138Error FramebufferGL::invalidateSub(size_t count,
139 const GLenum *attachments,
140 const gl::Rectangle &area)
Geoff Langf9a6f082015-01-22 13:32:49 -0500141{
Geoff Lang64a72442015-04-01 14:43:11 -0400142 // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is available.
143 if (mFunctions->invalidateSubFramebuffer)
144 {
145 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700146 mFunctions->invalidateSubFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count),
147 attachments, area.x, area.y, area.width, area.height);
Geoff Lang64a72442015-04-01 14:43:11 -0400148 }
149
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500150 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500151}
152
Jamie Madill8415b5f2016-04-26 13:41:39 -0400153Error FramebufferGL::clear(ContextImpl *context, GLbitfield mask)
Geoff Langf9a6f082015-01-22 13:32:49 -0500154{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400155 syncClearState(mask);
Geoff Lang4ad17092015-03-10 16:47:44 -0400156 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
157 mFunctions->clear(mask);
158
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500159 return Error(GL_NO_ERROR);
Geoff Lang4ad17092015-03-10 16:47:44 -0400160}
161
Jamie Madill8415b5f2016-04-26 13:41:39 -0400162Error FramebufferGL::clearBufferfv(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500163 GLenum buffer,
164 GLint drawbuffer,
165 const GLfloat *values)
Geoff Langf9a6f082015-01-22 13:32:49 -0500166{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400167 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400168 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
169 mFunctions->clearBufferfv(buffer, drawbuffer, values);
170
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500171 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500172}
173
Jamie Madill8415b5f2016-04-26 13:41:39 -0400174Error FramebufferGL::clearBufferuiv(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500175 GLenum buffer,
176 GLint drawbuffer,
177 const GLuint *values)
Geoff Langf9a6f082015-01-22 13:32:49 -0500178{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400179 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400180 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
181 mFunctions->clearBufferuiv(buffer, drawbuffer, values);
182
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500183 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500184}
185
Jamie Madill8415b5f2016-04-26 13:41:39 -0400186Error FramebufferGL::clearBufferiv(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500187 GLenum buffer,
188 GLint drawbuffer,
189 const GLint *values)
Geoff Langf9a6f082015-01-22 13:32:49 -0500190{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400191 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400192 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
193 mFunctions->clearBufferiv(buffer, drawbuffer, values);
194
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500195 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500196}
197
Jamie Madill8415b5f2016-04-26 13:41:39 -0400198Error FramebufferGL::clearBufferfi(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500199 GLenum buffer,
200 GLint drawbuffer,
201 GLfloat depth,
202 GLint stencil)
Geoff Langf9a6f082015-01-22 13:32:49 -0500203{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400204 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400205 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
206 mFunctions->clearBufferfi(buffer, drawbuffer, depth, stencil);
207
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500208 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500209}
210
211GLenum FramebufferGL::getImplementationColorReadFormat() const
212{
Jamie Madilla3944d42016-07-22 22:13:26 -0400213 const auto *readAttachment = mState.getReadAttachment();
214 const Format &format = readAttachment->getFormat();
215 return format.info->format;
Geoff Langf9a6f082015-01-22 13:32:49 -0500216}
217
218GLenum FramebufferGL::getImplementationColorReadType() const
219{
Jamie Madilla3944d42016-07-22 22:13:26 -0400220 const auto *readAttachment = mState.getReadAttachment();
221 const Format &format = readAttachment->getFormat();
222 return format.info->type;
Geoff Langf9a6f082015-01-22 13:32:49 -0500223}
224
Jamie Madill8415b5f2016-04-26 13:41:39 -0400225Error FramebufferGL::readPixels(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500226 const gl::Rectangle &area,
227 GLenum format,
228 GLenum type,
229 GLvoid *pixels) const
Geoff Langf9a6f082015-01-22 13:32:49 -0500230{
Geoff Langda34d002015-09-04 11:08:59 -0400231 // TODO: don't sync the pixel pack state here once the dirty bits contain the pixel pack buffer
232 // binding
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700233 const PixelPackState &packState = context->getGLState().getPackState();
Geoff Langda34d002015-09-04 11:08:59 -0400234 mStateManager->setPixelPackState(packState);
Jamie Madill87de3622015-03-16 10:41:44 -0400235
Geoff Lang4ad17092015-03-10 16:47:44 -0400236 mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, mFramebufferID);
237 mFunctions->readPixels(area.x, area.y, area.width, area.height, format, type, pixels);
238
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500239 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500240}
241
Jamie Madill8415b5f2016-04-26 13:41:39 -0400242Error FramebufferGL::blit(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500243 const gl::Rectangle &sourceArea,
244 const gl::Rectangle &destArea,
245 GLbitfield mask,
Jamie Madill8415b5f2016-04-26 13:41:39 -0400246 GLenum filter)
Geoff Langf9a6f082015-01-22 13:32:49 -0500247{
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700248 const Framebuffer *sourceFramebuffer = context->getGLState().getReadFramebuffer();
Geoff Lang4ad17092015-03-10 16:47:44 -0400249 const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(sourceFramebuffer);
250
251 mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID());
252 mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebufferID);
253
Jamie Madill2da819e2015-12-03 15:53:19 -0500254 mFunctions->blitFramebuffer(sourceArea.x, sourceArea.y, sourceArea.x1(), sourceArea.y1(),
255 destArea.x, destArea.y, destArea.x1(), destArea.y1(), mask, filter);
Geoff Lang4ad17092015-03-10 16:47:44 -0400256
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500257 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500258}
259
Jamie Madillcc86d642015-11-24 13:00:07 -0500260bool FramebufferGL::checkStatus() const
Geoff Langf9a6f082015-01-22 13:32:49 -0500261{
Geoff Lang4ad17092015-03-10 16:47:44 -0400262 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Jamie Madillcc86d642015-11-24 13:00:07 -0500263 GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
264 if (status != GL_FRAMEBUFFER_COMPLETE)
265 {
266 ANGLEPlatformCurrent()->logWarning("GL framebuffer returned incomplete.");
267 }
268 return (status == GL_FRAMEBUFFER_COMPLETE);
Geoff Lang4ad17092015-03-10 16:47:44 -0400269}
270
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500271void FramebufferGL::syncState(const Framebuffer::DirtyBits &dirtyBits)
272{
273 // Don't need to sync state for the default FBO.
274 if (mIsDefault)
275 {
276 return;
277 }
278
279 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
280
281 for (auto dirtyBit : angle::IterateBitSet(dirtyBits))
282 {
283 switch (dirtyBit)
284 {
285 case Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT:
286 BindFramebufferAttachment(mFunctions, GL_DEPTH_ATTACHMENT,
Jamie Madill48ef11b2016-04-27 15:21:52 -0400287 mState.getDepthAttachment());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500288 break;
289 case Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT:
290 BindFramebufferAttachment(mFunctions, GL_STENCIL_ATTACHMENT,
Jamie Madill48ef11b2016-04-27 15:21:52 -0400291 mState.getStencilAttachment());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500292 break;
293 case Framebuffer::DIRTY_BIT_DRAW_BUFFERS:
294 {
Jamie Madill48ef11b2016-04-27 15:21:52 -0400295 const auto &drawBuffers = mState.getDrawBufferStates();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500296 mFunctions->drawBuffers(static_cast<GLsizei>(drawBuffers.size()),
297 drawBuffers.data());
298 break;
299 }
300 case Framebuffer::DIRTY_BIT_READ_BUFFER:
Jamie Madill48ef11b2016-04-27 15:21:52 -0400301 mFunctions->readBuffer(mState.getReadBufferState());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500302 break;
303 default:
304 {
305 ASSERT(Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 &&
306 dirtyBit < Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX);
307 size_t index =
308 static_cast<size_t>(dirtyBit - Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0);
309 BindFramebufferAttachment(mFunctions,
310 static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + index),
Jamie Madill48ef11b2016-04-27 15:21:52 -0400311 mState.getColorAttachment(index));
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500312 break;
313 }
314 }
315 }
316}
317
Geoff Lang4ad17092015-03-10 16:47:44 -0400318GLuint FramebufferGL::getFramebufferID() const
319{
320 return mFramebufferID;
Geoff Langf9a6f082015-01-22 13:32:49 -0500321}
322
Geoff Langafd7f0a2015-09-09 15:33:31 -0400323void FramebufferGL::syncDrawState() const
324{
325 if (mFunctions->standard == STANDARD_GL_DESKTOP)
326 {
327 // Enable SRGB blending for all framebuffers except the default framebuffer on Desktop
328 // OpenGL.
329 // When SRGB blending is enabled, only SRGB capable formats will use it but the default
330 // framebuffer will always use it if it is enabled.
331 // TODO(geofflang): Update this when the framebuffer binding dirty changes, when it exists.
332 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
333 }
334}
335
336void FramebufferGL::syncClearState(GLbitfield mask)
337{
Frank Henigmana3d333c2016-03-22 22:09:14 -0400338 if (mFunctions->standard == STANDARD_GL_DESKTOP)
Geoff Langafd7f0a2015-09-09 15:33:31 -0400339 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400340 if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments &&
341 (mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault)
Geoff Langafd7f0a2015-09-09 15:33:31 -0400342 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400343 bool hasSRBAttachment = false;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400344 for (const auto &attachment : mState.getColorAttachments())
Geoff Langafd7f0a2015-09-09 15:33:31 -0400345 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400346 if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB)
347 {
348 hasSRBAttachment = true;
349 break;
350 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400351 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400352
Frank Henigmana3d333c2016-03-22 22:09:14 -0400353 mStateManager->setFramebufferSRGBEnabled(hasSRBAttachment);
354 }
355 else
356 {
357 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
358 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400359 }
360}
361
362void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer)
363{
364 if (mFunctions->standard == STANDARD_GL_DESKTOP)
365 {
366 if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && buffer == GL_COLOR &&
367 !mIsDefault)
368 {
369 // If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer
370 // is an SRGB format.
Jamie Madill48ef11b2016-04-27 15:21:52 -0400371 const auto &drawbufferState = mState.getDrawBufferStates();
372 const auto &colorAttachments = mState.getColorAttachments();
Geoff Langafd7f0a2015-09-09 15:33:31 -0400373
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500374 const FramebufferAttachment *attachment = nullptr;
Geoff Langafd7f0a2015-09-09 15:33:31 -0400375 if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 &&
376 drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size())
377 {
378 size_t attachmentIdx =
379 static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0);
380 attachment = &colorAttachments[attachmentIdx];
381 }
382
383 if (attachment != nullptr)
384 {
385 mStateManager->setFramebufferSRGBEnabled(attachment->getColorEncoding() == GL_SRGB);
386 }
387 }
388 else
389 {
390 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
391 }
392 }
393}
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500394} // namespace rx