Revision: 45778
http://sourceforge.net/p/vice-emu/code/45778
Author: gpz
Date: 2025-09-20 17:25:52 +0000 (Sat, 20 Sep 2025)
Log Message:
-----------
implement support for flipx/flipy in the open-gl renderer for gtk
Modified Paths:
--------------
trunk/vice/src/arch/gtk3/directx_renderer_impl.cc
trunk/vice/src/arch/gtk3/opengl_renderer.c
trunk/vice/src/arch/gtk3/opengl_renderer_unix.c
trunk/vice/src/arch/gtk3/widgets/canvasrendermirrorwidget.c
Modified: trunk/vice/src/arch/gtk3/directx_renderer_impl.cc
===================================================================
--- trunk/vice/src/arch/gtk3/directx_renderer_impl.cc 2025-09-18 16:49:44 UTC (rev 45777)
+++ trunk/vice/src/arch/gtk3/directx_renderer_impl.cc 2025-09-20 17:25:52 UTC (rev 45778)
@@ -236,14 +236,14 @@
if (!context->d3d_swap_chain) {
DXGI_SWAP_CHAIN_DESC1 swap_chain_desc = { 0 };
- swap_chain_desc.Width = 0; // use automatic sizing
+ swap_chain_desc.Width = 0; /* use automatic sizing */
swap_chain_desc.Height = 0;
- swap_chain_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // this is the most common swapchain format
+ swap_chain_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; /* this is the most common swapchain format */
swap_chain_desc.Stereo = false;
- swap_chain_desc.SampleDesc.Count = 1; // don't use multi-sampling
+ swap_chain_desc.SampleDesc.Count = 1; /* don't use multi-sampling */
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
- swap_chain_desc.BufferCount = 2; // use double buffering to enable flip
+ swap_chain_desc.BufferCount = 2; /* use double buffering to enable flip */
swap_chain_desc.Scaling = DXGI_SCALING_STRETCH;
swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swap_chain_desc.Flags = 0;
@@ -264,7 +264,7 @@
return;
}
- // Ensure that DXGI doesn't queue more than one frame at a time.
+ /* Ensure that DXGI doesn't queue more than one frame at a time. */
context->dxgi_device->SetMaximumFrameLatency(1);
}
@@ -387,8 +387,7 @@
bitmap_properies,
&context->render_bitmap);
- if (FAILED(result))
- {
+ if (FAILED(result)) {
vice_directx_impl_log_windows_error("CreateBitmap1");
return;
}
Modified: trunk/vice/src/arch/gtk3/opengl_renderer.c
===================================================================
--- trunk/vice/src/arch/gtk3/opengl_renderer.c 2025-09-18 16:49:44 UTC (rev 45777)
+++ trunk/vice/src/arch/gtk3/opengl_renderer.c 2025-09-20 17:25:52 UTC (rev 45778)
@@ -89,35 +89,20 @@
1.0f, -1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f,
-/* normal */
+ /* normal */
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f
-#if 0
-/* xflip */
- 1.0f, 1.0f,
- 0.0f, 1.0f,
- 1.0f, 0.0f,
- 0.0f, 0.0f,
-/* yflip */
- 0.0f, 0.0f,
- 1.0f, 0.0f,
- 0.0f, 1.0f,
- 1.0f, 1.0f,
-/* xyflip (180 degr rot) */
- 1.0f, 0.0f,
- 0.0f, 0.0f,
- 1.0f, 1.0f,
- 0.0f, 1.0f,
-/* 90 degr rot */
- 1.0f, 1.0f,
- 1.0f, 0.0f,
- 0.0f, 1.0f,
- 0.0f, 0.0f,
-#endif
};
+static const float vertexDataPatches[4][8] = {
+ { 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f }, /* normal */
+ { 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f }, /* flip x */
+ { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,}, /* flip y */
+ { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }, /* flip x & y */
+};
+
/**/
static void vice_opengl_initialise_canvas(video_canvas_t *canvas)
@@ -197,7 +182,12 @@
glGenBuffers(1, &context->vbo);
glBindBuffer(GL_ARRAY_BUFFER, context->vbo);
+#if 0
+ /* FIXME: we should really do flipx/flipy in the shader instead */
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);
+#else
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_DYNAMIC_DRAW);
+#endif
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenVertexArrays(1, &context->vao);
}
@@ -217,7 +207,6 @@
/* Due to the weird inverted native co-ordinates on macOS, we also need to layout when the window size changes */
g_signal_connect_unlocked(gtk_widget_get_toplevel(canvas->event_box), "size-allocate", G_CALLBACK(on_top_level_widget_resized), canvas);
#endif
-
CANVAS_UNLOCK();
}
@@ -529,17 +518,25 @@
int filter;
GLuint gl_filter;
+ int flipidx;
- float u1 = 0.0f;
- float v1 = 0.0f;
- float u2 = 1.0f;
- float v2 = 1.0f;
+ float u1;
+ float v1;
+ float u2;
+ float v2;
vice_opengl_renderer_context_t *context = (vice_opengl_renderer_context_t *)canvas->renderer_context;
filter = canvas->videoconfig->glfilter;
- /* FIXME: add support for flipx/flipy/rotate */
+ /* FIXME: add support for rotate */
+ /* update texture coords according to flipx/flipy */
+ flipidx = canvas->videoconfig->flipx | (canvas->videoconfig->flipy << 1);
+ u1 = vertexDataPatches[flipidx][4];
+ v1 = vertexDataPatches[flipidx][5];
+ u2 = vertexDataPatches[flipidx][2];
+ v2 = vertexDataPatches[flipidx][3];
+
/* We only support builtin linear and nearest on legacy OpenGL contexts */
gl_filter = filter ? GL_LINEAR : GL_NEAREST;
@@ -594,6 +591,8 @@
/* Used when OpenGL 3.2+ is available */
int filter;
+ int flipidx;
+ static int flipidxlast;
GLint gl_filter;
GLuint program;
@@ -608,8 +607,14 @@
vice_opengl_renderer_context_t *context = (vice_opengl_renderer_context_t *)canvas->renderer_context;
filter = canvas->videoconfig->glfilter;
- /* FIXME: add support for flipx/flipy/rotate */
+ /* FIXME: add support for rotate */
+ /* update texture coords according to flipx/flipy */
+ flipidx = canvas->videoconfig->flipx | (canvas->videoconfig->flipy << 1);
+ if (flipidxlast != flipidx) {
+ memcpy(&vertexData[16], &vertexDataPatches[flipidx], sizeof(float) * 8);
+ }
+
/* For shader filters, we start with nearest neighbor. So only use linear if directly requested. */
gl_filter = (filter == VIDEO_GLFILTER_BILINEAR) ? GL_LINEAR : GL_NEAREST;
@@ -644,6 +649,13 @@
glDisable(GL_BLEND);
glBindVertexArray(context->vao);
glBindBuffer(GL_ARRAY_BUFFER, context->vbo);
+
+ if (flipidxlast != flipidx) {
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertexData), vertexData);
+ }
+
+ flipidxlast = flipidx;
+
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(position_attribute, 4, GL_FLOAT, GL_FALSE, 0, 0);
Modified: trunk/vice/src/arch/gtk3/opengl_renderer_unix.c
===================================================================
--- trunk/vice/src/arch/gtk3/opengl_renderer_unix.c 2025-09-18 16:49:44 UTC (rev 45777)
+++ trunk/vice/src/arch/gtk3/opengl_renderer_unix.c 2025-09-20 17:25:52 UTC (rev 45778)
@@ -38,6 +38,9 @@
#include "log.h"
#include "render_queue.h"
+/* for testing, undefine to use legacy renderer even with 3.2+ */
+/*#define FORCE_LEGACY_RENDERER*/
+
extern log_t opengl_log;
#define CANVAS_LOCK() pthread_mutex_lock(context->canvas_lock_ptr)
@@ -179,9 +182,8 @@
* Check for the GLX_ARB_create_context extension string and the function.
* If either is not present, use GLX 1.3 context creation method.
*/
-
if (!isExtensionSupported(glx_extensions, "GLX_ARB_create_context") || !vice_glXCreateContextAttribsARB) {
- /* Legact context -- TODO, actually support using this */
+ /* Legacy context -- TODO, actually support using this */
PFNGLXCREATENEWCONTEXTPROC vice_glXCreateNewContext = (PFNGLXCREATENEWCONTEXTPROC)glXGetProcAddressARB((const GLubyte *)"glXCreateNewContext");
context->gl_context = vice_glXCreateNewContext(context->x_display, framebuffer_config, GLX_RGBA_TYPE, NULL, True);
} else {
@@ -189,7 +191,11 @@
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+#ifdef FORCE_LEGACY_RENDERER
+ GLX_CONTEXT_MINOR_VERSION_ARB, 1,
+#else
GLX_CONTEXT_MINOR_VERSION_ARB, 2,
+#endif
None
};
@@ -225,7 +231,12 @@
vice_opengl_renderer_make_current(context);
glewInit();
+#ifdef FORCE_LEGACY_RENDERER
+ major = 3;
+ minor = 1;
+#else
sscanf((const char *)glGetString(GL_VERSION), "%d.%d", &major, &minor);
+#endif
/* Anything less than OpenGL 3.2 will use the legacy renderer */
context->gl_context_is_legacy = major < 3 || (major == 3 && minor < 2);
Modified: trunk/vice/src/arch/gtk3/widgets/canvasrendermirrorwidget.c
===================================================================
--- trunk/vice/src/arch/gtk3/widgets/canvasrendermirrorwidget.c 2025-09-18 16:49:44 UTC (rev 45777)
+++ trunk/vice/src/arch/gtk3/widgets/canvasrendermirrorwidget.c 2025-09-20 17:25:52 UTC (rev 45778)
@@ -80,10 +80,13 @@
rotate = vice_gtk3_resource_check_button_new_sprintf("%sRotate",
"Rotate 90\u00b0",
chip);
-#if 1
/* grey out the options, remove this once it's implemented in the renderer */
+#if defined(WINDOWS_COMPILE)
+ /* flipx/flipy works on opengl */
gtk_widget_set_sensitive(flip_x, 0);
gtk_widget_set_sensitive(flip_y, 0);
+#endif
+#if 1
gtk_widget_set_sensitive(rotate, 0);
#endif
gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|