Newer
Older
static LLFastTimer::DeclareTimer FTM_BIND_GL_INDICES("Bind Indices");
David Parks
committed
bool LLVertexBuffer::bindGLIndices(bool force_bind)
{
bindGLArray();
bool ret = false;
if (useVBOs() && (force_bind || (mGLIndices && (mGLIndices != sGLRenderIndices || !sIBOActive))))
{
David Parks
committed
/*if (sMapped)
{
llerrs << "VBO bound while another VBO mapped!" << llendl;
}*/
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices);
sGLRenderIndices = mGLIndices;
stop_glerror();
sBindCount++;
David Parks
committed
ret = true;
}
return ret;
}
void LLVertexBuffer::flush()
{
if (useVBOs())
{
unmapBuffer();
}
}
// Set for rendering
David Parks
committed
void LLVertexBuffer::setBuffer(U32 data_mask)
David Parks
committed
flush();
LLMemType mt2(LLMemType::MTYPE_VERTEX_SET_BUFFER);
//set up pointers if the data mask is different ...
Leslie Linden
committed
bool setup = (sLastMask != data_mask);
David Parks
committed
if (gDebugGL && data_mask != 0)
David Parks
committed
{ //make sure data requirements are fulfilled
David Parks
committed
LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
if (shader)
{
U32 required_mask = 0;
David Parks
committed
for (U32 i = 0; i < LLVertexBuffer::TYPE_TEXTURE_INDEX; ++i)
David Parks
committed
{
if (shader->getAttribLocation(i) > -1)
{
U32 required = 1 << i;
if ((data_mask & required) == 0)
{
David Parks
committed
llwarns << "Missing attribute: " << LLShaderMgr::instance()->mReservedAttribs[i] << llendl;
David Parks
committed
}
required_mask |= required;
}
}
if ((data_mask & required_mask) != required_mask)
{
llerrs << "Shader consumption mismatches data provision." << llendl;
}
}
}
if (useVBOs())
{
David Parks
committed
if (mGLArray)
{
David Parks
committed
bindGLArray();
Leslie Linden
committed
setup = false; //do NOT perform pointer setup if using VAO
}
David Parks
committed
else
Leslie Linden
committed
const bool bindBuffer = bindGLBuffer();
const bool bindIndices = bindGLIndices();
setup = setup || bindBuffer || bindIndices;
Leslie Linden
committed
bool error = false;
David Parks
committed
if (gDebugGL && !mGLArray)
{
GLint buff;
glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff);
if (gDebugSession)
{
Leslie Linden
committed
error = true;
gFailLog << "Invalid GL vertex buffer bound: " << buff << std::endl;
}
else
{
llerrs << "Invalid GL vertex buffer bound: " << buff << llendl;
}
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff);
if ((GLuint)buff != mGLIndices)
if (gDebugSession)
{
Leslie Linden
committed
error = true;
gFailLog << "Invalid GL index buffer bound: " << buff << std::endl;
}
else
{
llerrs << "Invalid GL index buffer bound: " << buff << llendl;
}
David Parks
committed
}
else
{
if (sGLRenderArray)
{
David Parks
committed
glBindVertexArray(0);
David Parks
committed
sGLRenderArray = 0;
David Parks
committed
sGLRenderIndices = 0;
}
if (mGLBuffer)
{
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
sBindCount++;
Leslie Linden
committed
setup = true; // ... or a VBO is deactivated
}
if (sGLRenderBuffer != mGLBuffer)
{
David Parks
committed
sGLRenderBuffer = mGLBuffer;
Leslie Linden
committed
setup = true; // ... or a client memory pointer changed
David Parks
committed
if (mGLIndices)
David Parks
committed
if (sIBOActive)
{
David Parks
committed
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
sBindCount++;
David Parks
committed
}
sGLRenderIndices = mGLIndices;
David Parks
committed
if (!mGLArray)
setupClientArrays(data_mask);
David Parks
committed
if (mGLBuffer)
{
if (data_mask && setup)
{
setupVertexBuffer(data_mask); // subclass specific setup (virtual function)
sSetCount++;
}
}
}
// virtual (default)
David Parks
committed
void LLVertexBuffer::setupVertexBuffer(U32 data_mask)
LLMemType mt2(LLMemType::MTYPE_VERTEX_SETUP_VERTEX_BUFFER);
volatile U8* base = useVBOs() ? (U8*) mAlignedOffset : mMappedData;
David Parks
committed
/*if ((data_mask & mTypeMask) != data_mask)
{
llerrs << "LLVertexBuffer::setupVertexBuffer missing required components for supplied data mask." << llendl;
David Parks
committed
}*/
David Parks
committed
if (LLGLSLShader::sNoFixedFunction)
David Parks
committed
if (data_mask & MAP_NORMAL)
David Parks
committed
S32 loc = TYPE_NORMAL;
void* ptr = (void*)(base + mOffsets[TYPE_NORMAL]);
David Parks
committed
glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr);
David Parks
committed
if (data_mask & MAP_TEXCOORD3)
David Parks
committed
S32 loc = TYPE_TEXCOORD3;
void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD3]);
David Parks
committed
glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr);
David Parks
committed
if (data_mask & MAP_TEXCOORD2)
David Parks
committed
S32 loc = TYPE_TEXCOORD2;
void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD2]);
David Parks
committed
glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr);
David Parks
committed
if (data_mask & MAP_TEXCOORD1)
David Parks
committed
S32 loc = TYPE_TEXCOORD1;
void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD1]);
David Parks
committed
glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr);
David Parks
committed
if (data_mask & MAP_BINORMAL)
David Parks
committed
S32 loc = TYPE_BINORMAL;
void* ptr = (void*)(base + mOffsets[TYPE_BINORMAL]);
David Parks
committed
glVertexAttribPointerARB(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_BINORMAL], ptr);
David Parks
committed
if (data_mask & MAP_TEXCOORD0)
David Parks
committed
S32 loc = TYPE_TEXCOORD0;
void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD0]);
David Parks
committed
glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr);
David Parks
committed
if (data_mask & MAP_COLOR)
David Parks
committed
S32 loc = TYPE_COLOR;
void* ptr = (void*)(base + mOffsets[TYPE_COLOR]);
glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr);
David Parks
committed
if (data_mask & MAP_EMISSIVE)
David Parks
committed
S32 loc = TYPE_EMISSIVE;
void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE]);
David Parks
committed
glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr);
David Parks
committed
if (data_mask & MAP_WEIGHT)
David Parks
committed
S32 loc = TYPE_WEIGHT;
void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT]);
Leslie Linden
committed
glVertexAttribPointerARB(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr);
David Parks
committed
if (data_mask & MAP_WEIGHT4)
David Parks
committed
S32 loc = TYPE_WEIGHT4;
void* ptr = (void*)(base+mOffsets[TYPE_WEIGHT4]);
Leslie Linden
committed
glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr);
David Parks
committed
if (data_mask & MAP_CLOTHWEIGHT)
David Parks
committed
S32 loc = TYPE_CLOTHWEIGHT;
void* ptr = (void*)(base + mOffsets[TYPE_CLOTHWEIGHT]);
Leslie Linden
committed
glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr);
David Parks
committed
if (data_mask & MAP_TEXTURE_INDEX &&
(gGLManager.mGLSLVersionMajor >= 2 || gGLManager.mGLSLVersionMinor >= 30)) //indexed texture rendering requires GLSL 1.30 or later
S32 loc = TYPE_TEXTURE_INDEX;
David Parks
committed
void *ptr = (void*) (base + mOffsets[TYPE_VERTEX] + 12);
David Parks
committed
glVertexAttribIPointer(loc, 4, GL_UNSIGNED_BYTE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr);
David Parks
committed
if (data_mask & MAP_VERTEX)
{
S32 loc = TYPE_VERTEX;
void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]);
glVertexAttribPointerARB(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr);
David Parks
committed
}
}
else
David Parks
committed
if (data_mask & MAP_NORMAL)
David Parks
committed
glNormalPointer(GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_NORMAL], (void*)(base + mOffsets[TYPE_NORMAL]));
David Parks
committed
if (data_mask & MAP_TEXCOORD3)
{
David Parks
committed
glClientActiveTextureARB(GL_TEXTURE3_ARB);
glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], (void*)(base + mOffsets[TYPE_TEXCOORD3]));
glClientActiveTextureARB(GL_TEXTURE0_ARB);
David Parks
committed
if (data_mask & MAP_TEXCOORD2)
David Parks
committed
{
David Parks
committed
glClientActiveTextureARB(GL_TEXTURE2_ARB);
glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], (void*)(base + mOffsets[TYPE_TEXCOORD2]));
glClientActiveTextureARB(GL_TEXTURE0_ARB);
David Parks
committed
}
David Parks
committed
if (data_mask & MAP_TEXCOORD1)
David Parks
committed
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], (void*)(base + mOffsets[TYPE_TEXCOORD1]));
glClientActiveTextureARB(GL_TEXTURE0_ARB);
David Parks
committed
if (data_mask & MAP_BINORMAL)
{
David Parks
committed
glClientActiveTextureARB(GL_TEXTURE2_ARB);
glTexCoordPointer(3,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_BINORMAL], (void*)(base + mOffsets[TYPE_BINORMAL]));
glClientActiveTextureARB(GL_TEXTURE0_ARB);
David Parks
committed
if (data_mask & MAP_TEXCOORD0)
David Parks
committed
{
David Parks
committed
glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], (void*)(base + mOffsets[TYPE_TEXCOORD0]));
David Parks
committed
}
David Parks
committed
if (data_mask & MAP_COLOR)
David Parks
committed
{
David Parks
committed
glColorPointer(4, GL_UNSIGNED_BYTE, LLVertexBuffer::sTypeSize[TYPE_COLOR], (void*)(base + mOffsets[TYPE_COLOR]));
David Parks
committed
if (data_mask & MAP_VERTEX)
David Parks
committed
glVertexPointer(3,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_VERTEX], (void*)(base + 0));
}
}
llglassertok();
}
LLVertexBuffer::MappedRegion::MappedRegion(S32 type, S32 index, S32 count)
: mType(type), mIndex(index), mCount(count)
{
llassert(mType == LLVertexBuffer::TYPE_INDEX ||
mType < LLVertexBuffer::TYPE_TEXTURE_INDEX);
}