Skip to content

Commit 49c211c

Browse files
committed
transparency management added
1 parent 38768c8 commit 49c211c

File tree

7 files changed

+37
-18
lines changed

7 files changed

+37
-18
lines changed

src/core/bridge.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
9-
/* Updated: 2023/11/23 14:32:41 by maldavid ### ########.fr */
9+
/* Updated: 2023/11/25 10:12:36 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -100,8 +100,8 @@ extern "C"
100100
unsigned char color_bits[4];
101101
color_bits[0] = (color & 0x00FF0000) >> 16;
102102
color_bits[1] = (color & 0x0000FF00) >> 8;
103-
color_bits[2] = color & 0x000000FF;
104-
color_bits[3] = 0xFF;
103+
color_bits[2] = (color & 0x000000FF);
104+
color_bits[3] = (color & 0xFF000000) >> 24;
105105
mlx->setTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits));
106106
}
107107

src/core/graphics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
9-
/* Updated: 2023/11/24 19:19:25 by maldavid ### ########.fr */
9+
/* Updated: 2023/11/24 20:42:15 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

src/core/graphics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
9-
/* Updated: 2023/11/23 14:26:06 by maldavid ### ########.fr */
9+
/* Updated: 2023/11/25 09:59:39 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -49,7 +49,7 @@ namespace mlx
4949
~GraphicsSupport();
5050

5151
private:
52-
std::unordered_set<TextureRenderData> _textures_to_render;
52+
std::vector<TextureRenderData> _textures_to_render;
5353
PixelPutPipeline _pixel_put_pipeline;
5454
glm::mat4 _proj = glm::mat4(1.0);
5555
std::shared_ptr<MLX_Window> _window;

src/core/graphics.inl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
/* */
1111
/* ************************************************************************** */
1212

13+
#include "renderer/images/texture.h"
1314
#include <core/graphics.h>
15+
#include <type_traits>
1416

1517
namespace mlx
1618
{
@@ -44,7 +46,17 @@ namespace mlx
4446

4547
void GraphicsSupport::texturePut(Texture* texture, int x, int y)
4648
{
47-
_textures_to_render.emplace(texture, x, y);
49+
_textures_to_render.emplace_back(texture, x, y);
50+
std::size_t hash = std::hash<TextureRenderData>{}(_textures_to_render.back());
51+
_textures_to_render.back().hash = hash;
52+
53+
auto it = std::find_if(_textures_to_render.begin(), _textures_to_render.end() - 1, [=](const TextureRenderData& rhs)
54+
{
55+
return rhs.hash == hash;
56+
});
57+
58+
if(it != _textures_to_render.end() - 1)
59+
_textures_to_render.erase(it);
4860
}
4961

5062
void GraphicsSupport::loadFont(const std::filesystem::path& filepath, float scale)

src/renderer/images/texture.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
9-
/* Updated: 2023/11/16 14:01:05 by maldavid ### ########.fr */
9+
/* Updated: 2023/11/25 10:01:35 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -66,6 +66,7 @@ namespace mlx
6666
struct TextureRenderData
6767
{
6868
Texture* texture;
69+
std::size_t hash = 0;
6970
int x;
7071
int y;
7172

src/renderer/pipeline/pipeline.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
9-
/* Updated: 2023/11/20 07:24:09 by maldavid ### ########.fr */
9+
/* Updated: 2023/11/25 10:23:20 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -194,7 +194,7 @@ namespace mlx
194194
fragShaderStageInfo.module = fshader;
195195
fragShaderStageInfo.pName = "main";
196196

197-
std::vector<VkPipelineShaderStageCreateInfo> stages = {vertShaderStageInfo, fragShaderStageInfo};
197+
std::array<VkPipelineShaderStageCreateInfo, 2> stages = {vertShaderStageInfo, fragShaderStageInfo};
198198

199199
auto bindingDescription = Vertex::getBindingDescription();
200200
auto attributeDescriptions = Vertex::getAttributeDescriptions();
@@ -255,18 +255,24 @@ namespace mlx
255255

256256
VkPipelineColorBlendAttachmentState colorBlendAttachment{};
257257
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
258-
colorBlendAttachment.blendEnable = VK_FALSE;
258+
colorBlendAttachment.blendEnable = VK_TRUE;
259+
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
260+
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
261+
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
262+
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
263+
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
264+
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
259265

260266
VkPipelineColorBlendStateCreateInfo colorBlending{};
261267
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
262268
colorBlending.logicOpEnable = VK_FALSE;
263269
colorBlending.logicOp = VK_LOGIC_OP_COPY;
264270
colorBlending.attachmentCount = 1;
265271
colorBlending.pAttachments = &colorBlendAttachment;
266-
colorBlending.blendConstants[0] = 0.0f;
267-
colorBlending.blendConstants[1] = 0.0f;
268-
colorBlending.blendConstants[2] = 0.0f;
269-
colorBlending.blendConstants[3] = 0.0f;
272+
colorBlending.blendConstants[0] = 1.0f;
273+
colorBlending.blendConstants[1] = 1.0f;
274+
colorBlending.blendConstants[2] = 1.0f;
275+
colorBlending.blendConstants[3] = 1.0f;
270276

271277
VkDescriptorSetLayout layouts[] = {
272278
renderer.getVertDescriptorSetLayout().get(),

test/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
9-
/* Updated: 2023/11/24 19:08:57 by maldavid ### ########.fr */
9+
/* Updated: 2023/11/25 10:29:56 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -29,7 +29,7 @@ int update(t_mlx *mlx)
2929
int k;
3030

3131
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100);
32-
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 220, 20);
32+
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 150, 60);
3333
mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text");
3434
j = 0;
3535
k = 0;
@@ -65,7 +65,7 @@ void *create_image(t_mlx *mlx)
6565
pixel[0] = i[0];
6666
pixel[1] = i[1];
6767
pixel[2] = i[2];
68-
pixel[3] = 0xFF;
68+
pixel[3] = 0x99;
6969
mlx_set_image_pixel(mlx->mlx, img, i[1], i[2], *((int *)pixel));
7070
}
7171
i[0] += 4;

0 commit comments

Comments
 (0)