-
Notifications
You must be signed in to change notification settings - Fork 5
Merge graphics library into main library with untested functions #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YuanSang0512
wants to merge
20
commits into
gkit-org:main
Choose a base branch
from
YuanSang0512:feature/merge-render-lib
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 232204b
Merge the graphics library into the main library(Some functions have …
YuanSang0512 708a0ae
fix
YuanSang0512 5aa84e0
Fix Windows workflow
YuanSang0512 5f1d9c0
Merge branch 'gkit-org:main' into feature/merge-render-lib
YuanSang0512 b6eae64
Modify the comment format
YuanSang0512 1473be0
Change Renderer and StateManager to inherit from singleton template c…
YuanSang0512 6f9422f
The VertexBuffer has added the UpdateSubData and UpdateData interfaces.
YuanSang0512 b38b06a
delete auto gkit::graphic::Renderer::Draw(const gkit::graphic::opengl…
YuanSang0512 b8e29e4
Disable copy functionality, enable move functionality; fix spelling e…
YuanSang0512 c449122
Fix the bug in VAO index
YuanSang0512 a2e4fe3
Modify the function naming method
YuanSang0512 577dfc3
Remove the Get method of the Renderer、StateManager
YuanSang0512 4f9dc33
Add shader compilation and linking checks; Access log system
YuanSang0512 5a526fd
Fix shader parsing undefined behavior and add validation;Change CMake…
YuanSang0512 5a57f27
Some minor modifications regarding function naming
YuanSang0512 43892a4
Remove third-party header files from the public header file
YuanSang0512 015c58a
Remove the hardcoded Python address and revert the .yml file for Wind…
YuanSang0512 e8105ff
fix: use PowerShell instead of cmd
YuanSang0512 6538ad7
debug: workflow on windows
YuanSang0512 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,7 @@ AGENTS.md | |
|
|
||
| # binary files | ||
| bin/ | ||
| build/ | ||
| build/ | ||
|
|
||
| # third party generated | ||
| third_party/glad_generated/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| #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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 改为 |
||
| 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(); | ||
|
|
||
|
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; | ||
|
|
||
| }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
头文件包含应从
gkit目录开始(用户代码包含该头文件时会错误)