+#define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
+static void Upload(vout_display_opengl_t *vgl, int in_width, int in_height,
+ int in_full_width, int in_full_height,
+ int w_num, int w_den, int h_num, int h_den,
+ int pitch, int pixel_pitch,
+ int full_upload, const uint8_t *pixels,
+ int tex_target, int tex_format, int tex_type)
+{
+ int width = in_width * w_num / w_den;
+ int full_width = in_full_width * w_num / w_den;
+ int height = in_height * h_num / h_den;
+ int full_height = in_full_height * h_num / h_den;
+ // This unpack alignment is the default, but setting it just in case.
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+#ifndef GL_UNPACK_ROW_LENGTH
+ int dst_width = full_upload ? full_width : width;
+ int dst_pitch = ALIGN(dst_width * pixel_pitch, 4);
+ if ( pitch != dst_pitch )
+ {
+ int buf_size = dst_pitch * full_height * pixel_pitch;
+ const uint8_t *source = pixels;
+ uint8_t *destination;
+ if( !vgl->texture_temp_buf || vgl->texture_temp_buf_size < buf_size )
+ {
+ free( vgl->texture_temp_buf );
+ vgl->texture_temp_buf = xmalloc( buf_size );
+ vgl->texture_temp_buf_size = buf_size;
+ }
+ destination = vgl->texture_temp_buf;
+
+ for( int h = 0; h < height ; h++ )
+ {
+ memcpy( destination, source, width * pixel_pitch );
+ source += pitch;
+ destination += dst_pitch;
+ }
+ if (full_upload)
+ glTexImage2D( tex_target, 0, tex_format,
+ full_width, full_height,
+ 0, tex_format, tex_type, vgl->texture_temp_buf );
+ else
+ glTexSubImage2D( tex_target, 0,
+ 0, 0,
+ width, height,
+ tex_format, tex_type, vgl->texture_temp_buf );
+ } else {
+#else
+ (void) width;
+ (void) height;
+ (void) vgl;
+ {
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / pixel_pitch);
+#endif
+ if (full_upload)
+ glTexImage2D(tex_target, 0, tex_format,
+ full_width, full_height,
+ 0, tex_format, tex_type, pixels);
+ else
+ glTexSubImage2D(tex_target, 0,
+ 0, 0,
+ width, height,
+ tex_format, tex_type, pixels);
+ }
+}
+