Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4a76175
fix: add library stb
WSQS Nov 23, 2025
d6f5c93
feat: add asset library
WSQS Nov 23, 2025
05107bb
feat: call function stbi_load and successfully load png
WSQS Nov 23, 2025
bad4203
feat: also install png
WSQS Nov 23, 2025
c2b5fec
feat: Add data type ImageData
WSQS Nov 23, 2025
874bec7
feat: extract function load_image
WSQS Nov 23, 2025
030e899
feat: add property m_image_data
WSQS Nov 23, 2025
6a24d89
feat: add function create_texture_from_image
WSQS Nov 23, 2025
90106a3
breaking: trying to implement
WSQS Nov 23, 2025
0c7098d
feat:add num_samplers
Sophomore42 Nov 24, 2025
611ce5e
feat:implement texture
Sophomore42 Nov 24, 2025
19b3289
feat:release texture and sampler
Sophomore42 Nov 24, 2025
9709c35
fix: remote unused header file
Sophomore42 Nov 24, 2025
3230a5a
feat: flip vertical on load
Sophomore42 Nov 24, 2025
942c941
feat: change hierarchy
Sophomore42 Nov 24, 2025
8ef6d46
feat: move reflector type into data_type module
Sophomore42 Nov 24, 2025
8681328
feat: trying to get reflection of uniform
Sophomore42 Nov 24, 2025
53e8e89
feat: add type FragmentReflection
Sophomore42 Nov 24, 2025
d7832d2
feat: add function reflect_fragment
Sophomore42 Nov 24, 2025
ccfb6f4
feat: add test case for reflect_fragment
Sophomore42 Nov 24, 2025
84327f7
fix: cleanup code
WSQS Nov 24, 2025
727cae2
feat: add readme
WSQS Nov 24, 2025
50f0658
doc: add limit for document
WSQS Nov 24, 2025
fe46797
doc: add document
WSQS Nov 24, 2025
39af349
feat: using reflector to define sampler
WSQS Nov 24, 2025
cfba354
feat: add class TransferBufferWrapper
WSQS Nov 24, 2025
e3a4489
feat: Split Implement and interface of render data
Sophomore42 Nov 25, 2025
8d8f261
feat: add file render_data_impl
Sophomore42 Nov 25, 2025
e941454
feat: change signature of create_data
Sophomore42 Nov 25, 2025
f47735f
feat: Not export Module buffer
Sophomore42 Nov 25, 2025
8e56215
feat: Add type texture
Sophomore42 Nov 25, 2025
3aeaf51
feat: export texture
WSQS Nov 25, 2025
b579452
feat: move transfer_buffer into cpp
WSQS Nov 25, 2025
80478b5
fix:Buffer not include gpu
WSQS Nov 25, 2025
9c1c7a5
fix: remove export on transfer buffer
WSQS Nov 25, 2025
a8618c9
fix: add missing return value for function
WSQS Nov 25, 2025
488e556
feat: draw Texture using TextureWrapper
WSQS Nov 25, 2025
9d97e61
fix: add noexcept identifier
WSQS Nov 25, 2025
8189d63
fix: remove test texture
WSQS Nov 25, 2025
2921e9c
feat:set imgui and stb header file as system
WSQS Nov 25, 2025
8849833
feat:clean up readme
WSQS Nov 25, 2025
6cdeac1
feat:Add Track in Readme
WSQS Nov 25, 2025
dab4034
fix: release command buffer if begin copy pass failed
Sophomore42 Nov 26, 2025
5df9b86
fix:check texture wrapper before using
Sophomore42 Nov 26, 2025
e522e57
fix: update vertex count
Sophomore42 Nov 26, 2025
bcd257e
feat: make file name correct
Sophomore42 Nov 26, 2025
b8e7d4d
feat: format document
Sophomore42 Nov 26, 2025
955f9d3
feat: Add missing header file
Sophomore42 Nov 26, 2025
3577ff3
fix: change submit function signature
Sophomore42 Nov 26, 2025
8dff3d4
fix: add initializer sampler_count
Sophomore42 Nov 26, 2025
4557e6e
fix: add std::move
Sophomore42 Nov 26, 2025
24645d1
log: add log for create texture failed
Sophomore42 Nov 26, 2025
5ae60b4
fix: add index count for RenderData
Sophomore42 Nov 26, 2025
b62817a
fix: release buffer to avoid leak
Sophomore42 Nov 26, 2025
2566e27
fix: avoid texture leak
Sophomore42 Nov 26, 2025
be8ca77
fix: remove magic number and using parameter
Sophomore42 Nov 26, 2025
c1b759a
fix: add missing header file
Sophomore42 Nov 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,23 @@ add_library(imgui STATIC
${IMGUI_DIR}/backends/imgui_impl_sdlgpu3.cpp
${IMGUI_DIR}/misc/cpp/imgui_stdlib.cpp
)
target_include_directories(imgui PUBLIC
target_include_directories(imgui SYSTEM PUBLIC
${IMGUI_DIR}
${IMGUI_DIR}/backends
)
target_link_libraries(imgui PUBLIC SDL3::SDL3)

FetchContent_Declare(
stb
GIT_REPOSITORY https://github.com/nothings/stb.git
GIT_TAG master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(stb)
add_library(stb INTERFACE)
target_include_directories(stb SYSTEM INTERFACE ${stb_SOURCE_DIR})

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
Expand All @@ -111,10 +122,26 @@ add_subdirectory(sdl_wrapper)
add_subdirectory(glsl_reflector)

add_executable(SDL_TEST main.cpp)
target_link_libraries(SDL_TEST PRIVATE imgui sdl_wrapper)

target_link_libraries(SDL_TEST PRIVATE imgui sdl_wrapper stb)

include(GNUInstallDirs)
install(TARGETS SDL_TEST
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
)

set(ASSETS_DST_DIR ${CMAKE_BINARY_DIR}/assets)
file(MAKE_DIRECTORY ${ASSETS_DST_DIR})

set(TEST_TEXTURE_PATH ${ASSETS_DST_DIR}/test_texture.png)

if (NOT EXISTS ${TEST_TEXTURE_PATH})
file(DOWNLOAD
"https://opengameart.org/sites/default/files/slime_25.png"
"${TEST_TEXTURE_PATH}"
SHOW_PROGRESS
)
endif()

install(DIRECTORY ${ASSETS_DST_DIR}/
DESTINATION ${CMAKE_INSTALL_BINDIR}/assets
)
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SDL Test

This is a personal learning project following [Learn OpenGL](https://learnopengl.com/)

## Track

- [ ] Getting started
- [x] OpenGL
- [x] Creating a window
- [x] Hello Window
- [x] Hello Triangle
- [x] Shaders
- [x] Textures
- [ ] Transformations
- [ ] Coordinate Systems
- [ ] Camera
- [ ] Lighting
- [ ] Model Loading
- [ ] Advanced OpenGL
- [ ] Advanced Lighting
- [ ] PBR
- [ ] In Practice
50 changes: 45 additions & 5 deletions data_type/modules/data_type.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
// Created by sophomore on 11/23/25.
//
module;
#include<expected>
#include <cstdint>
#include <expected>
#include <string>
#include <vector>
export module data_type;

export namespace sopho {
enum class GpuError {
export namespace sopho
{
enum class GpuError
{
UNINITIALIZED,
CREATE_DEVICE_FAILED,
CREATE_WINDOW_FAILED,
CLAIM_WINDOW_FAILED,
CREATE_GPU_BUFFER_FAILED,
CREATE_TRANSFER_BUFFER_FAILED,
CREATE_TEXTURE_FAILED,
CREATE_SHADER_FAILED,
CREATE_PIPELINE_FAILED,
CREATE_SAMPLER_FAILED,
GET_TEXTUREFORMAT_FAILED,
BUFFER_OVERFLOW,
MAP_TRANSFER_BUFFER_FAILED,
Expand All @@ -26,6 +33,39 @@ export namespace sopho {
};

using TError = GpuError;
template<typename T>
template <typename T>
using checkable = std::expected<T, TError>;
}

struct ImageData
{
int width{};
int height{};
int channels{};
std::vector<std::byte> pixels{};
};

enum class BasicType : std::uint8_t
{
NONE,
FLOAT
};

struct VertexInfo
{
std::uint32_t location{};
std::string name{};
BasicType basic_type{};
int vector_size{};
};

struct VertexReflection
{
std::vector<VertexInfo> inputs{};
};

struct FragmentReflection
{
std::uint32_t sampler_count{};
};

} // namespace sopho
3 changes: 1 addition & 2 deletions glsl_reflector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ target_sources(glsl_reflector
PUBLIC
FILE_SET cxx_modules TYPE CXX_MODULES FILES
modules/glsl_reflector.ixx
modules/glsl_reflector.type.ixx
)

target_link_libraries(glsl_reflector PUBLIC glslang glslang::glslang-default-resource-limits)
target_link_libraries(glsl_reflector PUBLIC glslang glslang::glslang-default-resource-limits data_type)

add_executable(glslr test/test.cpp)

Expand Down
55 changes: 54 additions & 1 deletion glsl_reflector/modules/glsl_reflector.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module;
#include "glslang/Public/ResourceLimits.h"
#include "glslang/Public/ShaderLang.h"
export module glsl_reflector;
export import :type;
export import data_type;

namespace sopho
{
Expand Down Expand Up @@ -82,6 +82,59 @@ namespace sopho
.basic_type = to_basic_type(type->getBasicType()),
.vector_size = type->getVectorSize()});
}
count = program.getNumUniformVariables();
for (auto i = 0; i < count; i++)
{
auto var = program.getUniform(i);
}
return result;
}

export auto reflect_fragment(const std::string& fragment_source)
{
GlslangProcessGuard glslang_initializer{};
FragmentReflection result{};
glslang::TShader shader(EShLangFragment);
std::vector sources{fragment_source.data()};
shader.setStrings(sources.data(), sources.size());

int clientInputSemanticsVersion = 100; // not used for desktop GL
glslang::EShTargetClientVersion clientVersion = glslang::EShTargetOpenGL_450;
glslang::EShTargetLanguageVersion targetVersion = glslang::EShTargetSpv_1_0;

shader.setEnvInput(glslang::EShSourceGlsl, EShLangFragment, glslang::EShClientOpenGL,
clientInputSemanticsVersion);
shader.setEnvClient(glslang::EShClientOpenGL, clientVersion);
shader.setEnvTarget(glslang::EShTargetSpv, targetVersion);

EShMessages messages = (EShMessages)(EShMsgDefault | EShMsgSpvRules | EShMsgVulkanRules);

if (!shader.parse(GetDefaultResources(), 450, ENoProfile, false, false, messages))
{
std::cerr << "Parse failed:\n" << shader.getInfoLog() << std::endl;
return result;
}

glslang::TProgram program;
program.addShader(&shader);
if (!program.link(messages))
{
std::cerr << "Link failed:\n" << program.getInfoLog() << std::endl;
return result;
}
program.buildReflection();
auto count = program.getNumUniformVariables();
for (auto i = 0; i < count; i++)
{
auto var = program.getUniform(i);
auto type = var.getType();
auto basic_type = type->getBasicType();
if (basic_type == glslang::EbtSampler)
{
result.sampler_count++;
}
}
return result;
}

} // namespace sopho
30 changes: 0 additions & 30 deletions glsl_reflector/modules/glsl_reflector.type.ixx

This file was deleted.

38 changes: 38 additions & 0 deletions glsl_reflector/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,41 @@ TEST(reflect_vertex, Basic)
EXPECT_EQ(reflect_info.inputs[1].basic_type, sopho::BasicType::FLOAT);
EXPECT_EQ(reflect_info.inputs[1].vector_size, 3);
}


TEST(reflect_fragment, Basic)
{
auto reflect_info = sopho::reflect_fragment(R"(
#version 460

layout (location = 0) in vec4 v_color;
layout (location = 0) out vec4 FragColor;

layout(set = 2, binding = 0) uniform sampler2D uTexture;

void main()
{
FragColor = texture(uTexture, v_color.xy);
}
)");
EXPECT_EQ(reflect_info.sampler_count, 1);
}

TEST(reflect_fragment, Multi)
{
auto reflect_info = sopho::reflect_fragment(R"(
#version 460

layout (location = 0) in vec4 v_color;
layout (location = 0) out vec4 FragColor;

layout(set = 2, binding = 0) uniform sampler2D uTexture;
layout(set = 2, binding = 1) uniform sampler2D uTexture1;

void main()
{
FragColor = texture(uTexture, v_color.xy) + texture(uTexture1, v_color.xy);
}
)");
EXPECT_EQ(reflect_info.sampler_count, 2);
}
Loading