2018-08-10 06:09:40 +02:00
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.OpenGL
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
class OglPipeline : IGalPipeline
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private static Dictionary<GalVertexAttribSize, int> _attribElements =
|
2018-08-10 06:09:40 +02:00
|
|
|
|
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 }
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> _floatAttribTypes =
|
2018-10-13 03:37:01 +02:00
|
|
|
|
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 }
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> _signedAttribTypes =
|
2018-08-10 06:09:40 +02:00
|
|
|
|
new Dictionary<GalVertexAttribSize, VertexAttribPointerType>()
|
|
|
|
|
{
|
2018-08-20 21:02:38 +02: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 }
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> _unsignedAttribTypes =
|
2018-08-20 21:02:38 +02:00
|
|
|
|
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-10 06:09:40 +02:00
|
|
|
|
};
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private GalPipelineState _old;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private OglConstBuffer _buffer;
|
|
|
|
|
private OglRenderTarget _renderTarget;
|
|
|
|
|
private OglRasterizer _rasterizer;
|
|
|
|
|
private OglShader _shader;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private int _vaoHandle;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
public OglPipeline(
|
|
|
|
|
OglConstBuffer buffer,
|
|
|
|
|
OglRenderTarget renderTarget,
|
|
|
|
|
OglRasterizer rasterizer,
|
|
|
|
|
OglShader shader)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_buffer = buffer;
|
|
|
|
|
_renderTarget = renderTarget;
|
|
|
|
|
_rasterizer = rasterizer;
|
|
|
|
|
_shader = shader;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
|
|
|
|
//These values match OpenGL's defaults
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_old = new GalPipelineState
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
FrontFace = GalFrontFace.Ccw,
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
|
|
|
|
CullFaceEnabled = false,
|
2018-10-23 21:04:08 +02:00
|
|
|
|
CullFace = GalCullFace.Back,
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2018-10-23 21:04:08 +02:00
|
|
|
|
DepthTestEnabled = false,
|
2018-09-20 03:02:11 +02:00
|
|
|
|
DepthWriteEnabled = true,
|
2018-10-23 21:04:08 +02:00
|
|
|
|
DepthFunc = GalComparisonOp.Less,
|
|
|
|
|
DepthRangeNear = 0,
|
|
|
|
|
DepthRangeFar = 1,
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
|
|
|
|
StencilTestEnabled = false,
|
|
|
|
|
|
|
|
|
|
StencilBackFuncFunc = GalComparisonOp.Always,
|
2018-10-23 21:04:08 +02:00
|
|
|
|
StencilBackFuncRef = 0,
|
2018-08-10 06:09:40 +02:00
|
|
|
|
StencilBackFuncMask = UInt32.MaxValue,
|
2018-10-23 21:04:08 +02:00
|
|
|
|
StencilBackOpFail = GalStencilOp.Keep,
|
|
|
|
|
StencilBackOpZFail = GalStencilOp.Keep,
|
|
|
|
|
StencilBackOpZPass = GalStencilOp.Keep,
|
|
|
|
|
StencilBackMask = UInt32.MaxValue,
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
|
|
|
|
StencilFrontFuncFunc = GalComparisonOp.Always,
|
2018-10-23 21:04:08 +02:00
|
|
|
|
StencilFrontFuncRef = 0,
|
2018-08-10 06:09:40 +02:00
|
|
|
|
StencilFrontFuncMask = UInt32.MaxValue,
|
2018-10-23 21:04:08 +02:00
|
|
|
|
StencilFrontOpFail = GalStencilOp.Keep,
|
|
|
|
|
StencilFrontOpZFail = GalStencilOp.Keep,
|
|
|
|
|
StencilFrontOpZPass = GalStencilOp.Keep,
|
|
|
|
|
StencilFrontMask = UInt32.MaxValue,
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2018-11-01 05:22:24 +01:00
|
|
|
|
BlendIndependent = false,
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
|
|
|
|
PrimitiveRestartEnabled = false,
|
2018-10-23 21:04:08 +02:00
|
|
|
|
PrimitiveRestartIndex = 0
|
2018-08-10 06:09:40 +02:00
|
|
|
|
};
|
2018-10-17 23:02:23 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++)
|
2018-10-17 23:02:23 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_old.Blends[index] = BlendState.Default;
|
2018-11-01 05:22:24 +01:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_old.ColorMasks[index] = ColorMaskState.Default;
|
2018-10-17 23:02:23 +02:00
|
|
|
|
}
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Bind(GalPipelineState New)
|
|
|
|
|
{
|
|
|
|
|
BindConstBuffers(New);
|
|
|
|
|
|
|
|
|
|
BindVertexLayout(New);
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.FramebufferSrgb != _old.FramebufferSrgb)
|
2018-09-18 06:30:35 +02:00
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.FramebufferSrgb, New.FramebufferSrgb);
|
2018-11-29 00:09:44 +01:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_renderTarget.FramebufferSrgb = New.FramebufferSrgb;
|
2018-09-18 06:30:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.FlipX != _old.FlipX || New.FlipY != _old.FlipY || New.Instance != _old.Instance)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_shader.SetExtraData(New.FlipX, New.FlipY, New.Instance);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.FrontFace != _old.FrontFace)
|
2019-02-15 04:23:14 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.FrontFace(OglEnumConverter.GetFrontFace(New.FrontFace));
|
2019-02-15 04:23:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.CullFaceEnabled != _old.CullFaceEnabled)
|
2019-02-15 04:23:14 +01:00
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.CullFace, New.CullFaceEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.CullFaceEnabled)
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.CullFace != _old.CullFace)
|
2019-02-15 04:23:14 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.CullFace(OglEnumConverter.GetCullFace(New.CullFace));
|
2019-02-15 04:23:14 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.DepthTestEnabled != _old.DepthTestEnabled)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.DepthTest, New.DepthTestEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.DepthWriteEnabled != _old.DepthWriteEnabled)
|
2018-09-20 03:02:11 +02:00
|
|
|
|
{
|
|
|
|
|
GL.DepthMask(New.DepthWriteEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 06:09:40 +02:00
|
|
|
|
if (New.DepthTestEnabled)
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.DepthFunc != _old.DepthFunc)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.DepthFunc(OglEnumConverter.GetDepthFunc(New.DepthFunc));
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.DepthRangeNear != _old.DepthRangeNear ||
|
|
|
|
|
New.DepthRangeFar != _old.DepthRangeFar)
|
2018-10-23 21:04:08 +02:00
|
|
|
|
{
|
|
|
|
|
GL.DepthRange(New.DepthRangeNear, New.DepthRangeFar);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.StencilTestEnabled != _old.StencilTestEnabled)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.StencilTest, New.StencilTestEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.StencilTwoSideEnabled != _old.StencilTwoSideEnabled)
|
2018-10-14 04:54:14 +02:00
|
|
|
|
{
|
|
|
|
|
Enable((EnableCap)All.StencilTestTwoSideExt, New.StencilTwoSideEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 06:09:40 +02:00
|
|
|
|
if (New.StencilTestEnabled)
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.StencilBackFuncFunc != _old.StencilBackFuncFunc ||
|
|
|
|
|
New.StencilBackFuncRef != _old.StencilBackFuncRef ||
|
|
|
|
|
New.StencilBackFuncMask != _old.StencilBackFuncMask)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
GL.StencilFuncSeparate(
|
|
|
|
|
StencilFace.Back,
|
2019-03-04 02:45:25 +01:00
|
|
|
|
OglEnumConverter.GetStencilFunc(New.StencilBackFuncFunc),
|
2018-08-10 06:09:40 +02:00
|
|
|
|
New.StencilBackFuncRef,
|
|
|
|
|
New.StencilBackFuncMask);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.StencilBackOpFail != _old.StencilBackOpFail ||
|
|
|
|
|
New.StencilBackOpZFail != _old.StencilBackOpZFail ||
|
|
|
|
|
New.StencilBackOpZPass != _old.StencilBackOpZPass)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
GL.StencilOpSeparate(
|
|
|
|
|
StencilFace.Back,
|
2019-03-04 02:45:25 +01:00
|
|
|
|
OglEnumConverter.GetStencilOp(New.StencilBackOpFail),
|
|
|
|
|
OglEnumConverter.GetStencilOp(New.StencilBackOpZFail),
|
|
|
|
|
OglEnumConverter.GetStencilOp(New.StencilBackOpZPass));
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.StencilBackMask != _old.StencilBackMask)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
GL.StencilMaskSeparate(StencilFace.Back, New.StencilBackMask);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.StencilFrontFuncFunc != _old.StencilFrontFuncFunc ||
|
|
|
|
|
New.StencilFrontFuncRef != _old.StencilFrontFuncRef ||
|
|
|
|
|
New.StencilFrontFuncMask != _old.StencilFrontFuncMask)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
GL.StencilFuncSeparate(
|
|
|
|
|
StencilFace.Front,
|
2019-03-04 02:45:25 +01:00
|
|
|
|
OglEnumConverter.GetStencilFunc(New.StencilFrontFuncFunc),
|
2018-08-10 06:09:40 +02:00
|
|
|
|
New.StencilFrontFuncRef,
|
|
|
|
|
New.StencilFrontFuncMask);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.StencilFrontOpFail != _old.StencilFrontOpFail ||
|
|
|
|
|
New.StencilFrontOpZFail != _old.StencilFrontOpZFail ||
|
|
|
|
|
New.StencilFrontOpZPass != _old.StencilFrontOpZPass)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
GL.StencilOpSeparate(
|
|
|
|
|
StencilFace.Front,
|
2019-03-04 02:45:25 +01:00
|
|
|
|
OglEnumConverter.GetStencilOp(New.StencilFrontOpFail),
|
|
|
|
|
OglEnumConverter.GetStencilOp(New.StencilFrontOpZFail),
|
|
|
|
|
OglEnumConverter.GetStencilOp(New.StencilFrontOpZPass));
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.StencilFrontMask != _old.StencilFrontMask)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
GL.StencilMaskSeparate(StencilFace.Front, New.StencilFrontMask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-13 22:26:42 +01:00
|
|
|
|
|
|
|
|
|
// Scissor Test
|
2019-03-02 11:50:21 +01:00
|
|
|
|
// All scissor test are disabled before drawing final framebuffer to screen so we don't need to handle disabling
|
|
|
|
|
// Skip if there are no scissor tests to enable
|
|
|
|
|
if (New.ScissorTestCount != 0)
|
2019-01-13 22:26:42 +01:00
|
|
|
|
{
|
2019-03-02 11:50:21 +01:00
|
|
|
|
int scissorsApplied = 0;
|
|
|
|
|
bool applyToAll = false;
|
2019-01-13 22:26:42 +01:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++)
|
2019-01-13 22:26:42 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.ScissorTestEnabled[index])
|
2019-01-13 22:26:42 +01:00
|
|
|
|
{
|
2019-03-02 11:50:21 +01:00
|
|
|
|
// If viewport arrays are unavailable apply first scissor test to all or
|
|
|
|
|
// there is only 1 scissor test and it's the first, the scissor test applies to all viewports
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (!OglExtension.Required.ViewportArray || (index == 0 && New.ScissorTestCount == 1))
|
2019-03-02 11:50:21 +01:00
|
|
|
|
{
|
|
|
|
|
GL.Enable(EnableCap.ScissorTest);
|
|
|
|
|
applyToAll = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.Enable(IndexedEnableCap.ScissorTest, index);
|
2019-03-02 11:50:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.ScissorTestEnabled[index] != _old.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])
|
2019-03-02 11:50:21 +01:00
|
|
|
|
{
|
|
|
|
|
if (applyToAll)
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.Scissor(New.ScissorTestX[index], New.ScissorTestY[index],
|
|
|
|
|
New.ScissorTestWidth[index], New.ScissorTestHeight[index]);
|
2019-03-02 11:50:21 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.ScissorIndexed(index, New.ScissorTestX[index], New.ScissorTestY[index],
|
|
|
|
|
New.ScissorTestWidth[index], New.ScissorTestHeight[index]);
|
2019-03-02 11:50:21 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
// If all scissor tests have been applied, or viewport arrays are unavailable we can skip remaining iterations
|
|
|
|
|
if (!OglExtension.Required.ViewportArray || ++scissorsApplied == New.ScissorTestCount)
|
2019-03-02 11:50:21 +01:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-01-13 22:26:42 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-11-01 05:22:24 +01:00
|
|
|
|
if (New.BlendIndependent)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
SetBlendState(index, New.Blends[index], _old.Blends[index]);
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
2018-11-01 05:22:24 +01:00
|
|
|
|
else
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.BlendIndependent != _old.BlendIndependent)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2018-11-01 05:22:24 +01:00
|
|
|
|
SetAllBlendState(New.Blends[0]);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
SetBlendState(New.Blends[0], _old.Blends[0]);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 23:30:09 +02:00
|
|
|
|
if (New.ColorMaskCommon)
|
2018-10-14 04:54:14 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.ColorMaskCommon != _old.ColorMaskCommon || !New.ColorMasks[0].Equals(_old.ColorMasks[0]))
|
2018-10-17 23:02:23 +02:00
|
|
|
|
{
|
|
|
|
|
GL.ColorMask(
|
2018-10-25 23:30:09 +02:00
|
|
|
|
New.ColorMasks[0].Red,
|
|
|
|
|
New.ColorMasks[0].Green,
|
|
|
|
|
New.ColorMasks[0].Blue,
|
|
|
|
|
New.ColorMasks[0].Alpha);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++)
|
2018-10-25 23:30:09 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (!New.ColorMasks[index].Equals(_old.ColorMasks[index]))
|
2018-10-25 23:30:09 +02:00
|
|
|
|
{
|
|
|
|
|
GL.ColorMask(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
index,
|
|
|
|
|
New.ColorMasks[index].Red,
|
|
|
|
|
New.ColorMasks[index].Green,
|
|
|
|
|
New.ColorMasks[index].Blue,
|
|
|
|
|
New.ColorMasks[index].Alpha);
|
2018-10-25 23:30:09 +02:00
|
|
|
|
}
|
2018-10-17 23:02:23 +02:00
|
|
|
|
}
|
2018-10-14 04:54:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.PrimitiveRestartEnabled != _old.PrimitiveRestartEnabled)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.PrimitiveRestart, New.PrimitiveRestartEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.PrimitiveRestartEnabled)
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.PrimitiveRestartIndex != _old.PrimitiveRestartIndex)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
GL.PrimitiveRestartIndex(New.PrimitiveRestartIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_old = New;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
public void Unbind(GalPipelineState state)
|
2019-03-02 11:50:21 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (state.ScissorTestCount > 0)
|
2019-03-02 11:50:21 +01:00
|
|
|
|
{
|
|
|
|
|
GL.Disable(EnableCap.ScissorTest);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 05:22:24 +01:00
|
|
|
|
private void SetAllBlendState(BlendState New)
|
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.Blend, New.Enabled);
|
|
|
|
|
|
|
|
|
|
if (New.Enabled)
|
|
|
|
|
{
|
|
|
|
|
if (New.SeparateAlpha)
|
|
|
|
|
{
|
|
|
|
|
GL.BlendEquationSeparate(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
OglEnumConverter.GetBlendEquation(New.EquationRgb),
|
|
|
|
|
OglEnumConverter.GetBlendEquation(New.EquationAlpha));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
|
|
|
|
|
GL.BlendFuncSeparate(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
(BlendingFactorSrc) OglEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
(BlendingFactorDest)OglEnumConverter.GetBlendFactor(New.FuncDstRgb),
|
|
|
|
|
(BlendingFactorSrc) OglEnumConverter.GetBlendFactor(New.FuncSrcAlpha),
|
|
|
|
|
(BlendingFactorDest)OglEnumConverter.GetBlendFactor(New.FuncDstAlpha));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.BlendEquation(OglEnumConverter.GetBlendEquation(New.EquationRgb));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
|
|
|
|
|
GL.BlendFunc(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
OglEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
OglEnumConverter.GetBlendFactor(New.FuncDstRgb));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private void SetBlendState(BlendState New, BlendState old)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.Enabled != old.Enabled)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
|
|
|
|
Enable(EnableCap.Blend, New.Enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.Enabled)
|
|
|
|
|
{
|
|
|
|
|
if (New.SeparateAlpha)
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.EquationRgb != old.EquationRgb ||
|
|
|
|
|
New.EquationAlpha != old.EquationAlpha)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
|
|
|
|
GL.BlendEquationSeparate(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
OglEnumConverter.GetBlendEquation(New.EquationRgb),
|
|
|
|
|
OglEnumConverter.GetBlendEquation(New.EquationAlpha));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.FuncSrcRgb != old.FuncSrcRgb ||
|
|
|
|
|
New.FuncDstRgb != old.FuncDstRgb ||
|
|
|
|
|
New.FuncSrcAlpha != old.FuncSrcAlpha ||
|
|
|
|
|
New.FuncDstAlpha != old.FuncDstAlpha)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
|
|
|
|
GL.BlendFuncSeparate(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
(BlendingFactorSrc) OglEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
(BlendingFactorDest)OglEnumConverter.GetBlendFactor(New.FuncDstRgb),
|
|
|
|
|
(BlendingFactorSrc) OglEnumConverter.GetBlendFactor(New.FuncSrcAlpha),
|
|
|
|
|
(BlendingFactorDest)OglEnumConverter.GetBlendFactor(New.FuncDstAlpha));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.EquationRgb != old.EquationRgb)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.BlendEquation(OglEnumConverter.GetBlendEquation(New.EquationRgb));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.FuncSrcRgb != old.FuncSrcRgb ||
|
|
|
|
|
New.FuncDstRgb != old.FuncDstRgb)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
|
|
|
|
GL.BlendFunc(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
OglEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
OglEnumConverter.GetBlendFactor(New.FuncDstRgb));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private void SetBlendState(int index, BlendState New, BlendState old)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.Enabled != old.Enabled)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
Enable(IndexedEnableCap.Blend, index, New.Enabled);
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (New.Enabled)
|
|
|
|
|
{
|
|
|
|
|
if (New.SeparateAlpha)
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.EquationRgb != old.EquationRgb ||
|
|
|
|
|
New.EquationAlpha != old.EquationAlpha)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
|
|
|
|
GL.BlendEquationSeparate(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
index,
|
|
|
|
|
OglEnumConverter.GetBlendEquation(New.EquationRgb),
|
|
|
|
|
OglEnumConverter.GetBlendEquation(New.EquationAlpha));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.FuncSrcRgb != old.FuncSrcRgb ||
|
|
|
|
|
New.FuncDstRgb != old.FuncDstRgb ||
|
|
|
|
|
New.FuncSrcAlpha != old.FuncSrcAlpha ||
|
|
|
|
|
New.FuncDstAlpha != old.FuncDstAlpha)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
|
|
|
|
GL.BlendFuncSeparate(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
index,
|
|
|
|
|
(BlendingFactorSrc) OglEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
(BlendingFactorDest)OglEnumConverter.GetBlendFactor(New.FuncDstRgb),
|
|
|
|
|
(BlendingFactorSrc) OglEnumConverter.GetBlendFactor(New.FuncSrcAlpha),
|
|
|
|
|
(BlendingFactorDest)OglEnumConverter.GetBlendFactor(New.FuncDstAlpha));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.EquationRgb != old.EquationRgb)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.BlendEquation(index, OglEnumConverter.GetBlendEquation(New.EquationRgb));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (New.FuncSrcRgb != old.FuncSrcRgb ||
|
|
|
|
|
New.FuncDstRgb != old.FuncDstRgb)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
|
|
|
|
GL.BlendFunc(
|
2019-03-04 02:45:25 +01:00
|
|
|
|
index,
|
|
|
|
|
(BlendingFactorSrc) OglEnumConverter.GetBlendFactor(New.FuncSrcRgb),
|
|
|
|
|
(BlendingFactorDest)OglEnumConverter.GetBlendFactor(New.FuncDstRgb));
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 06:09:40 +02:00
|
|
|
|
private void BindConstBuffers(GalPipelineState New)
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
int freeBinding = OglShader.ReservedCbufCount;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
void BindIfNotNull(OglShaderStage stage)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (stage != null)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
foreach (ShaderDeclInfo declInfo in stage.ConstBufferUsage)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
long key = New.ConstBufferKeys[(int)stage.Type][declInfo.Cbuf];
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (key != 0 && _buffer.TryGetUbo(key, out int uboHandle))
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, freeBinding, uboHandle);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
freeBinding++;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
BindIfNotNull(_shader.Current.Vertex);
|
|
|
|
|
BindIfNotNull(_shader.Current.TessControl);
|
|
|
|
|
BindIfNotNull(_shader.Current.TessEvaluation);
|
|
|
|
|
BindIfNotNull(_shader.Current.Geometry);
|
|
|
|
|
BindIfNotNull(_shader.Current.Fragment);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BindVertexLayout(GalPipelineState New)
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
foreach (GalVertexBinding binding in New.VertexBindings)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (!binding.Enabled || !_rasterizer.TryGetVbo(binding.VboKey, out int vboHandle))
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (_vaoHandle == 0)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_vaoHandle = GL.GenVertexArray();
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
|
|
|
|
//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
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.BindVertexArray(_vaoHandle);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
foreach (GalVertexAttrib attrib in binding.Attribs)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2018-09-18 06:30:35 +02:00
|
|
|
|
//Skip uninitialized attributes.
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (attrib.Size == 0)
|
2018-09-18 06:30:35 +02:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.BindBuffer(BufferTarget.ArrayBuffer, vboHandle);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
bool unsigned =
|
|
|
|
|
attrib.Type == GalVertexAttribType.Unorm ||
|
|
|
|
|
attrib.Type == GalVertexAttribType.Uint ||
|
|
|
|
|
attrib.Type == GalVertexAttribType.Uscaled;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
bool normalize =
|
|
|
|
|
attrib.Type == GalVertexAttribType.Snorm ||
|
|
|
|
|
attrib.Type == GalVertexAttribType.Unorm;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
VertexAttribPointerType type = 0;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (attrib.Type == GalVertexAttribType.Float)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
type = GetType(_floatAttribTypes, attrib);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (unsigned)
|
2018-08-20 21:02:38 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
type = GetType(_unsignedAttribTypes, attrib);
|
2018-08-20 21:02:38 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
type = GetType(_signedAttribTypes, attrib);
|
2018-08-20 21:02:38 +02:00
|
|
|
|
}
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (!_attribElements.TryGetValue(attrib.Size, out int size))
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
throw new InvalidOperationException("Invalid attribute size \"" + attrib.Size + "\"!");
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
int offset = attrib.Offset;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (binding.Stride != 0)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.EnableVertexAttribArray(attrib.Index);
|
2018-10-13 03:37:01 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (attrib.Type == GalVertexAttribType.Sint ||
|
|
|
|
|
attrib.Type == GalVertexAttribType.Uint)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
IntPtr pointer = new IntPtr(offset);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
VertexAttribIntegerType iType = (VertexAttribIntegerType)type;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribIPointer(attrib.Index, size, iType, binding.Stride, pointer);
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribPointer(attrib.Index, size, type, normalize, binding.Stride, offset);
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.DisableVertexAttribArray(attrib.Index);
|
2018-10-13 03:37:01 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
SetConstAttrib(attrib);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
2018-08-25 06:16:58 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (binding.Instanced && binding.Divisor != 0)
|
2018-08-25 06:16:58 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribDivisor(attrib.Index, 1);
|
2018-08-25 06:16:58 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribDivisor(attrib.Index, 0);
|
2018-08-25 06:16:58 +02:00
|
|
|
|
}
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private static VertexAttribPointerType GetType(Dictionary<GalVertexAttribSize, VertexAttribPointerType> dict, GalVertexAttrib attrib)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (!dict.TryGetValue(attrib.Size, out VertexAttribPointerType type))
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
ThrowUnsupportedAttrib(attrib);
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
return type;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private static unsafe void SetConstAttrib(GalVertexAttrib attrib)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (attrib.Size == GalVertexAttribSize._10_10_10_2 ||
|
|
|
|
|
attrib.Size == GalVertexAttribSize._11_11_10)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
ThrowUnsupportedAttrib(attrib);
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
fixed (byte* ptr = attrib.Data)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (attrib.Type == GalVertexAttribType.Unorm)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
switch (attrib.Size)
|
2018-11-28 23:18:09 +01:00
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._8:
|
|
|
|
|
case GalVertexAttribSize._8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8_8:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttrib4N((uint)attrib.Index, ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._16:
|
|
|
|
|
case GalVertexAttribSize._16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16_16:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttrib4N((uint)attrib.Index, (ushort*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttrib4N((uint)attrib.Index, (uint*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
2019-03-04 02:45:25 +01:00
|
|
|
|
else if (attrib.Type == GalVertexAttribType.Snorm)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
switch (attrib.Size)
|
2018-11-28 23:18:09 +01:00
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._8:
|
|
|
|
|
case GalVertexAttribSize._8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8_8:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttrib4N((uint)attrib.Index, (sbyte*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._16:
|
|
|
|
|
case GalVertexAttribSize._16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16_16:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttrib4N((uint)attrib.Index, (short*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttrib4N((uint)attrib.Index, (int*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
2019-03-04 02:45:25 +01:00
|
|
|
|
else if (attrib.Type == GalVertexAttribType.Uint)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
switch (attrib.Size)
|
2018-11-28 23:18:09 +01:00
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._8:
|
|
|
|
|
case GalVertexAttribSize._8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8_8:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribI4((uint)attrib.Index, ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._16:
|
|
|
|
|
case GalVertexAttribSize._16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16_16:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribI4((uint)attrib.Index, (ushort*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribI4((uint)attrib.Index, (uint*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
2019-03-04 02:45:25 +01:00
|
|
|
|
else if (attrib.Type == GalVertexAttribType.Sint)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
switch (attrib.Size)
|
2018-11-28 23:18:09 +01:00
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._8:
|
|
|
|
|
case GalVertexAttribSize._8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8:
|
|
|
|
|
case GalVertexAttribSize._8_8_8_8:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribI4((uint)attrib.Index, (sbyte*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._16:
|
|
|
|
|
case GalVertexAttribSize._16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16:
|
|
|
|
|
case GalVertexAttribSize._16_16_16_16:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribI4((uint)attrib.Index, (short*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttribI4((uint)attrib.Index, (int*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
2019-03-04 02:45:25 +01:00
|
|
|
|
else if (attrib.Type == GalVertexAttribType.Float)
|
2018-10-13 03:37:01 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
switch (attrib.Size)
|
2018-11-28 23:18:09 +01:00
|
|
|
|
{
|
|
|
|
|
case GalVertexAttribSize._32:
|
|
|
|
|
case GalVertexAttribSize._32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32:
|
|
|
|
|
case GalVertexAttribSize._32_32_32_32:
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.VertexAttrib4(attrib.Index, (float*)ptr);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
break;
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
default: ThrowUnsupportedAttrib(attrib); break;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
}
|
2018-10-13 03:37:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private static void ThrowUnsupportedAttrib(GalVertexAttrib attrib)
|
2018-10-25 23:30:09 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
throw new NotImplementedException("Unsupported size \"" + attrib.Size + "\" on type \"" + attrib.Type + "\"!");
|
2018-10-25 23:30:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private void Enable(EnableCap cap, bool enabled)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (enabled)
|
2018-08-10 06:09:40 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.Enable(cap);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.Disable(cap);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-17 23:02:23 +02:00
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
private void Enable(IndexedEnableCap cap, int index, bool enabled)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
if (enabled)
|
2018-11-01 05:22:24 +01:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.Enable(cap, index);
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
GL.Disable(cap, index);
|
2018-11-01 05:22:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 23:02:23 +02:00
|
|
|
|
public void ResetDepthMask()
|
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_old.DepthWriteEnabled = true;
|
2018-10-17 23:02:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
|
public void ResetColorMask(int index)
|
2018-10-17 23:02:23 +02:00
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
|
_old.ColorMasks[index] = ColorMaskState.Default;
|
2018-10-17 23:02:23 +02:00
|
|
|
|
}
|
2018-08-10 06:09:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|