blob: 40890e0625d55e2c93bb70f2239b2725be7d7f15 [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 Madill48ef11b2016-04-27 15:21:52 -0400213 const FramebufferAttachment *readAttachment = mState.getReadAttachment();
Geoff Lang4ad17092015-03-10 16:47:44 -0400214 GLenum internalFormat = readAttachment->getInternalFormat();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500215 const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang4ad17092015-03-10 16:47:44 -0400216 return internalFormatInfo.format;
Geoff Langf9a6f082015-01-22 13:32:49 -0500217}
218
219GLenum FramebufferGL::getImplementationColorReadType() const
220{
Jamie Madill48ef11b2016-04-27 15:21:52 -0400221 const FramebufferAttachment *readAttachment = mState.getReadAttachment();
Geoff Lang4ad17092015-03-10 16:47:44 -0400222 GLenum internalFormat = readAttachment->getInternalFormat();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500223 const InternalFormat &internalFormatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang4ad17092015-03-10 16:47:44 -0400224 return internalFormatInfo.type;
Geoff Langf9a6f082015-01-22 13:32:49 -0500225}
226
Jamie Madill8415b5f2016-04-26 13:41:39 -0400227Error FramebufferGL::readPixels(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500228 const gl::Rectangle &area,
229 GLenum format,
230 GLenum type,
231 GLvoid *pixels) const
Geoff Langf9a6f082015-01-22 13:32:49 -0500232{
Geoff Langda34d002015-09-04 11:08:59 -0400233 // TODO: don't sync the pixel pack state here once the dirty bits contain the pixel pack buffer
234 // binding
Jamie Madill8415b5f2016-04-26 13:41:39 -0400235 const PixelPackState &packState = context->getState().getPackState();
Geoff Langda34d002015-09-04 11:08:59 -0400236 mStateManager->setPixelPackState(packState);
Jamie Madill87de3622015-03-16 10:41:44 -0400237
Geoff Lang4ad17092015-03-10 16:47:44 -0400238 mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, mFramebufferID);
239 mFunctions->readPixels(area.x, area.y, area.width, area.height, format, type, pixels);
240
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500241 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500242}
243
Jamie Madill8415b5f2016-04-26 13:41:39 -0400244Error FramebufferGL::blit(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500245 const gl::Rectangle &sourceArea,
246 const gl::Rectangle &destArea,
247 GLbitfield mask,
Jamie Madill8415b5f2016-04-26 13:41:39 -0400248 GLenum filter)
Geoff Langf9a6f082015-01-22 13:32:49 -0500249{
Jamie Madill8415b5f2016-04-26 13:41:39 -0400250 const Framebuffer *sourceFramebuffer = context->getState().getReadFramebuffer();
Geoff Lang4ad17092015-03-10 16:47:44 -0400251 const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(sourceFramebuffer);
252
253 mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID());
254 mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebufferID);
255
Jamie Madill2da819e2015-12-03 15:53:19 -0500256 mFunctions->blitFramebuffer(sourceArea.x, sourceArea.y, sourceArea.x1(), sourceArea.y1(),
257 destArea.x, destArea.y, destArea.x1(), destArea.y1(), mask, filter);
Geoff Lang4ad17092015-03-10 16:47:44 -0400258
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500259 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500260}
261
Jamie Madillcc86d642015-11-24 13:00:07 -0500262bool FramebufferGL::checkStatus() const
Geoff Langf9a6f082015-01-22 13:32:49 -0500263{
Geoff Lang4ad17092015-03-10 16:47:44 -0400264 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Jamie Madillcc86d642015-11-24 13:00:07 -0500265 GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
266 if (status != GL_FRAMEBUFFER_COMPLETE)
267 {
268 ANGLEPlatformCurrent()->logWarning("GL framebuffer returned incomplete.");
269 }
270 return (status == GL_FRAMEBUFFER_COMPLETE);
Geoff Lang4ad17092015-03-10 16:47:44 -0400271}
272
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500273void FramebufferGL::syncState(const Framebuffer::DirtyBits &dirtyBits)
274{
275 // Don't need to sync state for the default FBO.
276 if (mIsDefault)
277 {
278 return;
279 }
280
281 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
282
283 for (auto dirtyBit : angle::IterateBitSet(dirtyBits))
284 {
285 switch (dirtyBit)
286 {
287 case Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT:
288 BindFramebufferAttachment(mFunctions, GL_DEPTH_ATTACHMENT,
Jamie Madill48ef11b2016-04-27 15:21:52 -0400289 mState.getDepthAttachment());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500290 break;
291 case Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT:
292 BindFramebufferAttachment(mFunctions, GL_STENCIL_ATTACHMENT,
Jamie Madill48ef11b2016-04-27 15:21:52 -0400293 mState.getStencilAttachment());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500294 break;
295 case Framebuffer::DIRTY_BIT_DRAW_BUFFERS:
296 {
Jamie Madill48ef11b2016-04-27 15:21:52 -0400297 const auto &drawBuffers = mState.getDrawBufferStates();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500298 mFunctions->drawBuffers(static_cast<GLsizei>(drawBuffers.size()),
299 drawBuffers.data());
300 break;
301 }
302 case Framebuffer::DIRTY_BIT_READ_BUFFER:
Jamie Madill48ef11b2016-04-27 15:21:52 -0400303 mFunctions->readBuffer(mState.getReadBufferState());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500304 break;
305 default:
306 {
307 ASSERT(Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 &&
308 dirtyBit < Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX);
309 size_t index =
310 static_cast<size_t>(dirtyBit - Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0);
311 BindFramebufferAttachment(mFunctions,
312 static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + index),
Jamie Madill48ef11b2016-04-27 15:21:52 -0400313 mState.getColorAttachment(index));
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500314 break;
315 }
316 }
317 }
318}
319
Geoff Lang4ad17092015-03-10 16:47:44 -0400320GLuint FramebufferGL::getFramebufferID() const
321{
322 return mFramebufferID;
Geoff Langf9a6f082015-01-22 13:32:49 -0500323}
324
Geoff Langafd7f0a2015-09-09 15:33:31 -0400325void FramebufferGL::syncDrawState() const
326{
327 if (mFunctions->standard == STANDARD_GL_DESKTOP)
328 {
329 // Enable SRGB blending for all framebuffers except the default framebuffer on Desktop
330 // OpenGL.
331 // When SRGB blending is enabled, only SRGB capable formats will use it but the default
332 // framebuffer will always use it if it is enabled.
333 // TODO(geofflang): Update this when the framebuffer binding dirty changes, when it exists.
334 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
335 }
336}
337
338void FramebufferGL::syncClearState(GLbitfield mask)
339{
Frank Henigmana3d333c2016-03-22 22:09:14 -0400340 if (mFunctions->standard == STANDARD_GL_DESKTOP)
Geoff Langafd7f0a2015-09-09 15:33:31 -0400341 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400342 if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments &&
343 (mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault)
Geoff Langafd7f0a2015-09-09 15:33:31 -0400344 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400345 bool hasSRBAttachment = false;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400346 for (const auto &attachment : mState.getColorAttachments())
Geoff Langafd7f0a2015-09-09 15:33:31 -0400347 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400348 if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB)
349 {
350 hasSRBAttachment = true;
351 break;
352 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400353 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400354
Frank Henigmana3d333c2016-03-22 22:09:14 -0400355 mStateManager->setFramebufferSRGBEnabled(hasSRBAttachment);
356 }
357 else
358 {
359 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
360 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400361 }
362}
363
364void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer)
365{
366 if (mFunctions->standard == STANDARD_GL_DESKTOP)
367 {
368 if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && buffer == GL_COLOR &&
369 !mIsDefault)
370 {
371 // If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer
372 // is an SRGB format.
Jamie Madill48ef11b2016-04-27 15:21:52 -0400373 const auto &drawbufferState = mState.getDrawBufferStates();
374 const auto &colorAttachments = mState.getColorAttachments();
Geoff Langafd7f0a2015-09-09 15:33:31 -0400375
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500376 const FramebufferAttachment *attachment = nullptr;
Geoff Langafd7f0a2015-09-09 15:33:31 -0400377 if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 &&
378 drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size())
379 {
380 size_t attachmentIdx =
381 static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0);
382 attachment = &colorAttachments[attachmentIdx];
383 }
384
385 if (attachment != nullptr)
386 {
387 mStateManager->setFramebufferSRGBEnabled(attachment->getColorEncoding() == GL_SRGB);
388 }
389 }
390 else
391 {
392 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
393 }
394 }
395}
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500396} // namespace rx