blob: b2219dc55e8f329617d9eb91c8103065130e33a0 [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"
18#include "libANGLE/renderer/gl/FunctionsGL.h"
Jacek Cabanfa60f692015-04-27 18:23:44 +020019#include "libANGLE/renderer/gl/RenderbufferGL.h"
Geoff Lang4ad17092015-03-10 16:47:44 -040020#include "libANGLE/renderer/gl/StateManagerGL.h"
21#include "libANGLE/renderer/gl/TextureGL.h"
Geoff Langafd7f0a2015-09-09 15:33:31 -040022#include "libANGLE/renderer/gl/WorkaroundsGL.h"
Jamie Madillcc86d642015-11-24 13:00:07 -050023#include "platform/Platform.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050024
Jamie Madill60ec6ea2016-01-22 15:27:19 -050025using namespace gl;
26
Geoff Langf9a6f082015-01-22 13:32:49 -050027namespace rx
28{
29
Jamie Madill48ef11b2016-04-27 15:21:52 -040030FramebufferGL::FramebufferGL(const FramebufferState &state,
Geoff Langafd7f0a2015-09-09 15:33:31 -040031 const FunctionsGL *functions,
32 StateManagerGL *stateManager,
33 const WorkaroundsGL &workarounds,
34 bool isDefault)
Jamie Madill48ef11b2016-04-27 15:21:52 -040035 : FramebufferImpl(state),
Geoff Lang4ad17092015-03-10 16:47:44 -040036 mFunctions(functions),
37 mStateManager(stateManager),
Geoff Langafd7f0a2015-09-09 15:33:31 -040038 mWorkarounds(workarounds),
Corentin Wallez6ab01b92015-08-03 10:16:36 -070039 mFramebufferID(0),
40 mIsDefault(isDefault)
Geoff Lang4ad17092015-03-10 16:47:44 -040041{
Corentin Wallez6ab01b92015-08-03 10:16:36 -070042 if (!mIsDefault)
Geoff Lang4ad17092015-03-10 16:47:44 -040043 {
44 mFunctions->genFramebuffers(1, &mFramebufferID);
45 }
46}
Geoff Langf9a6f082015-01-22 13:32:49 -050047
Corentin Wallez86f8dd72015-08-12 12:37:48 -070048FramebufferGL::FramebufferGL(GLuint id,
Jamie Madill48ef11b2016-04-27 15:21:52 -040049 const FramebufferState &state,
Corentin Wallez86f8dd72015-08-12 12:37:48 -070050 const FunctionsGL *functions,
Geoff Langafd7f0a2015-09-09 15:33:31 -040051 const WorkaroundsGL &workarounds,
Corentin Wallez86f8dd72015-08-12 12:37:48 -070052 StateManagerGL *stateManager)
Jamie Madill48ef11b2016-04-27 15:21:52 -040053 : FramebufferImpl(state),
Corentin Wallez86f8dd72015-08-12 12:37:48 -070054 mFunctions(functions),
55 mStateManager(stateManager),
Geoff Langafd7f0a2015-09-09 15:33:31 -040056 mWorkarounds(workarounds),
Corentin Wallez86f8dd72015-08-12 12:37:48 -070057 mFramebufferID(id),
58 mIsDefault(true)
59{
60}
61
Geoff Langf9a6f082015-01-22 13:32:49 -050062FramebufferGL::~FramebufferGL()
Geoff Lang4ad17092015-03-10 16:47:44 -040063{
Geoff Lang1eb708e2015-05-04 14:58:23 -040064 mStateManager->deleteFramebuffer(mFramebufferID);
65 mFramebufferID = 0;
Geoff Lang4ad17092015-03-10 16:47:44 -040066}
67
Jamie Madill60ec6ea2016-01-22 15:27:19 -050068static void BindFramebufferAttachment(const FunctionsGL *functions,
69 GLenum attachmentPoint,
70 const FramebufferAttachment *attachment)
Geoff Lang4ad17092015-03-10 16:47:44 -040071{
72 if (attachment)
73 {
74 if (attachment->type() == GL_TEXTURE)
75 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -050076 const Texture *texture = attachment->getTexture();
Geoff Lang4ad17092015-03-10 16:47:44 -040077 const TextureGL *textureGL = GetImplAs<TextureGL>(texture);
78
79 if (texture->getTarget() == GL_TEXTURE_2D)
80 {
81 functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D,
82 textureGL->getTextureID(), attachment->mipLevel());
83 }
84 else if (texture->getTarget() == GL_TEXTURE_CUBE_MAP)
85 {
86 functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, attachment->cubeMapFace(),
87 textureGL->getTextureID(), attachment->mipLevel());
88 }
89 else if (texture->getTarget() == GL_TEXTURE_2D_ARRAY || texture->getTarget() == GL_TEXTURE_3D)
90 {
91 functions->framebufferTextureLayer(GL_FRAMEBUFFER, attachmentPoint, textureGL->getTextureID(),
92 attachment->mipLevel(), attachment->layer());
93 }
94 else
95 {
96 UNREACHABLE();
97 }
98 }
99 else if (attachment->type() == GL_RENDERBUFFER)
100 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500101 const Renderbuffer *renderbuffer = attachment->getRenderbuffer();
Geoff Langcd69f1c2015-03-18 14:33:23 -0400102 const RenderbufferGL *renderbufferGL = GetImplAs<RenderbufferGL>(renderbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400103
Geoff Langcd69f1c2015-03-18 14:33:23 -0400104 functions->framebufferRenderbuffer(GL_FRAMEBUFFER, attachmentPoint, GL_RENDERBUFFER,
105 renderbufferGL->getRenderbufferID());
Geoff Lang4ad17092015-03-10 16:47:44 -0400106 }
107 else
108 {
109 UNREACHABLE();
110 }
111 }
112 else
113 {
114 // Unbind this attachment
115 functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, 0, 0);
116 }
117}
Geoff Langf9a6f082015-01-22 13:32:49 -0500118
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500119Error FramebufferGL::discard(size_t count, const GLenum *attachments)
Austin Kinross08332632015-05-05 13:35:47 -0700120{
121 UNIMPLEMENTED();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500122 return Error(GL_INVALID_OPERATION);
Austin Kinross08332632015-05-05 13:35:47 -0700123}
124
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500125Error FramebufferGL::invalidate(size_t count, const GLenum *attachments)
Geoff Langf9a6f082015-01-22 13:32:49 -0500126{
Geoff Lang64a72442015-04-01 14:43:11 -0400127 // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is available.
128 if (mFunctions->invalidateFramebuffer)
129 {
130 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700131 mFunctions->invalidateFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), attachments);
Geoff Lang64a72442015-04-01 14:43:11 -0400132 }
133
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500134 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500135}
136
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500137Error FramebufferGL::invalidateSub(size_t count,
138 const GLenum *attachments,
139 const gl::Rectangle &area)
Geoff Langf9a6f082015-01-22 13:32:49 -0500140{
Geoff Lang64a72442015-04-01 14:43:11 -0400141 // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is available.
142 if (mFunctions->invalidateSubFramebuffer)
143 {
144 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700145 mFunctions->invalidateSubFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count),
146 attachments, area.x, area.y, area.width, area.height);
Geoff Lang64a72442015-04-01 14:43:11 -0400147 }
148
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500149 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500150}
151
Jamie Madill9082b982016-04-27 15:21:51 -0400152Error FramebufferGL::clear(const ContextState &data, GLbitfield mask)
Geoff Langf9a6f082015-01-22 13:32:49 -0500153{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400154 syncClearState(mask);
Geoff Lang4ad17092015-03-10 16:47:44 -0400155 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
156 mFunctions->clear(mask);
157
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500158 return Error(GL_NO_ERROR);
Geoff Lang4ad17092015-03-10 16:47:44 -0400159}
160
Jamie Madill9082b982016-04-27 15:21:51 -0400161Error FramebufferGL::clearBufferfv(const ContextState &data,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500162 GLenum buffer,
163 GLint drawbuffer,
164 const GLfloat *values)
Geoff Langf9a6f082015-01-22 13:32:49 -0500165{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400166 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400167 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
168 mFunctions->clearBufferfv(buffer, drawbuffer, values);
169
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500170 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500171}
172
Jamie Madill9082b982016-04-27 15:21:51 -0400173Error FramebufferGL::clearBufferuiv(const ContextState &data,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500174 GLenum buffer,
175 GLint drawbuffer,
176 const GLuint *values)
Geoff Langf9a6f082015-01-22 13:32:49 -0500177{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400178 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400179 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
180 mFunctions->clearBufferuiv(buffer, drawbuffer, values);
181
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500182 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500183}
184
Jamie Madill9082b982016-04-27 15:21:51 -0400185Error FramebufferGL::clearBufferiv(const ContextState &data,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500186 GLenum buffer,
187 GLint drawbuffer,
188 const GLint *values)
Geoff Langf9a6f082015-01-22 13:32:49 -0500189{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400190 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400191 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
192 mFunctions->clearBufferiv(buffer, drawbuffer, values);
193
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500194 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500195}
196
Jamie Madill9082b982016-04-27 15:21:51 -0400197Error FramebufferGL::clearBufferfi(const ContextState &data,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500198 GLenum buffer,
199 GLint drawbuffer,
200 GLfloat depth,
201 GLint stencil)
Geoff Langf9a6f082015-01-22 13:32:49 -0500202{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400203 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400204 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
205 mFunctions->clearBufferfi(buffer, drawbuffer, depth, stencil);
206
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500207 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500208}
209
210GLenum FramebufferGL::getImplementationColorReadFormat() const
211{
Jamie Madill48ef11b2016-04-27 15:21:52 -0400212 const FramebufferAttachment *readAttachment = mState.getReadAttachment();
Geoff Lang4ad17092015-03-10 16:47:44 -0400213 GLenum internalFormat = readAttachment->getInternalFormat();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500214 const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang4ad17092015-03-10 16:47:44 -0400215 return internalFormatInfo.format;
Geoff Langf9a6f082015-01-22 13:32:49 -0500216}
217
218GLenum FramebufferGL::getImplementationColorReadType() const
219{
Jamie Madill48ef11b2016-04-27 15:21:52 -0400220 const FramebufferAttachment *readAttachment = mState.getReadAttachment();
Geoff Lang4ad17092015-03-10 16:47:44 -0400221 GLenum internalFormat = readAttachment->getInternalFormat();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500222 const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang4ad17092015-03-10 16:47:44 -0400223 return internalFormatInfo.type;
Geoff Langf9a6f082015-01-22 13:32:49 -0500224}
225
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500226Error FramebufferGL::readPixels(const State &state,
227 const gl::Rectangle &area,
228 GLenum format,
229 GLenum type,
230 GLvoid *pixels) const
Geoff Langf9a6f082015-01-22 13:32:49 -0500231{
Geoff Langda34d002015-09-04 11:08:59 -0400232 // TODO: don't sync the pixel pack state here once the dirty bits contain the pixel pack buffer
233 // binding
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500234 const PixelPackState &packState = state.getPackState();
Geoff Langda34d002015-09-04 11:08:59 -0400235 mStateManager->setPixelPackState(packState);
Jamie Madill87de3622015-03-16 10:41:44 -0400236
Geoff Lang4ad17092015-03-10 16:47:44 -0400237 mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, mFramebufferID);
238 mFunctions->readPixels(area.x, area.y, area.width, area.height, format, type, pixels);
239
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500240 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500241}
242
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500243Error FramebufferGL::blit(const State &state,
244 const gl::Rectangle &sourceArea,
245 const gl::Rectangle &destArea,
246 GLbitfield mask,
247 GLenum filter,
248 const Framebuffer *sourceFramebuffer)
Geoff Langf9a6f082015-01-22 13:32:49 -0500249{
Geoff Lang4ad17092015-03-10 16:47:44 -0400250 const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(sourceFramebuffer);
251
252 mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID());
253 mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebufferID);
254
Jamie Madill2da819e2015-12-03 15:53:19 -0500255 mFunctions->blitFramebuffer(sourceArea.x, sourceArea.y, sourceArea.x1(), sourceArea.y1(),
256 destArea.x, destArea.y, destArea.x1(), destArea.y1(), mask, filter);
Geoff Lang4ad17092015-03-10 16:47:44 -0400257
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500258 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500259}
260
Jamie Madillcc86d642015-11-24 13:00:07 -0500261bool FramebufferGL::checkStatus() const
Geoff Langf9a6f082015-01-22 13:32:49 -0500262{
Geoff Lang4ad17092015-03-10 16:47:44 -0400263 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Jamie Madillcc86d642015-11-24 13:00:07 -0500264 GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
265 if (status != GL_FRAMEBUFFER_COMPLETE)
266 {
267 ANGLEPlatformCurrent()->logWarning("GL framebuffer returned incomplete.");
268 }
269 return (status == GL_FRAMEBUFFER_COMPLETE);
Geoff Lang4ad17092015-03-10 16:47:44 -0400270}
271
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500272void FramebufferGL::syncState(const Framebuffer::DirtyBits &dirtyBits)
273{
274 // Don't need to sync state for the default FBO.
275 if (mIsDefault)
276 {
277 return;
278 }
279
280 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
281
282 for (auto dirtyBit : angle::IterateBitSet(dirtyBits))
283 {
284 switch (dirtyBit)
285 {
286 case Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT:
287 BindFramebufferAttachment(mFunctions, GL_DEPTH_ATTACHMENT,
Jamie Madill48ef11b2016-04-27 15:21:52 -0400288 mState.getDepthAttachment());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500289 break;
290 case Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT:
291 BindFramebufferAttachment(mFunctions, GL_STENCIL_ATTACHMENT,
Jamie Madill48ef11b2016-04-27 15:21:52 -0400292 mState.getStencilAttachment());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500293 break;
294 case Framebuffer::DIRTY_BIT_DRAW_BUFFERS:
295 {
Jamie Madill48ef11b2016-04-27 15:21:52 -0400296 const auto &drawBuffers = mState.getDrawBufferStates();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500297 mFunctions->drawBuffers(static_cast<GLsizei>(drawBuffers.size()),
298 drawBuffers.data());
299 break;
300 }
301 case Framebuffer::DIRTY_BIT_READ_BUFFER:
Jamie Madill48ef11b2016-04-27 15:21:52 -0400302 mFunctions->readBuffer(mState.getReadBufferState());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500303 break;
304 default:
305 {
306 ASSERT(Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 &&
307 dirtyBit < Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX);
308 size_t index =
309 static_cast<size_t>(dirtyBit - Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0);
310 BindFramebufferAttachment(mFunctions,
311 static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + index),
Jamie Madill48ef11b2016-04-27 15:21:52 -0400312 mState.getColorAttachment(index));
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500313 break;
314 }
315 }
316 }
317}
318
Geoff Lang4ad17092015-03-10 16:47:44 -0400319GLuint FramebufferGL::getFramebufferID() const
320{
321 return mFramebufferID;
Geoff Langf9a6f082015-01-22 13:32:49 -0500322}
323
Geoff Langafd7f0a2015-09-09 15:33:31 -0400324void FramebufferGL::syncDrawState() const
325{
326 if (mFunctions->standard == STANDARD_GL_DESKTOP)
327 {
328 // Enable SRGB blending for all framebuffers except the default framebuffer on Desktop
329 // OpenGL.
330 // When SRGB blending is enabled, only SRGB capable formats will use it but the default
331 // framebuffer will always use it if it is enabled.
332 // TODO(geofflang): Update this when the framebuffer binding dirty changes, when it exists.
333 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
334 }
335}
336
337void FramebufferGL::syncClearState(GLbitfield mask)
338{
Frank Henigmana3d333c2016-03-22 22:09:14 -0400339 if (mFunctions->standard == STANDARD_GL_DESKTOP)
Geoff Langafd7f0a2015-09-09 15:33:31 -0400340 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400341 if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments &&
342 (mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault)
Geoff Langafd7f0a2015-09-09 15:33:31 -0400343 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400344 bool hasSRBAttachment = false;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400345 for (const auto &attachment : mState.getColorAttachments())
Geoff Langafd7f0a2015-09-09 15:33:31 -0400346 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400347 if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB)
348 {
349 hasSRBAttachment = true;
350 break;
351 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400352 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400353
Frank Henigmana3d333c2016-03-22 22:09:14 -0400354 mStateManager->setFramebufferSRGBEnabled(hasSRBAttachment);
355 }
356 else
357 {
358 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
359 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400360 }
361}
362
363void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer)
364{
365 if (mFunctions->standard == STANDARD_GL_DESKTOP)
366 {
367 if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && buffer == GL_COLOR &&
368 !mIsDefault)
369 {
370 // If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer
371 // is an SRGB format.
Jamie Madill48ef11b2016-04-27 15:21:52 -0400372 const auto &drawbufferState = mState.getDrawBufferStates();
373 const auto &colorAttachments = mState.getColorAttachments();
Geoff Langafd7f0a2015-09-09 15:33:31 -0400374
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500375 const FramebufferAttachment *attachment = nullptr;
Geoff Langafd7f0a2015-09-09 15:33:31 -0400376 if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 &&
377 drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size())
378 {
379 size_t attachmentIdx =
380 static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0);
381 attachment = &colorAttachments[attachmentIdx];
382 }
383
384 if (attachment != nullptr)
385 {
386 mStateManager->setFramebufferSRGBEnabled(attachment->getColorEncoding() == GL_SRGB);
387 }
388 }
389 else
390 {
391 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
392 }
393 }
394}
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500395} // namespace rx