satdump/android/imgui_image.cpp

87 lines
3.2 KiB
C++
Raw Permalink Normal View History

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
int funcGetMaxTextureSize()
{
int maxTextureSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
return maxTextureSize;
}
2022-05-13 21:35:51 +02:00
intptr_t funcMakeImageTexture(int, int)
2022-05-13 21:35:51 +02:00
{
GLuint gl_text;
glGenTextures(1, &gl_text);
return gl_text;
}
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);
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);
}
void funcUpdateMMImageTexture(intptr_t gl_text, uint32_t *buffer, int width, int height)
{
glBindTexture(GL_TEXTURE_2D, gl_text);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
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);
}
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()
{
maxTextureSize = funcGetMaxTextureSize();
2022-05-13 21:35:51 +02:00
makeImageTexture = funcMakeImageTexture;
updateImageTexture = funcUpdateImageTexture;
updateMMImageTexture = funcUpdateMMImageTexture;
2022-05-13 21:35:51 +02:00
deleteImageTexture = funcDeleteImageTexture;
}