OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h" |
6 | 6 |
7 #include "gpu/command_buffer/service/gl_utils.h" | 7 #include "gpu/command_buffer/service/gl_utils.h" |
8 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 8 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
9 #include "ui/gfx/geometry/size.h" | 9 #include "ui/gfx/geometry/size.h" |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 DLOG(ERROR) << "Shader compilation failure."; | 49 DLOG(ERROR) << "Shader compilation failure."; |
50 } | 50 } |
51 #endif | 51 #endif |
52 } | 52 } |
53 | 53 |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 namespace gpu { | 56 namespace gpu { |
57 | 57 |
58 ClearFramebufferResourceManager::ClearFramebufferResourceManager( | 58 ClearFramebufferResourceManager::ClearFramebufferResourceManager( |
59 const gles2::GLES2Decoder* decoder) | 59 const gles2::GLES2Decoder* decoder, |
60 : initialized_(false), program_(0u), buffer_id_(0u) { | 60 const gles2::FeatureInfo::FeatureFlags& feature_flags) |
61 Initialize(decoder); | 61 : initialized_(false), program_(0u), vao_(0), buffer_id_(0u) { |
| 62 Initialize(decoder, feature_flags); |
62 } | 63 } |
63 | 64 |
64 ClearFramebufferResourceManager::~ClearFramebufferResourceManager() { | 65 ClearFramebufferResourceManager::~ClearFramebufferResourceManager() { |
65 Destroy(); | 66 Destroy(); |
66 DCHECK(!buffer_id_); | 67 DCHECK(!buffer_id_); |
67 } | 68 } |
68 | 69 |
69 void ClearFramebufferResourceManager::Initialize( | 70 void ClearFramebufferResourceManager::Initialize( |
70 const gles2::GLES2Decoder* decoder) { | 71 const gles2::GLES2Decoder* decoder, |
| 72 const gles2::FeatureInfo::FeatureFlags& feature_flags) { |
71 static_assert( | 73 static_assert( |
72 kVertexPositionAttrib == 0u, | 74 kVertexPositionAttrib == 0u, |
73 "kVertexPositionAttrib must be 0"); | 75 "kVertexPositionAttrib must be 0"); |
| 76 |
74 DCHECK(!buffer_id_); | 77 DCHECK(!buffer_id_); |
75 | |
76 glGenBuffersARB(1, &buffer_id_); | 78 glGenBuffersARB(1, &buffer_id_); |
77 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); | 79 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); |
78 const GLfloat kQuadVertices[] = {-1.0f, -1.0f, | 80 const GLfloat kQuadVertices[] = {-1.0f, -1.0f, |
79 1.0f, -1.0f, | 81 1.0f, -1.0f, |
80 1.0f, 1.0f, | 82 1.0f, 1.0f, |
81 -1.0f, 1.0f}; | 83 -1.0f, 1.0f}; |
82 glBufferData( | 84 glBufferData( |
83 GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW); | 85 GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW); |
| 86 |
| 87 DCHECK(!vao_); |
| 88 |
| 89 if (feature_flags.native_vertex_array_object) { |
| 90 glGenVertexArraysOES(1, &vao_); |
| 91 |
| 92 glBindVertexArrayOES(vao_); |
| 93 glEnableVertexAttribArray(kVertexPositionAttrib); |
| 94 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); |
| 95 |
| 96 decoder->RestoreAllAttributes(); |
| 97 } |
| 98 |
84 decoder->RestoreBufferBindings(); | 99 decoder->RestoreBufferBindings(); |
85 initialized_ = true; | 100 initialized_ = true; |
86 } | 101 } |
87 | 102 |
88 void ClearFramebufferResourceManager::Destroy() { | 103 void ClearFramebufferResourceManager::Destroy() { |
89 if (!initialized_) | 104 if (!initialized_) |
90 return; | 105 return; |
91 | 106 |
92 glDeleteProgram(program_); | 107 glDeleteProgram(program_); |
| 108 |
| 109 if (vao_ != 0) { |
| 110 glDeleteVertexArraysOES(1, &vao_); |
| 111 vao_ = 0; |
| 112 } |
| 113 |
93 glDeleteBuffersARB(1, &buffer_id_); | 114 glDeleteBuffersARB(1, &buffer_id_); |
94 buffer_id_ = 0; | 115 buffer_id_ = 0; |
95 } | 116 } |
96 | 117 |
97 void ClearFramebufferResourceManager::ClearFramebuffer( | 118 void ClearFramebufferResourceManager::ClearFramebuffer( |
98 const gles2::GLES2Decoder* decoder, | 119 const gles2::GLES2Decoder* decoder, |
99 const gfx::Size& framebuffer_size, | 120 const gfx::Size& framebuffer_size, |
100 GLbitfield mask, | 121 GLbitfield mask, |
101 GLfloat clear_color_red, | 122 GLfloat clear_color_red, |
102 GLfloat clear_color_green, | 123 GLfloat clear_color_green, |
(...skipping 30 matching lines...) Expand all Loading... |
133 glUseProgram(program_); | 154 glUseProgram(program_); |
134 | 155 |
135 #if DCHECK_IS_ON() | 156 #if DCHECK_IS_ON() |
136 glValidateProgram(program_); | 157 glValidateProgram(program_); |
137 GLint validation_status = GL_FALSE; | 158 GLint validation_status = GL_FALSE; |
138 glGetProgramiv(program_, GL_VALIDATE_STATUS, &validation_status); | 159 glGetProgramiv(program_, GL_VALIDATE_STATUS, &validation_status); |
139 if (GL_TRUE != validation_status) | 160 if (GL_TRUE != validation_status) |
140 DLOG(ERROR) << "Invalid shader."; | 161 DLOG(ERROR) << "Invalid shader."; |
141 #endif | 162 #endif |
142 | 163 |
143 decoder->ClearAllAttributes(); | 164 if (vao_) { |
144 glEnableVertexAttribArray(kVertexPositionAttrib); | 165 glBindVertexArrayOES(vao_); |
145 | 166 } else { |
146 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); | 167 decoder->ClearAllAttributes(); |
147 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); | 168 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); |
| 169 glEnableVertexAttribArray(kVertexPositionAttrib); |
| 170 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); |
| 171 } |
148 | 172 |
149 glUniform1f(depth_handle_, clear_depth_value); | 173 glUniform1f(depth_handle_, clear_depth_value); |
150 glUniform4f(color_handle_, clear_color_red, clear_color_green, | 174 glUniform4f(color_handle_, clear_color_red, clear_color_green, |
151 clear_color_blue, clear_color_alpha); | 175 clear_color_blue, clear_color_alpha); |
152 | 176 |
153 if (!(mask & GL_COLOR_BUFFER_BIT)) { | 177 if (!(mask & GL_COLOR_BUFFER_BIT)) { |
154 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); | 178 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
155 } | 179 } |
156 | 180 |
157 if (mask & GL_DEPTH_BUFFER_BIT) { | 181 if (mask & GL_DEPTH_BUFFER_BIT) { |
(...skipping 14 matching lines...) Expand all Loading... |
172 glStencilMask(0); | 196 glStencilMask(0); |
173 } | 197 } |
174 | 198 |
175 glDisable(GL_CULL_FACE); | 199 glDisable(GL_CULL_FACE); |
176 glDisable(GL_BLEND); | 200 glDisable(GL_BLEND); |
177 glDisable(GL_POLYGON_OFFSET_FILL); | 201 glDisable(GL_POLYGON_OFFSET_FILL); |
178 | 202 |
179 glViewport(0, 0, framebuffer_size.width(), framebuffer_size.height()); | 203 glViewport(0, 0, framebuffer_size.width(), framebuffer_size.height()); |
180 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 204 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
181 | 205 |
| 206 if (vao_ == 0) { |
| 207 decoder->RestoreBufferBindings(); |
| 208 } |
182 decoder->RestoreAllAttributes(); | 209 decoder->RestoreAllAttributes(); |
183 decoder->RestoreProgramBindings(); | 210 decoder->RestoreProgramBindings(); |
184 decoder->RestoreBufferBindings(); | |
185 decoder->RestoreGlobalState(); | 211 decoder->RestoreGlobalState(); |
186 } | 212 } |
187 | 213 |
188 } // namespace gpu | 214 } // namespace gpu |
OLD | NEW |