2018-08-09 21:09:40 -07:00
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.OpenGL
|
|
|
|
|
{
|
|
|
|
|
class OGLPipeline : IGalPipeline
|
|
|
|
|
{
|
|
|
|
|
private static Dictionary<GalVertexAttribSize, int> AttribElements =
|
|
|
|
|
new Dictionary<GalVertexAttribSize, int>()
|
|
|
|
|
{
|
|
|
|
|
{ GalVertexAttribSize._32_32_32_32, 4 },
|
|
|
|
|
{ GalVertexAttribSize._32_32_32, 3 },
|
|
|
|
|
{ GalVertexAttribSize._16_16_16_16, 4 },
|
|
|
|
|
{ GalVertexAttribSize._32_32, 2 },
|
|
|
|
|
{ GalVertexAttribSize._16_16_16, 3 },
|
|
|
|
|
{ GalVertexAttribSize._8_8_8_8, 4 },
|
|
|
|
|
{ GalVertexAttribSize._16_16, 2 },
|
|
|
|
|
{ GalVertexAttribSize._32, 1 },
|
|
|
|
|
{ GalVertexAttribSize._8_8_8, 3 },
|
|
|
|
|
{ GalVertexAttribSize._8_8, 2 },
|
|
|
|
|
{ GalVertexAttribSize._16, 1 },
|
|
|
|
|
{ GalVertexAttribSize._8, 1 },
|
|
|
|
|
{ GalVertexAttribSize._10_10_10_2, 4 },
|
|
|
|
|
{ GalVertexAttribSize._11_11_10, 3 }
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-12 18:37:01 -07:00
|
|
|
|
private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> FloatAttribTypes =
|
|
|
|
|
new Dictionary<GalVertexAttribSize, VertexAttribPointerType>()
|
|
|
|
|
{
|
|
|
|
|
{ GalVertexAttribSize._32_32_32_32, VertexAttribPointerType.Float },
|
|
|
|
|
{ GalVertexAttribSize._32_32_32, VertexAttribPointerType.Float },
|
|
|
|
|
{ GalVertexAttribSize._16_16_16_16, VertexAttribPointerType.HalfFloat },
|
|
|
|
|
{ GalVertexAttribSize._32_32, VertexAttribPointerType.Float },
|
|
|
|
|
{ GalVertexAttribSize._16_16_16, VertexAttribPointerType.HalfFloat },
|
|
|
|
|
{ GalVertexAttribSize._16_16, VertexAttribPointerType.HalfFloat },
|
|
|
|
|
{ GalVertexAttribSize._32, VertexAttribPointerType.Float },
|
|
|
|
|
{ GalVertexAttribSize._16, VertexAttribPointerType.HalfFloat }
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-20 12:02:38 -07:00
|
|
|
|
private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> SignedAttribTypes =
|
2018-08-09 21:09:40 -07:00
|
|
|
|
new Dictionary<GalVertexAttribSize, VertexAttribPointerType>()
|
|
|
|
|
{
|
2018-08-20 12:02:38 -07:00
|
|
|
|
{ GalVertexAttribSize._32_32_32_32, VertexAttribPointerType.Int },
|
|
|
|
|
{ GalVertexAttribSize._32_32_32, VertexAttribPointerType.Int },
|
|
|
|
|
{ GalVertexAttribSize._16_16_16_16, VertexAttribPointerType.Short },
|
|
|
|
|
{ GalVertexAttribSize._32_32, VertexAttribPointerType.Int },
|
|
|
|
|
{ GalVertexAttribSize._16_16_16, VertexAttribPointerType.Short },
|
|
|
|
|
{ GalVertexAttribSize._8_8_8_8, VertexAttribPointerType.Byte },
|
|
|
|
|
{ GalVertexAttribSize._16_16, VertexAttribPointerType.Short },
|
|
|
|
|
{ GalVertexAttribSize._32, VertexAttribPointerType.Int },
|
|
|
|
|
{ GalVertexAttribSize._8_8_8, VertexAttribPointerType.Byte },
|
|
|
|
|
{ GalVertexAttribSize._8_8, VertexAttribPointerType.Byte },
|
|
|
|
|
{ GalVertexAttribSize._16, VertexAttribPointerType.Short },
|
|
|
|
|
{ GalVertexAttribSize._8, VertexAttribPointerType.Byte },
|
|
|
|
|
{ GalVertexAttribSize._10_10_10_2, VertexAttribPointerType.Int2101010Rev }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> UnsignedAttribTypes =
|
|
|
|
|
new Dictionary<GalVertexAttribSize, VertexAttribPointerType>()
|
|
|
|
|
{
|
|
|
|
|
{ GalVertexAttribSize._32_32_32_32, VertexAttribPointerType.UnsignedInt },
|
|
|
|
|
{ GalVertexAttribSize._32_32_32, VertexAttribPointerType.UnsignedInt },
|
|
|
|
|
{ GalVertexAttribSize._16_16_16_16, VertexAttribPointerType.UnsignedShort },
|
|
|
|
|
{ GalVertexAttribSize._32_32, VertexAttribPointerType.UnsignedInt },
|
|
|
|
|
{ GalVertexAttribSize._16_16_16, VertexAttribPointerType.UnsignedShort },
|
|
|
|
|
{ GalVertexAttribSize._8_8_8_8, VertexAttribPointerType.UnsignedByte },
|
|
|
|
|
{ GalVertexAttribSize._16_16, VertexAttribPointerType.UnsignedShort },
|
|
|
|
|
{ GalVertexAttribSize._32, VertexAttribPointerType.UnsignedInt },
|
|
|
|
|
{ GalVertexAttribSize._8_8_8, VertexAttribPointerType.UnsignedByte },
|
|
|
|
|
{ GalVertexAttribSize._8_8, VertexAttribPointerType.UnsignedByte },
|
|
|
|
|
{ GalVertexAttribSize._16, VertexAttribPointerType.UnsignedShort },
|
|
|
|
|
{ GalVertexAttribSize._8, VertexAttribPointerType.UnsignedByte },
|
|
|
|
|
{ GalVertexAttribSize._10_10_10_2, VertexAttribPointerType.UnsignedInt2101010Rev },
|
|
|
|
|
{ GalVertexAttribSize._11_11_10, VertexAttribPointerType.UnsignedInt10F11F11FRev }
|
2018-08-09 21:09:40 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private GalPipelineState Old;
|
|
|
|
|
|
2018-11-28 15:09:44 -08:00
|
|
|
|
private OGLConstBuffer Buffer;
|
|
|
|
|
private OGLRenderTarget RenderTarget;
|
|
|
|
|
private OGLRasterizer Rasterizer;
|
|
|
|
|
private OGLShader Shader;
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
|
|
|
|
private int VaoHandle;
|
|
|
|
|
|
2018-11-28 15:09:44 -08:00
|
|
|
|
public OGLPipeline(
|
|
|
|
|
OGLConstBuffer Buffer,
|
|
|
|
|
OGLRenderTarget RenderTarget,
|
|
|
|
|
OGLRasterizer Rasterizer,
|
|
|
|
|
OGLShader Shader)
|
2018-08-09 21:09:40 -07:00
|
|
|
|
{
|
2018-11-28 15:09:44 -08:00
|
|
|
|
this.Buffer = Buffer;
|
|
|
|
|
this.RenderTarget = RenderTarget;
|
|
|
|
|
this.Rasterizer = Rasterizer;
|
|
|
|
|
this.Shader = Shader;
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
|
|
|
|
//These values match OpenGL's defaults
|
|
|
|
|
Old = new GalPipelineState
|
|
|
|
|
{
|
|
|
|
|
FrontFace = GalFrontFace.CCW,
|
|
|
|
|
|
|
|
|
|
CullFaceEnabled = false,
|
2018-10-23 12:04:08 -07:00
|
|
|
|
CullFace = GalCullFace.Back,
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
2018-10-23 12:04:08 -07:00
|
|
|
|
DepthTestEnabled = false,
|
2018-09-19 18:02:11 -07:00
|
|
|
|
DepthWriteEnabled = true,
|
2018-10-23 12:04:08 -07:00
|
|
|
|
DepthFunc = GalComparisonOp.Less,
|
|
|
|
|
DepthRangeNear = 0,
|
|
|
|
|
DepthRangeFar = 1,
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
|
|
|
|
StencilTestEnabled = false,
|
|
|
|
|
|
|
|
|
|
StencilBackFuncFunc = GalComparisonOp.Always,
|
2018-10-23 12:04:08 -07:00
|
|
|
|
StencilBackFuncRef = 0,
|
2018-08-09 21:09:40 -07:00
|
|
|
|
StencilBackFuncMask = UInt32.MaxValue,
|
2018-10-23 12:04:08 -07:00
|
|
|
|
StencilBackOpFail = GalStencilOp.Keep,
|
|
|
|
|
StencilBackOpZFail = GalStencilOp.Keep,
|
|
|
|
|
StencilBackOpZPass = GalStencilOp.Keep,
|
|
|
|
|
StencilBackMask = UInt32.MaxValue,
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
|
|
|
|
StencilFrontFuncFunc = GalComparisonOp.Always,
|
2018-10-23 12:04:08 -07:00
|
|
|
|
StencilFrontFuncRef = 0,
|
2018-08-09 21:09:40 -07:00
|
|
|
|
StencilFrontFuncMask = UInt32.MaxValue,
|
2018-10-23 12:04:08 -07:00
|
|
|
|
StencilFrontOpFail = GalStencilOp.Keep,
|
|
|
|
|
StencilFrontOpZFail = GalStencilOp.Keep,
|
|
|
|
|
StencilFrontOpZPass = GalStencilOp.Keep,
|
|
|
|
|
StencilFrontMask = UInt32.MaxValue,
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
2018-10-31 21:22:24 -07:00
|
|
|
|
BlendIndependent = false,
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
|
|
|
|
PrimitiveRestartEnabled = false,
|
2018-10-23 12:04:08 -07:00
|
|
|
|
PrimitiveRestartIndex = 0
|
2018-08-09 21:09:40 -07:00
|
|
|
|
};
|
2018-10-17 14:02:23 -07:00
|
|
|
|
|
|
|
|
|
for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++)
|
|
|
|
|
{
|
2018-10-31 21:22:24 -07:00
|
|
|
|
Old.Blends[Index] = BlendState.Default;
|
|
|
|
|
|
|
|
|
|
Old.ColorMasks[Index] = ColorMaskState.Default;
|
2018-10-17 14:02:23 -07:00
|
|
|
|
}
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Bind(GalPipelineState New)
|
|
|
|
|
{
|
|
|
|
|
BindConstBuffers(New);
|
|
|
|
|
|
|
|
|
|
BindVertexLayout(New);
|
|
|
|
|
|
2018-09-17 21:30:35 -07:00
|
|
|
|
if (New.FramebufferSrgb != Old.FramebufferSrgb)
|
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.FramebufferSrgb, New.FramebufferSrgb);
|
2018-11-28 15:09:44 -08:00
|
|
|
|
|
|
|
|
|
RenderTarget.FramebufferSrgb = New.FramebufferSrgb;
|
2018-09-17 21:30:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-24 21:16:58 -07:00
|
|
|
|
if (New.FlipX != Old.FlipX || New.FlipY != Old.FlipY || New.Instance != Old.Instance)
|
2018-08-09 21:09:40 -07:00
|
|
|
|
{
|
2018-08-24 21:16:58 -07:00
|
|
|
|
Shader.SetExtraData(New.FlipX, New.FlipY, New.Instance);
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Note: Uncomment SetFrontFace and SetCullFace when flipping issues are solved
|
|
|
|
|
|
2018-09-19 18:02:11 -07:00
|
|
|
|
//if (New.FrontFace != Old.FrontFace)
|
2018-08-09 21:09:40 -07:00
|
|
|
|
//{
|
|
|
|
|
// GL.FrontFace(OGLEnumConverter.GetFrontFace(New.FrontFace));
|
|
|
|
|
//}
|
|
|
|
|
|
2018-09-19 18:02:11 -07:00
|
|
|
|
//if (New.CullFaceEnabled != Old.CullFaceEnabled)
|
2018-08-09 21:09:40 -07:00
|
|
|
|
//{
|
|
|
|
|
// Enable(EnableCap.CullFace, New.CullFaceEnabled);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//if (New.CullFaceEnabled)
|
|
|
|
|
//{
|
2018-09-19 18:02:11 -07:00
|
|
|
|
// if (New.CullFace != Old.CullFace)
|
2018-08-09 21:09:40 -07:00
|
|
|
|
// {
|
|
|
|
|
// GL.CullFace(OGLEnumConverter.GetCullFace(New.CullFace));
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (New.DepthTestEnabled != Old.DepthTestEnabled)
|
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.DepthTest, New.DepthTestEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-19 18:02:11 -07:00
|
|
|
|
if (New.DepthWriteEnabled != Old.DepthWriteEnabled)
|
|
|
|
|
{
|
|
|
|
|
GL.DepthMask(New.DepthWriteEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
|
if (New.DepthTestEnabled)
|
|
|
|
|
{
|
|
|
|
|
if (New.DepthFunc != Old.DepthFunc)
|
|
|
|
|
{
|
|
|
|
|
GL.DepthFunc(OGLEnumConverter.GetDepthFunc(New.DepthFunc));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 12:04:08 -07:00
|
|
|
|
if (New.DepthRangeNear != Old.DepthRangeNear ||
|
|
|
|
|
New.DepthRangeFar != Old.DepthRangeFar)
|
|
|
|
|
{
|
|
|
|
|
GL.DepthRange(New.DepthRangeNear, New.DepthRangeFar);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
|
if (New.StencilTestEnabled != Old.StencilTestEnabled)
|
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.StencilTest, New.StencilTestEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-13 19:54:14 -07:00
|
|
|
|
if (New.StencilTwoSideEnabled != Old.StencilTwoSideEnabled)
|
|
|
|
|
{
|
|
|
|
|
Enable((EnableCap)All.StencilTestTwoSideExt, New.StencilTwoSideEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
|
if (New.StencilTestEnabled)
|
|
|
|
|
{
|
|
|
|
|
if (New.StencilBackFuncFunc != Old.StencilBackFuncFunc ||
|
|
|
|
|
New.StencilBackFuncRef != Old.StencilBackFuncRef ||
|
|
|
|
|
New.StencilBackFuncMask != Old.StencilBackFuncMask)
|
|
|
|
|
{
|
|
|
|
|
GL.StencilFuncSeparate(
|
|
|
|
|
StencilFace.Back,
|
|
|
|
|
OGLEnumConverter.GetStencilFunc(New.StencilBackFuncFunc),
|
|
|
|
|
New.StencilBackFuncRef,
|
|
|
|
|
New.StencilBackFuncMask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.StencilBackOpFail != Old.StencilBackOpFail ||
|
|
|
|
|
New.StencilBackOpZFail != Old.StencilBackOpZFail ||
|
|
|
|
|
New.StencilBackOpZPass != Old.StencilBackOpZPass)
|
|
|
|
|
{
|
|
|
|
|
GL.StencilOpSeparate(
|
|
|
|
|
StencilFace.Back,
|
|
|
|
|
OGLEnumConverter.GetStencilOp(New.StencilBackOpFail),
|
|
|
|
|
OGLEnumConverter.GetStencilOp(New.StencilBackOpZFail),
|
|
|
|
|
OGLEnumConverter.GetStencilOp(New.StencilBackOpZPass));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.StencilBackMask != Old.StencilBackMask)
|
|
|
|
|
{
|
|
|
|
|
GL.StencilMaskSeparate(StencilFace.Back, New.StencilBackMask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.StencilFrontFuncFunc != Old.StencilFrontFuncFunc ||
|
|
|
|
|
New.StencilFrontFuncRef != Old.StencilFrontFuncRef ||
|
|
|
|
|
New.StencilFrontFuncMask != Old.StencilFrontFuncMask)
|
|
|
|
|
{
|
|
|
|
|
GL.StencilFuncSeparate(
|
|
|
|
|
StencilFace.Front,
|
|
|
|
|
OGLEnumConverter.GetStencilFunc(New.StencilFrontFuncFunc),
|
|
|
|
|
New.StencilFrontFuncRef,
|
|
|
|
|
New.StencilFrontFuncMask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.StencilFrontOpFail != Old.StencilFrontOpFail ||
|
|
|
|
|
New.StencilFrontOpZFail != Old.StencilFrontOpZFail ||
|
|
|
|
|
New.StencilFrontOpZPass != Old.StencilFrontOpZPass)
|
|
|
|
|
{
|
|
|
|
|
GL.StencilOpSeparate(
|
|
|
|
|
StencilFace.Front,
|
|
|
|
|
OGLEnumConverter.GetStencilOp(New.StencilFrontOpFail),
|
|
|
|
|
OGLEnumConverter.GetStencilOp(New.StencilFrontOpZFail),
|
|
|
|
|
OGLEnumConverter.GetStencilOp(New.StencilFrontOpZPass));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.StencilFrontMask != Old.StencilFrontMask)
|
|
|
|
|
{
|
|
|
|
|
GL.StencilMaskSeparate(StencilFace.Front, New.StencilFrontMask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-13 13:26:42 -08:00
|
|
|
|
|
|
|
|
|
// Scissor Test
|
|
|
|
|
bool forceUpdate;
|
|
|
|
|
|
|
|
|
|
for (int Index = 0; Index < New.ScissorTestCount; Index++)
|
|
|
|
|
{
|
|
|
|
|
forceUpdate = false;
|
|
|
|
|
|
|
|
|
|
if (New.ScissorTestEnabled[Index] != Old.ScissorTestEnabled[Index])
|
|
|
|
|
{
|
|
|
|
|
if (New.ScissorTestEnabled[Index])
|
|
|
|
|
{
|
|
|
|
|
// If there is only 1 scissor test geometry shaders are disables so the scissor test applies to all viewports
|
|
|
|
|
if (New.ScissorTestCount == 1)
|
|
|
|
|
{
|
|
|
|
|
GL.Enable(EnableCap.ScissorTest);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GL.Enable(IndexedEnableCap.ScissorTest, Index);
|
|
|
|
|
}
|
|
|
|
|
forceUpdate = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GL.Disable(IndexedEnableCap.ScissorTest, Index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.ScissorTestEnabled[Index] &&
|
|
|
|
|
(New.ScissorTestX[Index] != Old.ScissorTestX[Index] ||
|
|
|
|
|
New.ScissorTestY[Index] != Old.ScissorTestY[Index] ||
|
|
|
|
|
New.ScissorTestWidth[Index] != Old.ScissorTestWidth[Index] ||
|
|
|
|
|
New.ScissorTestHeight[Index] != Old.ScissorTestHeight[Index] ||
|
|
|
|
|
forceUpdate)) // Force update intentionally last to reduce if comparisons
|
|
|
|
|
{
|
|
|
|
|
// If there is only 1 scissor test geometry shaders are disables so the scissor test applies to all viewports
|
|
|
|
|
if (New.ScissorTestCount == 1)
|
|
|
|
|
{
|
|
|
|
|
GL.Scissor(New.ScissorTestX[Index], New.ScissorTestY[Index],
|
|
|
|
|
New.ScissorTestWidth[Index], New.ScissorTestHeight[Index]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GL.ScissorIndexed(Index, New.ScissorTestX[Index], New.ScissorTestY[Index],
|
|
|
|
|
New.ScissorTestWidth[Index], New.ScissorTestHeight[Index]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-10-31 21:22:24 -07:00
|
|
|
|
if (New.BlendIndependent)
|
2018-08-09 21:09:40 -07:00
|
|
|
|
{
|
2018-10-31 21:22:24 -07:00
|
|
|
|
for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++)
|
|
|
|
|
{
|
|
|
|
|
SetBlendState(Index, New.Blends[Index], Old.Blends[Index]);
|
|
|
|
|
}
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
2018-10-31 21:22:24 -07:00
|
|
|
|
else
|
2018-08-09 21:09:40 -07:00
|
|
|
|
{
|
2018-10-31 21:22:24 -07:00
|
|
|
|
if (New.BlendIndependent != Old.BlendIndependent)
|
2018-08-09 21:09:40 -07:00
|
|
|
|
{
|
2018-10-31 21:22:24 -07:00
|
|
|
|
SetAllBlendState(New.Blends[0]);
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-31 21:22:24 -07:00
|
|
|
|
SetBlendState(New.Blends[0], Old.Blends[0]);
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 14:30:09 -07:00
|
|
|
|
if (New.ColorMaskCommon)
|
2018-10-13 19:54:14 -07:00
|
|
|
|
{
|
2018-10-25 14:30:09 -07:00
|
|
|
|
if (New.ColorMaskCommon != Old.ColorMaskCommon || !New.ColorMasks[0].Equals(Old.ColorMasks[0]))
|
2018-10-17 14:02:23 -07:00
|
|
|
|
{
|
|
|
|
|
GL.ColorMask(
|
2018-10-25 14:30:09 -07:00
|
|
|
|
New.ColorMasks[0].Red,
|
|
|
|
|
New.ColorMasks[0].Green,
|
|
|
|
|
New.ColorMasks[0].Blue,
|
|
|
|
|
New.ColorMasks[0].Alpha);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++)
|
|
|
|
|
{
|
|
|
|
|
if (!New.ColorMasks[Index].Equals(Old.ColorMasks[Index]))
|
|
|
|
|
{
|
|
|
|
|
GL.ColorMask(
|
|
|
|
|
Index,
|
|
|
|
|
New.ColorMasks[Index].Red,
|
|
|
|
|
New.ColorMasks[Index].Green,
|
|
|
|
|
New.ColorMasks[Index].Blue,
|
|
|
|
|
New.ColorMasks[Index].Alpha);
|
|
|
|
|
}
|
2018-10-17 14:02:23 -07:00
|
|
|
|
}
|
2018-10-13 19:54:14 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
|
if (New.PrimitiveRestartEnabled != Old.PrimitiveRestartEnabled)
|
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.PrimitiveRestart, New.PrimitiveRestartEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.PrimitiveRestartEnabled)
|
|
|
|
|
{
|
|
|
|
|
if (New.PrimitiveRestartIndex != Old.PrimitiveRestartIndex)
|
|
|
|
|
{
|
|
|
|
|
GL.PrimitiveRestartIndex(New.PrimitiveRestartIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Old = New;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 21:22:24 -07:00
|
|
|
|
private void SetAllBlendState(BlendState New)
|
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.Blend, New.Enabled);
|
|
|
|
|
|
|
|
|
|
if (New.Enabled)
|
|
|
|
|
{
|
|
|
|
|
if (New.SeparateAlpha)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendEquationSeparate(
|
|
|
|
|
OGLEnumConverter.GetBlendEquation(New.EquationRgb),
|
|
|
|
|
OGLEnumConverter.GetBlendEquation(New.EquationAlpha));
|
|
|
|
|
|
|
|
|
|
GL.BlendFuncSeparate(
|
|
|
|
|
(BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
(BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.FuncDstRgb),
|
|
|
|
|
(BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.FuncSrcAlpha),
|
|
|
|
|
(BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.FuncDstAlpha));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GL.BlendEquation(OGLEnumConverter.GetBlendEquation(New.EquationRgb));
|
|
|
|
|
|
|
|
|
|
GL.BlendFunc(
|
|
|
|
|
OGLEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
OGLEnumConverter.GetBlendFactor(New.FuncDstRgb));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetBlendState(BlendState New, BlendState Old)
|
|
|
|
|
{
|
|
|
|
|
if (New.Enabled != Old.Enabled)
|
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.Blend, New.Enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.Enabled)
|
|
|
|
|
{
|
|
|
|
|
if (New.SeparateAlpha)
|
|
|
|
|
{
|
|
|
|
|
if (New.EquationRgb != Old.EquationRgb ||
|
|
|
|
|
New.EquationAlpha != Old.EquationAlpha)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendEquationSeparate(
|
|
|
|
|
OGLEnumConverter.GetBlendEquation(New.EquationRgb),
|
|
|
|
|
OGLEnumConverter.GetBlendEquation(New.EquationAlpha));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.FuncSrcRgb != Old.FuncSrcRgb ||
|
|
|
|
|
New.FuncDstRgb != Old.FuncDstRgb ||
|
|
|
|
|
New.FuncSrcAlpha != Old.FuncSrcAlpha ||
|
|
|
|
|
New.FuncDstAlpha != Old.FuncDstAlpha)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendFuncSeparate(
|
|
|
|
|
(BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
(BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.FuncDstRgb),
|
|
|
|
|
(BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.FuncSrcAlpha),
|
|
|
|
|
(BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.FuncDstAlpha));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (New.EquationRgb != Old.EquationRgb)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendEquation(OGLEnumConverter.GetBlendEquation(New.EquationRgb));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.FuncSrcRgb != Old.FuncSrcRgb ||
|
|
|
|
|
New.FuncDstRgb != Old.FuncDstRgb)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendFunc(
|
|
|
|
|
OGLEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
OGLEnumConverter.GetBlendFactor(New.FuncDstRgb));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetBlendState(int Index, BlendState New, BlendState Old)
|
|
|
|
|
{
|
|
|
|
|
if (New.Enabled != Old.Enabled)
|
|
|
|
|
{
|
|
|
|
|
Enable(IndexedEnableCap.Blend, Index, New.Enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.Enabled)
|
|
|
|
|
{
|
|
|
|
|
if (New.SeparateAlpha)
|
|
|
|
|
{
|
|
|
|
|
if (New.EquationRgb != Old.EquationRgb ||
|
|
|
|
|
New.EquationAlpha != Old.EquationAlpha)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendEquationSeparate(
|
|
|
|
|
Index,
|
|
|
|
|
OGLEnumConverter.GetBlendEquation(New.EquationRgb),
|
|
|
|
|
OGLEnumConverter.GetBlendEquation(New.EquationAlpha));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.FuncSrcRgb != Old.FuncSrcRgb ||
|
|
|
|
|
New.FuncDstRgb != Old.FuncDstRgb ||
|
|
|
|
|
New.FuncSrcAlpha != Old.FuncSrcAlpha ||
|
|
|
|
|
New.FuncDstAlpha != Old.FuncDstAlpha)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendFuncSeparate(
|
|
|
|
|
Index,
|
|
|
|
|
(BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
(BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.FuncDstRgb),
|
|
|
|
|
(BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.FuncSrcAlpha),
|
|
|
|
|
(BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.FuncDstAlpha));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (New.EquationRgb != Old.EquationRgb)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendEquation(Index, OGLEnumConverter.GetBlendEquation(New.EquationRgb));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.FuncSrcRgb != Old.FuncSrcRgb ||
|
|
|
|
|
New.FuncDstRgb != Old.FuncDstRgb)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendFunc(
|
|
|
|
|
Index,
|
|
|
|
|
(BlendingFactorSrc) OGLEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
(BlendingFactorDest)OGLEnumConverter.GetBlendFactor(New.FuncDstRgb));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
|
private void BindConstBuffers(GalPipelineState New)
|
|
|
|
|
{
|
2018-08-24 21:16:58 -07:00
|
|
|
|
int FreeBinding = OGLShader.ReservedCbufCount;
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
|
|
|
|
void BindIfNotNull(OGLShaderStage Stage)
|
|
|
|
|
{
|
|
|
|
|
if (Stage != null)
|
|
|
|
|
{
|
2018-08-15 11:59:51 -07:00
|
|
|
|
foreach (ShaderDeclInfo DeclInfo in Stage.ConstBufferUsage)
|
2018-08-09 21:09:40 -07:00
|
|
|
|
{
|
|
|
|
|
long Key = New.ConstBufferKeys[(int)Stage.Type][DeclInfo.Cbuf];
|
|
|
|
|
|
|
|
|
|
if (Key != 0 && Buffer.TryGetUbo(Key, out int UboHandle))
|
|
|
|
|
{
|
|
|
|
|
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, FreeBinding, UboHandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FreeBinding++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BindIfNotNull(Shader.Current.Vertex);
|
|
|
|
|
BindIfNotNull(Shader.Current.TessControl);
|
|
|
|
|
BindIfNotNull(Shader.Current.TessEvaluation);
|
|
|
|
|
BindIfNotNull(Shader.Current.Geometry);
|
|
|
|
|
BindIfNotNull(Shader.Current.Fragment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BindVertexLayout(GalPipelineState New)
|
|
|
|
|
{
|
|
|
|
|
foreach (GalVertexBinding Binding in New.VertexBindings)
|
|
|
|
|
{
|
|
|
|
|
if (!Binding.Enabled || !Rasterizer.TryGetVbo(Binding.VboKey, out int VboHandle))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (VaoHandle == 0)
|
|
|
|
|
{
|
|
|
|
|
VaoHandle = GL.GenVertexArray();
|
|
|
|
|
|
|
|
|
|
//Vertex arrays shouldn't be used anywhere else in OpenGL's backend
|
|
|
|
|
//if you want to use it, move this line out of the if
|
|
|
|
|
GL.BindVertexArray(VaoHandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (GalVertexAttrib Attrib in Binding.Attribs)
|
|
|
|
|
{
|
2018-09-17 21:30:35 -07:00
|
|
|
|
//Skip uninitialized attributes.
|
|
|
|
|
if (Attrib.Size == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
|
GL.BindBuffer(BufferTarget.ArrayBuffer, VboHandle);
|
|
|
|
|
|
|
|
|
|
bool Unsigned =
|
|
|
|
|
Attrib.Type == GalVertexAttribType.Unorm ||
|
2018-08-20 12:02:38 -07:00
|
|
|
|
Attrib.Type == GalVertexAttribType.Uint ||
|
2018-08-09 21:09:40 -07:00
|
|
|
|
Attrib.Type == GalVertexAttribType.Uscaled;
|
|
|
|
|
|
|
|
|
|
bool Normalize =
|
|
|
|
|
Attrib.Type == GalVertexAttribType.Snorm ||
|
|
|
|
|
Attrib.Type == GalVertexAttribType.Unorm;
|
|
|
|
|
|
|
|
|
|
VertexAttribPointerType Type = 0;
|
|
|
|
|
|
|
|
|
|
if (Attrib.Type == GalVertexAttribType.Float)
|
|
|
|
|
{
|
2018-10-12 18:37:01 -07:00
|
|
|
|
Type = GetType(FloatAttribTypes, Attrib);
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-20 12:02:38 -07:00
|
|
|
|
if (Unsigned)
|
|
|
|
|
{
|
2018-10-12 18:37:01 -07:00
|
|
|
|
Type = GetType(UnsignedAttribTypes, Attrib);
|
2018-08-20 12:02:38 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-12 18:37:01 -07:00
|
|
|
|
Type = GetType(SignedAttribTypes, Attrib);
|
2018-08-20 12:02:38 -07:00
|
|
|
|
}
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 18:37:01 -07:00
|
|
|
|
if (!AttribElements.TryGetValue(Attrib.Size, out int Size))
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Invalid attribute size \"" + Attrib.Size + "\"!");
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
|
int Offset = Attrib.Offset;
|
|
|
|
|
|
2018-10-12 18:37:01 -07:00
|
|
|
|
if (Binding.Stride != 0)
|
2018-08-09 21:09:40 -07:00
|
|
|
|
{
|
2018-10-12 18:37:01 -07:00
|
|
|
|
GL.EnableVertexAttribArray(Attrib.Index);
|
|
|
|
|
|
|
|
|
|
if (Attrib.Type == GalVertexAttribType.Sint ||
|
|
|
|
|
Attrib.Type == GalVertexAttribType.Uint)
|
|
|
|
|
{
|
|
|
|
|
IntPtr Pointer = new IntPtr(Offset);
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
2018-10-12 18:37:01 -07:00
|
|
|
|
VertexAttribIntegerType IType = (VertexAttribIntegerType)Type;
|
2018-08-09 21:09:40 -07:00
|
|
|
|
|
2018-10-12 18:37:01 -07:00
|
|
|
|
GL.VertexAttribIPointer(Attrib.Index, Size, IType, Binding.Stride, Pointer);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GL.VertexAttribPointer(Attrib.Index, Size, Type, Normalize, Binding.Stride, Offset);
|
|
|
|
|
}
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-10-12 18:37:01 -07:00
|
|
|
|
GL.DisableVertexAttribArray(Attrib.Index);
|
|
|
|
|
|
|
|
|
|
SetConstAttrib(Attrib);
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
2018-08-24 21:16:58 -07:00
|
|
|
|
|
|
|
|
|
if (Binding.Instanced && Binding.Divisor != 0)
|
|
|
|
|
{
|
|
|
|
|
GL.VertexAttribDivisor(Attrib.Index, 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GL.VertexAttribDivisor(Attrib.Index, 0);
|
|
|
|
|
}
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 18:37:01 -07:00
|
|
|
|
private static VertexAttribPointerType GetType(Dictionary<GalVertexAttribSize, VertexAttribPointerType> Dict, GalVertexAttrib Attrib)
|
|
|
|
|
{
|
|
|
|
|
if (!Dict.TryGetValue(Attrib.Size, out VertexAttribPointerType Type))
|
|
|
|
|
{
|
2018-10-25 14:30:09 -07:00
|
|
|
|
ThrowUnsupportedAttrib(Attrib);
|
2018-10-12 18:37:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private unsafe static void SetConstAttrib(GalVertexAttrib Attrib)
|
|
|
|
|
{
|
|
|
|
|
if (Attrib.Size == GalVertexAttribSize._10_10_10_2 ||
|
|
|
|
|
Attrib.Size == GalVertexAttribSize._11_11_10)
|
|
|
|
|
{
|
2018-10-25 14:30:09 -07:00
|
|
|
|
ThrowUnsupportedAttrib(Attrib);
|
2018-10-12 18:37:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 14:18:09 -08:00
|
|
|
|
fixed (byte* Ptr = Attrib.Data)
|
2018-10-12 18:37:01 -07:00
|
|
|
|
{
|
2018-11-28 14:18:09 -08:00
|
|
|
|
if (Attrib.Type == GalVertexAttribType.Unorm)
|
2018-10-12 18:37:01 -07:00
|
|
|
|
{
|
2018-11-28 14:18:09 -08:00
|
|
|
|
switch (Attrib.Size)
|
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._8:
|
|
|
|
|
case GalVertexAttribSize._8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8_8:
|
|
|
|
|
GL.VertexAttrib4N((uint)Attrib.Index, Ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._16:
|
|
|
|
|
case GalVertexAttribSize._16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16_16:
|
|
|
|
|
GL.VertexAttrib4N((uint)Attrib.Index, (ushort*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
|
|
|
|
GL.VertexAttrib4N((uint)Attrib.Index, (uint*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-12 18:37:01 -07:00
|
|
|
|
}
|
2018-11-28 14:18:09 -08:00
|
|
|
|
else if (Attrib.Type == GalVertexAttribType.Snorm)
|
2018-10-12 18:37:01 -07:00
|
|
|
|
{
|
2018-11-28 14:18:09 -08:00
|
|
|
|
switch (Attrib.Size)
|
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._8:
|
|
|
|
|
case GalVertexAttribSize._8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8_8:
|
|
|
|
|
GL.VertexAttrib4N((uint)Attrib.Index, (sbyte*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._16:
|
|
|
|
|
case GalVertexAttribSize._16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16_16:
|
|
|
|
|
GL.VertexAttrib4N((uint)Attrib.Index, (short*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
|
|
|
|
GL.VertexAttrib4N((uint)Attrib.Index, (int*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-12 18:37:01 -07:00
|
|
|
|
}
|
2018-11-28 14:18:09 -08:00
|
|
|
|
else if (Attrib.Type == GalVertexAttribType.Uint)
|
2018-10-12 18:37:01 -07:00
|
|
|
|
{
|
2018-11-28 14:18:09 -08:00
|
|
|
|
switch (Attrib.Size)
|
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._8:
|
|
|
|
|
case GalVertexAttribSize._8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8_8:
|
|
|
|
|
GL.VertexAttribI4((uint)Attrib.Index, Ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._16:
|
|
|
|
|
case GalVertexAttribSize._16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16_16:
|
|
|
|
|
GL.VertexAttribI4((uint)Attrib.Index, (ushort*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
|
|
|
|
GL.VertexAttribI4((uint)Attrib.Index, (uint*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-12 18:37:01 -07:00
|
|
|
|
}
|
2018-11-28 14:18:09 -08:00
|
|
|
|
else if (Attrib.Type == GalVertexAttribType.Sint)
|
2018-10-12 18:37:01 -07:00
|
|
|
|
{
|
2018-11-28 14:18:09 -08:00
|
|
|
|
switch (Attrib.Size)
|
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._8:
|
|
|
|
|
case GalVertexAttribSize._8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8_8:
|
|
|
|
|
GL.VertexAttribI4((uint)Attrib.Index, (sbyte*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._16:
|
|
|
|
|
case GalVertexAttribSize._16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16_16:
|
|
|
|
|
GL.VertexAttribI4((uint)Attrib.Index, (short*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
|
|
|
|
GL.VertexAttribI4((uint)Attrib.Index, (int*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-12 18:37:01 -07:00
|
|
|
|
}
|
2018-11-28 14:18:09 -08:00
|
|
|
|
else if (Attrib.Type == GalVertexAttribType.Float)
|
2018-10-12 18:37:01 -07:00
|
|
|
|
{
|
2018-11-28 14:18:09 -08:00
|
|
|
|
switch (Attrib.Size)
|
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
|
|
|
|
GL.VertexAttrib4(Attrib.Index, (float*)Ptr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: ThrowUnsupportedAttrib(Attrib); break;
|
|
|
|
|
}
|
2018-10-12 18:37:01 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 14:30:09 -07:00
|
|
|
|
private static void ThrowUnsupportedAttrib(GalVertexAttrib Attrib)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException("Unsupported size \"" + Attrib.Size + "\" on type \"" + Attrib.Type + "\"!");
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
|
private void Enable(EnableCap Cap, bool Enabled)
|
|
|
|
|
{
|
|
|
|
|
if (Enabled)
|
|
|
|
|
{
|
|
|
|
|
GL.Enable(Cap);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GL.Disable(Cap);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-17 14:02:23 -07:00
|
|
|
|
|
2018-10-31 21:22:24 -07:00
|
|
|
|
private void Enable(IndexedEnableCap Cap, int Index, bool Enabled)
|
|
|
|
|
{
|
|
|
|
|
if (Enabled)
|
|
|
|
|
{
|
|
|
|
|
GL.Enable(Cap, Index);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GL.Disable(Cap, Index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 14:02:23 -07:00
|
|
|
|
public void ResetDepthMask()
|
|
|
|
|
{
|
|
|
|
|
Old.DepthWriteEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetColorMask(int Index)
|
|
|
|
|
{
|
2018-10-31 21:22:24 -07:00
|
|
|
|
Old.ColorMasks[Index] = ColorMaskState.Default;
|
2018-10-17 14:02:23 -07:00
|
|
|
|
}
|
2018-08-09 21:09:40 -07:00
|
|
|
|
}
|
|
|
|
|
}
|