opengl4
This commit is contained in:
+20
-12
@@ -10,6 +10,8 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
{
|
||||
public class RendererData
|
||||
{
|
||||
public GL Gl = null!;
|
||||
|
||||
public uint GlVersion; // e.g. 320 for GL 3.2
|
||||
public string GlslVersionString = ""; // e.g. "#version 330 core\n"
|
||||
public bool GlProfileIsES2;
|
||||
@@ -35,12 +37,10 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
|
||||
public bool UseTexParameterToSetSampler;
|
||||
public int NextSampler; // GL_LINEAR or GL_NEAREST
|
||||
|
||||
public GL Gl = null!;
|
||||
}
|
||||
|
||||
|
||||
public static RendererData? GetRendererData() => ImGui.GetCurrentContext().Handle != null ? ImGuiUserData<RendererData>.Get(ImGui.GetIO().BackendRendererUserData) : null;
|
||||
|
||||
|
||||
public static bool Init(GL gl, string? glslVersion = null)
|
||||
{
|
||||
ImGuiIOPtr io = ImGui.GetIO();
|
||||
@@ -143,7 +143,6 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
io.BackendRendererName = null;
|
||||
io.BackendRendererUserData = null;
|
||||
io.BackendFlags &= ~(ImGuiBackendFlags.RendererHasVtxOffset | ImGuiBackendFlags.RendererHasTextures | ImGuiBackendFlags.RendererHasViewports);
|
||||
|
||||
}
|
||||
|
||||
public static void NewFrame()
|
||||
@@ -222,7 +221,6 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
int idxSize = drawList.IdxBuffer.Size * sizeof(ushort);
|
||||
|
||||
gl.BufferData(GLBufferTargetARB.ArrayBuffer, vtxSize, drawList.VtxBuffer.Data, GLBufferUsageARB.StreamDraw);
|
||||
|
||||
gl.BufferData(GLBufferTargetARB.ElementArrayBuffer, idxSize, drawList.IdxBuffer.Data, GLBufferUsageARB.StreamDraw);
|
||||
|
||||
for (int cmdIdx = 0; cmdIdx < drawList.CmdBuffer.Size; cmdIdx++)
|
||||
@@ -234,11 +232,17 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
|
||||
nint cbPtr = (nint)cmd.UserCallback;
|
||||
if (cbPtr == (nint)DelegateStorage.DrawCallbackResetRenderStateDelegate.GetPtrForDelegate())
|
||||
{
|
||||
SetupRenderState(drawData, fbWidth, fbHeight, vao);
|
||||
}
|
||||
else if (cbPtr == (nint)DelegateStorage.DrawCallbackSetSamplerLinearDelegate.GetPtrForDelegate())
|
||||
{
|
||||
ApplySamplerLinear(bd);
|
||||
}
|
||||
else if (cbPtr == (nint)DelegateStorage.DrawCallbackSetSamplerNearestDelegate.GetPtrForDelegate())
|
||||
{
|
||||
ApplySamplerNearest(bd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImDrawCmdPtr cmdPtr = new ImDrawCmdPtr { Handle = &cmd };
|
||||
@@ -352,7 +356,7 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
2.0f / (R - L), 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 2.0f / (T - B), 0.0f, 0.0f,
|
||||
0.0f, 0.0f, -1.0f, 0.0f,
|
||||
(R + L) / (L - R), (T + B) / (B - T), 0.0f, 1.0f,
|
||||
(R + L) / (L - R), (T + B) / (B - T), 0.0f, 1.0f
|
||||
};
|
||||
|
||||
gl.UseProgram(bd.ShaderHandle);
|
||||
@@ -467,7 +471,7 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
< 130 => (vertSrc120, fragSrc120),
|
||||
300 => (vertSrc300es, fragSrc300es),
|
||||
>= 410 => (vertSrc410, fragSrc410),
|
||||
_ => (vertSrc130, fragSrc130),
|
||||
_ => (vertSrc130, fragSrc130)
|
||||
};
|
||||
|
||||
string fullVert = bd.GlslVersionString + vertSrc;
|
||||
@@ -577,7 +581,10 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
|
||||
private static void ApplySamplerLinear(RendererData bd)
|
||||
{
|
||||
if (bd.HasBindSampler) bd.Gl.BindSampler(0, bd.TexSamplers[0]);
|
||||
if (bd.HasBindSampler)
|
||||
{
|
||||
bd.Gl.BindSampler(0, bd.TexSamplers[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
bd.UseTexParameterToSetSampler = true;
|
||||
@@ -587,7 +594,10 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
|
||||
private static void ApplySamplerNearest(RendererData bd)
|
||||
{
|
||||
if (bd.HasBindSampler) bd.Gl.BindSampler(0, bd.TexSamplers[1]);
|
||||
if (bd.HasBindSampler)
|
||||
{
|
||||
bd.Gl.BindSampler(0, bd.TexSamplers[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
bd.UseTexParameterToSetSampler = true;
|
||||
@@ -630,8 +640,6 @@ public unsafe static class ImGuiSDL3Renderer
|
||||
|
||||
public static class DelegateStorage
|
||||
{
|
||||
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal delegate void DrawCallbackFn(ImDrawListPtr drawList, ImDrawCmdPtr cmd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user