backend updates

pd-3ds:
Add support for RGB565 textures
pd-desktop:
Add support for A8 textures
Add glfw callback chain to not break other libs using the same callback
This commit is contained in:
2026-01-05 14:37:57 +01:00
parent 3575a6787d
commit eb5d5f9974
5 changed files with 31 additions and 5 deletions

View File

@@ -95,6 +95,11 @@ void FragCfg(GPU_TEXCOLOR clr) {
C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE);
C3D_TexEnvFunc(env, C3D_Alpha, GPU_MODULATE);
break;
case GPU_RGB565:
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
C3D_TexEnvFunc(env, C3D_RGB, GPU_MODULATE);
C3D_TexEnvFunc(env, C3D_Alpha, GPU_REPLACE);
break;
default:
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);

View File

@@ -57,6 +57,7 @@ class GfxGL2 : public GfxDriver {
GLuint Shader;
GLuint pLocProjection;
GLuint pLocTex;
GLuint pLocAlfa;
GLuint VBO, IBO;
};
} // namespace PD

View File

@@ -64,6 +64,7 @@ class HidGLFW : public HidDriver {
GLFWwindow* Window;
int PrevState;
std::unordered_map<int, int> PrevStates;
static GLFWcharfun pOldTextCB;
static std::string* pText;
bool pInTextMode = false;
PD::u64 pLastUpdate = 0;

View File

@@ -53,10 +53,15 @@ const char* frag_shader = R"(
varying vec4 oColor;
uniform sampler2D tex;
uniform bool alfa;
void main() {
vec4 tc = texture2D(tex, oUV);
gl_FragColor = tc*oColor;
vec4 tc = texture2D(tex, oUV);
if (alfa) {
gl_FragColor = vec4(oColor.rgb, tc.a * oColor.a);
} else {
gl_FragColor = tc * oColor;
}
}
)";
@@ -138,6 +143,7 @@ void GfxGL2::Init() {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
pLocTex = glGetUniformLocation(Shader, "tex");
pLocAlfa = glGetUniformLocation(Shader, "alfa");
pLocProjection = glGetUniformLocation(Shader, "projection");
glBindBuffer(GL_ARRAY_BUFFER, 0);
@@ -172,6 +178,9 @@ void GfxGL2::BindTex(PD::Li::TexAddress addr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
glUniform1i(pLocTex, 0);
GLint fmt = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
}
void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {

View File

@@ -24,11 +24,21 @@ SOFTWARE.
#include <pd-desktop/bknd-hid.hpp>
namespace PD {
std::string* HidGLFW::pText;
std::string* HidGLFW::pText = nullptr;
GLFWcharfun HidGLFW::pOldTextCB = nullptr;
// Default Call back (If no Text input is requsted)
void NullTextCB(GLFWwindow* win, unsigned int c) {}
void NullTextCB(GLFWwindow* win, unsigned int c) {
// Chain
if (HidGLFW::pOldTextCB) {
HidGLFW::pOldTextCB(win, c);
}
}
// Text callback if requested
void TextCB(GLFWwindow* win, unsigned int c) {
// Chain
if (HidGLFW::pOldTextCB) {
HidGLFW::pOldTextCB(win, c);
}
if (!HidGLFW::pText) {
return;
}
@@ -36,7 +46,7 @@ void TextCB(GLFWwindow* win, unsigned int c) {
}
HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") {
Window = win;
glfwSetCharCallback(Window, NullTextCB);
HidGLFW::pOldTextCB = glfwSetCharCallback(Window, NullTextCB);
Flags |= Flags_HasKeyboard;
Flags |= Flags_HasMouse;
pBinds[GLFW_MOUSE_BUTTON_LEFT] = Touch;