-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from gmbeard/fix/drm-color-conversion
fix: Color conversion for Wayland compositors that use non-linear pixel formats
- Loading branch information
Showing
55 changed files
with
11,577 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixes color conversion on Wayland compositors that don't use a linear pixel format for DRM planes (#39) (thanks: @SleepingPanda) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# This will create an object library target called `${NAME}.o` | ||
# which will embed and export the GLSL as a array of bytes. | ||
# The symbol name given to each export GLSL file is derived | ||
# from the entry in `SOURCES`... | ||
# | ||
# ``` | ||
# extern char const _private_<SOURCE_FILE_WITH_UNDERSCORES>_start[]; | ||
# extern char const _private_<SOURCE_FILE_WITH_UNDERSCORES>_end[]; | ||
# ``` | ||
# | ||
# The source file (combined with any path components) have all `.` | ||
# `-`, `/`, etc replaced with underscores (`_`) | ||
# | ||
# To keep the exported symbol names short, you should restrict | ||
# `SOURCES` to files in the current directory. Any relative | ||
# directories will also form part of the symbol name. E.g... | ||
# | ||
# ``` | ||
# add_embedded_glsl_target( | ||
# SOURCES glsl/vertex-shaders/shader.glsl | ||
# ... | ||
# ) | ||
# ``` | ||
# | ||
# would yield the following symbol names... | ||
# | ||
# ``` | ||
# extern char const _private_glsl_vertex_shaders_shader_glsl_start[]; | ||
# extern char const _private_glsl_vertex_shaders_shader_glsl_end[]; | ||
# ``` | ||
function(add_embedded_glsl_target) | ||
set(single_value_args NAME) | ||
set(multi_value_args SOURCES) | ||
cmake_parse_arguments( | ||
ADD_EMBEDDED_GLSL_TARGET | ||
"${options}" | ||
"${single_value_args}" | ||
"${multi_value_args}" | ||
${ARGN} | ||
) | ||
|
||
# We may be able to use the `-L` argument when generating an | ||
# object file, which could remove the path element from the | ||
# symbol names (`-L` is a search path)... | ||
add_custom_target( | ||
${ADD_EMBEDDED_GLSL_TARGET_NAME}_generator | ||
COMMAND ${CMAKE_LINKER} -b binary -r | ||
-o "${CMAKE_CURRENT_BINARY_DIR}/${ADD_EMBEDDED_GLSL_TARGET_NAME}.o" | ||
${ADD_EMBEDDED_GLSL_TARGET_SOURCES} | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" | ||
) | ||
add_library(${ADD_EMBEDDED_GLSL_TARGET_NAME} OBJECT IMPORTED GLOBAL) | ||
set_target_properties( | ||
${ADD_EMBEDDED_GLSL_TARGET_NAME} | ||
PROPERTIES | ||
IMPORTED_OBJECTS "${CMAKE_CURRENT_BINARY_DIR}/${ADD_EMBEDDED_GLSL_TARGET_NAME}.o" | ||
) | ||
add_dependencies(${ADD_EMBEDDED_GLSL_TARGET_NAME} ${ADD_EMBEDDED_GLSL_TARGET_NAME}_generator) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "gl/buffer.hpp" | ||
#include "gl/error.hpp" | ||
|
||
namespace sc::opengl | ||
{ | ||
auto BufferTraits::create() const -> GLuint | ||
{ | ||
GLuint name; | ||
gl().glGenBuffers(1, &name); | ||
SC_CHECK_GL_ERROR("glGenBuffers"); | ||
return name; | ||
} | ||
|
||
auto BufferTraits::destroy(GLuint name) const noexcept -> void | ||
{ | ||
gl().glDeleteBuffers(1, &name); | ||
SC_CHECK_GL_ERROR_NOEXCEPT("glDeleteBuffers"); | ||
} | ||
|
||
auto BufferTraits::bind(GLenum target, GLint name) const noexcept -> void | ||
{ | ||
gl().glBindBuffer(target, name); | ||
SC_CHECK_GL_ERROR("glBindBuffer"); | ||
} | ||
|
||
auto vertex_attrib_pointer( | ||
BoundTarget<BufferTarget<GL_ARRAY_BUFFER>, Buffer> const& /*array_buffer*/, | ||
GLuint index, | ||
GLint size, | ||
GLenum type, | ||
GLboolean normalized, | ||
GLsizei stride, | ||
void const* pointer) -> void | ||
{ | ||
gl().glVertexAttribPointer(index, size, type, normalized, stride, pointer); | ||
SC_CHECK_GL_ERROR("glVertexAttribPointer"); | ||
} | ||
} // namespace sc::opengl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#ifndef SHADOW_CAST_GL_BUFFER_HPP_INCLUDED | ||
#define SHADOW_CAST_GL_BUFFER_HPP_INCLUDED | ||
|
||
#include "gl/error.hpp" | ||
#include "gl/object.hpp" | ||
#include "platform/opengl.hpp" | ||
#include <GL/gl.h> | ||
#include <GL/glext.h> | ||
#include <span> | ||
#include <tuple> | ||
#include <type_traits> | ||
namespace sc | ||
{ | ||
|
||
namespace opengl | ||
{ | ||
template <typename T> | ||
concept BufferableConcept = std::is_arithmetic_v<T>; | ||
|
||
struct BufferCategory | ||
{ | ||
}; | ||
|
||
struct BufferTraits | ||
{ | ||
using category = BufferCategory; | ||
|
||
auto create() const -> GLuint; | ||
auto destroy(GLuint name) const noexcept -> void; | ||
auto bind(GLenum target, GLint name) const noexcept -> void; | ||
}; | ||
|
||
using Buffer = ObjectBase<BufferTraits>; | ||
template <GLenum T> | ||
using BufferTarget = TargetBase<T, BufferTraits>; | ||
|
||
template <typename T> | ||
concept BufferConcept = | ||
std::is_convertible_v<typename T::category, BufferCategory>; | ||
|
||
template <typename T> | ||
concept BoundBufferConcept = | ||
BindingConcept<std::decay_t<T>> && BufferConcept<T>; | ||
|
||
template <BoundBufferConcept A, BufferableConcept T> | ||
auto named_buffer_data(A& array_buffer, std::span<T const> data, GLenum usage) | ||
-> void | ||
{ | ||
const auto [id, sz, d] = | ||
std::make_tuple(array_buffer.name(), data.size(), data.data()); | ||
|
||
gl().glNamedBufferData(id, sz * sizeof(T), d, usage); | ||
SC_CHECK_GL_ERROR("glNamedBufferData"); | ||
} | ||
|
||
template <BoundBufferConcept A, BufferableConcept T> | ||
auto buffer_data(A& array_buffer, std::span<T> data, GLenum usage) -> void | ||
{ | ||
const auto [target, sz, d] = | ||
std::make_tuple(array_buffer.target(), data.size(), data.data()); | ||
|
||
gl().glBufferData(target, sz * sizeof(T), d, usage); | ||
SC_CHECK_GL_ERROR("glBufferData"); | ||
} | ||
|
||
auto vertex_attrib_pointer( | ||
BoundTarget<BufferTarget<GL_ARRAY_BUFFER>, Buffer> const& array_buffer, | ||
GLuint index, | ||
GLint size, | ||
GLenum type, | ||
GLboolean normalized, | ||
GLsizei stride, | ||
void const* pointer) -> void; | ||
|
||
constexpr BufferTarget<GL_ARRAY_BUFFER> array_buffer_target {}; | ||
constexpr BufferTarget<GL_ELEMENT_ARRAY_BUFFER> element_array_buffer_target {}; | ||
|
||
} // namespace opengl | ||
|
||
} // namespace sc | ||
|
||
#endif // SHADOW_CAST_GL_BUFFER_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "gl/core.hpp" | ||
#include "gl/error.hpp" | ||
#include "platform/opengl.hpp" | ||
|
||
namespace sc::opengl | ||
{ | ||
|
||
auto viewport(GLint x, GLint y, GLsizei width, GLsizei height) -> void | ||
{ | ||
gl().glViewport(x, y, width, height); | ||
SC_CHECK_GL_ERROR("glViewport"); | ||
} | ||
|
||
auto clear(GLenum mask) -> void | ||
{ | ||
gl().glClear(mask); | ||
SC_CHECK_GL_ERROR("glClear"); | ||
} | ||
|
||
auto clear_color(float red, float green, float blue, float alpha) noexcept | ||
-> void | ||
{ | ||
gl().glClearColor(red, green, blue, alpha); | ||
} | ||
|
||
} // namespace sc::opengl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef SHADOW_CAST_GL_CORE_HPP_INCLUDED | ||
#define SHADOW_CAST_GL_CORE_HPP_INCLUDED | ||
|
||
#include <GL/gl.h> | ||
|
||
namespace sc::opengl | ||
{ | ||
auto viewport(GLint x, GLint y, GLsizei width, GLsizei height) -> void; | ||
auto clear(GLenum mask) -> void; | ||
auto clear_color(float red, float green, float blue, float alpha) noexcept | ||
-> void; | ||
|
||
} // namespace sc::opengl | ||
|
||
#endif // SHADOW_CAST_GL_CORE_HPP_INCLUDED |
Oops, something went wrong.