From 5e0b387dc1d5964407c7876daf88caceeebe52f3 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Fri, 19 Jan 2018 02:59:55 +0100 Subject: [PATCH] gs-vertexbuffer: Functions to directly access internal buffers Skips the previously necessary step to call At(0) and use the pointers stored in GS::Vertex to directly write to the buffers. --- source/gs-vertexbuffer.cpp | 22 +++++++++++++++++++++ source/gs-vertexbuffer.h | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/source/gs-vertexbuffer.cpp b/source/gs-vertexbuffer.cpp index 5fd3bcd0..9cb5f096 100644 --- a/source/gs-vertexbuffer.cpp +++ b/source/gs-vertexbuffer.cpp @@ -265,6 +265,28 @@ uint32_t GS::VertexBuffer::GetUVLayers() { return m_layers; } +vec3* GS::VertexBuffer::GetPositions() { + return m_positions; +} + +vec3* GS::VertexBuffer::GetNormals() { + return m_normals; +} + +vec3* GS::VertexBuffer::GetTangents() { + return m_tangents; +} + +uint32_t* GS::VertexBuffer::GetColors() { + return m_colors; +} + +vec4* GS::VertexBuffer::GetUVLayer(size_t idx) { + if ((idx < 0) || (idx >= m_layers)) { + throw std::out_of_range("idx out of range"); + } + return m_uvs[idx]; +} gs_vertbuffer_t* GS::VertexBuffer::Update(bool refreshGPU) { if (!refreshGPU) diff --git a/source/gs-vertexbuffer.h b/source/gs-vertexbuffer.h index 6cfc6429..39013da1 100644 --- a/source/gs-vertexbuffer.h +++ b/source/gs-vertexbuffer.h @@ -114,6 +114,46 @@ namespace GS { uint32_t GetUVLayers(); + /*! + * \brief Directly access the positions buffer + * Returns the internal memory that is assigned to hold all vertex positions. + * + * \return A that points at the first vertex's position. + */ + vec3* GetPositions(); + + /*! + * \brief Directly access the normals buffer + * Returns the internal memory that is assigned to hold all vertex normals. + * + * \return A that points at the first vertex's normal. + */ + vec3* GetNormals(); + + /*! + * \brief Directly access the tangents buffer + * Returns the internal memory that is assigned to hold all vertex tangents. + * + * \return A that points at the first vertex's tangent. + */ + vec3* GetTangents(); + + /*! + * \brief Directly access the colors buffer + * Returns the internal memory that is assigned to hold all vertex colors. + * + * \return A that points at the first vertex's color. + */ + uint32_t* GetColors(); + + /*! + * \brief Directly access the uv buffer + * Returns the internal memory that is assigned to hold all vertex uvs. + * + * \return A that points at the first vertex's uv. + */ + vec4* GetUVLayer(size_t idx); + #pragma region Update / Grab GS object gs_vertbuffer_t* Update();