Chromium Code Reviews| Index: ui/gl/scoped_binders.cc |
| diff --git a/ui/gl/scoped_binders.cc b/ui/gl/scoped_binders.cc |
| index bb2b290105622a9823b49b284d6bbd72aa6f36bc..74d541314353002b52d9c4d968955cd1f016bd4c 100644 |
| --- a/ui/gl/scoped_binders.cc |
| +++ b/ui/gl/scoped_binders.cc |
| @@ -29,6 +29,16 @@ ScopedFrameBufferBinder::~ScopedFrameBufferBinder() { |
| } |
| } |
| +ScopedActiveTexture::ScopedActiveTexture(unsigned int texture) |
| + : old_texture_(-1) { |
| + glGetIntegerv(GL_ACTIVE_TEXTURE, &old_texture_); |
| + glActiveTexture(texture); |
| +} |
| + |
| +ScopedActiveTexture::~ScopedActiveTexture() { |
| + glActiveTexture(old_texture_); |
| +} |
| + |
| ScopedTextureBinder::ScopedTextureBinder(unsigned int target, unsigned int id) |
| : state_restorer_(!GLContext::GetCurrent() |
| ? NULL |
| @@ -47,8 +57,11 @@ ScopedTextureBinder::ScopedTextureBinder(unsigned int target, unsigned int id) |
| case GL_TEXTURE_EXTERNAL_OES: |
| target_getter = GL_TEXTURE_BINDING_EXTERNAL_OES; |
| break; |
| + case GL_TEXTURE_RECTANGLE_ARB: |
| + target_getter = GL_TEXTURE_BINDING_RECTANGLE_ARB; |
| + break; |
| default: |
| - NOTIMPLEMENTED() << "Target not part of OpenGL ES 2.0 spec."; |
| + NOTIMPLEMENTED() << " Target not supported."; |
| } |
| glGetIntegerv(target_getter, &old_id_); |
| } |
| @@ -65,4 +78,105 @@ ScopedTextureBinder::~ScopedTextureBinder() { |
| } |
| } |
| +ScopedUseProgram::ScopedUseProgram(unsigned int program) : old_program_(-1) { |
| + glGetIntegerv(GL_CURRENT_PROGRAM, &old_program_); |
| + glUseProgram(program); |
| +} |
| + |
| +ScopedUseProgram::~ScopedUseProgram() { |
| + glUseProgram(old_program_); |
| +} |
| + |
| +ScopedVertexAttribArray::ScopedVertexAttribArray(unsigned int index, |
| + int size, |
| + unsigned int type, |
| + char normalized, |
| + int stride, |
| + const void* pointer) |
| + : enabled_(GL_FALSE), |
| + index_(index), |
| + size_(-1), |
| + type_(-1), |
| + normalized_(GL_FALSE), |
| + stride_(0), |
| + pointer_(0) { |
| + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled_); |
| + glEnableVertexAttribArray(index); |
| + |
| + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &size_); |
| + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &type_); |
| + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &normalized_); |
| + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &stride_); |
| + glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &pointer_); |
| + |
| + glVertexAttribPointer(index, size, type, normalized, stride, pointer); |
| +} |
| + |
| +ScopedVertexAttribArray::~ScopedVertexAttribArray() { |
| + glVertexAttribPointer(index_, size_, type_, normalized_, stride_, pointer_); |
|
piman
2015/11/04 22:49:45
So this one is a little tricky, because there's an
Daniele Castagna
2015/12/03 23:12:08
Done.
|
| + if (enabled_ == GL_FALSE) { |
| + glDisableVertexAttribArray(index_); |
| + } |
| +} |
| + |
| +ScopedBufferBinder::ScopedBufferBinder(unsigned int target, unsigned int id) |
| + : target_(target), old_id_(-1) { |
| + GLenum target_getter = 0; |
| + switch (target) { |
| + case GL_ARRAY_BUFFER: |
| + target_getter = GL_ARRAY_BUFFER_BINDING; |
| + break; |
| + default: |
| + NOTIMPLEMENTED() << " Target not supported."; |
| + } |
| + glGetIntegerv(target_getter, &old_id_); |
| + glBindBuffer(target_, id); |
| +} |
| + |
| +ScopedBufferBinder::~ScopedBufferBinder() { |
| + glBindBuffer(target_, old_id_); |
| +} |
| + |
| +ScopedViewport::ScopedViewport(int x, int y, int width, int height) { |
| + glGetIntegerv(GL_VIEWPORT, data_); |
| + glViewport(x, y, width, height); |
| +} |
| + |
| +ScopedViewport::~ScopedViewport() { |
| + glViewport(data_[0], data_[1], data_[2], data_[3]); |
| +} |
| + |
| +ScopedColorMask::ScopedColorMask(char red, char green, char blue, char alpha) { |
| + glGetBooleanv(GL_COLOR_WRITEMASK, colors_); |
| + glColorMask(red, green, blue, alpha); |
| +} |
| + |
| +ScopedColorMask::~ScopedColorMask() { |
| + glColorMask(colors_[0], colors_[1], colors_[2], colors_[3]); |
| +} |
| + |
| +// static |
| +GLenum ScopedCapabilitiesRestorer::kCapabilities[] = { |
| + GL_BLEND, GL_CULL_FACE, GL_DEPTH_TEST, |
| + GL_DITHER, GL_POLYGON_OFFSET_FILL, GL_SAMPLE_ALPHA_TO_COVERAGE, |
|
piman
2015/11/04 22:49:45
- polygon offset shouldn't matter since you disabl
Daniele Castagna
2015/12/03 23:12:08
Ack.
This ScopedCapabilitiesRestorer could be used
piman
2015/12/04 00:02:16
Sure, but why these ones and not others too? E.g.
Daniele Castagna
2015/12/04 00:40:18
Not sure why I left GL_SAMPLE_COVERAGE out. My int
|
| + GL_SCISSOR_TEST, GL_STENCIL_TEST}; |
| + |
| +ScopedCapabilitiesRestorer::ScopedCapabilitiesRestorer() { |
| + static_assert(arraysize(kCapabilities) <= arraysize(enabled_), |
| + "enabled_ array size should be at least kCapabilities size. "); |
| + for (size_t i = 0; i < arraysize(kCapabilities); ++i) { |
| + enabled_[i] = glIsEnabled(kCapabilities[i]); |
| + } |
| +} |
| + |
| +ScopedCapabilitiesRestorer::~ScopedCapabilitiesRestorer() { |
| + for (size_t i = 0; i < arraysize(kCapabilities); ++i) { |
| + if (enabled_[i] == GL_TRUE) { |
| + glEnable(kCapabilities[i]); |
| + } else { |
| + glDisable(kCapabilities[i]); |
| + } |
| + } |
| +} |
| + |
| } // namespace gfx |