mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 14:19:55 -06:00
BAHAHAHHHH
HARK HARK HARK
This commit is contained in:
@ -104,6 +104,7 @@ GLuint GL_ScreenShader[3];
|
||||
struct
|
||||
{
|
||||
float uScreenSize[2];
|
||||
u32 u3DScale;
|
||||
u32 uFilterMode;
|
||||
|
||||
} GL_ShaderConfig;
|
||||
@ -217,6 +218,7 @@ void GLDrawing_DrawScreen()
|
||||
|
||||
GL_ShaderConfig.uScreenSize[0] = WindowWidth;
|
||||
GL_ShaderConfig.uScreenSize[1] = WindowHeight;
|
||||
GL_ShaderConfig.u3DScale = 1 << GPU3D::GetScale();
|
||||
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, GL_ShaderConfigUBO);
|
||||
void* unibuf = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY);
|
||||
@ -342,7 +344,7 @@ void GLDrawing_DrawScreen()
|
||||
|
||||
OpenGL_UseShaderProgram(GL_ScreenShader);
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
@ -353,11 +355,14 @@ void GLDrawing_DrawScreen()
|
||||
GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 768, 256<<ScreenScale[1], 192<<ScreenScale[1], GL_RGBA_INTEGER,
|
||||
GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]);*/
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3, 192, GL_RGBA_INTEGER,
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3 + 1, 192, GL_RGBA_INTEGER,
|
||||
GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 768, 256*3, 192, GL_RGBA_INTEGER,
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 768, 256*3 + 1, 192, GL_RGBA_INTEGER,
|
||||
GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]);
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
GPU3D::SetupAccelFrame();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID);
|
||||
glBindVertexArray(GL_ScreenVertexArrayID);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 4*3);
|
||||
|
@ -24,6 +24,7 @@ const char* kScreenVS = R"(#version 420
|
||||
layout(std140, binding=0) uniform uConfig
|
||||
{
|
||||
vec2 uScreenSize;
|
||||
uint u3DScale;
|
||||
uint uFilterMode;
|
||||
};
|
||||
|
||||
@ -50,10 +51,12 @@ const char* kScreenFS = R"(#version 420
|
||||
layout(std140, binding=0) uniform uConfig
|
||||
{
|
||||
vec2 uScreenSize;
|
||||
uint u3DScale;
|
||||
uint uFilterMode;
|
||||
};
|
||||
|
||||
layout(binding=0) uniform usampler2D ScreenTex;
|
||||
layout(binding=1) uniform sampler2D _3DTex;
|
||||
|
||||
smooth in vec2 fTexcoord;
|
||||
|
||||
@ -63,9 +66,127 @@ void main()
|
||||
{
|
||||
uvec4 pixel = texelFetch(ScreenTex, ivec2(fTexcoord), 0);
|
||||
|
||||
// bit0-13: BLDCNT
|
||||
// bit14-15: DISPCNT display mode
|
||||
// bit16-20: EVA
|
||||
// bit21-25: EVB
|
||||
// bit26-30: EVY
|
||||
uvec4 ctl = texelFetch(ScreenTex, ivec2(256*3, int(fTexcoord.y)), 0);
|
||||
uint dispmode = (ctl.g >> 6) & 0x3;
|
||||
|
||||
if (dispmode == 1)
|
||||
{
|
||||
uint eva = ctl.b & 0x1F;
|
||||
uint evb = (ctl.b >> 5) | ((ctl.a & 0x03) << 3);
|
||||
uint evy = ctl.a >> 2;
|
||||
|
||||
uvec4 top = pixel;
|
||||
uvec4 mid = texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(256,0), 0);
|
||||
uvec4 bot = texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(512,0), 0);
|
||||
|
||||
uint winmask = top.b >> 7;
|
||||
|
||||
if ((top.a & 0x40) != 0)
|
||||
{
|
||||
float xpos = top.r + fract(fTexcoord.x);
|
||||
uvec4 _3dpix = uvec4(texelFetch(_3DTex, ivec2(vec2(xpos, fTexcoord.y)*u3DScale), 0).bgra
|
||||
* vec4(63,63,63,31));
|
||||
|
||||
if (_3dpix.a > 0) { top = _3dpix; top.a |= 0x40; bot = mid; }
|
||||
else top = mid;
|
||||
}
|
||||
else if ((mid.a & 0x40) != 0)
|
||||
{
|
||||
float xpos = mid.r + fract(fTexcoord.x);
|
||||
uvec4 _3dpix = uvec4(texelFetch(_3DTex, ivec2(vec2(xpos, fTexcoord.y)*u3DScale), 0).bgra
|
||||
* vec4(63,63,63,31));
|
||||
|
||||
if (_3dpix.a > 0) { bot = _3dpix; bot.a |= 0x40; }
|
||||
}
|
||||
else
|
||||
{
|
||||
// conditional texture fetch no good for performance, apparently
|
||||
//texelFetch(_3DTex, ivec2(0, fTexcoord.y*2), 0);
|
||||
bot = mid;
|
||||
}
|
||||
|
||||
top.b &= 0x3F;
|
||||
bot.b &= 0x3F;
|
||||
|
||||
uint target2;
|
||||
if ((bot.a & 0x80) != 0) target2 = 0x10;
|
||||
else if ((bot.a & 0x40) != 0) target2 = 0x01;
|
||||
else target2 = bot.a;
|
||||
bool t2pass = ((ctl.g & target2) != 0);
|
||||
|
||||
uint coloreffect = 0;
|
||||
|
||||
if ((top.a & 0x80) != 0 && t2pass)
|
||||
{
|
||||
// sprite blending
|
||||
|
||||
coloreffect = 1;
|
||||
|
||||
if ((top.a & 0x40) != 0)
|
||||
{
|
||||
eva = top.a & 0x1F;
|
||||
evb = 16 - eva;
|
||||
}
|
||||
}
|
||||
else if ((top.a & 0x40) != 0 && t2pass)
|
||||
{
|
||||
// 3D layer blending
|
||||
|
||||
coloreffect = 4;
|
||||
eva = (top.a & 0x1F) + 1;
|
||||
evb = 32 - eva;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((top.a & 0x80) != 0) top.a = 0x10;
|
||||
else if ((top.a & 0x40) != 0) top.a = 0x01;
|
||||
|
||||
if ((ctl.r & top.a) != 0 && winmask != 0)
|
||||
{
|
||||
uint effect = ctl.r >> 6;
|
||||
if ((effect != 1) || t2pass) coloreffect = effect;
|
||||
}
|
||||
}
|
||||
|
||||
if (coloreffect == 0)
|
||||
{
|
||||
pixel = top;
|
||||
}
|
||||
else if (coloreffect == 1)
|
||||
{
|
||||
pixel = ((top * eva) + (bot * evb)) >> 4;
|
||||
pixel = min(pixel, 0x3F);
|
||||
}
|
||||
else if (coloreffect == 2)
|
||||
{
|
||||
pixel = top;
|
||||
pixel += ((uvec4(0x3F,0x3F,0x3F,0) - pixel) * evy) >> 4;
|
||||
}
|
||||
else if (coloreffect == 3)
|
||||
{
|
||||
pixel = top;
|
||||
pixel -= (pixel * evy) >> 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
pixel = ((top * eva) + (bot * evb)) >> 5;
|
||||
if (eva <= 16) pixel += uvec4(1,1,1,0);
|
||||
pixel = min(pixel, 0x3F);
|
||||
}
|
||||
}
|
||||
|
||||
pixel.rgb <<= 2;
|
||||
pixel.rgb |= (pixel.rgb >> 6);
|
||||
|
||||
// TODO: filters
|
||||
|
||||
oColor = vec4(vec3(pixel.bgr) / 255.0, 1.0);
|
||||
oColor = vec4(vec3(pixel.rgb) / 255.0, 1.0);
|
||||
//oColor = texelFetch(_3DTex, ivec2(fTexcoord*4), 0).bgra;
|
||||
}
|
||||
)";
|
||||
|
||||
|
Reference in New Issue
Block a user