Skip to content

Commit

Permalink
refactor DrawBuffers (#1815)
Browse files Browse the repository at this point in the history
* move glDrawBuffers

* merge DrawBuffersEnum

* internal DrawBuffers

* DrawBuffers GL version support
  • Loading branch information
nkast authored Sep 1, 2024
1 parent 685a65e commit 9462824
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Platforms/Graphics/.GL.SDL/ConcreteGraphicsContext.SDL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal sealed class ConcreteGraphicsContext : ConcreteGraphicsContextGL
private IntPtr _glSharedContext;
private IntPtr _glSharedContextWindowHandle;

internal DrawBuffersEnum[] _drawBuffers;
internal DrawBufferMode[] _drawBuffers;

internal IntPtr GlContext { get { return _glContext; } }

Expand Down
4 changes: 2 additions & 2 deletions Platforms/Graphics/.GL.SDL/ConcreteGraphicsDevice.SDL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ protected override void PlatformSetup(PresentationParameters presentationParamet
((ConcreteGraphicsCapabilities)_capabilities).PlatformInitialize(this, _glMajorVersion, _glMinorVersion);

// Initialize draw buffer attachment array
((IPlatformGraphicsContext)_mainContext).Strategy.ToConcrete<ConcreteGraphicsContext>()._drawBuffers = new DrawBuffersEnum[((ConcreteGraphicsCapabilities)this.Capabilities).MaxDrawBuffers];
((IPlatformGraphicsContext)_mainContext).Strategy.ToConcrete<ConcreteGraphicsContext>()._drawBuffers = new DrawBufferMode[((ConcreteGraphicsCapabilities)this.Capabilities).MaxDrawBuffers];
for (int i = 0; i < ((IPlatformGraphicsContext)_mainContext).Strategy.ToConcrete<ConcreteGraphicsContext>()._drawBuffers.Length; i++)
((IPlatformGraphicsContext)_mainContext).Strategy.ToConcrete<ConcreteGraphicsContext>()._drawBuffers[i] = (DrawBuffersEnum)(DrawBuffersEnum.ColorAttachment0 + i);
((IPlatformGraphicsContext)_mainContext).Strategy.ToConcrete<ConcreteGraphicsContext>()._drawBuffers[i] = (DrawBufferMode)(DrawBufferMode.ColorAttachment0 + i);

((IPlatformGraphicsContext)_mainContext).Strategy.ToConcrete<ConcreteGraphicsContext>()._newEnabledVertexAttributes = new bool[this.Capabilities.MaxVertexBufferSlots];
}
Expand Down
43 changes: 26 additions & 17 deletions Platforms/Graphics/.GL/OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ internal enum StencilFace
Front = 0x0404,
Back = 0x0405,
}
internal enum DrawBuffersEnum
{
None = 0x0000,
Back = 0x0405,
ColorAttachment0 = 0x8CE0,
}

internal enum ShaderType
{
Expand Down Expand Up @@ -97,6 +91,8 @@ internal enum ReadBufferMode

internal enum DrawBufferMode
{
None = 0x0000,
Back = 0x0405,
ColorAttachment0 = 0x8CE0,
}

Expand Down Expand Up @@ -677,12 +673,6 @@ internal unsafe int GenTexture()
internal delegate void PolygonOffsetDelegate(float slopeScaleDepthBias, float depthbias);
internal PolygonOffsetDelegate PolygonOffset;

[System.Security.SuppressUnmanagedCodeSecurity()]
[UnmanagedFunctionPointer(callingConvention)]
[MonoNativeFunctionWrapper]
internal delegate void DrawBuffersDelegate(int count, DrawBuffersEnum[] buffers);
internal DrawBuffersDelegate DrawBuffers;

[System.Security.SuppressUnmanagedCodeSecurity()]
[UnmanagedFunctionPointer(callingConvention)]
[MonoNativeFunctionWrapper]
Expand Down Expand Up @@ -913,7 +903,26 @@ internal delegate void FramebufferRenderbufferDelegate(FramebufferTarget target,
[UnmanagedFunctionPointer(callingConvention)]
[MonoNativeFunctionWrapper]
internal delegate void DrawBufferDelegate(DrawBufferMode buffer);
internal DrawBufferDelegate DrawBuffer;
internal DrawBufferDelegate DrawBufferInternal; // OpenGL 2.0, GLES N/A.

internal unsafe void DrawBuffer(DrawBufferMode buffer)
{
DrawBufferInternal(buffer);
}

[System.Security.SuppressUnmanagedCodeSecurity()]
[UnmanagedFunctionPointer(callingConvention)]
[MonoNativeFunctionWrapper]
internal unsafe delegate void DrawBuffersDelegate(int count, DrawBufferMode* pbuffers);
internal DrawBuffersDelegate DrawBuffersInternal; // OpenGL 2.0, GLES 3.0.

internal unsafe void DrawBuffers(int count, DrawBufferMode[] buffers)
{
fixed (DrawBufferMode* pbuffers = buffers)
{
DrawBuffersInternal(count, pbuffers);
}
}

[System.Security.SuppressUnmanagedCodeSecurity()]
[UnmanagedFunctionPointer(callingConvention)]
Expand All @@ -928,7 +937,7 @@ internal delegate void BlitFramebufferDelegate(int srcX0,
int dstY1,
ClearBufferMask mask,
BlitFramebufferFilter filter);
internal BlitFramebufferDelegate BlitFramebuffer;
internal BlitFramebufferDelegate BlitFramebuffer; // OpenGL 3.0, GLES 3.0.

[System.Security.SuppressUnmanagedCodeSecurity()]
[UnmanagedFunctionPointer(callingConvention)]
Expand Down Expand Up @@ -1462,7 +1471,9 @@ private void LoadEntryPoints()
PolygonOffset = LoadFunctionOrNull<PolygonOffsetDelegate>("glPolygonOffset");

BindBuffer = LoadFunctionOrNull<BindBufferDelegate>("glBindBuffer");
DrawBuffers = LoadFunctionOrNull<DrawBuffersDelegate>("glDrawBuffers");
ReadBuffer = LoadFunctionOrNull<ReadBufferDelegate>("glReadBuffer");
DrawBufferInternal = LoadFunctionOrNull<DrawBufferDelegate>("glDrawBuffer");
DrawBuffersInternal = LoadFunctionOrNull<DrawBuffersDelegate>("glDrawBuffers");
DrawElements = LoadFunctionOrNull<DrawElementsDelegate>("glDrawElements");
DrawArrays = LoadFunctionOrNull<DrawArraysDelegate>("glDrawArrays");

Expand All @@ -1485,8 +1496,6 @@ private void LoadEntryPoints()
// uniforms OpenGL Version >= 3.0
// ... Uniform 1ui,1uiv,2ui,2uiv,2ui,2uiv,2ui,2uiv

ReadBuffer = LoadFunctionOrNull<ReadBufferDelegate>("glReadBuffer");
DrawBuffer = LoadFunctionOrNull<DrawBufferDelegate>("glDrawBuffer");

// Render Target Support. These might be null if they are not supported
GenRenderbuffers = LoadFunctionOrNull<GenRenderbuffersDelegate>("glGenRenderbuffers");
Expand Down

0 comments on commit 9462824

Please sign in to comment.