fix Gl renderer; texture binding was totally busted
This commit is contained in:
@@ -23,6 +23,7 @@ namespace OpenRA.Renderer.Glsl
|
|||||||
{
|
{
|
||||||
int program;
|
int program;
|
||||||
readonly Dictionary<string, int> samplers = new Dictionary<string, int>();
|
readonly Dictionary<string, int> samplers = new Dictionary<string, int>();
|
||||||
|
readonly Dictionary<int, ITexture> textures = new Dictionary<int, ITexture>();
|
||||||
|
|
||||||
public Shader(GraphicsDevice dev, string type)
|
public Shader(GraphicsDevice dev, string type)
|
||||||
{
|
{
|
||||||
@@ -85,7 +86,7 @@ namespace OpenRA.Renderer.Glsl
|
|||||||
Gl.glGetObjectParameterivARB( program, Gl.GL_ACTIVE_UNIFORMS, out numUniforms );
|
Gl.glGetObjectParameterivARB( program, Gl.GL_ACTIVE_UNIFORMS, out numUniforms );
|
||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
|
|
||||||
int nextTexUnit = 1;
|
int nextTexUnit = 0;
|
||||||
for( int i = 0 ; i < numUniforms ; i++ )
|
for( int i = 0 ; i < numUniforms ; i++ )
|
||||||
{
|
{
|
||||||
int uLen, uSize, uType, loc;
|
int uLen, uSize, uType, loc;
|
||||||
@@ -103,11 +104,22 @@ namespace OpenRA.Renderer.Glsl
|
|||||||
++nextTexUnit;
|
++nextTexUnit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render(Action a)
|
public void Render(Action a)
|
||||||
{
|
{
|
||||||
Gl.glUseProgramObjectARB(program);
|
Gl.glUseProgramObjectARB(program);
|
||||||
|
|
||||||
|
/* bind the textures */
|
||||||
|
|
||||||
|
foreach (var kv in textures)
|
||||||
|
{
|
||||||
|
Gl.glActiveTextureARB( Gl.GL_TEXTURE0_ARB + kv.Key );
|
||||||
|
Gl.glBindTexture( Gl.GL_TEXTURE_2D, ((Texture)kv.Value).texture );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* configure blend state */
|
||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
// Todo: Only enable alpha blending if we need it
|
// Todo: Only enable alpha blending if we need it
|
||||||
Gl.glEnable(Gl.GL_BLEND);
|
Gl.glEnable(Gl.GL_BLEND);
|
||||||
@@ -123,18 +135,9 @@ namespace OpenRA.Renderer.Glsl
|
|||||||
public void SetValue(string name, ITexture t)
|
public void SetValue(string name, ITexture t)
|
||||||
{
|
{
|
||||||
if( t == null ) return;
|
if( t == null ) return;
|
||||||
Gl.glUseProgramObjectARB(program);
|
|
||||||
ErrorHandler.CheckGlError();
|
|
||||||
var texture = (Texture)t;
|
|
||||||
int texUnit;
|
int texUnit;
|
||||||
if( samplers.TryGetValue( name, out texUnit ) )
|
if( samplers.TryGetValue( name, out texUnit ) )
|
||||||
{
|
textures[texUnit] = t;
|
||||||
Gl.glActiveTextureARB( Gl.GL_TEXTURE0_ARB + texUnit );
|
|
||||||
ErrorHandler.CheckGlError();
|
|
||||||
Gl.glBindTexture( Gl.GL_TEXTURE_2D, texture.texture );
|
|
||||||
ErrorHandler.CheckGlError();
|
|
||||||
Gl.glActiveTextureARB( Gl.GL_TEXTURE0_ARB );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValue(string name, float x, float y)
|
public void SetValue(string name, float x, float y)
|
||||||
|
|||||||
Reference in New Issue
Block a user