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 "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "gpu/command_buffer/service/gl_utils.h" | 10 #include "gpu/command_buffer/service/gl_utils.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 211 } |
212 #endif | 212 #endif |
213 return true; | 213 return true; |
214 } | 214 } |
215 | 215 |
216 void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder, | 216 void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder, |
217 GLenum source_target, | 217 GLenum source_target, |
218 GLuint source_id, | 218 GLuint source_id, |
219 GLuint dest_id, | 219 GLuint dest_id, |
220 GLint dest_level, | 220 GLint dest_level, |
221 GLenum dest_internal_format, | |
222 GLsizei width, | 221 GLsizei width, |
223 GLsizei height, | 222 GLsizei height, |
224 GLuint framebuffer) { | 223 GLuint framebuffer) { |
225 DCHECK(source_target == GL_TEXTURE_2D || | 224 DCHECK(source_target == GL_TEXTURE_2D || |
226 source_target == GL_TEXTURE_RECTANGLE_ARB); | 225 source_target == GL_TEXTURE_RECTANGLE_ARB); |
227 if (BindFramebufferTexture2D( | 226 if (BindFramebufferTexture2D( |
228 source_target, source_id, 0 /* level */, framebuffer)) { | 227 source_target, source_id, 0 /* level */, framebuffer)) { |
229 glBindTexture(GL_TEXTURE_2D, dest_id); | 228 glBindTexture(GL_TEXTURE_2D, dest_id); |
230 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 229 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
231 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 230 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
232 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 231 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 232 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
234 glCopyTexImage2D(GL_TEXTURE_2D, | 233 glCopyTexSubImage2D(GL_TEXTURE_2D, dest_level, 0 /* xoffset */, |
235 dest_level, | 234 0 /* yoffset */, 0 /* x */, 0 /* y */, width, height); |
236 dest_internal_format, | |
237 0 /* x */, | |
238 0 /* y */, | |
239 width, | |
240 height, | |
241 0 /* border */); | |
242 } | 235 } |
243 | 236 |
244 decoder->RestoreTextureState(source_id); | 237 decoder->RestoreTextureState(source_id); |
245 decoder->RestoreTextureState(dest_id); | 238 decoder->RestoreTextureState(dest_id); |
246 decoder->RestoreTextureUnitBindings(0); | 239 decoder->RestoreTextureUnitBindings(0); |
247 decoder->RestoreActiveTexture(); | 240 decoder->RestoreActiveTexture(); |
248 decoder->RestoreFramebufferBindings(); | 241 decoder->RestoreFramebufferBindings(); |
249 } | 242 } |
250 | 243 |
251 } // namespace | 244 } // namespace |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 bool premultiply_alpha, | 318 bool premultiply_alpha, |
326 bool unpremultiply_alpha) { | 319 bool unpremultiply_alpha) { |
327 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; | 320 bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha; |
328 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's | 321 // GL_INVALID_OPERATION is generated if the currently bound framebuffer's |
329 // format does not contain a superset of the components required by the base | 322 // format does not contain a superset of the components required by the base |
330 // format of internalformat. | 323 // format of internalformat. |
331 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml | 324 // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glCopyTexImage2D.xml |
332 bool source_format_contain_superset_of_dest_format = | 325 bool source_format_contain_superset_of_dest_format = |
333 source_internal_format == dest_internal_format || | 326 source_internal_format == dest_internal_format || |
334 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); | 327 (source_internal_format == GL_RGBA && dest_internal_format == GL_RGB); |
335 // GL_TEXTURE_RECTANGLE_ARB on FBO is supported by OpenGL, not GLES2, | 328 bool source_target_allowed = source_target == GL_TEXTURE_2D || |
336 // so restrict this to GL_TEXTURE_2D. | 329 source_target == GL_TEXTURE_RECTANGLE_ARB; |
337 if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change && | 330 if (source_target_allowed && !flip_y && !premultiply_alpha_change && |
338 source_format_contain_superset_of_dest_format) { | 331 source_format_contain_superset_of_dest_format) { |
339 DoCopyTexImage2D(decoder, | 332 DoCopyTexImage2D(decoder, |
340 source_target, | 333 source_target, |
341 source_id, | 334 source_id, |
342 dest_id, | 335 dest_id, |
343 dest_level, | 336 dest_level, |
344 dest_internal_format, | |
345 width, | 337 width, |
346 height, | 338 height, |
347 framebuffer_); | 339 framebuffer_); |
348 return; | 340 return; |
349 } | 341 } |
350 | 342 |
351 // Use default transform matrix if no transform passed in. | 343 // Use default transform matrix if no transform passed in. |
352 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, | 344 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
353 0.0f, 1.0f, 0.0f, 0.0f, | 345 0.0f, 1.0f, 0.0f, 0.0f, |
354 0.0f, 0.0f, 1.0f, 0.0f, | 346 0.0f, 0.0f, 1.0f, 0.0f, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 decoder->RestoreTextureState(dest_id); | 465 decoder->RestoreTextureState(dest_id); |
474 decoder->RestoreTextureUnitBindings(0); | 466 decoder->RestoreTextureUnitBindings(0); |
475 decoder->RestoreActiveTexture(); | 467 decoder->RestoreActiveTexture(); |
476 decoder->RestoreProgramBindings(); | 468 decoder->RestoreProgramBindings(); |
477 decoder->RestoreBufferBindings(); | 469 decoder->RestoreBufferBindings(); |
478 decoder->RestoreFramebufferBindings(); | 470 decoder->RestoreFramebufferBindings(); |
479 decoder->RestoreGlobalState(); | 471 decoder->RestoreGlobalState(); |
480 } | 472 } |
481 | 473 |
482 } // namespace gpu | 474 } // namespace gpu |
OLD | NEW |