blasphemy

This commit is contained in:
Lauchmelder 2021-12-23 04:19:13 +01:00
parent 923213a650
commit 711d18e718
11 changed files with 74 additions and 35 deletions

View file

@ -19,7 +19,7 @@ add_library(lol STATIC
"src/Shader.cpp" "src/Shader.cpp"
"src/VertexArrayObject.cpp" "src/VertexArrayObject.cpp"
"vendor/glad/src/glad.c" "vendor/glad/src/glad.c"
) "include/lol/Texture.hpp" "src/Texture.cpp" "include/lol/util/Factory.hpp" )
target_include_directories(lol PUBLIC target_include_directories(lol PUBLIC
${GLM_INCLUDE_DIRS} ${GLM_INCLUDE_DIRS}

View file

@ -6,14 +6,16 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <lol/NonCopyable.hpp> #include <lol/util/NonCopyable.hpp>
#include <lol/util/Factory.hpp>
#include <lol/util/ObjectManager.hpp>
namespace lol namespace lol
{ {
class AbstractShader : public NonCopyable class AbstractShader : public NonCopyable
{ {
friend class ShaderFactory; PRODUCT(AbstractShader);
public: public:
AbstractShader(const std::string& vertexShader, const std::string& fragmentShader); AbstractShader(const std::string& vertexShader, const std::string& fragmentShader);
@ -32,14 +34,6 @@ namespace lol
}; };
typedef std::shared_ptr<AbstractShader> Shader; typedef std::shared_ptr<AbstractShader> Shader;
typedef Factory<AbstractShader> ShaderFactory;
class ShaderFactory typedef ObjectManager<AbstractShader> ShaderManager;
{
public:
inline static Shader Produce(const std::string& vertexShader, const std::string& fragmentShader)
{
return std::make_shared<AbstractShader>(vertexShader, fragmentShader);
}
};
} }

15
include/lol/Texture.hpp Normal file
View file

@ -0,0 +1,15 @@
#pragma once
#include <lol/util/NonCopyable.hpp>
namespace lol
{
class Texture2D : public NonCopyable
{
public:
Texture2D();
private:
unsigned int textureID;
};
}

View file

@ -3,7 +3,9 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <lol/NonCopyable.hpp> #include <lol/util/NonCopyable.hpp>
#include <lol/util/Factory.hpp>
#include <lol/util/ObjectManager.hpp>
namespace lol namespace lol
{ {
@ -30,17 +32,20 @@ namespace lol
}; };
// VAO structure that sets up the buffers and deletes them at the end of the lifecycle // VAO structure that sets up the buffers and deletes them at the end of the lifecycle
class AbstractVertexArrayObject : public NonCopyable class AbstractVertexArrayObject :
public NonCopyable
{ {
friend class VAOFactory; PRODUCT(AbstractVertexArrayObject);
public: public:
AbstractVertexArrayObject() = delete; AbstractVertexArrayObject() = delete;
AbstractVertexArrayObject(const VertexArray& vertices, const IndexArray& indices, const Layout& layout, Usage usage);
~AbstractVertexArrayObject(); ~AbstractVertexArrayObject();
void Render(unsigned int mode = 4); void Render(unsigned int mode = 4);
private:
AbstractVertexArrayObject(const VertexArray& vertices, const IndexArray& indices, const Layout& layout, Usage usage = Usage::Static);
private: private:
unsigned int vao, vbo, ebo; unsigned int vao, vbo, ebo;
size_t indexCount; size_t indexCount;
@ -53,13 +58,9 @@ namespace lol
typedef std::shared_ptr<AbstractVertexArrayObject> VertexArrayObject; typedef std::shared_ptr<AbstractVertexArrayObject> VertexArrayObject;
// Factory for creating said shared pointers. // Factory for creating said shared pointers.
class VAOFactory typedef Factory<AbstractVertexArrayObject> VAOFactory;
{
public: // Object manager for managing said shared pointers
static VertexArrayObject Produce(const VertexArray& vertices, const IndexArray& indices, const Layout& layout, Usage usage = Usage::Static) typedef ObjectManager<AbstractVertexArrayObject> VAOManager;
{
return std::make_shared<AbstractVertexArrayObject>(vertices, indices, layout, usage);
}
};
} }

View file

@ -2,8 +2,7 @@
#include <lol/VertexArrayObject.hpp> #include <lol/VertexArrayObject.hpp>
#include <lol/Shader.hpp> #include <lol/Shader.hpp>
#include <lol/ObjectManager.hpp>
#include <lol/Drawable.hpp> #include <lol/Drawable.hpp>
#include <lol/Transformable.hpp> #include <lol/Transformable.hpp>
#include <lol/BoundingBox.hpp> #include <lol/Camera.hpp>
#include <lol/Camera.hpp> #include <lol/util/BoundingBox.hpp>

View file

@ -0,0 +1,26 @@
#pragma once
#include <lol/util/NonCopyable.hpp>
#define PRODUCT(type) friend class Factory<type>
namespace lol
{
template<typename Type>
class Factory : public NonCopyable
{
public:
~Factory() {}
template<typename... Args>
inline static std::shared_ptr<Type> Produce(Args&&... args)
{
return std::shared_ptr<Type>(new Type(args...));
}
private:
Factory() {}
};
}

View file

@ -63,10 +63,4 @@ namespace lol
std::map<unsigned int, std::shared_ptr<Type>> objects; std::map<unsigned int, std::shared_ptr<Type>> objects;
}; };
class AbstractShader;
class AbstractVertexArrayObject;
typedef ObjectManager<AbstractVertexArrayObject> VAOManager;
typedef ObjectManager<AbstractShader> ShaderManager;
} }

11
src/Texture.cpp Normal file
View file

@ -0,0 +1,11 @@
#include <lol/Texture.hpp>
#include <glad/glad.h>
namespace lol
{
Texture2D::Texture2D()
{
}
}

View file

@ -61,5 +61,4 @@ namespace lol
index++; index++;
} }
} }
} }