- implement ApplyUniforms

This commit is contained in:
Magnus Norddahl 2019-08-14 12:36:33 +02:00
parent 3c44f77b60
commit 1d09a0f86a
13 changed files with 445 additions and 259 deletions

View file

@ -3462,17 +3462,17 @@ namespace CodeImp.DoomBuilder.Data
Matrix mprojection = Matrix.PerspectiveFovLH(Angle2D.PIHALF, 1.0f, 0.5f, 100.0f);
// Place camera at origin
General.Map.Graphics.SetUniform(Uniform.campos, new Vector4());
General.Map.Graphics.SetUniform(UniformName.campos, new Vector4());
// Begin fullbright shaderpass
General.Map.Graphics.SetVertexDeclaration(General.Map.Graphics.Shaders.WorldVertexDecl);
General.Map.Graphics.SetShader(Shader.world3d_fullbright);
General.Map.Graphics.SetShader(ShaderName.world3d_fullbright);
// Render to the six faces of the cube map
for(int i = 0; i < 6; i++)
{
Matrix faceview = GetCubeMapViewMatrix((CubeMapFace)i);
General.Map.Graphics.SetUniform(Uniform.worldviewproj, mworld * faceview * mprojection);
General.Map.Graphics.SetUniform(UniformName.worldviewproj, mworld * faceview * mprojection);
// Render the skysphere meshes
for(int j = 0; j < meshes.Meshes.Count; j++)
@ -3480,9 +3480,9 @@ namespace CodeImp.DoomBuilder.Data
// Set appropriate texture
switch(meshes.Skins[j])
{
case "top.png": General.Map.Graphics.SetUniform(Uniform.texture1, textop); break;
case "bottom.png": General.Map.Graphics.SetUniform(Uniform.texture1, texbottom); break;
case "side.png": General.Map.Graphics.SetUniform(Uniform.texture1, texside); break;
case "top.png": General.Map.Graphics.SetUniform(UniformName.texture1, textop); break;
case "bottom.png": General.Map.Graphics.SetUniform(UniformName.texture1, texbottom); break;
case "side.png": General.Map.Graphics.SetUniform(UniformName.texture1, texside); break;
default: throw new Exception("Unexpected skin!");
}

View file

@ -57,6 +57,59 @@ namespace CodeImp.DoomBuilder.Rendering
}
}
public void SetShader(ShaderName shader)
{
RenderDevice_SetShader(Handle, shader);
}
public void SetUniform(UniformName uniform, bool value)
{
RenderDevice_SetUniform(Handle, uniform, new float[] { value ? 1.0f : 0.0f }, 1);
}
public void SetUniform(UniformName uniform, float value)
{
RenderDevice_SetUniform(Handle, uniform, new float[] { value }, 1);
}
public void SetUniform(UniformName uniform, Vector2 value)
{
RenderDevice_SetUniform(Handle, uniform, new float[] { value.X, value.Y }, 2);
}
public void SetUniform(UniformName uniform, Vector3 value)
{
RenderDevice_SetUniform(Handle, uniform, new float[] { value.X, value.Y, value.Z }, 3);
}
public void SetUniform(UniformName uniform, Vector4 value)
{
RenderDevice_SetUniform(Handle, uniform, new float[] { value.X, value.Y, value.Z, value.W }, 4);
}
public void SetUniform(UniformName uniform, Color4 value)
{
RenderDevice_SetUniform(Handle, uniform, new float[] { value.Red, value.Green, value.Blue, value.Alpha }, 4);
}
public void SetUniform(UniformName uniform, BaseTexture value)
{
}
public void SetUniform(UniformName uniform, TextureFilter value)
{
}
public void SetUniform(UniformName uniform, Matrix matrix)
{
RenderDevice_SetUniform(Handle, uniform, new float[] {
matrix.M11, matrix.M12, matrix.M13, matrix.M14,
matrix.M21, matrix.M22, matrix.M23, matrix.M24,
matrix.M31, matrix.M32, matrix.M33, matrix.M34,
matrix.M41, matrix.M42, matrix.M43, matrix.M44
}, 16);
}
public void SetVertexBuffer(int index, VertexBuffer buffer, long offset, long stride)
{
RenderDevice_SetVertexBuffer(Handle, index, buffer != null ? buffer.Handle : IntPtr.Zero, offset, stride);
@ -261,6 +314,12 @@ namespace CodeImp.DoomBuilder.Rendering
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void RenderDevice_Delete(IntPtr handle);
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr RenderDevice_SetShader(IntPtr hwnd, ShaderName name);
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr RenderDevice_SetUniform(IntPtr hwnd, UniformName name, float[] data, int count);
[DllImport("BuilderNative.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void RenderDevice_SetVertexBuffer(IntPtr handle, int index, IntPtr buffer, long offset, long stride);
@ -389,20 +448,9 @@ namespace CodeImp.DoomBuilder.Rendering
{
return new Vector2D(v2.X, v2.Y);
}
public void SetShader(Shader shader) { }
public void SetUniform(Uniform uniform, bool value) { }
public void SetUniform(Uniform uniform, float value) { }
public void SetUniform(Uniform uniform, Vector2 value) { }
public void SetUniform(Uniform uniform, Vector3 value) { }
public void SetUniform(Uniform uniform, Vector4 value) { }
public void SetUniform(Uniform uniform, Color4 value) { }
public void SetUniform(Uniform uniform, Matrix value) { }
public void SetUniform(Uniform uniform, BaseTexture value) { }
public void SetUniform(Uniform uniform, TextureFilter value) { }
}
public enum Shader : int
public enum ShaderName : int
{
basic,
display2d_fsaa,
@ -431,11 +479,10 @@ namespace CodeImp.DoomBuilder.Rendering
world3d_lightpass // AlphaBlendEnable = true
}
public enum Uniform : int
public enum UniformName : int
{
rendersettings,
transformsettings,
filtersettings,
desaturation,
texture1,
highlightcolor,
@ -452,6 +499,7 @@ namespace CodeImp.DoomBuilder.Rendering
ignoreNormals,
spotLight,
campos,
filtersettings,
magfiltersettings,
minfiltersettings,
mipfiltersettings,

View file

@ -191,7 +191,7 @@ namespace CodeImp.DoomBuilder.Rendering
// Go for all layers
foreach(PresentLayer layer in present.layers)
{
Shader aapass;
ShaderName aapass;
// Set blending mode
switch(layer.blending)
@ -226,7 +226,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// Check which pass to use
if(layer.antialiasing && General.Settings.QualityDisplay) aapass = Shader.display2d_fsaa; else aapass = Shader.display2d_normal;
if(layer.antialiasing && General.Settings.QualityDisplay) aapass = ShaderName.display2d_fsaa; else aapass = ShaderName.display2d_normal;
// Render layer
switch(layer.layer)
@ -235,7 +235,7 @@ namespace CodeImp.DoomBuilder.Rendering
case RendererLayer.Background:
if((backimageverts == null) || (General.Map.Grid.Background.Texture == null)) break;
graphics.SetShader(aapass);
graphics.SetUniform(Uniform.texture1, General.Map.Grid.Background.Texture);
graphics.SetUniform(UniformName.texture1, General.Map.Grid.Background.Texture);
graphics.Shaders.SetDisplay2DSettings(1f / windowsize.Width, 1f / windowsize.Height, FSAA_FACTOR, layer.alpha, false);
graphics.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, backimageverts);
graphics.SetVertexBuffer(0, screenverts, 0, sizeof(FlatVertex));
@ -244,7 +244,7 @@ namespace CodeImp.DoomBuilder.Rendering
// GRID
case RendererLayer.Grid:
graphics.SetShader(aapass);
graphics.SetUniform(Uniform.texture1, backtex);
graphics.SetUniform(UniformName.texture1, backtex);
graphics.Shaders.SetDisplay2DSettings(1f / backsize.Width, 1f / backsize.Height, FSAA_FACTOR, layer.alpha, false);
graphics.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
break;
@ -252,7 +252,7 @@ namespace CodeImp.DoomBuilder.Rendering
// GEOMETRY
case RendererLayer.Geometry:
graphics.SetShader(aapass);
graphics.SetUniform(Uniform.texture1, plottertex);
graphics.SetUniform(UniformName.texture1, plottertex);
graphics.Shaders.SetDisplay2DSettings(1f / structsize.Width, 1f / structsize.Height, FSAA_FACTOR, layer.alpha, false);
graphics.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
break;
@ -260,7 +260,7 @@ namespace CodeImp.DoomBuilder.Rendering
// THINGS
case RendererLayer.Things:
graphics.SetShader(aapass);
graphics.SetUniform(Uniform.texture1, thingstex);
graphics.SetUniform(UniformName.texture1, thingstex);
graphics.Shaders.SetDisplay2DSettings(1f / thingssize.Width, 1f / thingssize.Height, FSAA_FACTOR, layer.alpha, false);
graphics.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
break;
@ -268,7 +268,7 @@ namespace CodeImp.DoomBuilder.Rendering
// OVERLAY
case RendererLayer.Overlay:
graphics.SetShader(aapass);
graphics.SetUniform(Uniform.texture1, overlaytex);
graphics.SetUniform(UniformName.texture1, overlaytex);
graphics.Shaders.SetDisplay2DSettings(1f / overlaysize.Width, 1f / overlaysize.Height, FSAA_FACTOR, layer.alpha, false);
graphics.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
break;
@ -276,7 +276,7 @@ namespace CodeImp.DoomBuilder.Rendering
// SURFACE
case RendererLayer.Surface:
graphics.SetShader(aapass);
graphics.SetUniform(Uniform.texture1, surfacetex);
graphics.SetUniform(UniformName.texture1, surfacetex);
graphics.Shaders.SetDisplay2DSettings(1f / overlaysize.Width, 1f / overlaysize.Height, FSAA_FACTOR, layer.alpha, false);
graphics.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
break;
@ -288,7 +288,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.Present();
// Release binds
graphics.SetUniform(Uniform.texture1, null);
graphics.SetUniform(UniformName.texture1, null);
graphics.SetVertexBuffer(0, null, 0, 0);
}
@ -1209,10 +1209,10 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetVertexBuffer(0, thingsvertices, 0, FlatVertex.Stride);
// Set things texture
graphics.SetUniform(Uniform.texture1, General.Map.Data.ThingTexture.Texture); //mxd
graphics.SetUniform(UniformName.texture1, General.Map.Data.ThingTexture.Texture); //mxd
SetWorldTransformation(false);
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.things2d_thing);
graphics.SetShader(ShaderName.things2d_thing);
graphics.Shaders.SetThings2DSettings(alpha);
// Determine next lock size
@ -1278,7 +1278,7 @@ namespace CodeImp.DoomBuilder.Rendering
//mxd. Render sprites
int selectionColor = General.Colors.Selection.ToInt();
graphics.SetShader(Shader.things2d_sprite);
graphics.SetShader(ShaderName.things2d_sprite);
foreach(KeyValuePair<int, List<Thing>> group in thingsByType)
{
@ -1323,7 +1323,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
if(sprite.Texture == null) sprite.CreateTexture();
graphics.SetUniform(Uniform.texture1, sprite.Texture);
graphics.SetUniform(UniformName.texture1, sprite.Texture);
// Determine next lock size
locksize = (framegroup.Value.Count > THING_BUFFER_SIZE) ? THING_BUFFER_SIZE : framegroup.Value.Count;
@ -1418,8 +1418,8 @@ namespace CodeImp.DoomBuilder.Rendering
}
//mxd. Render thing arrows
graphics.SetUniform(Uniform.texture1, General.Map.Data.ThingTexture.Texture);
graphics.SetShader(Shader.things2d_thing);
graphics.SetUniform(UniformName.texture1, General.Map.Data.ThingTexture.Texture);
graphics.SetShader(ShaderName.things2d_thing);
// Determine next lock size
locksize = (thingsByPosition.Count > THING_BUFFER_SIZE) ? THING_BUFFER_SIZE : thingsByPosition.Count;
@ -1467,7 +1467,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetTextureFactor(-1);
graphics.SetFillMode(FillMode.Wireframe);
graphics.SetShader(Shader.things2d_fill);
graphics.SetShader(ShaderName.things2d_fill);
Color4 cSelection = General.Colors.Selection.ToColorValue();
Color4 cWire = ((c.ToInt() == General.Colors.Highlight.ToInt()) ? General.Colors.Highlight.ToColorValue() : General.Colors.ModelWireframe.ToColorValue());
@ -1491,7 +1491,7 @@ namespace CodeImp.DoomBuilder.Rendering
((screenpos.y + mde.Model.Radius * modelScale) <= 0.0f) || ((screenpos.y - mde.Model.Radius * modelScale) >= windowsize.Height))
continue;
graphics.SetUniform(Uniform.FillColor, (t.Selected ? cSelection : cWire));
graphics.SetUniform(UniformName.FillColor, (t.Selected ? cSelection : cWire));
// Set transform settings
float sx = t.ScaleX * t.ActorScale.Width;
@ -1621,8 +1621,8 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetTextureFactor(-1);
graphics.SetFogEnable(false);
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.display2d_normal);
graphics.SetUniform(Uniform.texture1, t);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetUniform(UniformName.texture1, t);
SetWorldTransformation(transformcoords);
graphics.Shaders.SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
@ -1645,12 +1645,12 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetFogEnable(false);
SetWorldTransformation(true);
graphics.SetUniform(Uniform.FillColor, new Color4(color));
graphics.SetUniform(UniformName.FillColor, new Color4(color));
graphics.Shaders.SetThings2DSettings(1.0f);
// Draw
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.things2d_fill);
graphics.SetShader(ShaderName.things2d_fill);
graphics.DrawUserPrimitives(PrimitiveType.TriangleList, 0, vertices.Length / 3, vertices);
}
@ -1673,8 +1673,8 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetTextureFactor(-1);
graphics.SetFogEnable(false);
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.display2d_normal);
graphics.SetUniform(Uniform.texture1, label.Texture);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetUniform(UniformName.texture1, label.Texture);
SetWorldTransformation(false);
graphics.Shaders.SetDisplay2DSettings(1f, 1f, 0f, 1f, false);
graphics.SetVertexBuffer(0, label.VertexBuffer, 0, FlatVertex.Stride);
@ -1706,7 +1706,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.display2d_normal);
graphics.SetShader(ShaderName.display2d_normal);
graphics.Shaders.SetDisplay2DSettings(1f, 1f, 0f, 1f, false);
foreach(ITextLabel label in labels)
@ -1714,7 +1714,7 @@ namespace CodeImp.DoomBuilder.Rendering
// Text is created?
if(!label.SkipRendering)
{
graphics.SetUniform(Uniform.texture1, label.Texture);
graphics.SetUniform(UniformName.texture1, label.Texture);
graphics.SetVertexBuffer(0, label.VertexBuffer, 0, FlatVertex.Stride);
// Draw
@ -1774,8 +1774,8 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.display2d_normal);
graphics.SetUniform(Uniform.texture1, General.Map.Data.WhiteTexture.Texture);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetUniform(UniformName.texture1, General.Map.Data.WhiteTexture.Texture);
graphics.Shaders.SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
// Draw
@ -1810,8 +1810,8 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.display2d_normal);
graphics.SetUniform(Uniform.texture1, General.Map.Data.WhiteTexture.Texture);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetUniform(UniformName.texture1, General.Map.Data.WhiteTexture.Texture);
graphics.Shaders.SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
// Draw
@ -1843,8 +1843,8 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.display2d_normal);
graphics.SetUniform(Uniform.texture1, texture.Texture);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetUniform(UniformName.texture1, texture.Texture);
graphics.Shaders.SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
// Draw
@ -1943,8 +1943,8 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.display2d_normal);
graphics.SetUniform(Uniform.texture1, General.Map.Data.WhiteTexture.Texture);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetUniform(UniformName.texture1, General.Map.Data.WhiteTexture.Texture);
graphics.Shaders.SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
// Draw
@ -1996,8 +1996,8 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.display2d_normal);
graphics.SetUniform(Uniform.texture1, General.Map.Data.WhiteTexture.Texture);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetUniform(UniformName.texture1, General.Map.Data.WhiteTexture.Texture);
graphics.Shaders.SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
// Draw

