Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <FslBase/BasicTypes.hpp>
#include <FslBase/Span/ReadOnlyFlexSpan.hpp>
#include <FslBase/Span/ReadOnlyFlexSpanUtil.hpp>
#include <FslBase/Span/ReadOnlySpan.hpp>
#include <FslBase/UncheckedNumericCast.hpp>
#include <FslUtil/OpenGLES2/Common.hpp>
#include <FslUtil/OpenGLES2/GLValues.hpp>
Expand Down Expand Up @@ -194,15 +195,32 @@ namespace Fsl::GLES2
SetDataEx(dstIndex, ReadOnlyFlexSpanUtil::AsSpan(bufferData));
}

template <typename T>
void SetDataFast(const std::size_t dstIndex, const ReadOnlySpan<T> bufferData)
{
SetDataFast(dstIndex, ReadOnlyFlexSpanUtil::AsSpan(bufferData));
}

//! @brief Update the given area of the buffer
//! This is the recommended way of updating the content of a buffer both for full and partial updates!
//! @param dstIndex the dst index where the data will be written.
//! @param bufferData the elements that should be written.
//! @note This method does not check for glErrors since its intended for use during rendering.
//! @throws IndexOutOfRangeException if the dstIndex + elementCount exceeds the capacity of the buffer.
//! @throws std::invalid_argument if the bufferData span stride is incompatible with the buffer.
//! @throws UsageErrorException if the object isn't valid
void SetData(const std::size_t dstIndex, const ReadOnlyFlexSpan bufferData);

//! @brief Update the given area of the buffer
//! This is the recommended way of updating the content of a buffer both for full and partial updates!
//! This does not unbind the GLBuffer after modification
//! @param dstIndex the dst index where the data will be written.
//! @param bufferData the elements that should be written.
//! @note This method does not check for glErrors since its intended for use during rendering.
//! @throws IndexOutOfRangeException if the dstIndex + elementCount exceeds the capacity of the buffer.
//! @throws std::invalid_argument if the bufferData span stride is incompatible with the buffer.
//! @throws UsageErrorException if the object isn't valid
void SetData(const std::size_t dstIndex, ReadOnlyFlexSpan bufferData);
void SetDataEx(const std::size_t dstIndex, const ReadOnlyFlexSpan bufferData);

//! @brief Update the given area of the buffer
//! This is the recommended way of updating the content of a buffer both for full and partial updates!
Expand All @@ -213,7 +231,7 @@ namespace Fsl::GLES2
//! @throws IndexOutOfRangeException if the dstIndex + elementCount exceeds the capacity of the buffer.
//! @throws std::invalid_argument if the bufferData span stride is incompatible with the buffer.
//! @throws UsageErrorException if the object isn't valid
void SetDataEx(const std::size_t dstIndex, ReadOnlyFlexSpan bufferData);
void SetDataFast(const std::size_t dstIndex, const ReadOnlyFlexSpan bufferData);

//! @brief Update the given area of the buffer
//! This is the recommended way of updating the content of a buffer both for full and partial updates!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
****************************************************************************************************************************************************/

// Make sure Common.hpp is the first include file (to make the error message as helpful as possible when disabled)
#include <FslGraphics/Vertices/ReadOnlyFlexVertexSpan.hpp>
#include <FslGraphics/Vertices/VertexDeclarationSpan.hpp>
#include <FslUtil/OpenGLES2/Common.hpp>
#include <FslUtil/OpenGLES2/GLBuffer.hpp>
Expand Down Expand Up @@ -89,6 +89,20 @@ namespace Fsl::GLES2
Reset(pVertices, elementCount, usage);
}

//! @brief Create a initialized vertex buffer
GLVertexBuffer(const ReadOnlyFlexSpan vertices, const VertexDeclarationSpan vertexDeclarationSpan, const GLenum usage)
: GLVertexBuffer()
{
Reset(vertices, vertexDeclarationSpan, usage);
}

//! @brief Create a initialized vertex buffer
GLVertexBuffer(const ReadOnlyFlexVertexSpan vertices, const GLenum usage)
: GLVertexBuffer()
{
Reset(vertices, usage);
}

//! @brief Create a initialized vertex buffer
template <typename T, std::size_t TSize>
GLVertexBuffer(const std::array<T, TSize>& vertices, const GLenum usage)
Expand Down Expand Up @@ -126,6 +140,22 @@ namespace Fsl::GLES2
Reset(pVertices, elementCount, T::AsVertexDeclarationSpan(), usage);
}

