mirror of
https://git.shylie.info/shylie/glerminal.git
synced 2024-11-24 09:21:05 +00:00
Geometry shader is passthrough now
This commit is contained in:
parent
320164e597
commit
c125a36cf0
@ -82,7 +82,7 @@ namespace glerminal
|
|||||||
unsigned int m_sprites[CELL_SIZE * CELL_SIZE * (1 << (8 * sizeof(*m_cells)))];
|
unsigned int m_sprites[CELL_SIZE * CELL_SIZE * (1 << (8 * sizeof(*m_cells)))];
|
||||||
glerminal_main_cb m_main;
|
glerminal_main_cb m_main;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT
|
||||||
mutable std::ofstream m_log;
|
mutable std::ofstream m_log;
|
||||||
void log(GLenum type, GLuint id, GLenum severity, const char* message) const;
|
void log(GLenum type, GLuint id, GLenum severity, const char* message) const;
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,7 +25,7 @@ namespace
|
|||||||
-1, 0 // top left
|
-1, 0 // top left
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr char* VERTEX_SHADER_SOURCE =
|
constexpr char VERTEX_SHADER_SOURCE[] =
|
||||||
"#version 450 core\n"
|
"#version 450 core\n"
|
||||||
"layout (location = 0) in vec2 position;\n"
|
"layout (location = 0) in vec2 position;\n"
|
||||||
"layout (location = 1) in vec2 offset;\n"
|
"layout (location = 1) in vec2 offset;\n"
|
||||||
@ -36,7 +36,6 @@ namespace
|
|||||||
" float scales[];\n"
|
" float scales[];\n"
|
||||||
"} lss;\n"
|
"} lss;\n"
|
||||||
"out VS_OUT {\n"
|
"out VS_OUT {\n"
|
||||||
" flat vec2 offset;\n"
|
|
||||||
" flat int sprite;\n"
|
" flat int sprite;\n"
|
||||||
" flat int layer;\n"
|
" flat int layer;\n"
|
||||||
" vec2 texcoord;\n"
|
" vec2 texcoord;\n"
|
||||||
@ -44,21 +43,22 @@ namespace
|
|||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" const int layer = int(floor(gl_InstanceID / " GRID_SIZE_UNIFORM_NAME ".y));\n"
|
" const int layer = int(floor(gl_InstanceID / " GRID_SIZE_UNIFORM_NAME ".y));\n"
|
||||||
|
" vec2 scaled_offset = 2 * offset * " GRID_SIZE_UNIFORM_NAME ".zw;\n"
|
||||||
" vs_out.sprite = sprite;\n"
|
" vs_out.sprite = sprite;\n"
|
||||||
" vs_out.offset = offset * " GRID_SIZE_UNIFORM_NAME ".zw;\n"
|
|
||||||
" vs_out.layer = layer;\n"
|
" vs_out.layer = layer;\n"
|
||||||
" vs_out.texcoord = vec2(position.x + 1, -position.y);\n"
|
" vs_out.texcoord = vec2(position.x + 1, -position.y);\n"
|
||||||
" vec2 cell_position = vec2(lss.scales[layer] + (gl_InstanceID % int(" GRID_SIZE_UNIFORM_NAME ".y)) - " GRID_SIZE_UNIFORM_NAME ".x * floor((gl_InstanceID % int(" GRID_SIZE_UNIFORM_NAME ".y)) * " GRID_SIZE_UNIFORM_NAME ".z), -floor((gl_InstanceID % int(" GRID_SIZE_UNIFORM_NAME ".y)) * " GRID_SIZE_UNIFORM_NAME ".z));\n"
|
" vec2 cell_position = vec2(lss.scales[layer] + (gl_InstanceID % int(" GRID_SIZE_UNIFORM_NAME ".y)) - " GRID_SIZE_UNIFORM_NAME ".x * floor((gl_InstanceID % int(" GRID_SIZE_UNIFORM_NAME ".y)) * " GRID_SIZE_UNIFORM_NAME ".z), -floor((gl_InstanceID % int(" GRID_SIZE_UNIFORM_NAME ".y)) * " GRID_SIZE_UNIFORM_NAME ".z));\n"
|
||||||
" vec2 temp = ((position + vec2(-0.5, 0.5)) * lss.scales[layer] + cell_position + vec2(0.5, -0.5)) * " GRID_SIZE_UNIFORM_NAME ".zw * 2 + vec2(-1, 1);\n"
|
" vec2 temp = ((position + vec2(-0.5, 0.5)) * lss.scales[layer] + cell_position + vec2(0.5, -0.5)) * " GRID_SIZE_UNIFORM_NAME ".zw * 2 + vec2(-1, 1);\n"
|
||||||
" gl_Position = vec4(temp.x, -temp.y, 0, 1);\n"
|
" gl_Position = vec4(scaled_offset.x + temp.x, scaled_offset.y - temp.y, 0, 1);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
constexpr char* GEOMETRY_SHADER_SOURCE =
|
constexpr const char* VERTEX_SHADER_SOURCE_PTR = VERTEX_SHADER_SOURCE;
|
||||||
|
|
||||||
|
constexpr char GEOMETRY_SHADER_SOURCE[] =
|
||||||
"#version 450 core\n"
|
"#version 450 core\n"
|
||||||
"layout (triangles) in;\n"
|
"layout (triangles) in;\n"
|
||||||
"layout (triangle_strip, max_vertices = 3) out;\n"
|
"layout (triangle_strip, max_vertices = 3) out;\n"
|
||||||
"in VS_OUT {\n"
|
"in VS_OUT {\n"
|
||||||
" flat vec2 offset;\n"
|
|
||||||
" flat int sprite;\n"
|
" flat int sprite;\n"
|
||||||
" flat int layer;\n"
|
" flat int layer;\n"
|
||||||
" vec2 texcoord;\n"
|
" vec2 texcoord;\n"
|
||||||
@ -68,24 +68,26 @@ namespace
|
|||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" gl_Layer = gs_in[0].layer;\n"
|
" gl_Layer = gs_in[0].layer;\n"
|
||||||
" gl_Position = vec4(gl_in[0].gl_Position.xy + gs_in[0].offset * 2, 0, 1);\n"
|
" gl_Position = gl_in[0].gl_Position;\n"
|
||||||
" sprite = gs_in[0].sprite;\n"
|
" sprite = gs_in[0].sprite;\n"
|
||||||
" texcoord = gs_in[0].texcoord;\n"
|
" texcoord = gs_in[0].texcoord;\n"
|
||||||
" EmitVertex();\n"
|
" EmitVertex();\n"
|
||||||
" gl_Layer = gs_in[1].layer;\n"
|
" gl_Layer = gs_in[1].layer;\n"
|
||||||
" gl_Position = vec4(gl_in[1].gl_Position.xy + gs_in[1].offset * 2, 0, 1);\n"
|
" gl_Position = gl_in[1].gl_Position;\n"
|
||||||
" sprite = gs_in[1].sprite;\n"
|
" sprite = gs_in[1].sprite;\n"
|
||||||
" texcoord = gs_in[1].texcoord;\n"
|
" texcoord = gs_in[1].texcoord;\n"
|
||||||
" EmitVertex();\n"
|
" EmitVertex();\n"
|
||||||
" gl_Layer = gs_in[2].layer;\n"
|
" gl_Layer = gs_in[2].layer;\n"
|
||||||
" gl_Position = vec4(gl_in[2].gl_Position.xy + gs_in[2].offset * 2, 0, 1);\n"
|
" gl_Position = gl_in[2].gl_Position;\n"
|
||||||
" sprite = gs_in[2].sprite;\n"
|
" sprite = gs_in[2].sprite;\n"
|
||||||
" texcoord = gs_in[2].texcoord;\n"
|
" texcoord = gs_in[2].texcoord;\n"
|
||||||
" EmitVertex();\n"
|
" EmitVertex();\n"
|
||||||
" EndPrimitive();\n"
|
" EndPrimitive();\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
constexpr char* FRAGMENT_SHADER_SOURCE =
|
constexpr const char* GEOMETRY_SHADER_SOURCE_PTR = GEOMETRY_SHADER_SOURCE;
|
||||||
|
|
||||||
|
constexpr char FRAGMENT_SHADER_SOURCE[] =
|
||||||
"#version 450 core\n"
|
"#version 450 core\n"
|
||||||
"in vec2 texcoord;\n"
|
"in vec2 texcoord;\n"
|
||||||
"flat in int sprite;\n"
|
"flat in int sprite;\n"
|
||||||
@ -96,7 +98,9 @@ namespace
|
|||||||
" FragColor = texture(" SPRITES_UNIFORM_NAME ", vec3(texcoord, sprite));\n"
|
" FragColor = texture(" SPRITES_UNIFORM_NAME ", vec3(texcoord, sprite));\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
constexpr char* SCREEN_VERTEX_SHADER_SOURCE =
|
constexpr const char* FRAGMENT_SHADER_SOURCE_PTR = FRAGMENT_SHADER_SOURCE;
|
||||||
|
|
||||||
|
constexpr char SCREEN_VERTEX_SHADER_SOURCE[] =
|
||||||
"#version 450 core\n"
|
"#version 450 core\n"
|
||||||
"layout (location = 0) in vec2 position;\n"
|
"layout (location = 0) in vec2 position;\n"
|
||||||
"out vec2 texcoord;\n"
|
"out vec2 texcoord;\n"
|
||||||
@ -106,6 +110,8 @@ namespace
|
|||||||
" texcoord = vec2(position.x + 1, -position.y);\n"
|
" texcoord = vec2(position.x + 1, -position.y);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
constexpr const char* SCREEN_VERTEX_SHADER_SOURCE_PTR = SCREEN_VERTEX_SHADER_SOURCE;
|
||||||
|
|
||||||
constexpr char* SCREEN_FRAGMENT_SHADER_SOURCE =
|
constexpr char* SCREEN_FRAGMENT_SHADER_SOURCE =
|
||||||
"#version 450 core\n"
|
"#version 450 core\n"
|
||||||
"in vec2 texcoord;\n"
|
"in vec2 texcoord;\n"
|
||||||
@ -126,6 +132,8 @@ namespace
|
|||||||
" }\n"
|
" }\n"
|
||||||
" FragColor = vec4(current_color, 1);\n"
|
" FragColor = vec4(current_color, 1);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
constexpr const char* SCREEN_FRAGMENT_SHADER_SOURCE_PTR = SCREEN_FRAGMENT_SHADER_SOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace glerminal
|
namespace glerminal
|
||||||
@ -444,15 +452,15 @@ namespace glerminal
|
|||||||
// -- setup shader program --
|
// -- setup shader program --
|
||||||
// compile
|
// compile
|
||||||
const unsigned int vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
const unsigned int vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
glShaderSource(vertex_shader, 1, &VERTEX_SHADER_SOURCE, nullptr);
|
glShaderSource(vertex_shader, 1, &VERTEX_SHADER_SOURCE_PTR, nullptr);
|
||||||
glCompileShader(vertex_shader);
|
glCompileShader(vertex_shader);
|
||||||
|
|
||||||
const unsigned int geometry_shader = glCreateShader(GL_GEOMETRY_SHADER);
|
const unsigned int geometry_shader = glCreateShader(GL_GEOMETRY_SHADER);
|
||||||
glShaderSource(geometry_shader, 1, &GEOMETRY_SHADER_SOURCE, nullptr);
|
glShaderSource(geometry_shader, 1, &GEOMETRY_SHADER_SOURCE_PTR, nullptr);
|
||||||
glCompileShader(geometry_shader);
|
glCompileShader(geometry_shader);
|
||||||
|
|
||||||
const unsigned int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
const unsigned int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
glShaderSource(fragment_shader, 1, &FRAGMENT_SHADER_SOURCE, nullptr);
|
glShaderSource(fragment_shader, 1, &FRAGMENT_SHADER_SOURCE_PTR, nullptr);
|
||||||
glCompileShader(fragment_shader);
|
glCompileShader(fragment_shader);
|
||||||
|
|
||||||
constexpr int INFO_LOG_SIZE = 512;
|
constexpr int INFO_LOG_SIZE = 512;
|
||||||
@ -523,11 +531,11 @@ namespace glerminal
|
|||||||
|
|
||||||
// compile
|
// compile
|
||||||
const unsigned int screen_vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
const unsigned int screen_vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
glShaderSource(screen_vertex_shader, 1, &SCREEN_VERTEX_SHADER_SOURCE, nullptr);
|
glShaderSource(screen_vertex_shader, 1, &SCREEN_VERTEX_SHADER_SOURCE_PTR, nullptr);
|
||||||
glCompileShader(screen_vertex_shader);
|
glCompileShader(screen_vertex_shader);
|
||||||
|
|
||||||
const unsigned int screen_fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
const unsigned int screen_fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
glShaderSource(screen_fragment_shader, 1, &SCREEN_FRAGMENT_SHADER_SOURCE, nullptr);
|
glShaderSource(screen_fragment_shader, 1, &SCREEN_FRAGMENT_SHADER_SOURCE_PTR, nullptr);
|
||||||
glCompileShader(screen_fragment_shader);
|
glCompileShader(screen_fragment_shader);
|
||||||
|
|
||||||
// verify compile
|
// verify compile
|
||||||
|
Loading…
Reference in New Issue
Block a user