satdump/src-ui/imgui/imgui_image_base.cpp

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

// SatDump base OpenGL texture functions
// - All functions specified in imgui/imgui_image.h should be defined/assigned here
// - Only OpenGL calls defined in the system headers can be called here; no loaders
// are used.
// - Functions in this file must be compliant with OpenGL 2.1 and OpenGL ES 2.0
// - Functions must also be complaint with OpenGL 3.0+, unless they are overridden
// by a function in imgui_image_adv.cpp.
#include "imgui/imgui_image.h"
#include "gl.h"
2023-11-14 11:11:33 -05:00
#ifndef GL_GENERATE_MIPMAP
#define GL_GENERATE_MIPMAP 0x8191
#endif
#ifndef GL_CLAMP_TO_EDGE
#define GL_CLAMP_TO_EDGE 0x812F
#endif
2023-11-04 15:47:11 -04:00
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <GLES2/gl2ext.h>
#if !defined(GL_UNPACK_ROW_LENGTH) && defined(GL_UNPACK_ROW_LENGTH_EXT)
#define GL_UNPACK_ROW_LENGTH GL_UNPACK_ROW_LENGTH_EXT
#endif
2023-11-04 15:47:11 -04:00
#endif
int funcGetMaxTextureSize()
{
int maxTextureSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
return maxTextureSize;
}
unsigned int funcMakeImageTexture()
{
GLuint gl_text;
glGenTextures(1, &gl_text);
return gl_text;
}
2023-12-29 17:08:58 +01:00
void funcUpdateImageTexture(unsigned int gl_text, uint32_t *buffer, int width, int height)
{
glBindTexture(GL_TEXTURE_2D, gl_text);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2022-04-13 17:51:30 +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);
}
2023-12-29 17:08:58 +01:00
void funcUpdateMMImageTexture_GL2(unsigned int gl_text, uint32_t *buffer, int width, int height)
2023-11-13 09:00:28 -05:00
{
#if defined(IMGUI_IMPL_OPENGL_ES2)
if (width % 2 == 1 || height % 2 == 1)
{
funcUpdateImageTexture(gl_text, buffer, width, height);
return;
}
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);
#else
2023-11-13 09:00:28 -05:00
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);
2023-11-14 11:11:33 -05:00
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
2023-11-13 09:00:28 -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);
#endif
2023-11-13 09:00:28 -05:00
glBindTexture(GL_TEXTURE_2D, 0);
}
2023-12-29 17:08:58 +01:00
void funcDeleteImageTexture(unsigned int gl_text)
{
2023-12-29 17:08:58 +01:00
glDeleteTextures(1, &gl_text);
}
2023-11-13 09:00:28 -05:00
void bindBaseTextureFunctions()
{
maxTextureSize = funcGetMaxTextureSize();
makeImageTexture = funcMakeImageTexture;
updateImageTexture = funcUpdateImageTexture;
2023-11-13 09:00:28 -05:00
updateMMImageTexture = funcUpdateMMImageTexture_GL2;
deleteImageTexture = funcDeleteImageTexture;
2023-11-04 15:47:11 -04:00
}