//! @brief Reset the buffer to contain the supplied elements
//! @note This is a very slow operation and its not recommended for updating the content of the buffer (since it creates a new buffer
//! internally)
void Reset(const ReadOnlyFlexSpan vertices, const VertexDeclarationSpan vertexDeclarationSpan, const GLenum usage)
{
Reset(vertices.data(), vertices.size(), vertexDeclarationSpan, usage);
}

//! @brief Reset the buffer to contain the supplied elements
//! @note This is a very slow operation and its not recommended for updating the content of the buffer (since it creates a new buffer
//! internally)
void Reset(const ReadOnlyFlexVertexSpan vertices, const GLenum usage)
{
Reset(vertices.data(), vertices.size(), vertices.AsVertexDeclarationSpan(), usage);
}

//! @brief Reset the buffer to contain the supplied elements
//! @note This is a very slow operation and its not recommended for updating the content of the buffer (since it creates a new buffer
//! internally)
Expand Down Expand Up @@ -166,7 +196,7 @@ namespace Fsl::GLES2
// m_vertexElements.EnableAttribArrays(pAttributeIndices, count);
//}

//! @brief Disable all attrib arrays in the supplied index list.
////! @brief Disable all attrib arrays in the supplied index list.
// void DisableAttribArrays(const GLuint* const pAttributeIndices, const std::size_t count) const
//{
// m_vertexElements.DisableAttribArrays(pAttributeIndices, count);
Expand All @@ -184,6 +214,12 @@ namespace Fsl::GLES2
m_vertexElements.DisableAttribArrays(pLinks, count);
}

//! @brief Enable all vertex elements listed in the supplied link list binding the to the requested index
void EnableAttribArrays(const ReadOnlySpan<GLVertexAttribLink> links) const
{
m_vertexElements.EnableAttribArrays(links);
}

template <std::size_t TSize>
void EnableAttribArrays(const std::array<GLVertexAttribLink, TSize>& links) const
{
Expand All @@ -196,6 +232,12 @@ namespace Fsl::GLES2
m_vertexElements.EnableAttribArrays(links);
}

//! @brief Disable all vertex elements listed in the supplied link
void DisableAttribArrays(const ReadOnlySpan<GLVertexAttribLink> links) const
{
m_vertexElements.DisableAttribArrays(links);
}

//! @brief Disable all vertex elements listed in the supplied link
template <std::size_t TSize>
void DisableAttribArrays(const std::array<GLVertexAttribLink, TSize>& links) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
****************************************************************************************************************************************************/

// Make sure Common.hpp is the first include file (to make the error message as helpful as possible when disabled)
#include <FslBase/Span/ReadOnlySpan.hpp>
#include <FslGraphics/Vertices/VertexDeclarationSpan.hpp>
#include <FslUtil/OpenGLES2/Common.hpp>
#include <FslUtil/OpenGLES2/GLVertexAttribLink.hpp>
Expand Down Expand Up @@ -118,9 +118,15 @@ namespace Fsl::GLES2
//! @brief Enable all vertex elements listed in the supplied link list binding the to the requested index
void EnableAttribArrays(const GLVertexAttribLink* const pLinks, const std::size_t count) const;

//! @brief Enable all vertex elements listed in the supplied link list binding the to the requested index
void EnableAttribArrays(const ReadOnlySpan<GLVertexAttribLink> links) const;

//! @brief Disable all vertex elements listed in the supplied link
void DisableAttribArrays(const GLVertexAttribLink* const pLinks, const std::size_t count) const;

//! @brief Disable all vertex elements listed in the supplied link
void DisableAttribArrays(const ReadOnlySpan<GLVertexAttribLink> links) const;

template <std::size_t TSize>
void EnableAttribArrays(const std::array<GLVertexAttribLink, TSize>& links) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace Fsl::GLES2
}
}

void GLBuffer::SetData(const std::size_t dstIndex, ReadOnlyFlexSpan bufferData)
void GLBuffer::SetData(const std::size_t dstIndex, const ReadOnlyFlexSpan bufferData)
{
if (!bufferData.empty())
{
Expand All @@ -96,7 +96,7 @@ namespace Fsl::GLES2
}
}

