Graphics v0.0.0
A simple abstraction layer for the modern graphics APIs.
载入中...
搜索中...
未找到
GLCommandBuffer.h
1// Copyright 2022 ShenMian
2// License(Apache-2.0)
3
4#pragma once
5
6#include "CommandBuffer.h"
7#include "GLIndexBuffer.h"
8#include "GLTexture.h"
9#include "GLVertexBuffer.h"
10#include <cstdint>
11#include <vector>
12
13enum class GLOpcode;
14
16{
17public:
18 void begin() override;
19 void end() override;
20
21 void begin_render_pass() override;
22 void end_render_pass() override;
23
24 void set_viewport(const Viewport& viewport) override;
25
26 void set_pipeline(std::shared_ptr<Pipeline> pipeline) override;
27
28 void set_vertex_buffer(std::shared_ptr<VertexBuffer> vertex_buffer) override;
29 void set_index_buffer(std::shared_ptr<IndexBuffer> index_buffer) override;
30 void set_texture(std::shared_ptr<Texture> texture, unsigned int slot) override;
31
32 void clear(uint8_t flags) override;
33 void set_clear_color(const Vector4& color) override;
34 void set_clear_depth(float depth) override;
35 void set_clear_stencil(uint32_t value) override;
36
37 void draw(uint32_t vertex_count, uint32_t first_vertex) override;
38 void draw_indexed(uint32_t index_count, uint32_t first_index) override;
39
40 const auto& get_data() const;
41
42private:
43 void add_command(GLOpcode opcode);
44 template <typename T>
45 T* add_command(GLOpcode opcode);
46
47 std::vector<uint8_t> buffer;
48};
49
50inline const auto& GLCommandBuffer::get_data() const
51{
52 return buffer;
53}
54
55template <typename T>
56inline T* GLCommandBuffer::add_command(GLOpcode opcode)
57{
58 auto offset = buffer.size();
59 buffer.push_back(static_cast<uint8_t>(opcode));
60 buffer.resize(offset + sizeof(GLOpcode) + sizeof(T));
61 return reinterpret_cast<T*>(&buffer[offset + sizeof(GLOpcode)]);
62}
63
64enum class GLOpcode
65{
66 setViewport,
67
68 setPipeline,
69
70 setVertexBuffer,
71 setIndexBuffer,
72 setTexture,
73
74 clear,
75 setClearColor,
76 setClearDepth,
77 setClearStencil,
78
79 draw,
80 drawIndexed
81};
82
84{
85 GLint x, y;
86 GLsizei width, height;
87 GLfloat n, f;
88};
89
91{
92 std::shared_ptr<Pipeline> pipeline;
93};
94
96{
97 std::shared_ptr<GLVertexBuffer> vertexBuffer;
98};
99
101{
102 std::shared_ptr<GLIndexBuffer> indexBuffer;
103};
104
106{
107 std::shared_ptr<GLTexture> texture;
108 unsigned int slot;
109};
110
112{
113 uint8_t flags;
114};
115
117{
118 Vector4 color;
119};
120
122{
123 float depth;
124};
125
127{
128 int s;
129};
130
132{
133 uint32_t firstVertex;
134 uint32_t vertexCount;
135};
136
138{
139 uint32_t firstIndex;
140 uint32_t indexCount;
141};
命令缓冲区.
Definition: CommandBuffer.h:31
Definition: GLCommandBuffer.h:16
void set_clear_depth(float depth) override
设置清空深度缓冲区的默认值.
Definition: GLCommandBuffer.cpp:83
void set_clear_color(const Vector4 &color) override
设置清空颜色缓冲区的默认值.
Definition: GLCommandBuffer.cpp:77
void end() override
结束记录命令.
Definition: GLCommandBuffer.cpp:23
void set_clear_stencil(uint32_t value) override
设置清空模板缓冲区的默认值.
Definition: GLCommandBuffer.cpp:89
void clear(uint8_t flags) override
清空缓冲区.
Definition: GLCommandBuffer.cpp:71
void begin() override
开始记录命令.
Definition: GLCommandBuffer.cpp:18
Definition: GLCommandBuffer.h:112
Definition: GLCommandBuffer.h:132
Definition: GLCommandBuffer.h:138
Definition: GLCommandBuffer.h:117
Definition: GLCommandBuffer.h:122
Definition: GLCommandBuffer.h:127
Definition: GLCommandBuffer.h:101
Definition: GLCommandBuffer.h:91
Definition: GLCommandBuffer.h:106
Definition: GLCommandBuffer.h:96
Definition: GLCommandBuffer.h:84
视口.
Definition: Viewport.hpp:12