View file

@ -51,7 +51,7 @@ namespace CodeImp.DoomBuilder.Rendering
private Matrix world;
private Vector3D cameraposition;
private Vector3D cameravector;
private Shader shaderpass;
private ShaderName shaderpass;
// Window size
private Size windowsize;
@ -281,7 +281,7 @@ namespace CodeImp.DoomBuilder.Rendering
// This applies the matrices
private void ApplyMatrices3D()
{
graphics.SetUniform(Uniform.worldviewproj, world * viewproj); //mxd. Multiplication is ~2x faster than "world * view3d * projection";
graphics.SetUniform(UniformName.worldviewproj, world * viewproj); //mxd. Multiplication is ~2x faster than "world * view3d * projection";
}
// This sets the appropriate view matrix
@ -314,7 +314,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetFogStart(General.Settings.ViewDistance * FOG_RANGE);
graphics.SetFogEnd(General.Settings.ViewDistance);
graphics.SetTextureFactor(-1);
graphics.SetUniform(Uniform.highlightcolor, new Color4()); //mxd
graphics.SetUniform(UniformName.highlightcolor, new Color4()); //mxd
// Texture addressing
graphics.SetSamplerState(0, TextureAddress.Wrap);
@ -336,7 +336,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// Determine shader pass to use
shaderpass = (fullbrightness ? Shader.world3d_fullbright : Shader.world3d_main);
shaderpass = (fullbrightness ? ShaderName.world3d_fullbright : ShaderName.world3d_main);
// Create crosshair vertices
if(crosshairverts == null)
@ -432,9 +432,9 @@ namespace CodeImp.DoomBuilder.Rendering
{
graphics.SetAlphaTestEnable(true);
graphics.SetCullMode(Cull.None);
graphics.SetUniform(Uniform.ignoreNormals, true);
graphics.SetUniform(UniformName.ignoreNormals, true);
RenderModels(true, false);
graphics.SetUniform(Uniform.ignoreNormals, false);
graphics.SetUniform(UniformName.ignoreNormals, false);
graphics.SetCullMode(Cull.Counterclockwise);
}
}
@ -477,9 +477,9 @@ namespace CodeImp.DoomBuilder.Rendering
if (General.Settings.GZDrawLightsMode != LightRenderMode.NONE && !fullbrightness && lightthings.Count > 0 && translucentmodelthings.Count > 0)
{
graphics.SetAlphaTestEnable(true);
graphics.SetUniform(Uniform.ignoreNormals, true);
graphics.SetUniform(UniformName.ignoreNormals, true);
RenderModels(true, true);
graphics.SetUniform(Uniform.ignoreNormals, false);
graphics.SetUniform(UniformName.ignoreNormals, false);
}
// THING CAGES
@ -497,7 +497,7 @@ namespace CodeImp.DoomBuilder.Rendering
if(General.Settings.GZShowEventLines) RenderArrows(eventlines);
// Remove references
graphics.SetUniform(Uniform.texture1, null);
graphics.SetUniform(UniformName.texture1, null);
//mxd. Trash collections
solidgeo = null;
@ -586,7 +586,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.SourceAlpha);
graphics.SetShader(Shader.world3d_constant_color);
graphics.SetShader(ShaderName.world3d_constant_color);
foreach(VisualThing t in allthings)
{
@ -601,7 +601,7 @@ namespace CodeImp.DoomBuilder.Rendering
thingcolor = t.CageColor;
if(t != highlighted) thingcolor.Alpha = 0.6f;
}
graphics.SetUniform(Uniform.vertexColor, thingcolor);
graphics.SetUniform(UniformName.vertexColor, thingcolor);
//Render cage
graphics.SetVertexBuffer(0, t.CageBuffer, 0, WorldVertex.Stride);
@ -623,7 +623,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.SourceAlpha);
graphics.SetShader(Shader.world3d_constant_color);
graphics.SetShader(ShaderName.world3d_constant_color);
foreach(VisualVertex v in visualvertices)
{
@ -641,7 +641,7 @@ namespace CodeImp.DoomBuilder.Rendering
color = v.HaveHeightOffset ? General.Colors.InfoLine.ToColorValue() : General.Colors.Vertices.ToColorValue();
if(v != highlighted) color.Alpha = 0.6f;
}
graphics.SetUniform(Uniform.vertexColor, color);
graphics.SetUniform(UniformName.vertexColor, color);
//Commence drawing!!11
graphics.SetVertexBuffer(0, v.CeilingVertex ? vertexhandle.Upper : vertexhandle.Lower, 0, WorldVertex.Stride);
@ -717,7 +717,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.SourceAlpha);
graphics.SetShader(Shader.world3d_vertex_color);
graphics.SetShader(ShaderName.world3d_vertex_color);
world = Matrix.Identity;
ApplyMatrices3D();
@ -735,8 +735,8 @@ namespace CodeImp.DoomBuilder.Rendering
private void RenderSinglePass(Dictionary<ImageData, List<VisualGeometry>> geopass, Dictionary<ImageData, List<VisualThing>> thingspass)
{
ImageData curtexture;
Shader currentshaderpass = shaderpass;
Shader highshaderpass = (Shader)(shaderpass + 2);
ShaderName currentshaderpass = shaderpass;
ShaderName highshaderpass = (ShaderName)(shaderpass + 2);
// Begin rendering with this shader
graphics.SetShader(shaderpass);
@ -757,7 +757,7 @@ namespace CodeImp.DoomBuilder.Rendering
curtexture.CreateTexture();
// Apply texture
graphics.SetUniform(Uniform.texture1, curtexture.Texture);
graphics.SetUniform(UniformName.texture1, curtexture.Texture);
//mxd. Sort geometry by sector index
group.Value.Sort((g1, g2) => g1.Sector.Sector.FixedIndex - g2.Sector.Sector.FixedIndex);
@ -789,11 +789,11 @@ namespace CodeImp.DoomBuilder.Rendering
}
}
graphics.SetUniform(Uniform.desaturation, 0.0f);
graphics.SetUniform(UniformName.desaturation, 0.0f);
if (sector != null)
{
// Determine the shader pass we want to use for this object
Shader wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass;
ShaderName wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass;
//mxd. Render fog?
if(General.Settings.GZDrawFog && !fullbrightness && sector.Sector.FogMode != SectorFogMode.NONE)
@ -806,25 +806,25 @@ namespace CodeImp.DoomBuilder.Rendering
currentshaderpass = wantedshaderpass;
//mxd. Set variables for fog rendering?
if(wantedshaderpass > Shader.world3d_p7)
if(wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(Uniform.world, world);
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
}
}
//mxd. Set variables for fog rendering?
if(wantedshaderpass > Shader.world3d_p7)
if(wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, g.FogFactor));
graphics.SetUniform(Uniform.lightColor, sector.Sector.FogColor);
graphics.SetUniform(UniformName.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, g.FogFactor));
graphics.SetUniform(UniformName.lightColor, sector.Sector.FogColor);
}
// Set the colors to use
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection)));
graphics.SetUniform(UniformName.highlightcolor, CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection)));
// [ZZ] include desaturation factor
graphics.SetUniform(Uniform.desaturation, sector.Sector.Desaturation);
graphics.SetUniform(UniformName.desaturation, sector.Sector.Desaturation);
// Render!
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
@ -857,7 +857,7 @@ namespace CodeImp.DoomBuilder.Rendering
curtexture.CreateTexture();
// Apply texture
graphics.SetUniform(Uniform.texture1, curtexture.Texture);
graphics.SetUniform(UniformName.texture1, curtexture.Texture);
// Render all things with this texture
foreach(VisualThing t in group.Value)
@ -873,7 +873,7 @@ namespace CodeImp.DoomBuilder.Rendering
if(t.GeometryBuffer != null)
{
// Determine the shader pass we want to use for this object
Shader wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass;
ShaderName wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass;
//mxd. If fog is enagled, switch to shader, which calculates it
if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE)
@ -911,25 +911,25 @@ namespace CodeImp.DoomBuilder.Rendering
}
//mxd. Set variables for fog rendering?
if(wantedshaderpass > Shader.world3d_p7)
if(wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(Uniform.world, world);
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
graphics.SetUniform(UniformName.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
}
// Set the colors to use
if(t.Thing.Sector != null) graphics.SetUniform(Uniform.lightColor, t.Thing.Sector.FogColor);
graphics.SetUniform(Uniform.vertexColor, vertexcolor);
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection)));
if(t.Thing.Sector != null) graphics.SetUniform(UniformName.lightColor, t.Thing.Sector.FogColor);
graphics.SetUniform(UniformName.vertexColor, vertexcolor);
graphics.SetUniform(UniformName.highlightcolor, CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection)));
// [ZZ] check if we want stencil
graphics.SetUniform(Uniform.stencilColor, t.StencilColor.ToColorValue());
graphics.SetUniform(UniformName.stencilColor, t.StencilColor.ToColorValue());
// [ZZ] apply desaturation
if (t.Thing.Sector != null)
graphics.SetUniform(Uniform.desaturation, t.Thing.Sector.Desaturation);
else graphics.SetUniform(Uniform.desaturation, 0.0f);
graphics.SetUniform(UniformName.desaturation, t.Thing.Sector.Desaturation);
else graphics.SetUniform(UniformName.desaturation, 0.0f);
// Apply changes
ApplyMatrices3D();
@ -943,7 +943,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// [ZZ]
graphics.SetUniform(Uniform.stencilColor, new Color4(0f, 1f, 1f, 1f));
graphics.SetUniform(UniformName.stencilColor, new Color4(0f, 1f, 1f, 1f));
}
// Texture addressing
@ -955,8 +955,8 @@ namespace CodeImp.DoomBuilder.Rendering
//mxd
private void RenderTranslucentPass(List<VisualGeometry> geopass, List<VisualThing> thingspass)
{
Shader currentshaderpass = shaderpass;
Shader highshaderpass = (Shader)(shaderpass + 2);
ShaderName currentshaderpass = shaderpass;
ShaderName highshaderpass = (ShaderName)(shaderpass + 2);
// Sort geometry by camera distance. First vertex of the BoundingBox is it's center
geopass.Sort(delegate(VisualGeometry vg1, VisualGeometry vg2)
@ -1037,7 +1037,7 @@ namespace CodeImp.DoomBuilder.Rendering
curtexture.CreateTexture();
// Apply texture
graphics.SetUniform(Uniform.texture1, curtexture.Texture);
graphics.SetUniform(UniformName.texture1, curtexture.Texture);
curtexturename = g.Texture.LongName;
}
@ -1066,7 +1066,7 @@ namespace CodeImp.DoomBuilder.Rendering
if (sector != null)
{
// Determine the shader pass we want to use for this object
Shader wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass;
ShaderName wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass;
//mxd. Render fog?
if (General.Settings.GZDrawFog && !fullbrightness && sector.Sector.FogMode != SectorFogMode.NONE)
@ -1079,31 +1079,31 @@ namespace CodeImp.DoomBuilder.Rendering
currentshaderpass = wantedshaderpass;
//mxd. Set variables for fog rendering?
if (wantedshaderpass > Shader.world3d_p7)
if (wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(Uniform.world, world);
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
}
}
// Set variables for fog rendering?
if (wantedshaderpass > Shader.world3d_p7 && g.FogFactor != fogfactor)
if (wantedshaderpass > ShaderName.world3d_p7 && g.FogFactor != fogfactor)
{
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, g.FogFactor));
graphics.SetUniform(UniformName.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, g.FogFactor));
fogfactor = g.FogFactor;
}
//
graphics.SetUniform(Uniform.desaturation, sector.Sector.Desaturation);
graphics.SetUniform(UniformName.desaturation, sector.Sector.Desaturation);
// Set the colors to use
graphics.SetUniform(Uniform.lightColor, sector.Sector.FogColor);
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection)));
graphics.SetUniform(UniformName.lightColor, sector.Sector.FogColor);
graphics.SetUniform(UniformName.highlightcolor, CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection)));
// Render!
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
}
else graphics.SetUniform(Uniform.desaturation, 0.0f);
else graphics.SetUniform(UniformName.desaturation, 0.0f);
}
// Get things for this pass
@ -1171,7 +1171,7 @@ namespace CodeImp.DoomBuilder.Rendering
curtexture.CreateTexture();
// Apply texture
graphics.SetUniform(Uniform.texture1, curtexture.Texture);
graphics.SetUniform(UniformName.texture1, curtexture.Texture);
curtexturename = t.Texture.LongName;
}
@ -1179,7 +1179,7 @@ namespace CodeImp.DoomBuilder.Rendering
if(t.GeometryBuffer != null)
{
// Determine the shader pass we want to use for this object
Shader wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass;
ShaderName wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass;
//mxd. if fog is enagled, switch to shader, which calculates it
if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE)
@ -1217,27 +1217,27 @@ namespace CodeImp.DoomBuilder.Rendering
}
//mxd. Set variables for fog rendering?
if(wantedshaderpass > Shader.world3d_p7)
if(wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(Uniform.world, world);
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
if (t.FogFactor != fogfactor)
{
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
graphics.SetUniform(UniformName.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
fogfactor = t.FogFactor;
}
}
// Set the colors to use
graphics.SetUniform(Uniform.lightColor, t.Thing.Sector.FogColor);
graphics.SetUniform(Uniform.vertexColor, vertexcolor);
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection)));
graphics.SetUniform(UniformName.lightColor, t.Thing.Sector.FogColor);
graphics.SetUniform(UniformName.vertexColor, vertexcolor);
graphics.SetUniform(UniformName.highlightcolor, CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection)));
// [ZZ] check if we want stencil
graphics.SetUniform(Uniform.stencilColor, t.StencilColor.ToColorValue());
graphics.SetUniform(UniformName.stencilColor, t.StencilColor.ToColorValue());
//
graphics.SetUniform(Uniform.desaturation, t.Thing.Sector.Desaturation);
graphics.SetUniform(UniformName.desaturation, t.Thing.Sector.Desaturation);
// Apply changes
ApplyMatrices3D();
@ -1251,7 +1251,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// [ZZ] check if we want stencil
graphics.SetUniform(Uniform.stencilColor, new Color4(0f, 1f, 1f, 1f));
graphics.SetUniform(UniformName.stencilColor, new Color4(0f, 1f, 1f, 1f));
// Texture addressing
graphics.SetSamplerState(0, TextureAddress.Wrap);
@ -1326,14 +1326,14 @@ namespace CodeImp.DoomBuilder.Rendering
if (sector == null) continue;
graphics.SetUniform(Uniform.desaturation, sector.Sector.Desaturation);
graphics.SetUniform(UniformName.desaturation, sector.Sector.Desaturation);
// note: additive geometry doesn't receive lighting
if (g.RenderPass == RenderPass.Additive)
continue;
if (settexture)
graphics.SetUniform(Uniform.texture1, g.Texture.Texture);
graphics.SetUniform(UniformName.texture1, g.Texture.Texture);
//normal lights
int count = lightOffsets[0];
@ -1348,16 +1348,16 @@ namespace CodeImp.DoomBuilder.Rendering
{
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
if (lpr.W == 0) continue;
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
graphics.SetUniform(UniformName.lightColor, lights[i].LightColor);
graphics.SetUniform(UniformName.lightPosAndRadius, lpr);
GZGeneral.LightData ld = lights[i].LightType;
if (ld.LightType == GZGeneral.LightType.SPOT)
{
graphics.SetUniform(Uniform.spotLight, true);
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
graphics.SetUniform(UniformName.spotLight, true);
graphics.SetUniform(UniformName.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(UniformName.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
}
else graphics.SetUniform(Uniform.spotLight, false);
else graphics.SetUniform(UniformName.spotLight, false);
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
}
}
@ -1375,16 +1375,16 @@ namespace CodeImp.DoomBuilder.Rendering
{
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
if (lpr.W == 0) continue;
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
graphics.SetUniform(UniformName.lightColor, lights[i].LightColor);
graphics.SetUniform(UniformName.lightPosAndRadius, lpr);
GZGeneral.LightData ld = lights[i].LightType;
if (ld.LightType == GZGeneral.LightType.SPOT)
{
graphics.SetUniform(Uniform.spotLight, true);
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
graphics.SetUniform(UniformName.spotLight, true);
graphics.SetUniform(UniformName.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(UniformName.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
}
else graphics.SetUniform(Uniform.spotLight, false);
else graphics.SetUniform(UniformName.spotLight, false);
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
}
}
@ -1402,16 +1402,16 @@ namespace CodeImp.DoomBuilder.Rendering
{
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
if (lpr.W == 0) continue;
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
graphics.SetUniform(UniformName.lightColor, lights[i].LightColor);
graphics.SetUniform(UniformName.lightPosAndRadius, lpr);
GZGeneral.LightData ld = lights[i].LightType;
if (ld.LightType == GZGeneral.LightType.SPOT)
{
graphics.SetUniform(Uniform.spotLight, true);
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
graphics.SetUniform(UniformName.spotLight, true);
graphics.SetUniform(UniformName.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(UniformName.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
}
else graphics.SetUniform(Uniform.spotLight, false);
else graphics.SetUniform(UniformName.spotLight, false);
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
}
}
@ -1430,16 +1430,16 @@ namespace CodeImp.DoomBuilder.Rendering
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
if (lpr.W == 0) continue;
Color4 lc = lights[i].LightColor;
graphics.SetUniform(Uniform.lightColor, new Color4(lc.Alpha, (lc.Green + lc.Blue) / 2, (lc.Red + lc.Blue) / 2, (lc.Green + lc.Red) / 2));
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
graphics.SetUniform(UniformName.lightColor, new Color4(lc.Alpha, (lc.Green + lc.Blue) / 2, (lc.Red + lc.Blue) / 2, (lc.Green + lc.Red) / 2));
graphics.SetUniform(UniformName.lightPosAndRadius, lpr);
GZGeneral.LightData ld = lights[i].LightType;
if (ld.LightType == GZGeneral.LightType.SPOT)
{
graphics.SetUniform(Uniform.spotLight, true);
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
graphics.SetUniform(UniformName.spotLight, true);
graphics.SetUniform(UniformName.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(UniformName.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
}
else graphics.SetUniform(Uniform.spotLight, false);
else graphics.SetUniform(UniformName.spotLight, false);
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
}
}
@ -1454,9 +1454,9 @@ namespace CodeImp.DoomBuilder.Rendering
{
if (geometrytolit.Count == 0) return;
graphics.SetUniform(Uniform.world, Matrix.Identity);
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
graphics.SetShader(Shader.world3d_lightpass);
graphics.SetUniform(UniformName.world, Matrix.Identity);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
graphics.SetShader(ShaderName.world3d_lightpass);
VisualSector sector = null;
@ -1476,9 +1476,9 @@ namespace CodeImp.DoomBuilder.Rendering
// Anything to do?
if (geometrytolit.Count == 0) return;
graphics.SetUniform(Uniform.world, Matrix.Identity);
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
graphics.SetShader(Shader.world3d_lightpass);
graphics.SetUniform(UniformName.world, Matrix.Identity);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
graphics.SetShader(ShaderName.world3d_lightpass);
VisualSector sector = null;
@ -1488,7 +1488,7 @@ namespace CodeImp.DoomBuilder.Rendering
foreach (KeyValuePair<ImageData, List<VisualGeometry>> group in geometrytolit)
{
if (group.Key.Texture == null) continue;
graphics.SetUniform(Uniform.texture1, group.Key.Texture);
graphics.SetUniform(UniformName.texture1, group.Key.Texture);
sector = RenderLightsFromGeometryList(group.Value, lights, sector, false);
}
@ -1499,9 +1499,9 @@ namespace CodeImp.DoomBuilder.Rendering
//mxd. Render models
private void RenderModels(bool lightpass, bool trans)
{
Shader shaderpass = (fullbrightness ? Shader.world3d_fullbright : Shader.world3d_main_vertexcolor);
Shader currentshaderpass = shaderpass;
Shader highshaderpass = (Shader)(shaderpass + 2);
ShaderName shaderpass = (fullbrightness ? ShaderName.world3d_fullbright : ShaderName.world3d_main_vertexcolor);
ShaderName currentshaderpass = shaderpass;
ShaderName highshaderpass = (ShaderName)(shaderpass + 2);
RenderPass currentpass = RenderPass.Solid;
@ -1512,7 +1512,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
else
{
graphics.SetShader(Shader.world3d_lightpass);
graphics.SetShader(ShaderName.world3d_lightpass);
}
List<VisualThing> things;
@ -1563,10 +1563,10 @@ namespace CodeImp.DoomBuilder.Rendering
Color4 vertexcolor = new Color4(t.VertexColor);
// Check if model is affected by dynamic lights and set color accordingly
graphics.SetUniform(Uniform.vertexColor, vertexcolor);
graphics.SetUniform(UniformName.vertexColor, vertexcolor);
// Determine the shader pass we want to use for this object
Shader wantedshaderpass = ((((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass);
ShaderName wantedshaderpass = ((((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass);
// If fog is enagled, switch to shader, which calculates it
if (General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE)
@ -1580,7 +1580,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// Set the colors to use
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection)));
graphics.SetUniform(UniformName.highlightcolor, CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection)));
// Create the matrix for positioning / rotation
float sx = t.Thing.ScaleX * t.Thing.ActorScale.Width;
@ -1593,23 +1593,23 @@ namespace CodeImp.DoomBuilder.Rendering
ApplyMatrices3D();
// Set variables for fog rendering
if(wantedshaderpass > Shader.world3d_p7)
if(wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(Uniform.world, world);
graphics.SetUniform(UniformName.world, world);
// this is not right...
graphics.SetUniform(Uniform.modelnormal, General.Map.Data.ModeldefEntries[t.Thing.Type].TransformRotation * modelrotation);
if (t.Thing.Sector != null) graphics.SetUniform(Uniform.lightColor, t.Thing.Sector.FogColor);
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
graphics.SetUniform(UniformName.modelnormal, General.Map.Data.ModeldefEntries[t.Thing.Type].TransformRotation * modelrotation);
if (t.Thing.Sector != null) graphics.SetUniform(UniformName.lightColor, t.Thing.Sector.FogColor);
graphics.SetUniform(UniformName.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
}
if (t.Thing.Sector != null)
graphics.SetUniform(Uniform.desaturation, t.Thing.Sector.Desaturation);
else graphics.SetUniform(Uniform.desaturation, 0.0f);
graphics.SetUniform(UniformName.desaturation, t.Thing.Sector.Desaturation);
else graphics.SetUniform(UniformName.desaturation, 0.0f);
GZModel model = General.Map.Data.ModeldefEntries[t.Thing.Type].Model;
for (int j = 0; j < model.Meshes.Count; j++)
{
graphics.SetUniform(Uniform.texture1, model.Textures[j]);
graphics.SetUniform(UniformName.texture1, model.Textures[j]);
if (!lightpass)
{
@ -1634,16 +1634,16 @@ namespace CodeImp.DoomBuilder.Rendering
{
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
if (lpr.W == 0) continue;
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
graphics.SetUniform(UniformName.lightColor, lights[i].LightColor);
graphics.SetUniform(UniformName.lightPosAndRadius, lpr);
GZGeneral.LightData ld = lights[i].LightType;
if (ld.LightType == GZGeneral.LightType.SPOT)
{
graphics.SetUniform(Uniform.spotLight, true);
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
graphics.SetUniform(UniformName.spotLight, true);
graphics.SetUniform(UniformName.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(UniformName.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
}
else graphics.SetUniform(Uniform.spotLight, false);
else graphics.SetUniform(UniformName.spotLight, false);
model.Meshes[j].Draw(graphics);
}
}
@ -1661,16 +1661,16 @@ namespace CodeImp.DoomBuilder.Rendering
{
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
if (lpr.W == 0) continue;
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
graphics.SetUniform(UniformName.lightColor, lights[i].LightColor);
graphics.SetUniform(UniformName.lightPosAndRadius, lpr);
GZGeneral.LightData ld = lights[i].LightType;
if (ld.LightType == GZGeneral.LightType.SPOT)
{
graphics.SetUniform(Uniform.spotLight, true);
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
graphics.SetUniform(UniformName.spotLight, true);
graphics.SetUniform(UniformName.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(UniformName.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
}
else graphics.SetUniform(Uniform.spotLight, false);
else graphics.SetUniform(UniformName.spotLight, false);
model.Meshes[j].Draw(graphics);
}
}
@ -1688,16 +1688,16 @@ namespace CodeImp.DoomBuilder.Rendering
{
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
if (lpr.W == 0) continue;
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
graphics.SetUniform(UniformName.lightColor, lights[i].LightColor);
graphics.SetUniform(UniformName.lightPosAndRadius, lpr);
GZGeneral.LightData ld = lights[i].LightType;
if (ld.LightType == GZGeneral.LightType.SPOT)
{
graphics.SetUniform(Uniform.spotLight, true);
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
graphics.SetUniform(UniformName.spotLight, true);
graphics.SetUniform(UniformName.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(UniformName.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
}
else graphics.SetUniform(Uniform.spotLight, false);
else graphics.SetUniform(UniformName.spotLight, false);
model.Meshes[j].Draw(graphics);
}
}
@ -1716,16 +1716,16 @@ namespace CodeImp.DoomBuilder.Rendering
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
if (lpr.W == 0) continue;
Color4 lc = lights[i].LightColor;
graphics.SetUniform(Uniform.lightColor, new Color4(lc.Alpha, (lc.Green + lc.Blue) / 2, (lc.Red + lc.Blue) / 2, (lc.Green + lc.Red) / 2));
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
graphics.SetUniform(UniformName.lightColor, new Color4(lc.Alpha, (lc.Green + lc.Blue) / 2, (lc.Red + lc.Blue) / 2, (lc.Green + lc.Red) / 2));
graphics.SetUniform(UniformName.lightPosAndRadius, lpr);
GZGeneral.LightData ld = lights[i].LightType;
if (ld.LightType == GZGeneral.LightType.SPOT)
{
graphics.SetUniform(Uniform.spotLight, true);
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
graphics.SetUniform(UniformName.spotLight, true);
graphics.SetUniform(UniformName.lightOrientation, lights[i].VectorLookAt);
graphics.SetUniform(UniformName.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
}
else graphics.SetUniform(Uniform.spotLight, false);
else graphics.SetUniform(UniformName.spotLight, false);
model.Meshes[j].Draw(graphics);
}
}
@ -1743,10 +1743,10 @@ namespace CodeImp.DoomBuilder.Rendering
VisualSector sector = null;
// Set render settings
graphics.SetShader(Shader.world3d_skybox);
graphics.SetUniform(Uniform.texture1, General.Map.Data.SkyBox);
graphics.SetUniform(Uniform.world, world);
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, 0f));
graphics.SetShader(ShaderName.world3d_skybox);
graphics.SetUniform(UniformName.texture1, General.Map.Data.SkyBox);
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, 0f));
foreach(VisualGeometry g in geo)
{
@ -1774,7 +1774,7 @@ namespace CodeImp.DoomBuilder.Rendering
if(sector != null)
{
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection)));
graphics.SetUniform(UniformName.highlightcolor, CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection)));
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
}
}
@ -2008,18 +2008,18 @@ namespace CodeImp.DoomBuilder.Rendering
ApplyMatrices2D();
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
graphics.SetShader(Shader.display2d_normal);
graphics.SetShader(ShaderName.display2d_normal);
// Texture
if(crosshairbusy)
{
if(General.Map.Data.CrosshairBusy3D.Texture == null) General.Map.Data.CrosshairBusy3D.CreateTexture();
graphics.SetUniform(Uniform.texture1, General.Map.Data.CrosshairBusy3D.Texture);
graphics.SetUniform(UniformName.texture1, General.Map.Data.CrosshairBusy3D.Texture);
}
else
{
if(General.Map.Data.Crosshair3D.Texture == null) General.Map.Data.Crosshair3D.CreateTexture();
graphics.SetUniform(Uniform.texture1, General.Map.Data.Crosshair3D.Texture);
graphics.SetUniform(UniformName.texture1, General.Map.Data.Crosshair3D.Texture);
}
// Draw

View file

@ -120,38 +120,38 @@ namespace CodeImp.DoomBuilder.Rendering
public void SetDisplay2DSettings(float texelx, float texely, float fsaafactor, float alpha, bool bilinear)
{
Vector4 values = new Vector4(texelx, texely, fsaafactor, alpha);
D3DDevice.SetUniform(Uniform.rendersettings, values);
D3DDevice.SetUniform(UniformName.rendersettings, values);
Matrix world = D3DDevice.GetTransform(TransformState.World);
Matrix view = D3DDevice.GetTransform(TransformState.View);
D3DDevice.SetUniform(Uniform.transformsettings, world * view);
D3DDevice.SetUniform(UniformName.transformsettings, world * view);
TextureFilter filter = (bilinear ? TextureFilter.Linear : TextureFilter.Point);
D3DDevice.SetUniform(Uniform.filtersettings, (int)filter);
D3DDevice.SetUniform(UniformName.filtersettings, filter);
}
public void SetThings2DSettings(float alpha)
{
Vector4 values = new Vector4(0.0f, 0.0f, 1.0f, alpha);
D3DDevice.SetUniform(Uniform.rendersettings, values);
D3DDevice.SetUniform(UniformName.rendersettings, values);
Matrix world = D3DDevice.GetTransform(TransformState.World);
Matrix view = D3DDevice.GetTransform(TransformState.View);
D3DDevice.SetUniform(Uniform.transformsettings, world * view);
D3DDevice.SetUniform(UniformName.transformsettings, world * view);
}
//mxd. Used to render models
public void SetThings2DTransformSettings(Matrix world)
{
Matrix view = D3DDevice.GetTransform(TransformState.View);
D3DDevice.SetUniform(Uniform.transformsettings, world * view);
D3DDevice.SetUniform(UniformName.transformsettings, world * view);
}
public void SetWorld3DConstants(bool bilinear, float maxanisotropy)
{
//mxd. It's still nice to have anisotropic filtering when texture filtering is disabled
TextureFilter magminfilter = (bilinear ? TextureFilter.Linear : TextureFilter.Point);
D3DDevice.SetUniform(Uniform.magfiltersettings, magminfilter);
D3DDevice.SetUniform(Uniform.minfiltersettings, (maxanisotropy > 1.0f ? TextureFilter.Anisotropic : magminfilter));
D3DDevice.SetUniform(Uniform.mipfiltersettings, (bilinear ? TextureFilter.Linear : TextureFilter.None)); // [SB] use None, otherwise textures are still filtered
D3DDevice.SetUniform(Uniform.maxanisotropysetting, maxanisotropy);
D3DDevice.SetUniform(UniformName.magfiltersettings, magminfilter);
D3DDevice.SetUniform(UniformName.minfiltersettings, (maxanisotropy > 1.0f ? TextureFilter.Anisotropic : magminfilter));
D3DDevice.SetUniform(UniformName.mipfiltersettings, (bilinear ? TextureFilter.Linear : TextureFilter.None)); // [SB] use None, otherwise textures are still filtered
D3DDevice.SetUniform(UniformName.maxanisotropysetting, maxanisotropy);
}
}
}

