#include "../../../include/RenderBackend/OpenGL/DeviceMemory.hpp" #include "../../../include/RenderBackend/OpenGL/opengl.hpp" #include namespace amalgine { u32 getOpenglStorageType(DeviceMemory::StorageType storageType) { switch(storageType) { case DeviceMemory::StorageType::STATIC: return GL_STATIC_DRAW; case DeviceMemory::StorageType::DYNAMIC: return GL_DYNAMIC_DRAW; case DeviceMemory::StorageType::STREAM: return GL_STREAM_DRAW; default: assert(false); return -1; } } DeviceMemory::DeviceMemory() : primitiveType(0), numVertices(0), type(DeviceMemoryType::NONE) { glGenBuffers(1, &vertexBufferObjectId); } DeviceMemory::~DeviceMemory() { glDeleteBuffers(1, &vertexBufferObjectId); } void DeviceMemory::use() const { // TODO: Bind vao here? glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId); } /* void DeviceMemory::copy(const DataView &data, StorageType storageType, PrimitiveType primitiveType) { glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId); glBufferData(GL_ARRAY_BUFFER, data.getByteSize(), data.data, getOpenglStorageType(storageType)); this->primitiveType = getOpenglPrimitiveType(primitiveType); numVertices = getPrimitiveTypePointsPerVertices(primitiveType); } */ void DeviceMemory::copy(const DataView &texture_coords, StorageType storageType) { glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId); glBufferData(GL_ARRAY_BUFFER, texture_coords.getByteSize(), texture_coords.data, getOpenglStorageType(storageType)); primitiveType = GL_TRIANGLES; numVertices = texture_coords.size * 2; type = DeviceMemoryType::VEC2; } void DeviceMemory::copy(const DataView &triangles, StorageType storageType) { glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId); glBufferData(GL_ARRAY_BUFFER, triangles.getByteSize(), triangles.data, getOpenglStorageType(storageType)); primitiveType = GL_TRIANGLES; numVertices = triangles.size * 2; type = DeviceMemoryType::VEC2; } void DeviceMemory::copy(const DataView &triangles, StorageType storageType) { glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjectId); glBufferData(GL_ARRAY_BUFFER, triangles.getByteSize(), triangles.data, getOpenglStorageType(storageType)); primitiveType = GL_TRIANGLES; numVertices = triangles.size * 3; type = DeviceMemoryType::VEC3; } void DeviceMemory::draw() { glDrawArrays(primitiveType, 0, numVertices); } }