Skip to content
Snippets Groups Projects
Commit 7c1e4a1d authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

VBO opt

parent 31227922
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,19 @@
#ifndef LL_LLSTRIDER_H
#define LL_LLSTRIDER_H
#include "stdtypes.h"
#include "llmath.h"
#include "llvector4a.h"
template<typename T>
inline void copyArray(T* dst, const T* src, const U32 bytes)
{
memcpy(dst, src, bytes);
}
template<>
inline void copyArray<>(LLVector4a* dst, const LLVector4a* src, const U32 bytes)
{
LLVector4a::memcpyNonAliased16(dst->getF32ptr(), src->getF32ptr(), bytes);
}
template <class Object> class LLStrider
{
......@@ -39,7 +51,7 @@ template <class Object> class LLStrider
public:
LLStrider() { mObjectp = NULL; mSkip = sizeof(Object); }
~LLStrider() { }
~LLStrider() = default;
const LLStrider<Object>& operator = (Object *first) { mObjectp = first; return *this;}
void setStride (S32 skipBytes) { mSkip = (skipBytes ? skipBytes : sizeof(Object));}
......@@ -62,6 +74,21 @@ template <class Object> class LLStrider
Object* operator +=(int i) { mBytep += mSkip*i; return mObjectp; }
Object& operator[](U32 index) { return *(Object*)(mBytep + (mSkip * index)); }
void copyArray(const U32 offset, const Object* src, const U32 length)
{
if (mSkip == sizeof(Object))
{
::copyArray(mObjectp + offset, src, length * sizeof(Object));
}
else
{
for (U32 i = 0; i < length; i++)
{
(*this)[offset + i] = src[i];
}
}
}
};
#endif // LL_LLSTRIDER_H
......@@ -2097,34 +2097,21 @@ void LLVertexBuffer::unmapBuffer()
//----------------------------------------------------------------------------
template <class T,S32 type> struct VertexBufferStrider
template <class T, S32 type>
struct VertexBufferStrider
{
typedef LLStrider<T> strider_t;
static bool get(LLVertexBuffer& vbo,
strider_t& strider,
S32 index, S32 count, bool map_range)
static bool get(LLVertexBuffer& vbo,
strider_t& strider,
S32 index, S32 count, bool map_range)
{
if (type == LLVertexBuffer::TYPE_INDEX)
{
volatile U8* ptr = vbo.mapIndexBuffer(index, count, map_range);
if (ptr == NULL)
{
LL_WARNS() << "mapIndexBuffer failed!" << LL_ENDL;
return false;
}
strider = (T*)ptr;
strider.setStride(0);
return true;
}
else if (vbo.hasDataType(type))
if (vbo.hasDataType(type))
{
S32 stride = LLVertexBuffer::sTypeSize[type];
volatile U8* ptr = vbo.mapVertexBuffer(type, index, count, map_range);
if (ptr == NULL)
if (ptr == nullptr)
{
LL_WARNS() << "mapVertexBuffer failed!" << LL_ENDL;
return false;
......@@ -2142,6 +2129,28 @@ template <class T,S32 type> struct VertexBufferStrider
}
};
template<class T>
struct VertexBufferStrider<T, LLVertexBuffer::TYPE_INDEX>
{
typedef LLStrider<T> strider_t;
static bool get(LLVertexBuffer& vbo,
strider_t& strider,
S32 index, S32 count, bool map_range)
{
volatile U8* ptr = vbo.mapIndexBuffer(index, count, map_range);
if (ptr == nullptr)
{
LL_WARNS() << "mapIndexBuffer failed!" << LL_ENDL;
return false;
}
strider = (T*) ptr;
strider.setStride(0);
return true;
}
};
bool LLVertexBuffer::getVertexStrider(LLStrider<LLVector3>& strider, S32 index, S32 count, bool map_range)
{
return VertexBufferStrider<LLVector3,TYPE_VERTEX>::get(*this, strider, index, count, map_range);
......@@ -2326,9 +2335,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask)
{
U32 unsatisfied_mask = (required_mask & ~data_mask);
U32 i = 0;
while (i < TYPE_MAX)
for (U32 i = 0; i < TYPE_MAX; i++) // <alchemy/>
{
U32 unsatisfied_flag = unsatisfied_mask & (1 << i);
switch (unsatisfied_flag)
......@@ -2355,7 +2362,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask)
LL_INFOS() << "Missing indices" << LL_ENDL;
}
LL_ERRS() << "Shader consumption mismatches data provision." << LL_ENDL;
LL_WARNS() << "Shader consumption mismatches data provision." << LL_ENDL;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment