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/OpenGLES3/Common.hpp>
#include <FslUtil/OpenGLES3/GLValues.hpp>
Expand Down Expand Up @@ -194,15 +195,32 @@ namespace Fsl::GLES3
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::GLES3
//! @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 @@ -214,6 +214,12 @@ namespace Fsl::GLES3
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 @@ -226,6 +232,12 @@ namespace Fsl::GLES3
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/OpenGLES3/Common.hpp>
#include <FslUtil/OpenGLES3/GLVertexAttribLink.hpp>
Expand Down Expand Up @@ -118,9 +118,15 @@ namespace Fsl::GLES3
//! @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::GLES3
}
}

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::GLES3
}
}

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::GLES3
}
}

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::GLES3

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::GLES3
}


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::GLES3
}

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::GLES3
}
}

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