@@ -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
108123static 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
589612static 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 ) {
0 commit comments