use raw string literals

This commit is contained in:
Brad Grantham 2020-01-11 18:20:27 -08:00
parent b76c734115
commit 0a9399d646

View File

@ -172,122 +172,122 @@ tuple<float,bool> get_paddle(int num)
const int raster_coords_attrib = 0; const int raster_coords_attrib = 0;
static const char *hires_vertex_shader = "\n\ static const char *hires_vertex_shader = R"(
uniform mat3 to_screen;\n\ uniform mat3 to_screen;
in vec2 vertex_coords;\n\ in vec2 vertex_coords;
out vec2 raster_coords;\n\ out vec2 raster_coords;
uniform float x_offset;\n\ uniform float x_offset;
uniform float y_offset;\n\ uniform float y_offset;
\n\
void main()\n\ void main()
{\n\ {
raster_coords = vertex_coords;\n\ raster_coords = vertex_coords;
vec3 screen_coords = to_screen * vec3(vertex_coords + vec2(x_offset, y_offset), 1);\n\ vec3 screen_coords = to_screen * vec3(vertex_coords + vec2(x_offset, y_offset), 1);
gl_Position = vec4(screen_coords.x, screen_coords.y, .5, 1);\n\ gl_Position = vec4(screen_coords.x, screen_coords.y, .5, 1);
}\n"; })";
static const char *image_fragment_shader = "\n\ static const char *image_fragment_shader = R"(
in vec2 raster_coords;\n\ in vec2 raster_coords;
uniform vec2 image_coord_scale;\n\ uniform vec2 image_coord_scale;
uniform sampler2D image;\n\ uniform sampler2D image;
\n\
out vec4 color;\n\ out vec4 color;
\n\
void main()\n\ void main()
{\n\ {
ivec2 tc = ivec2(raster_coords.x, raster_coords.y);\n\ ivec2 tc = ivec2(raster_coords.x, raster_coords.y);
float pixel = texture(image, raster_coords * image_coord_scale).x;\n\ float pixel = texture(image, raster_coords * image_coord_scale).x;
color = vec4(pixel, pixel, pixel, 1);\n\ color = vec4(pixel, pixel, pixel, 1);
}\n"; })";
static const char *hires_fragment_shader = "\n\ static const char *hires_fragment_shader = R"(
in vec2 raster_coords;\n\ in vec2 raster_coords;
uniform vec2 hires_texture_coord_scale;\n\ uniform vec2 hires_texture_coord_scale;
uniform sampler2D hires_texture;\n\ uniform sampler2D hires_texture;
\n\
out vec4 color;\n\ out vec4 color;
\n\
void main()\n\ void main()
{\n\ {
int byte = int(raster_coords.x) / 7;\n\ int byte = int(raster_coords.x) / 7;
int bit = int(raster_coords.x) % 7;\n\ int bit = int(raster_coords.x) % 7;
int texturex = byte * 8 + bit;\n\ int texturex = byte * 8 + bit;
ivec2 tc = ivec2(texturex, raster_coords.y);\n\ ivec2 tc = ivec2(texturex, raster_coords.y);
float pixel = texture(hires_texture, (tc + vec2(.01f, .01f)) * hires_texture_coord_scale).x;\n\ float pixel = texture(hires_texture, (tc + vec2(.01f, .01f)) * hires_texture_coord_scale).x;
color = vec4(pixel, pixel, pixel, 1);\n\ color = vec4(pixel, pixel, pixel, 1);
}\n"; })";
static const char *hirescolor_fragment_shader = "\n\ static const char *hirescolor_fragment_shader = R"(
in vec2 raster_coords;\n\ in vec2 raster_coords;
uniform vec2 hires_texture_coord_scale;\n\ uniform vec2 hires_texture_coord_scale;
uniform sampler2D hires_texture;\n\ uniform sampler2D hires_texture;
\n\
out vec4 color;\n\ out vec4 color;
\n\
vec2 raster_to_texture(int x, int y)\n\ vec2 raster_to_texture(int x, int y)
{\n\ {
int byte = x / 7;\n\ int byte = x / 7;
int bit = x % 7;\n\ int bit = x % 7;
int texturex = byte * 8 + bit;\n\ int texturex = byte * 8 + bit;
return vec2(texturex + .01f, y + .01f) * hires_texture_coord_scale; \n\ return vec2(texturex + .01f, y + .01f) * hires_texture_coord_scale;
}\n\ }
void main()\n\ void main()
{\n\ {
int x = int(raster_coords.x); \n\ int x = int(raster_coords.x);
int y = int(raster_coords.y); \n\ int y = int(raster_coords.y);
\n\
uint left = (x < 1) ? 0u : uint(255 * texture(hires_texture, raster_to_texture(x - 1, y)).x);\n\ uint left = (x < 1) ? 0u : uint(255 * texture(hires_texture, raster_to_texture(x - 1, y)).x);
uint pixel = uint(255 * texture(hires_texture, raster_to_texture(x, y)).x);\n\ uint pixel = uint(255 * texture(hires_texture, raster_to_texture(x, y)).x);
uint right = (x > 278) ? 0u : uint(255 * texture(hires_texture, raster_to_texture(x + 1, y)).x);\n\ uint right = (x > 278) ? 0u : uint(255 * texture(hires_texture, raster_to_texture(x + 1, y)).x);
\n\
if((pixel == 255u) && ((left == 255u) || (right == 255u))) { \n\ if((pixel == 255u) && ((left == 255u) || (right == 255u))) {
/* Okay, first of all, if this pixel's on and its left or right are on, it's white. */ \n\ /* Okay, first of all, if this pixel's on and its left or right are on, it's white. */
color = vec4(1.0, 1.0, 1.0, 1.0);\n\ color = vec4(1.0, 1.0, 1.0, 1.0);
} else if((pixel == 0u) && (left == 0u) && (right == 0u)) { \n\ } else if((pixel == 0u) && (left == 0u) && (right == 0u)) {
/* If none are on, it's black */ \n\ /* If none are on, it's black */
color = vec4(0.0, 0.0, 0.0, 1.0);\n\ color = vec4(0.0, 0.0, 0.0, 1.0);
} else { \n\ } else {
uint even = (x % 2 == 1) ? left : pixel; \n\ uint even = (x % 2 == 1) ? left : pixel;
uint odd = (x % 2 == 1) ? pixel : right; \n\ uint odd = (x % 2 == 1) ? pixel : right;
uint palette = uint(texture(hires_texture, vec2((x / 7) * 8 + 7 + .01f, raster_coords.y + .01f) * hires_texture_coord_scale).x); \n\ uint palette = uint(texture(hires_texture, vec2((x / 7) * 8 + 7 + .01f, raster_coords.y + .01f) * hires_texture_coord_scale).x);
\n\
if(palette == 0u) { \n\ if(palette == 0u) {
if((even == 0u) && (odd == 255u)) { \n\ if((even == 0u) && (odd == 255u)) {
color = vec4(20.0/255.0, 245.0/255.0, 60.0/255.0, 1.0);\n\ color = vec4(20.0/255.0, 245.0/255.0, 60.0/255.0, 1.0);
/* green 20 245 60 */ \n\ /* green 20 245 60 */
} else if((even == 255u) && (odd == 0u)) { \n\ } else if((even == 255u) && (odd == 0u)) {
/* purple 255 68 253 */ \n\ /* purple 255 68 253 */
color = vec4(255.0/255.0, 68.0/255.0, 253.0/255.0, 1.0);\n\ color = vec4(255.0/255.0, 68.0/255.0, 253.0/255.0, 1.0);
} else if((even == 0u) && (odd == 0u)) { \n\ } else if((even == 0u) && (odd == 0u)) {
color = vec4(0, 0, 0, 1);\n\ color = vec4(0, 0, 0, 1);
} /* handled 1,1 above */ \n\ } /* handled 1,1 above */
} else { \n\ } else {
if((even == 0u) && (odd == 255u)) { \n\ if((even == 0u) && (odd == 255u)) {
/* orange 255 106 60 */ \n\ /* orange 255 106 60 */
color = vec4(255.0/255.0, 106.0/255.0, 60.0/255.0, 1.0);\n\ color = vec4(255.0/255.0, 106.0/255.0, 60.0/255.0, 1.0);
} else if((even == 255u) && (odd == 0u)) { \n\ } else if((even == 255u) && (odd == 0u)) {
/* blue 20 207 253 */ \n\ /* blue 20 207 253 */
color = vec4(20.0/255.0, 207.0/255.0, 253.0/255.0, 1.0);\n\ color = vec4(20.0/255.0, 207.0/255.0, 253.0/255.0, 1.0);
} else if((even == 0u) && (odd == 0u)) { \n\ } else if((even == 0u) && (odd == 0u)) {
color = vec4(0, 0, 0, 1);\n\ color = vec4(0, 0, 0, 1);
} /* handled 1,1 above */ \n\ } /* handled 1,1 above */
} \n\ }
} \n\ }
}\n"; })";
static const char *text_vertex_shader = "\n\ static const char *text_vertex_shader = R"(
uniform mat3 to_screen;\n\ uniform mat3 to_screen;
in vec2 vertex_coords;\n\ in vec2 vertex_coords;
uniform float x_offset;\n\ uniform float x_offset;
uniform float y_offset;\n\ uniform float y_offset;
out vec2 raster_coords;\n\ out vec2 raster_coords;
\n\
void main()\n\ void main()
{\n\ {
raster_coords = vertex_coords;\n\ raster_coords = vertex_coords;
vec3 screen_coords = to_screen * vec3(vertex_coords + vec2(x_offset, y_offset), 1);\n\ vec3 screen_coords = to_screen * vec3(vertex_coords + vec2(x_offset, y_offset), 1);
gl_Position = vec4(screen_coords.x, screen_coords.y, .5, 1);\n\ gl_Position = vec4(screen_coords.x, screen_coords.y, .5, 1);
}\n"; })";
// 0-31 is inverse 32-63 // 0-31 is inverse 32-63
// 32-63 is inverse 0-31 // 32-63 is inverse 0-31
@ -298,176 +298,176 @@ static const char *text_vertex_shader = "\n\
// 192-223 is normal 32-63 // 192-223 is normal 32-63
// 224-255 is normal 64-95 // 224-255 is normal 64-95
static const char *text_fragment_shader = "\n\ static const char *text_fragment_shader = R"(
in vec2 raster_coords;\n\ in vec2 raster_coords;
uniform int blink;\n\ uniform int blink;
uniform vec4 foreground;\n\ uniform vec4 foreground;
uniform vec4 background;\n\ uniform vec4 background;
uniform vec2 font_texture_coord_scale;\n\ uniform vec2 font_texture_coord_scale;
uniform sampler2D font_texture;\n\ uniform sampler2D font_texture;
uniform vec2 textport_texture_coord_scale;\n\ uniform vec2 textport_texture_coord_scale;
uniform sampler2D textport_texture;\n\ uniform sampler2D textport_texture;
\n\
out vec4 color;\n\ out vec4 color;
\n\
void main()\n\ void main()
{\n\ {
uint character;\n\ uint character;
character = uint(texture(textport_texture, (uvec2(uint(raster_coords.x) / 7u, uint(raster_coords.y) / 8u) + vec2(.01f, .01f)) * textport_texture_coord_scale).x * 255.0); \n\ character = uint(texture(textport_texture, (uvec2(uint(raster_coords.x) / 7u, uint(raster_coords.y) / 8u) + vec2(.01f, .01f)) * textport_texture_coord_scale).x * 255.0);
bool inverse = false;\n\ bool inverse = false;
if(character >= 0u && character <= 31u) {\n\ if(character >= 0u && character <= 31u) {
character = character - 0u + 32u;\n\ character = character - 0u + 32u;
inverse = true;\n\ inverse = true;
} else if(character >= 32u && character <= 63u) {\n\ } else if(character >= 32u && character <= 63u) {
character = character - 32u + 0u;\n\ character = character - 32u + 0u;
inverse = true;\n\ inverse = true;
} else if(character >= 64u && character <= 95u) {\n\ } else if(character >= 64u && character <= 95u) {
character = character - 64u + 32u; // XXX BLINK \n\ character = character - 64u + 32u; // XXX BLINK
inverse = blink == 1;\n\ inverse = blink == 1;
} else if(character >= 96u && character <= 127u){\n\ } else if(character >= 96u && character <= 127u){
character = character - 96u + 0u; // XXX BLINK \n\ character = character - 96u + 0u; // XXX BLINK
inverse = blink == 1;\n\ inverse = blink == 1;
} else if(character >= 128u && character <= 159u)\n\ } else if(character >= 128u && character <= 159u)
character = character - 128u + 32u;\n\ character = character - 128u + 32u;
else if(character >= 160u && character <= 191u)\n\ else if(character >= 160u && character <= 191u)
character = character - 160u + 0u;\n\ character = character - 160u + 0u;
else if(character >= 192u && character <= 223u)\n\ else if(character >= 192u && character <= 223u)
character = character - 192u + 32u;\n\ character = character - 192u + 32u;
else if(character >= 224u && character <= 255u)\n\ else if(character >= 224u && character <= 255u)
character = character - 224u + 64u;\n\ character = character - 224u + 64u;
else \n\ else
character = 33u;\n\ character = 33u;
uvec2 inglyph = uvec2(uint(raster_coords.x) % 7u, uint(raster_coords.y) % 8u);\n\ uvec2 inglyph = uvec2(uint(raster_coords.x) % 7u, uint(raster_coords.y) % 8u);
uvec2 infont = inglyph + uvec2(0, character * 8u);\n\ uvec2 infont = inglyph + uvec2(0, character * 8u);
float pixel = texture(font_texture, (infont + vec2(.01f, 0.1f)) * font_texture_coord_scale).x;\n\ float pixel = texture(font_texture, (infont + vec2(.01f, 0.1f)) * font_texture_coord_scale).x;
if(inverse)\n\ if(inverse)
color = mix(background, foreground, 1.0 - pixel);\n\ color = mix(background, foreground, 1.0 - pixel);
else\n\ else
color = mix(background, foreground, pixel);\n\ color = mix(background, foreground, pixel);
}\n"; })";
static const char *text80_fragment_shader = "\n\ static const char *text80_fragment_shader = R"(
in vec2 raster_coords;\n\ in vec2 raster_coords;
uniform int blink;\n\ uniform int blink;
uniform vec4 foreground;\n\ uniform vec4 foreground;
uniform vec4 background;\n\ uniform vec4 background;
uniform vec2 font_texture_coord_scale;\n\ uniform vec2 font_texture_coord_scale;
uniform sampler2D font_texture;\n\ uniform sampler2D font_texture;
uniform vec2 textport_texture_coord_scale;\n\ uniform vec2 textport_texture_coord_scale;
uniform sampler2D textport_texture;\n\ uniform sampler2D textport_texture;
uniform sampler2D textport_aux_texture;\n\ uniform sampler2D textport_aux_texture;
\n\
out vec4 color;\n\ out vec4 color;
\n\
void main()\n\ void main()
{\n\ {
uint character;\n\ uint character;
uint x = uint(raster_coords.x * 2) / 7u; \n\ uint x = uint(raster_coords.x * 2) / 7u;
if(x % 2u == 1u) \n\ if(x % 2u == 1u)
character = uint(texture(textport_texture, (uvec2((x - 1u) / 2u, uint(raster_coords.y) / 8u) + vec2(.01f, .01f)) * textport_texture_coord_scale).x * 255.0); \n\ character = uint(texture(textport_texture, (uvec2((x - 1u) / 2u, uint(raster_coords.y) / 8u) + vec2(.01f, .01f)) * textport_texture_coord_scale).x * 255.0);
else \n\ else
character = uint(texture(textport_aux_texture, (uvec2(x / 2u, uint(raster_coords.y) / 8u) + vec2(.01f, .01f)) * textport_texture_coord_scale).x * 255.0); \n\ character = uint(texture(textport_aux_texture, (uvec2(x / 2u, uint(raster_coords.y) / 8u) + vec2(.01f, .01f)) * textport_texture_coord_scale).x * 255.0);
bool inverse = false;\n\ bool inverse = false;
if(character >= 0u && character <= 31u) {\n\ if(character >= 0u && character <= 31u) {
character = character - 0u + 32u;\n\ character = character - 0u + 32u;
inverse = true;\n\ inverse = true;
} else if(character >= 32u && character <= 63u) {\n\ } else if(character >= 32u && character <= 63u) {
character = character - 32u + 0u;\n\ character = character - 32u + 0u;
inverse = true;\n\ inverse = true;
} else if(character >= 64u && character <= 95u) {\n\ } else if(character >= 64u && character <= 95u) {
character = character - 64u + 32u; // XXX BLINK \n\ character = character - 64u + 32u; // XXX BLINK
inverse = blink == 1;\n\ inverse = blink == 1;
} else if(character >= 96u && character <= 127u){\n\ } else if(character >= 96u && character <= 127u){
character = character - 96u + 0u; // XXX BLINK \n\ character = character - 96u + 0u; // XXX BLINK
inverse = blink == 1;\n\ inverse = blink == 1;
} else if(character >= 128u && character <= 159u)\n\ } else if(character >= 128u && character <= 159u)
character = character - 128u + 32u;\n\ character = character - 128u + 32u;
else if(character >= 160u && character <= 191u)\n\ else if(character >= 160u && character <= 191u)
character = character - 160u + 0u;\n\ character = character - 160u + 0u;
else if(character >= 192u && character <= 223u)\n\ else if(character >= 192u && character <= 223u)
character = character - 192u + 32u;\n\ character = character - 192u + 32u;
else if(character >= 224u && character <= 255u)\n\ else if(character >= 224u && character <= 255u)
character = character - 224u + 64u;\n\ character = character - 224u + 64u;
else \n\ else
character = 33u;\n\ character = 33u;
uvec2 inglyph = uvec2(uint(raster_coords.x * 2) % 7u, uint(raster_coords.y) % 8u);\n\ uvec2 inglyph = uvec2(uint(raster_coords.x * 2) % 7u, uint(raster_coords.y) % 8u);
uvec2 infont = inglyph + uvec2(0, character * 8u);\n\ uvec2 infont = inglyph + uvec2(0, character * 8u);
float pixel = texture(font_texture, (infont + vec2(.01f, 0.1f)) * font_texture_coord_scale).x;\n\ float pixel = texture(font_texture, (infont + vec2(.01f, 0.1f)) * font_texture_coord_scale).x;
float value;\n\ float value;
if(inverse)\n\ if(inverse)
color = mix(background, foreground, 1.0 - pixel);\n\ color = mix(background, foreground, 1.0 - pixel);
else\n\ else
color = mix(background, foreground, pixel);\n\ color = mix(background, foreground, pixel);
}\n"; })";
static const char *lores_fragment_shader = "\n\ static const char *lores_fragment_shader = R"(
in vec2 raster_coords;\n\ in vec2 raster_coords;
uniform vec2 lores_texture_coord_scale;\n\ uniform vec2 lores_texture_coord_scale;
uniform sampler2D lores_texture;\n\ uniform sampler2D lores_texture;
\n\
out vec4 color;\n\ out vec4 color;
\n\
void main()\n\ void main()
{\n\ {
uint byte;\n\ uint byte;
byte = uint(texture(lores_texture, (uvec2(uint(raster_coords.x) / 7u, uint(raster_coords.y) / 8u) + vec2(.01f, .01f)) * lores_texture_coord_scale).x * 255.0); \n\ byte = uint(texture(lores_texture, (uvec2(uint(raster_coords.x) / 7u, uint(raster_coords.y) / 8u) + vec2(.01f, .01f)) * lores_texture_coord_scale).x * 255.0);
uint inglyph_y = uint(raster_coords.y) % 8u;\n\ uint inglyph_y = uint(raster_coords.y) % 8u;
uint lorespixel;\n\ uint lorespixel;
if(inglyph_y < 4u)\n\ if(inglyph_y < 4u)
lorespixel = byte % 16u;\n\ lorespixel = byte % 16u;
else\n\ else
lorespixel = byte / 16u;\n\ lorespixel = byte / 16u;
switch(lorespixel) {\n\ switch(lorespixel) {
case 0u:\n\ case 0u:
color = vec4(0, 0, 0, 1);\n\ color = vec4(0, 0, 0, 1);
break;\n\ break;
case 1u:\n\ case 1u:
color = vec4(227.0/255.0, 30.0/255.0, 96.0/255.0, 1);\n\ color = vec4(227.0/255.0, 30.0/255.0, 96.0/255.0, 1);
break;\n\ break;
case 2u:\n\ case 2u:
color = vec4(96.0/255.0, 78.0/255.0, 189.0/255.0, 1);\n\ color = vec4(96.0/255.0, 78.0/255.0, 189.0/255.0, 1);
break;\n\ break;
case 3u:\n\ case 3u:
color = vec4(255.0/255.0, 68.0/255.0, 253.0/255.0, 1);\n\ color = vec4(255.0/255.0, 68.0/255.0, 253.0/255.0, 1);
break;\n\ break;
case 4u:\n\ case 4u:
color = vec4(9.0/255.0, 163.0/255.0, 96.0/255.0, 1);\n\ color = vec4(9.0/255.0, 163.0/255.0, 96.0/255.0, 1);
break;\n\ break;
case 5u:\n\ case 5u:
color = vec4(156.0/255.0, 156.0/255.0, 156.0/255.0, 1);\n\ color = vec4(156.0/255.0, 156.0/255.0, 156.0/255.0, 1);
break;\n\ break;
case 6u:\n\ case 6u:
color = vec4(20.0/255.0, 207.0/255.0, 253.0/255.0, 1);\n\ color = vec4(20.0/255.0, 207.0/255.0, 253.0/255.0, 1);
break;\n\ break;
case 7u:\n\ case 7u:
color = vec4(208.0/255.0, 195.0/255.0, 255.0/255.0, 1);\n\ color = vec4(208.0/255.0, 195.0/255.0, 255.0/255.0, 1);
break;\n\ break;
case 8u:\n\ case 8u:
color = vec4(96.0/255.0, 114.0/255.0, 3.0/255.0, 1);\n\ color = vec4(96.0/255.0, 114.0/255.0, 3.0/255.0, 1);
break;\n\ break;
case 9u:\n\ case 9u:
color = vec4(255.0/255.0, 106.0/255.0, 60.0/255.0, 1);\n\ color = vec4(255.0/255.0, 106.0/255.0, 60.0/255.0, 1);
break;\n\ break;
case 10u:\n\ case 10u:
color = vec4(156.0/255.0, 156.0/255.0, 156.0/255.0, 1);\n\ color = vec4(156.0/255.0, 156.0/255.0, 156.0/255.0, 1);
break;\n\ break;
case 11u:\n\ case 11u:
color = vec4(255.0/255.0, 160.0/255.0, 208.0/255.0, 1);\n\ color = vec4(255.0/255.0, 160.0/255.0, 208.0/255.0, 1);
break;\n\ break;
case 12u:\n\ case 12u:
color = vec4(20.0/255.0, 245.0/255.0, 60.0/255.0, 1);\n\ color = vec4(20.0/255.0, 245.0/255.0, 60.0/255.0, 1);
break;\n\ break;
case 13u:\n\ case 13u:
color = vec4(208.0/255.0, 221.0/255.0, 141.0/255.0, 1);\n\ color = vec4(208.0/255.0, 221.0/255.0, 141.0/255.0, 1);
break;\n\ break;
case 14u:\n\ case 14u:
color = vec4(114.0/255.0, 255.0/255.0, 208.0/255.0, 1);\n\ color = vec4(114.0/255.0, 255.0/255.0, 208.0/255.0, 1);
break;\n\ break;
case 15u:\n\ case 15u:
color = vec4(255.0/255.0, 255.0/255.0, 255.0/255.0, 1);\n\ color = vec4(255.0/255.0, 255.0/255.0, 255.0/255.0, 1);
break;\n\ break;
}\n\ }
}\n"; })";
void set_image_shader(float to_screen[9], const opengl_texture& texture, float x, float y) void set_image_shader(float to_screen[9], const opengl_texture& texture, float x, float y)
{ {
@ -1776,6 +1776,10 @@ void iterate(const ModeHistory& history, unsigned long long current_byte, float
glfwSwapBuffers(my_window); glfwSwapBuffers(my_window);
CheckOpenGL(__FILE__, __LINE__); CheckOpenGL(__FILE__, __LINE__);
for(int i = 0; i < 16; i++)
if(glfwJoystickPresent(GLFW_JOYSTICK_1 + i))
printf("joy %d present\n", i);
if(glfwJoystickPresent(GLFW_JOYSTICK_1)) { if(glfwJoystickPresent(GLFW_JOYSTICK_1)) {
if(false) printf("joystick 1 present\n"); if(false) printf("joystick 1 present\n");