Store integer and boolean uniforms in 4-element vectors.

TRAC #22428 Signed-off-by: Geoff Lang Signed-off-by: Jamie Madill Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1897 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent cd714ef2
......@@ -1633,7 +1633,6 @@ void Renderer9::applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray
if (targetUniform->dirty)
{
int count = targetUniform->elementCount();
GLfloat *f = (GLfloat*)targetUniform->data;
GLint *i = (GLint*)targetUniform->data;
......@@ -1641,22 +1640,28 @@ void Renderer9::applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray
{
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
break;
case GL_BOOL: applyUniformnbv(targetUniform, count, 1, i); break;
case GL_BOOL_VEC2: applyUniformnbv(targetUniform, count, 2, i); break;
case GL_BOOL_VEC3: applyUniformnbv(targetUniform, count, 3, i); break;
case GL_BOOL_VEC4: applyUniformnbv(targetUniform, count, 4, i); break;
break;
case GL_BOOL:
case GL_BOOL_VEC2:
case GL_BOOL_VEC3:
case GL_BOOL_VEC4:
applyUniformnbv(targetUniform, i);
break;
case GL_FLOAT:
case GL_FLOAT_VEC2:
case GL_FLOAT_VEC3:
case GL_FLOAT_VEC4:
case GL_FLOAT_MAT2:
case GL_FLOAT_MAT3:
case GL_FLOAT_MAT4: applyUniformnfv(targetUniform, f); break;
case GL_INT: applyUniform1iv(targetUniform, count, i); break;
case GL_INT_VEC2: applyUniform2iv(targetUniform, count, i); break;
case GL_INT_VEC3: applyUniform3iv(targetUniform, count, i); break;
case GL_INT_VEC4: applyUniform4iv(targetUniform, count, i); break;
case GL_FLOAT_MAT4:
applyUniformnfv(targetUniform, f);
break;
case GL_INT:
case GL_INT_VEC2:
case GL_INT_VEC3:
case GL_INT_VEC4:
applyUniformniv(targetUniform, i);
break;
default:
UNREACHABLE();
}
......@@ -1674,32 +1679,6 @@ void Renderer9::applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray
}
}
void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int width, const GLint *v)
{
float vector[D3D9_MAX_FLOAT_CONSTANTS * 4];
if (targetUniform->psRegisterIndex >= 0 || targetUniform->vsRegisterIndex >= 0)
{
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
for (int i = 0; i < count; i++)
{
for (int j = 0; j < 4; j++)
{
if (j < width)
{
vector[i * 4 + j] = (v[i * width + j] == GL_FALSE) ? 0.0f : 1.0f;
}
else
{
vector[i * 4 + j] = 0.0f;
}
}
}
}
applyUniformnfv(targetUniform, vector);
}
void Renderer9::applyUniformnfv(gl::Uniform *targetUniform, const GLfloat *v)
{
if (targetUniform->psRegisterIndex >= 0)
......@@ -1713,62 +1692,36 @@ void Renderer9::applyUniformnfv(gl::Uniform *targetUniform, const GLfloat *v)
}
}
void Renderer9::applyUniform1iv(gl::Uniform *targetUniform, GLsizei count, const GLint *v)
{
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
gl::Vector4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
vector[i] = gl::Vector4((float)v[i], 0, 0, 0);
}
applyUniformnfv(targetUniform, (const GLfloat*)vector);
}
void Renderer9::applyUniform2iv(gl::Uniform *targetUniform, GLsizei count, const GLint *v)
{
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
gl::Vector4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++)
{
vector[i] = gl::Vector4((float)v[0], (float)v[1], 0, 0);
v += 2;
}
applyUniformnfv(targetUniform, (const GLfloat*)vector);
}
void Renderer9::applyUniform3iv(gl::Uniform *targetUniform, GLsizei count, const GLint *v)
void Renderer9::applyUniformniv(gl::Uniform *targetUniform, const GLint *v)
{
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
gl::Vector4 vector[D3D9_MAX_FLOAT_CONSTANTS];
ASSERT(targetUniform->registerCount <= D3D9_MAX_FLOAT_CONSTANTS);
GLfloat vector[D3D9_MAX_FLOAT_CONSTANTS][4];
for (int i = 0; i < count; i++)
for (unsigned int i = 0; i < targetUniform->registerCount; i++)
{
vector[i] = gl::Vector4((float)v[0], (float)v[1], (float)v[2], 0);
v += 3;
vector[i][0] = (GLfloat)v[4 * i + 0];
vector[i][1] = (GLfloat)v[4 * i + 1];
vector[i][2] = (GLfloat)v[4 * i + 2];
vector[i][3] = (GLfloat)v[4 * i + 3];
}
applyUniformnfv(targetUniform, (const GLfloat*)vector);
applyUniformnfv(targetUniform, (GLfloat*)vector);
}
void Renderer9::applyUniform4iv(gl::Uniform *targetUniform, GLsizei count, const GLint *v)
void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, const GLint *v)
{
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
gl::Vector4 vector[D3D9_MAX_FLOAT_CONSTANTS];
ASSERT(targetUniform->registerCount <= D3D9_MAX_FLOAT_CONSTANTS);
GLfloat vector[D3D9_MAX_FLOAT_CONSTANTS][4];
for (int i = 0; i < count; i++)
for (unsigned int i = 0; i < targetUniform->registerCount; i++)
{
vector[i] = gl::Vector4((float)v[0], (float)v[1], (float)v[2], (float)v[3]);
v += 4;
vector[i][0] = (v[4 * i + 0] == GL_FALSE) ? 0.0f : 1.0f;
vector[i][1] = (v[4 * i + 1] == GL_FALSE) ? 0.0f : 1.0f;
vector[i][2] = (v[4 * i + 2] == GL_FALSE) ? 0.0f : 1.0f;
vector[i][3] = (v[4 * i + 3] == GL_FALSE) ? 0.0f : 1.0f;
}
applyUniformnfv(targetUniform, (const GLfloat*)vector);
applyUniformnfv(targetUniform, (GLfloat*)vector);
}
void Renderer9::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer)
......
......@@ -210,11 +210,8 @@ class Renderer9 : public Renderer
DISALLOW_COPY_AND_ASSIGN(Renderer9);
void applyUniformnfv(gl::Uniform *targetUniform, const GLfloat *v);
void applyUniform1iv(gl::Uniform *targetUniform, GLsizei count, const GLint *v);
void applyUniform2iv(gl::Uniform *targetUniform, GLsizei count, const GLint *v);
void applyUniform3iv(gl::Uniform *targetUniform, GLsizei count, const GLint *v);
void applyUniform4iv(gl::Uniform *targetUniform, GLsizei count, const GLint *v);
void applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int width, const GLint *v);
void applyUniformniv(gl::Uniform *targetUniform, const GLint *v);
void applyUniformnbv(gl::Uniform *targetUniform, const GLint *v);
void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
......
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
......@@ -19,8 +19,7 @@
namespace gl
{
// This is how much data the application expects for a uniform
int UniformExternalComponentCount(GLenum type)
int UniformComponentCount(GLenum type)
{
switch (type)
{
......@@ -54,42 +53,6 @@ int UniformExternalComponentCount(GLenum type)
return 0;
}
// This is how much data we actually store for a uniform
int UniformInternalComponentCount(GLenum type)
{
switch (type)
{
case GL_BOOL:
case GL_INT:
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
return 1;
case GL_BOOL_VEC2:
case GL_INT_VEC2:
return 2;
case GL_INT_VEC3:
case GL_BOOL_VEC3:
return 3;
case GL_FLOAT:
case GL_FLOAT_VEC2:
case GL_FLOAT_VEC3:
case GL_BOOL_VEC4:
case GL_FLOAT_VEC4:
case GL_INT_VEC4:
return 4;
case GL_FLOAT_MAT2:
return 8;
case GL_FLOAT_MAT3:
return 12;
case GL_FLOAT_MAT4:
return 16;
default:
UNREACHABLE();
}
return 0;
}
GLenum UniformComponentType(GLenum type)
{
switch(type)
......@@ -136,12 +99,13 @@ size_t UniformComponentSize(GLenum type)
size_t UniformInternalSize(GLenum type)
{
return UniformComponentSize(UniformComponentType(type)) * UniformInternalComponentCount(type);
// Expanded to 4-element vectors
return UniformComponentSize(UniformComponentType(type)) * VariableRowCount(type) * 4;
}
size_t UniformExternalSize(GLenum type)
{
return UniformComponentSize(UniformComponentType(type)) * UniformExternalComponentCount(type);
return UniformComponentSize(UniformComponentType(type)) * UniformComponentCount(type);
}
int VariableRowCount(GLenum type)
......@@ -187,6 +151,8 @@ int VariableColumnCount(GLenum type)
case GL_BOOL:
case GL_FLOAT:
case GL_INT:
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
return 1;
case GL_BOOL_VEC2:
case GL_FLOAT_VEC2:
......
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
......@@ -20,8 +20,7 @@ namespace gl
struct Color;
int UniformExternalComponentCount(GLenum type);
int UniformInternalComponentCount(GLenum type);
int UniformComponentCount(GLenum type);
GLenum UniformComponentType(GLenum type);
size_t UniformInternalSize(GLenum type);
size_t UniformExternalSize(GLenum type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment