Переглянути джерело

gpu: allow to set array uniform values.

legacy
Sam Hocevar sam 12 роки тому
джерело
коміт
e960628223
2 змінених файлів з 103 додано та 0 видалено
  1. +98
    -0
      src/gpu/shader.cpp
  2. +5
    -0
      src/gpu/shader.h

+ 98
- 0
src/gpu/shader.cpp Переглянути файл

@@ -379,6 +379,10 @@ ShaderUniform Shader::GetUniformLocation(char const *uni) const
return ret;
}

/*
* Uniform setters for scalars
*/

void Shader::SetUniform(ShaderUniform const &uni, int i)
{
#if defined USE_D3D9 || defined _XBOX
@@ -557,6 +561,100 @@ void Shader::SetUniform(ShaderUniform const &uni, ShaderTexture tex, int index)
#endif
}

/*
* Uniform setters for arrays
*/

void Shader::SetUniform(ShaderUniform const &uni, Array<float> const &v)
{
#if defined USE_D3D9 || defined _XBOX
/* FIXME: this will not work properly because we don't know how tell DX9
* it's a bunch of floats instead of vec4. */
if (uni.flags & 1)
g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag,
&v[0], v.Count() / 4);
if (uni.flags & 2)
g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert,
&v[0], v.Count() / 4);
#elif !defined __CELLOS_LV2__
glUniform1fv(uni.frag, v.Count(), &v[0]);
#else
if (uni.frag)
cgGLSetParameterArray1fv((CGparameter)uni.frag,
0, v.Count(), &v[0]);
if (uni.vert)
cgGLSetParameterArray1fv((CGparameter)uni.vert,
0, v.Count(), &v[0]);
#endif
}

void Shader::SetUniform(ShaderUniform const &uni, Array<vec2> const &v)
{
#if defined USE_D3D9 || defined _XBOX
/* FIXME: this will not work properly because we don't know how tell DX9
* it's a bunch of vec2 instead of vec4. */
if (uni.flags & 1)
g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag,
&v[0][0], v.Count() / 2);
if (uni.flags & 2)
g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert,
&v[0][0], v.Count() / 2);
#elif !defined __CELLOS_LV2__
glUniform2fv(uni.frag, v.Count(), &v[0][0]);
#else
if (uni.frag)
cgGLSetParameterArray2fv((CGparameter)uni.frag,
0, v.Count(), &v[0][0]);
if (uni.vert)
cgGLSetParameterArray2fv((CGparameter)uni.vert,
0, v.Count(), &v[0][0]);
#endif
}

void Shader::SetUniform(ShaderUniform const &uni, Array<vec3> const &v)
{
#if defined USE_D3D9 || defined _XBOX
/* FIXME: this will not work properly because we don't know how tell DX9
* it's a bunch of vec3 instead of vec4. */
if (uni.flags & 1)
g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag,
&v[0][0], v.Count());
if (uni.flags & 2)
g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert,
&v[0][0], v.Count());
#elif !defined __CELLOS_LV2__
glUniform3fv(uni.frag, v.Count(), &v[0][0]);
#else
if (uni.frag)
cgGLSetParameterArray3fv((CGparameter)uni.frag,
0, v.Count(), &v[0][0]);
if (uni.vert)
cgGLSetParameterArray3fv((CGparameter)uni.vert,
0, v.Count(), &v[0][0]);
#endif
}

void Shader::SetUniform(ShaderUniform const &uni, Array<vec4> const &v)
{
#if defined USE_D3D9 || defined _XBOX
if (uni.flags & 1)
g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag,
&v[0][0], v.Count());
if (uni.flags & 2)
g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert,
&v[0][0], v.Count());
#elif !defined __CELLOS_LV2__
glUniform4fv(uni.frag, v.Count(), &v[0][0]);
#else
if (uni.frag)
cgGLSetParameterArray4fv((CGparameter)uni.frag,
0, v.Count(), &v[0][0]);
if (uni.vert)
cgGLSetParameterArray4fv((CGparameter)uni.vert,
0, v.Count(), &v[0][0]);
#endif
}

void Shader::Bind() const
{
#if defined USE_D3D9 || defined _XBOX


+ 5
- 0
src/gpu/shader.h Переглянути файл

@@ -84,6 +84,11 @@ public:
void SetUniform(ShaderUniform const &uni, mat4 const &m);
void SetUniform(ShaderUniform const &uni, ShaderTexture tex, int index);

void SetUniform(ShaderUniform const &uni, Array<float> const &v);
void SetUniform(ShaderUniform const &uni, Array<vec2> const &v);
void SetUniform(ShaderUniform const &uni, Array<vec3> const &v);
void SetUniform(ShaderUniform const &uni, Array<vec4> const &v);

void Bind() const;
void Unbind() const;



Завантаження…
Відмінити
Зберегти