| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762 |
- 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 }
- };
- 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 }
- };
- private static Dictionary<GalVertexAttribSize, VertexAttribPointerType> SignedAttribTypes =
- new Dictionary<GalVertexAttribSize, VertexAttribPointerType>()
- {
- { 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 }
- };
- private GalPipelineState Old;
- private OGLConstBuffer Buffer;
- private OGLRasterizer Rasterizer;
- private OGLShader Shader;
- private int VaoHandle;
- public OGLPipeline(OGLConstBuffer Buffer, OGLRasterizer Rasterizer, OGLShader Shader)
- {
- this.Buffer = Buffer;
- this.Rasterizer = Rasterizer;
- this.Shader = Shader;
- //These values match OpenGL's defaults
- Old = new GalPipelineState
- {
- FrontFace = GalFrontFace.CCW,
- CullFaceEnabled = false,
- CullFace = GalCullFace.Back,
- DepthTestEnabled = false,
- DepthWriteEnabled = true,
- DepthFunc = GalComparisonOp.Less,
- DepthRangeNear = 0,
- DepthRangeFar = 1,
- StencilTestEnabled = false,
- StencilBackFuncFunc = GalComparisonOp.Always,
- StencilBackFuncRef = 0,
- StencilBackFuncMask = UInt32.MaxValue,
- StencilBackOpFail = GalStencilOp.Keep,
- StencilBackOpZFail = GalStencilOp.Keep,
- StencilBackOpZPass = GalStencilOp.Keep,
- StencilBackMask = UInt32.MaxValue,
- StencilFrontFuncFunc = GalComparisonOp.Always,
- StencilFrontFuncRef = 0,
- StencilFrontFuncMask = UInt32.MaxValue,
- StencilFrontOpFail = GalStencilOp.Keep,
- StencilFrontOpZFail = GalStencilOp.Keep,
- StencilFrontOpZPass = GalStencilOp.Keep,
- StencilFrontMask = UInt32.MaxValue,
- BlendIndependent = false,
- PrimitiveRestartEnabled = false,
- PrimitiveRestartIndex = 0
- };
- for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++)
- {
- Old.Blends[Index] = BlendState.Default;
- Old.ColorMasks[Index] = ColorMaskState.Default;
- }
- }
- public void Bind(GalPipelineState New)
- {
- BindConstBuffers(New);
- BindVertexLayout(New);
- if (New.FramebufferSrgb != Old.FramebufferSrgb)
- {
- Enable(EnableCap.FramebufferSrgb, New.FramebufferSrgb);
- }
- if (New.FlipX != Old.FlipX || New.FlipY != Old.FlipY || New.Instance != Old.Instance)
- {
- Shader.SetExtraData(New.FlipX, New.FlipY, New.Instance);
- }
- //Note: Uncomment SetFrontFace and SetCullFace when flipping issues are solved
- //if (New.FrontFace != Old.FrontFace)
- //{
- // GL.FrontFace(OGLEnumConverter.GetFrontFace(New.FrontFace));
- //}
- //if (New.CullFaceEnabled != Old.CullFaceEnabled)
- //{
- // Enable(EnableCap.CullFace, New.CullFaceEnabled);
- //}
- //if (New.CullFaceEnabled)
- //{
- // if (New.CullFace != Old.CullFace)
- // {
- // GL.CullFace(OGLEnumConverter.GetCullFace(New.CullFace));
- // }
- //}
- if (New.DepthTestEnabled != Old.DepthTestEnabled)
- {
- Enable(EnableCap.DepthTest, New.DepthTestEnabled);
- }
- if (New.DepthWriteEnabled != Old.DepthWriteEnabled)
- {
- GL.DepthMask(New.DepthWriteEnabled);
- }
- if (New.DepthTestEnabled)
- {
- if (New.DepthFunc != Old.DepthFunc)
- {
- GL.DepthFunc(OGLEnumConverter.GetDepthFunc(New.DepthFunc));
- }
- }
- if (New.DepthRangeNear != Old.DepthRangeNear ||
- New.DepthRangeFar != Old.DepthRangeFar)
- {
- GL.DepthRange(New.DepthRangeNear, New.DepthRangeFar);
- }
- if (New.StencilTestEnabled != Old.StencilTestEnabled)
- {
- Enable(EnableCap.StencilTest, New.StencilTestEnabled);
- }
- if (New.StencilTwoSideEnabled != Old.StencilTwoSideEnabled)
- {
- Enable((EnableCap)All.StencilTestTwoSideExt, New.StencilTwoSideEnabled);
- }
- 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);
- }
- }
- if (New.BlendIndependent)
- {
- for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++)
- {
- SetBlendState(Index, New.Blends[Index], Old.Blends[Index]);
- }
- }
- else
- {
- if (New.BlendIndependent != Old.BlendIndependent)
- {
- SetAllBlendState(New.Blends[0]);
- }
- else
- {
- SetBlendState(New.Blends[0], Old.Blends[0]);
- }
- }
- if (New.ColorMaskCommon)
- {
- if (New.ColorMaskCommon != Old.ColorMaskCommon || !New.ColorMasks[0].Equals(Old.ColorMasks[0]))
- {
- GL.ColorMask(
- 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);
- }
- }
- }
- if (New.PrimitiveRestartEnabled != Old.PrimitiveRestartEnabled)
- {
- Enable(EnableCap.PrimitiveRestart, New.PrimitiveRestartEnabled);
- }
- if (New.PrimitiveRestartEnabled)
- {
- if (New.PrimitiveRestartIndex != Old.PrimitiveRestartIndex)
- {
- GL.PrimitiveRestartIndex(New.PrimitiveRestartIndex);
- }
- }
- Old = New;
- }
- 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));
- }
- }
- }
- }
- private void BindConstBuffers(GalPipelineState New)
- {
- int FreeBinding = OGLShader.ReservedCbufCount;
- void BindIfNotNull(OGLShaderStage Stage)
- {
- if (Stage != null)
- {
- foreach (ShaderDeclInfo DeclInfo in Stage.ConstBufferUsage)
- {
- 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)
- {
- //Skip uninitialized attributes.
- if (Attrib.Size == 0)
- {
- continue;
- }
- GL.BindBuffer(BufferTarget.ArrayBuffer, VboHandle);
- bool Unsigned =
- Attrib.Type == GalVertexAttribType.Unorm ||
- Attrib.Type == GalVertexAttribType.Uint ||
- Attrib.Type == GalVertexAttribType.Uscaled;
- bool Normalize =
- Attrib.Type == GalVertexAttribType.Snorm ||
- Attrib.Type == GalVertexAttribType.Unorm;
- VertexAttribPointerType Type = 0;
- if (Attrib.Type == GalVertexAttribType.Float)
- {
- Type = GetType(FloatAttribTypes, Attrib);
- }
- else
- {
- if (Unsigned)
- {
- Type = GetType(UnsignedAttribTypes, Attrib);
- }
- else
- {
- Type = GetType(SignedAttribTypes, Attrib);
- }
- }
- if (!AttribElements.TryGetValue(Attrib.Size, out int Size))
- {
- throw new InvalidOperationException("Invalid attribute size \"" + Attrib.Size + "\"!");
- }
- int Offset = Attrib.Offset;
- if (Binding.Stride != 0)
- {
- GL.EnableVertexAttribArray(Attrib.Index);
- if (Attrib.Type == GalVertexAttribType.Sint ||
- Attrib.Type == GalVertexAttribType.Uint)
- {
- IntPtr Pointer = new IntPtr(Offset);
- VertexAttribIntegerType IType = (VertexAttribIntegerType)Type;
- GL.VertexAttribIPointer(Attrib.Index, Size, IType, Binding.Stride, Pointer);
- }
- else
- {
- GL.VertexAttribPointer(Attrib.Index, Size, Type, Normalize, Binding.Stride, Offset);
- }
- }
- else
- {
- GL.DisableVertexAttribArray(Attrib.Index);
- SetConstAttrib(Attrib);
- }
- if (Binding.Instanced && Binding.Divisor != 0)
- {
- GL.VertexAttribDivisor(Attrib.Index, 1);
- }
- else
- {
- GL.VertexAttribDivisor(Attrib.Index, 0);
- }
- }
- }
- }
- private static VertexAttribPointerType GetType(Dictionary<GalVertexAttribSize, VertexAttribPointerType> Dict, GalVertexAttrib Attrib)
- {
- if (!Dict.TryGetValue(Attrib.Size, out VertexAttribPointerType Type))
- {
- ThrowUnsupportedAttrib(Attrib);
- }
- return Type;
- }
- private unsafe static void SetConstAttrib(GalVertexAttrib Attrib)
- {
- if (Attrib.Size == GalVertexAttribSize._10_10_10_2 ||
- Attrib.Size == GalVertexAttribSize._11_11_10)
- {
- ThrowUnsupportedAttrib(Attrib);
- }
- if (Attrib.Type == GalVertexAttribType.Unorm)
- {
- 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, (byte*)Attrib.Pointer);
- 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*)Attrib.Pointer);
- 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*)Attrib.Pointer);
- break;
- }
- }
- else if (Attrib.Type == GalVertexAttribType.Snorm)
- {
- 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*)Attrib.Pointer);
- 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*)Attrib.Pointer);
- 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*)Attrib.Pointer);
- break;
- }
- }
- else if (Attrib.Type == GalVertexAttribType.Uint)
- {
- 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, (byte*)Attrib.Pointer);
- 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*)Attrib.Pointer);
- 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*)Attrib.Pointer);
- break;
- }
- }
- else if (Attrib.Type == GalVertexAttribType.Sint)
- {
- 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*)Attrib.Pointer);
- 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*)Attrib.Pointer);
- 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*)Attrib.Pointer);
- break;
- }
- }
- else if (Attrib.Type == GalVertexAttribType.Float)
- {
- 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*)Attrib.Pointer);
- break;
- default: ThrowUnsupportedAttrib(Attrib); break;
- }
- }
- }
- private static void ThrowUnsupportedAttrib(GalVertexAttrib Attrib)
- {
- throw new NotImplementedException("Unsupported size \"" + Attrib.Size + "\" on type \"" + Attrib.Type + "\"!");
- }
- private void Enable(EnableCap Cap, bool Enabled)
- {
- if (Enabled)
- {
- GL.Enable(Cap);
- }
- else
- {
- GL.Disable(Cap);
- }
- }
- private void Enable(IndexedEnableCap Cap, int Index, bool Enabled)
- {
- if (Enabled)
- {
- GL.Enable(Cap, Index);
- }
- else
- {
- GL.Disable(Cap, Index);
- }
- }
- public void ResetDepthMask()
- {
- Old.DepthWriteEnabled = true;
- }
- public void ResetColorMask(int Index)
- {
- Old.ColorMasks[Index] = ColorMaskState.Default;
- }
- }
- }
|