Adding stb lib

main
anulax1225 ago%!(EXTRA string=6 months)
parent 554bbe6567
commit b2ebd91bec
  1. 1
      dependencies
  2. 5
      package.json
  3. 5
      premake5.lua
  4. 13
      src/bakara/renderer/buffer.cpp
  5. 4
      src/bakara/renderer/buffer.h
  6. 4
      src/bakara/renderer/renderer.cpp
  7. 6
      src/bakara/renderer/shader.cpp
  8. 3
      src/bakara/renderer/shader.h
  9. 18
      src/bakara/renderer/texture.cpp
  10. 22
      src/bakara/renderer/texture.h
  11. 6
      src/bakara/renderer/vertex_array.cpp
  12. 2
      src/bakara/renderer/vertex_array.h
  13. 2
      src/platforms/glfw/glfw_window.cpp
  14. 22
      src/platforms/opengl/opengl_texture.cpp
  15. 20
      src/platforms/opengl/opengl_texture.h

@ -1,5 +1,6 @@
IncludeDirs["bakara"] = "%{wks.location}/vendor/bakara/src" IncludeDirs["bakara"] = "%{wks.location}/vendor/bakara/src"
IncludeDirs["glm"] = "%{wks.location}/vendor/glm" IncludeDirs["glm"] = "%{wks.location}/vendor/glm"
IncludeDirs["stb"] = "%{wks.location}/vendor/stb"
group "Bakara" group "Bakara"
include "vendor/bakara" include "vendor/bakara"

@ -9,7 +9,6 @@
"includes": "includes":
[ [
"bakara", "bakara",
"spdlog",
"glm" "glm"
], ],
"packages": "packages":
@ -37,6 +36,10 @@
{ {
"author": "anulax1225", "author": "anulax1225",
"name": "imgui" "name": "imgui"
},
{
"author": "anulax1225",
"name": "stb"
} }
] ]
} }

@ -10,6 +10,8 @@ project "bakara"
{ {
"%{wks.location}/vendor/glm/glm/**.hpp", "%{wks.location}/vendor/glm/glm/**.hpp",
"%{wks.location}/vendor/glm/glm/**.inl", "%{wks.location}/vendor/glm/glm/**.inl",
"%{wks.location}/vendor/stb/stb_image.h",
"%{wks.location}/vendor/stb/stb_image.cpp",
"src/bakara/**.h", "src/bakara/**.h",
"src/bakara/**.cpp", "src/bakara/**.cpp",
"src/platforms/**.h", "src/platforms/**.h",
@ -30,7 +32,8 @@ project "bakara"
"%{IncludeDirs.glad}", "%{IncludeDirs.glad}",
"%{IncludeDirs.glfw}", "%{IncludeDirs.glfw}",
"%{IncludeDirs.imgui}", "%{IncludeDirs.imgui}",
"%{IncludeDirs.bakatools}" "%{IncludeDirs.bakatools}",
"%{InlcudeDirs.stb}"
} }
links links

@ -1,25 +1,30 @@
#include "buffer.h" #include "buffer.h"
#include "bakara/renderer/renderer.h" #include "bakara/renderer/renderer.h"
#include "bakatools/container/types.h"
#include "bakatools/logging/assert.h" #include "bakatools/logging/assert.h"
#include "platforms/opengl/opengl_buffer.h" #include "platforms/opengl/opengl_buffer.h"
namespace Bk namespace Bk
{ {
VertexBuffer* VertexBuffer::Create(float *vertices, u32 size) Ref<VertexBuffer> VertexBuffer::Create(float *vertices, u32 size)
{ {
switch (Renderer::GetAPI()) switch (Renderer::GetAPI())
{ {
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr;
case Renderer::API::Opengl: return new Platform::OpenglVertexBuffer(vertices, size); case Renderer::API::Opengl: return CreateRef<Platform::OpenglVertexBuffer>(vertices, size);
} }
BK_MSG_ASSERT(false, "API not supported");
return nullptr;
} }
IndexBuffer* IndexBuffer::Create(u32* indices, u32 count) Ref<IndexBuffer> IndexBuffer::Create(u32* indices, u32 count)
{ {
switch (Renderer::GetAPI()) switch (Renderer::GetAPI())
{ {
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr;
case Renderer::API::Opengl: return new Platform::OpenglIndexBuffer(indices, count); case Renderer::API::Opengl: return CreateRef<Platform::OpenglIndexBuffer>(indices, count);
} }
BK_MSG_ASSERT(false, "API not supported");
return nullptr;
} }
} }

@ -12,7 +12,7 @@ namespace Bk
virtual void Unbind() = 0; virtual void Unbind() = 0;
virtual void SetLayout(BufferLayout layout) = 0; virtual void SetLayout(BufferLayout layout) = 0;
virtual BufferLayout& GetLayout() = 0; virtual BufferLayout& GetLayout() = 0;
static VertexBuffer* Create(float* vertices, u32 size); static Ref<VertexBuffer> Create(float* vertices, u32 size);
}; };
class IndexBuffer class IndexBuffer
@ -22,6 +22,6 @@ namespace Bk
virtual void Bind() = 0; virtual void Bind() = 0;
virtual void Unbind() = 0; virtual void Unbind() = 0;
virtual u32 GetCount() = 0; virtual u32 GetCount() = 0;
static IndexBuffer* Create(u32* indices, u32 count); static Ref<IndexBuffer> Create(u32* indices, u32 count);
}; };
} }

