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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 1136713003: Add ES3 commands GetVertexAttribI{u}iv to GPU command buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
OLDNEW
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_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return gfx::OVERLAY_TRANSFORM_ROTATE_90; 166 return gfx::OVERLAY_TRANSFORM_ROTATE_90;
167 case GL_OVERLAY_TRANSFORM_ROTATE_180_CHROMIUM: 167 case GL_OVERLAY_TRANSFORM_ROTATE_180_CHROMIUM:
168 return gfx::OVERLAY_TRANSFORM_ROTATE_180; 168 return gfx::OVERLAY_TRANSFORM_ROTATE_180;
169 case GL_OVERLAY_TRANSFORM_ROTATE_270_CHROMIUM: 169 case GL_OVERLAY_TRANSFORM_ROTATE_270_CHROMIUM:
170 return gfx::OVERLAY_TRANSFORM_ROTATE_270; 170 return gfx::OVERLAY_TRANSFORM_ROTATE_270;
171 default: 171 default:
172 return gfx::OVERLAY_TRANSFORM_INVALID; 172 return gfx::OVERLAY_TRANSFORM_INVALID;
173 } 173 }
174 } 174 }
175 175
176 struct Vec4f {
177 Vec4f(Vec4 data) {
piman 2015/05/13 01:47:44 nit: explicit
Zhenyao Mo 2015/05/13 16:52:25 Done.
178 for (int ii = 0; ii < 4; ++ii) {
179 v[ii] = static_cast<float>(data.v[ii]);
180 }
181 }
182
183 float v[4];
184 };
185
176 } // namespace 186 } // namespace
177 187
178 class GLES2DecoderImpl; 188 class GLES2DecoderImpl;
179 189
180 // Local versions of the SET_GL_ERROR macros 190 // Local versions of the SET_GL_ERROR macros
181 #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ 191 #define LOCAL_SET_GL_ERROR(error, function_name, msg) \
182 ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg) 192 ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg)
183 #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ 193 #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \
184 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \ 194 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \
185 function_name, value, label) 195 function_name, value, label)
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 1475
1466 // Wrapper for glGetShaderiv 1476 // Wrapper for glGetShaderiv
1467 void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); 1477 void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params);
1468 1478
1469 // Wrappers for glGetTexParameter. 1479 // Wrappers for glGetTexParameter.
1470 void DoGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params); 1480 void DoGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params);
1471 void DoGetTexParameteriv(GLenum target, GLenum pname, GLint* params); 1481 void DoGetTexParameteriv(GLenum target, GLenum pname, GLint* params);
1472 void InitTextureMaxAnisotropyIfNeeded(GLenum target, GLenum pname); 1482 void InitTextureMaxAnisotropyIfNeeded(GLenum target, GLenum pname);
1473 1483
1474 // Wrappers for glGetVertexAttrib. 1484 // Wrappers for glGetVertexAttrib.
1475 void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); 1485 template <typename T>
1476 void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); 1486 void DoGetVertexAttribImpl(GLuint index, GLenum pname, T* params);
1487 void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params);
1488 void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint* params);
1489 void DoGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params);
1490 void DoGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params);
1477 1491
1478 // Wrappers for glIsXXX functions. 1492 // Wrappers for glIsXXX functions.
1479 bool DoIsEnabled(GLenum cap); 1493 bool DoIsEnabled(GLenum cap);
1480 bool DoIsBuffer(GLuint client_id); 1494 bool DoIsBuffer(GLuint client_id);
1481 bool DoIsFramebuffer(GLuint client_id); 1495 bool DoIsFramebuffer(GLuint client_id);
1482 bool DoIsProgram(GLuint client_id); 1496 bool DoIsProgram(GLuint client_id);
1483 bool DoIsRenderbuffer(GLuint client_id); 1497 bool DoIsRenderbuffer(GLuint client_id);
1484 bool DoIsShader(GLuint client_id); 1498 bool DoIsShader(GLuint client_id);
1485 bool DoIsTexture(GLuint client_id); 1499 bool DoIsTexture(GLuint client_id);
1486 bool DoIsVertexArrayOES(GLuint client_id); 1500 bool DoIsVertexArrayOES(GLuint client_id);
(...skipping 5354 matching lines...) Expand 10 before | Expand all | Expand 10 after
6841 return true; 6855 return true;
6842 } 6856 }
6843 6857
6844 // Make a buffer with a single repeated vec4 value enough to 6858 // Make a buffer with a single repeated vec4 value enough to
6845 // simulate the constant value that is supposed to be here. 6859 // simulate the constant value that is supposed to be here.
6846 // This is required to emulate GLES2 on GL. 6860 // This is required to emulate GLES2 on GL.
6847 GLuint num_vertices = max_vertex_accessed + 1; 6861 GLuint num_vertices = max_vertex_accessed + 1;
6848 uint32 size_needed = 0; 6862 uint32 size_needed = 0;
6849 6863
6850 if (num_vertices == 0 || 6864 if (num_vertices == 0 ||
6851 !SafeMultiplyUint32(num_vertices, sizeof(Vec4), &size_needed) || 6865 !SafeMultiplyUint32(num_vertices, sizeof(Vec4f), &size_needed) ||
6852 size_needed > 0x7FFFFFFFU) { 6866 size_needed > 0x7FFFFFFFU) {
6853 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); 6867 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0");
6854 return false; 6868 return false;
6855 } 6869 }
6856 6870
6857 LOCAL_PERFORMANCE_WARNING( 6871 LOCAL_PERFORMANCE_WARNING(
6858 "Attribute 0 is disabled. This has signficant performance penalty"); 6872 "Attribute 0 is disabled. This has signficant performance penalty");
6859 6873
6860 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); 6874 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name);
6861 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); 6875 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_);
6862 6876
6863 bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; 6877 bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_;
6864 if (new_buffer) { 6878 if (new_buffer) {
6865 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); 6879 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW);
6866 GLenum error = glGetError(); 6880 GLenum error = glGetError();
6867 if (error != GL_NO_ERROR) { 6881 if (error != GL_NO_ERROR) {
6868 LOCAL_SET_GL_ERROR( 6882 LOCAL_SET_GL_ERROR(
6869 GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); 6883 GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0");
6870 return false; 6884 return false;
6871 } 6885 }
6872 } 6886 }
6873 6887
6874 const Vec4& value = state_.attrib_values[0]; 6888 const Vec4& value = state_.attrib_values[0];
6875 if (new_buffer || 6889 if (new_buffer ||
6876 (attrib_0_used && 6890 (attrib_0_used &&
6877 (!attrib_0_buffer_matches_value_ || 6891 (!attrib_0_buffer_matches_value_ || value.v != attrib_0_value_.v))) {
6878 (value.v[0] != attrib_0_value_.v[0] || 6892 // TODO(zmo): This is not 100% correct because we might lose data when
6879 value.v[1] != attrib_0_value_.v[1] || 6893 // casting to float type, but it is a corner case and once we migrate to
6880 value.v[2] != attrib_0_value_.v[2] || 6894 // core profiles on desktop GL, it is no longer relevant.
6881 value.v[3] != attrib_0_value_.v[3])))) { 6895 Vec4f fvalue(value);
6882 std::vector<Vec4> temp(num_vertices, value); 6896 std::vector<Vec4f> temp(num_vertices, fvalue);
6883 glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); 6897 glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]);
6884 attrib_0_buffer_matches_value_ = true; 6898 attrib_0_buffer_matches_value_ = true;
6885 attrib_0_value_ = value; 6899 attrib_0_value_ = value;
6886 attrib_0_size_ = size_needed; 6900 attrib_0_size_ = size_needed;
6887 } 6901 }
6888 6902
6889 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); 6903 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
6890 6904
6891 if (attrib->divisor()) 6905 if (attrib->divisor())
6892 glVertexAttribDivisorANGLE(0, 0); 6906 glVertexAttribDivisorANGLE(0, 0);
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
7585 program_client_id, "glValidateProgram"); 7599 program_client_id, "glValidateProgram");
7586 if (!program) { 7600 if (!program) {
7587 return; 7601 return;
7588 } 7602 }
7589 program->Validate(); 7603 program->Validate();
7590 } 7604 }
7591 7605
7592 void GLES2DecoderImpl::GetVertexAttribHelper( 7606 void GLES2DecoderImpl::GetVertexAttribHelper(
7593 const VertexAttrib* attrib, GLenum pname, GLint* params) { 7607 const VertexAttrib* attrib, GLenum pname, GLint* params) {
7594 switch (pname) { 7608 switch (pname) {
7595 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { 7609 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
7610 {
7596 Buffer* buffer = attrib->buffer(); 7611 Buffer* buffer = attrib->buffer();
7597 if (buffer && !buffer->IsDeleted()) { 7612 if (buffer && !buffer->IsDeleted()) {
7598 GLuint client_id; 7613 GLuint client_id;
7599 buffer_manager()->GetClientId(buffer->service_id(), &client_id); 7614 buffer_manager()->GetClientId(buffer->service_id(), &client_id);
7600 *params = client_id; 7615 *params = client_id;
7601 } 7616 }
7602 break; 7617 break;
7603 } 7618 }
7604 case GL_VERTEX_ATTRIB_ARRAY_ENABLED: 7619 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
7605 *params = attrib->enabled(); 7620 *params = attrib->enabled();
7606 break; 7621 break;
7607 case GL_VERTEX_ATTRIB_ARRAY_SIZE: 7622 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
7608 *params = attrib->size(); 7623 *params = attrib->size();
7609 break; 7624 break;
7610 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: 7625 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
7611 *params = attrib->gl_stride(); 7626 *params = attrib->gl_stride();
7612 break; 7627 break;
7613 case GL_VERTEX_ATTRIB_ARRAY_TYPE: 7628 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
7614 *params = attrib->type(); 7629 *params = attrib->type();
7615 break; 7630 break;
7616 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: 7631 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
7617 *params = attrib->normalized(); 7632 *params = attrib->normalized();
7618 break; 7633 break;
7619 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: 7634 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
7620 *params = attrib->divisor(); 7635 *params = attrib->divisor();
7621 break; 7636 break;
7637 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
7638 *params = attrib->integer();
7639 break;
7622 default: 7640 default:
7623 NOTREACHED(); 7641 NOTREACHED();
7624 break; 7642 break;
7625 } 7643 }
7626 } 7644 }
7627 7645
7628 void GLES2DecoderImpl::DoGetTexParameterfv( 7646 void GLES2DecoderImpl::DoGetTexParameterfv(
7629 GLenum target, GLenum pname, GLfloat* params) { 7647 GLenum target, GLenum pname, GLfloat* params) {
7630 InitTextureMaxAnisotropyIfNeeded(target, pname); 7648 InitTextureMaxAnisotropyIfNeeded(target, pname);
7631 glGetTexParameterfv(target, pname, params); 7649 glGetTexParameterfv(target, pname, params);
(...skipping 19 matching lines...) Expand all
7651 if (!texture_ref) { 7669 if (!texture_ref) {
7652 LOCAL_SET_GL_ERROR( 7670 LOCAL_SET_GL_ERROR(
7653 GL_INVALID_OPERATION, 7671 GL_INVALID_OPERATION,
7654 "glGetTexParamter{fi}v", "unknown texture for target"); 7672 "glGetTexParamter{fi}v", "unknown texture for target");
7655 return; 7673 return;
7656 } 7674 }
7657 Texture* texture = texture_ref->texture(); 7675 Texture* texture = texture_ref->texture();
7658 texture->InitTextureMaxAnisotropyIfNeeded(target); 7676 texture->InitTextureMaxAnisotropyIfNeeded(target);
7659 } 7677 }
7660 7678
7661 void GLES2DecoderImpl::DoGetVertexAttribfv( 7679 template <typename T>
7662 GLuint index, GLenum pname, GLfloat* params) { 7680 void GLES2DecoderImpl::DoGetVertexAttribImpl(
7681 GLuint index, GLenum pname, T* params) {
7663 VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); 7682 VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index);
7664 if (!attrib) { 7683 if (!attrib) {
7665 LOCAL_SET_GL_ERROR( 7684 LOCAL_SET_GL_ERROR(
7666 GL_INVALID_VALUE, "glGetVertexAttribfv", "index out of range"); 7685 GL_INVALID_VALUE, "glGetVertexAttrib", "index out of range");
7667 return; 7686 return;
7668 } 7687 }
7669 switch (pname) { 7688 switch (pname) {
7670 case GL_CURRENT_VERTEX_ATTRIB: { 7689 case GL_CURRENT_VERTEX_ATTRIB: {
7671 const Vec4& value = state_.attrib_values[index]; 7690 const Vec4& value = state_.attrib_values[index];
7672 params[0] = value.v[0]; 7691 params[0] = static_cast<T>(value.v[0]);
7673 params[1] = value.v[1]; 7692 params[1] = static_cast<T>(value.v[1]);
7674 params[2] = value.v[2]; 7693 params[2] = static_cast<T>(value.v[2]);
7675 params[3] = value.v[3]; 7694 params[3] = static_cast<T>(value.v[3]);
7676 break; 7695 break;
7677 } 7696 }
7678 default: { 7697 default: {
7679 GLint value = 0; 7698 GLint value = 0;
7680 GetVertexAttribHelper(attrib, pname, &value); 7699 GetVertexAttribHelper(attrib, pname, &value);
7681 *params = static_cast<GLfloat>(value); 7700 *params = static_cast<T>(value);
7682 break; 7701 break;
7683 } 7702 }
7684 } 7703 }
7685 } 7704 }
7686 7705
7706 void GLES2DecoderImpl::DoGetVertexAttribfv(
7707 GLuint index, GLenum pname, GLfloat* params) {
7708 DoGetVertexAttribImpl<GLfloat>(index, pname, params);
7709 }
7710
7687 void GLES2DecoderImpl::DoGetVertexAttribiv( 7711 void GLES2DecoderImpl::DoGetVertexAttribiv(
7688 GLuint index, GLenum pname, GLint* params) { 7712 GLuint index, GLenum pname, GLint* params) {
7689 VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); 7713 DoGetVertexAttribImpl<GLint>(index, pname, params);
7690 if (!attrib) { 7714 }
7691 LOCAL_SET_GL_ERROR( 7715
7692 GL_INVALID_VALUE, "glGetVertexAttribiv", "index out of range"); 7716 void GLES2DecoderImpl::DoGetVertexAttribIiv(
7693 return; 7717 GLuint index, GLenum pname, GLint* params) {
7694 } 7718 DoGetVertexAttribImpl<GLint>(index, pname, params);
7695 switch (pname) { 7719 }
7696 case GL_CURRENT_VERTEX_ATTRIB: { 7720
7697 const Vec4& value = state_.attrib_values[index]; 7721 void GLES2DecoderImpl::DoGetVertexAttribIuiv(
7698 params[0] = static_cast<GLint>(value.v[0]); 7722 GLuint index, GLenum pname, GLuint* params) {
7699 params[1] = static_cast<GLint>(value.v[1]); 7723 DoGetVertexAttribImpl<GLuint>(index, pname, params);
7700 params[2] = static_cast<GLint>(value.v[2]);
7701 params[3] = static_cast<GLint>(value.v[3]);
7702 break;
7703 }
7704 default:
7705 GetVertexAttribHelper(attrib, pname, params);
7706 break;
7707 }
7708 } 7724 }
7709 7725
7710 bool GLES2DecoderImpl::SetVertexAttribValue( 7726 bool GLES2DecoderImpl::SetVertexAttribValue(
7711 const char* function_name, GLuint index, const GLfloat* value) { 7727 const char* function_name, GLuint index, const GLfloat* value) {
7712 if (index >= state_.attrib_values.size()) { 7728 if (index >= state_.attrib_values.size()) {
7713 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "index out of range"); 7729 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "index out of range");
7714 return false; 7730 return false;
7715 } 7731 }
7716 Vec4& v = state_.attrib_values[index]; 7732 Vec4& v = state_.attrib_values[index];
7717 v.v[0] = value[0]; 7733 v.v[0] = value[0];
(...skipping 5421 matching lines...) Expand 10 before | Expand all | Expand 10 after
13139 } 13155 }
13140 } 13156 }
13141 13157
13142 // Include the auto-generated part of this file. We split this because it means 13158 // Include the auto-generated part of this file. We split this because it means
13143 // we can easily edit the non-auto generated parts right here in this file 13159 // we can easily edit the non-auto generated parts right here in this file
13144 // instead of having to edit some template or the code generator. 13160 // instead of having to edit some template or the code generator.
13145 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 13161 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
13146 13162
13147 } // namespace gles2 13163 } // namespace gles2
13148 } // namespace gpu 13164 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698