diff --git a/src/platform/opengl/gl.c b/src/platform/opengl/gl.c index 832e78cee..ec477b954 100644 --- a/src/platform/opengl/gl.c +++ b/src/platform/opengl/gl.c @@ -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); diff --git a/src/platform/opengl/gles2.c b/src/platform/opengl/gles2.c index a2d0b6e50..2beea3a78 100644 --- a/src/platform/opengl/gles2.c +++ b/src/platform/opengl/gles2.c @@ -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); } diff --git a/src/platform/opengl/gles2.h b/src/platform/opengl/gles2.h index dc15041d9..c81e9d8e2 100644 --- a/src/platform/opengl/gles2.h +++ b/src/platform/opengl/gles2.h @@ -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; diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index ca35c6bb6..1913dc27c 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -696,25 +696,19 @@ void PainterGL::recenterLayers() { if (!m_context) { return; } - const static std::initializer_list centeredLayers{VIDEO_LAYER_BACKGROUND, VIDEO_LAYER_IMAGE}; + const static std::initializer_list 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); } diff --git a/src/platform/sdl/gl-common.c b/src/platform/sdl/gl-common.c index f62e04a6b..076429f6b 100644 --- a/src/platform/sdl/gl-common.c +++ b/src/platform/sdl/gl-common.c @@ -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);