Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
850ed51
Merge the graphics library into the main library(Some functions have …
YuanSang0512 Apr 26, 2026
232204b
Merge the graphics library into the main library(Some functions have …
YuanSang0512 Apr 26, 2026
708a0ae
fix
YuanSang0512 Apr 26, 2026
5aa84e0
Fix Windows workflow
YuanSang0512 Apr 27, 2026
5f1d9c0
Merge branch 'gkit-org:main' into feature/merge-render-lib
YuanSang0512 Apr 27, 2026
b6eae64
Modify the comment format
YuanSang0512 Apr 27, 2026
1473be0
Change Renderer and StateManager to inherit from singleton template c…
YuanSang0512 Apr 29, 2026
6f9422f
The VertexBuffer has added the UpdateSubData and UpdateData interfaces.
YuanSang0512 Apr 29, 2026
b38b06a
delete auto gkit::graphic::Renderer::Draw(const gkit::graphic::opengl…
YuanSang0512 Apr 29, 2026
b8e29e4
Disable copy functionality, enable move functionality; fix spelling e…
YuanSang0512 Apr 29, 2026
c449122
Fix the bug in VAO index
YuanSang0512 Apr 29, 2026
a2e4fe3
Modify the function naming method
YuanSang0512 Apr 30, 2026
577dfc3
Remove the Get method of the Renderer、StateManager
YuanSang0512 Apr 30, 2026
4f9dc33
Add shader compilation and linking checks; Access log system
YuanSang0512 Apr 30, 2026
5a526fd
Fix shader parsing undefined behavior and add validation;Change CMake…
YuanSang0512 Apr 30, 2026
5a57f27
Some minor modifications regarding function naming
YuanSang0512 Apr 30, 2026
43892a4
Remove third-party header files from the public header file
YuanSang0512 Jun 1, 2026
015c58a
Remove the hardcoded Python address and revert the .yml file for Wind…
YuanSang0512 Jun 1, 2026
e8105ff
fix: use PowerShell instead of cmd
YuanSang0512 Jun 1, 2026
6538ad7
debug: workflow on windows
YuanSang0512 Jun 18, 2026
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
36 changes: 29 additions & 7 deletions .github/workflows/windows-debug-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
name: Build and Test on Windows
runs-on: windows-latest
strategy:
matrix:
matrix:
preset: [ "windows-x86_64-mingw64-debug",
"windows-x86_64-llvm-debug",
"windows-x86_64-msvc-debug",]

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -31,23 +31,45 @@ jobs:
echo "Repository: ${{ github.repository }}"
echo "Commit SHA: ${{ github.sha }}"

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Debug Python paths
shell: pwsh
run: |
echo "🔍 Python paths:"
python --version
python -c "import sys; print('sys.executable ->', sys.executable)"
echo "--- where.exe python ---"
where.exe python
echo "--- where.exe python3 ---"
where.exe python3

- name: Install dependencies
shell: pwsh
run: |
echo "📦 Installing Windows dependencies..."

$py = python -c "import sys; print(sys.executable)"
echo "Python used for install: $py"
python -m pip install jinja2
echo "✅ Windows dependencies installed successfully"

- name: Configure MSVC
if: ${{ matrix.preset == 'windows-x86_64-msvc-debug' || matrix.preset == 'windows-x86_64-msvc-noabi-debug' }}
uses: TheMrMilchmann/setup-msvc-dev@v4.0.0
with:
with:
arch: x64

- name: Configure CMake
shell: pwsh
run: |
echo "⚙️ Configuring CMake ..."
echo "Using preset: ${{matrix.preset}}"
cmake --preset ${{matrix.preset}}
$PythonPath = python -c "import sys; print(sys.executable)"
echo "Using Python: $PythonPath"
cmake --preset ${{matrix.preset}} "-DPython_EXECUTABLE=$PythonPath"
echo "✅ CMake configuration completed"

- name: Configure and build project
Expand All @@ -64,7 +86,7 @@ jobs:
echo "🎉 Build process completed!"
echo "Platform: ${{ runner.os }}"
echo "Job status: ${{ job.status }}"

# # List built files
# echo "📁 Built files:"
# find ${{ github.workspace }}/build -name "*.so" -o -name "*.dll" -o -name "*.a" -o -name "*.lib" 2>/dev/null || echo "No library files found"
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ AGENTS.md

# binary files
bin/
build/
build/

# third party generated
third_party/glad_generated/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
path = third_party/sdl_image
url = https://github.com/libsdl-org/SDL_image.git
branch = release-3.4.x
[submodule "third_party/glad"]
path = third_party/glad
url = https://github.com/Dav1dde/glad.git
49 changes: 49 additions & 0 deletions include/gkit/graphic/Renderer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include "opengl/IndexBuffer.hpp"
#include "opengl/VertexArray.hpp"
#include "Shader.hpp"
#include "opengl/config.hpp"
Comment on lines +3 to +6

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

头文件包含应从 gkit 目录开始(用户代码包含该头文件时会错误)

#include "gkit/core/scene/singleton.hpp"

#include <cstdint>

/**
* @brief Renderer class providing public rendering interface
*
* The Renderer provides a unified interface for rendering operations.
* Uses singleton pattern for global access.
*/
namespace gkit::graphic {

class Renderer : public core::scene::Singleton<Renderer> {
public:
Renderer() = default;

/**
* @brief Clear the current framebuffer
*
* @param flags Bitmask specifying which buffers to clear (e.g., ClearFlags::Color | ClearFlags::Depth)
* Defaults to ClearFlags::All (clears all buffers)
*/
auto clear(opengl::ClearFlags flags = opengl::ClearFlags::All) const -> void;

/**
* @brief Draw indexed geometry
* @param va Vertex array containing vertex data
* @param ib Index buffer containing indices
* @param shader Shader program to use for rendering
*/
auto draw(const gkit::graphic::opengl::VertexArray& va, const gkit::graphic::opengl::buffer::IndexBuffer& ib, const gkit::graphic::Shader& shader) const -> void;

/**
* @brief Draw multiple instances of indexed geometry
* @param va Vertex array containing vertex data
* @param ib Index buffer containing indices
* @param shader Shader program to use for rendering
* @param instanceCount Number of instances to draw
*/
auto draw_instance(const gkit::graphic::opengl::VertexArray& va, const gkit::graphic::opengl::buffer::IndexBuffer& ib, const gkit::graphic::Shader& shader, uint32_t instanceCount) const -> void;
};

} // namespace gkit::graphic
158 changes: 158 additions & 0 deletions include/gkit/graphic/Shader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#pragma once

#include <string>
#include <unordered_map>
#include <cstdint>

namespace gkit::graphic{
/**
* @brief Structure holding parsed shader source code
*/
struct ShaderProgramSource {
std::string vertexShader; ///< Vertex shader source code
std::string fragmentShader; ///< Fragment shader source code (note: typo in original)
};

/**
* @brief Shader wrapper for OpenGL shader programs
*
* Provides functionality to load, compile, and manage shader programs
* including uniform variable manipulation.
*/
class Shader {
public:
Shader(const Shader&) = delete;
Shader& operator=(const Shader&) = delete;

/** @brief Move constructor - transfers ownership of GL shader program
* @param other Source object to move from (will be invalidated)
*/
Shader(Shader&& other) noexcept;

/** @brief Move assignment - transfers ownership of GL shader program
* @param other Source object to move from (will be invalidated)
* @note Releases any existing GL shader program before taking ownership
*/
auto operator=(Shader&& other) noexcept -> Shader&;

private:
uint32_t m_RendererID; ///< OpenGL shader program ID
std::string m_FilePath; ///< Path to the shader file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改为 std::filepath 类型

std::unordered_map<std::string, int> m_UniformLocationCach; ///< Cache for uniform locations
public:
/**
* @brief Construct a shader from a file
* @param filepath Path to the shader source file
*/
Shader(const std::string& filepath);

/**
* @brief Destructor - deletes the shader program
*/
~Shader();

Comment thread
YuanSang0512 marked this conversation as resolved.
/**
* @brief Bind this shader program to the current OpenGL context
*/
auto bind() const -> void;

/**
* @brief Unbind this shader program from the current OpenGL context
*/
auto unbind() const -> void;

// Uniform setters

/**
* @brief Set an integer uniform variable
* @param name Name of the uniform
* @param value Integer value to set
*/
auto set_uniform_1i(const std::string& name, int value) -> void;

/**
* @brief Set a float uniform variable
* @param name Name of the uniform
* @param value Float value to set
*/
auto set_uniform_1f(const std::string& name, float value) -> void;

/**
* @brief Set a 4-component float uniform variable
* @param name Name of the uniform
* @param v0 First component
* @param v1 Second component
* @param f2 Third component
* @param f3 Fourth component
*/
auto set_uniform_4f(const std::string& name, float v0, float v1, float f2, float f3) -> void;

/**
* @brief Set a 4-component float vector uniform
* @param name Name of the uniform
* @param vector4 Pointer to 4-component float array
*/
auto set_uniform_vec_4f(const std::string& name, const float* vector4) -> void;

/**
* @brief Set a 3-component float vector uniform
* @param name Name of the uniform
* @param vector3 Pointer to 3-component float array
*/
auto set_uniform_vec_3f(const std::string& name, const float* vector3) -> void;

/**
* @brief Set a 4x4 float matrix uniform
* @param name Name of the uniform
* @param matrix Pointer to 16-element float array (column-major)
*/
auto set_uniform_mat_4f(const std::string& name, const float* matrix) -> void;

/**
* @brief Set a 3x3 float matrix uniform
* @param name Name of the uniform
* @param matrix Pointer to 9-element float array (column-major)
*/
auto set_uniform_mat_3f(const std::string& name, const float* matrix) -> void;

/**
* @brief Set an array of integer uniform variables
* @param name Name of the uniform
* @param sz Number of elements
* @param ind Array of integer values
*/
auto set_uniform_1iv(const std::string& name, const int sz, const int* ind) -> void;

private:
/**
* @brief Parse shader source from file
* @param filePath Path to the shader file
* @return Parsed shader source structure
*/
auto parse_shader(const std::string& filePath) -> ShaderProgramSource;

/**
* @brief Compile a shader of the specified type
* @param type Shader type (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
* @param source Shader source code
* @return Compiled shader ID
*/
auto compile_shader(uint32_t type, const std::string& source) -> uint32_t;

/**
* @brief Create a shader program from vertex and fragment shaders
* @param vertexShader Vertex shader source
* @param fragmentShader Fragment shader source
* @return Linked shader program ID
*/
auto create_shader(const std::string& vertexShader, const std::string& fragmentShader) -> uint32_t;

/**
* @brief Get the location of a uniform variable
* @param name Name of the uniform
* @return Location ID, or -1 if not found
*/
auto get_uniform_location(const std::string& name) -> int;

};
}
Loading
Loading