Graphics v0.0.0
A simple abstraction layer for the modern graphics APIs.
载入中...
搜索中...
未找到
Program.h
1// Copyright 2022 ShenMian
2// License(Apache-2.0)
3
4#pragma once
5
6#include <math/math.hpp>
7#include <memory>
8#include <string>
9#include <unordered_map>
10
11class Shader;
12
21{
22public:
23 struct Descriptor;
24
30 [[nodiscard]] static std::shared_ptr<Program> create(const Descriptor& desc);
31
39 [[nodiscard]] static std::shared_ptr<Program> create(std::string_view name);
40
41 virtual void use() = 0;
42
43 virtual void set_uniform(const std::string& name, int value) = 0;
44 virtual void set_uniform(const std::string& name, float value) = 0;
45 virtual void set_uniform(const std::string& name, const Vector2& value) = 0;
46 virtual void set_uniform(const std::string& name, const Vector3& value) = 0;
47 virtual void set_uniform(const std::string& name, const Vector4& value) = 0;
48 virtual void set_uniform(const std::string& name, const Matrix4& value) = 0;
49
50 int get_stage_count() const;
51
52protected:
53 Program(const Descriptor& desc);
54
55 std::string name_;
56 int stage_count_ = 0;
57
58 inline static std::unordered_map<std::string, std::shared_ptr<Program>> cache_;
59};
60
62{
63 std::string name;
64 std::shared_ptr<Shader> vertex;
65 std::shared_ptr<Shader> fragment;
66 std::shared_ptr<Shader> geometry;
67 std::shared_ptr<Shader> compute;
68};
69
着色器程序.
Definition: Program.h:21
static std::shared_ptr< Program > create(const Descriptor &desc)
创建着色器阶段.
Definition: Program.cpp:18
着色器阶段.
Definition: Shader.h:20
Definition: Program.h:62