mirror of
https://github.com/libretro/ppsspp.git
synced 2024-12-01 04:10:30 +00:00
Make DrawActiveTexture more flexible (u/v origin too).
This commit is contained in:
parent
3b3c794a37
commit
3c2819afea
@ -466,9 +466,9 @@ void FramebufferManager::DrawPixels(const u8 *framebuf, GEBufferFormat pixelForm
|
||||
// Should try to unify this path with the regular path somehow, but this simple solution works for most of the post shaders
|
||||
// (it always runs at output resolution so FXAA may look odd).
|
||||
if (applyPostShader && usePostShader_ && g_Config.iRenderingMode != FB_NON_BUFFERED_MODE) {
|
||||
DrawActiveTexture(0, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, false, 480.0f / 512.0f, 1.0f, postShaderProgram_);
|
||||
DrawActiveTexture(0, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, false, 0.0f, 0.0f, 480.0f / 512.0f, 1.0f, postShaderProgram_);
|
||||
} else {
|
||||
DrawActiveTexture(0, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, false, 480.0f / 512.0f);
|
||||
DrawActiveTexture(0, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, false, 0.0f, 0.0f, 480.0f / 512.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -509,26 +509,24 @@ void FramebufferManager::DrawPlainColor(u32 color) {
|
||||
}
|
||||
|
||||
// x, y, w, h are relative coordinates against destW/destH, which is not very intuitive.
|
||||
void FramebufferManager::DrawActiveTexture(GLuint texture, float x, float y, float w, float h, float destW, float destH, bool flip, float uscale, float vscale, GLSLProgram *program) {
|
||||
float u2 = uscale;
|
||||
// Since we're flipping, 0 is down. That's where the scale goes.
|
||||
float v1 = flip ? 1.0f : 1.0f - vscale;
|
||||
float v2 = flip ? 1.0f - vscale : 1.0f;
|
||||
|
||||
const float u1 = 0.0f;
|
||||
const float texCoords[8] = {u1,v1, u2,v1, u2,v2, u1,v2};
|
||||
void FramebufferManager::DrawActiveTexture(GLuint texture, float x, float y, float w, float h, float destW, float destH, bool flip, float u0, float v0, float u1, float v1, GLSLProgram *program) {
|
||||
if (flip) {
|
||||
std::swap(v0, v1);
|
||||
}
|
||||
const float texCoords[8] = {u0,v0, u1,v0, u1,v1, u0,v1};
|
||||
static const GLushort indices[4] = {0,1,3,2};
|
||||
|
||||
if (texture) {
|
||||
// We know the texture, we can do a DrawTexture shortcut on nvidia.
|
||||
#if !defined(__SYMBIAN32__) && !defined(MEEGO_EDITION_HARMATTAN) && !defined(IOS) && !defined(BLACKBERRY) && !defined(MAEMO)
|
||||
// Don't remember why I disabled this - no win?
|
||||
if (false && gl_extensions.NV_draw_texture && !program) {
|
||||
// Fast path for Tegra. TODO: Make this path work on desktop nvidia, seems GLEW doesn't have a clue.
|
||||
// Actually, on Desktop we should just use glBlitFramebuffer - although we take a texture here
|
||||
// so that's a little gnarly, will have to modify all callers.
|
||||
glDrawTextureNV(texture, 0,
|
||||
x, y, w, h, 0.0f,
|
||||
u1, v2, u2, v1);
|
||||
u0, v1, u1, v0);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@ -543,9 +541,11 @@ void FramebufferManager::DrawActiveTexture(GLuint texture, float x, float y, flo
|
||||
x,y+h,0
|
||||
};
|
||||
|
||||
float invDestW = 1.0f / (destW * 0.5f);
|
||||
float invDestH = 1.0f / (destH * 0.5f);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
pos[i * 3] = pos[i * 3] / (destW * 0.5) - 1.0f;
|
||||
pos[i * 3 + 1] = -(pos[i * 3 + 1] / (destH * 0.5) - 1.0f);
|
||||
pos[i * 3] = pos[i * 3] * invDestW - 1.0f;
|
||||
pos[i * 3 + 1] = -(pos[i * 3 + 1] * invDestH - 1.0f);
|
||||
}
|
||||
|
||||
if (!program) {
|
||||
@ -1086,14 +1086,14 @@ void FramebufferManager::CopyDisplayToOutput() {
|
||||
if (!usePostShader_) {
|
||||
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
|
||||
// These are in the output display coordinates
|
||||
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height);
|
||||
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 0.0f, 0.0f, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height);
|
||||
} else if (usePostShader_ && extraFBOs_.size() == 1 && !postShaderAtOutputResolution_) {
|
||||
// An additional pass, post-processing shader to the extra FBO.
|
||||
fbo_bind_as_render_target(extraFBOs_[0]);
|
||||
int fbo_w, fbo_h;
|
||||
fbo_get_dimensions(extraFBOs_[0], &fbo_w, &fbo_h);
|
||||
glstate.viewport.set(0, 0, fbo_w, fbo_h);
|
||||
DrawActiveTexture(colorTexture, 0, 0, fbo_w, fbo_h, fbo_w, fbo_h, true, 1.0f, 1.0f, postShaderProgram_);
|
||||
DrawActiveTexture(colorTexture, 0, 0, fbo_w, fbo_h, fbo_w, fbo_h, true, 0.0f, 0.0f, 1.0f, 1.0f, postShaderProgram_);
|
||||
|
||||
fbo_unbind();
|
||||
|
||||
@ -1106,12 +1106,12 @@ void FramebufferManager::CopyDisplayToOutput() {
|
||||
colorTexture = fbo_get_color_texture(extraFBOs_[0]);
|
||||
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
|
||||
// These are in the output display coordinates
|
||||
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height);
|
||||
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 0.0f, 0.0f, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height);
|
||||
} else {
|
||||
// Use post-shader, but run shader at output resolution.
|
||||
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
|
||||
// These are in the output display coordinates
|
||||
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height, postShaderProgram_);
|
||||
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 0.0f, 0.0f, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height, postShaderProgram_);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
@ -1273,7 +1273,7 @@ void FramebufferManager::BlitFramebuffer_(VirtualFramebuffer *src, VirtualFrameb
|
||||
float y = 0.0f;
|
||||
float w = 480.0f;
|
||||
float h = 272.0f;
|
||||
DrawActiveTexture(0, x, y, w, h, 480.0f, 272.0f, false, 1.0f, 1.0f, draw2dprogram_);
|
||||
DrawActiveTexture(0, x, y, w, h, 480.0f, 272.0f, false, 0.0f, 0.0f, 1.0f, 1.0f, draw2dprogram_);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
fbo_unbind();
|
||||
|
@ -127,7 +127,8 @@ public:
|
||||
void DrawPixels(const u8 *framebuf, GEBufferFormat pixelFormat, int linesize, bool applyPostShader = false);
|
||||
|
||||
// If texture != 0, will bind it.
|
||||
void DrawActiveTexture(GLuint texture, float x, float y, float w, float h, float destW, float destH, bool flip = false, float uscale = 1.0f, float vscale = 1.0f, GLSLProgram *program = 0);
|
||||
// x,y,w,h are relative to destW, destH which fill out the target completely.
|
||||
void DrawActiveTexture(GLuint texture, float x, float y, float w, float h, float destW, float destH, bool flip = false, float u0 = 0.0f, float v0 = 0.0f, float u1 = 1.0f, float v1 = 1.0f, GLSLProgram *program = 0);
|
||||
|
||||
void DrawPlainColor(u32 color);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user