Hash :
de09f8db
Author :
Date :
2021-09-02T18:21:37
Revert "GL: Update StateManagerGL binding funcs to use ANGLE_GL_TRY" This reverts commit 4b5a774e855af2493d64b0635f56053bd795c5c5. Reason for revert: broken on iOS and Skia Original change's description: > GL: Update StateManagerGL binding funcs to use ANGLE_GL_TRY > > Bug: angleproject:3020 > Change-Id: Iff460a1012d06e1c5feff84d91117de87e7c870a > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3123167 > Reviewed-by: Jamie Madill <jmadill@chromium.org> > Commit-Queue: Geoff Lang <geofflang@chromium.org> Bug: angleproject:3020 Change-Id: I54d81a7b734d007f65ff97990008f5e6eb8536f6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3140453 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
//
// Copyright 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ClearMultiviewGL:
// A helper for clearing multiview side-by-side and layered framebuffers.
//
#include "libANGLE/renderer/gl/ClearMultiviewGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/renderer/gl/TextureGL.h"
#include "libANGLE/Framebuffer.h"
namespace rx
{
ClearMultiviewGL::ClearMultiviewGL(const FunctionsGL *functions, StateManagerGL *stateManager)
: mFunctions(functions), mStateManager(stateManager), mFramebuffer(0u)
{}
ClearMultiviewGL::~ClearMultiviewGL()
{
if (mFramebuffer != 0u)
{
mFunctions->deleteFramebuffers(1, &mFramebuffer);
}
}
void ClearMultiviewGL::clearMultiviewFBO(const gl::FramebufferState &state,
const gl::Rectangle &scissorBase,
ClearCommandType clearCommandType,
GLbitfield mask,
GLenum buffer,
GLint drawbuffer,
const uint8_t *values,
GLfloat depth,
GLint stencil)
{
const gl::FramebufferAttachment *firstAttachment = state.getFirstNonNullAttachment();
if (firstAttachment->isMultiview())
{
clearLayeredFBO(state, clearCommandType, mask, buffer, drawbuffer, values, depth, stencil);
}
}
void ClearMultiviewGL::clearLayeredFBO(const gl::FramebufferState &state,
ClearCommandType clearCommandType,
GLbitfield mask,
GLenum buffer,
GLint drawbuffer,
const uint8_t *values,
GLfloat depth,
GLint stencil)
{
initializeResources();
mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer);
const gl::FramebufferAttachment *firstAttachment = state.getFirstNonNullAttachment();
ASSERT(firstAttachment->isMultiview());
const auto &drawBuffers = state.getDrawBufferStates();
mFunctions->drawBuffers(static_cast<GLsizei>(drawBuffers.size()), drawBuffers.data());
// Attach the new attachments and clear.
int numViews = firstAttachment->getNumViews();
int baseViewIndex = firstAttachment->getBaseViewIndex();
for (int i = 0; i < numViews; ++i)
{
attachTextures(state, baseViewIndex + i);
genericClear(clearCommandType, mask, buffer, drawbuffer, values, depth, stencil);
}
detachTextures(state);
}
void ClearMultiviewGL::genericClear(ClearCommandType clearCommandType,
GLbitfield mask,
GLenum buffer,
GLint drawbuffer,
const uint8_t *values,
GLfloat depth,
GLint stencil)
{
switch (clearCommandType)
{
case ClearCommandType::Clear:
mFunctions->clear(mask);
break;
case ClearCommandType::ClearBufferfv:
mFunctions->clearBufferfv(buffer, drawbuffer,
reinterpret_cast<const GLfloat *>(values));
break;
case ClearCommandType::ClearBufferuiv:
mFunctions->clearBufferuiv(buffer, drawbuffer,
reinterpret_cast<const GLuint *>(values));
break;
case ClearCommandType::ClearBufferiv:
mFunctions->clearBufferiv(buffer, drawbuffer, reinterpret_cast<const GLint *>(values));
break;
case ClearCommandType::ClearBufferfi:
mFunctions->clearBufferfi(buffer, drawbuffer, depth, stencil);
break;
default:
UNREACHABLE();
}
}
void ClearMultiviewGL::attachTextures(const gl::FramebufferState &state, int layer)
{
for (auto drawBufferId : state.getEnabledDrawBuffers())
{
const gl::FramebufferAttachment *attachment = state.getColorAttachment(drawBufferId);
if (attachment == nullptr)
{
continue;
}
const auto &imageIndex = attachment->getTextureImageIndex();
ASSERT(imageIndex.getType() == gl::TextureType::_2DArray);
GLenum colorAttachment =
static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + static_cast<int>(drawBufferId));
const TextureGL *textureGL = GetImplAs<TextureGL>(attachment->getTexture());
mFunctions->framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, colorAttachment,
textureGL->getTextureID(), imageIndex.getLevelIndex(),
layer);
}
const gl::FramebufferAttachment *depthStencilAttachment = state.getDepthStencilAttachment();
const gl::FramebufferAttachment *depthAttachment = state.getDepthAttachment();
const gl::FramebufferAttachment *stencilAttachment = state.getStencilAttachment();
if (depthStencilAttachment != nullptr)
{
const auto &imageIndex = depthStencilAttachment->getTextureImageIndex();
ASSERT(imageIndex.getType() == gl::TextureType::_2DArray);
const TextureGL *textureGL = GetImplAs<TextureGL>(depthStencilAttachment->getTexture());
mFunctions->framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
textureGL->getTextureID(), imageIndex.getLevelIndex(),
layer);
}
else if (depthAttachment != nullptr)
{
const auto &imageIndex = depthAttachment->getTextureImageIndex();
ASSERT(imageIndex.getType() == gl::TextureType::_2DArray);
const TextureGL *textureGL = GetImplAs<TextureGL>(depthAttachment->getTexture());
mFunctions->framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
textureGL->getTextureID(), imageIndex.getLevelIndex(),
layer);
}
else if (stencilAttachment != nullptr)
{
const auto &imageIndex = stencilAttachment->getTextureImageIndex();
ASSERT(imageIndex.getType() == gl::TextureType::_2DArray);
const TextureGL *textureGL = GetImplAs<TextureGL>(stencilAttachment->getTexture());
mFunctions->framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
textureGL->getTextureID(), imageIndex.getLevelIndex(),
layer);
}
}
void ClearMultiviewGL::detachTextures(const gl::FramebufferState &state)
{
for (auto drawBufferId : state.getEnabledDrawBuffers())
{
const gl::FramebufferAttachment *attachment = state.getColorAttachment(drawBufferId);
if (attachment == nullptr)
{
continue;
}
GLenum colorAttachment =
static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + static_cast<int>(drawBufferId));
mFunctions->framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, colorAttachment, 0, 0, 0);
}
const gl::FramebufferAttachment *depthStencilAttachment = state.getDepthStencilAttachment();
const gl::FramebufferAttachment *depthAttachment = state.getDepthAttachment();
const gl::FramebufferAttachment *stencilAttachment = state.getStencilAttachment();
if (depthStencilAttachment != nullptr)
{
mFunctions->framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, 0, 0,
0);
}
else if (depthAttachment != nullptr)
{
mFunctions->framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, 0, 0, 0);
}
else if (stencilAttachment != nullptr)
{
mFunctions->framebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, 0, 0, 0);
}
}
void ClearMultiviewGL::initializeResources()
{
if (mFramebuffer == 0u)
{
mFunctions->genFramebuffers(1, &mFramebuffer);
}
ASSERT(mFramebuffer != 0u);
}
} // namespace rx