Load OpenGL through SDL instead of glad
gl.h lists the 62 functions the editor calls, loaded with SDL_GL_GetProcAddress into gl, as in smack-a-brother. The 25k lines of glad and KHR headers are gone.
This commit is contained in:
1 parent
7e81ea4259
commit
6f2fc8c196
18 files changed
+254
-25290
No files matched your search
+2
-2
@@ -59,7 +59,7 @@ endforeach()
|
|||||||
add_library(anm2ed_core STATIC ${CORE_SOURCES} external/pugixml/src/pugixml.cpp external/imgui/imgui.cpp
|
add_library(anm2ed_core STATIC ${CORE_SOURCES} external/pugixml/src/pugixml.cpp external/imgui/imgui.cpp
|
||||||
external/imgui/imgui_draw.cpp external/imgui/imgui_widgets.cpp external/imgui/imgui_tables.cpp
|
external/imgui/imgui_draw.cpp external/imgui/imgui_widgets.cpp external/imgui/imgui_tables.cpp
|
||||||
${CMAKE_BINARY_DIR}/embed/embed.c)
|
${CMAKE_BINARY_DIR}/embed/embed.c)
|
||||||
target_include_directories(anm2ed_core PUBLIC include external external/imgui external/glm external/stb src
|
target_include_directories(anm2ed_core PUBLIC external external/imgui external/glm external/stb src
|
||||||
${CMAKE_BINARY_DIR}/embed)
|
${CMAKE_BINARY_DIR}/embed)
|
||||||
target_link_libraries(anm2ed_core PUBLIC lunasvg simdjson SDL3::Headers)
|
target_link_libraries(anm2ed_core PUBLIC lunasvg simdjson SDL3::Headers)
|
||||||
target_compile_definitions(anm2ed_core PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
target_compile_definitions(anm2ed_core PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
@@ -69,7 +69,7 @@ target_compile_definitions(anm2ed_core PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
|||||||
file(GLOB_RECURSE APP_SOURCES CONFIGURE_DEPENDS src/*.cpp)
|
file(GLOB_RECURSE APP_SOURCES CONFIGURE_DEPENDS src/*.cpp)
|
||||||
list(REMOVE_ITEM APP_SOURCES ${CORE_SOURCES} ${CMAKE_SOURCE_DIR}/src/main.cpp)
|
list(REMOVE_ITEM APP_SOURCES ${CORE_SOURCES} ${CMAKE_SOURCE_DIR}/src/main.cpp)
|
||||||
set_source_files_properties(external/stb/stb_vorbis.c PROPERTIES COMPILE_OPTIONS -w)
|
set_source_files_properties(external/stb/stb_vorbis.c PROPERTIES COMPILE_OPTIONS -w)
|
||||||
add_library(anm2ed_app STATIC ${APP_SOURCES} external/stb/stb_vorbis.c include/glad/glad.cpp external/imgui/backends/imgui_impl_sdl3.cpp
|
add_library(anm2ed_app STATIC ${APP_SOURCES} external/stb/stb_vorbis.c external/imgui/backends/imgui_impl_sdl3.cpp
|
||||||
external/imgui/backends/imgui_impl_opengl3.cpp)
|
external/imgui/backends/imgui_impl_opengl3.cpp)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(PLATFORM_LIBRARIES opengl32 ws2_32 bcrypt imm32 version winmm shell32 ole32 advapi32 gdi32 user32 setupapi
|
set(PLATFORM_LIBRARIES opengl32 ws2_32 bcrypt imm32 version winmm shell32 ole32 advapi32 gdi32 user32 setupapi
|
||||||
|
|||||||
@@ -1,311 +0,0 @@
|
|||||||
#ifndef __khrplatform_h_
|
|
||||||
#define __khrplatform_h_
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
|
||||||
**
|
|
||||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
|
||||||
** copy of this software and/or associated documentation files (the
|
|
||||||
** "Materials"), to deal in the Materials without restriction, including
|
|
||||||
** without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
|
||||||
** permit persons to whom the Materials are furnished to do so, subject to
|
|
||||||
** the following conditions:
|
|
||||||
**
|
|
||||||
** The above copyright notice and this permission notice shall be included
|
|
||||||
** in all copies or substantial portions of the Materials.
|
|
||||||
**
|
|
||||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
||||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Khronos platform-specific types and definitions.
|
|
||||||
*
|
|
||||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
|
||||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
|
||||||
* The last semantic modification to khrplatform.h was at commit ID:
|
|
||||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
|
||||||
*
|
|
||||||
* Adopters may modify this file to suit their platform. Adopters are
|
|
||||||
* encouraged to submit platform specific modifications to the Khronos
|
|
||||||
* group so that they can be included in future versions of this file.
|
|
||||||
* Please submit changes by filing pull requests or issues on
|
|
||||||
* the EGL Registry repository linked above.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* See the Implementer's Guidelines for information about where this file
|
|
||||||
* should be located on your system and for more details of its use:
|
|
||||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
|
||||||
*
|
|
||||||
* This file should be included as
|
|
||||||
* #include <KHR/khrplatform.h>
|
|
||||||
* by Khronos client API header files that use its types and defines.
|
|
||||||
*
|
|
||||||
* The types in khrplatform.h should only be used to define API-specific types.
|
|
||||||
*
|
|
||||||
* Types defined in khrplatform.h:
|
|
||||||
* khronos_int8_t signed 8 bit
|
|
||||||
* khronos_uint8_t unsigned 8 bit
|
|
||||||
* khronos_int16_t signed 16 bit
|
|
||||||
* khronos_uint16_t unsigned 16 bit
|
|
||||||
* khronos_int32_t signed 32 bit
|
|
||||||
* khronos_uint32_t unsigned 32 bit
|
|
||||||
* khronos_int64_t signed 64 bit
|
|
||||||
* khronos_uint64_t unsigned 64 bit
|
|
||||||
* khronos_intptr_t signed same number of bits as a pointer
|
|
||||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
|
||||||
* khronos_ssize_t signed size
|
|
||||||
* khronos_usize_t unsigned size
|
|
||||||
* khronos_float_t signed 32 bit floating point
|
|
||||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
|
||||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
|
||||||
* nanoseconds
|
|
||||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
|
||||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
|
||||||
* only be used as a base type when a client API's boolean type is
|
|
||||||
* an enum. Client APIs which use an integer or other type for
|
|
||||||
* booleans cannot use this as the base type for their boolean.
|
|
||||||
*
|
|
||||||
* Tokens defined in khrplatform.h:
|
|
||||||
*
|
|
||||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
|
||||||
*
|
|
||||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
|
||||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
|
||||||
*
|
|
||||||
* Calling convention macros defined in this file:
|
|
||||||
* KHRONOS_APICALL
|
|
||||||
* KHRONOS_APIENTRY
|
|
||||||
* KHRONOS_APIATTRIBUTES
|
|
||||||
*
|
|
||||||
* These may be used in function prototypes as:
|
|
||||||
*
|
|
||||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
|
||||||
* int arg1,
|
|
||||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
|
||||||
# define KHRONOS_STATIC 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* Definition of KHRONOS_APICALL
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
* This precedes the return type of the function in the function prototype.
|
|
||||||
*/
|
|
||||||
#if defined(KHRONOS_STATIC)
|
|
||||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
|
||||||
* header compatible with static linking. */
|
|
||||||
# define KHRONOS_APICALL
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
# define KHRONOS_APICALL __declspec(dllimport)
|
|
||||||
#elif defined (__SYMBIAN32__)
|
|
||||||
# define KHRONOS_APICALL IMPORT_C
|
|
||||||
#elif defined(__ANDROID__)
|
|
||||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
# define KHRONOS_APICALL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* Definition of KHRONOS_APIENTRY
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
* This follows the return type of the function and precedes the function
|
|
||||||
* name in the function prototype.
|
|
||||||
*/
|
|
||||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
|
||||||
/* Win32 but not WinCE */
|
|
||||||
# define KHRONOS_APIENTRY __stdcall
|
|
||||||
#else
|
|
||||||
# define KHRONOS_APIENTRY
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* Definition of KHRONOS_APIATTRIBUTES
|
|
||||||
*-------------------------------------------------------------------------
|
|
||||||
* This follows the closing parenthesis of the function prototype arguments.
|
|
||||||
*/
|
|
||||||
#if defined (__ARMCC_2__)
|
|
||||||
#define KHRONOS_APIATTRIBUTES __softfp
|
|
||||||
#else
|
|
||||||
#define KHRONOS_APIATTRIBUTES
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
|
||||||
* basic type definitions
|
|
||||||
*-----------------------------------------------------------------------*/
|
|
||||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Using <stdint.h>
|
|
||||||
*/
|
|
||||||
#include <stdint.h>
|
|
||||||
typedef int32_t khronos_int32_t;
|
|
||||||
typedef uint32_t khronos_uint32_t;
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
/*
|
|
||||||
* To support platform where unsigned long cannot be used interchangeably with
|
|
||||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
|
||||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
|
||||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
|
||||||
* unsigned long long or similar (this results in different C++ name mangling).
|
|
||||||
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
|
||||||
* platforms where the size of a pointer is larger than the size of long.
|
|
||||||
*/
|
|
||||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
|
||||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
|
||||||
#define KHRONOS_USE_INTPTR_T
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(__VMS ) || defined(__sgi)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Using <inttypes.h>
|
|
||||||
*/
|
|
||||||
#include <inttypes.h>
|
|
||||||
typedef int32_t khronos_int32_t;
|
|
||||||
typedef uint32_t khronos_uint32_t;
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Win32
|
|
||||||
*/
|
|
||||||
typedef __int32 khronos_int32_t;
|
|
||||||
typedef unsigned __int32 khronos_uint32_t;
|
|
||||||
typedef __int64 khronos_int64_t;
|
|
||||||
typedef unsigned __int64 khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#elif defined(__sun__) || defined(__digital__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Sun or Digital
|
|
||||||
*/
|
|
||||||
typedef int khronos_int32_t;
|
|
||||||
typedef unsigned int khronos_uint32_t;
|
|
||||||
#if defined(__arch64__) || defined(_LP64)
|
|
||||||
typedef long int khronos_int64_t;
|
|
||||||
typedef unsigned long int khronos_uint64_t;
|
|
||||||
#else
|
|
||||||
typedef long long int khronos_int64_t;
|
|
||||||
typedef unsigned long long int khronos_uint64_t;
|
|
||||||
#endif /* __arch64__ */
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#elif 0
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hypothetical platform with no float or int64 support
|
|
||||||
*/
|
|
||||||
typedef int khronos_int32_t;
|
|
||||||
typedef unsigned int khronos_uint32_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 0
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 0
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Generic fallback
|
|
||||||
*/
|
|
||||||
#include <stdint.h>
|
|
||||||
typedef int32_t khronos_int32_t;
|
|
||||||
typedef uint32_t khronos_uint32_t;
|
|
||||||
typedef int64_t khronos_int64_t;
|
|
||||||
typedef uint64_t khronos_uint64_t;
|
|
||||||
#define KHRONOS_SUPPORT_INT64 1
|
|
||||||
#define KHRONOS_SUPPORT_FLOAT 1
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Types that are (so far) the same on all platforms
|
|
||||||
*/
|
|
||||||
typedef signed char khronos_int8_t;
|
|
||||||
typedef unsigned char khronos_uint8_t;
|
|
||||||
typedef signed short int khronos_int16_t;
|
|
||||||
typedef unsigned short int khronos_uint16_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
|
||||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
|
||||||
* to be the only LLP64 architecture in current use.
|
|
||||||
*/
|
|
||||||
#ifdef KHRONOS_USE_INTPTR_T
|
|
||||||
typedef intptr_t khronos_intptr_t;
|
|
||||||
typedef uintptr_t khronos_uintptr_t;
|
|
||||||
#elif defined(_WIN64)
|
|
||||||
typedef signed long long int khronos_intptr_t;
|
|
||||||
typedef unsigned long long int khronos_uintptr_t;
|
|
||||||
#else
|
|
||||||
typedef signed long int khronos_intptr_t;
|
|
||||||
typedef unsigned long int khronos_uintptr_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN64)
|
|
||||||
typedef signed long long int khronos_ssize_t;
|
|
||||||
typedef unsigned long long int khronos_usize_t;
|
|
||||||
#else
|
|
||||||
typedef signed long int khronos_ssize_t;
|
|
||||||
typedef unsigned long int khronos_usize_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if KHRONOS_SUPPORT_FLOAT
|
|
||||||
/*
|
|
||||||
* Float type
|
|
||||||
*/
|
|
||||||
typedef float khronos_float_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if KHRONOS_SUPPORT_INT64
|
|
||||||
/* Time types
|
|
||||||
*
|
|
||||||
* These types can be used to represent a time interval in nanoseconds or
|
|
||||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
|
||||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
|
||||||
* time the system booted). The Unadjusted System Time is an unsigned
|
|
||||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
|
||||||
* may be either signed or unsigned.
|
|
||||||
*/
|
|
||||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
|
||||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Dummy value used to pad enum types to 32 bits.
|
|
||||||
*/
|
|
||||||
#ifndef KHRONOS_MAX_ENUM
|
|
||||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Enumerated boolean type
|
|
||||||
*
|
|
||||||
* Values other than zero should be considered to be true. Therefore
|
|
||||||
* comparisons should not be made against KHRONOS_TRUE.
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
KHRONOS_FALSE = 0,
|
|
||||||
KHRONOS_TRUE = 1,
|
|
||||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
|
||||||
} khronos_boolean_enum_t;
|
|
||||||
|
|
||||||
#endif /* __khrplatform_h_ */
|
|
||||||
File diff suppressed because it is too large.
Load diff
-15776
File diff suppressed because it is too large.
Load diff
+75
-75
@@ -12,24 +12,24 @@ using namespace glm;
|
|||||||
|
|
||||||
static void canvas_blend_premultiplied_set()
|
static void canvas_blend_premultiplied_set()
|
||||||
{
|
{
|
||||||
glEnable(GL_BLEND);
|
gl.Enable(GL_BLEND);
|
||||||
glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
gl.BlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void canvas_blend_straight_set()
|
static void canvas_blend_straight_set()
|
||||||
{
|
{
|
||||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glEnable(GL_BLEND);
|
gl.Enable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vertex_array_make(GLuint& vao, GLuint& vbo, const void* data, GLsizeiptr size, GLenum usage,
|
static void vertex_array_make(GLuint& vao, GLuint& vbo, const void* data, GLsizeiptr size, GLenum usage,
|
||||||
std::initializer_list<int> attributeSizes)
|
std::initializer_list<int> attributeSizes)
|
||||||
{
|
{
|
||||||
glGenVertexArrays(1, &vao);
|
gl.GenVertexArrays(1, &vao);
|
||||||
glGenBuffers(1, &vbo);
|
gl.GenBuffers(1, &vbo);
|
||||||
glBindVertexArray(vao);
|
gl.BindVertexArray(vao);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
gl.BindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, size, data, usage);
|
gl.BufferData(GL_ARRAY_BUFFER, size, data, usage);
|
||||||
|
|
||||||
auto stride = 0;
|
auto stride = 0;
|
||||||
for (auto attributeSize : attributeSizes)
|
for (auto attributeSize : attributeSizes)
|
||||||
@@ -38,8 +38,8 @@ static void vertex_array_make(GLuint& vao, GLuint& vbo, const void* data, GLsize
|
|||||||
auto index = 0;
|
auto index = 0;
|
||||||
for (auto attributeSize : attributeSizes)
|
for (auto attributeSize : attributeSizes)
|
||||||
{
|
{
|
||||||
glEnableVertexAttribArray(index);
|
gl.EnableVertexAttribArray(index);
|
||||||
glVertexAttribPointer(index++, attributeSize, GL_FLOAT, GL_FALSE, stride * sizeof(float),
|
gl.VertexAttribPointer(index++, attributeSize, GL_FLOAT, GL_FALSE, stride * sizeof(float),
|
||||||
(void*)(offset * sizeof(float)));
|
(void*)(offset * sizeof(float)));
|
||||||
offset += attributeSize;
|
offset += attributeSize;
|
||||||
}
|
}
|
||||||
@@ -54,10 +54,10 @@ Canvas::Canvas(vec2 size)
|
|||||||
vertex_array_make(gridVAO, gridVBO, GRID_VERTICES, sizeof(GRID_VERTICES), GL_STATIC_DRAW, {2, 2});
|
vertex_array_make(gridVAO, gridVBO, GRID_VERTICES, sizeof(GRID_VERTICES), GL_STATIC_DRAW, {2, 2});
|
||||||
vertex_array_make(rectVAO, rectVBO, RECT_VERTICES, sizeof(RECT_VERTICES), GL_STATIC_DRAW, {2});
|
vertex_array_make(rectVAO, rectVBO, RECT_VERTICES, sizeof(RECT_VERTICES), GL_STATIC_DRAW, {2});
|
||||||
vertex_array_make(textureVAO, textureVBO, nullptr, sizeof(TEXTURE_VERTICES), GL_DYNAMIC_DRAW, {2, 2});
|
vertex_array_make(textureVAO, textureVBO, nullptr, sizeof(TEXTURE_VERTICES), GL_DYNAMIC_DRAW, {2, 2});
|
||||||
glGenBuffers(1, &textureEBO);
|
gl.GenBuffers(1, &textureEBO);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, textureEBO);
|
gl.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, textureEBO);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(TEXTURE_INDICES), TEXTURE_INDICES, GL_DYNAMIC_DRAW);
|
gl.BufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(TEXTURE_INDICES), TEXTURE_INDICES, GL_DYNAMIC_DRAW);
|
||||||
glBindVertexArray(0);
|
gl.BindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas::~Canvas()
|
Canvas::~Canvas()
|
||||||
@@ -65,9 +65,9 @@ Canvas::~Canvas()
|
|||||||
if (!Framebuffer::is_valid())
|
if (!Framebuffer::is_valid())
|
||||||
return;
|
return;
|
||||||
for (auto vao : {axisVAO, gridVAO, rectVAO, textureVAO})
|
for (auto vao : {axisVAO, gridVAO, rectVAO, textureVAO})
|
||||||
glDeleteVertexArrays(1, &vao);
|
gl.DeleteVertexArrays(1, &vao);
|
||||||
for (auto buffer : {axisVBO, gridVBO, rectVBO, textureVBO, textureEBO})
|
for (auto buffer : {axisVBO, gridVBO, rectVBO, textureVBO, textureEBO})
|
||||||
glDeleteBuffers(1, &buffer);
|
gl.DeleteBuffers(1, &buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 Canvas::transform_get(float zoom, vec2 pan) const
|
mat4 Canvas::transform_get(float zoom, vec2 pan) const
|
||||||
@@ -89,21 +89,21 @@ void Canvas::axes_render(ShaderProgram& shader, float zoom, vec2 pan, vec4 color
|
|||||||
auto originNDC = transform_get(zoom, pan) * vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
auto originNDC = transform_get(zoom, pan) * vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
originNDC /= originNDC.w;
|
originNDC /= originNDC.w;
|
||||||
|
|
||||||
glUseProgram(shader.id);
|
gl.UseProgram(shader.id);
|
||||||
|
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_COLOR), 1, value_ptr(color));
|
gl.Uniform4fv(gl.GetUniformLocation(shader.id, UNIFORM_COLOR), 1, value_ptr(color));
|
||||||
glUniform2f(glGetUniformLocation(shader.id, UNIFORM_ORIGIN_NDC), originNDC.x, originNDC.y);
|
gl.Uniform2f(gl.GetUniformLocation(shader.id, UNIFORM_ORIGIN_NDC), originNDC.x, originNDC.y);
|
||||||
|
|
||||||
glBindVertexArray(axisVAO);
|
gl.BindVertexArray(axisVAO);
|
||||||
|
|
||||||
glUniform1i(glGetUniformLocation(shader.id, UNIFORM_AXIS), 0);
|
gl.Uniform1i(gl.GetUniformLocation(shader.id, UNIFORM_AXIS), 0);
|
||||||
glDrawArrays(GL_LINES, 0, 2);
|
gl.DrawArrays(GL_LINES, 0, 2);
|
||||||
|
|
||||||
glUniform1i(glGetUniformLocation(shader.id, UNIFORM_AXIS), 1);
|
gl.Uniform1i(gl.GetUniformLocation(shader.id, UNIFORM_AXIS), 1);
|
||||||
glDrawArrays(GL_LINES, 0, 2);
|
gl.DrawArrays(GL_LINES, 0, 2);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
gl.BindVertexArray(0);
|
||||||
glUseProgram(0);
|
gl.UseProgram(0);
|
||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,36 +113,36 @@ void Canvas::grid_render(ShaderProgram& shader, float zoom, vec2 pan, ivec2 size
|
|||||||
|
|
||||||
auto transform = glm::inverse(transform_get(zoom, pan));
|
auto transform = glm::inverse(transform_get(zoom, pan));
|
||||||
|
|
||||||
glUseProgram(shader.id);
|
gl.UseProgram(shader.id);
|
||||||
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.id, UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
gl.UniformMatrix4fv(gl.GetUniformLocation(shader.id, UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
||||||
glUniform2f(glGetUniformLocation(shader.id, UNIFORM_SIZE), (float)size.x, (float)size.y);
|
gl.Uniform2f(gl.GetUniformLocation(shader.id, UNIFORM_SIZE), (float)size.x, (float)size.y);
|
||||||
glUniform2f(glGetUniformLocation(shader.id, UNIFORM_OFFSET), (float)offset.x, (float)offset.y);
|
gl.Uniform2f(gl.GetUniformLocation(shader.id, UNIFORM_OFFSET), (float)offset.x, (float)offset.y);
|
||||||
glUniform4f(glGetUniformLocation(shader.id, UNIFORM_COLOR), color.r, color.g, color.b, color.a);
|
gl.Uniform4f(gl.GetUniformLocation(shader.id, UNIFORM_COLOR), color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
glBindVertexArray(gridVAO);
|
gl.BindVertexArray(gridVAO);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
gl.DrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
glBindVertexArray(0);
|
gl.BindVertexArray(0);
|
||||||
|
|
||||||
glUseProgram(0);
|
gl.UseProgram(0);
|
||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void texture_uniform_set(const ShaderUniform& uniform, vec4 value)
|
static void texture_uniform_set(const ShaderUniform& uniform, vec4 value)
|
||||||
{
|
{
|
||||||
if (uniform.valueType == UNIFORM_VALUE_INT || uniform.valueType == UNIFORM_VALUE_SAMPLER2D)
|
if (uniform.valueType == UNIFORM_VALUE_INT || uniform.valueType == UNIFORM_VALUE_SAMPLER2D)
|
||||||
return glUniform1i(uniform.location, uniform.intValue);
|
return gl.Uniform1i(uniform.location, uniform.intValue);
|
||||||
switch (UNIFORM_VALUE_TYPE_INFOS[uniform.valueType].componentCount)
|
switch (UNIFORM_VALUE_TYPE_INFOS[uniform.valueType].componentCount)
|
||||||
{
|
{
|
||||||
case 2:
|
case 2:
|
||||||
return glUniform2fv(uniform.location, 1, value_ptr(value));
|
return gl.Uniform2fv(uniform.location, 1, value_ptr(value));
|
||||||
case 3:
|
case 3:
|
||||||
return glUniform3fv(uniform.location, 1, value_ptr(value));
|
return gl.Uniform3fv(uniform.location, 1, value_ptr(value));
|
||||||
case 4:
|
case 4:
|
||||||
return glUniform4fv(uniform.location, 1, value_ptr(value));
|
return gl.Uniform4fv(uniform.location, 1, value_ptr(value));
|
||||||
default:
|
default:
|
||||||
if (uniform.valueType == UNIFORM_VALUE_FLOAT)
|
if (uniform.valueType == UNIFORM_VALUE_FLOAT)
|
||||||
glUniform1f(uniform.location, value.x);
|
gl.Uniform1f(uniform.location, value.x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,10 +160,10 @@ static void texture_uniforms_set(ShaderProgram& shader, mat4 transform, vec4 tin
|
|||||||
{
|
{
|
||||||
if (shader.uniforms.empty())
|
if (shader.uniforms.empty())
|
||||||
{
|
{
|
||||||
glUniform1i(glGetUniformLocation(shader.id, UNIFORM_TEXTURE), 0);
|
gl.Uniform1i(gl.GetUniformLocation(shader.id, UNIFORM_TEXTURE), 0);
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_COLOR_OFFSET), 1, value_ptr(colorOffset));
|
gl.Uniform4fv(gl.GetUniformLocation(shader.id, UNIFORM_COLOR_OFFSET), 1, value_ptr(colorOffset));
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_TINT), 1, value_ptr(tint));
|
gl.Uniform4fv(gl.GetUniformLocation(shader.id, UNIFORM_TINT), 1, value_ptr(tint));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.id, UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
gl.UniformMatrix4fv(gl.GetUniformLocation(shader.id, UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,11 +175,11 @@ static void texture_uniforms_set(ShaderProgram& shader, mat4 transform, vec4 tin
|
|||||||
switch (uniform.binding)
|
switch (uniform.binding)
|
||||||
{
|
{
|
||||||
case UNIFORM_BINDING_MAIN_TEXTURE:
|
case UNIFORM_BINDING_MAIN_TEXTURE:
|
||||||
glUniform1i(uniform.location, 0);
|
gl.Uniform1i(uniform.location, 0);
|
||||||
break;
|
break;
|
||||||
case UNIFORM_BINDING_TRANSFORM:
|
case UNIFORM_BINDING_TRANSFORM:
|
||||||
if (uniform.valueType == UNIFORM_VALUE_MAT4)
|
if (uniform.valueType == UNIFORM_VALUE_MAT4)
|
||||||
glUniformMatrix4fv(uniform.location, 1, GL_FALSE, value_ptr(transform));
|
gl.UniformMatrix4fv(uniform.location, 1, GL_FALSE, value_ptr(transform));
|
||||||
break;
|
break;
|
||||||
case UNIFORM_BINDING_FRAME_TINT:
|
case UNIFORM_BINDING_FRAME_TINT:
|
||||||
texture_uniform_set(uniform, tint);
|
texture_uniform_set(uniform, tint);
|
||||||
@@ -210,30 +210,30 @@ void Canvas::texture_render(ShaderProgram& shader, GLuint texture, mat4 transfor
|
|||||||
{
|
{
|
||||||
canvas_blend_premultiplied_set();
|
canvas_blend_premultiplied_set();
|
||||||
|
|
||||||
glUseProgram(shader.id);
|
gl.UseProgram(shader.id);
|
||||||
|
|
||||||
texture_uniforms_set(shader, transform, tint, colorOffset, textureSize, playbackTime);
|
texture_uniforms_set(shader, transform, tint, colorOffset, textureSize, playbackTime);
|
||||||
// The editor's own texture shader blurs. A custom shader without these uniforms ignores them.
|
// The editor's own texture shader blurs. A custom shader without these uniforms ignores them.
|
||||||
glUniform1f(glGetUniformLocation(shader.id, UNIFORM_BLUR), blur.radius);
|
gl.Uniform1f(gl.GetUniformLocation(shader.id, UNIFORM_BLUR), blur.radius);
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_REGION), 1, value_ptr(blur.region));
|
gl.Uniform4fv(gl.GetUniformLocation(shader.id, UNIFORM_REGION), 1, value_ptr(blur.region));
|
||||||
glUniform2fv(glGetUniformLocation(shader.id, UNIFORM_TEXEL), 1,
|
gl.Uniform2fv(gl.GetUniformLocation(shader.id, UNIFORM_TEXEL), 1,
|
||||||
value_ptr(textureSize.x > 0 && textureSize.y > 0 ? 1.0f / textureSize : vec2()));
|
value_ptr(textureSize.x > 0 && textureSize.y > 0 ? 1.0f / textureSize : vec2()));
|
||||||
glVertexAttrib4fv(2, value_ptr(tint));
|
gl.VertexAttrib4fv(2, value_ptr(tint));
|
||||||
|
|
||||||
glBindVertexArray(textureVAO);
|
gl.BindVertexArray(textureVAO);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, textureVBO);
|
gl.BindBuffer(GL_ARRAY_BUFFER, textureVBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(TEXTURE_VERTICES), vertices, GL_DYNAMIC_DRAW);
|
gl.BufferData(GL_ARRAY_BUFFER, sizeof(TEXTURE_VERTICES), vertices, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
gl.ActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
gl.BindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
gl.DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
gl.BindVertexArray(0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
gl.BindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
gl.BindTexture(GL_TEXTURE_2D, 0);
|
||||||
glUseProgram(0);
|
gl.UseProgram(0);
|
||||||
|
|
||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
@@ -241,19 +241,19 @@ void Canvas::texture_render(ShaderProgram& shader, GLuint texture, mat4 transfor
|
|||||||
static void rect_begin(ShaderProgram& shader, const mat4& transform, const mat4& model, vec4 color)
|
static void rect_begin(ShaderProgram& shader, const mat4& transform, const mat4& model, vec4 color)
|
||||||
{
|
{
|
||||||
canvas_blend_premultiplied_set();
|
canvas_blend_premultiplied_set();
|
||||||
glUseProgram(shader.id);
|
gl.UseProgram(shader.id);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.id, UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
gl.UniformMatrix4fv(gl.GetUniformLocation(shader.id, UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
||||||
if (auto location = glGetUniformLocation(shader.id, UNIFORM_MODEL); location != -1)
|
if (auto location = gl.GetUniformLocation(shader.id, UNIFORM_MODEL); location != -1)
|
||||||
glUniformMatrix4fv(location, 1, GL_FALSE, value_ptr(model));
|
gl.UniformMatrix4fv(location, 1, GL_FALSE, value_ptr(model));
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_COLOR), 1, value_ptr(color));
|
gl.Uniform4fv(gl.GetUniformLocation(shader.id, UNIFORM_COLOR), 1, value_ptr(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rect_end(GLuint vao, GLenum mode, int count = 4)
|
static void rect_end(GLuint vao, GLenum mode, int count = 4)
|
||||||
{
|
{
|
||||||
glBindVertexArray(vao);
|
gl.BindVertexArray(vao);
|
||||||
glDrawArrays(mode, 0, count);
|
gl.DrawArrays(mode, 0, count);
|
||||||
glBindVertexArray(0);
|
gl.BindVertexArray(0);
|
||||||
glUseProgram(0);
|
gl.UseProgram(0);
|
||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,12 +265,12 @@ void Canvas::dashed_render(ShaderProgram& shader, const mat4& transform, const m
|
|||||||
auto origin = model * vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
auto origin = model * vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
for (auto [name, axis] : {std::pair{UNIFORM_AXIS_X, vec4(1.0f, 0.0f, 0.0f, 1.0f)},
|
for (auto [name, axis] : {std::pair{UNIFORM_AXIS_X, vec4(1.0f, 0.0f, 0.0f, 1.0f)},
|
||||||
std::pair{UNIFORM_AXIS_Y, vec4(0.0f, 1.0f, 0.0f, 1.0f)}})
|
std::pair{UNIFORM_AXIS_Y, vec4(0.0f, 1.0f, 0.0f, 1.0f)}})
|
||||||
if (auto location = glGetUniformLocation(shader.id, name); location != -1)
|
if (auto location = gl.GetUniformLocation(shader.id, name); location != -1)
|
||||||
glUniform2fv(location, 1, value_ptr(vec2(model * axis - origin)));
|
gl.Uniform2fv(location, 1, value_ptr(vec2(model * axis - origin)));
|
||||||
for (auto [name, value] : {std::pair{UNIFORM_DASH_LENGTH, dashLength}, std::pair{UNIFORM_DASH_GAP, dashGap},
|
for (auto [name, value] : {std::pair{UNIFORM_DASH_LENGTH, dashLength}, std::pair{UNIFORM_DASH_GAP, dashGap},
|
||||||
std::pair{UNIFORM_DASH_OFFSET, dashOffset}})
|
std::pair{UNIFORM_DASH_OFFSET, dashOffset}})
|
||||||
if (auto location = glGetUniformLocation(shader.id, name); location != -1)
|
if (auto location = gl.GetUniformLocation(shader.id, name); location != -1)
|
||||||
glUniform1f(location, value);
|
gl.Uniform1f(location, value);
|
||||||
|
|
||||||
rect_end(rectVAO, mode, count);
|
rect_end(rectVAO, mode, count);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include "gl.h"
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
|
|||||||
+28
-28
@@ -6,9 +6,9 @@ using namespace glm;
|
|||||||
|
|
||||||
Framebuffer::Framebuffer()
|
Framebuffer::Framebuffer()
|
||||||
{
|
{
|
||||||
glGenFramebuffers(1, &fbo);
|
gl.GenFramebuffers(1, &fbo);
|
||||||
glGenRenderbuffers(1, &rbo);
|
gl.GenRenderbuffers(1, &rbo);
|
||||||
glGenTextures(1, &texture);
|
gl.GenTextures(1, &texture);
|
||||||
set();
|
set();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,27 +17,27 @@ Framebuffer::~Framebuffer()
|
|||||||
if (!is_valid())
|
if (!is_valid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glDeleteFramebuffers(1, &fbo);
|
gl.DeleteFramebuffers(1, &fbo);
|
||||||
glDeleteRenderbuffers(1, &rbo);
|
gl.DeleteRenderbuffers(1, &rbo);
|
||||||
glDeleteTextures(1, &texture);
|
gl.DeleteTextures(1, &texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::set()
|
void Framebuffer::set()
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
gl.BindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
gl.BindTexture(GL_TEXTURE_2D, texture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||||
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
gl.BindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, size.x, size.y);
|
gl.RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, size.x, size.y);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::resize_check()
|
void Framebuffer::resize_check()
|
||||||
@@ -61,23 +61,23 @@ std::vector<uint8_t> Framebuffer::pixels_get() const
|
|||||||
auto count = size.x * size.y * IMAGE_CHANNELS;
|
auto count = size.x * size.y * IMAGE_CHANNELS;
|
||||||
std::vector<uint8_t> pixels(count);
|
std::vector<uint8_t> pixels(count);
|
||||||
|
|
||||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
gl.ReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
gl.PixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
gl.PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||||
glReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
|
gl.ReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
return pixels;
|
return pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::clear(vec4 color) const
|
void Framebuffer::clear(vec4 color) const
|
||||||
{
|
{
|
||||||
glEnable(GL_BLEND);
|
gl.Enable(GL_BLEND);
|
||||||
glClearColor(color.r, color.g, color.b, color.a);
|
gl.ClearColor(color.r, color.g, color.b, color.a);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
gl.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
if (color.a <= 0.0f)
|
if (color.a <= 0.0f)
|
||||||
glDisable(GL_BLEND);
|
gl.Disable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Framebuffer::is_valid() const
|
bool Framebuffer::is_valid() const
|
||||||
@@ -87,15 +87,15 @@ bool Framebuffer::is_valid() const
|
|||||||
|
|
||||||
void Framebuffer::viewport_set() const
|
void Framebuffer::viewport_set() const
|
||||||
{
|
{
|
||||||
glViewport(0, 0, size.x, size.y);
|
gl.Viewport(0, 0, size.x, size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::bind() const
|
void Framebuffer::bind() const
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
gl.BindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::unbind() const
|
void Framebuffer::unbind() const
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include "gl.h"
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
class Framebuffer
|
class Framebuffer
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
#include "gl.h"
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
Gl gl;
|
||||||
|
|
||||||
|
bool gl_load()
|
||||||
|
{
|
||||||
|
bool isLoaded = true;
|
||||||
|
#define X(name) \
|
||||||
|
gl.name = (decltype(gl.name))SDL_GL_GetProcAddress("gl" #name); \
|
||||||
|
isLoaded &= gl.name != nullptr;
|
||||||
|
GL_FUNCTIONS(X)
|
||||||
|
#undef X
|
||||||
|
return isLoaded;
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define GL_GLEXT_PROTOTYPES
|
||||||
|
#include <SDL3/SDL_opengl.h>
|
||||||
|
|
||||||
|
#define GL_FUNCTIONS(X) \
|
||||||
|
X(ActiveTexture) \
|
||||||
|
X(AttachShader) \
|
||||||
|
X(BindAttribLocation) \
|
||||||
|
X(BindBuffer) \
|
||||||
|
X(BindFramebuffer) \
|
||||||
|
X(BindRenderbuffer) \
|
||||||
|
X(BindTexture) \
|
||||||
|
X(BindVertexArray) \
|
||||||
|
X(BlendFuncSeparate) \
|
||||||
|
X(BufferData) \
|
||||||
|
X(Clear) \
|
||||||
|
X(ClearColor) \
|
||||||
|
X(CompileShader) \
|
||||||
|
X(CreateProgram) \
|
||||||
|
X(CreateShader) \
|
||||||
|
X(DeleteBuffers) \
|
||||||
|
X(DeleteFramebuffers) \
|
||||||
|
X(DeleteProgram) \
|
||||||
|
X(DeleteRenderbuffers) \
|
||||||
|
X(DeleteShader) \
|
||||||
|
X(DeleteTextures) \
|
||||||
|
X(DeleteVertexArrays) \
|
||||||
|
X(Disable) \
|
||||||
|
X(DrawArrays) \
|
||||||
|
X(DrawElements) \
|
||||||
|
X(Enable) \
|
||||||
|
X(EnableVertexAttribArray) \
|
||||||
|
X(FramebufferRenderbuffer) \
|
||||||
|
X(FramebufferTexture2D) \
|
||||||
|
X(GenBuffers) \
|
||||||
|
X(GenFramebuffers) \
|
||||||
|
X(GenRenderbuffers) \
|
||||||
|
X(GenTextures) \
|
||||||
|
X(GenVertexArrays) \
|
||||||
|
X(GetActiveUniform) \
|
||||||
|
X(GetProgramInfoLog) \
|
||||||
|
X(GetProgramiv) \
|
||||||
|
X(GetShaderInfoLog) \
|
||||||
|
X(GetShaderiv) \
|
||||||
|
X(GetString) \
|
||||||
|
X(GetUniformLocation) \
|
||||||
|
X(LineWidth) \
|
||||||
|
X(LinkProgram) \
|
||||||
|
X(PixelStorei) \
|
||||||
|
X(ReadBuffer) \
|
||||||
|
X(ReadPixels) \
|
||||||
|
X(RenderbufferStorage) \
|
||||||
|
X(ShaderSource) \
|
||||||
|
X(TexImage2D) \
|
||||||
|
X(TexParameteri) \
|
||||||
|
X(Uniform1f) \
|
||||||
|
X(Uniform1i) \
|
||||||
|
X(Uniform2f) \
|
||||||
|
X(Uniform2fv) \
|
||||||
|
X(Uniform3fv) \
|
||||||
|
X(Uniform4f) \
|
||||||
|
X(Uniform4fv) \
|
||||||
|
X(UniformMatrix4fv) \
|
||||||
|
X(UseProgram) \
|
||||||
|
X(VertexAttrib4fv) \
|
||||||
|
X(VertexAttribPointer) \
|
||||||
|
X(Viewport)
|
||||||
|
|
||||||
|
// The OpenGL functions the editor calls, through pointers loaded by gl_load once a context is current.
|
||||||
|
struct Gl
|
||||||
|
{
|
||||||
|
#define X(name) decltype(&gl##name) name = nullptr;
|
||||||
|
GL_FUNCTIONS(X)
|
||||||
|
#undef X
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Gl gl;
|
||||||
|
|
||||||
|
bool gl_load();
|
||||||
+7
-7
@@ -213,20 +213,20 @@ Loader::Loader(int argc, const char** argv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gladLoadGLLoader((GLADloadproc)(SDL_GL_GetProcAddress)))
|
if (!gl_load())
|
||||||
{
|
{
|
||||||
logger.fatal(std::format("Could not initialize OpenGL!"));
|
logger.fatal(std::format("Could not initialize OpenGL!"));
|
||||||
isError = true;
|
isError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(std::format("Initialized OpenGL {}", (const char*)glGetString(GL_VERSION)));
|
logger.info(std::format("Initialized OpenGL {}", (const char*)gl.GetString(GL_VERSION)));
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
gl.Enable(GL_BLEND);
|
||||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glLineWidth(2.0f);
|
gl.LineWidth(2.0f);
|
||||||
glDisable(GL_DEPTH_TEST);
|
gl.Disable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_LINE_SMOOTH);
|
gl.Disable(GL_LINE_SMOOTH);
|
||||||
|
|
||||||
random_seed_set();
|
random_seed_set();
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL_timer.h>
|
#include <SDL3/SDL_timer.h>
|
||||||
#include <SDL3/SDL_video.h>
|
#include <SDL3/SDL_video.h>
|
||||||
#include <glad/glad.h>
|
#include "gl.h"
|
||||||
|
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "canvas.h"
|
#include "canvas.h"
|
||||||
@@ -258,15 +258,15 @@ HeadlessGL::HeadlessGL()
|
|||||||
window = SDL_CreateWindow("anm2ed", 1, 1, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
|
window = SDL_CreateWindow("anm2ed", 1, 1, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
|
||||||
if (window)
|
if (window)
|
||||||
context = SDL_GL_CreateContext(window);
|
context = SDL_GL_CreateContext(window);
|
||||||
if (!context || !gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress))
|
if (!context || !gl_load())
|
||||||
{
|
{
|
||||||
if (context)
|
if (context)
|
||||||
SDL_GL_DestroyContext(context);
|
SDL_GL_DestroyContext(context);
|
||||||
context = nullptr;
|
context = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
glEnable(GL_BLEND);
|
gl.Enable(GL_BLEND);
|
||||||
glDisable(GL_DEPTH_TEST);
|
gl.Disable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
HeadlessGL::~HeadlessGL()
|
HeadlessGL::~HeadlessGL()
|
||||||
|
|||||||
+24
-24
@@ -430,8 +430,8 @@ static std::vector<ShaderUniform> uniforms_get(GLuint id)
|
|||||||
{
|
{
|
||||||
GLint count = 0;
|
GLint count = 0;
|
||||||
GLint maxLength = 0;
|
GLint maxLength = 0;
|
||||||
glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &count);
|
gl.GetProgramiv(id, GL_ACTIVE_UNIFORMS, &count);
|
||||||
glGetProgramiv(id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
|
gl.GetProgramiv(id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
|
||||||
|
|
||||||
std::vector<ShaderUniform> uniforms;
|
std::vector<ShaderUniform> uniforms;
|
||||||
if (count <= 0 || maxLength <= 0)
|
if (count <= 0 || maxLength <= 0)
|
||||||
@@ -443,14 +443,14 @@ static std::vector<ShaderUniform> uniforms_get(GLuint id)
|
|||||||
GLsizei length = 0;
|
GLsizei length = 0;
|
||||||
GLint size = 0;
|
GLint size = 0;
|
||||||
GLenum type = 0;
|
GLenum type = 0;
|
||||||
glGetActiveUniform(id, (GLuint)index, maxLength, &length, &size, &type, name.data());
|
gl.GetActiveUniform(id, (GLuint)index, maxLength, &length, &size, &type, name.data());
|
||||||
|
|
||||||
auto uniformName = uniform_name_clean_get(std::string(name.data(), (std::size_t)length));
|
auto uniformName = uniform_name_clean_get(std::string(name.data(), (std::size_t)length));
|
||||||
auto valueType = uniform_value_type_get(type);
|
auto valueType = uniform_value_type_get(type);
|
||||||
|
|
||||||
ShaderUniform uniform = {};
|
ShaderUniform uniform = {};
|
||||||
uniform.name = uniformName;
|
uniform.name = uniformName;
|
||||||
uniform.location = glGetUniformLocation(id, uniformName.c_str());
|
uniform.location = gl.GetUniformLocation(id, uniformName.c_str());
|
||||||
uniform.glType = type;
|
uniform.glType = type;
|
||||||
uniform.size = size;
|
uniform.size = size;
|
||||||
uniform.valueType = valueType;
|
uniform.valueType = valueType;
|
||||||
@@ -501,67 +501,67 @@ std::string gles_vertex_convert(std::string_view source)
|
|||||||
ShaderCompileResult shader_compile(const char* vertex, const char* fragment)
|
ShaderCompileResult shader_compile(const char* vertex, const char* fragment)
|
||||||
{
|
{
|
||||||
ShaderCompileResult result = {};
|
ShaderCompileResult result = {};
|
||||||
result.id = glCreateProgram();
|
result.id = gl.CreateProgram();
|
||||||
|
|
||||||
auto compile = [&](const GLuint& id, const char* text, const char* label) {
|
auto compile = [&](const GLuint& id, const char* text, const char* label) {
|
||||||
int isCompile = 0;
|
int isCompile = 0;
|
||||||
glShaderSource(id, 1, &text, nullptr);
|
gl.ShaderSource(id, 1, &text, nullptr);
|
||||||
glCompileShader(id);
|
gl.CompileShader(id);
|
||||||
glGetShaderiv(id, GL_COMPILE_STATUS, &isCompile);
|
gl.GetShaderiv(id, GL_COMPILE_STATUS, &isCompile);
|
||||||
|
|
||||||
if (!isCompile)
|
if (!isCompile)
|
||||||
{
|
{
|
||||||
GLint length = 0;
|
GLint length = 0;
|
||||||
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
|
gl.GetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
length = 1;
|
length = 1;
|
||||||
std::string compileLog((std::size_t)length, '\0');
|
std::string compileLog((std::size_t)length, '\0');
|
||||||
glGetShaderInfoLog(id, length, nullptr, compileLog.data());
|
gl.GetShaderInfoLog(id, length, nullptr, compileLog.data());
|
||||||
result.output += std::format("{} shader compile log:\n{}\n", label, compileLog.c_str());
|
result.output += std::format("{} shader compile log:\n{}\n", label, compileLog.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto vertexHandle = glCreateShader(GL_VERTEX_SHADER);
|
auto vertexHandle = gl.CreateShader(GL_VERTEX_SHADER);
|
||||||
auto fragmentHandle = glCreateShader(GL_FRAGMENT_SHADER);
|
auto fragmentHandle = gl.CreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
auto isVertexCompiled = compile(vertexHandle, vertex, "Vertex");
|
auto isVertexCompiled = compile(vertexHandle, vertex, "Vertex");
|
||||||
auto isFragmentCompiled = compile(fragmentHandle, fragment, "Fragment");
|
auto isFragmentCompiled = compile(fragmentHandle, fragment, "Fragment");
|
||||||
result.isCompiled = isVertexCompiled && isFragmentCompiled;
|
result.isCompiled = isVertexCompiled && isFragmentCompiled;
|
||||||
if (result.isCompiled)
|
if (result.isCompiled)
|
||||||
{
|
{
|
||||||
glAttachShader(result.id, vertexHandle);
|
gl.AttachShader(result.id, vertexHandle);
|
||||||
glAttachShader(result.id, fragmentHandle);
|
gl.AttachShader(result.id, fragmentHandle);
|
||||||
|
|
||||||
for (auto& alias : ATTRIBUTE_ALIASES)
|
for (auto& alias : ATTRIBUTE_ALIASES)
|
||||||
glBindAttribLocation(result.id, alias.index, alias.name);
|
gl.BindAttribLocation(result.id, alias.index, alias.name);
|
||||||
|
|
||||||
glLinkProgram(result.id);
|
gl.LinkProgram(result.id);
|
||||||
|
|
||||||
auto isLinked = GL_FALSE;
|
auto isLinked = GL_FALSE;
|
||||||
glGetProgramiv(result.id, GL_LINK_STATUS, &isLinked);
|
gl.GetProgramiv(result.id, GL_LINK_STATUS, &isLinked);
|
||||||
result.isLinked = isLinked == GL_TRUE;
|
result.isLinked = isLinked == GL_TRUE;
|
||||||
if (!result.isLinked)
|
if (!result.isLinked)
|
||||||
{
|
{
|
||||||
GLint length = 0;
|
GLint length = 0;
|
||||||
glGetProgramiv(result.id, GL_INFO_LOG_LENGTH, &length);
|
gl.GetProgramiv(result.id, GL_INFO_LOG_LENGTH, &length);
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
length = 1;
|
length = 1;
|
||||||
std::string linkLog((std::size_t)length, '\0');
|
std::string linkLog((std::size_t)length, '\0');
|
||||||
glGetProgramInfoLog(result.id, length, nullptr, linkLog.data());
|
gl.GetProgramInfoLog(result.id, length, nullptr, linkLog.data());
|
||||||
result.output += std::format("Shader link log:\n{}\n", linkLog.c_str());
|
result.output += std::format("Shader link log:\n{}\n", linkLog.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result.uniforms = uniforms_get(result.id);
|
result.uniforms = uniforms_get(result.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDeleteShader(vertexHandle);
|
gl.DeleteShader(vertexHandle);
|
||||||
glDeleteShader(fragmentHandle);
|
gl.DeleteShader(fragmentHandle);
|
||||||
|
|
||||||
if (!result.isLinked)
|
if (!result.isLinked)
|
||||||
{
|
{
|
||||||
glDeleteProgram(result.id);
|
gl.DeleteProgram(result.id);
|
||||||
result.id = 0;
|
result.id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -589,7 +589,7 @@ ShaderProgram& ShaderProgram::operator=(ShaderProgram&& other) noexcept
|
|||||||
if (this != &other)
|
if (this != &other)
|
||||||
{
|
{
|
||||||
if (is_valid())
|
if (is_valid())
|
||||||
glDeleteProgram(id);
|
gl.DeleteProgram(id);
|
||||||
id = other.id;
|
id = other.id;
|
||||||
uniforms = std::move(other.uniforms);
|
uniforms = std::move(other.uniforms);
|
||||||
other.id = 0;
|
other.id = 0;
|
||||||
@@ -600,7 +600,7 @@ ShaderProgram& ShaderProgram::operator=(ShaderProgram&& other) noexcept
|
|||||||
ShaderProgram::~ShaderProgram()
|
ShaderProgram::~ShaderProgram()
|
||||||
{
|
{
|
||||||
if (is_valid())
|
if (is_valid())
|
||||||
glDeleteProgram(id);
|
gl.DeleteProgram(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderProgram::is_valid() const
|
bool ShaderProgram::is_valid() const
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include "gl.h"
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|||||||
+2
-2
@@ -209,8 +209,8 @@ void State::update(SDL_Window*& window, Settings& settings)
|
|||||||
|
|
||||||
void State::render(SDL_Window*& window, Settings& settings)
|
void State::render(SDL_Window*& window, Settings& settings)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, settings.windowSize.x, settings.windowSize.y);
|
gl.Viewport(0, 0, settings.windowSize.x, settings.windowSize.y);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
gl.Clear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|||||||
+10
-10
@@ -25,16 +25,16 @@ GLuint texture_id_get(const Image& image)
|
|||||||
return entry.id;
|
return entry.id;
|
||||||
|
|
||||||
auto filter = image.isLinear ? GL_LINEAR : GL_NEAREST;
|
auto filter = image.isLinear ? GL_LINEAR : GL_NEAREST;
|
||||||
glGenTextures(1, &entry.id);
|
gl.GenTextures(1, &entry.id);
|
||||||
glBindTexture(GL_TEXTURE_2D, entry.id);
|
gl.BindTexture(GL_TEXTURE_2D, entry.id);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.size.x, image.size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.size.x, image.size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||||
image.pixels.data());
|
image.pixels.data());
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
gl.BindTexture(GL_TEXTURE_2D, 0);
|
||||||
return entry.id;
|
return entry.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ void texture_garbage_collect()
|
|||||||
std::erase_if(entries, [](auto& pair) {
|
std::erase_if(entries, [](auto& pair) {
|
||||||
auto& entry = pair.second;
|
auto& entry = pair.second;
|
||||||
if (!entry.isUsed)
|
if (!entry.isUsed)
|
||||||
glDeleteTextures(1, &entry.id);
|
gl.DeleteTextures(1, &entry.id);
|
||||||
return !std::exchange(entry.isUsed, false);
|
return !std::exchange(entry.isUsed, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include "gl.h"
|
||||||
|
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include "gl.h"
|
||||||
|
|
||||||
constexpr ImU32 DROP_LINE_COLOR = IM_COL32(255, 255, 0, 255);
|
constexpr ImU32 DROP_LINE_COLOR = IM_COL32(255, 255, 0, 255);
|
||||||
constexpr float DROP_LINE_THICKNESS = 2.0f;
|
constexpr float DROP_LINE_THICKNESS = 2.0f;
|
||||||
@@ -46,7 +46,7 @@ void drop_line_draw(ImDrawList* drawList, ImVec2 min, ImVec2 max, bool isAfter)
|
|||||||
|
|
||||||
static void image_premultiplied_blend_set(const ImDrawList*, const ImDrawCmd*)
|
static void image_premultiplied_blend_set(const ImDrawList*, const ImDrawCmd*)
|
||||||
{
|
{
|
||||||
glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
gl.BlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
void image_premultiplied_draw(ImTextureID texture, ImVec2 size)
|
void image_premultiplied_draw(ImTextureID texture, ImVec2 size)
|
||||||
|
|||||||
Reference in new issue
Block a user