@ -20,8 +20,8 @@ namespace Bk
{ {
va->Bind(); va->Bind();
shader->Bind(); shader->Bind();
shader->Set("viewProjection", sceneData->VPMatrix); shader->Set("u_ViewProjection", sceneData->VPMatrix);
shader->Set("transform", transform); shader->Set("u_Transform", transform);
RenderCommand::DrawIndexed(va); RenderCommand::DrawIndexed(va);
} }
} }

@ -5,12 +5,14 @@
namespace Bk namespace Bk
{ {
Shader* Shader::Create(std::string vertexSrc, std::string fragSrc) Ref<Shader> Shader::Create(std::string vertexSrc, std::string fragSrc)
{ {
switch(Renderer::GetAPI()) switch(Renderer::GetAPI())
{ {
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr;
case Renderer::API::Opengl: return new Platform::OpenglShader(vertexSrc, fragSrc); case Renderer::API::Opengl: return CreateRef<Platform::OpenglShader>(vertexSrc, fragSrc);
} }
BK_MSG_ASSERT(false, "API not supported");
return nullptr;
} }
} }

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "bakara/math/types.h" #include "bakara/math/types.h"
#include "bakatools/container/types.h"
#include <string> #include <string>
namespace Bk namespace Bk
@ -23,6 +24,6 @@ namespace Bk
virtual void Set(const std::string name, Mat3 val) = 0; virtual void Set(const std::string name, Mat3 val) = 0;
virtual void Set(const std::string name, Mat4 val) = 0; virtual void Set(const std::string name, Mat4 val) = 0;
static Shader* Create(std::string vertexSrc, std::string fragSrc); static Ref<Shader> Create(std::string vertexSrc, std::string fragSrc);
}; };
} }

@ -0,0 +1,18 @@
#include "bakara/renderer/renderer.h"
#include "bakatools/logging/assert.h"
#include "texture.h"
#include "platforms/opengl/opengl_texture.h"
namespace Bk
{
Ref<Texture2D> Texture2D::Create(const std::string& filePath)
{
switch (Renderer::GetAPI())
{
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr;
case Renderer::API::Opengl: return CreateRef<Platform::OpenglTexture2D>(filePath);
}
BK_MSG_ASSERT(false, "API not supported");
return nullptr;
}
}

@ -0,0 +1,22 @@
#pragma once
#include "bakatools/container/types.h"
#include <string>
namespace Bk
{
class Texture
{
public:
virtual ~Texture() {}
virtual u32 GetWidth() = 0;
virtual u32 GetHeight() = 0;
virtual void Bind() = 0;
};
class Texture2D : public Texture
{
public:
static Ref<Texture2D> Create(const std::string& filePath);
};
}

@ -5,12 +5,14 @@
namespace Bk namespace Bk
{ {
VertexArray* VertexArray::Create() Ref<VertexArray> VertexArray::Create()
{ {
switch (Renderer::GetAPI()) switch (Renderer::GetAPI())
{ {
case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr; case Renderer::API::None: BK_MSG_ASSERT(false, "API not supported"); return nullptr;
case Renderer::API::Opengl: return new Platform::OpenglVertexArray(); case Renderer::API::Opengl: return CreateRef<Platform::OpenglVertexArray>();
} }
BK_MSG_ASSERT(false, "API not supported");
return nullptr;
} }
} }

@ -16,6 +16,6 @@ namespace Bk
virtual std::vector<Ref<VertexBuffer>> GetVertexBuffers() = 0; virtual std::vector<Ref<VertexBuffer>> GetVertexBuffers() = 0;
virtual Ref<IndexBuffer> GetIndexbuffer() = 0; virtual Ref<IndexBuffer> GetIndexbuffer() = 0;
static VertexArray* Create(); static Ref<VertexArray> Create();
}; };
} }

@ -42,7 +42,7 @@ namespace Bk {
void GlfwWindow::Init() void GlfwWindow::Init()
{ {
h_IsOpen = true; h_IsOpen = true;
BK_CORE_INFO("Creating window : {0} ({1}, {2})", p_data.title, p_data.width, p_data.height); BK_CORE_INFO("Creating window '{0}' ({1}, {2})", p_data.title, p_data.width, p_data.height);
if (!p_glfw_Initialized++) if (!p_glfw_Initialized++)
{ {
int success = glfwInit(); int success = glfwInit();

@ -0,0 +1,22 @@
#include "opengl_texture.h"
#include <stb_image.h>
#include <glad/glad.h>
namespace Bk::Platform
{
OpenglTexture2D::OpenglTexture2D(const std::string& filePath)
{
}
OpenglTexture2D::~OpenglTexture2D()
{
}
void OpenglTexture2D::Bind()
{
}
}

@ -0,0 +1,20 @@
#pragma once
#include "bakara/renderer/texture.h"
namespace Bk::Platform
{
class OpenglTexture2D : public Texture2D
{
public:
OpenglTexture2D(const std::string& filePath);
virtual ~OpenglTexture2D();
virtual u32 GetWidth() override { return width; }
virtual u32 GetHeight() override { return height; }
virtual void Bind() override;
private:
u32 id;
u32 width, height;
};
}
Loading…
Cancel
Save