almost first rendering, fixing renderer issues

This commit is contained in:
Kbz-8
2022-12-19 00:59:45 +01:00
parent 4a67aab716
commit f1e0499564
417 changed files with 60861 additions and 298 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */
/* Updated: 2022/12/18 01:13:32 by maldavid ### ########.fr */
/* Updated: 2022/12/18 23:09:55 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,7 @@
namespace mlx
{
Input::Input(const std::vector<std::shared_ptr<MLX_Window>>& wins) : _wins(wins)
Input::Input()
{
std::memset(_keys.data(), 0, SDL_NUM_SCANCODES);
std::memset(_mouse.data(), 0, 8);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */
/* Updated: 2022/12/18 01:13:19 by maldavid ### ########.fr */
/* Updated: 2022/12/18 23:09:41 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,7 +25,7 @@ namespace mlx
class Input
{
public:
Input(const std::vector<std::shared_ptr<MLX_Window>>& wins);
Input();
void update();
@@ -49,7 +49,6 @@ namespace mlx
SDL_Event _event;
std::array<uint8_t, SDL_NUM_SCANCODES> _keys;
std::array<uint8_t, 8> _mouse;
std::vector<std::shared_ptr<MLX_Window>> _wins;
int _x = 0;
int _y = 0;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
/* Updated: 2022/12/18 01:12:05 by maldavid ### ########.fr */
/* Updated: 2022/12/19 00:46:55 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,15 +15,44 @@
namespace mlx
{
MLX_Window::MLX_Window(std::size_t w, std::size_t h, std::string title, int id) : _id(id)
MLX_Window::MLX_Window(std::size_t w, std::size_t h, std::string title, int id) : _id(id), _renderer(new Renderer())
{
_win = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, /*SDL_WINDOW_VULKAN |*/ SDL_WINDOW_SHOWN);
_win = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN);
if(!_win)
core::error::report(e_kind::fatal_error, std::string("Unable to open a new window, ") + SDL_GetError());
_renderer->setWindow(this);
_renderer->init();
_vbo.create(sizeof(Vertex));
}
bool MLX_Window::beginFrame()
{
return _renderer->beginFrame();
}
void MLX_Window::pixel_put(int x, int y, int color)
{
uint32_t ucolor = color;
Vertex vert;
vert.pos = glm::vec2(x, y);
vert.color.r = (ucolor >> 16) & 0xFF;
vert.color.g = (ucolor >> 8) & 0xFF;
vert.color.b = ucolor & 0xFF;
_vbo.setData(sizeof(Vertex), &vert);
_vbo.bind(*_renderer);
vkCmdDraw(_renderer->getActiveCmdBuffer().get(), 1, 1, 0, 0);
}
void MLX_Window::endFrame()
{
_renderer->endFrame();
}
MLX_Window::~MLX_Window()
{
_vbo.destroy();
_renderer->destroy();
if(_win)
SDL_DestroyWindow(_win);
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
/* Updated: 2022/12/18 03:41:53 by maldavid ### ########.fr */
/* Updated: 2022/12/19 00:40:26 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,6 +15,9 @@
#include <SDL2/SDL.h>
#include <string>
#include <memory>
#include <renderer/renderer.h>
#include <renderer/buffers/vk_vbo.h>
namespace mlx
{
@@ -26,11 +29,16 @@ namespace mlx
inline int& get_id() noexcept { return _id; }
inline SDL_Window* getNativeWindow() const noexcept { return _win; }
void pixel_put(int x, int y, int color) {}
bool beginFrame();
void endFrame();
void pixel_put(int x, int y, int color);
~MLX_Window();
private:
std::unique_ptr<Renderer> _renderer;
VBO _vbo;
SDL_Window* _win = nullptr;
int _id;
};