@@ -366,10 +366,10 @@ struct gl_vertex_attribs_definition {
366
366
};
367
367
368
368
static const struct gl_vertex_attribs_definition gl_blit_vertex_attribs = {
369
- .stride = sizeof (GLint ) * 4 ,
369
+ .stride = sizeof (GLfloat ) * 4 ,
370
370
.count = 2 ,
371
- .attribs = {{GL_INT , vert_coord_loc , NULL },
372
- {GL_INT , vert_in_texcoord_loc , ((GLint * )NULL ) + 2 }},
371
+ .attribs = {{GL_FLOAT , vert_coord_loc , NULL },
372
+ {GL_FLOAT , vert_in_texcoord_loc , ((GLfloat * )NULL ) + 2 }},
373
373
};
374
374
375
375
/**
@@ -384,7 +384,7 @@ static const struct gl_vertex_attribs_definition gl_blit_vertex_attribs = {
384
384
* @param nuniforms number of uniforms for `shader`
385
385
* @param uniforms uniforms for `shader`
386
386
*/
387
- static void gl_blit_inner (GLuint target_fbo , int nrects , GLint * coord , GLuint * indices ,
387
+ static void gl_blit_inner (GLuint target_fbo , int nrects , GLfloat * coord , GLuint * indices ,
388
388
const struct gl_vertex_attribs_definition * vert_attribs ,
389
389
const struct gl_shader * shader , int nuniforms ,
390
390
struct gl_uniform_value * uniforms ) {
@@ -475,26 +475,29 @@ static void gl_blit_inner(GLuint target_fbo, int nrects, GLint *coord, GLuint *i
475
475
gl_check_err ();
476
476
}
477
477
478
- void gl_mask_rects_to_coords (ivec2 origin , int nrects , const rect_t * rects , GLint * coord ,
479
- GLuint * indices ) {
478
+ void gl_mask_rects_to_coords (ivec2 origin , int nrects , const rect_t * rects , vec2 scale ,
479
+ GLfloat * coord , GLuint * indices ) {
480
480
for (ptrdiff_t i = 0 ; i < nrects ; i ++ ) {
481
481
// Rectangle in source image coordinates
482
482
rect_t rect_src = region_translate_rect (rects [i ], ivec2_neg (origin ));
483
483
// Rectangle in target image coordinates
484
484
rect_t rect_dst = rects [i ];
485
485
486
+ // clang-format off
486
487
memcpy (& coord [i * 16 ],
487
- ((GLint [][2 ]){
488
- {rect_dst .x1 , rect_dst .y1 }, // Vertex, bottom-left
489
- {rect_src .x1 , rect_src .y1 }, // Texture
490
- {rect_dst .x2 , rect_dst .y1 }, // Vertex, bottom-right
491
- {rect_src .x2 , rect_src .y1 }, // Texture
492
- {rect_dst .x2 , rect_dst .y2 }, // Vertex, top-right
493
- {rect_src .x2 , rect_src .y2 }, // Texture
494
- {rect_dst .x1 , rect_dst .y2 }, // Vertex, top-left
495
- {rect_src .x1 , rect_src .y2 }, // Texture
488
+ ((GLfloat [][2 ]){
489
+ // Interleaved vertex and texture coordinates, starting with vertex.
490
+ {(GLfloat )rect_dst .x1 , (GLfloat )rect_dst .y1 }, // bottom-left
491
+ {(GLfloat )(rect_src .x1 / scale .x ), (GLfloat )(rect_src .y1 / scale .y )},
492
+ {(GLfloat )rect_dst .x2 , (GLfloat )rect_dst .y1 }, // bottom-right
493
+ {(GLfloat )(rect_src .x2 / scale .x ), (GLfloat )(rect_src .y1 / scale .y )},
494
+ {(GLfloat )rect_dst .x2 , (GLfloat )rect_dst .y2 }, // top-right
495
+ {(GLfloat )(rect_src .x2 / scale .x ), (GLfloat )(rect_src .y2 / scale .y )},
496
+ {(GLfloat )rect_dst .x1 , (GLfloat )rect_dst .y2 }, // top-left
497
+ {(GLfloat )(rect_src .x1 / scale .x ), (GLfloat )(rect_src .y2 / scale .y )},
496
498
}),
497
499
sizeof (GLint [2 ]) * 8 );
500
+ // clang-format on
498
501
499
502
GLuint u = (GLuint )(i * 4 );
500
503
memcpy (& indices [i * 6 ],
@@ -509,13 +512,13 @@ void gl_mask_rects_to_coords(ivec2 origin, int nrects, const rect_t *rects, GLin
509
512
/// @param[in] nrects number of rectangles
510
513
/// @param[in] coord OpenGL vertex coordinates
511
514
/// @param[in] texture_height height of the source image
512
- static inline void gl_y_flip_texture (int nrects , GLint * coord , GLint texture_height ) {
515
+ static inline void gl_y_flip_texture (int nrects , GLfloat * coord , GLint texture_height ) {
513
516
for (ptrdiff_t i = 0 ; i < nrects ; i ++ ) {
514
517
auto current_rect = & coord [i * 16 ]; // 16 numbers per rectangle
515
518
for (ptrdiff_t j = 0 ; j < 4 ; j ++ ) {
516
519
// 4 numbers per vertex, texture coordinates are the last two
517
520
auto current_vertex = & current_rect [j * 4 + 2 ];
518
- current_vertex [1 ] = texture_height - current_vertex [1 ];
521
+ current_vertex [1 ] = ( GLfloat ) texture_height - current_vertex [1 ];
519
522
}
520
523
}
521
524
}
@@ -524,7 +527,7 @@ static inline void gl_y_flip_texture(int nrects, GLint *coord, GLint texture_hei
524
527
/// shader, and uniforms.
525
528
static int
526
529
gl_lower_blit_args (struct gl_data * gd , ivec2 origin , const struct backend_blit_args * args ,
527
- GLint * * coord , GLuint * * indices , struct gl_shader * * shader ,
530
+ GLfloat * * coord , GLuint * * indices , struct gl_shader * * shader ,
528
531
struct gl_uniform_value * uniforms ) {
529
532
auto img = (struct gl_texture * )args -> source_image ;
530
533
int nrects ;
@@ -534,9 +537,9 @@ gl_lower_blit_args(struct gl_data *gd, ivec2 origin, const struct backend_blit_a
534
537
// Nothing to paint
535
538
return 0 ;
536
539
}
537
- * coord = ccalloc (nrects * 16 , GLint );
540
+ * coord = ccalloc (nrects * 16 , GLfloat );
538
541
* indices = ccalloc (nrects * 6 , GLuint );
539
- gl_mask_rects_to_coords (origin , nrects , rects , * coord , * indices );
542
+ gl_mask_rects_to_coords (origin , nrects , rects , args -> scale , * coord , * indices );
540
543
if (!img -> y_inverted ) {
541
544
gl_y_flip_texture (nrects , * coord , img -> height );
542
545
}
@@ -558,11 +561,13 @@ gl_lower_blit_args(struct gl_data *gd, ivec2 origin, const struct backend_blit_a
558
561
border_width = 0 ;
559
562
}
560
563
// clang-format off
564
+ auto tex_sampler = vec2_eq (args -> scale , SCALE_IDENTITY ) ?
565
+ gd -> samplers [GL_SAMPLER_REPEAT ] : gd -> samplers [GL_SAMPLER_REPEAT_SCALE ];
561
566
struct gl_uniform_value from_uniforms [] = {
562
567
[UNIFORM_OPACITY_LOC ] = {.type = GL_FLOAT , .f = (float )args -> opacity },
563
568
[UNIFORM_INVERT_COLOR_LOC ] = {.type = GL_INT , .i = args -> color_inverted },
564
569
[UNIFORM_TEX_LOC ] = {.type = GL_TEXTURE_2D ,
565
- .tu = {img -> texture , gd -> samplers [ GL_SAMPLER_REPEAT ] }},
570
+ .tu = {img -> texture , tex_sampler }},
566
571
[UNIFORM_EFFECTIVE_SIZE_LOC ] = {.type = GL_FLOAT_VEC2 ,
567
572
.f2 = {(float )args -> effective_size .width ,
568
573
(float )args -> effective_size .height }},
@@ -613,7 +618,7 @@ bool gl_blit(backend_t *base, ivec2 origin, image_handle target_,
613
618
return false;
614
619
}
615
620
616
- GLint * coord ;
621
+ GLfloat * coord ;
617
622
GLuint * indices ;
618
623
struct gl_shader * shader ;
619
624
struct gl_uniform_value uniforms [NUMBER_OF_UNIFORMS ] = {};
@@ -678,9 +683,9 @@ static bool gl_copy_area_draw(struct gl_data *gd, ivec2 origin,
678
683
return true;
679
684
}
680
685
681
- auto coord = ccalloc (16 * nrects , GLint );
686
+ auto coord = ccalloc (16 * nrects , GLfloat );
682
687
auto indices = ccalloc (6 * nrects , GLuint );
683
- gl_mask_rects_to_coords (origin , nrects , rects , coord , indices );
688
+ gl_mask_rects_to_coords (origin , nrects , rects , SCALE_IDENTITY , coord , indices );
684
689
if (!target -> y_inverted ) {
685
690
gl_y_flip_target (nrects , coord , target -> height );
686
691
}
@@ -856,6 +861,17 @@ uint64_t gl_get_shader_attributes(backend_t *backend_data attr_unused, void *sha
856
861
return ret ;
857
862
}
858
863
864
+ static const struct {
865
+ GLint filter ;
866
+ GLint wrap ;
867
+ } gl_sampler_params [] = {
868
+ [GL_SAMPLER_REPEAT ] = {GL_NEAREST , GL_REPEAT },
869
+ [GL_SAMPLER_REPEAT_SCALE ] = {GL_LINEAR , GL_REPEAT },
870
+ [GL_SAMPLER_BLUR ] = {GL_LINEAR , GL_CLAMP_TO_EDGE },
871
+ [GL_SAMPLER_EDGE ] = {GL_NEAREST , GL_CLAMP_TO_EDGE },
872
+ [GL_SAMPLER_BORDER ] = {GL_NEAREST , GL_CLAMP_TO_BORDER },
873
+ };
874
+
859
875
bool gl_init (struct gl_data * gd , session_t * ps ) {
860
876
if (!epoxy_has_gl_extension ("GL_ARB_explicit_uniform_location" )) {
861
877
log_error ("GL_ARB_explicit_uniform_location support is required but "
@@ -965,20 +981,16 @@ bool gl_init(struct gl_data *gd, session_t *ps) {
965
981
gd -> back_image .height = ps -> root_height ;
966
982
967
983
glGenSamplers (GL_MAX_SAMPLERS , gd -> samplers );
968
- for (int i = 0 ; i < GL_MAX_SAMPLERS ; i ++ ) {
969
- glSamplerParameteri (gd -> samplers [i ], GL_TEXTURE_MIN_FILTER , GL_NEAREST );
970
- glSamplerParameteri (gd -> samplers [i ], GL_TEXTURE_MAG_FILTER , GL_NEAREST );
971
- }
972
- glSamplerParameterf (gd -> samplers [GL_SAMPLER_EDGE ], GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE );
973
- glSamplerParameterf (gd -> samplers [GL_SAMPLER_EDGE ], GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE );
974
- glSamplerParameterf (gd -> samplers [GL_SAMPLER_BLUR ], GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE );
975
- glSamplerParameterf (gd -> samplers [GL_SAMPLER_BLUR ], GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE );
976
- glSamplerParameterf (gd -> samplers [GL_SAMPLER_BLUR ], GL_TEXTURE_MIN_FILTER , GL_LINEAR );
977
- glSamplerParameterf (gd -> samplers [GL_SAMPLER_BLUR ], GL_TEXTURE_MAG_FILTER , GL_LINEAR );
978
- glSamplerParameterf (gd -> samplers [GL_SAMPLER_BORDER ], GL_TEXTURE_WRAP_S ,
979
- GL_CLAMP_TO_BORDER );
980
- glSamplerParameterf (gd -> samplers [GL_SAMPLER_BORDER ], GL_TEXTURE_WRAP_T ,
981
- GL_CLAMP_TO_BORDER );
984
+ for (size_t i = 0 ; i < ARR_SIZE (gl_sampler_params ); i ++ ) {
985
+ glSamplerParameteri (gd -> samplers [i ], GL_TEXTURE_MIN_FILTER ,
986
+ gl_sampler_params [i ].filter );
987
+ glSamplerParameteri (gd -> samplers [i ], GL_TEXTURE_MAG_FILTER ,
988
+ gl_sampler_params [i ].filter );
989
+ glSamplerParameteri (gd -> samplers [i ], GL_TEXTURE_WRAP_S ,
990
+ gl_sampler_params [i ].wrap );
991
+ glSamplerParameteri (gd -> samplers [i ], GL_TEXTURE_WRAP_T ,
992
+ gl_sampler_params [i ].wrap );
993
+ }
982
994
983
995
gd -> logger = gl_string_marker_logger_new ();
984
996
if (gd -> logger ) {
@@ -1100,9 +1112,9 @@ image_handle gl_new_image(backend_t *backend_data attr_unused,
1100
1112
bool gl_apply_alpha (backend_t * base , image_handle target , double alpha , const region_t * reg_op ) {
1101
1113
auto gd = (struct gl_data * )base ;
1102
1114
static const struct gl_vertex_attribs_definition vertex_attribs = {
1103
- .stride = sizeof (GLint ) * 4 ,
1115
+ .stride = sizeof (GLfloat ) * 4 ,
1104
1116
.count = 1 ,
1105
- .attribs = {{GL_INT , vert_coord_loc , NULL }},
1117
+ .attribs = {{GL_FLOAT , vert_coord_loc , NULL }},
1106
1118
};
1107
1119
if (alpha == 1.0 || !pixman_region32_not_empty (reg_op )) {
1108
1120
return true;
@@ -1115,7 +1127,7 @@ bool gl_apply_alpha(backend_t *base, image_handle target, double alpha, const re
1115
1127
int nrects ;
1116
1128
const rect_t * rect = pixman_region32_rectangles (reg_op , & nrects );
1117
1129
1118
- auto coord = ccalloc (nrects * 16 , GLint );
1130
+ auto coord = ccalloc (nrects * 16 , GLfloat );
1119
1131
auto indices = ccalloc (nrects * 6 , GLuint );
1120
1132
1121
1133
struct gl_uniform_value uniforms [] = {
0 commit comments