OpenGL: Make backends handle non-zero origin outer frame boundaries

This commit is contained in:
Vicki Pfau 2023-04-04 02:04:59 -07:00
parent 45762c8f9f
commit 9920a609e8
5 changed files with 30 additions and 33 deletions

View File

@ -141,13 +141,13 @@ static void _setFilter(struct VideoBackend* v) {
}
}
static void _setFrame(struct mRectangle* dims, int frameW, int frameH) {
static void _setFrame(struct mRectangle* dims, struct mRectangle* frame) {
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glScissor(viewport[0] + dims->x * viewport[2] / frameW,
viewport[1] + dims->y * viewport[3] / frameH,
dims->width * viewport[2] / frameW,
dims->height * viewport[3] / frameH);
glScissor(viewport[0] + (dims->x - frame->x) * viewport[2] / frame->width,
viewport[1] + (dims->y - frame->y) * viewport[3] / frame->height,
dims->width * viewport[2] / frame->width,
dims->height * viewport[3] / frame->height);
glTranslatef(dims->x, dims->y, 0);
glScalef(toPow2(dims->width), toPow2(dims->height), 1);
}
@ -162,9 +162,9 @@ void mGLContextDrawFrame(struct VideoBackend* v) {
glTexCoordPointer(2, GL_INT, 0, _glTexCoords);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
unsigned frameW, frameH;
VideoBackendGetFrameSize(v, &frameW, &frameH);
glOrtho(0, frameW, frameH, 0, 0, 1);
struct mRectangle frame;
VideoBackendGetFrame(v, &frame);
glOrtho(frame.x, frame.x + frame.width, frame.y + frame.height, frame.y, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@ -178,12 +178,12 @@ void mGLContextDrawFrame(struct VideoBackend* v) {
glBindTexture(GL_TEXTURE_2D, context->layers[layer]);
_setFilter(v);
glPushMatrix();
_setFrame(&context->layerDims[layer], frameW, frameH);
_setFrame(&context->layerDims[layer], &frame);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glPopMatrix();
}
_setFrame(&context->layerDims[VIDEO_LAYER_IMAGE], frameW, frameH);
_setFrame(&context->layerDims[VIDEO_LAYER_IMAGE], &frame);
if (v->interframeBlending) {
glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
glBlendColor(1, 1, 1, 0.5);

View File

@ -212,10 +212,9 @@ static void mGLES2ContextSetLayerDimensions(struct VideoBackend* v, enum VideoLa
context->layerDims[layer].x = dims->x;
context->layerDims[layer].y = dims->y;
unsigned newW;
unsigned newH;
VideoBackendGetFrameSize(v, &newW, &newH);
if (newW != context->width || newH != context->height) {
struct mRectangle frame;
VideoBackendGetFrame(v, &frame);
if (frame.width != context->width || frame.height != context->height) {
size_t n;
for (n = 0; n < context->nShaders; ++n) {
if (context->shaders[n].width < 0 || context->shaders[n].height < 0) {
@ -224,9 +223,11 @@ static void mGLES2ContextSetLayerDimensions(struct VideoBackend* v, enum VideoLa
}
context->initialShader.dirty = true;
context->interframeShader.dirty = true;
context->width = newW;
context->height = newH;
context->width = frame.width;
context->height = frame.height;
}
context->x = frame.x;
context->y = frame.y;
}
static void mGLES2ContextLayerDimensions(const struct VideoBackend* v, enum VideoLayer layer, struct mRectangle* dims) {
@ -320,7 +321,7 @@ static void _drawShaderEx(struct mGLES2Context* context, struct mGLES2Shader* sh
}
if (layer >= 0 && layer < VIDEO_LAYER_MAX) {
glViewport(context->layerDims[layer].x, context->layerDims[layer].y, context->layerDims[layer].width, context->layerDims[layer].height);
glViewport(context->layerDims[layer].x - context->x, context->layerDims[layer].y - context->y, context->layerDims[layer].width, context->layerDims[layer].height);
} else {
glViewport(padW, padH, drawW, drawH);
}

View File

@ -84,6 +84,8 @@ struct mGLES2Context {
struct mRectangle layerDims[VIDEO_LAYER_MAX];
struct mSize imageSizes[VIDEO_LAYER_MAX];
int x;
int y;
unsigned width;
unsigned height;

View File

@ -696,25 +696,19 @@ void PainterGL::recenterLayers() {
if (!m_context) {
return;
}
const static std::initializer_list<VideoLayer> centeredLayers{VIDEO_LAYER_BACKGROUND, VIDEO_LAYER_IMAGE};
const static std::initializer_list<VideoLayer> centeredLayers{VIDEO_LAYER_BACKGROUND};
int width, height;
mRectangle frame = {0};
m_backend->imageSize(m_backend, VIDEO_LAYER_IMAGE, &width, &height);
frame.width = width;
frame.height = height;
unsigned scale = std::max(1U, m_context->videoScale());
for (VideoLayer l : centeredLayers) {
mRectangle dims{};
int width, height;
m_backend->imageSize(m_backend, l, &width, &height);
dims.width = width;
dims.height = height;
if (l != VIDEO_LAYER_IMAGE) {
dims.width *= scale;
dims.height *= scale;
m_backend->setLayerDimensions(m_backend, l, &dims);
}
mRectangleUnion(&frame, &dims);
}
for (VideoLayer l : centeredLayers) {
mRectangle dims;
m_backend->layerDimensions(m_backend, l, &dims);
dims.width = width * scale;
dims.height = height * scale;
mRectangleCenter(&frame, &dims);
m_backend->setLayerDimensions(m_backend, l, &dims);
}

View File

@ -137,9 +137,9 @@ void mSDLGLCommonRunloop(struct mSDLRenderer* renderer, void* user) {
renderer->player.windowUpdated = true;
struct mRectangle frame;
VideoBackendGetFrame(v, &frame);
v->layerDimensions(v, VIDEO_LAYER_IMAGE, &frame);
int i;
for (i = 0; i <= VIDEO_LAYER_IMAGE; ++i) {
for (i = 0; i < VIDEO_LAYER_IMAGE; ++i) {
struct mRectangle dims;
v->layerDimensions(v, i, &dims);
mRectangleCenter(&frame, &dims);