Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gl/scoped_binders.h" | 5 #include "ui/gl/scoped_binders.h" |
| 6 #include "ui/gl/gl_bindings.h" | 6 #include "ui/gl/gl_bindings.h" |
| 7 #include "ui/gl/gl_context.h" | 7 #include "ui/gl/gl_context.h" |
| 8 #include "ui/gl/gl_state_restorer.h" | 8 #include "ui/gl/gl_state_restorer.h" |
| 9 #include "ui/gl/gl_version_info.h" | |
| 9 | 10 |
| 10 namespace gl { | 11 namespace gl { |
| 11 | 12 |
| 12 ScopedFrameBufferBinder::ScopedFrameBufferBinder(unsigned int fbo) | 13 ScopedFrameBufferBinder::ScopedFrameBufferBinder(unsigned int fbo) |
| 13 : state_restorer_(!GLContext::GetCurrent() | 14 : state_restorer_(!GLContext::GetCurrent() |
| 14 ? NULL | 15 ? NULL |
| 15 : GLContext::GetCurrent()->GetGLStateRestorer()), | 16 : GLContext::GetCurrent()->GetGLStateRestorer()), |
| 16 old_fbo_(-1) { | 17 old_fbo_(-1) { |
| 17 if (!state_restorer_) | 18 if (!state_restorer_) |
| 18 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo_); | 19 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo_); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 char normalized, | 94 char normalized, |
| 94 int stride, | 95 int stride, |
| 95 const void* pointer) | 96 const void* pointer) |
| 96 : buffer_(0), | 97 : buffer_(0), |
| 97 enabled_(GL_FALSE), | 98 enabled_(GL_FALSE), |
| 98 index_(index), | 99 index_(index), |
| 99 size_(-1), | 100 size_(-1), |
| 100 type_(-1), | 101 type_(-1), |
| 101 normalized_(GL_FALSE), | 102 normalized_(GL_FALSE), |
| 102 stride_(0), | 103 stride_(0), |
| 103 pointer_(0) { | 104 pointer_(0), |
| 104 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &buffer_); | 105 current_vao_(0u), |
| 105 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled_); | 106 vao_(0u) { |
| 107 const GLVersionInfo* version_info = GLContext::GetCurrent()->GetVersionInfo(); | |
| 108 if (version_info->IsAtLeastGL(3, 3) || version_info->IsAtLeastGLES(3, 0)) { | |
| 109 GLint value = 0; | |
| 110 glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &value); | |
| 111 current_vao_ = static_cast<unsigned>(value); | |
| 112 glGenVertexArraysOES(1, &vao_); | |
| 113 glBindVertexArrayOES(vao_); | |
|
piman
2016/08/18 00:44:50
The 2 paths are not really equivalent... the old p
Zhenyao Mo
2016/08/18 00:54:19
On ES3, there is a default vao, on desktop GL, the
piman
2016/08/18 00:57:46
On desktop only then? VAOs are not available on ES
Ken Russell (switch to Gerrit)
2016/08/18 01:32:52
It sounds good to me to modify the test rather tha
| |
| 114 } else { | |
| 115 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &buffer_); | |
| 116 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled_); | |
| 117 | |
| 118 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &size_); | |
| 119 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &type_); | |
| 120 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &normalized_); | |
| 121 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &stride_); | |
| 122 glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &pointer_); | |
| 123 } | |
| 124 | |
| 106 glEnableVertexAttribArray(index); | 125 glEnableVertexAttribArray(index); |
| 107 | |
| 108 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &size_); | |
| 109 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &type_); | |
| 110 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &normalized_); | |
| 111 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &stride_); | |
| 112 glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &pointer_); | |
| 113 | |
| 114 glVertexAttribPointer(index, size, type, normalized, stride, pointer); | 126 glVertexAttribPointer(index, size, type, normalized, stride, pointer); |
| 115 } | 127 } |
| 116 | 128 |
| 117 ScopedVertexAttribArray::~ScopedVertexAttribArray() { | 129 ScopedVertexAttribArray::~ScopedVertexAttribArray() { |
| 118 ScopedBufferBinder buffer_binder(GL_ARRAY_BUFFER, buffer_); | 130 if (vao_ > 0) { |
| 119 glVertexAttribPointer(index_, size_, type_, normalized_, stride_, pointer_); | 131 glBindVertexArrayOES(current_vao_); |
| 120 if (enabled_ == GL_FALSE) { | 132 glDeleteVertexArraysOES(1, &vao_); |
| 121 glDisableVertexAttribArray(index_); | 133 vao_ = 0u; |
| 134 } else { | |
| 135 ScopedBufferBinder buffer_binder(GL_ARRAY_BUFFER, buffer_); | |
| 136 glVertexAttribPointer(index_, size_, type_, normalized_, stride_, pointer_); | |
| 137 if (enabled_ == GL_FALSE) { | |
| 138 glDisableVertexAttribArray(index_); | |
| 139 } | |
| 122 } | 140 } |
| 123 } | 141 } |
| 124 | 142 |
| 125 ScopedBufferBinder::ScopedBufferBinder(unsigned int target, unsigned int id) | 143 ScopedBufferBinder::ScopedBufferBinder(unsigned int target, unsigned int id) |
| 126 : target_(target), old_id_(-1) { | 144 : target_(target), old_id_(-1) { |
| 127 GLenum target_getter = 0; | 145 GLenum target_getter = 0; |
| 128 switch (target) { | 146 switch (target) { |
| 129 case GL_ARRAY_BUFFER: | 147 case GL_ARRAY_BUFFER: |
| 130 target_getter = GL_ARRAY_BUFFER_BINDING; | 148 target_getter = GL_ARRAY_BUFFER_BINDING; |
| 131 break; | 149 break; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 188 |
| 171 ScopedCapability::~ScopedCapability() { | 189 ScopedCapability::~ScopedCapability() { |
| 172 if (enabled_ == GL_TRUE) { | 190 if (enabled_ == GL_TRUE) { |
| 173 glEnable(capability_); | 191 glEnable(capability_); |
| 174 } else { | 192 } else { |
| 175 glDisable(capability_); | 193 glDisable(capability_); |
| 176 } | 194 } |
| 177 } | 195 } |
| 178 | 196 |
| 179 } // namespace gl | 197 } // namespace gl |
| OLD | NEW |