Chromium Code Reviews| Index: gpu/command_buffer/service/gles2_cmd_decoder.cc |
| diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| index a22c2f9b83e6f863d1d0e213dba7c857b685e56f..380d30e4712bb9180557eda76c373613b894af48 100644 |
| --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| @@ -173,6 +173,16 @@ static gfx::OverlayTransform GetGFXOverlayTransform(GLenum plane_transform) { |
| } |
| } |
| +struct Vec4f { |
| + Vec4f(Vec4 data) { |
|
piman
2015/05/13 01:47:44
nit: explicit
Zhenyao Mo
2015/05/13 16:52:25
Done.
|
| + for (int ii = 0; ii < 4; ++ii) { |
| + v[ii] = static_cast<float>(data.v[ii]); |
| + } |
| + } |
| + |
| + float v[4]; |
| +}; |
| + |
| } // namespace |
| class GLES2DecoderImpl; |
| @@ -1472,8 +1482,12 @@ class GLES2DecoderImpl : public GLES2Decoder, |
| void InitTextureMaxAnisotropyIfNeeded(GLenum target, GLenum pname); |
| // Wrappers for glGetVertexAttrib. |
| - void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); |
| - void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); |
| + template <typename T> |
| + void DoGetVertexAttribImpl(GLuint index, GLenum pname, T* params); |
| + void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params); |
| + void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint* params); |
| + void DoGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params); |
| + void DoGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params); |
| // Wrappers for glIsXXX functions. |
| bool DoIsEnabled(GLenum cap); |
| @@ -6848,7 +6862,7 @@ bool GLES2DecoderImpl::SimulateAttrib0( |
| uint32 size_needed = 0; |
| if (num_vertices == 0 || |
| - !SafeMultiplyUint32(num_vertices, sizeof(Vec4), &size_needed) || |
| + !SafeMultiplyUint32(num_vertices, sizeof(Vec4f), &size_needed) || |
| size_needed > 0x7FFFFFFFU) { |
| LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
| return false; |
| @@ -6874,12 +6888,12 @@ bool GLES2DecoderImpl::SimulateAttrib0( |
| const Vec4& value = state_.attrib_values[0]; |
| if (new_buffer || |
| (attrib_0_used && |
| - (!attrib_0_buffer_matches_value_ || |
| - (value.v[0] != attrib_0_value_.v[0] || |
| - value.v[1] != attrib_0_value_.v[1] || |
| - value.v[2] != attrib_0_value_.v[2] || |
| - value.v[3] != attrib_0_value_.v[3])))) { |
| - std::vector<Vec4> temp(num_vertices, value); |
| + (!attrib_0_buffer_matches_value_ || value.v != attrib_0_value_.v))) { |
| + // TODO(zmo): This is not 100% correct because we might lose data when |
| + // casting to float type, but it is a corner case and once we migrate to |
| + // core profiles on desktop GL, it is no longer relevant. |
| + Vec4f fvalue(value); |
| + std::vector<Vec4f> temp(num_vertices, fvalue); |
| glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); |
| attrib_0_buffer_matches_value_ = true; |
| attrib_0_value_ = value; |
| @@ -7592,7 +7606,8 @@ void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { |
| void GLES2DecoderImpl::GetVertexAttribHelper( |
| const VertexAttrib* attrib, GLenum pname, GLint* params) { |
| switch (pname) { |
| - case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { |
| + case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| + { |
| Buffer* buffer = attrib->buffer(); |
| if (buffer && !buffer->IsDeleted()) { |
| GLuint client_id; |
| @@ -7616,9 +7631,12 @@ void GLES2DecoderImpl::GetVertexAttribHelper( |
| case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| *params = attrib->normalized(); |
| break; |
| - case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: |
| + case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| *params = attrib->divisor(); |
| break; |
| + case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| + *params = attrib->integer(); |
| + break; |
| default: |
| NOTREACHED(); |
| break; |
| @@ -7658,53 +7676,51 @@ void GLES2DecoderImpl::InitTextureMaxAnisotropyIfNeeded( |
| texture->InitTextureMaxAnisotropyIfNeeded(target); |
| } |
| -void GLES2DecoderImpl::DoGetVertexAttribfv( |
| - GLuint index, GLenum pname, GLfloat* params) { |
| +template <typename T> |
| +void GLES2DecoderImpl::DoGetVertexAttribImpl( |
| + GLuint index, GLenum pname, T* params) { |
| VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| if (!attrib) { |
| LOCAL_SET_GL_ERROR( |
| - GL_INVALID_VALUE, "glGetVertexAttribfv", "index out of range"); |
| + GL_INVALID_VALUE, "glGetVertexAttrib", "index out of range"); |
| return; |
| } |
| switch (pname) { |
| case GL_CURRENT_VERTEX_ATTRIB: { |
| const Vec4& value = state_.attrib_values[index]; |
| - params[0] = value.v[0]; |
| - params[1] = value.v[1]; |
| - params[2] = value.v[2]; |
| - params[3] = value.v[3]; |
| + params[0] = static_cast<T>(value.v[0]); |
| + params[1] = static_cast<T>(value.v[1]); |
| + params[2] = static_cast<T>(value.v[2]); |
| + params[3] = static_cast<T>(value.v[3]); |
| break; |
| } |
| default: { |
| GLint value = 0; |
| GetVertexAttribHelper(attrib, pname, &value); |
| - *params = static_cast<GLfloat>(value); |
| + *params = static_cast<T>(value); |
| break; |
| } |
| } |
| } |
| +void GLES2DecoderImpl::DoGetVertexAttribfv( |
| + GLuint index, GLenum pname, GLfloat* params) { |
| + DoGetVertexAttribImpl<GLfloat>(index, pname, params); |
| +} |
| + |
| void GLES2DecoderImpl::DoGetVertexAttribiv( |
| GLuint index, GLenum pname, GLint* params) { |
| - VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| - if (!attrib) { |
| - LOCAL_SET_GL_ERROR( |
| - GL_INVALID_VALUE, "glGetVertexAttribiv", "index out of range"); |
| - return; |
| - } |
| - switch (pname) { |
| - case GL_CURRENT_VERTEX_ATTRIB: { |
| - const Vec4& value = state_.attrib_values[index]; |
| - params[0] = static_cast<GLint>(value.v[0]); |
| - params[1] = static_cast<GLint>(value.v[1]); |
| - params[2] = static_cast<GLint>(value.v[2]); |
| - params[3] = static_cast<GLint>(value.v[3]); |
| - break; |
| - } |
| - default: |
| - GetVertexAttribHelper(attrib, pname, params); |
| - break; |
| - } |
| + DoGetVertexAttribImpl<GLint>(index, pname, params); |
| +} |
| + |
| +void GLES2DecoderImpl::DoGetVertexAttribIiv( |
| + GLuint index, GLenum pname, GLint* params) { |
| + DoGetVertexAttribImpl<GLint>(index, pname, params); |
| +} |
| + |
| +void GLES2DecoderImpl::DoGetVertexAttribIuiv( |
| + GLuint index, GLenum pname, GLuint* params) { |
| + DoGetVertexAttribImpl<GLuint>(index, pname, params); |
| } |
| bool GLES2DecoderImpl::SetVertexAttribValue( |