Tiny C++ software renderer/rasterizer that implements the main steps of the GPU rendering pipeline, including point, line and polygon rasterization, texture mapping, depth testing, color blending, etc., and emulates vertex shaders and fragment shaders using C++, 3D models (GLTF) are loaded by Assimp, and using GLM as math library. The project also adds OpenGL and Vulkan renderers implementation, you can switch between them (Software/OpenGL/Vulkan) in real time while running.
The purpose of this project is to provide a starting point for developers who want to learn about modern graphics programming.
dFdx
dFdy
Lod
, Bias
, Offset
Linear
imgui
All renderers (Software/OpenGL/Vulkan) are implemented based on this abstract renderer class:
class Renderer {
public:
// framebuffer
std::shared_ptr<FrameBuffer> createFrameBuffer(bool offscreen);
// texture
std::shared_ptr<Texture> createTexture(const TextureDesc &desc);
// vertex
std::shared_ptr<VertexArrayObject> createVertexArrayObject(const VertexArray &vertexArray);
// shader program
std::shared_ptr<ShaderProgram> createShaderProgram();
// pipeline states
std::shared_ptr<PipelineStates> createPipelineStates(const RenderStates &renderStates);
// uniform
std::shared_ptr<UniformBlock> createUniformBlock(const std::string &name, int size);
std::shared_ptr<UniformSampler> createUniformSampler(const std::string &name, const TextureDesc &desc);
// pipeline
void beginRenderPass(std::shared_ptr<FrameBuffer> &frameBuffer, const ClearStates &states);
void setViewPort(int x, int y, int width, int height);
void setVertexArrayObject(std::shared_ptr<VertexArrayObject> &vao);
void setShaderProgram(std::shared_ptr<ShaderProgram> &program);
void setShaderResources(std::shared_ptr<ShaderResources> &uniforms);
void setPipelineStates(std::shared_ptr<PipelineStates> &states);
void draw();
void endRenderPass();
};
To build the project, you must first install the following tools:
If you want to run the vulkan renderer, you need to install vulkan library as follows:
To get the code for this library, you can clone the GitHub repository using the following command:
git clone https://github.com/keith2018/SoftGLRender.git
Alternatively, you can download the source code as a ZIP file from the GitHub repository.
To build the project, navigate to the root directory of the repository and run the following commands:
mkdir build
cmake -B ./build -DCMAKE_BUILD_TYPE=Release
cmake --build ./build --config Release
This will generate the executable file and copy assets to directory bin
, which you can run by executing the following
command:
cd bin/Release
./SoftGLRender
assets
: GLTF models and skybox textures, assets.json
is the index of all model & skybox materialssrc
: Main source code directory
Base
: Basic utility classes like file, hash, timer, etc.Render
: Renderer abstraction, include vertex, texture, uniform, framebuffer, etc.
Software
: Software renderer implementationOpenGL
: OpenGL renderer implementationVulkan
: Vulkan renderer implementationViewer
: GLTF loading (based on Assimp), camera & controller, config panel, and render pass management
Shader/GLSL
: GLSL shader code, for OpenGL & Vulkan rendererShader/Software
: C++ simulation of vertex shaders and fragment shadersthird_party
: External libraries and assetsassimp
https://github.com/assimp/assimpglfw
https://github.com/glfw/glfwglm
https://github.com/g-truc/glmglslang
https://github.com/KhronosGroup/glslangimgui
https://github.com/ocornut/imguijson11
https://github.com/dropbox/json11stb_image
https://github.com/nothings/stbvma
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocatorIf you would like to contribute to the project, you are welcome to submit pull requests with bug fixes, new features, or other improvements. Please ensure that your code is well-documented and adheres to the project's coding standards.
This code is licensed under the MIT License (see LICENSE).