mirror of
https://git.shylie.info/shylie/glerminal.git
synced 2024-11-21 16:40:04 +00:00
Fix layering
This commit is contained in:
parent
a32897d5d4
commit
4f5bc7b5cd
@ -4,19 +4,27 @@ namespace
|
||||
{
|
||||
void init()
|
||||
{
|
||||
glerminal_update_palette(0, 0xFF0000FF);
|
||||
glerminal_update_palette(1, 0x00FF00FF);
|
||||
glerminal_update_palette(0, 0x00000000);
|
||||
glerminal_update_palette(1, 0xFF00001F);
|
||||
glerminal_update_palette(2, 0x00FF001F);
|
||||
|
||||
glerminal_update_sprite(0, {
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0
|
||||
glerminal_update_sprite(1, {
|
||||
2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 1, 1, 1, 1, 1, 1, 2,
|
||||
2, 1, 1, 1, 1, 1, 1, 2,
|
||||
2, 1, 1, 1, 1, 1, 1, 2,
|
||||
2, 1, 1, 1, 1, 1, 1, 2,
|
||||
2, 1, 1, 1, 1, 1, 1, 2,
|
||||
2, 1, 1, 1, 1, 1, 1, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2
|
||||
});
|
||||
|
||||
glerminal_set(0, 0, 0, 1);
|
||||
glerminal_set(1, 0, 0, 1);
|
||||
glerminal_set(1, 0, 1, 1);
|
||||
glerminal_set(2, 0, 0, 1);
|
||||
glerminal_set(2, 0, 1, 1);
|
||||
glerminal_set(2, 0, 2, 1);
|
||||
}
|
||||
|
||||
void mainloop(float dt)
|
||||
|
@ -25,18 +25,19 @@ namespace
|
||||
constexpr char* VERTEX_SHADER_SOURCE =
|
||||
"#version 400 core\n"
|
||||
"layout (location = 0) in vec2 position;\n"
|
||||
"layout (location = 1) in int sprite;\n"
|
||||
"layout (location = 1) in ivec4 sprite[4];\n"
|
||||
"uniform vec4 " SCREEN_SIZE_UNIFORM_NAME ";\n"
|
||||
"out VS_OUT {\n"
|
||||
" flat int sprite;\n"
|
||||
" flat ivec4 sprite[4];\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vs_out;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vs_out.sprite = sprite;\n"
|
||||
" vs_out.texcoord = position + 1;\n"
|
||||
" vs_out.texcoord = vec2(position.x + 1, -position.y);\n"
|
||||
" vec2 cell_position = vec2(1 + gl_InstanceID - " SCREEN_SIZE_UNIFORM_NAME ".x * floor(gl_InstanceID * " SCREEN_SIZE_UNIFORM_NAME ".z), -floor((gl_InstanceID) * " SCREEN_SIZE_UNIFORM_NAME ".z));\n"
|
||||
" gl_Position = vec4((position + cell_position) * " SCREEN_SIZE_UNIFORM_NAME ".zw * 2 + vec2(-1, 1), 0, 1);\n"
|
||||
" vec2 temp = vec2((position + cell_position) * " SCREEN_SIZE_UNIFORM_NAME ".zw * 2 + vec2(-1, 1));\n"
|
||||
" gl_Position = vec4(temp.x, -temp.y, 0, 1);\n"
|
||||
"}";
|
||||
|
||||
constexpr char* GEOMETRY_SHADER_SOURCE =
|
||||
@ -45,7 +46,7 @@ namespace
|
||||
"layout (triangle_strip, max_vertices = 48) out;\n"
|
||||
"layout (invocations = 16) in;\n"
|
||||
"in VS_OUT {\n"
|
||||
" flat int sprite;\n"
|
||||
" flat ivec4 sprite[4];\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} gs_in[];\n"
|
||||
"flat out int sprite;\n"
|
||||
@ -54,17 +55,17 @@ namespace
|
||||
"{\n"
|
||||
" gl_Layer = gl_InvocationID;\n"
|
||||
" gl_Position = gl_in[0].gl_Position;\n"
|
||||
" sprite = gs_in[0].sprite;\n"
|
||||
" sprite = gs_in[0].sprite[gl_InvocationID / 16][gl_InvocationID % 16];\n"
|
||||
" texcoord = gs_in[0].texcoord;\n"
|
||||
" EmitVertex();\n"
|
||||
" gl_Layer = gl_InvocationID;\n"
|
||||
" gl_Position = gl_in[1].gl_Position;\n"
|
||||
" sprite = gs_in[1].sprite;\n"
|
||||
" sprite = gs_in[1].sprite[gl_InvocationID / 16][gl_InvocationID % 16];\n"
|
||||
" texcoord = gs_in[1].texcoord;\n"
|
||||
" EmitVertex();\n"
|
||||
" gl_Layer = gl_InvocationID;\n"
|
||||
" gl_Position = gl_in[2].gl_Position;\n"
|
||||
" sprite = gs_in[2].sprite;\n"
|
||||
" sprite = gs_in[2].sprite[gl_InvocationID / 16][gl_InvocationID % 16];\n"
|
||||
" texcoord = gs_in[2].texcoord;\n"
|
||||
" EmitVertex();\n"
|
||||
" EndPrimitive();\n"
|
||||
@ -100,10 +101,10 @@ namespace
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec3 current_color = vec3(0);\n"
|
||||
" for (int i = 15; i >= 0; i--)\n"
|
||||
" for (int i = 0; i < 16; i++)\n"
|
||||
" {\n"
|
||||
" vec4 texsample = texture(" LAYERS_UNIFORM_NAME ", vec3(texcoord, i));\n"
|
||||
" current_color = mix(current_color, texsample.xyz, texsample.w);\n"
|
||||
" current_color = mix(current_color, texsample.rgb, texsample.a);\n"
|
||||
" }\n"
|
||||
" FragColor = vec4(current_color, 1);\n"
|
||||
"}";
|
||||
@ -195,7 +196,7 @@ namespace glerminal
|
||||
{
|
||||
if (x < GRID_WIDTH && y < GRID_HEIGHT && layer < LAYER_COUNT)
|
||||
{
|
||||
m_cells[x + y * GRID_WIDTH + layer * GRID_AREA] = sprite;
|
||||
m_cells[layer + x * LAYER_COUNT + y * LAYER_COUNT * GRID_WIDTH] = sprite;
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,8 +224,8 @@ namespace glerminal
|
||||
{
|
||||
m_palette[4 * id + 0] = ((color >> 24) & 0xFF) / 255.0f;
|
||||
m_palette[4 * id + 1] = ((color >> 16) & 0xFF) / 255.0f;
|
||||
m_palette[4 * id + 2] = ((color >> 8) & 0xFF) / 255.0f;
|
||||
m_palette[4 * id + 3] = ((color >> 0) & 0xFF) / 255.0f;
|
||||
m_palette[4 * id + 2] = ((color >> 8) & 0xFF) / 255.0f;
|
||||
m_palette[4 * id + 3] = ((color >> 0) & 0xFF) / 255.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,8 +351,17 @@ namespace glerminal
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_instance_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(m_cells), m_cells, GL_STREAM_DRAW);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribIPointer(1, 1, GL_UNSIGNED_BYTE, sizeof(*m_cells), reinterpret_cast<void*>(0));
|
||||
glVertexAttribIPointer(1, 4, GL_UNSIGNED_BYTE, 16 * sizeof(*m_cells), reinterpret_cast<void*>(0));
|
||||
glVertexAttribDivisor(1, 1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribIPointer(2, 4, GL_UNSIGNED_BYTE, 16 * sizeof(*m_cells), reinterpret_cast<void*>(4));
|
||||
glVertexAttribDivisor(2, 1);
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribIPointer(3, 4, GL_UNSIGNED_BYTE, 16 * sizeof(*m_cells), reinterpret_cast<void*>(8));
|
||||
glVertexAttribDivisor(3, 1);
|
||||
glEnableVertexAttribArray(4);
|
||||
glVertexAttribIPointer(4, 4, GL_UNSIGNED_BYTE, 16 * sizeof(*m_cells), reinterpret_cast<void*>(12));
|
||||
glVertexAttribDivisor(4, 1);
|
||||
|
||||
// set up static vertex attributes
|
||||
glGenVertexArrays(1, &m_screen_vao);
|
||||
|
Loading…
Reference in New Issue
Block a user