Move Uniform to separate files.

TRAC #22245 Signed-off-by: Daniel Koch Signed-off-by: Geoff Lang Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1595 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent b6e55102
...@@ -305,6 +305,8 @@ ...@@ -305,6 +305,8 @@
'libGLESv2/Shader.h', 'libGLESv2/Shader.h',
'libGLESv2/Texture.cpp', 'libGLESv2/Texture.cpp',
'libGLESv2/Texture.h', 'libGLESv2/Texture.h',
'libGLESv2/Uniform.cpp',
'libGLESv2/Uniform.h',
'libGLESv2/utilities.cpp', 'libGLESv2/utilities.cpp',
'libGLESv2/utilities.h', 'libGLESv2/utilities.h',
], ],
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "libGLESv2/Context.h" #include "libGLESv2/Context.h"
#include "libGLESv2/mathutil.h" #include "libGLESv2/mathutil.h"
#include "libGLESv2/Shader.h" #include "libGLESv2/Shader.h"
#include "libGLESv2/Uniform.h"
#include "libGLESv2/renderer/ShaderExecutable.h" #include "libGLESv2/renderer/ShaderExecutable.h"
...@@ -29,60 +30,6 @@ namespace gl ...@@ -29,60 +30,6 @@ namespace gl
class FragmentShader; class FragmentShader;
class VertexShader; class VertexShader;
// Helper struct representing a single shader uniform
struct Uniform
{
Uniform(GLenum type, const std::string &_name, unsigned int arraySize);
~Uniform();
bool isArray();
const GLenum type;
const std::string _name; // Decorated name
const std::string name; // Undecorated name
const unsigned int arraySize;
unsigned char *data;
bool dirty;
struct RegisterInfo
{
RegisterInfo()
{
float4Index = -1;
samplerIndex = -1;
boolIndex = -1;
registerCount = 0;
}
void set(const rx::D3DConstant *constant)
{
switch(constant->registerSet)
{
case rx::D3DConstant::RS_BOOL: boolIndex = constant->registerIndex; break;
case rx::D3DConstant::RS_FLOAT4: float4Index = constant->registerIndex; break;
case rx::D3DConstant::RS_SAMPLER: samplerIndex = constant->registerIndex; break;
default: UNREACHABLE();
}
ASSERT(registerCount == 0 || registerCount == (int)constant->registerCount);
registerCount = constant->registerCount;
}
int float4Index;
int samplerIndex;
int boolIndex;
int registerCount;
};
RegisterInfo ps;
RegisterInfo vs;
};
typedef std::vector<Uniform*> UniformArray;
// Struct used for correlating uniforms/elements of uniform arrays to handles // Struct used for correlating uniforms/elements of uniform arrays to handles
struct UniformLocation struct UniformLocation
{ {
...@@ -161,7 +108,6 @@ class ProgramBinary : public RefCountObject ...@@ -161,7 +108,6 @@ class ProgramBinary : public RefCountObject
unsigned int getSerial() const; unsigned int getSerial() const;
static std::string decorateAttribute(const std::string &name); // Prepend an underscore static std::string decorateAttribute(const std::string &name); // Prepend an underscore
static std::string undecorateUniform(const std::string &_name); // Remove leading underscore
private: private:
DISALLOW_COPY_AND_ASSIGN(ProgramBinary); DISALLOW_COPY_AND_ASSIGN(ProgramBinary);
......
//
// Copyright (c) 2010-2012 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.
//
#include "libGLESv2/Uniform.h"
#include "libGLESv2/utilities.h"
namespace gl
{
Uniform::Uniform(GLenum type, const std::string &_name, unsigned int arraySize)
: type(type), _name(_name), name(undecorate(_name)), arraySize(arraySize)
{
int bytes = gl::UniformInternalSize(type) * arraySize;
data = new unsigned char[bytes];
memset(data, 0, bytes);
dirty = true;
}
Uniform::~Uniform()
{
delete[] data;
}
bool Uniform::isArray()
{
size_t dot = _name.find_last_of('.');
if (dot == std::string::npos) dot = -1;
return _name.compare(dot + 1, dot + 4, "ar_") == 0;
}
std::string Uniform::undecorate(const std::string &_name)
{
std::string name = _name;
// Remove any structure field decoration
size_t pos = 0;
while ((pos = name.find("._", pos)) != std::string::npos)
{
name.replace(pos, 2, ".");
}
// Remove the leading decoration
if (name[0] == '_')
{
return name.substr(1);
}
else if (name.compare(0, 3, "ar_") == 0)
{
return name.substr(3);
}
return name;
}
}
//
// Copyright (c) 2010-2012 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.
//
#ifndef LIBGLESV2_UNIFORM_H_
#define LIBGLESV2_UNIFORM_H_
#include <string>
#define GL_APICALL
#include <GLES2/gl2.h>
#include "common/debug.h"
#include "libGLESv2/renderer/D3DConstantTable.h"
namespace gl
{
// Helper struct representing a single shader uniform
struct Uniform
{
Uniform(GLenum type, const std::string &_name, unsigned int arraySize);
~Uniform();
bool isArray();
static std::string Uniform::undecorate(const std::string &_name);
const GLenum type;
const std::string _name; // Decorated name
const std::string name; // Undecorated name
const unsigned int arraySize;
unsigned char *data;
bool dirty;
struct RegisterInfo
{
RegisterInfo()
{
float4Index = -1;
samplerIndex = -1;
boolIndex = -1;
registerCount = 0;
}
void set(const rx::D3DConstant *constant)
{
switch(constant->registerSet)
{
case rx::D3DConstant::RS_BOOL: boolIndex = constant->registerIndex; break;
case rx::D3DConstant::RS_FLOAT4: float4Index = constant->registerIndex; break;
case rx::D3DConstant::RS_SAMPLER: samplerIndex = constant->registerIndex; break;
default: UNREACHABLE();
}
ASSERT(registerCount == 0 || registerCount == (int)constant->registerCount);
registerCount = constant->registerCount;
}
int float4Index;
int samplerIndex;
int boolIndex;
int registerCount;
};
RegisterInfo ps;
RegisterInfo vs;
};
typedef std::vector<Uniform*> UniformArray;
}
#endif // LIBGLESV2_UNIFORM_H_
...@@ -270,6 +270,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -270,6 +270,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClCompile Include="ResourceManager.cpp" /> <ClCompile Include="ResourceManager.cpp" />
<ClCompile Include="Shader.cpp" /> <ClCompile Include="Shader.cpp" />
<ClCompile Include="Texture.cpp" /> <ClCompile Include="Texture.cpp" />
<ClCompile Include="Uniform.cpp" />
<ClCompile Include="utilities.cpp" /> <ClCompile Include="utilities.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
...@@ -324,6 +325,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -324,6 +325,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="ResourceManager.h" /> <ClInclude Include="ResourceManager.h" />
<ClInclude Include="Shader.h" /> <ClInclude Include="Shader.h" />
<ClInclude Include="Texture.h" /> <ClInclude Include="Texture.h" />
<ClInclude Include="Uniform.h" />
<ClInclude Include="utilities.h" /> <ClInclude Include="utilities.h" />
<ClInclude Include="..\common\version.h" /> <ClInclude Include="..\common\version.h" />
</ItemGroup> </ItemGroup>
......
...@@ -152,6 +152,9 @@ ...@@ -152,6 +152,9 @@
<ClCompile Include="renderer\Image11.cpp"> <ClCompile Include="renderer\Image11.cpp">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Uniform.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="BinaryStream.h"> <ClInclude Include="BinaryStream.h">
...@@ -313,6 +316,9 @@ ...@@ -313,6 +316,9 @@
<ClInclude Include="renderer\Image11.h"> <ClInclude Include="renderer\Image11.h">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Uniform.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="libGLESv2.def"> <None Include="libGLESv2.def">
...@@ -322,4 +328,4 @@ ...@@ -322,4 +328,4 @@
<ItemGroup> <ItemGroup>
<ResourceCompile Include="libGLESv2.rc" /> <ResourceCompile Include="libGLESv2.rc" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
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