mirror of
https://git.shylie.info/shylie/glerminal.git
synced 2024-12-22 06:30:05 +00:00
Compare commits
5 Commits
c8e7a28837
...
11380a0d88
Author | SHA1 | Date | |
---|---|---|---|
|
11380a0d88 | ||
|
2be0aeaf99 | ||
|
c125a36cf0 | ||
|
320164e597 | ||
|
eaab60cfda |
@ -1,22 +1,22 @@
|
||||
/*
|
||||
|
||||
OpenGL loader generated by glad 0.1.36 on Tue May 14 15:22:23 2024.
|
||||
OpenGL loader generated by glad 0.1.36 on Sun May 26 16:07:25 2024.
|
||||
|
||||
Language/Generator: C/C++
|
||||
Specification: gl
|
||||
APIs: gl=4.6
|
||||
APIs: gl=4.5
|
||||
Profile: core
|
||||
Extensions:
|
||||
|
||||
GL_AMD_vertex_shader_layer
|
||||
Loader: True
|
||||
Local files: False
|
||||
Omit khrplatform: False
|
||||
Reproducible: False
|
||||
|
||||
Commandline:
|
||||
--profile="core" --api="gl=4.6" --generator="c" --spec="gl" --extensions=""
|
||||
--profile="core" --api="gl=4.5" --generator="c" --spec="gl" --extensions="GL_AMD_vertex_shader_layer"
|
||||
Online:
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.6
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.5&extensions=GL_AMD_vertex_shader_layer
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -273,7 +273,6 @@ int GLAD_GL_VERSION_4_2 = 0;
|
||||
int GLAD_GL_VERSION_4_3 = 0;
|
||||
int GLAD_GL_VERSION_4_4 = 0;
|
||||
int GLAD_GL_VERSION_4_5 = 0;
|
||||
int GLAD_GL_VERSION_4_6 = 0;
|
||||
PFNGLACTIVESHADERPROGRAMPROC glad_glActiveShaderProgram = NULL;
|
||||
PFNGLACTIVETEXTUREPROC glad_glActiveTexture = NULL;
|
||||
PFNGLATTACHSHADERPROC glad_glAttachShader = NULL;
|
||||
@ -635,11 +634,9 @@ PFNGLMEMORYBARRIERBYREGIONPROC glad_glMemoryBarrierByRegion = NULL;
|
||||
PFNGLMINSAMPLESHADINGPROC glad_glMinSampleShading = NULL;
|
||||
PFNGLMULTIDRAWARRAYSPROC glad_glMultiDrawArrays = NULL;
|
||||
PFNGLMULTIDRAWARRAYSINDIRECTPROC glad_glMultiDrawArraysIndirect = NULL;
|
||||
PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC glad_glMultiDrawArraysIndirectCount = NULL;
|
||||
PFNGLMULTIDRAWELEMENTSPROC glad_glMultiDrawElements = NULL;
|
||||
PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC glad_glMultiDrawElementsBaseVertex = NULL;
|
||||
PFNGLMULTIDRAWELEMENTSINDIRECTPROC glad_glMultiDrawElementsIndirect = NULL;
|
||||
PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC glad_glMultiDrawElementsIndirectCount = NULL;
|
||||
PFNGLMULTITEXCOORDP1UIPROC glad_glMultiTexCoordP1ui = NULL;
|
||||
PFNGLMULTITEXCOORDP1UIVPROC glad_glMultiTexCoordP1uiv = NULL;
|
||||
PFNGLMULTITEXCOORDP2UIPROC glad_glMultiTexCoordP2ui = NULL;
|
||||
@ -676,7 +673,6 @@ PFNGLPOINTPARAMETERIVPROC glad_glPointParameteriv = NULL;
|
||||
PFNGLPOINTSIZEPROC glad_glPointSize = NULL;
|
||||
PFNGLPOLYGONMODEPROC glad_glPolygonMode = NULL;
|
||||
PFNGLPOLYGONOFFSETPROC glad_glPolygonOffset = NULL;
|
||||
PFNGLPOLYGONOFFSETCLAMPPROC glad_glPolygonOffsetClamp = NULL;
|
||||
PFNGLPOPDEBUGGROUPPROC glad_glPopDebugGroup = NULL;
|
||||
PFNGLPRIMITIVERESTARTINDEXPROC glad_glPrimitiveRestartIndex = NULL;
|
||||
PFNGLPROGRAMBINARYPROC glad_glProgramBinary = NULL;
|
||||
@ -758,7 +754,6 @@ PFNGLSECONDARYCOLORP3UIVPROC glad_glSecondaryColorP3uiv = NULL;
|
||||
PFNGLSHADERBINARYPROC glad_glShaderBinary = NULL;
|
||||
PFNGLSHADERSOURCEPROC glad_glShaderSource = NULL;
|
||||
PFNGLSHADERSTORAGEBLOCKBINDINGPROC glad_glShaderStorageBlockBinding = NULL;
|
||||
PFNGLSPECIALIZESHADERPROC glad_glSpecializeShader = NULL;
|
||||
PFNGLSTENCILFUNCPROC glad_glStencilFunc = NULL;
|
||||
PFNGLSTENCILFUNCSEPARATEPROC glad_glStencilFuncSeparate = NULL;
|
||||
PFNGLSTENCILMASKPROC glad_glStencilMask = NULL;
|
||||
@ -973,6 +968,7 @@ PFNGLVIEWPORTARRAYVPROC glad_glViewportArrayv = NULL;
|
||||
PFNGLVIEWPORTINDEXEDFPROC glad_glViewportIndexedf = NULL;
|
||||
PFNGLVIEWPORTINDEXEDFVPROC glad_glViewportIndexedfv = NULL;
|
||||
PFNGLWAITSYNCPROC glad_glWaitSync = NULL;
|
||||
int GLAD_GL_AMD_vertex_shader_layer = 0;
|
||||
static void load_GL_VERSION_1_0(GLADloadproc load) {
|
||||
if(!GLAD_GL_VERSION_1_0) return;
|
||||
glad_glCullFace = (PFNGLCULLFACEPROC)load("glCullFace");
|
||||
@ -1726,16 +1722,9 @@ static void load_GL_VERSION_4_5(GLADloadproc load) {
|
||||
glad_glGetnMinmax = (PFNGLGETNMINMAXPROC)load("glGetnMinmax");
|
||||
glad_glTextureBarrier = (PFNGLTEXTUREBARRIERPROC)load("glTextureBarrier");
|
||||
}
|
||||
static void load_GL_VERSION_4_6(GLADloadproc load) {
|
||||
if(!GLAD_GL_VERSION_4_6) return;
|
||||
glad_glSpecializeShader = (PFNGLSPECIALIZESHADERPROC)load("glSpecializeShader");
|
||||
glad_glMultiDrawArraysIndirectCount = (PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC)load("glMultiDrawArraysIndirectCount");
|
||||
glad_glMultiDrawElementsIndirectCount = (PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC)load("glMultiDrawElementsIndirectCount");
|
||||
glad_glPolygonOffsetClamp = (PFNGLPOLYGONOFFSETCLAMPPROC)load("glPolygonOffsetClamp");
|
||||
}
|
||||
static int find_extensionsGL(void) {
|
||||
if (!get_exts()) return 0;
|
||||
(void)&has_ext;
|
||||
GLAD_GL_AMD_vertex_shader_layer = has_ext("GL_AMD_vertex_shader_layer");
|
||||
free_exts();
|
||||
return 1;
|
||||
}
|
||||
@ -1794,10 +1783,9 @@ static void find_coreGL(void) {
|
||||
GLAD_GL_VERSION_4_3 = (major == 4 && minor >= 3) || major > 4;
|
||||
GLAD_GL_VERSION_4_4 = (major == 4 && minor >= 4) || major > 4;
|
||||
GLAD_GL_VERSION_4_5 = (major == 4 && minor >= 5) || major > 4;
|
||||
GLAD_GL_VERSION_4_6 = (major == 4 && minor >= 6) || major > 4;
|
||||
if (GLVersion.major > 4 || (GLVersion.major >= 4 && GLVersion.minor >= 6)) {
|
||||
if (GLVersion.major > 4 || (GLVersion.major >= 4 && GLVersion.minor >= 5)) {
|
||||
max_loaded_major = 4;
|
||||
max_loaded_minor = 6;
|
||||
max_loaded_minor = 5;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1825,7 +1813,6 @@ int gladLoadGLLoader(GLADloadproc load) {
|
||||
load_GL_VERSION_4_3(load);
|
||||
load_GL_VERSION_4_4(load);
|
||||
load_GL_VERSION_4_5(load);
|
||||
load_GL_VERSION_4_6(load);
|
||||
|
||||
if (!find_extensionsGL()) return 0;
|
||||
return GLVersion.major != 0 || GLVersion.minor != 0;
|
||||
|
@ -1,22 +1,22 @@
|
||||
/*
|
||||
|
||||
OpenGL loader generated by glad 0.1.36 on Tue May 14 15:22:23 2024.
|
||||
OpenGL loader generated by glad 0.1.36 on Sun May 26 16:07:25 2024.
|
||||
|
||||
Language/Generator: C/C++
|
||||
Specification: gl
|
||||
APIs: gl=4.6
|
||||
APIs: gl=4.5
|
||||
Profile: core
|
||||
Extensions:
|
||||
|
||||
GL_AMD_vertex_shader_layer
|
||||
Loader: True
|
||||
Local files: False
|
||||
Omit khrplatform: False
|
||||
Reproducible: False
|
||||
|
||||
Commandline:
|
||||
--profile="core" --api="gl=4.6" --generator="c" --spec="gl" --extensions=""
|
||||
--profile="core" --api="gl=4.5" --generator="c" --spec="gl" --extensions="GL_AMD_vertex_shader_layer"
|
||||
Online:
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.6
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.5&extensions=GL_AMD_vertex_shader_layer
|
||||
*/
|
||||
|
||||
|
||||
@ -1491,28 +1491,6 @@ typedef void (APIENTRY *GLVULKANPROCNV)(void);
|
||||
#define GL_MINMAX 0x802E
|
||||
#define GL_CONTEXT_RELEASE_BEHAVIOR 0x82FB
|
||||
#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82FC
|
||||
#define GL_SHADER_BINARY_FORMAT_SPIR_V 0x9551
|
||||
#define GL_SPIR_V_BINARY 0x9552
|
||||
#define GL_PARAMETER_BUFFER 0x80EE
|
||||
#define GL_PARAMETER_BUFFER_BINDING 0x80EF
|
||||
#define GL_CONTEXT_FLAG_NO_ERROR_BIT 0x00000008
|
||||
#define GL_VERTICES_SUBMITTED 0x82EE
|
||||
#define GL_PRIMITIVES_SUBMITTED 0x82EF
|
||||
#define GL_VERTEX_SHADER_INVOCATIONS 0x82F0
|
||||
#define GL_TESS_CONTROL_SHADER_PATCHES 0x82F1
|
||||
#define GL_TESS_EVALUATION_SHADER_INVOCATIONS 0x82F2
|
||||
#define GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED 0x82F3
|
||||
#define GL_FRAGMENT_SHADER_INVOCATIONS 0x82F4
|
||||
#define GL_COMPUTE_SHADER_INVOCATIONS 0x82F5
|
||||
#define GL_CLIPPING_INPUT_PRIMITIVES 0x82F6
|
||||
#define GL_CLIPPING_OUTPUT_PRIMITIVES 0x82F7
|
||||
#define GL_POLYGON_OFFSET_CLAMP 0x8E1B
|
||||
#define GL_SPIR_V_EXTENSIONS 0x9553
|
||||
#define GL_NUM_SPIR_V_EXTENSIONS 0x9554
|
||||
#define GL_TEXTURE_MAX_ANISOTROPY 0x84FE
|
||||
#define GL_MAX_TEXTURE_MAX_ANISOTROPY 0x84FF
|
||||
#define GL_TRANSFORM_FEEDBACK_OVERFLOW 0x82EC
|
||||
#define GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW 0x82ED
|
||||
#ifndef GL_VERSION_1_0
|
||||
#define GL_VERSION_1_0 1
|
||||
GLAPI int GLAD_GL_VERSION_1_0;
|
||||
@ -3670,21 +3648,9 @@ typedef void (APIENTRYP PFNGLTEXTUREBARRIERPROC)(void);
|
||||
GLAPI PFNGLTEXTUREBARRIERPROC glad_glTextureBarrier;
|
||||
#define glTextureBarrier glad_glTextureBarrier
|
||||
#endif
|
||||
#ifndef GL_VERSION_4_6
|
||||
#define GL_VERSION_4_6 1
|
||||
GLAPI int GLAD_GL_VERSION_4_6;
|
||||
typedef void (APIENTRYP PFNGLSPECIALIZESHADERPROC)(GLuint shader, const GLchar *pEntryPoint, GLuint numSpecializationConstants, const GLuint *pConstantIndex, const GLuint *pConstantValue);
|
||||
GLAPI PFNGLSPECIALIZESHADERPROC glad_glSpecializeShader;
|
||||
#define glSpecializeShader glad_glSpecializeShader
|
||||
typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC)(GLenum mode, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
|
||||
GLAPI PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC glad_glMultiDrawArraysIndirectCount;
|
||||
#define glMultiDrawArraysIndirectCount glad_glMultiDrawArraysIndirectCount
|
||||
typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC)(GLenum mode, GLenum type, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
|
||||
GLAPI PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC glad_glMultiDrawElementsIndirectCount;
|
||||
#define glMultiDrawElementsIndirectCount glad_glMultiDrawElementsIndirectCount
|
||||
typedef void (APIENTRYP PFNGLPOLYGONOFFSETCLAMPPROC)(GLfloat factor, GLfloat units, GLfloat clamp);
|
||||
GLAPI PFNGLPOLYGONOFFSETCLAMPPROC glad_glPolygonOffsetClamp;
|
||||
#define glPolygonOffsetClamp glad_glPolygonOffsetClamp
|
||||
#ifndef GL_AMD_vertex_shader_layer
|
||||
#define GL_AMD_vertex_shader_layer 1
|
||||
GLAPI int GLAD_GL_AMD_vertex_shader_layer;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
||||
@ -82,7 +83,7 @@ namespace glerminal
|
||||
unsigned int m_sprites[CELL_SIZE * CELL_SIZE * (1 << (8 * sizeof(*m_cells)))];
|
||||
glerminal_main_cb m_main;
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT
|
||||
mutable std::ofstream m_log;
|
||||
void log(GLenum type, GLuint id, GLenum severity, const char* message) const;
|
||||
#endif
|
||||
|
@ -25,8 +25,8 @@ namespace
|
||||
-1, 0 // top left
|
||||
};
|
||||
|
||||
constexpr char* VERTEX_SHADER_SOURCE =
|
||||
"#version 460 core\n"
|
||||
constexpr char VERTEX_SHADER_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
"layout (location = 0) in vec2 position;\n"
|
||||
"layout (location = 1) in vec2 offset;\n"
|
||||
"layout (location = 2) in int sprite;\n"
|
||||
@ -36,7 +36,6 @@ namespace
|
||||
" float scales[];\n"
|
||||
"} lss;\n"
|
||||
"out VS_OUT {\n"
|
||||
" flat vec2 offset;\n"
|
||||
" flat int sprite;\n"
|
||||
" flat int layer;\n"
|
||||
" vec2 texcoord;\n"
|
||||
@ -44,21 +43,51 @@ namespace
|
||||
"void main()\n"
|
||||
"{\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.offset = offset * " GRID_SIZE_UNIFORM_NAME ".zw;\n"
|
||||
" vs_out.layer = layer;\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 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 =
|
||||
"#version 460 core\n"
|
||||
// note: AMD_vertex_shader_layer support required
|
||||
constexpr char VERTEX_SHADER_AMD_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
"#extension GL_AMD_vertex_shader_layer : enable\n"
|
||||
"layout (location = 0) in vec2 position;\n"
|
||||
"layout (location = 1) in vec2 offset;\n"
|
||||
"layout (location = 2) in int sprite;\n"
|
||||
"uniform vec4 " GRID_SIZE_UNIFORM_NAME ";\n"
|
||||
"layout (std430, binding = 0) buffer LayerScales"
|
||||
"{\n"
|
||||
" float scales[];\n"
|
||||
"} lss;\n"
|
||||
"out VS_OUT {\n"
|
||||
" flat int sprite;\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vs_out;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" const int layer = int(floor(gl_InstanceID / " GRID_SIZE_UNIFORM_NAME ".y));\n"
|
||||
" gl_Layer = layer;\n"
|
||||
" vec2 scaled_offset = 2 * offset * " GRID_SIZE_UNIFORM_NAME ".zw;\n"
|
||||
" vs_out.sprite = sprite;\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 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(scaled_offset.x + temp.x, scaled_offset.y - temp.y, 0, 1);\n"
|
||||
"}";
|
||||
|
||||
constexpr const char* VERTEX_SHADER_SOURCE_PTR = VERTEX_SHADER_SOURCE;
|
||||
constexpr const char* VERTEX_SHADER_AMD_SOURCE_PTR = VERTEX_SHADER_AMD_SOURCE;
|
||||
|
||||
constexpr char GEOMETRY_SHADER_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
"layout (triangles) in;\n"
|
||||
"layout (triangle_strip, max_vertices = 3) out;\n"
|
||||
"in VS_OUT {\n"
|
||||
" flat vec2 offset;\n"
|
||||
" flat int sprite;\n"
|
||||
" flat int layer;\n"
|
||||
" vec2 texcoord;\n"
|
||||
@ -68,25 +97,27 @@ namespace
|
||||
"void main()\n"
|
||||
"{\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"
|
||||
" texcoord = gs_in[0].texcoord;\n"
|
||||
" EmitVertex();\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"
|
||||
" texcoord = gs_in[1].texcoord;\n"
|
||||
" EmitVertex();\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"
|
||||
" texcoord = gs_in[2].texcoord;\n"
|
||||
" EmitVertex();\n"
|
||||
" EndPrimitive();\n"
|
||||
"}";
|
||||
|
||||
constexpr char* FRAGMENT_SHADER_SOURCE =
|
||||
"#version 460 core\n"
|
||||
constexpr const char* GEOMETRY_SHADER_SOURCE_PTR = GEOMETRY_SHADER_SOURCE;
|
||||
|
||||
constexpr char FRAGMENT_SHADER_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
"in vec2 texcoord;\n"
|
||||
"flat in int sprite;\n"
|
||||
"layout (binding = 0) uniform sampler2DArray " SPRITES_UNIFORM_NAME ";\n"
|
||||
@ -96,8 +127,25 @@ namespace
|
||||
" FragColor = texture(" SPRITES_UNIFORM_NAME ", vec3(texcoord, sprite));\n"
|
||||
"}";
|
||||
|
||||
constexpr char* SCREEN_VERTEX_SHADER_SOURCE =
|
||||
"#version 460 core\n"
|
||||
// note: AMD_vertex_shader_layer support required
|
||||
constexpr char FRAGMENT_SHADER_AMD_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
"in VS_OUT {\n"
|
||||
" flat int sprite;\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} fs_in;\n"
|
||||
"layout (binding = 0) uniform sampler2DArray " SPRITES_UNIFORM_NAME ";\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" FragColor = texture(" SPRITES_UNIFORM_NAME ", vec3(fs_in.texcoord, fs_in.sprite));\n"
|
||||
"}";
|
||||
|
||||
constexpr const char* FRAGMENT_SHADER_SOURCE_PTR = FRAGMENT_SHADER_SOURCE;
|
||||
constexpr const char* FRAGMENT_SHADER_AMD_SOURCE_PTR = FRAGMENT_SHADER_AMD_SOURCE;
|
||||
|
||||
constexpr char SCREEN_VERTEX_SHADER_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
"layout (location = 0) in vec2 position;\n"
|
||||
"out vec2 texcoord;\n"
|
||||
"void main()\n"
|
||||
@ -106,8 +154,10 @@ namespace
|
||||
" 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 =
|
||||
"#version 460 core\n"
|
||||
"#version 450 core\n"
|
||||
"in vec2 texcoord;\n"
|
||||
"layout (binding = 1) uniform sampler2DArray " LAYERS_UNIFORM_NAME ";\n"
|
||||
"layout (std430, binding = 1) buffer LayerColors"
|
||||
@ -126,6 +176,8 @@ namespace
|
||||
" }\n"
|
||||
" FragColor = vec4(current_color, 1);\n"
|
||||
"}";
|
||||
|
||||
constexpr const char* SCREEN_FRAGMENT_SHADER_SOURCE_PTR = SCREEN_FRAGMENT_SHADER_SOURCE;
|
||||
}
|
||||
|
||||
namespace glerminal
|
||||
@ -137,7 +189,7 @@ namespace glerminal
|
||||
m_sprites{ },
|
||||
m_layer_colors{ },
|
||||
m_layer_scales{ }
|
||||
#ifdef _DEBUG
|
||||
#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT
|
||||
, m_log("log.txt")
|
||||
#endif
|
||||
{
|
||||
@ -207,14 +259,12 @@ namespace glerminal
|
||||
update_layer_colors();
|
||||
update_layer_scales();
|
||||
|
||||
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
glUseProgram(m_program);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
|
||||
glBindVertexArray(m_vao);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, GRID_AREA * LAYER_COUNT);
|
||||
|
||||
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
glUseProgram(m_screen_program);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindVertexArray(m_screen_vao);
|
||||
@ -293,7 +343,7 @@ namespace glerminal
|
||||
glfwInit();
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
// not resizable for now.
|
||||
//
|
||||
@ -391,6 +441,7 @@ namespace glerminal
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
// -- setup vertex data --
|
||||
// create vertex buffer object
|
||||
@ -442,17 +493,20 @@ namespace glerminal
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_layer_colors_buffer);
|
||||
|
||||
// -- setup shader program --
|
||||
// test for features
|
||||
const bool vertex_shader_layer_supported = glfwExtensionSupported("GL_AMD_vertex_shader_layer");
|
||||
|
||||
// compile
|
||||
const unsigned int vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, &VERTEX_SHADER_SOURCE, nullptr);
|
||||
glShaderSource(vertex_shader, 1, &(vertex_shader_layer_supported ? VERTEX_SHADER_AMD_SOURCE_PTR : VERTEX_SHADER_SOURCE_PTR), nullptr);
|
||||
glCompileShader(vertex_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);
|
||||
|
||||
const unsigned int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, &FRAGMENT_SHADER_SOURCE, nullptr);
|
||||
glShaderSource(fragment_shader, 1, &(vertex_shader_layer_supported ? FRAGMENT_SHADER_AMD_SOURCE_PTR : FRAGMENT_SHADER_SOURCE_PTR), nullptr);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
constexpr int INFO_LOG_SIZE = 512;
|
||||
@ -499,7 +553,11 @@ namespace glerminal
|
||||
// link
|
||||
m_program = glCreateProgram();
|
||||
glAttachShader(m_program, vertex_shader);
|
||||
glAttachShader(m_program, geometry_shader);
|
||||
// only need geometry shader if AMD_vertex_shader_layer is not supported
|
||||
if (!vertex_shader_layer_supported)
|
||||
{
|
||||
glAttachShader(m_program, geometry_shader);
|
||||
}
|
||||
glAttachShader(m_program, fragment_shader);
|
||||
glLinkProgram(m_program);
|
||||
glDeleteShader(vertex_shader);
|
||||
@ -510,6 +568,8 @@ namespace glerminal
|
||||
glGetProgramiv(m_program, GL_LINK_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetProgramInfoLog(m_program, INFO_LOG_SIZE, nullptr, info_log);
|
||||
|
||||
glDeleteProgram(m_program);
|
||||
|
||||
throw std::runtime_error("Could not link shader program.");
|
||||
@ -523,11 +583,11 @@ namespace glerminal
|
||||
|
||||
// compile
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
// verify compile
|
||||
@ -665,7 +725,7 @@ void glerminal_run(glerminal_init_cb init, glerminal_main_cb main)
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
e.what();
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user