zwcloud / ImGui

Immediate Mode GUI for C#
https://zwcloud.net/#project/imgui
GNU Affero General Public License v3.0
197 stars 21 forks source link

Core Graphics card does not support some OpenGL features. #85

Open GodZza opened 1 year ago

GodZza commented 1 year ago

Hello When i run the DEMO on my notebook.the following error is thrown in all of them:

Exception has occurred: CLR/System.Exception
“System.Exception”类型的未经处理的异常在 ImGui.dll 中发生 : 'Failed to GetAddress for <wglBindTexImageARB>'
   在 ImGui.OSImplementation.Windows.Win32OpenGLRenderer.Wgl.GetAddress(String function_string)
   在 ImGui.OSImplementation.Windows.Win32OpenGLRenderer.Wgl.LoadEntryPoints(IntPtr hdc)
   在 ImGui.OSImplementation.Windows.Win32OpenGLRenderer.Wgl.Init(IntPtr mainWindowHwnd)
   在 ImGui.OSImplementation.Windows.Win32OpenGLRenderer.CreateOpenGLContext(IntPtr hwnd)
   在 ImGui.OSImplementation.Windows.Win32OpenGLRenderer.Init(IntPtr windowHandle, Size size)
   在 ImGui.OSImplementation.Windows.Win32OpenGLRenderer..ctor(IWindow window)
   在 ImGui.OSImplementation.Windows.WindowsContext.CRenderer(IWindow window)
   在 ImGui.Application.Run(Form mainForm, Action onGUI)
   在 YourApp.Program.Main()

I use 'Windows 11 home basic', version '21H2', 64-bit operating system. the Core Graphic Card is Intel UHD Graphics and the Discrete graphic card is NVIDIA GeForce RTX 3070. the DEMO runs on the Core Graphic Card display mode.

I checked, the Core Graphic Card does not support these APIs, and our ImGui project may have not used these?

wglBindTexImageARB
wglReleaseTexImageARB
wglSetPbufferAttribARB

so here's my temporary solution is comment all of them.

As well as, on the Core Graphic Card display mode, it can not even create images.

Exception has occurred: CLR/System.Exception
“System.Exception”类型的未经处理的异常在 ImGui.dll 中发生 : 'glError: 0x500 (GL_INVALID_ENUM)'
   在 ImGui.Utility.CheckGLError()
   在 ImGui.OSImplementation.Shared.OpenGLTexture.LoadImage(String filePath)
   在 ImGui.OSAbstraction.Graphics.TextureCache.GetOrAdd(String path, IRenderer renderer)
   在 ImGui.Rendering.DrawingContextEx.DrawImage(DrawingContext dc, String path, Rect rect)
   在 ImGui.Window.FirstUpdate(String name, Size size, Boolean& open, Double backgroundAlpha, WindowFlags flags, Int64 currentFrame, Window parentWindow)
   在 ImGui.GUI.Begin(String name, Boolean& open, Point position, Size size, Double bg_alpha, WindowFlags flags)
   在 ImGui.GUI.Begin(String title, Rect rect, WindowFlags flags)
   在 ImGui.Application.NewFrame()
   在 ImGui.Application.<>c__DisplayClass20_0.<Run>b__0()
   在 ImGui.OSImplementation.Windows.Win32Window.MainLoop(Action guiMethod)
   在 ImGui.Form.MainLoop(Action loopMethod)
   在 ImGui.Application.Run(Form mainForm, Action onGUI)
   在 YourApp.Program.Main() 

I checked,the Core Graphic Card does not support GL.GL_CLAMP at LoadImage() Function.

/// <summary>
/// Load an image from a file.
/// </summary>
/// <param name="filePath"></param>
public void LoadImage(string filePath)
{
    // check file header, save texture data to buffer
    if (!filePath.EndsWith(".png"))
    {
        throw new NotSupportedException("Only RGBA8 png file is supported for now.");
    }

    this.image = new Image(filePath);
    textureData = image.Data;
    this.Width = this.image.Width;
    this.Height = this.image.Height;

    // create opengl texture object
    GL.ActiveTexture(GL.GL_TEXTURE0);
    GL.GenTextures(1, this.textureIdBuffer);
    var textureHandle = this.textureIdBuffer[0];
    GL.BindTexture(GL.GL_TEXTURE_2D, textureHandle);
    var textureDataPtr = Marshal.UnsafeAddrOfPinnedArrayElement(this.textureData, 0);
    GL.TexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, this.Width, this.Height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, textureDataPtr);
    //sampler settings
    GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, (int)GL.GL_CLAMP);  //HERE!
    GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, (int)GL.GL_CLAMP);  //HERE!
    GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR);
    GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR);
    Utility.CheckGLError();
}

let (int)GL.GL_CLAMP change to GL.GL_CLAMP_TO_EDGE. it's fine.

//   TextureWrapMode
// GL_CLAMP doesn't exist in WebGL, so don't use it in WebGL! Use GL_CLAMP_TO_EDGE instead.
public const uint GL_CLAMP = 0x2900;

BUT When I switch display mode to Discrete Graphic Card, the code have not change. the DEMO program would be good.

Do you plan to make it compatible? THANKS!

zwcloud commented 1 year ago

Thanks for testing and reporting the issue. I will make use of your investigation when fixing the issue.

Do you plan to make it compatible?

Yes, when I have time.