View file

@ -607,18 +607,18 @@ namespace CodeImp.DoomBuilder.Rendering
{
if(!resourcesunloaded)
{
Shader pass = Renderer.FullBrightness ? Shader.display2d_fullbright : Shader.display2d_normal; //mxd
ShaderName pass = Renderer.FullBrightness ? ShaderName.display2d_fullbright : ShaderName.display2d_normal; //mxd
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
foreach(KeyValuePair<ImageData, List<SurfaceEntry>> imgsurfaces in surfaces)
{
graphics.SetShader(pass);
graphics.SetUniform(Uniform.texture1, imgsurfaces.Key.Texture);
graphics.SetUniform(UniformName.texture1, imgsurfaces.Key.Texture);
// Go for all surfaces
VertexBuffer lastbuffer = null;
foreach(SurfaceEntry entry in imgsurfaces.Value)
{
graphics.SetUniform(Uniform.desaturation, entry.desaturation);
graphics.SetUniform(UniformName.desaturation, entry.desaturation);
// Set the vertex buffer
SurfaceBufferSet set = sets[entry.numvertices];
@ -632,7 +632,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.DrawPrimitives(PrimitiveType.TriangleList, entry.vertexoffset + (entry.numvertices * surfacevertexoffsetmul), entry.numvertices / 3);
}
}
graphics.SetUniform(Uniform.desaturation, 0.0f);
graphics.SetUniform(UniformName.desaturation, 0.0f);
}
}