void GLBuffer::SetDataEx(const std::size_t dstIndex, ReadOnlyFlexSpan bufferData)
void GLBuffer::SetDataEx(const std::size_t dstIndex, const ReadOnlyFlexSpan bufferData)
{
if (m_elementStride != bufferData.stride())
{
Expand All @@ -120,6 +120,30 @@ namespace Fsl::GLES2
}
}

void GLBuffer::SetDataFast(const std::size_t dstIndex, const ReadOnlyFlexSpan bufferData)
{
if (m_elementStride != bufferData.stride())
{
throw std::invalid_argument("bufferData is not compatible with GLBuffer");
}
if ((dstIndex + bufferData.size()) > m_capacity)
{
throw IndexOutOfRangeException("SetData");
}
if (!IsValid())
{
throw UsageErrorException("SetData called on invalid buffer");
}
if (!bufferData.empty())
{
assert(m_elementStride > 0);
assert(bufferData.data() != nullptr);
glBufferSubData(m_target, UncheckedNumericCast<GLintptr>(dstIndex * m_elementStride), UncheckedNumericCast<GLsizeiptr>(bufferData.byte_size()),
bufferData.data());
}
}


void GLBuffer::SetDataFast(const std::size_t dstIndex, const void* const pElements, const std::size_t elementCount)
{
if (pElements == nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ namespace Fsl::GLES2

const ReadOnlySpan<GLVertexElement> vertexElementSpan = SpanUtil::AsReadOnlySpan(m_vertexElements);
const auto vertexStride = VertexStride();
assert(count <= std::numeric_limits<uint32_t>::max());
for (uint32_t i = 0; i < static_cast<uint32_t>(count); ++i)
const auto count32 = UncheckedNumericCast<uint32_t>(count);
for (uint32_t i = 0; i < count32; ++i)
{
if (pLinks[i].AttribIndex >= 0) // if present in shader
{
Expand All @@ -283,6 +283,27 @@ namespace Fsl::GLES2
}


void GLVertexElements::EnableAttribArrays(const ReadOnlySpan<GLVertexAttribLink> links) const
{
if (links.size() > std::numeric_limits<uint32_t>::max())
{
throw NotSupportedException("We only support 32bit of elements");
}

const ReadOnlySpan<GLVertexElement> vertexElementSpan = SpanUtil::AsReadOnlySpan(m_vertexElements);
const auto vertexStride = VertexStride();
const auto count32 = UncheckedNumericCast<uint32_t>(links.size());
for (uint32_t i = 0; i < count32; ++i)
{
if (links[i].AttribIndex >= 0) // if present in shader
{
assert(links[i].VertexElementIndex < vertexElementSpan.size());
EnableAttribArray(vertexElementSpan[links[i].VertexElementIndex], links[i].AttribIndex, vertexStride, vertexElementSpan);
}
}
}


void GLVertexElements::DisableAttribArrays(const GLVertexAttribLink* const pLinks, const std::size_t count) const
{
if (pLinks == nullptr)
Expand All @@ -295,7 +316,8 @@ namespace Fsl::GLES2
}

const ReadOnlySpan<GLVertexElement> vertexElementSpan = SpanUtil::AsReadOnlySpan(m_vertexElements);
for (uint32_t i = 0; i < static_cast<uint32_t>(count); ++i)
const auto count32 = UncheckedNumericCast<uint32_t>(count);
for (uint32_t i = 0; i < count32; ++i)
{
if (pLinks[i].AttribIndex >= 0)
{
Expand All @@ -305,6 +327,25 @@ namespace Fsl::GLES2
}
}

void GLVertexElements::DisableAttribArrays(const ReadOnlySpan<GLVertexAttribLink> links) const
{
if (links.size() > std::numeric_limits<uint32_t>::max())
{
throw NotSupportedException("We only support 32bit of elements");
}

const ReadOnlySpan<GLVertexElement> vertexElementSpan = SpanUtil::AsReadOnlySpan(m_vertexElements);
const auto count32 = UncheckedNumericCast<uint32_t>(links.size());
for (uint32_t i = 0; i < count32; ++i)
{
if (links[i].AttribIndex >= 0)
{
assert(links[i].VertexElementIndex < vertexElementSpan.size());
DisableAttribArray(vertexElementSpan[links[i].VertexElementIndex], links[i].AttribIndex);
}
}
}


void GLVertexElements::SetVertexAttribPointers() const
{
Expand Down