transparency management added

This commit is contained in:
2023-11-25 10:31:06 +01:00
parent df29e41ac5
commit db91730e13
7 changed files with 37 additions and 18 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */ /* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
/* Updated: 2023/11/23 14:32:41 by maldavid ### ########.fr */ /* Updated: 2023/11/25 10:12:36 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -100,8 +100,8 @@ extern "C"
unsigned char color_bits[4]; unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16; color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8; color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = color & 0x000000FF; color_bits[2] = (color & 0x000000FF);
color_bits[3] = 0xFF; color_bits[3] = (color & 0xFF000000) >> 24;
mlx->setTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits)); mlx->setTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits));
} }

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */ /* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
/* Updated: 2023/11/24 19:19:25 by maldavid ### ########.fr */ /* Updated: 2023/11/24 20:42:15 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */ /* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
/* Updated: 2023/11/23 14:26:06 by maldavid ### ########.fr */ /* Updated: 2023/11/25 09:59:39 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -49,7 +49,7 @@ namespace mlx
~GraphicsSupport(); ~GraphicsSupport();
private: private:
std::unordered_set<TextureRenderData> _textures_to_render; std::vector<TextureRenderData> _textures_to_render;
PixelPutPipeline _pixel_put_pipeline; PixelPutPipeline _pixel_put_pipeline;
glm::mat4 _proj = glm::mat4(1.0); glm::mat4 _proj = glm::mat4(1.0);
std::shared_ptr<MLX_Window> _window; std::shared_ptr<MLX_Window> _window;

View File

@@ -10,7 +10,9 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "renderer/images/texture.h"
#include <core/graphics.h> #include <core/graphics.h>
#include <type_traits>
namespace mlx namespace mlx
{ {
@@ -44,7 +46,17 @@ namespace mlx
void GraphicsSupport::texturePut(Texture* texture, int x, int y) void GraphicsSupport::texturePut(Texture* texture, int x, int y)
{ {
_textures_to_render.emplace(texture, x, y); _textures_to_render.emplace_back(texture, x, y);
std::size_t hash = std::hash<TextureRenderData>{}(_textures_to_render.back());
_textures_to_render.back().hash = hash;
auto it = std::find_if(_textures_to_render.begin(), _textures_to_render.end() - 1, [=](const TextureRenderData& rhs)
{
return rhs.hash == hash;
});
if(it != _textures_to_render.end() - 1)
_textures_to_render.erase(it);
} }
void GraphicsSupport::loadFont(const std::filesystem::path& filepath, float scale) void GraphicsSupport::loadFont(const std::filesystem::path& filepath, float scale)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */ /* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
/* Updated: 2023/11/16 14:01:05 by maldavid ### ########.fr */ /* Updated: 2023/11/25 10:01:35 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -66,6 +66,7 @@ namespace mlx
struct TextureRenderData struct TextureRenderData
{ {
Texture* texture; Texture* texture;
std::size_t hash = 0;
int x; int x;
int y; int y;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */ /* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
/* Updated: 2023/11/20 07:24:09 by maldavid ### ########.fr */ /* Updated: 2023/11/25 10:23:20 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -194,7 +194,7 @@ namespace mlx
fragShaderStageInfo.module = fshader; fragShaderStageInfo.module = fshader;
fragShaderStageInfo.pName = "main"; fragShaderStageInfo.pName = "main";
std::vector<VkPipelineShaderStageCreateInfo> stages = {vertShaderStageInfo, fragShaderStageInfo}; std::array<VkPipelineShaderStageCreateInfo, 2> stages = {vertShaderStageInfo, fragShaderStageInfo};
auto bindingDescription = Vertex::getBindingDescription(); auto bindingDescription = Vertex::getBindingDescription();
auto attributeDescriptions = Vertex::getAttributeDescriptions(); auto attributeDescriptions = Vertex::getAttributeDescriptions();
@@ -255,7 +255,13 @@ namespace mlx
VkPipelineColorBlendAttachmentState colorBlendAttachment{}; VkPipelineColorBlendAttachmentState colorBlendAttachment{};
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
colorBlendAttachment.blendEnable = VK_FALSE; colorBlendAttachment.blendEnable = VK_TRUE;
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
VkPipelineColorBlendStateCreateInfo colorBlending{}; VkPipelineColorBlendStateCreateInfo colorBlending{};
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
@@ -263,10 +269,10 @@ namespace mlx
colorBlending.logicOp = VK_LOGIC_OP_COPY; colorBlending.logicOp = VK_LOGIC_OP_COPY;
colorBlending.attachmentCount = 1; colorBlending.attachmentCount = 1;
colorBlending.pAttachments = &colorBlendAttachment; colorBlending.pAttachments = &colorBlendAttachment;
colorBlending.blendConstants[0] = 0.0f; colorBlending.blendConstants[0] = 1.0f;
colorBlending.blendConstants[1] = 0.0f; colorBlending.blendConstants[1] = 1.0f;
colorBlending.blendConstants[2] = 0.0f; colorBlending.blendConstants[2] = 1.0f;
colorBlending.blendConstants[3] = 0.0f; colorBlending.blendConstants[3] = 1.0f;
VkDescriptorSetLayout layouts[] = { VkDescriptorSetLayout layouts[] = {
renderer.getVertDescriptorSetLayout().get(), renderer.getVertDescriptorSetLayout().get(),

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */ /* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
/* Updated: 2023/11/24 19:08:57 by maldavid ### ########.fr */ /* Updated: 2023/11/25 10:29:56 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -29,7 +29,7 @@ int update(t_mlx *mlx)
int k; int k;
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100);
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 220, 20); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 150, 60);
mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text"); mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text");
j = 0; j = 0;
k = 0; k = 0;
@@ -65,7 +65,7 @@ void *create_image(t_mlx *mlx)
pixel[0] = i[0]; pixel[0] = i[0];
pixel[1] = i[1]; pixel[1] = i[1];
pixel[2] = i[2]; pixel[2] = i[2];
pixel[3] = 0xFF; pixel[3] = 0x99;
mlx_set_image_pixel(mlx->mlx, img, i[1], i[2], *((int *)pixel)); mlx_set_image_pixel(mlx->mlx, img, i[1], i[2], *((int *)pixel));
} }
i[0] += 4; i[0] += 4;