Move GuiShader to new DefaultShaders file.

This commit is contained in:
UnknownShadow200 2015-06-20 07:09:15 +10:00
parent 28dc8e94b9
commit efaf29a4d0
3 changed files with 69 additions and 64 deletions

View file

@ -118,6 +118,7 @@
<Compile Include="Game\Game.cs" />
<Compile Include="Game\Game.Events.cs" />
<Compile Include="Game\Game.InputHandling.cs" />
<Compile Include="GraphicsAPI\DefaultShaders.cs" />
<Compile Include="GraphicsAPI\IGraphicsApi.cs" />
<Compile Include="GraphicsAPI\ModernGLApi.cs" />
<Compile Include="GraphicsAPI\OpenGLApi.cs" />

View file

@ -0,0 +1,68 @@
using System;
namespace ClassicalSharp.GraphicsAPI {
public sealed class GuiShader : Shader {
public GuiShader() {
VertexSource = @"
#version 130
in vec3 in_position;
in vec2 in_texcoords;
in vec4 in_colour;
out vec2 out_texcoords;
out vec4 out_colour;
uniform mat4 proj;
void main() {
gl_Position = proj * vec4(in_position, 1.0);
out_texcoords = in_texcoords;
out_colour = in_colour;
}";
FragmentSource = @"
#version 130
in vec2 out_texcoords;
in vec4 out_colour;
out vec4 final_colour;
uniform sampler2D texImage;
void main() {
vec4 col;
if(out_texcoords.r >= 0) {
col = texture2D(texImage, out_texcoords) * out_colour;
} else {
col = out_colour;
}
if(col.a < 0.05) {
discard;
}
final_colour = col;
}";
}
public int positionLoc, texCoordsLoc, colourLoc;
public int texImageLoc, projLoc;
protected override void GetLocations( OpenGLApi api ) {
positionLoc = api.GetAttribLocation( ProgramId, "in_position" );
texCoordsLoc = api.GetAttribLocation( ProgramId, "in_texcoords" );
colourLoc = api.GetAttribLocation( ProgramId, "in_colour" );
texImageLoc = api.GetUniformLocation( ProgramId, "texImage" );
projLoc = api.GetUniformLocation( ProgramId, "proj" );
}
const int stride = VertexPos3fTex2fCol4b.Size;
protected override void EnableVertexAttribStates( OpenGLApi api ) {
api.EnableVertexAttribF( positionLoc, 3, stride, 0 );
api.EnableVertexAttribF( colourLoc, 4, VertexAttribType.UInt8, true, stride, 12 );
api.EnableVertexAttribF( texCoordsLoc, 2, stride, 16 );
}
protected override void DisableVertexAttribStates( OpenGLApi api ) {
api.DisableVertexAttrib( positionLoc );
api.DisableVertexAttrib( texCoordsLoc );
api.DisableVertexAttrib( colourLoc );
}
}
}

View file

@ -46,68 +46,4 @@ namespace ClassicalSharp.GraphicsAPI {
protected virtual void DisableVertexAttribStates( OpenGLApi api ) {
}
}
public sealed class GuiShader : Shader {
public GuiShader() {
VertexSource = @"
#version 130
in vec3 in_position;
in vec2 in_texcoords;
in vec4 in_colour;
out vec2 out_texcoords;
out vec4 out_colour;
uniform mat4 proj;
void main() {
gl_Position = proj * vec4(in_position, 1.0);
out_texcoords = in_texcoords;
out_colour = in_colour;
}";
FragmentSource = @"
#version 130
in vec2 out_texcoords;
in vec4 out_colour;
out vec4 final_colour;
uniform sampler2D texImage;
void main() {
vec4 col;
if(out_texcoords.r >= 0) {
col = texture2D(texImage, out_texcoords) * out_colour;
} else {
col = out_colour;
}
if(col.a < 0.05) {
discard;
}
final_colour = col;
}";
}
public int positionLoc, texCoordsLoc, colourLoc;
public int texImageLoc, projLoc;
protected override void GetLocations( OpenGLApi api ) {
positionLoc = api.GetAttribLocation( ProgramId, "in_position" );
texCoordsLoc = api.GetAttribLocation( ProgramId, "in_texcoords" );
colourLoc = api.GetAttribLocation( ProgramId, "in_colour" );
texImageLoc = api.GetUniformLocation( ProgramId, "texImage" );
projLoc = api.GetUniformLocation( ProgramId, "proj" );
}
const int stride = VertexPos3fTex2fCol4b.Size;
protected override void EnableVertexAttribStates( OpenGLApi api ) {
api.EnableVertexAttribF( positionLoc, 3, stride, 0 );
api.EnableVertexAttribF( colourLoc, 4, VertexAttribType.UInt8, true, stride, 12 );
api.EnableVertexAttribF( texCoordsLoc, 2, stride, 16 );
}
protected override void DisableVertexAttribStates( OpenGLApi api ) {
api.DisableVertexAttrib( positionLoc );
api.DisableVertexAttrib( texCoordsLoc );
api.DisableVertexAttrib( colourLoc );
}
}
}