mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 03:52:48 -05:00
embed shaders in binary
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
add_custom_target(resources DEPENDS resources_output)
|
||||
add_custom_command(
|
||||
OUTPUT resources_output
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/res ${CMAKE_CURRENT_BINARY_DIR}/res
|
||||
COMMENT "Copying Resources")
|
||||
add_subdirectory(shaders)
|
||||
|
||||
add_executable(vis
|
||||
src/main.cpp
|
||||
@@ -15,6 +11,6 @@ target_link_libraries(vis
|
||||
imgui
|
||||
eigen
|
||||
nlohmann_json
|
||||
shaders
|
||||
)
|
||||
target_include_directories(vis PUBLIC include)
|
||||
add_dependencies(vis resources)
|
||||
|
||||
@@ -23,6 +23,17 @@ public:
|
||||
// todo throw if compile failed
|
||||
}
|
||||
|
||||
explicit Shader(const std::string_view &src) {
|
||||
id = glCreateShader(mode);
|
||||
|
||||
const char *str = src.data();
|
||||
const GLint length = (GLint) src.length();
|
||||
glShaderSource(id, 1, &str, &length);
|
||||
glCompileShader(id);
|
||||
|
||||
// todo throw if compile failed
|
||||
}
|
||||
|
||||
explicit Shader(std::ifstream source)
|
||||
: Shader(std::string(
|
||||
std::istreambuf_iterator<char>(source),
|
||||
|
||||
4
vis/shaders/CMakeLists.txt
Normal file
4
vis/shaders/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
add_embed_library(shaders
|
||||
main-4d.vert.glsl
|
||||
main.vert.glsl
|
||||
main.frag.glsl)
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <shaders.hpp>
|
||||
|
||||
struct State {
|
||||
Eigen::Vector4f bg{0.16, 0.16, 0.16, 1.00};
|
||||
Eigen::Vector4f fg{0.71, 0.53, 0.94, 1.00};
|
||||
@@ -39,8 +41,8 @@ template<typename V_=Eigen::Vector4f>
|
||||
struct PointRenderer {
|
||||
using Vertex = V_;
|
||||
|
||||
VertexShader vs{std::ifstream("res/shaders/main.vert.glsl")};
|
||||
FragmentShader fs{std::ifstream("res/shaders/main.frag.glsl")};
|
||||
VertexShader vs{shaders::main_vert_glsl};
|
||||
FragmentShader fs{shaders::main_frag_glsl};
|
||||
|
||||
Program pgm{vs, fs};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user