View file

@ -10,10 +10,13 @@
RenderDevice::RenderDevice(HWND hwnd) : Context(hwnd)
{
memset(mUniforms, 0, sizeof(mUniforms));
if (Context)
{
Context.Begin();
mShaderManager = std::make_unique<ShaderManager>();
mShader = &mShaderManager->Shaders[(int)ShaderName::basic];
Context.End();
}
}
@ -200,6 +203,7 @@ void RenderDevice::ApplyChanges()
ApplyVertexBuffers();
ApplyIndexBuffer();
ApplyMatrices();
ApplyUniforms();
ApplyTextures();
ApplyRasterizerState();
ApplyBlendState();
@ -212,7 +216,7 @@ void RenderDevice::ApplyChanges()
void RenderDevice::ApplyShader()
{
//glUseProgram(mShader->GetProgram());
glUseProgram(mShader->GetProgram());
}
void RenderDevice::ApplyRasterizerState()
@ -325,10 +329,71 @@ void RenderDevice::ApplyMatrices()
for (size_t i = 0; i < (size_t)TransformState::NumTransforms; i++)
{
auto& binding = mTransforms[i];
//glUniformMatrix4fv(mShader->TransformLocations[i], 1, GL_FALSE, binding.Values);
glUniformMatrix4fv(mShader->TransformLocations[i], 1, GL_FALSE, binding.Values);
}
}
void RenderDevice::SetShader(ShaderName name)
{
mShader = &mShaderManager->Shaders[(int)name];
mNeedApply = true;
}
static const int uniformLocations[(int)UniformName::NumUniforms] = {
64, // rendersettings
0, // transformsettings
108, // desaturation
-1, // texture1,
80, // highlightcolor
16, // worldviewproj
32, // world
48, // modelnormal
68, // FillColor
72, // vertexColor
84, // stencilColor
92, // lightPosAndRadius
96, // lightOrientation
100, // light2Radius
104, // lightColor
109, // ignoreNormals
110, // spotLight
76, // campos
};
void RenderDevice::SetUniform(UniformName name, const void* values, int count)
{
memcpy(&mUniforms[uniformLocations[(int)name]], values, sizeof(float) * count);
mNeedApply = true;
}
void RenderDevice::ApplyUniforms()
{
auto& locations = mShader->UniformLocations;
glUniformMatrix4fv(locations[(int)UniformName::transformsettings], 1, GL_FALSE, &mUniforms[0].valuef);
glUniformMatrix4fv(locations[(int)UniformName::worldviewproj], 1, GL_FALSE, &mUniforms[16].valuef);
glUniformMatrix4fv(locations[(int)UniformName::world], 1, GL_FALSE, &mUniforms[32].valuef);
glUniformMatrix4fv(locations[(int)UniformName::modelnormal], 1, GL_FALSE, &mUniforms[48].valuef);
glUniform4fv(locations[(int)UniformName::rendersettings], 1, &mUniforms[64].valuef);
glUniform4fv(locations[(int)UniformName::FillColor], 1, &mUniforms[68].valuef);
glUniform4fv(locations[(int)UniformName::vertexColor], 1, &mUniforms[72].valuef);
glUniform4fv(locations[(int)UniformName::campos], 1, &mUniforms[76].valuef);
glUniform4fv(locations[(int)UniformName::highlightcolor], 1, &mUniforms[80].valuef);
glUniform4fv(locations[(int)UniformName::stencilColor], 1, &mUniforms[84].valuef);
glUniform4fv(locations[(int)UniformName::lightColor], 1, &mUniforms[88].valuef);
glUniform4fv(locations[(int)UniformName::lightPosAndRadius], 1, &mUniforms[92].valuef);
glUniform3fv(locations[(int)UniformName::lightOrientation], 1, &mUniforms[96].valuef);
glUniform2fv(locations[(int)UniformName::light2Radius], 1, &mUniforms[100].valuef);
glUniform4fv(locations[(int)UniformName::lightColor], 1, &mUniforms[104].valuef);
glUniform1fv(locations[(int)UniformName::desaturation], 1, &mUniforms[108].valuef);
glUniform1fv(locations[(int)UniformName::ignoreNormals], 1, &mUniforms[109].valuef);
glUniform1fv(locations[(int)UniformName::spotLight], 1, &mUniforms[110].valuef);
glUniform1i(locations[(int)UniformName::texture1], 0);
}
void RenderDevice::ApplyTextures()
{
static const int wrapMode[] = { GL_REPEAT, GL_CLAMP_TO_EDGE };
@ -371,6 +436,16 @@ void RenderDevice_Delete(RenderDevice* device)
delete device;
}
void RenderDevice_SetShader(RenderDevice* device, ShaderName name)
{
device->SetShader(name);
}
void RenderDevice_SetUniform(RenderDevice* device, UniformName name, const void* values, int count)
{
device->SetUniform(name, values, count);
}
void RenderDevice_SetVertexBuffer(RenderDevice* device, int index, VertexBuffer* buffer, long offset, long stride)
{
device->SetVertexBuffer(index, buffer, offset, stride);

View file

@ -7,6 +7,7 @@ class IndexBuffer;
class VertexDeclaration;
class Texture;
class ShaderManager;
class Shader;
enum class CubeMapFace;
enum class Cull : int { None, Counterclockwise };
@ -19,12 +20,67 @@ enum class ShaderFlags : int { None, Debug };
enum class PrimitiveType : int { LineList, TriangleList, TriangleStrip };
enum class TextureFilter : int { None, Point, Linear, Anisotropic };
enum class ShaderName
{
basic,
display2d_fsaa,
display2d_normal,
display2d_fullbright,
things2d_thing,
things2d_sprite,
things2d_fill,
world3d_main,
world3d_fullbright,
world3d_main_highlight,
world3d_fullbright_highlight,
world3d_main_vertexcolor,
world3d_skybox,
world3d_main_highlight_vertexcolor,
world3d_p7,
world3d_main_fog,
world3d_p9,
world3d_main_highlight_fog,
world3d_p11,
world3d_main_fog_vertexcolor,
world3d_p13,
world3d_main_highlight_fog_vertexcolor,
world3d_vertex_color,
world3d_constant_color,
world3d_lightpass, // AlphaBlendEnable = true
count
};
enum class UniformName : int
{
rendersettings,
transformsettings,
desaturation,
texture1,
highlightcolor,
worldviewproj,
world,
modelnormal,
FillColor,
vertexColor,
stencilColor,
lightPosAndRadius,
lightOrientation,
light2Radius,
lightColor,
ignoreNormals,
spotLight,
campos,
NumUniforms
};
class RenderDevice
{
public:
RenderDevice(HWND hwnd);
~RenderDevice();
void SetShader(ShaderName name);
void SetUniform(UniformName name, const void* values, int count);
void SetVertexBuffer(int index, VertexBuffer* buffer, long offset, long stride);
void SetIndexBuffer(IndexBuffer* buffer);
void SetAlphaBlendEnable(bool value);
@ -58,6 +114,7 @@ public:
void ApplyIndexBuffer();
void ApplyShader();
void ApplyMatrices();
void ApplyUniforms();
void ApplyTextures();
void ApplyRasterizerState();
void ApplyBlendState();
@ -78,12 +135,6 @@ public:
long Stride = 0;
};
struct Mat4f
{
Mat4f() { Values[0] = 1.0f; Values[5] = 1.0f; Values[10] = 1.0f; Values[15] = 1.0f; }
float Values[16] = { 0.0f };
};
struct SamplerState
{
SamplerState() = default;
@ -95,7 +146,6 @@ public:
};
enum { NumSlots = 16 };
Mat4f mTransforms[(int)TransformState::NumTransforms];
VertexDeclaration *mVertexDeclaration = nullptr;
GLuint mVAO = 0;
@ -107,6 +157,22 @@ public:
IndexBuffer* mIndexBuffer = nullptr;
std::unique_ptr<ShaderManager> mShaderManager;
Shader* mShader = nullptr;
struct Mat4f
{
Mat4f() { Values[0] = 1.0f; Values[5] = 1.0f; Values[10] = 1.0f; Values[15] = 1.0f; }
float Values[16] = { 0.0f };
};
union UniformEntry
{
float valuef;
int32_t valuei;
};
Mat4f mTransforms[(int)TransformState::NumTransforms];
UniformEntry mUniforms[4 * 16 + 12 * 4];
Cull mCullMode = Cull::None;
FillMode mFillMode = FillMode::Solid;

View file

@ -60,6 +60,32 @@ bool Shader::Compile(const std::string& vertexShader, const std::string& fragmen
TransformLocations[(int)TransformState::View] = glGetUniformLocation(mProgram, "View");
TransformLocations[(int)TransformState::Projection] = glGetUniformLocation(mProgram, "Projection");
static const char* names[(int)UniformName::NumUniforms] = {
"rendersettings",
"transformsettings",
"desaturation",
"texture1",
"highlightcolor",
"worldviewproj",
"world",
"modelnormal",
"fillColor",
"vertexColor",
"stencilColor",
"lightPosAndRadius",
"lightOrientation",
"light2Radius",
"lightColor",
"ignoreNormals",
"spotLight",
"campos"
};
for (int i = 0; i < (int)UniformName::NumUniforms; i++)
{
UniformLocations[i] = glGetUniformLocation(mProgram, names[i]);
}
return mProgram;
}

View file

@ -15,6 +15,7 @@ public:
GLuint GetProgram() const { return mProgram; }
GLuint TransformLocations[(int)TransformState::NumTransforms] = { 0 };
GLuint UniformLocations[(int)UniformName::NumUniforms] = { 0 };
private:
GLuint CompileShader(const std::string& code, GLenum type);

View file

@ -43,10 +43,10 @@ ShaderManager::ShaderManager()
{
if (ShaderSources[i].vs && ShaderSources[i].ps)
{
if (!mShaders[i].Compile(ShaderSources[i].vs, ShaderSources[i].ps))
if (!Shaders[i].Compile(ShaderSources[i].vs, ShaderSources[i].ps))
{
CompileErrors += "Could not compile " + std::to_string(i) + "\r\n";
CompileErrors += mShaders[i].GetErrors();
CompileErrors += Shaders[i].GetErrors();
}
}
}

View file

@ -2,45 +2,13 @@
#include "Shader.h"
enum class ShaderName
{
basic,
display2d_fsaa,
display2d_normal,
display2d_fullbright,
things2d_thing,
things2d_sprite,
things2d_fill,
world3d_main,
world3d_fullbright,
world3d_main_highlight,
world3d_fullbright_highlight,
world3d_main_vertexcolor,
world3d_skybox,
world3d_main_highlight_vertexcolor,
world3d_p7,
world3d_main_fog,
world3d_p9,
world3d_main_highlight_fog,
world3d_p11,
world3d_main_fog_vertexcolor,
world3d_p13,
world3d_main_highlight_fog_vertexcolor,
world3d_vertex_color,
world3d_constant_color,
world3d_lightpass, // AlphaBlendEnable = true
count
};
class ShaderManager
{
public:
ShaderManager();
void ReleaseResources();
std::string CompileErrors;
Shader Shaders[(int)ShaderName::count];
private:
Shader mShaders[(int)ShaderName::count];
std::string CompileErrors;
};

View file

@ -3,6 +3,8 @@ EXPORTS
RenderDevice_New
RenderDevice_Delete
RenderDevice_SetShader
RenderDevice_SetUniform
RenderDevice_SetVertexBuffer
RenderDevice_SetIndexBuffer
RenderDevice_SetAlphaBlendEnable