mirror of
https://git.shylie.info/shylie/glerminal.git
synced 2024-12-22 22:50:06 +00:00
Compare commits
No commits in common. "65c6de85ba4c334e5ead848d3496ce05045ce31a" and "11380a0d881f2921fe298e775f26f88544be7fec" have entirely different histories.
65c6de85ba
...
11380a0d88
@ -1,23 +1,22 @@
|
||||
/*
|
||||
|
||||
OpenGL loader generated by glad 0.1.36 on Mon May 27 15:25:59 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.5
|
||||
Profile: core
|
||||
Extensions:
|
||||
GL_AMD_vertex_shader_layer,
|
||||
GL_ARB_shader_viewport_layer_array
|
||||
GL_AMD_vertex_shader_layer
|
||||
Loader: True
|
||||
Local files: False
|
||||
Omit khrplatform: False
|
||||
Reproducible: False
|
||||
|
||||
Commandline:
|
||||
--profile="core" --api="gl=4.5" --generator="c" --spec="gl" --extensions="GL_AMD_vertex_shader_layer,GL_ARB_shader_viewport_layer_array"
|
||||
--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.5&extensions=GL_AMD_vertex_shader_layer&extensions=GL_ARB_shader_viewport_layer_array
|
||||
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>
|
||||
@ -970,7 +969,6 @@ PFNGLVIEWPORTINDEXEDFPROC glad_glViewportIndexedf = NULL;
|
||||
PFNGLVIEWPORTINDEXEDFVPROC glad_glViewportIndexedfv = NULL;
|
||||
PFNGLWAITSYNCPROC glad_glWaitSync = NULL;
|
||||
int GLAD_GL_AMD_vertex_shader_layer = 0;
|
||||
int GLAD_GL_ARB_shader_viewport_layer_array = 0;
|
||||
static void load_GL_VERSION_1_0(GLADloadproc load) {
|
||||
if(!GLAD_GL_VERSION_1_0) return;
|
||||
glad_glCullFace = (PFNGLCULLFACEPROC)load("glCullFace");
|
||||
@ -1727,7 +1725,6 @@ static void load_GL_VERSION_4_5(GLADloadproc load) {
|
||||
static int find_extensionsGL(void) {
|
||||
if (!get_exts()) return 0;
|
||||
GLAD_GL_AMD_vertex_shader_layer = has_ext("GL_AMD_vertex_shader_layer");
|
||||
GLAD_GL_ARB_shader_viewport_layer_array = has_ext("GL_ARB_shader_viewport_layer_array");
|
||||
free_exts();
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,23 +1,22 @@
|
||||
/*
|
||||
|
||||
OpenGL loader generated by glad 0.1.36 on Mon May 27 15:25:59 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.5
|
||||
Profile: core
|
||||
Extensions:
|
||||
GL_AMD_vertex_shader_layer,
|
||||
GL_ARB_shader_viewport_layer_array
|
||||
GL_AMD_vertex_shader_layer
|
||||
Loader: True
|
||||
Local files: False
|
||||
Omit khrplatform: False
|
||||
Reproducible: False
|
||||
|
||||
Commandline:
|
||||
--profile="core" --api="gl=4.5" --generator="c" --spec="gl" --extensions="GL_AMD_vertex_shader_layer,GL_ARB_shader_viewport_layer_array"
|
||||
--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.5&extensions=GL_AMD_vertex_shader_layer&extensions=GL_ARB_shader_viewport_layer_array
|
||||
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.5&extensions=GL_AMD_vertex_shader_layer
|
||||
*/
|
||||
|
||||
|
||||
@ -3653,10 +3652,6 @@ GLAPI PFNGLTEXTUREBARRIERPROC glad_glTextureBarrier;
|
||||
#define GL_AMD_vertex_shader_layer 1
|
||||
GLAPI int GLAD_GL_AMD_vertex_shader_layer;
|
||||
#endif
|
||||
#ifndef GL_ARB_shader_viewport_layer_array
|
||||
#define GL_ARB_shader_viewport_layer_array 1
|
||||
GLAPI int GLAD_GL_ARB_shader_viewport_layer_array;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -63,8 +63,6 @@ namespace glerminal
|
||||
unsigned int m_sprites_texture;
|
||||
unsigned int m_framebuffer;
|
||||
unsigned int m_framebuffer_backing_texture;
|
||||
unsigned int m_screen_framebuffer;
|
||||
unsigned int m_screen_framebuffer_backing_texture;
|
||||
unsigned int m_layer_colors_buffer;
|
||||
unsigned int m_layer_scales_buffer;
|
||||
unsigned int m_screen_size_uniform_location;
|
||||
@ -87,8 +85,8 @@ namespace glerminal
|
||||
|
||||
#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT
|
||||
mutable std::ofstream m_log;
|
||||
#endif
|
||||
void log(GLenum type, GLuint id, GLenum severity, const char* message) const;
|
||||
#endif
|
||||
|
||||
void init_glfw();
|
||||
void init_gl();
|
||||
|
@ -53,9 +53,8 @@ namespace
|
||||
"}";
|
||||
|
||||
// note: AMD_vertex_shader_layer support required
|
||||
constexpr char VERTEX_SHADER_ARB_SOURCE[] =
|
||||
constexpr char VERTEX_SHADER_AMD_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
"#extension GL_ARB_shader_viewport_layer_array : enable\n"
|
||||
"#extension GL_AMD_vertex_shader_layer : enable\n"
|
||||
"layout (location = 0) in vec2 position;\n"
|
||||
"layout (location = 1) in vec2 offset;\n"
|
||||
@ -82,7 +81,7 @@ namespace
|
||||
"}";
|
||||
|
||||
constexpr const char* VERTEX_SHADER_SOURCE_PTR = VERTEX_SHADER_SOURCE;
|
||||
constexpr const char* VERTEX_SHADER_ARB_SOURCE_PTR = VERTEX_SHADER_ARB_SOURCE;
|
||||
constexpr const char* VERTEX_SHADER_AMD_SOURCE_PTR = VERTEX_SHADER_AMD_SOURCE;
|
||||
|
||||
constexpr char GEOMETRY_SHADER_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
@ -129,7 +128,7 @@ namespace
|
||||
"}";
|
||||
|
||||
// note: AMD_vertex_shader_layer support required
|
||||
constexpr char FRAGMENT_SHADER_ARB_SOURCE[] =
|
||||
constexpr char FRAGMENT_SHADER_AMD_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
"in VS_OUT {\n"
|
||||
" flat int sprite;\n"
|
||||
@ -143,7 +142,7 @@ namespace
|
||||
"}";
|
||||
|
||||
constexpr const char* FRAGMENT_SHADER_SOURCE_PTR = FRAGMENT_SHADER_SOURCE;
|
||||
constexpr const char* FRAGMENT_SHADER_ARB_SOURCE_PTR = FRAGMENT_SHADER_ARB_SOURCE;
|
||||
constexpr const char* FRAGMENT_SHADER_AMD_SOURCE_PTR = FRAGMENT_SHADER_AMD_SOURCE;
|
||||
|
||||
constexpr char SCREEN_VERTEX_SHADER_SOURCE[] =
|
||||
"#version 450 core\n"
|
||||
@ -157,7 +156,7 @@ namespace
|
||||
|
||||
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"
|
||||
"in vec2 texcoord;\n"
|
||||
"layout (binding = 1) uniform sampler2DArray " LAYERS_UNIFORM_NAME ";\n"
|
||||
@ -267,13 +266,11 @@ namespace glerminal
|
||||
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, GRID_AREA * LAYER_COUNT);
|
||||
|
||||
glUseProgram(m_screen_program);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_screen_framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindVertexArray(m_screen_vao);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
glBlitNamedFramebuffer(m_screen_framebuffer, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
glfwSwapBuffers(m_window);
|
||||
}
|
||||
|
||||
@ -366,12 +363,12 @@ namespace glerminal
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT
|
||||
void glerminal::log(GLenum type, GLuint id, GLenum severity, const char* message) const
|
||||
{
|
||||
#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT
|
||||
glDebugMessageInsert(GL_DEBUG_SOURCE_THIRD_PARTY, type, id, severity, -1, message);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void glerminal::init_gl()
|
||||
{
|
||||
@ -497,12 +494,11 @@ namespace glerminal
|
||||
|
||||
// -- setup shader program --
|
||||
// test for features
|
||||
const bool vertex_shader_layer_supported =
|
||||
glfwExtensionSupported("GL_ARB_shader_viewport_layer_array") || glfwExtensionSupported("GL_AMD_vertex_shader_layer");
|
||||
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_layer_supported ? VERTEX_SHADER_ARB_SOURCE_PTR : VERTEX_SHADER_SOURCE_PTR), 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);
|
||||
@ -510,12 +506,12 @@ namespace glerminal
|
||||
glCompileShader(geometry_shader);
|
||||
|
||||
const unsigned int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, &(vertex_shader_layer_supported ? FRAGMENT_SHADER_ARB_SOURCE_PTR : FRAGMENT_SHADER_SOURCE_PTR), 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;
|
||||
int success;
|
||||
char info_log[INFO_LOG_SIZE + 1] = {};
|
||||
char info_log[INFO_LOG_SIZE];
|
||||
|
||||
// verify compile
|
||||
glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success);
|
||||
@ -527,9 +523,7 @@ namespace glerminal
|
||||
glDeleteShader(geometry_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
|
||||
log(GL_DEBUG_TYPE_ERROR, 0, 0, "Could not compile vertex shader.");
|
||||
log(GL_DEBUG_TYPE_ERROR, 0, 0, info_log);
|
||||
throw std::runtime_error("");
|
||||
throw std::runtime_error("Could not compile vertex shader.");
|
||||
}
|
||||
|
||||
glGetShaderiv(geometry_shader, GL_COMPILE_STATUS, &success);
|
||||
@ -541,9 +535,7 @@ namespace glerminal
|
||||
glDeleteShader(geometry_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
|
||||
log(GL_DEBUG_TYPE_ERROR, 1, 0, "Could not compile geometry shader.");
|
||||
log(GL_DEBUG_TYPE_ERROR, 1, 0, info_log);
|
||||
throw std::runtime_error("");
|
||||
throw std::runtime_error("Could not compile geometry shader.");
|
||||
}
|
||||
|
||||
glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success);
|
||||
@ -555,9 +547,7 @@ namespace glerminal
|
||||
glDeleteShader(geometry_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
|
||||
log(GL_DEBUG_TYPE_ERROR, 2, 0, "Could not compile fragment shader.");
|
||||
log(GL_DEBUG_TYPE_ERROR, 2, 0, info_log);
|
||||
throw std::runtime_error("");
|
||||
throw std::runtime_error("Could not compile fragment shader.");
|
||||
}
|
||||
|
||||
// link
|
||||
@ -582,9 +572,7 @@ namespace glerminal
|
||||
|
||||
glDeleteProgram(m_program);
|
||||
|
||||
log(GL_DEBUG_TYPE_ERROR, 3, 0, "Could not link shader program.");
|
||||
log(GL_DEBUG_TYPE_ERROR, 3, 0, info_log);
|
||||
throw std::runtime_error("");
|
||||
throw std::runtime_error("Could not link shader program.");
|
||||
}
|
||||
|
||||
// setup uniforms
|
||||
@ -611,9 +599,7 @@ namespace glerminal
|
||||
glDeleteShader(screen_vertex_shader);
|
||||
glDeleteShader(screen_fragment_shader);
|
||||
|
||||
log(GL_DEBUG_TYPE_ERROR, 4, 0, "Could not compile screen vertex shader.");
|
||||
log(GL_DEBUG_TYPE_ERROR, 4, 0, info_log);
|
||||
throw std::runtime_error("");
|
||||
throw std::runtime_error("Could not compile screen vertex shader.");
|
||||
}
|
||||
|
||||
glGetShaderiv(screen_fragment_shader, GL_COMPILE_STATUS, &success);
|
||||
@ -624,9 +610,7 @@ namespace glerminal
|
||||
glDeleteShader(screen_vertex_shader);
|
||||
glDeleteShader(screen_fragment_shader);
|
||||
|
||||
log(GL_DEBUG_TYPE_ERROR, 5, 0, "Could not compile screen fragment shader.");
|
||||
log(GL_DEBUG_TYPE_ERROR, 5, 0, info_log);
|
||||
throw std::runtime_error("");
|
||||
throw std::runtime_error("Could not compile screen fragment shader.");
|
||||
}
|
||||
|
||||
// link
|
||||
@ -643,15 +627,10 @@ namespace glerminal
|
||||
{
|
||||
glDeleteProgram(m_screen_program);
|
||||
|
||||
log(GL_DEBUG_TYPE_ERROR, 6, 0, "Could not link screen shader program.");
|
||||
log(GL_DEBUG_TYPE_ERROR, 6, 0, info_log);
|
||||
throw std::runtime_error("");
|
||||
throw std::runtime_error("Could not link screen shader program.");
|
||||
}
|
||||
|
||||
// setup uniforms for screen shader
|
||||
glUseProgram(m_screen_program);
|
||||
|
||||
glUniform1i(glGetUniformLocation(m_screen_program, LAYER_COUNT_UNIFORM_NAME), LAYER_COUNT);
|
||||
// setup uniforms later
|
||||
|
||||
// -- setup textures --
|
||||
glGenTextures(1, &m_sprites_texture);
|
||||
@ -691,24 +670,10 @@ namespace glerminal
|
||||
|
||||
glBindTextureUnit(1, m_framebuffer_backing_texture);
|
||||
|
||||
// -- setup screen framebuffer --
|
||||
glGenFramebuffers(1, &m_screen_framebuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_screen_framebuffer);
|
||||
// setup uniforms for screen shader
|
||||
glUseProgram(m_screen_program);
|
||||
|
||||
glGenTextures(1, &m_screen_framebuffer_backing_texture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_screen_framebuffer_backing_texture);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_screen_framebuffer_backing_texture, 0);
|
||||
glUniform1i(glGetUniformLocation(m_screen_program, LAYER_COUNT_UNIFORM_NAME), LAYER_COUNT);
|
||||
}
|
||||
|
||||
void glerminal::deinit_glfw()
|
||||
@ -720,8 +685,6 @@ namespace glerminal
|
||||
|
||||
void glerminal::deinit_gl()
|
||||
{
|
||||
glDeleteFramebuffers(1, &m_screen_framebuffer);
|
||||
glDeleteTextures(1, &m_screen_framebuffer_backing_texture);
|
||||
glDeleteFramebuffers(1, &m_framebuffer);
|
||||
glDeleteTextures(1, &m_framebuffer_backing_texture);
|
||||
glDeleteTextures(1, &m_sprites_texture);
|
||||
|
@ -13,12 +13,8 @@ namespace
|
||||
|
||||
void glerminal_test_save_image()
|
||||
{
|
||||
// -- DIRTY HACK --
|
||||
//
|
||||
// GL_TEXTURE_2D is not rebound after setting up screen framebuffer
|
||||
// This code will break if this behavior changes
|
||||
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
||||
glReadBuffer(GL_LEFT);
|
||||
glReadPixels(0, 0, GRID_WIDTH * CELL_SCALE * 8, GRID_HEIGHT * CELL_SCALE * 8, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
stbi_flip_vertically_on_write(true);
|
||||
stbi_write_png("image.png", GRID_WIDTH * CELL_SCALE * 8, GRID_HEIGHT * CELL_SCALE * 8, 3, pixels, 1280 * 3);
|
||||
|
Loading…
Reference in New Issue
Block a user