Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
-Egl api enum type
-gl-shadertoy example (3.3 Core) - plan to remove after vk-shadertoy done
-vk-shadertoy loader - wip
-third_party add glm 1.0.1

Signed-off-by: Joel Winarske <[email protected]>
  • Loading branch information
jwinarske committed May 5, 2024
1 parent 7f36476 commit 9c6e14e
Show file tree
Hide file tree
Showing 468 changed files with 69,497 additions and 79 deletions.
50 changes: 50 additions & 0 deletions cmake/glsl_compile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright 2024 Joel Winarske
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

find_program(GLSL_VALIDATOR glslangValidator REQUIRED)

macro(append_glsl_to_target target sources version)

foreach (GLSL ${sources})

get_filename_component(FILE_NAME ${GLSL} NAME)

set(SPIRV "${CMAKE_CURRENT_BINARY_DIR}/shaders/${FILE_NAME}.spv")

if (NOT EXISTS "${GLSL}")
set(GLSL "${CMAKE_CURRENT_SOURCE_DIR}/${GLSL}")
endif ()

add_custom_command(
OUTPUT ${SPIRV}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/shaders
COMMAND ${GLSL_VALIDATOR} -V${version} ${GLSL} -o ${SPIRV}
DEPENDS ${GLSL}
)

list(APPEND SPIRV_BINARY_FILES ${SPIRV})

endforeach ()

add_custom_target(Shaders DEPENDS ${SPIRV_BINARY_FILES})

add_dependencies(${target} Shaders)

add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${target}>/shaders/"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders" "$<TARGET_FILE_DIR:${target}>/shaders"
)
endmacro()
25 changes: 17 additions & 8 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# limitations under the License.
#

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLESv2 IMPORTED_TARGET glesv2)

#
# simple-egl
#
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLESv2 IMPORTED_TARGET glesv2)

add_executable(simple-egl simple-egl.cc)
target_include_directories(simple-egl PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

target_compile_definitions(simple-egl PRIVATE EGL_NO_X11 MESA_EGL_NO_X11_HEADERS)

Expand All @@ -37,7 +37,6 @@ add_sanitizers(simple-egl)
# simple-shm
#
add_executable(simple-shm simple-shm.cc)
target_include_directories(simple-shm PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

target_link_libraries(simple-shm PRIVATE waypp wayland-gen cxxopts::cxxopts)

Expand All @@ -52,7 +51,6 @@ add_sanitizers(simple-shm)
#
if (FALSE)
add_executable(presentation-shm presentation-shm.cc)
target_include_directories(presentation-shm PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

target_link_libraries(presentation-shm PRIVATE waypp wayland-gen cxxopts::cxxopts)

Expand All @@ -68,7 +66,6 @@ endif ()
#
if (HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1)
add_executable(simple-ext-protocol simple-ext-protocol.cc)
target_include_directories(simple-ext-protocol PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

target_link_libraries(simple-ext-protocol PRIVATE waypp wayland-gen cxxopts::cxxopts)

Expand All @@ -83,7 +80,6 @@ endif ()
# agl-simple-shm
#
add_executable(agl-simple-shm agl-simple-shm.cc)
target_include_directories(agl-simple-shm PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

target_link_libraries(agl-simple-shm PRIVATE waypp wayland-gen cxxopts::cxxopts)

Expand All @@ -94,7 +90,6 @@ endif ()
add_sanitizers(agl-simple-shm)

add_executable(agl-capture agl-capture.cc agl-capture.cc)
target_include_directories(agl-capture PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

target_link_libraries(agl-capture PRIVATE waypp wayland-gen cxxopts::cxxopts)

Expand All @@ -103,3 +98,17 @@ if (IPO_SUPPORT_RESULT)
endif ()

add_sanitizers(agl-capture)

#
# Vulkan
#
find_package(Vulkan)

if (VULKAN_FOUND)
add_subdirectory(vk-shadertoy)
endif ()

#
# GL
#
add_subdirectory(gl-shadertoy)
36 changes: 18 additions & 18 deletions examples/agl-simple-shm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,39 +137,39 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver
seat.value()->register_observer(this);
}

top_level_ = agl_shell_->create_top_level("agl-simple-shm",
"org.freedesktop.gitlab.jwinarske.waypp.simple_shm",
config.width,
config.height,
2,
WL_SHM_FORMAT_XRGB8888,
config.fullscreen,
config.maximized,
config.fullscreen_ratio,
config.tearing,
draw_frame
toplevel_ = agl_shell_->create_top_level("agl-simple-shm",
"org.freedesktop.gitlab.jwinarske.waypp.simple_shm",
config.width,
config.height,
2,
WL_SHM_FORMAT_XRGB8888,
config.fullscreen,
config.maximized,
config.fullscreen_ratio,
config.tearing,
draw_frame
);
spdlog::info("XDG Window Version: {}", top_level_->get_version());
spdlog::info("XDG Window Version: {}", toplevel_->get_version());

surface_ = top_level_->get_surface();
surface_ = toplevel_->get_surface();
output_ = agl_shell_->get_primary_output();
agl_shell_->set_background(surface_, output_);
agl_shell_->set_activate_region(output_, 0, 0, static_cast<uint32_t>(config.width),
static_cast<uint32_t>(config.height));
agl_shell_->ready();

/// paint padding
top_level_->set_surface_damage(0, 0, config.width, config.height);
top_level_->start_frame_callbacks();
toplevel_->set_surface_damage(0, 0, config.width, config.height);
toplevel_->start_frame_callbacks();
}

~App() override {
top_level_->stop_frame_callbacks();
toplevel_->stop_frame_callbacks();
}

bool run() {
/// display_dispatch is blocking
return (top_level_->is_valid() && agl_shell_->display_dispatch() != -1);
return (toplevel_->is_valid() && agl_shell_->display_dispatch() != -1);
}

void notify_seat_capabilities(Seat *seat, wl_seat * /* seat */, uint32_t /* caps */) override {
Expand Down Expand Up @@ -304,7 +304,7 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver
std::unique_ptr<Logging> logging_;
std::unique_ptr<AglShell> agl_shell_;
struct wl_output *output_;
XdgTopLevel *top_level_;
XdgTopLevel *toplevel_;
struct wl_surface *surface_;

std::random_device rd_;
Expand Down
27 changes: 27 additions & 0 deletions examples/gl-shadertoy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright 2024 Joel Winarske
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

add_executable(gl-shadertoy shadertoy.cc)

target_compile_definitions(gl-shadertoy PRIVATE EGL_NO_X11 MESA_EGL_NO_X11_HEADERS)

target_link_libraries(gl-shadertoy PRIVATE waypp wayland-gen PkgConfig::GLESv2 cxxopts::cxxopts)

if (IPO_SUPPORT_RESULT)
set_property(TARGET gl-shadertoy PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()

add_sanitizers(gl-shadertoy)
Loading

0 comments on commit 9c6e14e

Please sign in to comment.