blob: 8d84c608b421859eb6a780ccbbc67c4f38c9553b [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"
Geoff Langf607c602016-09-21 11:46:48 -040024#include "libANGLE/renderer/gl/formatutilsgl.h"
Jamie Madillcc86d642015-11-24 13:00:07 -050025#include "platform/Platform.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050026
Jamie Madill60ec6ea2016-01-22 15:27:19 -050027using namespace gl;
28
Geoff Langf9a6f082015-01-22 13:32:49 -050029namespace rx
30{
31
Jamie Madill48ef11b2016-04-27 15:21:52 -040032FramebufferGL::FramebufferGL(const FramebufferState &state,
Geoff Langafd7f0a2015-09-09 15:33:31 -040033 const FunctionsGL *functions,
34 StateManagerGL *stateManager,
35 const WorkaroundsGL &workarounds,
36 bool isDefault)
Jamie Madill48ef11b2016-04-27 15:21:52 -040037 : FramebufferImpl(state),
Geoff Lang4ad17092015-03-10 16:47:44 -040038 mFunctions(functions),
39 mStateManager(stateManager),
Geoff Langafd7f0a2015-09-09 15:33:31 -040040 mWorkarounds(workarounds),
Corentin Wallez6ab01b92015-08-03 10:16:36 -070041 mFramebufferID(0),
42 mIsDefault(isDefault)
Geoff Lang4ad17092015-03-10 16:47:44 -040043{
Corentin Wallez6ab01b92015-08-03 10:16:36 -070044 if (!mIsDefault)
Geoff Lang4ad17092015-03-10 16:47:44 -040045 {
46 mFunctions->genFramebuffers(1, &mFramebufferID);
47 }
48}
Geoff Langf9a6f082015-01-22 13:32:49 -050049
Corentin Wallez86f8dd72015-08-12 12:37:48 -070050FramebufferGL::FramebufferGL(GLuint id,
Jamie Madill48ef11b2016-04-27 15:21:52 -040051 const FramebufferState &state,
Corentin Wallez86f8dd72015-08-12 12:37:48 -070052 const FunctionsGL *functions,
Geoff Langafd7f0a2015-09-09 15:33:31 -040053 const WorkaroundsGL &workarounds,
Corentin Wallez86f8dd72015-08-12 12:37:48 -070054 StateManagerGL *stateManager)
Jamie Madill48ef11b2016-04-27 15:21:52 -040055 : FramebufferImpl(state),
Corentin Wallez86f8dd72015-08-12 12:37:48 -070056 mFunctions(functions),
57 mStateManager(stateManager),
Geoff Langafd7f0a2015-09-09 15:33:31 -040058 mWorkarounds(workarounds),
Corentin Wallez86f8dd72015-08-12 12:37:48 -070059 mFramebufferID(id),
60 mIsDefault(true)
61{
62}
63
Geoff Langf9a6f082015-01-22 13:32:49 -050064FramebufferGL::~FramebufferGL()
Geoff Lang4ad17092015-03-10 16:47:44 -040065{
Geoff Lang1eb708e2015-05-04 14:58:23 -040066 mStateManager->deleteFramebuffer(mFramebufferID);
67 mFramebufferID = 0;
Geoff Lang4ad17092015-03-10 16:47:44 -040068}
69
Jamie Madill60ec6ea2016-01-22 15:27:19 -050070static void BindFramebufferAttachment(const FunctionsGL *functions,
71 GLenum attachmentPoint,
72 const FramebufferAttachment *attachment)
Geoff Lang4ad17092015-03-10 16:47:44 -040073{
74 if (attachment)
75 {
76 if (attachment->type() == GL_TEXTURE)
77 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -050078 const Texture *texture = attachment->getTexture();
Geoff Lang4ad17092015-03-10 16:47:44 -040079 const TextureGL *textureGL = GetImplAs<TextureGL>(texture);
80
81 if (texture->getTarget() == GL_TEXTURE_2D)
82 {
83 functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D,
84 textureGL->getTextureID(), attachment->mipLevel());
85 }
86 else if (texture->getTarget() == GL_TEXTURE_CUBE_MAP)
87 {
88 functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, attachment->cubeMapFace(),
89 textureGL->getTextureID(), attachment->mipLevel());
90 }
91 else if (texture->getTarget() == GL_TEXTURE_2D_ARRAY || texture->getTarget() == GL_TEXTURE_3D)
92 {
93 functions->framebufferTextureLayer(GL_FRAMEBUFFER, attachmentPoint, textureGL->getTextureID(),
94 attachment->mipLevel(), attachment->layer());
95 }
96 else
97 {
98 UNREACHABLE();
99 }
100 }
101 else if (attachment->type() == GL_RENDERBUFFER)
102 {
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500103 const Renderbuffer *renderbuffer = attachment->getRenderbuffer();
Geoff Langcd69f1c2015-03-18 14:33:23 -0400104 const RenderbufferGL *renderbufferGL = GetImplAs<RenderbufferGL>(renderbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400105
Geoff Langcd69f1c2015-03-18 14:33:23 -0400106 functions->framebufferRenderbuffer(GL_FRAMEBUFFER, attachmentPoint, GL_RENDERBUFFER,
107 renderbufferGL->getRenderbufferID());
Geoff Lang4ad17092015-03-10 16:47:44 -0400108 }
109 else
110 {
111 UNREACHABLE();
112 }
113 }
114 else
115 {
116 // Unbind this attachment
117 functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, 0, 0);
118 }
119}
Geoff Langf9a6f082015-01-22 13:32:49 -0500120
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500121Error FramebufferGL::discard(size_t count, const GLenum *attachments)
Austin Kinross08332632015-05-05 13:35:47 -0700122{
123 UNIMPLEMENTED();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500124 return Error(GL_INVALID_OPERATION);
Austin Kinross08332632015-05-05 13:35:47 -0700125}
126
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500127Error FramebufferGL::invalidate(size_t count, const GLenum *attachments)
Geoff Langf9a6f082015-01-22 13:32:49 -0500128{
Geoff Lang64a72442015-04-01 14:43:11 -0400129 // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is available.
130 if (mFunctions->invalidateFramebuffer)
131 {
132 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700133 mFunctions->invalidateFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), attachments);
Geoff Lang64a72442015-04-01 14:43:11 -0400134 }
135
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500136 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500137}
138
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500139Error FramebufferGL::invalidateSub(size_t count,
140 const GLenum *attachments,
141 const gl::Rectangle &area)
Geoff Langf9a6f082015-01-22 13:32:49 -0500142{
Geoff Lang64a72442015-04-01 14:43:11 -0400143 // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is available.
144 if (mFunctions->invalidateSubFramebuffer)
145 {
146 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700147 mFunctions->invalidateSubFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count),
148 attachments, area.x, area.y, area.width, area.height);
Geoff Lang64a72442015-04-01 14:43:11 -0400149 }
150
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500151 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500152}
153
Jamie Madill8415b5f2016-04-26 13:41:39 -0400154Error FramebufferGL::clear(ContextImpl *context, GLbitfield mask)
Geoff Langf9a6f082015-01-22 13:32:49 -0500155{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400156 syncClearState(mask);
Geoff Lang4ad17092015-03-10 16:47:44 -0400157 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
158 mFunctions->clear(mask);
159
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500160 return Error(GL_NO_ERROR);
Geoff Lang4ad17092015-03-10 16:47:44 -0400161}
162
Jamie Madill8415b5f2016-04-26 13:41:39 -0400163Error FramebufferGL::clearBufferfv(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500164 GLenum buffer,
165 GLint drawbuffer,
166 const GLfloat *values)
Geoff Langf9a6f082015-01-22 13:32:49 -0500167{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400168 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400169 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
170 mFunctions->clearBufferfv(buffer, drawbuffer, values);
171
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500172 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500173}
174
Jamie Madill8415b5f2016-04-26 13:41:39 -0400175Error FramebufferGL::clearBufferuiv(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500176 GLenum buffer,
177 GLint drawbuffer,
178 const GLuint *values)
Geoff Langf9a6f082015-01-22 13:32:49 -0500179{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400180 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400181 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
182 mFunctions->clearBufferuiv(buffer, drawbuffer, values);
183
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500184 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500185}
186
Jamie Madill8415b5f2016-04-26 13:41:39 -0400187Error FramebufferGL::clearBufferiv(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500188 GLenum buffer,
189 GLint drawbuffer,
190 const GLint *values)
Geoff Langf9a6f082015-01-22 13:32:49 -0500191{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400192 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400193 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
194 mFunctions->clearBufferiv(buffer, drawbuffer, values);
195
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500196 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500197}
198
Jamie Madill8415b5f2016-04-26 13:41:39 -0400199Error FramebufferGL::clearBufferfi(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500200 GLenum buffer,
201 GLint drawbuffer,
202 GLfloat depth,
203 GLint stencil)
Geoff Langf9a6f082015-01-22 13:32:49 -0500204{
Geoff Langafd7f0a2015-09-09 15:33:31 -0400205 syncClearBufferState(buffer, drawbuffer);
Geoff Lang4ad17092015-03-10 16:47:44 -0400206 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
207 mFunctions->clearBufferfi(buffer, drawbuffer, depth, stencil);
208
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500209 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500210}
211
212GLenum FramebufferGL::getImplementationColorReadFormat() const
213{
Jamie Madilla3944d42016-07-22 22:13:26 -0400214 const auto *readAttachment = mState.getReadAttachment();
215 const Format &format = readAttachment->getFormat();
Geoff Langf607c602016-09-21 11:46:48 -0400216 return format.info->getReadPixelsFormat();
Geoff Langf9a6f082015-01-22 13:32:49 -0500217}
218
219GLenum FramebufferGL::getImplementationColorReadType() const
220{
Jamie Madilla3944d42016-07-22 22:13:26 -0400221 const auto *readAttachment = mState.getReadAttachment();
222 const Format &format = readAttachment->getFormat();
Geoff Langf607c602016-09-21 11:46:48 -0400223 return format.info->getReadPixelsType();
Geoff Langf9a6f082015-01-22 13:32:49 -0500224}
225
Jamie Madill8415b5f2016-04-26 13:41:39 -0400226Error FramebufferGL::readPixels(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500227 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 Madilldfde6ab2016-06-09 07:07:18 -0700234 const PixelPackState &packState = context->getGLState().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);
Geoff Langf607c602016-09-21 11:46:48 -0400238
239 nativegl::ReadPixelsFormat readPixelsFormat =
240 nativegl::GetReadPixelsFormat(mFunctions, mWorkarounds, format, type);
241 mFunctions->readPixels(area.x, area.y, area.width, area.height, readPixelsFormat.format,
242 readPixelsFormat.type, pixels);
Geoff Lang4ad17092015-03-10 16:47:44 -0400243
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500244 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500245}
246
Jamie Madill8415b5f2016-04-26 13:41:39 -0400247Error FramebufferGL::blit(ContextImpl *context,
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500248 const gl::Rectangle &sourceArea,
249 const gl::Rectangle &destArea,
250 GLbitfield mask,
Jamie Madill8415b5f2016-04-26 13:41:39 -0400251 GLenum filter)
Geoff Langf9a6f082015-01-22 13:32:49 -0500252{
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700253 const Framebuffer *sourceFramebuffer = context->getGLState().getReadFramebuffer();
Geoff Lang4ad17092015-03-10 16:47:44 -0400254 const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(sourceFramebuffer);
255
256 mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID());
257 mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebufferID);
258
Jamie Madill2da819e2015-12-03 15:53:19 -0500259 mFunctions->blitFramebuffer(sourceArea.x, sourceArea.y, sourceArea.x1(), sourceArea.y1(),
260 destArea.x, destArea.y, destArea.x1(), destArea.y1(), mask, filter);
Geoff Lang4ad17092015-03-10 16:47:44 -0400261
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500262 return Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500263}
264
Jamie Madillcc86d642015-11-24 13:00:07 -0500265bool FramebufferGL::checkStatus() const
Geoff Langf9a6f082015-01-22 13:32:49 -0500266{
Geoff Lang4ad17092015-03-10 16:47:44 -0400267 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
Jamie Madillcc86d642015-11-24 13:00:07 -0500268 GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
269 if (status != GL_FRAMEBUFFER_COMPLETE)
270 {
271 ANGLEPlatformCurrent()->logWarning("GL framebuffer returned incomplete.");
272 }
273 return (status == GL_FRAMEBUFFER_COMPLETE);
Geoff Lang4ad17092015-03-10 16:47:44 -0400274}
275
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500276void FramebufferGL::syncState(const Framebuffer::DirtyBits &dirtyBits)
277{
278 // Don't need to sync state for the default FBO.
279 if (mIsDefault)
280 {
281 return;
282 }
283
284 mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID);
285
286 for (auto dirtyBit : angle::IterateBitSet(dirtyBits))
287 {
288 switch (dirtyBit)
289 {
290 case Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT:
291 BindFramebufferAttachment(mFunctions, GL_DEPTH_ATTACHMENT,
Jamie Madill48ef11b2016-04-27 15:21:52 -0400292 mState.getDepthAttachment());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500293 break;
294 case Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT:
295 BindFramebufferAttachment(mFunctions, GL_STENCIL_ATTACHMENT,
Jamie Madill48ef11b2016-04-27 15:21:52 -0400296 mState.getStencilAttachment());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500297 break;
298 case Framebuffer::DIRTY_BIT_DRAW_BUFFERS:
299 {
Jamie Madill48ef11b2016-04-27 15:21:52 -0400300 const auto &drawBuffers = mState.getDrawBufferStates();
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500301 mFunctions->drawBuffers(static_cast<GLsizei>(drawBuffers.size()),
302 drawBuffers.data());
303 break;
304 }
305 case Framebuffer::DIRTY_BIT_READ_BUFFER:
Jamie Madill48ef11b2016-04-27 15:21:52 -0400306 mFunctions->readBuffer(mState.getReadBufferState());
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500307 break;
308 default:
309 {
310 ASSERT(Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 &&
311 dirtyBit < Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX);
312 size_t index =
313 static_cast<size_t>(dirtyBit - Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0);
314 BindFramebufferAttachment(mFunctions,
315 static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + index),
Jamie Madill48ef11b2016-04-27 15:21:52 -0400316 mState.getColorAttachment(index));
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500317 break;
318 }
319 }
320 }
321}
322
Geoff Lang4ad17092015-03-10 16:47:44 -0400323GLuint FramebufferGL::getFramebufferID() const
324{
325 return mFramebufferID;
Geoff Langf9a6f082015-01-22 13:32:49 -0500326}
327
Geoff Langafd7f0a2015-09-09 15:33:31 -0400328void FramebufferGL::syncDrawState() const
329{
330 if (mFunctions->standard == STANDARD_GL_DESKTOP)
331 {
332 // Enable SRGB blending for all framebuffers except the default framebuffer on Desktop
333 // OpenGL.
334 // When SRGB blending is enabled, only SRGB capable formats will use it but the default
335 // framebuffer will always use it if it is enabled.
336 // TODO(geofflang): Update this when the framebuffer binding dirty changes, when it exists.
337 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
338 }
339}
340
341void FramebufferGL::syncClearState(GLbitfield mask)
342{
Frank Henigmana3d333c2016-03-22 22:09:14 -0400343 if (mFunctions->standard == STANDARD_GL_DESKTOP)
Geoff Langafd7f0a2015-09-09 15:33:31 -0400344 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400345 if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments &&
346 (mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault)
Geoff Langafd7f0a2015-09-09 15:33:31 -0400347 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400348 bool hasSRBAttachment = false;
Jamie Madill48ef11b2016-04-27 15:21:52 -0400349 for (const auto &attachment : mState.getColorAttachments())
Geoff Langafd7f0a2015-09-09 15:33:31 -0400350 {
Frank Henigmana3d333c2016-03-22 22:09:14 -0400351 if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB)
352 {
353 hasSRBAttachment = true;
354 break;
355 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400356 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400357
Frank Henigmana3d333c2016-03-22 22:09:14 -0400358 mStateManager->setFramebufferSRGBEnabled(hasSRBAttachment);
359 }
360 else
361 {
362 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
363 }
Geoff Langafd7f0a2015-09-09 15:33:31 -0400364 }
365}
366
367void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer)
368{
369 if (mFunctions->standard == STANDARD_GL_DESKTOP)
370 {
371 if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && buffer == GL_COLOR &&
372 !mIsDefault)
373 {
374 // If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer
375 // is an SRGB format.
Jamie Madill48ef11b2016-04-27 15:21:52 -0400376 const auto &drawbufferState = mState.getDrawBufferStates();
377 const auto &colorAttachments = mState.getColorAttachments();
Geoff Langafd7f0a2015-09-09 15:33:31 -0400378
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500379 const FramebufferAttachment *attachment = nullptr;
Geoff Langafd7f0a2015-09-09 15:33:31 -0400380 if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 &&
381 drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size())
382 {
383 size_t attachmentIdx =
384 static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0);
385 attachment = &colorAttachments[attachmentIdx];
386 }
387
388 if (attachment != nullptr)
389 {
390 mStateManager->setFramebufferSRGBEnabled(attachment->getColorEncoding() == GL_SRGB);
391 }
392 }
393 else
394 {
395 mStateManager->setFramebufferSRGBEnabled(!mIsDefault);
396 }
397 }
398}
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500399} // namespace rx