imgui_impl_opengl3.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
  2. // - Desktop GL: 2.x 3.x 4.x
  3. // - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
  4. // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
  5. // Implemented features:
  6. // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
  7. // [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices.
  8. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
  9. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
  10. // https://github.com/ocornut/imgui
  11. // About Desktop OpenGL function loaders:
  12. // Modern Desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
  13. // Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
  14. // You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
  15. // About GLSL version:
  16. // The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string.
  17. // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
  18. // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
  19. #pragma once
  20. #include "imgui.h" // IMGUI_IMPL_API
  21. // Backend API
  22. IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL);
  23. IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
  24. IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
  25. IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
  26. // (Optional) Called by Init/NewFrame/Shutdown
  27. IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
  28. IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
  29. IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
  30. IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
  31. // Specific OpenGL ES versions
  32. //#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
  33. //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android
  34. // Attempt to auto-detect the default Desktop GL loader based on available header files.
  35. // If auto-detection fails or doesn't select the same GL loader file as used by your application,
  36. // you are likely to get a crash in ImGui_ImplOpenGL3_Init().
  37. // You can explicitly select a loader by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
  38. #if !defined(IMGUI_IMPL_OPENGL_ES2) \
  39. && !defined(IMGUI_IMPL_OPENGL_ES3) \
  40. && !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \
  41. && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \
  42. && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \
  43. && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2) \
  44. && !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) \
  45. && !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) \
  46. && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
  47. // Try to detect GLES on matching platforms
  48. #if defined(__APPLE__)
  49. #include "TargetConditionals.h"
  50. #endif
  51. #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
  52. #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
  53. #elif defined(__EMSCRIPTEN__)
  54. #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
  55. // Otherwise try to detect supported Desktop OpenGL loaders..
  56. #elif defined(__has_include)
  57. #if __has_include(<GL/glew.h>)
  58. #define IMGUI_IMPL_OPENGL_LOADER_GLEW
  59. #elif __has_include(<glad/glad.h>)
  60. #define IMGUI_IMPL_OPENGL_LOADER_GLAD
  61. #elif __has_include(<glad/gl.h>)
  62. #define IMGUI_IMPL_OPENGL_LOADER_GLAD2
  63. #elif __has_include(<GL/gl3w.h>)
  64. #define IMGUI_IMPL_OPENGL_LOADER_GL3W
  65. #elif __has_include(<glbinding/glbinding.h>)
  66. #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING3
  67. #elif __has_include(<glbinding/Binding.h>)
  68. #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
  69. #else
  70. #error "Cannot detect OpenGL loader!"
  71. #endif
  72. #else
  73. #define IMGUI_IMPL_OPENGL_LOADER_GL3W // Default to GL3W embedded in our repository
  74. #endif
  75. #endif