2022-05-13 21:35:51 +02:00
|
|
|
#include "imgui/imgui_image.h"
|
|
|
|
|
|
|
|
|
|
// GL includes
|
|
|
|
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
|
|
|
|
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
|
2023-12-29 17:08:58 +01:00
|
|
|
#include <OpenGLES/ES2/gl.h> // Use GL ES 2
|
2022-05-13 21:35:51 +02:00
|
|
|
#else
|
2023-12-29 17:08:58 +01:00
|
|
|
#include <GLES2/gl2.h> // Use GL ES 2
|
2022-05-13 21:35:51 +02:00
|
|
|
#endif
|
|
|
|
|
#if defined(__EMSCRIPTEN__)
|
|
|
|
|
#ifndef GL_GLEXT_PROTOTYPES
|
|
|
|
|
#define GL_GLEXT_PROTOTYPES
|
|
|
|
|
#endif
|
|
|
|
|
#include <GLES2/gl2ext.h>
|
|
|
|
|
#endif
|
|
|
|
|
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
|
#include <TargetConditionals.h>
|
|
|
|
|
#endif
|
|
|
|
|
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
|
2023-12-29 17:08:58 +01:00
|
|
|
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
|
2022-05-13 21:35:51 +02:00
|
|
|
#else
|
2023-12-29 17:08:58 +01:00
|
|
|
#include <GLES3/gl3.h> // Use GL ES 3
|
2022-05-13 21:35:51 +02:00
|
|
|
#endif
|
|
|
|
|
#elif !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
|
|
|
|
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
|
|
|
|
|
// Helper libraries are often used for this purpose! Here we are using our own minimal custom loader based on gl3w.
|
|
|
|
|
// In the rest of your app/engine, you can use another loader of your choice (gl3w, glew, glad, glbinding, glext, glLoadGen, etc.).
|
|
|
|
|
// If you happen to be developing a new feature for this backend (imgui_impl_opengl3.cpp):
|
|
|
|
|
// - You may need to regenerate imgui_impl_opengl3_loader.h to add new symbols. See https://github.com/dearimgui/gl3w_stripped
|
|
|
|
|
// - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
|
|
|
|
|
// Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
|
|
|
|
|
#define IMGL3W_IMPL
|
|
|
|
|
#include "imgui_impl_opengl3_loader.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-11-13 21:38:07 -05:00
|
|
|
int funcGetMaxTextureSize()
|
|
|
|
|
{
|
|
|
|
|
int maxTextureSize;
|
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
|
|
|
|
|
return maxTextureSize;
|
|
|
|
|
}
|
2022-05-13 21:35:51 +02:00
|
|
|
|
2025-07-05 08:05:45 -04:00
|
|
|
intptr_t funcMakeImageTexture(int, int)
|
2022-05-13 21:35:51 +02:00
|
|
|
{
|
|
|
|
|
GLuint gl_text;
|
|
|
|
|
glGenTextures(1, &gl_text);
|
|
|
|
|
return gl_text;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-05 08:05:45 -04:00
|
|
|
void funcUpdateImageTexture(intptr_t gl_text, uint32_t *buffer, int width, int height)
|
2022-05-13 21:35:51 +02:00
|
|
|
{
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl_text);
|
2023-11-12 19:34:01 -05:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2022-05-13 21:35:51 +02:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-05 08:05:45 -04:00
|
|
|
void funcUpdateMMImageTexture(intptr_t gl_text, uint32_t *buffer, int width, int height)
|
2023-11-12 19:34:01 -05:00
|
|
|
{
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gl_text);
|
2023-11-14 08:45:42 -05:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2023-11-12 19:34:01 -05:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
|
|
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-05 08:05:45 -04:00
|
|
|
void funcDeleteImageTexture(intptr_t gl_text)
|
2022-05-13 21:35:51 +02:00
|
|
|
{
|
2023-12-29 17:08:58 +01:00
|
|
|
glDeleteTextures(1, &gl_text);
|
2022-05-13 21:35:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void bindImageTextureFunctions()
|
|
|
|
|
{
|
2023-11-13 21:38:07 -05:00
|
|
|
maxTextureSize = funcGetMaxTextureSize();
|
2022-05-13 21:35:51 +02:00
|
|
|
makeImageTexture = funcMakeImageTexture;
|
|
|
|
|
updateImageTexture = funcUpdateImageTexture;
|
2023-11-12 19:34:01 -05:00
|
|
|
updateMMImageTexture = funcUpdateMMImageTexture;
|
2022-05-13 21:35:51 +02:00
|
|
|
deleteImageTexture = funcDeleteImageTexture;
|
2023-11-14 08:45:42 -05:00
|
|
|
}
|