jGL
Loading...
Searching...
No Matches
vkTextRenderer.h
Go to the documentation of this file.
1#ifndef VKTEXTRENDERER_H
2#define VKTEXTRENDERER_H
3
7#include <memory>
8
9namespace jGL::Vulkan
10{
11
13 {
14
15 public:
16
18 (
19 const Device & device,
20 const Command & command,
21 const RenderPass & renderPass,
22 const VkViewport & viewport,
23 const VkRect2D & scissor,
24 uint32_t concurrentFrames,
25 VkSampleCountFlagBits msaa
26 );
27
29
30 void renderText
31 (
32 const Device & device,
33 const Command & command,
34 const VkCommandBuffer & commandBuffer,
35 uint32_t currentFrame,
36 std::string text,
37 glm::vec2 position,
38 float scale,
39 glm::vec4 colour,
40 glm::bvec2 centre = glm::bvec2(false,false)
41 );
42
43 void setProjection(glm::mat4 p);
44
45 private:
46
47 const char * vert = "#version 450\n"
48 "layout(location = 0) in vec4 posTex;\n"
49 "layout(set = 0, binding = 0) uniform vUBO { mat4 proj; } ubo;\n"
50 "layout(location = 0) out vec2 texCoords;\n"
51 "void main()\n"
52 "{\n"
53 " gl_Position = ubo.proj * vec4(posTex.xy, 0.0, 1.0);\n"
54 " texCoords = posTex.zw;\n"
55 "}\n";
56
57 const char * frag = "#version 450\n"
58 "layout(location = 0) in vec2 texCoords;\n"
59 "layout(location = 0) out vec4 colour;\n"
60 "layout(set = 0, binding = 1) uniform fUBO { vec4 textColour; } ubo;\n"
61 "layout(set = 1, binding = 0) uniform usampler2D glyph;\n"
62 "void main()\n"
63 "{\n"
64 " vec4 glpyhSample = vec4(1.0,1.0,1.0, texture(glyph,texCoords.xy).r);\n"
65 " colour = ubo.textColour*glpyhSample;\n"
66 "}";
67
68 vkShader shader;
69
70 std::shared_ptr<VertexBufferObject> pos;
71 std::shared_ptr<UniformBufferObject> uboV, uboF;
72 std::vector<glm::vec4> vertices;
73
74 VkImageView characterTextureView;
75
76 std::shared_ptr<vkTexture> fontTexture;
77 std::shared_ptr<Sampler> fontSampler;
78
79 std::unique_ptr<vkFont> font;
80
81 std::unique_ptr<Pipeline> textPipeline;
82
83 struct vUBO {glm::mat4 proj;};
84 struct fUBO {glm::vec4 colour;};
85
86 glm::ivec2 res;
87
88 };
89}
90
91#endif /* TEXTRENDERER */
Definition command.h:12
Definition device.h:10
Definition renderPass.h:11
Definition vkTextRenderer.h:13
void setProjection(glm::mat4 p)
Definition vkTextRenderer.cpp:119
void renderText(const Device &device, const Command &command, const VkCommandBuffer &commandBuffer, uint32_t currentFrame, std::string text, glm::vec2 position, float scale, glm::vec4 colour, glm::bvec2 centre=glm::bvec2(false, false))
Definition vkTextRenderer.cpp:127
~TextRenderer()
Definition vkTextRenderer.h:28
Definition vkShader.h:19
Definition buffer.h:10