Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc

Issue 1275773003: gpu: support GL_TEXTURE_CUBE_MAP destination target to Copy(Sub)TextureCHROMIUM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Choose correct and expensive way Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc
diff --git a/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc b/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc
index 846ac0d6a12b9be9218a3d26a2a866fc87c67292..45677d2b9e8e7b145f72e17b250feda21a3b44be 100644
--- a/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc
+++ b/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/basictypes.h"
+#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/service/gl_utils.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
@@ -200,15 +201,19 @@ void DeleteShader(GLuint shader) {
bool BindFramebufferTexture2D(GLenum target,
GLuint texture_id,
GLuint framebuffer) {
- DCHECK(target == GL_TEXTURE_2D || target == GL_TEXTURE_RECTANGLE_ARB);
+ GLenum binding_target =
+ gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(target);
+ DCHECK(binding_target == GL_TEXTURE_2D ||
+ binding_target == GL_TEXTURE_RECTANGLE_ARB ||
+ binding_target == GL_TEXTURE_CUBE_MAP);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(target, texture_id);
+ glBindTexture(binding_target, texture_id);
// NVidia drivers require texture settings to be a certain way
// or they won't report FRAMEBUFFER_COMPLETE.
- glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(binding_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(binding_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(binding_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(binding_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
texture_id, 0);
@@ -226,6 +231,7 @@ bool BindFramebufferTexture2D(GLenum target,
void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder,
GLenum source_target,
GLuint source_id,
+ GLenum dest_target,
GLuint dest_id,
GLenum dest_internal_format,
GLsizei width,
@@ -234,12 +240,14 @@ void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder,
DCHECK(source_target == GL_TEXTURE_2D ||
source_target == GL_TEXTURE_RECTANGLE_ARB);
if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) {
- glBindTexture(GL_TEXTURE_2D, dest_id);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glCopyTexImage2D(GL_TEXTURE_2D, 0 /* level */, dest_internal_format,
+ GLenum binding_target =
+ gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
+ glBindTexture(binding_target, dest_id);
+ glTexParameterf(binding_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(binding_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(binding_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(binding_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glCopyTexImage2D(dest_target, 0 /* level */, dest_internal_format,
0 /* x */, 0 /* y */, width, height, 0 /* border */);
}
@@ -253,6 +261,7 @@ void DoCopyTexImage2D(const gpu::gles2::GLES2Decoder* decoder,
void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder,
GLenum source_target,
GLuint source_id,
+ GLenum dest_target,
GLuint dest_id,
GLint xoffset,
GLint yoffset,
@@ -264,13 +273,15 @@ void DoCopyTexSubImage2D(const gpu::gles2::GLES2Decoder* decoder,
DCHECK(source_target == GL_TEXTURE_2D ||
source_target == GL_TEXTURE_RECTANGLE_ARB);
if (BindFramebufferTexture2D(source_target, source_id, framebuffer)) {
- glBindTexture(GL_TEXTURE_2D, dest_id);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0 /* level */, xoffset, yoffset,
- source_x, source_y, source_width, source_height);
+ GLenum binding_target =
+ gpu::gles2::GLES2Util::GLTextureTargetToBindingTarget(dest_target);
+ glBindTexture(binding_target, dest_id);
+ glTexParameterf(binding_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(binding_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(binding_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(binding_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glCopyTexSubImage2D(dest_target, 0 /* level */, xoffset, yoffset, source_x,
+ source_y, source_width, source_height);
}
decoder->RestoreTextureState(source_id);
@@ -317,6 +328,7 @@ void CopyTextureCHROMIUMResourceManager::Initialize(
GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW);
glGenFramebuffersEXT(1, &framebuffer_);
+ glGenTextures(1, &staging_testure_);
decoder->RestoreBufferBindings();
@@ -330,6 +342,9 @@ void CopyTextureCHROMIUMResourceManager::Destroy() {
glDeleteFramebuffersEXT(1, &framebuffer_);
framebuffer_ = 0;
+ glDeleteTextures(1, &staging_testure_);
+ staging_testure_ = 0;
+
std::for_each(vertex_shaders_.begin(), vertex_shaders_.end(), DeleteShader);
std::for_each(
fragment_shaders_.begin(), fragment_shaders_.end(), DeleteShader);
@@ -349,13 +364,16 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTexture(
GLenum source_target,
GLuint source_id,
GLenum source_internal_format,
+ GLenum dest_target,
GLuint dest_id,
GLenum dest_internal_format,
+ GLenum dest_type,
GLsizei width,
GLsizei height,
bool flip_y,
bool premultiply_alpha,
- bool unpremultiply_alpha) {
+ bool unpremultiply_alpha,
+ bool dest_cube_complete) {
bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha;
// GL_INVALID_OPERATION is generated if the currently bound framebuffer's
// format does not contain a superset of the components required by the base
@@ -369,21 +387,16 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTexture(
// so restrict this to GL_TEXTURE_2D.
if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change &&
source_format_contain_superset_of_dest_format) {
- DoCopyTexImage2D(decoder,
- source_target,
- source_id,
- dest_id,
- dest_internal_format,
- width,
- height,
- framebuffer_);
+ DoCopyTexImage2D(decoder, source_target, source_id, dest_target, dest_id,
+ dest_internal_format, width, height, framebuffer_);
return;
}
// Use kIdentityMatrix if no transform passed in.
- DoCopyTextureWithTransform(decoder, source_target, source_id, dest_id, width,
- height, flip_y, premultiply_alpha,
- unpremultiply_alpha, kIdentityMatrix);
+ DoCopyTextureWithTransform(
+ decoder, source_target, source_id, dest_target, dest_id,
+ dest_internal_format, dest_type, width, height, flip_y, premultiply_alpha,
+ unpremultiply_alpha, dest_cube_complete, kIdentityMatrix);
}
void CopyTextureCHROMIUMResourceManager::DoCopySubTexture(
@@ -391,8 +404,10 @@ void CopyTextureCHROMIUMResourceManager::DoCopySubTexture(
GLenum source_target,
GLuint source_id,
GLenum source_internal_format,
+ GLenum dest_target,
GLuint dest_id,
GLenum dest_internal_format,
+ GLenum dest_type,
GLint xoffset,
GLint yoffset,
GLint x,
@@ -405,7 +420,8 @@ void CopyTextureCHROMIUMResourceManager::DoCopySubTexture(
GLsizei source_height,
bool flip_y,
bool premultiply_alpha,
- bool unpremultiply_alpha) {
+ bool unpremultiply_alpha,
+ bool dest_cube_complete) {
bool premultiply_alpha_change = premultiply_alpha ^ unpremultiply_alpha;
// GL_INVALID_OPERATION is generated if the currently bound framebuffer's
// format does not contain a superset of the components required by the base
@@ -419,40 +435,77 @@ void CopyTextureCHROMIUMResourceManager::DoCopySubTexture(
// so restrict this to GL_TEXTURE_2D.
if (source_target == GL_TEXTURE_2D && !flip_y && !premultiply_alpha_change &&
source_format_contain_superset_of_dest_format) {
- DoCopyTexSubImage2D(decoder, source_target, source_id, dest_id, xoffset,
- yoffset, x, y, width, height, framebuffer_);
+ DoCopyTexSubImage2D(decoder, source_target, source_id, dest_target, dest_id,
+ xoffset, yoffset, x, y, width, height, framebuffer_);
+ return;
+ }
+
+ if (!dest_cube_complete) {
+ glBindTexture(GL_TEXTURE_2D, staging_testure_);
+ glTexImage2D(GL_TEXTURE_2D, 0, dest_internal_format, width, height, 0,
+ dest_internal_format, dest_type, nullptr);
+ DoCopyTextureInternal(
+ decoder, source_target, source_id, GL_TEXTURE_2D, staging_testure_, 0,
+ 0, x, y, width, height, width, height, source_width, source_height,
+ flip_y, premultiply_alpha, unpremultiply_alpha, kIdentityMatrix);
+ DoCopyTexSubImage2D(decoder, GL_TEXTURE_2D, staging_testure_, dest_target,
Ken Russell (switch to Gerrit) 2015/08/18 00:33:02 The staging_texture_ will stick around after this,
dshwang 2015/08/18 14:42:01 Acknowledged.
+ dest_id, xoffset, yoffset, 0, 0, width, height,
+ framebuffer_);
return;
}
- DoCopyTextureInternal(decoder, source_target, source_id, dest_id, xoffset,
- yoffset, x, y, width, height, dest_width, dest_height,
- source_width, source_height, flip_y, premultiply_alpha,
- unpremultiply_alpha, kIdentityMatrix);
+ DoCopyTextureInternal(
+ decoder, source_target, source_id, dest_target, dest_id, xoffset, yoffset,
+ x, y, width, height, dest_width, dest_height, source_width, source_height,
+ flip_y, premultiply_alpha, unpremultiply_alpha, kIdentityMatrix);
}
void CopyTextureCHROMIUMResourceManager::DoCopyTextureWithTransform(
const gles2::GLES2Decoder* decoder,
GLenum source_target,
GLuint source_id,
+ GLenum dest_target,
GLuint dest_id,
+ GLenum dest_internal_format,
+ GLenum dest_type,
GLsizei width,
GLsizei height,
bool flip_y,
bool premultiply_alpha,
bool unpremultiply_alpha,
+ bool dest_cube_complete,
const GLfloat transform_matrix[16]) {
GLsizei dest_width = width;
GLsizei dest_height = height;
- DoCopyTextureInternal(decoder, source_target, source_id, dest_id, 0, 0, 0, 0,
- width, height, dest_width, dest_height, width, height,
- flip_y, premultiply_alpha, unpremultiply_alpha,
- transform_matrix);
+
+ if (!dest_cube_complete) {
+ // The |dest_id| texture cannot be bound to FBO. Create a staging
+ // GL_TEXTURE_2D texture, and copy the source texture to the staging
+ // texture, and copy the staging texture to the dest texture.
+ glBindTexture(GL_TEXTURE_2D, staging_testure_);
+ glTexImage2D(GL_TEXTURE_2D, 0, dest_internal_format, width, height, 0,
+ dest_internal_format, dest_type, nullptr);
+ DoCopyTextureInternal(decoder, source_target, source_id, GL_TEXTURE_2D,
+ staging_testure_, 0, 0, 0, 0, width, height, width,
+ height, width, height, flip_y, premultiply_alpha,
+ unpremultiply_alpha, transform_matrix);
+ DoCopyTexImage2D(decoder, GL_TEXTURE_2D, staging_testure_, dest_target,
Ken Russell (switch to Gerrit) 2015/08/18 00:33:02 Similar comment about the staging_texture_ staying
dshwang 2015/08/18 14:42:01 Acknowledged.
+ dest_id, dest_internal_format, width, height,
+ framebuffer_);
+ return;
+ }
+
+ DoCopyTextureInternal(decoder, source_target, source_id, dest_target, dest_id,
+ 0, 0, 0, 0, width, height, dest_width, dest_height,
+ width, height, flip_y, premultiply_alpha,
+ unpremultiply_alpha, transform_matrix);
}
void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal(
const gles2::GLES2Decoder* decoder,
GLenum source_target,
GLuint source_id,
+ GLenum dest_target,
GLuint dest_id,
GLint xoffset,
GLint yoffset,
@@ -542,7 +595,7 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal(
else
glUniform2f(info->half_size_handle, 0.5f, 0.5f);
- if (BindFramebufferTexture2D(GL_TEXTURE_2D, dest_id, framebuffer_)) {
+ if (BindFramebufferTexture2D(dest_target, dest_id, framebuffer_)) {
#ifndef NDEBUG
// glValidateProgram of MACOSX validates FBO unlike other platforms, so
// glValidateProgram must be called after FBO binding. crbug.com/463439

Powered by Google App Engine
This is Rietveld 408576698