Skip to content

Commit 90b9e8b

Browse files
committed
Merge branch 'clean' into main
2 parents cf05179 + bb34f53 commit 90b9e8b

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

vice/data/GLSL/viewport.vert

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
uniform vec4 scale;
44
uniform vec2 view_size;
55

6+
uniform mat4 rotation;
7+
68
in vec4 position;
79
in vec2 tex;
810

911
out vec2 tex_coord;
1012

1113
void main() {
12-
gl_Position = position * scale;
14+
gl_Position = position * scale * rotation;
1315
tex_coord = (tex * (view_size - 1.0) + 0.5) / view_size;
14-
}
16+
}

vice/src/arch/gtk3/opengl_renderer.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static GLuint create_shader_program(char *vertex_shader_filename, char *fragment
8484
* entire display area, and the last eight assign texture coordinates
8585
* to each corner.
8686
*/
87-
static float vertexData[] = {
87+
static float vertexData[16 + 8] = {
8888
-1.0f, -1.0f, 0.0f, 1.0f,
8989
1.0f, -1.0f, 0.0f, 1.0f,
9090
-1.0f, 1.0f, 0.0f, 1.0f,
@@ -103,6 +103,21 @@ static const float vertexDataPatches[4][8] = {
103103
{ 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }, /* flip x & y */
104104
};
105105

106+
static const float model_matrix[2][16] = {
107+
{ /* ident, no rotation */
108+
1.0f, 0.0f, 0.0f, 0.0f,
109+
0.0f, 1.0f, 0.0f, 0.0f,
110+
0.0f, 0.0f, 1.0f, 0.0f,
111+
0.0f, 0.0f, 0.0f, 1.0f
112+
}, {
113+
/* rotated 90 degr clockwise */
114+
0.0f, 1.0f, 0.0f, 0.0f,
115+
-1.0f, 0.0f, 0.0f, 0.0f,
116+
0.0f, 0.0f, 1.0f, 0.0f,
117+
0.0f, 0.0f, 0.0f, 1.0f
118+
}
119+
};
120+
106121
/**/
107122

108123
static void vice_opengl_initialise_canvas(video_canvas_t *canvas)
@@ -528,8 +543,6 @@ static void legacy_render(video_canvas_t *canvas, float scale_x, float scale_y)
528543
vice_opengl_renderer_context_t *context = (vice_opengl_renderer_context_t *)canvas->renderer_context;
529544
filter = canvas->videoconfig->glfilter;
530545

531-
/* FIXME: add support for rotate */
532-
533546
/* update texture coords according to flipx/flipy */
534547
flipidx = canvas->videoconfig->flipx | (canvas->videoconfig->flipy << 1);
535548
u1 = vertexDataPatches[flipidx][4];
@@ -545,6 +558,13 @@ static void legacy_render(video_canvas_t *canvas, float scale_x, float scale_y)
545558
glEnable(GL_TEXTURE_2D);
546559
glActiveTexture(GL_TEXTURE0);
547560

561+
/* Save the current matrix. */
562+
glPushMatrix();
563+
564+
if (canvas->videoconfig->rotate) {
565+
glRotatef(270.0f, 0, 0, 1); /* rotate 90degr clockwise */
566+
}
567+
548568
if (context->interlaced) {
549569
glBindTexture(GL_TEXTURE_2D, context->previous_frame_texture);
550570
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter);
@@ -584,6 +604,9 @@ static void legacy_render(video_canvas_t *canvas, float scale_x, float scale_y)
584604

585605
glBindTexture(GL_TEXTURE_2D, 0);
586606
glDisable(GL_TEXTURE_2D);
607+
608+
/* Reset the current matrix to the one that was saved. */
609+
glPopMatrix();
587610
}
588611

589612
static void modern_render(video_canvas_t *canvas, float scale_x, float scale_y)
@@ -602,13 +625,12 @@ static void modern_render(video_canvas_t *canvas, float scale_x, float scale_y)
602625
GLuint view_size_uniform;
603626
GLuint source_size_uniform;
604627
GLuint this_frame_uniform;
628+
GLuint rotation_uniform;
605629
GLuint last_frame_uniform = 0;
606630

607631
vice_opengl_renderer_context_t *context = (vice_opengl_renderer_context_t *)canvas->renderer_context;
608632
filter = canvas->videoconfig->glfilter;
609633

610-
/* FIXME: add support for rotate */
611-
612634
/* update texture coords according to flipx/flipy */
613635
flipidx = canvas->videoconfig->flipx | (canvas->videoconfig->flipy << 1);
614636
if (flipidxlast != flipidx) {
@@ -641,6 +663,7 @@ static void modern_render(video_canvas_t *canvas, float scale_x, float scale_y)
641663
view_size_uniform = glGetUniformLocation(program, "view_size");
642664
source_size_uniform = glGetUniformLocation(program, "source_size");
643665
this_frame_uniform = glGetUniformLocation(program, "this_frame");
666+
rotation_uniform = glGetUniformLocation(program, "rotation");
644667

645668
if (context->interlaced) {
646669
last_frame_uniform = glGetUniformLocation(program, "last_frame");
@@ -665,6 +688,8 @@ static void modern_render(video_canvas_t *canvas, float scale_x, float scale_y)
665688
glUniform2f(view_size_uniform, context->native_view_width, context->native_view_height);
666689
glUniform2f(source_size_uniform, context->current_frame_width, context->current_frame_height);
667690

691+
glUniformMatrix4fv(rotation_uniform, 1, GL_FALSE, model_matrix[canvas->videoconfig->rotate]);
692+
668693
if (context->interlaced) {
669694
glUniform1i(last_frame_uniform, 0);
670695
glUniform1i(this_frame_uniform, 1);
@@ -760,7 +785,12 @@ static void render(void *job_data, void *pool_data)
760785
float viewport_aspect;
761786
float emulated_aspect;
762787

763-
viewport_aspect = (float)context->native_view_width / (float)context->native_view_height;
788+
if (canvas->videoconfig->rotate) {
789+
/* rotate aspect 90 degr too */
790+
viewport_aspect = (float)context->native_view_height / (float)context->native_view_width;
791+
} else {
792+
viewport_aspect = (float)context->native_view_width / (float)context->native_view_height;
793+
}
764794
emulated_aspect = (float)context->current_frame_width / (float)context->current_frame_height;
765795

766796
if (canvas->videoconfig->aspect_mode == VIDEO_ASPECT_MODE_TRUE) {

vice/src/arch/gtk3/widgets/canvasrendermirrorwidget.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ GtkWidget *canvas_render_mirror_widget_create(const char *chip)
8181
"Rotate 90\u00b0",
8282
chip);
8383
/* grey out rotate option, remove this once it's implemented in the renderer */
84+
#ifdef WINDOWS_COMPILE
8485
gtk_widget_set_sensitive(rotate, 0);
85-
86+
#endif
8687
gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1);
8788
gtk_grid_attach(GTK_GRID(grid), flip_x, 0, 1, 1, 1);
8889
gtk_grid_attach(GTK_GRID(grid), flip_y, 0, 2, 1, 1);

0 commit comments

Comments
 (0)