Skip to content

Instantly share code, notes, and snippets.

@rygorous
Last active October 26, 2017 00:05
Show Gist options
  • Save rygorous/98a8a45626309e98bc77 to your computer and use it in GitHub Desktop.
Save rygorous/98a8a45626309e98bc77 to your computer and use it in GitHub Desktop.
Scrollable, zoomable 64-bit integer virtual canvas
// Declare coord_x/coord_y as non-normalized GL_SHORT x4
// coord_x: write 64-bit uint (x ^ 0x8000800080008000) in little endian order
// of 16-bit words, same for y (on a LE platform this happens automatically)
layout(location=0) in vec4 coord_x, coord_y;
// Center of screen: 64-bit uint for x/y, split up into 4 floats:
// center_x_biased.x = ((center_x_u64 >> 0) & 0xffff) - 32768.0f;
// center_x_biased.y = ((center_x_u64 >> 16) & 0xffff) - 32768.0f;
// and so forth.
uniform vec4 center_x_biased, center_y_biased;
uniform vec2 scale_xy;
void main()
{
// Results is signed 17-bit integer intermediates;
// exactly representable as floats!
vec4 relative_x = coord_x - center_x_biased;
vec4 relative_y = coord_y - center_y_biased;
float x, y;
x = ((relative_x.w * 65536.0 + relative_x.z) * 65536.0 + relative_x.y) * 65536.0 + relative_x.x;
y = ((relative_y.w * 65536.0 + relative_y.z) * 65536.0 + relative_y.y) * 65536.0 + relative_y.x;
gl_Position.x = x * scale_xy.x;
gl_Position.y = y * scale_xy.y;
gl_Position.z = 0.0;
gl_Position.w = 1.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment