Browse Source
Merge pull request #4569 from ReinUsesLisp/glsl-cmake
Merge pull request #4569 from ReinUsesLisp/glsl-cmake
video_core/host_shaders: Add CMake integration for string shadersnce_cpp
committed by
GitHub
12 changed files with 127 additions and 51 deletions
-
5src/video_core/CMakeLists.txt
-
43src/video_core/host_shaders/CMakeLists.txt
-
11src/video_core/host_shaders/StringShaderHeader.cmake
-
10src/video_core/host_shaders/opengl_present.frag
-
24src/video_core/host_shaders/opengl_present.vert
-
9src/video_core/host_shaders/source_shader.h.in
-
9src/video_core/renderer_opengl/gl_resource_manager.cpp
-
3src/video_core/renderer_opengl/gl_resource_manager.h
-
1src/video_core/renderer_opengl/gl_shader_cache.cpp
-
15src/video_core/renderer_opengl/gl_shader_util.cpp
-
2src/video_core/renderer_opengl/gl_shader_util.h
-
46src/video_core/renderer_opengl/renderer_opengl.cpp
@ -0,0 +1,43 @@ |
|||||
|
set(SHADER_FILES |
||||
|
opengl_present.frag |
||||
|
opengl_present.vert |
||||
|
) |
||||
|
|
||||
|
set(SHADER_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/include) |
||||
|
set(HOST_SHADERS_INCLUDE ${SHADER_INCLUDE} PARENT_SCOPE) |
||||
|
|
||||
|
set(SHADER_DIR ${SHADER_INCLUDE}/video_core/host_shaders) |
||||
|
add_custom_command( |
||||
|
OUTPUT |
||||
|
${SHADER_DIR} |
||||
|
COMMAND |
||||
|
${CMAKE_COMMAND} -E make_directory ${SHADER_DIR} |
||||
|
) |
||||
|
|
||||
|
set(INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/source_shader.h.in) |
||||
|
set(HEADER_GENERATOR ${CMAKE_CURRENT_SOURCE_DIR}/StringShaderHeader.cmake) |
||||
|
|
||||
|
foreach(FILENAME IN ITEMS ${SHADER_FILES}) |
||||
|
string(REPLACE "." "_" SHADER_NAME ${FILENAME}) |
||||
|
set(SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}) |
||||
|
set(HEADER_FILE ${SHADER_DIR}/${SHADER_NAME}.h) |
||||
|
add_custom_command( |
||||
|
OUTPUT |
||||
|
${HEADER_FILE} |
||||
|
COMMAND |
||||
|
${CMAKE_COMMAND} -P ${HEADER_GENERATOR} ${SOURCE_FILE} ${HEADER_FILE} ${INPUT_FILE} |
||||
|
MAIN_DEPENDENCY |
||||
|
${SOURCE_FILE} |
||||
|
DEPENDS |
||||
|
${HEADER_GENERATOR} |
||||
|
${INPUT_FILE} |
||||
|
) |
||||
|
set(SHADER_HEADERS ${SHADER_HEADERS} ${HEADER_FILE}) |
||||
|
endforeach() |
||||
|
|
||||
|
add_custom_target(host_shaders |
||||
|
DEPENDS |
||||
|
${SHADER_HEADERS} |
||||
|
SOURCES |
||||
|
${SHADER_FILES} |
||||
|
) |
||||
@ -0,0 +1,11 @@ |
|||||
|
set(SOURCE_FILE ${CMAKE_ARGV3}) |
||||
|
set(HEADER_FILE ${CMAKE_ARGV4}) |
||||
|
set(INPUT_FILE ${CMAKE_ARGV5}) |
||||
|
|
||||
|
get_filename_component(CONTENTS_NAME ${SOURCE_FILE} NAME) |
||||
|
string(REPLACE "." "_" CONTENTS_NAME ${CONTENTS_NAME}) |
||||
|
string(TOUPPER ${CONTENTS_NAME} CONTENTS_NAME) |
||||
|
|
||||
|
file(READ ${SOURCE_FILE} CONTENTS) |
||||
|
|
||||
|
configure_file(${INPUT_FILE} ${HEADER_FILE} @ONLY) |
||||
@ -0,0 +1,10 @@ |
|||||
|
#version 430 core |
||||
|
|
||||
|
layout (location = 0) in vec2 frag_tex_coord; |
||||
|
layout (location = 0) out vec4 color; |
||||
|
|
||||
|
layout (binding = 0) uniform sampler2D color_texture; |
||||
|
|
||||
|
void main() { |
||||
|
color = vec4(texture(color_texture, frag_tex_coord).rgb, 1.0f); |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
#version 430 core |
||||
|
|
||||
|
out gl_PerVertex { |
||||
|
vec4 gl_Position; |
||||
|
}; |
||||
|
|
||||
|
layout (location = 0) in vec2 vert_position; |
||||
|
layout (location = 1) in vec2 vert_tex_coord; |
||||
|
layout (location = 0) out vec2 frag_tex_coord; |
||||
|
|
||||
|
// This is a truncated 3x3 matrix for 2D transformations: |
||||
|
// The upper-left 2x2 submatrix performs scaling/rotation/mirroring. |
||||
|
// The third column performs translation. |
||||
|
// The third row could be used for projection, which we don't need in 2D. It hence is assumed to |
||||
|
// implicitly be [0, 0, 1] |
||||
|
layout (location = 0) uniform mat3x2 modelview_matrix; |
||||
|
|
||||
|
void main() { |
||||
|
// Multiply input position by the rotscale part of the matrix and then manually translate by |
||||
|
// the last column. This is equivalent to using a full 3x3 matrix and expanding the vector |
||||
|
// to `vec3(vert_position.xy, 1.0)` |
||||
|
gl_Position = vec4(mat2(modelview_matrix) * vert_position + modelview_matrix[2], 0.0, 1.0); |
||||
|
frag_tex_coord = vert_tex_coord; |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <string_view> |
||||
|
|
||||
|
namespace HostShaders { |
||||
|
|
||||
|
constexpr std::string_view @CONTENTS_NAME@ = R"(@CONTENTS@)"; |
||||
|
|
||||
|
} // namespace HostShaders |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue