Pull in vertex buffer changes from alch.

This commit is contained in:
Shyotl
2018-01-22 19:32:46 -06:00
parent ecc820f784
commit 92eb988f2a
5 changed files with 103 additions and 250 deletions

View File

@@ -97,7 +97,6 @@ U32 LLVertexBuffer::sCurVAOName = 1;
U32 LLVertexBuffer::sAllocatedIndexBytes = 0; U32 LLVertexBuffer::sAllocatedIndexBytes = 0;
U32 LLVertexBuffer::sIndexCount = 0; U32 LLVertexBuffer::sIndexCount = 0;
LLPrivateMemoryPool* LLVertexBuffer::sPrivatePoolp = NULL;
U32 LLVertexBuffer::sBindCount = 0; U32 LLVertexBuffer::sBindCount = 0;
U32 LLVertexBuffer::sSetCount = 0; U32 LLVertexBuffer::sSetCount = 0;
S32 LLVertexBuffer::sCount = 0; S32 LLVertexBuffer::sCount = 0;
@@ -117,6 +116,7 @@ bool LLVertexBuffer::sMapped = false;
bool LLVertexBuffer::sUseStreamDraw = true; bool LLVertexBuffer::sUseStreamDraw = true;
bool LLVertexBuffer::sUseVAO = false; bool LLVertexBuffer::sUseVAO = false;
bool LLVertexBuffer::sPreferStreamDraw = false; bool LLVertexBuffer::sPreferStreamDraw = false;
LLVertexBuffer* LLVertexBuffer::sUtilityBuffer = nullptr;
U32 LLVBOPool::genBuffer() U32 LLVBOPool::genBuffer()
@@ -135,7 +135,7 @@ void LLVBOPool::deleteBuffer(U32 name)
LLVertexBuffer::unbind(); LLVertexBuffer::unbind();
glBindBufferARB(mType, name); glBindBufferARB(mType, name);
glBufferDataARB(mType, 0, NULL, mUsage); glBufferDataARB(mType, 0, nullptr, mUsage);
glBindBufferARB(mType, 0); glBindBufferARB(mType, 0);
glDeleteBuffersARB(1, &name); glDeleteBuffersARB(1, &name);
@@ -154,7 +154,7 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed)
{ {
llassert(vbo_block_size(size) == size); llassert(vbo_block_size(size) == size);
volatile U8* ret = NULL; volatile U8* ret = nullptr;
U32 i = vbo_block_index(size); U32 i = vbo_block_index(size);
@@ -186,12 +186,12 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed)
if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB) if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB)
{ {
glBufferDataARB(mType, size, 0, mUsage); glBufferDataARB(mType, size, nullptr, mUsage);
ret = (U8*) ll_aligned_malloc<64>(size); ret = (U8*) ll_aligned_malloc<64>(size);
} }
else else
{ //always use a true hint of static draw when allocating non-client-backed buffers { //always use a true hint of static draw when allocating non-client-backed buffers
glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); glBufferDataARB(mType, size, nullptr, GL_STATIC_DRAW_ARB);
} }
glBindBufferARB(mType, 0); glBindBufferARB(mType, 0);
@@ -449,7 +449,7 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask)
else else
{ {
GLenum array[] = static const GLenum array[] =
{ {
GL_VERTEX_ARRAY, GL_VERTEX_ARRAY,
GL_NORMAL_ARRAY, GL_NORMAL_ARRAY,
@@ -457,7 +457,7 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask)
GL_COLOR_ARRAY, GL_COLOR_ARRAY,
}; };
GLenum mask[] = static const GLenum mask[] =
{ {
MAP_VERTEX, MAP_VERTEX,
MAP_NORMAL, MAP_NORMAL,
@@ -568,73 +568,92 @@ void LLVertexBuffer::drawArrays(U32 mode, const std::vector<LLVector3>& pos, con
llassert(norm.size() >= pos.size()); llassert(norm.size() >= pos.size());
llassert(count > 0); llassert(count > 0);
if( count == 0 ) if (count == 0)
{ {
LL_WARNS() << "Called drawArrays with 0 vertices" << LL_ENDL; LL_WARNS() << "Called drawArrays with 0 vertices" << LL_ENDL;
return; return;
} }
if( norm.size() < pos.size() ) if (norm.size() < pos.size())
{ {
LL_WARNS() << "Called drawArrays with #" << norm.size() << " normals and #" << pos.size() << " vertices" << LL_ENDL; LL_WARNS() << "Called drawArrays with #" << norm.size() << " normals and #" << pos.size() << " vertices" << LL_ENDL;
return; return;
} }
unbind(); if (!sUtilityBuffer)
setupClientArrays(MAP_VERTEX | MAP_NORMAL);
LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
if (shader)
{ {
glVertexAttribPointerARB(TYPE_VERTEX, 3, GL_FLOAT, GL_FALSE, 0, pos[0].mV); sUtilityBuffer = new LLVertexBuffer(MAP_VERTEX | MAP_NORMAL | MAP_TEXCOORD0, GL_STREAM_DRAW);
glVertexAttribPointerARB(TYPE_NORMAL, 3, GL_FLOAT, GL_FALSE, 0, norm[0].mV); sUtilityBuffer->allocateBuffer(count, count, true);
} }
else if (sUtilityBuffer->getNumVerts() < (S32)count)
{ {
glVertexPointer(3, GL_FLOAT, 0, pos[0].mV); sUtilityBuffer->resizeBuffer(count, count);
glNormalPointer(GL_FLOAT, 0, norm[0].mV);
} }
glDrawArrays(sGLMode[mode], 0, count); LLStrider<LLVector3> vertex_strider;
LLStrider<LLVector3> normal_strider;
sUtilityBuffer->getVertexStrider(vertex_strider);
sUtilityBuffer->getNormalStrider(normal_strider);
for (U32 i = 0; i < count; ++i)
{
*(vertex_strider++) = pos[i];
*(normal_strider++) = norm[i];
}
sUtilityBuffer->setBuffer(MAP_VERTEX | MAP_NORMAL);
sUtilityBuffer->drawArrays(mode, 0, pos.size());
} }
//static //static
void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, S32 num_indices, const U16* indicesp) void LLVertexBuffer::drawElements(U32 mode, const S32 num_vertices, const LLVector4a* pos, const LLVector2* tc, S32 num_indices, const U16* indicesp)
{ {
llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL);
if (num_vertices <= 0)
{
LL_WARNS() << "Called drawElements with 0 vertices" << LL_ENDL;
return;
}
if (num_indices <= 0)
{
LL_WARNS() << "Called drawElements with 0 indices" << LL_ENDL;
return;
}
gGL.syncMatrices(); gGL.syncMatrices();
if (!sUtilityBuffer)
{
sUtilityBuffer = new LLVertexBuffer(MAP_VERTEX | MAP_NORMAL | MAP_TEXCOORD0, GL_STREAM_DRAW);
sUtilityBuffer->allocateBuffer(num_vertices, num_indices, true);
}
if (sUtilityBuffer->getNumVerts() < num_vertices || sUtilityBuffer->getNumIndices() < num_indices)
{
sUtilityBuffer->resizeBuffer(llmax(sUtilityBuffer->getNumVerts(), num_vertices), llmax(sUtilityBuffer->getNumIndices(), num_indices));
}
U32 mask = LLVertexBuffer::MAP_VERTEX; U32 mask = LLVertexBuffer::MAP_VERTEX;
LLStrider<U16> index_strider;
LLStrider<LLVector4a> vertex_strider;
sUtilityBuffer->getIndexStrider(index_strider);
sUtilityBuffer->getVertexStrider(vertex_strider);
const S32 index_size = ((num_indices * sizeof(U16)) + 0xF) & ~0xF;
const S32 vertex_size = ((num_vertices * 4 * sizeof(F32)) + 0xF) & ~0xF;
LLVector4a::memcpyNonAliased16((F32*)index_strider.get(), (F32*)indicesp, index_size);
LLVector4a::memcpyNonAliased16((F32*)vertex_strider.get(), (F32*)pos, vertex_size);
if (tc) if (tc)
{ {
mask = mask | LLVertexBuffer::MAP_TEXCOORD0; mask = mask | LLVertexBuffer::MAP_TEXCOORD0;
LLStrider<LLVector2> tc_strider;
sUtilityBuffer->getTexCoord0Strider(tc_strider);
const S32 tc_size = ((num_vertices * 2 * sizeof(F32)) + 0xF) & ~0xF;
LLVector4a::memcpyNonAliased16((F32*)tc_strider.get(), (F32*)tc, tc_size);
} }
unbind(); sUtilityBuffer->setBuffer(mask);
sUtilityBuffer->draw(mode, num_indices, 0);
setupClientArrays(mask);
if (LLGLSLShader::sNoFixedFunction)
{
glVertexAttribPointerARB(TYPE_VERTEX, 3, GL_FLOAT, GL_FALSE, 16, pos);
if (tc)
{
glVertexAttribPointerARB(TYPE_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, 0, tc);
}
}
else
{
glVertexPointer(3, GL_FLOAT, 16, pos);
if (tc)
{
glTexCoordPointer(2, GL_FLOAT, 0, tc);
}
}
glDrawElements(sGLMode[mode], num_indices, GL_UNSIGNED_SHORT, indicesp);
} }
void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const
@@ -822,7 +841,7 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const
} }
{ {
LL_RECORD_BLOCK_TIME(FTM_GL_DRAW_ARRAYS); //LL_RECORD_BLOCK_TIME(FTM_GL_DRAW_ARRAYS);
stop_glerror(); stop_glerror();
glDrawArrays(sGLMode[mode], first, count); glDrawArrays(sGLMode[mode], first, count);
} }
@@ -834,12 +853,7 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const
void LLVertexBuffer::initClass(bool use_vbo, bool no_vbo_mapping) void LLVertexBuffer::initClass(bool use_vbo, bool no_vbo_mapping)
{ {
sEnableVBOs = use_vbo && gGLManager.mHasVertexBufferObject; sEnableVBOs = use_vbo && gGLManager.mHasVertexBufferObject;
sDisableVBOMapping = sEnableVBOs;// && no_vbo_mapping; //Temporary workaround for vbo mapping being straight up broken sDisableVBOMapping = sEnableVBOs;// && no_vbo_mapping;
if (!sPrivatePoolp)
{
sPrivatePoolp = LLPrivateMemoryPoolManager::getInstance()->newPool(LLPrivateMemoryPool::STATIC);
}
} }
//static //static
@@ -882,11 +896,8 @@ void LLVertexBuffer::cleanupClass()
sStreamVBOPool.cleanup(); sStreamVBOPool.cleanup();
sDynamicVBOPool.cleanup(); sDynamicVBOPool.cleanup();
if(sPrivatePoolp) delete sUtilityBuffer;
{ sUtilityBuffer = nullptr;
LLPrivateMemoryPoolManager::getInstance()->deletePool(sPrivatePoolp);
sPrivatePoolp = NULL;
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@@ -944,8 +955,8 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) :
mGLBuffer(0), mGLBuffer(0),
mGLIndices(0), mGLIndices(0),
mGLArray(0), mGLArray(0),
mMappedData(NULL), mMappedData(nullptr),
mMappedIndexData(NULL), mMappedIndexData(nullptr),
mMappedDataUsingVBOs(false), mMappedDataUsingVBOs(false),
mMappedIndexDataUsingVBOs(false), mMappedIndexDataUsingVBOs(false),
mVertexLocked(false), mVertexLocked(false),
@@ -953,7 +964,7 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) :
mFinal(false), mFinal(false),
mEmpty(true), mEmpty(true),
mMappable(false), mMappable(false),
mFence(NULL) mFence(nullptr)
{ {
mMappable = (mUsage == GL_DYNAMIC_DRAW_ARB && !sDisableVBOMapping); mMappable = (mUsage == GL_DYNAMIC_DRAW_ARB && !sDisableVBOMapping);
@@ -1031,7 +1042,7 @@ LLVertexBuffer::~LLVertexBuffer()
delete mFence; delete mFence;
} }
mFence = NULL; mFence = nullptr;
sVertexCount -= mNumVerts; sVertexCount -= mNumVerts;
sIndexCount -= mNumIndices; sIndexCount -= mNumIndices;
@@ -1109,7 +1120,7 @@ void LLVertexBuffer::releaseBuffer()
} }
mGLBuffer = 0; mGLBuffer = 0;
mMappedData = NULL; mMappedData = nullptr;
sGLCount--; sGLCount--;
} }
@@ -1126,7 +1137,7 @@ void LLVertexBuffer::releaseIndices()
} }
mGLIndices = 0; mGLIndices = 0;
mMappedIndexData = NULL; mMappedIndexData = nullptr;
sGLCount--; sGLCount--;
} }
@@ -1155,7 +1166,7 @@ void LLVertexBuffer::createGLBuffer(U32 size)
{ {
static int gl_buffer_idx = 0; static int gl_buffer_idx = 0;
mGLBuffer = ++gl_buffer_idx; mGLBuffer = ++gl_buffer_idx;
mMappedData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); mMappedData = (U8*)ll_aligned_malloc_16(size);
mSize = size; mSize = size;
} }
} }
@@ -1187,7 +1198,7 @@ void LLVertexBuffer::createGLIndices(U32 size)
} }
else else
{ {
mMappedIndexData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); mMappedIndexData = (U8*)ll_aligned_malloc_16(size);
static int gl_buffer_idx = 0; static int gl_buffer_idx = 0;
mGLIndices = ++gl_buffer_idx; mGLIndices = ++gl_buffer_idx;
mIndicesSize = size; mIndicesSize = size;
@@ -1204,8 +1215,8 @@ void LLVertexBuffer::destroyGLBuffer()
} }
else else
{ {
FREE_MEM(sPrivatePoolp, (void*) mMappedData); ll_aligned_free_16((void*) mMappedData);
mMappedData = NULL; mMappedData = nullptr;
mEmpty = true; mEmpty = true;
} }
} }
@@ -1224,8 +1235,8 @@ void LLVertexBuffer::destroyGLIndices()
} }
else else
{ {
FREE_MEM(sPrivatePoolp, (void*) mMappedIndexData); ll_aligned_free_16((void*) mMappedIndexData);
mMappedIndexData = NULL; mMappedIndexData = nullptr;
mEmpty = true; mEmpty = true;
} }
} }
@@ -1529,7 +1540,7 @@ volatile U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, boo
} }
else else
{ {
volatile U8* src = NULL; volatile U8* src = nullptr;
waitFence(); waitFence();
if (gGLManager.mHasMapBufferRange) if (gGLManager.mHasMapBufferRange)
{ {
@@ -1716,7 +1727,7 @@ volatile U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range
} }
else else
{ {
volatile U8* src = NULL; volatile U8* src = nullptr;
waitFence(); waitFence();
if (gGLManager.mHasMapBufferRange) if (gGLManager.mHasMapBufferRange)
{ {
@@ -1849,7 +1860,7 @@ void LLVertexBuffer::unmapBuffer()
else else
{ {
stop_glerror(); stop_glerror();
glBufferDataARB(GL_ARRAY_BUFFER_ARB, getSize(), NULL, mUsage); glBufferDataARB(GL_ARRAY_BUFFER_ARB, getSize(), nullptr, mUsage); // <alchemy/>
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, getSize(), (U8*) mMappedData); glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, getSize(), (U8*) mMappedData);
stop_glerror(); stop_glerror();
} }
@@ -1887,7 +1898,7 @@ void LLVertexBuffer::unmapBuffer()
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
stop_glerror(); stop_glerror();
mMappedData = NULL; mMappedData = nullptr;
} }
mVertexLocked = false; mVertexLocked = false;
@@ -1916,7 +1927,7 @@ void LLVertexBuffer::unmapBuffer()
else else
{ {
stop_glerror(); stop_glerror();
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, getIndicesSize(), NULL, mUsage); glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, getIndicesSize(), nullptr, mUsage); // <alchemy/>
glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, getIndicesSize(), (U8*) mMappedIndexData); glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, getIndicesSize(), (U8*) mMappedIndexData);
stop_glerror(); stop_glerror();
} }
@@ -1955,7 +1966,7 @@ void LLVertexBuffer::unmapBuffer()
glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
stop_glerror(); stop_glerror();
mMappedIndexData = NULL; mMappedIndexData = nullptr;
} }
mIndexLocked = false; mIndexLocked = false;
@@ -1970,7 +1981,8 @@ void LLVertexBuffer::unmapBuffer()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
template <class T,S32 type> struct VertexBufferStrider template <class T, S32 type>
struct VertexBufferStrider
{ {
typedef LLStrider<T> strider_t; typedef LLStrider<T> strider_t;
static bool get(LLVertexBuffer& vbo, static bool get(LLVertexBuffer& vbo,
@@ -1983,7 +1995,7 @@ template <class T,S32 type> struct VertexBufferStrider
volatile U8* ptr = vbo.mapVertexBuffer(type, index, count, map_range); volatile U8* ptr = vbo.mapVertexBuffer(type, index, count, map_range);
if (ptr == NULL) if (ptr == nullptr)
{ {
LL_WARNS() << "mapVertexBuffer failed!" << LL_ENDL; LL_WARNS() << "mapVertexBuffer failed!" << LL_ENDL;
return false; return false;
@@ -2011,7 +2023,7 @@ struct VertexBufferStrider<T, LLVertexBuffer::TYPE_INDEX>
{ {
volatile U8* ptr = vbo.mapIndexBuffer(index, count, map_range); volatile U8* ptr = vbo.mapIndexBuffer(index, count, map_range);
if (ptr == NULL) if (ptr == nullptr)
{ {
LL_WARNS() << "mapIndexBuffer failed!" << LL_ENDL; LL_WARNS() << "mapIndexBuffer failed!" << LL_ENDL;
return false; return false;
@@ -2176,16 +2188,6 @@ void LLVertexBuffer::flush()
} }
} }
// bind for transform feedback (quick 'n dirty)
void LLVertexBuffer::bindForFeedback(U32 channel, U32 type, U32 index, U32 count)
{
#ifdef GL_TRANSFORM_FEEDBACK_BUFFER
U32 offset = mOffsets[type] + sTypeSize[type]*index;
U32 size= (sTypeSize[type]*count);
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, channel, mGLBuffer, offset, size);
#endif
}
// Set for rendering // Set for rendering
void LLVertexBuffer::setBuffer(U32 data_mask) void LLVertexBuffer::setBuffer(U32 data_mask)
{ {

View File

@@ -93,7 +93,6 @@ public:
//============================================================================ //============================================================================
// base class // base class
class LLPrivateMemoryPool;
class LLVertexBuffer : public LLRefCount class LLVertexBuffer : public LLRefCount
{ {
public: public:
@@ -142,7 +141,7 @@ public:
static void cleanupClass(); static void cleanupClass();
static void setupClientArrays(U32 data_mask); static void setupClientArrays(U32 data_mask);
static void drawArrays(U32 mode, const std::vector<LLVector3>& pos, const std::vector<LLVector3>& norm); static void drawArrays(U32 mode, const std::vector<LLVector3>& pos, const std::vector<LLVector3>& norm);
static void drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, S32 num_indices, const U16* indicesp); static void drawElements(U32 mode, const S32 num_vertices, const LLVector4a* pos, const LLVector2* tc, S32 num_indices, const U16* indicesp);
static void unbind(); //unbind any bound vertex buffer static void unbind(); //unbind any bound vertex buffer
@@ -227,8 +226,6 @@ public:
volatile U8* mapVertexBuffer(S32 type, S32 index, S32 count, bool map_range); volatile U8* mapVertexBuffer(S32 type, S32 index, S32 count, bool map_range);
volatile U8* mapIndexBuffer(S32 index, S32 count, bool map_range); volatile U8* mapIndexBuffer(S32 index, S32 count, bool map_range);
void bindForFeedback(U32 channel, U32 type, U32 index, U32 count);
// set for rendering // set for rendering
virtual void setBuffer(U32 data_mask); // calls setupVertexBuffer() if data_mask is not 0 virtual void setBuffer(U32 data_mask); // calls setupVertexBuffer() if data_mask is not 0
void flush(); //flush pending data to GL memory void flush(); //flush pending data to GL memory
@@ -327,9 +324,6 @@ protected:
static S32 determineUsage(S32 usage); static S32 determineUsage(S32 usage);
private:
static LLPrivateMemoryPool* sPrivatePoolp;
public: public:
static S32 sCount; static S32 sCount;
static S32 sGLCount; static S32 sGLCount;
@@ -353,6 +347,9 @@ public:
static U32 sIndexCount; static U32 sIndexCount;
static U32 sBindCount; static U32 sBindCount;
static U32 sSetCount; static U32 sSetCount;
private:
static LLVertexBuffer* sUtilityBuffer;
}; };

View File

@@ -607,7 +607,7 @@ void LLFace::renderSelected(LLViewerTexture *imagep, const LLColor4& color)
gGL.diffuseColor4fv(color.mV); gGL.diffuseColor4fv(color.mV);
LLVertexBuffer::drawElements(LLRender::TRIANGLES, vol_face.mPositions, vol_face.mTexCoords, vol_face.mNumIndices, vol_face.mIndices); LLVertexBuffer::drawElements(LLRender::TRIANGLES, vol_face.mNumVertices, vol_face.mPositions, vol_face.mTexCoords, vol_face.mNumIndices, vol_face.mIndices);
if(prev_shader) if(prev_shader)
{ {
@@ -1439,152 +1439,6 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
} }
static LLCachedControl<bool> use_transform_feedback("RenderUseTransformFeedback", false); static LLCachedControl<bool> use_transform_feedback("RenderUseTransformFeedback", false);
#ifdef GL_TRANSFORM_FEEDBACK_BUFFER
if (use_transform_feedback &&
gTransformPositionProgram.mProgramObject && //transform shaders are loaded
mVertexBuffer->useVBOs() && //target buffer is in VRAM
!rebuild_weights && //TODO: add support for weights
!volume.isUnique()) //source volume is NOT flexi
{ //use transform feedback to pack vertex buffer
LL_RECORD_BLOCK_TIME(FTM_FACE_GEOM_FEEDBACK);
LLGLEnable discard(GL_RASTERIZER_DISCARD);
LLVertexBuffer* buff = (LLVertexBuffer*) vf.mVertexBuffer.get();
if (vf.mVertexBuffer.isNull() || buff->getNumVerts() != vf.mNumVertices)
{
mVObjp->getVolume()->genTangents(f);
LLFace::cacheFaceInVRAM(vf);
buff = (LLVertexBuffer*) vf.mVertexBuffer.get();
}
LLGLSLShader* cur_shader = LLGLSLShader::sCurBoundShaderPtr;
gGL.pushMatrix();
gGL.loadMatrix(mat_vert_in);
if (rebuild_pos)
{
LL_RECORD_BLOCK_TIME(FTM_FACE_GEOM_FEEDBACK_POSITION);
gTransformPositionProgram.bind();
mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_VERTEX, mGeomIndex, mGeomCount);
U8 index = mTextureIndex < 255 ? mTextureIndex : 0;
S32 val = 0;
U8* vp = (U8*) &val;
vp[0] = index;
vp[1] = 0;
vp[2] = 0;
vp[3] = 0;
gTransformPositionProgram.uniform1i(sTextureIndexIn, val);
glBeginTransformFeedback(GL_POINTS);
buff->setBuffer(LLVertexBuffer::MAP_VERTEX);
push_for_transform(buff, vf.mNumVertices, mGeomCount);
glEndTransformFeedback();
}
if (rebuild_color)
{
LL_RECORD_BLOCK_TIME(FTM_FACE_GEOM_FEEDBACK_COLOR);
gTransformColorProgram.bind();
mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_COLOR, mGeomIndex, mGeomCount);
S32 val = *((S32*) color.mV);
gTransformColorProgram.uniform1i(sColorIn, val);
glBeginTransformFeedback(GL_POINTS);
buff->setBuffer(LLVertexBuffer::MAP_VERTEX);
push_for_transform(buff, vf.mNumVertices, mGeomCount);
glEndTransformFeedback();
}
if (rebuild_emissive)
{
LL_RECORD_BLOCK_TIME(FTM_FACE_GEOM_FEEDBACK_EMISSIVE);
gTransformColorProgram.bind();
mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_EMISSIVE, mGeomIndex, mGeomCount);
U8 glow = (U8) llclamp((S32) (getTextureEntry()->getGlow()*255), 0, 255);
S32 glow32 = glow |
(glow << 8) |
(glow << 16) |
(glow << 24);
gTransformColorProgram.uniform1i(sColorIn, glow32);
glBeginTransformFeedback(GL_POINTS);
buff->setBuffer(LLVertexBuffer::MAP_VERTEX);
push_for_transform(buff, vf.mNumVertices, mGeomCount);
glEndTransformFeedback();
}
if (rebuild_normal)
{
LL_RECORD_BLOCK_TIME(FTM_FACE_GEOM_FEEDBACK_NORMAL);
gTransformNormalProgram.bind();
mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_NORMAL, mGeomIndex, mGeomCount);
glBeginTransformFeedback(GL_POINTS);
buff->setBuffer(LLVertexBuffer::MAP_NORMAL);
push_for_transform(buff, vf.mNumVertices, mGeomCount);
glEndTransformFeedback();
}
if (rebuild_tangent)
{
LL_RECORD_BLOCK_TIME(FTM_FACE_GEOM_TANGENT);
gTransformTangentProgram.bind();
mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_TANGENT, mGeomIndex, mGeomCount);
glBeginTransformFeedback(GL_POINTS);
buff->setBuffer(LLVertexBuffer::MAP_TANGENT);
push_for_transform(buff, vf.mNumVertices, mGeomCount);
glEndTransformFeedback();
}
if (rebuild_tcoord)
{
LL_RECORD_BLOCK_TIME(FTM_FACE_GEOM_FEEDBACK_TEXTURE);
gTransformTexCoordProgram.bind();
mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_TEXCOORD0, mGeomIndex, mGeomCount);
glBeginTransformFeedback(GL_POINTS);
buff->setBuffer(LLVertexBuffer::MAP_TEXCOORD0);
push_for_transform(buff, vf.mNumVertices, mGeomCount);
glEndTransformFeedback();
bool do_bump = bump_code && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1);
if (do_bump)
{
mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_TEXCOORD1, mGeomIndex, mGeomCount);
glBeginTransformFeedback(GL_POINTS);
buff->setBuffer(LLVertexBuffer::MAP_TEXCOORD0);
push_for_transform(buff, vf.mNumVertices, mGeomCount);
glEndTransformFeedback();
}
}
glBindBufferARB(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
gGL.popMatrix();
if (cur_shader)
{
cur_shader->bind();
}
}
else
#endif
{ {
//if it's not fullbright and has no normals, bake sunlight based on face normal //if it's not fullbright and has no normals, bake sunlight based on face normal
//bool bake_sunlight = !getTextureEntry()->getFullbright() && //bool bake_sunlight = !getTextureEntry()->getFullbright() &&

View File

@@ -6140,7 +6140,7 @@ void pushWireframe(LLDrawable* drawable)
for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i) for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i)
{ {
const LLVolumeFace& face = volume->getVolumeFace(i); const LLVolumeFace& face = volume->getVolumeFace(i);
LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mPositions, NULL, face.mNumIndices, face.mIndices); LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mNumVertices, face.mPositions, NULL, face.mNumIndices, face.mIndices);
} }
} }

View File

@@ -1456,7 +1456,7 @@ void pushVerts(LLVolume* volume)
for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i) for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i)
{ {
const LLVolumeFace& face = volume->getVolumeFace(i); const LLVolumeFace& face = volume->getVolumeFace(i);
LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mPositions, NULL, face.mNumIndices, face.mIndices); LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mNumVertices, face.mPositions, NULL, face.mNumIndices, face.mIndices);
} }
} }
@@ -2325,11 +2325,11 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume)
llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShader != 0); llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShader != 0);
LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices); LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mNumHullPoints phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices);
gGL.diffuseColor4fv(color.mV); gGL.diffuseColor4fv(color.mV);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices); LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mNumHullPoints phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices);
} }
else else
@@ -2406,11 +2406,11 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume)
{ {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
gGL.diffuseColor4fv(line_color.mV); gGL.diffuseColor4fv(line_color.mV);
LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices); LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mNumHullPoints, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
gGL.diffuseColor4fv(color.mV); gGL.diffuseColor4fv(color.mV);
LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices); LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mNumHullPoints, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices);
} }
else else
{ {
@@ -2824,7 +2824,7 @@ void renderRaycast(LLDrawable* drawablep)
{ {
//render face positions //render face positions
gGL.diffuseColor4f(0,1,1,0.5f); gGL.diffuseColor4f(0,1,1,0.5f);
LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mPositions, NULL, face.mNumIndices, face.mIndices); LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mNumVertices, face.mPositions, NULL, face.mNumIndices, face.mIndices);
} }
if (!volume->isUnique()) if (!volume->isUnique())