aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2017-12-26 17:29:28 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-18 15:21:48 +0100
commitffe9dac56488ebfc9f5c37c4e400f4f5469a8a46 (patch)
tree5958b66f16d217e31215d2f6ec56bb341ec06a76 /include
parentb5f06b6c4cd07f3073897af32626b9b21a4d2ef8 (diff)
Add device memory, device frame. Rendering works
Diffstat (limited to 'include')
-rw-r--r--include/RenderBackend/OpenGL/CompiledShader.hpp9
-rw-r--r--include/RenderBackend/OpenGL/DeviceFrame.hpp24
-rw-r--r--include/RenderBackend/OpenGL/DeviceMemory.hpp42
-rw-r--r--include/RenderBackend/OpenGL/ShaderProgram.hpp4
-rw-r--r--include/RenderBackend/OpenGL/ShaderVec.hpp10
-rw-r--r--include/RenderBackend/OpenGL/VertexShader.hpp6
6 files changed, 80 insertions, 15 deletions
diff --git a/include/RenderBackend/OpenGL/CompiledShader.hpp b/include/RenderBackend/OpenGL/CompiledShader.hpp
index 67e6418..8d2ee84 100644
--- a/include/RenderBackend/OpenGL/CompiledShader.hpp
+++ b/include/RenderBackend/OpenGL/CompiledShader.hpp
@@ -1,6 +1,8 @@
#pragma once
#include "../../types.hpp"
+#include <unordered_map>
+#include <string>
namespace amalgine
{
@@ -22,9 +24,14 @@ namespace amalgine
public:
~CompiledPixelShader();
u32 getShaderId() const;
+ const auto& getPixelAttributes() const
+ {
+ return pixelAttributes;
+ }
private:
- CompiledPixelShader(u32 _shaderId);
+ CompiledPixelShader(u32 _shaderId, std::unordered_map<std::string, i32> &&_pixelAttributes);
private:
u32 shaderId;
+ std::unordered_map<std::string, i32> pixelAttributes;
};
}
diff --git a/include/RenderBackend/OpenGL/DeviceFrame.hpp b/include/RenderBackend/OpenGL/DeviceFrame.hpp
new file mode 100644
index 0000000..12e578a
--- /dev/null
+++ b/include/RenderBackend/OpenGL/DeviceFrame.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "../../types.hpp"
+#include "../../utils.hpp"
+#include <vector>
+
+namespace amalgine
+{
+ class DeviceMemory;
+
+ class DeviceFrame
+ {
+ DISABLE_COPY(DeviceFrame)
+ public:
+ DeviceFrame();
+ ~DeviceFrame();
+
+ DeviceMemory* alloc();
+ void draw();
+ private:
+ u32 vertexArrayObjectId;
+ std::vector<DeviceMemory*> buffers;
+ };
+}
diff --git a/include/RenderBackend/OpenGL/DeviceMemory.hpp b/include/RenderBackend/OpenGL/DeviceMemory.hpp
index 974c7cf..163b0ad 100644
--- a/include/RenderBackend/OpenGL/DeviceMemory.hpp
+++ b/include/RenderBackend/OpenGL/DeviceMemory.hpp
@@ -2,27 +2,49 @@
#include "../../DataView.hpp"
#include "../../utils.hpp"
+#include <stdexcept>
namespace amalgine
{
+ class DeviceMemoryEmpty : public std::runtime_error
+ {
+ public:
+ DeviceMemoryEmpty(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ };
+
class DeviceMemory
{
DISABLE_COPY(DeviceMemory)
+ friend class DeviceFrame;
+ friend class ShaderInputVec4;
public:
- DeviceMemory();
- ~DeviceMemory();
-
- // Uploaded once, drawn many times
- void copyAsStatic(const DataView<f32> &data);
+ enum class StorageType
+ {
+ // Uploaded once, drawn many times
+ STATIC,
+
+ // Created once, changed from time to time but drawn many times more than that
+ DYNAMIC,
+
+ // Uploaded once, drawn once (for example data that is changed every frame)
+ STREAM
+ };
- // Created once, changed from time to time but drawn many times more than that
- void copyAsDynamic(const DataView<f32> &data);
+ enum class PrimitiveType
+ {
+ TRIANGLE
+ };
- // Uploaded once, drawn once (for example data that is changed every frame)
- void copyAsStream(const DataView<f32> &data);
+ ~DeviceMemory();
+ void copy(const DataView<f32> &data, StorageType storageType, PrimitiveType primitiveType = PrimitiveType::TRIANGLE);
+ void draw();
private:
- void copy(const DataView<f32> &data, i32 storageType);
+ DeviceMemory();
+ void operator delete(void *data);
+ void use() const;
private:
u32 vertexBufferObjectId;
+ u32 primitiveType;
+ u32 numVertices;
};
}
diff --git a/include/RenderBackend/OpenGL/ShaderProgram.hpp b/include/RenderBackend/OpenGL/ShaderProgram.hpp
index a3e8a0f..2b1c5b4 100644
--- a/include/RenderBackend/OpenGL/ShaderProgram.hpp
+++ b/include/RenderBackend/OpenGL/ShaderProgram.hpp
@@ -26,8 +26,8 @@ namespace amalgine
ShaderProgram();
~ShaderProgram();
- bool addVertexShader(CompiledVertexShader *vertexShader);
- bool addPixelShader(CompiledPixelShader *pixelShader);
+ bool setVertexShader(CompiledVertexShader *vertexShader);
+ bool setPixelShader(CompiledPixelShader *pixelShader);
Result<bool> build();
void use();
diff --git a/include/RenderBackend/OpenGL/ShaderVec.hpp b/include/RenderBackend/OpenGL/ShaderVec.hpp
index 10e628c..a5163ba 100644
--- a/include/RenderBackend/OpenGL/ShaderVec.hpp
+++ b/include/RenderBackend/OpenGL/ShaderVec.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "../../types.hpp"
+#include "../../RenderBackend/OpenGL/DeviceMemory.hpp"
#include <string>
namespace amalgine
@@ -8,11 +9,20 @@ namespace amalgine
class VertexShader;
class PixelShader;
+ enum class AttributeType
+ {
+ NONE,
+ VEC2
+ };
+
+ AttributeType getAttributeTypeByName(const char *attributeName);
+
class ShaderInputVec2
{
friend class VertexShader;
public:
const std::string& getName() const;
+ void setData(const DeviceMemory &data);
private:
ShaderInputVec2(VertexShader *_vertexShader, i32 _attributeIndex) :
vertexShader(_vertexShader),
diff --git a/include/RenderBackend/OpenGL/VertexShader.hpp b/include/RenderBackend/OpenGL/VertexShader.hpp
index 43a5dd8..aaf8b24 100644
--- a/include/RenderBackend/OpenGL/VertexShader.hpp
+++ b/include/RenderBackend/OpenGL/VertexShader.hpp
@@ -3,6 +3,7 @@
#include "../../DataView.hpp"
#include "../../utils.hpp"
#include "../../Result.hpp"
+#include "CommonShader.hpp"
#include "ShaderVec.hpp"
#include <string>
#include <unordered_map>
@@ -51,7 +52,8 @@ namespace amalgine
public:
VertexShader();
- const std::string& getInputAttributeName(i32 attributeIndex);
+ const std::string& getInputAttributeName(i32 attributeIndex) const;
+ AttributeType getInputAttributeType(i32 attributeIndex) const;
ShaderInputVec2 defineInputVec2(const std::string &name);
void defineMain(VertexShaderMainFunc mainFunc);
Result<CompiledVertexShader*> compile();
@@ -71,7 +73,7 @@ namespace amalgine
int locationCounter;
i32 maxVertexAttribs; // Could make this static
std::unordered_map<std::string, i32> vertexAttributes;
- std::vector<std::string> vertexAttributeNames;
+ std::vector<ShaderAttribute> vertexAttributeNames;
bool mainFuncDefined;
};
}