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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 DCHECK(!buffer_id_); | 66 DCHECK(!buffer_id_); |
67 } | 67 } |
68 | 68 |
69 void ClearFramebufferResourceManager::Initialize( | 69 void ClearFramebufferResourceManager::Initialize( |
70 const gles2::GLES2Decoder* decoder) { | 70 const gles2::GLES2Decoder* decoder) { |
71 static_assert( | 71 static_assert( |
72 kVertexPositionAttrib == 0u, | 72 kVertexPositionAttrib == 0u, |
73 "kVertexPositionAttrib must be 0"); | 73 "kVertexPositionAttrib must be 0"); |
74 DCHECK(!buffer_id_); | 74 DCHECK(!buffer_id_); |
75 | 75 |
76 glGenVertexArraysOES(1, &vao_); | |
Zhenyao Mo
2016/06/20 21:16:20
initialize vao_ to 0 in constructor. and dcheck it
| |
77 | |
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); |
84 decoder->RestoreBufferBindings(); | 86 decoder->RestoreBufferBindings(); |
85 initialized_ = true; | 87 initialized_ = true; |
86 } | 88 } |
87 | 89 |
88 void ClearFramebufferResourceManager::Destroy() { | 90 void ClearFramebufferResourceManager::Destroy() { |
89 if (!initialized_) | 91 if (!initialized_) |
90 return; | 92 return; |
91 | 93 |
92 glDeleteProgram(program_); | 94 glDeleteProgram(program_); |
95 glDeleteVertexArraysOES(1, &vao_); | |
Zhenyao Mo
2016/06/20 21:16:20
Also set vao_ to 0 like buffer_id_
| |
93 glDeleteBuffersARB(1, &buffer_id_); | 96 glDeleteBuffersARB(1, &buffer_id_); |
94 buffer_id_ = 0; | 97 buffer_id_ = 0; |
95 } | 98 } |
96 | 99 |
97 void ClearFramebufferResourceManager::ClearFramebuffer( | 100 void ClearFramebufferResourceManager::ClearFramebuffer( |
98 const gles2::GLES2Decoder* decoder, | 101 const gles2::GLES2Decoder* decoder, |
99 const gfx::Size& framebuffer_size, | 102 const gfx::Size& framebuffer_size, |
100 GLbitfield mask, | 103 GLbitfield mask, |
101 GLfloat clear_color_red, | 104 GLfloat clear_color_red, |
102 GLfloat clear_color_green, | 105 GLfloat clear_color_green, |
(...skipping 30 matching lines...) Expand all Loading... | |
133 glUseProgram(program_); | 136 glUseProgram(program_); |
134 | 137 |
135 #if DCHECK_IS_ON() | 138 #if DCHECK_IS_ON() |
136 glValidateProgram(program_); | 139 glValidateProgram(program_); |
137 GLint validation_status = GL_FALSE; | 140 GLint validation_status = GL_FALSE; |
138 glGetProgramiv(program_, GL_VALIDATE_STATUS, &validation_status); | 141 glGetProgramiv(program_, GL_VALIDATE_STATUS, &validation_status); |
139 if (GL_TRUE != validation_status) | 142 if (GL_TRUE != validation_status) |
140 DLOG(ERROR) << "Invalid shader."; | 143 DLOG(ERROR) << "Invalid shader."; |
141 #endif | 144 #endif |
142 | 145 |
143 decoder->ClearAllAttributes(); | 146 glBindVertexArrayOES(vao_); |
144 glEnableVertexAttribArray(kVertexPositionAttrib); | 147 glEnableVertexAttribArray(kVertexPositionAttrib); |
Zhenyao Mo
2016/06/20 21:16:20
Shouldn't you also set all the vao states up in In
| |
145 | 148 |
146 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); | 149 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); |
147 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); | 150 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); |
148 | 151 |
149 glUniform1f(depth_handle_, clear_depth_value); | 152 glUniform1f(depth_handle_, clear_depth_value); |
150 glUniform4f(color_handle_, clear_color_red, clear_color_green, | 153 glUniform4f(color_handle_, clear_color_red, clear_color_green, |
151 clear_color_blue, clear_color_alpha); | 154 clear_color_blue, clear_color_alpha); |
152 | 155 |
153 if (!(mask & GL_COLOR_BUFFER_BIT)) { | 156 if (!(mask & GL_COLOR_BUFFER_BIT)) { |
154 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); | 157 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
(...skipping 17 matching lines...) Expand all Loading... | |
172 glStencilMask(0); | 175 glStencilMask(0); |
173 } | 176 } |
174 | 177 |
175 glDisable(GL_CULL_FACE); | 178 glDisable(GL_CULL_FACE); |
176 glDisable(GL_BLEND); | 179 glDisable(GL_BLEND); |
177 glDisable(GL_POLYGON_OFFSET_FILL); | 180 glDisable(GL_POLYGON_OFFSET_FILL); |
178 | 181 |
179 glViewport(0, 0, framebuffer_size.width(), framebuffer_size.height()); | 182 glViewport(0, 0, framebuffer_size.width(), framebuffer_size.height()); |
180 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 183 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
181 | 184 |
182 decoder->RestoreAllAttributes(); | 185 decoder->RestoreAllAttributes(); |
Zhenyao Mo
2016/06/20 21:16:20
This seems like an over kill. You just need to res
| |
183 decoder->RestoreProgramBindings(); | 186 decoder->RestoreProgramBindings(); |
184 decoder->RestoreBufferBindings(); | 187 decoder->RestoreBufferBindings(); |
185 decoder->RestoreGlobalState(); | 188 decoder->RestoreGlobalState(); |
186 } | 189 } |
187 | 190 |
188 } // namespace gpu | 191 } // namespace gpu |
OLD | NEW |