Skip to content
Permalink
Browse files

opengl: use horizontal and vertical display ranges

Clip and move display
  • Loading branch information
JaCzekanski committed Sep 25, 2019
1 parent 9f37bdf commit b74a20e0e41dc41f3a7ed2f5bb6f578ba381249e
Showing with 39 additions and 10 deletions.
  1. +9 −5 data/shader/blit.shader
  2. +30 −5 src/renderer/opengl/opengl.cpp
@@ -1,6 +1,8 @@
uniform sampler2D renderBuffer;
uniform vec2 clipLeftTop;
uniform vec2 clipRightBottom;
uniform vec2 iResolution;
uniform vec2 displayHorizontal;
uniform vec2 displayVertical;
uniform bool displayEnabled;

SHARED vec2 fragTexcoord;

@@ -17,10 +19,12 @@ void main() {

#ifdef FRAGMENT_SHADER
void main() {
vec2 pos = vec2(fragTexcoord.x, fragTexcoord.y);
vec2 pos = gl_FragCoord.xy / iResolution;
pos.y = 1. - pos.y;

if (pos.x < clipLeftTop.x || pos.y < clipLeftTop.y ||
pos.x >= clipRightBottom.x || pos.y >= clipRightBottom.y) {
if (!displayEnabled ||
pos.x < displayHorizontal.x || pos.x >= displayHorizontal.y ||
pos.y < displayVertical.x || pos.y >= displayVertical.y) {
outColor = vec4(0.0, 0.0, 0.0, 1.0);
return;
}
@@ -355,11 +355,36 @@ void OpenGL::renderBlit(gpu::GPU* gpu, bool software) {
y = static_cast<int>((height - h) / 2.f);
}

float y2 = static_cast<float>(gpu->displayRangeY2 - gpu->displayRangeY1);
if (gpu->gp1_08.getVerticalResoulution() == 480) y2 *= 2;
// TODO: convert xy to screen space
blitShader->getUniform("clipLeftTop").f(0, 0);
blitShader->getUniform("clipRightBottom").f(1024, gpu->displayAreaStartY + y2);
{
float yOffset = y / static_cast<float>(h); // Compensate for aspect ratio
float xOffset = x / static_cast<float>(w);

float vResolution = gpu->isNtsc() ? 240 : 256;

float displayTop = 0.f;
float displayBottom = (gpu->displayRangeY2 - gpu->displayRangeY1) / vResolution;

// V aligment disabled for now
// int firstLine = gpu->isNtsc() ? (0x88 - 224/2) : (0xA3 - 264/2);
// y -= ((gpu->displayRangeY1 - firstLine) / vResolution) * h;

float hres = gpu->gp1_08.getHorizontalResoulution();
int cyclesPerPixel = ceilf(640 * 4 / hres);

float displayXOffset = (gpu->displayRangeX1 - 0x260) / cyclesPerPixel / hres;

float displayLeft = 0.f;
float displayRight = (gpu->displayRangeX2 - gpu->displayRangeX1) / cyclesPerPixel / hres;

// Move display to right by offset
x += displayXOffset * w;

blitShader->getUniform("iResolution").f(w, h);
blitShader->getUniform("displayHorizontal").f(displayLeft + xOffset, displayRight + xOffset);
blitShader->getUniform("displayVertical").f(displayTop - yOffset, displayBottom - yOffset);
}

blitShader->getUniform("displayEnabled").i(!gpu->displayDisable);

glViewport(x, y, w, h);
blitBuffer->update(bb.size() * sizeof(BlitStruct), bb.data());

0 comments on commit b74a20e

Please sign in to comment.
You can’t perform that action at this time.