Draw Type with both renderers
Some checks are pending
ci/woodpecker/push/woodpecker.json Pipeline is pending
Some checks are pending
ci/woodpecker/push/woodpecker.json Pipeline is pending
This commit is contained in:
parent
e2a14db15f
commit
0f432c64bb
@ -19,12 +19,24 @@
|
||||
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 frag_color;
|
||||
layout(location = 0) in vec4 frag_color;
|
||||
layout(location = 1) in vec2 frag_texture_coordinate;
|
||||
layout(binding = 0) uniform sampler2D texture_sampler;
|
||||
layout(location = 2) flat in uint frag_draw_mode;
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
void main() {
|
||||
out_color = texture(texture_sampler, frag_texture_coordinate);
|
||||
if (frag_draw_mode == 1) {
|
||||
out_color = frag_color;
|
||||
} else {
|
||||
vec4 tex = texture(texture_sampler, frag_texture_coordinate);
|
||||
if (frag_draw_mode == 2)
|
||||
tex = frag_color * tex;
|
||||
else if (frag_draw_mode == 3)
|
||||
tex = vec4(frag_color.rgb, frag_color.a * tex.r);
|
||||
else
|
||||
tex = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
out_color = tex;
|
||||
}
|
||||
}
|
||||
|
@ -20,14 +20,17 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 in_position;
|
||||
layout(location = 2) in vec3 in_color;
|
||||
layout(location = 2) in vec4 in_color;
|
||||
layout(location = 4) in vec2 in_texture_coordinate;
|
||||
layout(location = 6) in uint in_drawmode;
|
||||
|
||||
layout(location = 0) out vec3 frag_color;
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
layout(location = 1) out vec2 frag_texture_coordinate;
|
||||
layout(location = 2) flat out uint frag_draw_mode;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 0.5, 1.0);
|
||||
gl_Position = vec4(in_position, 0.0, 1.0);
|
||||
frag_color = in_color;
|
||||
frag_texture_coordinate = in_texture_coordinate;
|
||||
frag_draw_mode = in_drawmode;
|
||||
}
|
||||
|
@ -26,14 +26,17 @@ layout(binding = 1) uniform UniformBufferObject {
|
||||
} ubo;
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 2) in vec3 in_color;
|
||||
layout(location = 2) in vec4 in_color;
|
||||
layout(location = 4) in vec2 in_texture_coordinate;
|
||||
layout(location = 6) in uint in_drawmode;
|
||||
|
||||
layout(location = 0) out vec3 frag_color;
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
layout(location = 1) out vec2 frag_texture_coordinate;
|
||||
layout(location = 2) flat out uint frag_draw_mode;
|
||||
|
||||
void main() {
|
||||
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(in_position, 1.0);
|
||||
frag_color = in_color;
|
||||
frag_texture_coordinate = in_texture_coordinate;
|
||||
frag_draw_mode = in_drawmode;
|
||||
}
|
||||
|
93
src/main.cpp
93
src/main.cpp
@ -123,11 +123,27 @@ private: // Swapchain/Framebuffer
|
||||
std::vector<vk::raii::Semaphore> vk_semephores_render_finished;
|
||||
|
||||
private:
|
||||
enum DrawMode : std::uint32_t {
|
||||
kPlain = 1,
|
||||
kTextured = 2,
|
||||
kFreetype = 3
|
||||
};
|
||||
static constexpr vk::ShaderModuleCreateInfo GetSharedShaderFragment() {
|
||||
return { .codeSize = embeded_shader_frag_glsl_spv.size, .pCode = reinterpret_cast<const std::uint32_t*>(embeded_shader_frag_glsl_spv.begin) };
|
||||
}
|
||||
|
||||
struct Vertex2 {
|
||||
glm::vec2 pos;
|
||||
glm::vec3 color;
|
||||
glm::vec4 color;
|
||||
glm::vec2 texture_coordinates;
|
||||
DrawMode draw_mode;
|
||||
|
||||
static constexpr vk::ShaderModuleCreateInfo GetShaderInfoFragment() {
|
||||
return VulkanExampleApplication::GetSharedShaderFragment();
|
||||
};
|
||||
static constexpr vk::ShaderModuleCreateInfo GetShaderInfoVertex() {
|
||||
return { .codeSize = embeded_shader_second_vertex_glsl_spv.size, .pCode = reinterpret_cast<const std::uint32_t*>(embeded_shader_second_vertex_glsl_spv.begin) };
|
||||
};
|
||||
static constexpr vk::VertexInputBindingDescription GetBindingDescription() {
|
||||
constexpr vk::VertexInputBindingDescription binding_description {
|
||||
.binding = 0,
|
||||
@ -136,8 +152,8 @@ private:
|
||||
};
|
||||
return binding_description;
|
||||
}
|
||||
static constexpr std::array<vk::VertexInputAttributeDescription, 3> GetAttributeDescriptions() {
|
||||
constexpr std::array<vk::VertexInputAttributeDescription, 3> attribute_descriptions {
|
||||
static constexpr std::array<vk::VertexInputAttributeDescription, 4> GetAttributeDescriptions() {
|
||||
constexpr std::array<vk::VertexInputAttributeDescription, 4> attribute_descriptions {
|
||||
vk::VertexInputAttributeDescription { // https://docs.vulkan.org/tutorial/latest/04_Vertex_buffers/00_Vertex_input_description.html
|
||||
.location = 0,
|
||||
.binding = 0,
|
||||
@ -146,14 +162,18 @@ private:
|
||||
vk::VertexInputAttributeDescription {
|
||||
.location = 2,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32B32Sfloat,
|
||||
.format = vk::Format::eR32G32B32A32Sfloat,
|
||||
.offset = offsetof(Vertex2, color) },
|
||||
vk::VertexInputAttributeDescription {
|
||||
.location = 4,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32Sfloat,
|
||||
.offset = offsetof(Vertex2, texture_coordinates) }
|
||||
|
||||
.offset = offsetof(Vertex2, texture_coordinates) },
|
||||
vk::VertexInputAttributeDescription {
|
||||
.location = 6,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32Uint,
|
||||
.offset = offsetof(Vertex2, draw_mode) }
|
||||
};
|
||||
return attribute_descriptions;
|
||||
}
|
||||
@ -162,11 +182,19 @@ private:
|
||||
static inline const std::vector<std::uint16_t> rectangle = { 0, 1, 2, 2, 3, 0 };
|
||||
};
|
||||
};
|
||||
|
||||
struct Vertex3 {
|
||||
glm::vec3 pos;
|
||||
glm::vec3 color;
|
||||
glm::vec4 color;
|
||||
glm::vec2 texture_coordinates;
|
||||
DrawMode draw_mode;
|
||||
|
||||
static constexpr vk::ShaderModuleCreateInfo GetShaderInfoFragment() {
|
||||
return VulkanExampleApplication::GetSharedShaderFragment();
|
||||
};
|
||||
static constexpr vk::ShaderModuleCreateInfo GetShaderInfoVertex() {
|
||||
return { .codeSize = embeded_shader_third_vertex_glsl_spv.size, .pCode = reinterpret_cast<const std::uint32_t*>(embeded_shader_third_vertex_glsl_spv.begin) };
|
||||
}
|
||||
static constexpr vk::VertexInputBindingDescription GetBindingDescription() {
|
||||
constexpr vk::VertexInputBindingDescription binding_description {
|
||||
.binding = 0,
|
||||
@ -175,8 +203,8 @@ private:
|
||||
};
|
||||
return binding_description;
|
||||
}
|
||||
static constexpr std::array<vk::VertexInputAttributeDescription, 3> GetAttributeDescriptions() {
|
||||
constexpr std::array<vk::VertexInputAttributeDescription, 3> attribute_descriptions {
|
||||
static constexpr std::array<vk::VertexInputAttributeDescription, 4> GetAttributeDescriptions() {
|
||||
constexpr std::array<vk::VertexInputAttributeDescription, 4> attribute_descriptions {
|
||||
vk::VertexInputAttributeDescription { // https://docs.vulkan.org/tutorial/latest/04_Vertex_buffers/00_Vertex_input_description.html
|
||||
.location = 0,
|
||||
.binding = 0,
|
||||
@ -185,13 +213,18 @@ private:
|
||||
vk::VertexInputAttributeDescription {
|
||||
.location = 2,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32B32Sfloat,
|
||||
.format = vk::Format::eR32G32B32A32Sfloat,
|
||||
.offset = offsetof(Vertex3, color) },
|
||||
vk::VertexInputAttributeDescription {
|
||||
.location = 4,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32Sfloat,
|
||||
.offset = offsetof(Vertex3, texture_coordinates) }
|
||||
.offset = offsetof(Vertex3, texture_coordinates) },
|
||||
vk::VertexInputAttributeDescription {
|
||||
.location = 6,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32Uint,
|
||||
.offset = offsetof(Vertex3, draw_mode) }
|
||||
|
||||
};
|
||||
return attribute_descriptions;
|
||||
@ -243,10 +276,10 @@ private:
|
||||
public:
|
||||
using IndexT = std::uint16_t;
|
||||
|
||||
void CreatePipeline(const vk::raii::Device& gpu, const vk::RenderPass& render_pass, const std::pair<vk::ShaderModuleCreateInfo, vk::ShaderModuleCreateInfo>& gfx_shaders, const vk::SampleCountFlagBits& msaa_samples = vk::SampleCountFlagBits::e1) {
|
||||
void CreatePipeline(const vk::raii::Device& gpu, const vk::RenderPass& render_pass, const vk::SampleCountFlagBits& msaa_samples = vk::SampleCountFlagBits::e1) {
|
||||
{ // Load Shaders
|
||||
this->vk_shader_vertex.emplace(gpu, gfx_shaders.first);
|
||||
this->vk_shader_frag.emplace(gpu, gfx_shaders.second);
|
||||
this->vk_shader_vertex.emplace(gpu, VertexT::GetShaderInfoVertex());
|
||||
this->vk_shader_frag.emplace(gpu, VertexT::GetShaderInfoFragment());
|
||||
}
|
||||
{
|
||||
constexpr auto descriptor_set_layout_bindings = [&]() {
|
||||
@ -550,22 +583,22 @@ private:
|
||||
VulkanRenderPipeline<Vertex3> vk_pipeline_third;
|
||||
|
||||
static inline const std::vector<Vertex2> vertices_rect_sample = {
|
||||
{ { -0.2f, -0.2f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f } },
|
||||
{ { 0.2f, -0.2f }, { 0.0f, 1.0f, 0.0f }, { 1.0f, 0.0f } },
|
||||
{ { 0.2f, 0.2f }, { 0.0f, 0.0f, 1.0f }, { 1.0f, 1.0f } },
|
||||
{ { -0.2f, 0.2f }, { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f } }
|
||||
{ { -0.2f, -0.2f }, { 0.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f }, DrawMode::kTextured },
|
||||
{ { 0.2f, -0.2f }, { 1.0f, 1.0f, 1.0f, 1.0f }, { 1.0f, 0.0f }, DrawMode::kTextured },
|
||||
{ { 0.2f, 0.2f }, { 1.0f, 1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f }, DrawMode::kTextured },
|
||||
{ { -0.2f, 0.2f }, { 1.0f, 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f }, DrawMode::kTextured }
|
||||
};
|
||||
|
||||
static inline const std::vector<Vertex3> vertices_cube_sample = {
|
||||
{ { -0.5f, -0.5f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f } },
|
||||
{ { 0.5f, -0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 1.0f, 0.0f } },
|
||||
{ { 0.5f, 0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f }, { 1.0f, 1.0f } },
|
||||
{ { -0.5f, 0.5f, 0.0f }, { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f } },
|
||||
{ { -0.5f, -0.5f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f }, DrawMode::kTextured },
|
||||
{ { 0.5f, -0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, { 1.0f, 0.0f }, DrawMode::kTextured },
|
||||
{ { 0.5f, 0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f }, { 1.0f, 1.0f }, DrawMode::kTextured },
|
||||
{ { -0.5f, 0.5f, 0.0f }, { 1.0f, 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f }, DrawMode::kTextured },
|
||||
|
||||
{ { -0.5f, -0.5f, -0.5f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f } },
|
||||
{ { 0.5f, -0.5f, -0.5f }, { 0.0f, 1.0f, 0.0f }, { 1.0f, 0.0f } },
|
||||
{ { 0.5f, 0.5f, -0.5f }, { 0.0f, 0.0f, 1.0f }, { 1.0f, 1.0f } },
|
||||
{ { -0.5f, 0.5f, -0.5f }, { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f } }
|
||||
{ { -0.5f, -0.5f, -0.5f }, { 1.0f, 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f }, DrawMode::kTextured },
|
||||
{ { 0.5f, -0.5f, -0.5f }, { 0.0f, 1.0f, 0.0f, 1.0f }, { 1.0f, 0.0f }, DrawMode::kTextured },
|
||||
{ { 0.5f, 0.5f, -0.5f }, { 0.0f, 0.0f, 1.0f, 1.0f }, { 1.0f, 1.0f }, DrawMode::kTextured },
|
||||
{ { -0.5f, 0.5f, -0.5f }, { 1.0f, 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f }, DrawMode::kTextured }
|
||||
};
|
||||
|
||||
private:
|
||||
@ -982,12 +1015,8 @@ public:
|
||||
this->vk_render_pass.emplace(*this->vk_gpu, render_pass_create_info);
|
||||
}
|
||||
{
|
||||
const auto shader_info_frag = vk::ShaderModuleCreateInfo { .codeSize = embeded_shader_frag_glsl_spv.size, .pCode = reinterpret_cast<const std::uint32_t*>(embeded_shader_frag_glsl_spv.begin) };
|
||||
const auto shader_second_info_vertex = vk::ShaderModuleCreateInfo { .codeSize = embeded_shader_second_vertex_glsl_spv.size, .pCode = reinterpret_cast<const std::uint32_t*>(embeded_shader_second_vertex_glsl_spv.begin) };
|
||||
this->vk_pipeline_second.CreatePipeline(*this->vk_gpu, *this->vk_render_pass, { shader_second_info_vertex, shader_info_frag }, this->vk_msaa_samples);
|
||||
|
||||
const auto shader_third_info_vertex = vk::ShaderModuleCreateInfo { .codeSize = embeded_shader_third_vertex_glsl_spv.size, .pCode = reinterpret_cast<const std::uint32_t*>(embeded_shader_third_vertex_glsl_spv.begin) };
|
||||
this->vk_pipeline_third.CreatePipeline(*this->vk_gpu, *this->vk_render_pass, { shader_third_info_vertex, shader_info_frag }, this->vk_msaa_samples);
|
||||
this->vk_pipeline_second.CreatePipeline(*this->vk_gpu, *this->vk_render_pass, this->vk_msaa_samples);
|
||||
this->vk_pipeline_third.CreatePipeline(*this->vk_gpu, *this->vk_render_pass, this->vk_msaa_samples);
|
||||
}
|
||||
{
|
||||
this->CreateBufferFrame();
|
||||
|
Loading…
x
Reference in New Issue
Block a user