From acfdcf2b1deeb04698174c78e8cb22b093445bb1 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:45:44 -0500 Subject: Second Life viewer sources 1.20.3 --- linden/indra/llrender/llglimmediate.cpp | 7 +- linden/indra/llrender/llglimmediate.h | 5 +- linden/indra/llrender/llimagegl.cpp | 79 +++++++++++--- linden/indra/llrender/llimagegl.h | 2 + linden/indra/llrender/llrendertarget.h | 2 +- linden/indra/llrender/llvertexbuffer.cpp | 176 ++++++++++++++++++++++++++++--- linden/indra/llrender/llvertexbuffer.h | 14 +++ 7 files changed, 246 insertions(+), 39 deletions(-) (limited to 'linden/indra/llrender') diff --git a/linden/indra/llrender/llglimmediate.cpp b/linden/indra/llrender/llglimmediate.cpp index db62f3d..da9239d 100644 --- a/linden/indra/llrender/llglimmediate.cpp +++ b/linden/indra/llrender/llglimmediate.cpp @@ -43,8 +43,7 @@ LLGLImmediate gGL; #endif bool LLGLImmediate::sClever = false; - -static BOOL sStarted = FALSE; +BOOL LLGLImmediate::sStarted = FALSE; LLGLImmediate::LLGLImmediate() { @@ -62,9 +61,9 @@ void LLGLImmediate::start() llerrs << "Redundant start." << llendl; } - sStarted = TRUE; LLVertexBuffer::unbind(); - + sStarted = TRUE; + glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); diff --git a/linden/indra/llrender/llglimmediate.h b/linden/indra/llrender/llglimmediate.h index bf2f9ab..cf4dc4f 100644 --- a/linden/indra/llrender/llglimmediate.h +++ b/linden/indra/llrender/llglimmediate.h @@ -91,9 +91,12 @@ public: GLfloat uv[2]; }; +public: + static BOOL sStarted; + private: static bool sClever; - + U32 mCount; U32 mMode; Vertex mBuffer[4096]; diff --git a/linden/indra/llrender/llimagegl.cpp b/linden/indra/llrender/llimagegl.cpp index 76c8252..c4b90a7 100644 --- a/linden/indra/llrender/llimagegl.cpp +++ b/linden/indra/llrender/llimagegl.cpp @@ -128,10 +128,16 @@ S32 LLImageGL::dataFormatComponents(S32 dataformat) void LLImageGL::bindExternalTexture(LLGLuint gl_name, S32 stage, LLGLenum bind_target ) { gGL.flush(); - glActiveTextureARB(GL_TEXTURE0_ARB + stage); - glClientActiveTextureARB(GL_TEXTURE0_ARB + stage); + if (stage > 0) + { + glActiveTextureARB(GL_TEXTURE0_ARB + stage); + } glBindTexture(bind_target, gl_name); sCurrentBoundTextures[stage] = gl_name; + if (stage > 0) + { + glActiveTextureARB(GL_TEXTURE0_ARB); + } } // static @@ -141,9 +147,16 @@ void LLImageGL::unbindTexture(S32 stage, LLGLenum bind_target) if (stage >= 0) { gGL.flush(); - glActiveTextureARB(GL_TEXTURE0_ARB + stage); - glClientActiveTextureARB(GL_TEXTURE0_ARB + stage); - glBindTexture(bind_target, 0); + if (stage > 0) + { + glActiveTextureARB(GL_TEXTURE0_ARB + stage); + glBindTexture(GL_TEXTURE_2D, 0); + glActiveTextureARB(GL_TEXTURE0_ARB); + } + else + { + glBindTexture(GL_TEXTURE_2D, 0); + } sCurrentBoundTextures[stage] = 0; } } @@ -151,15 +164,7 @@ void LLImageGL::unbindTexture(S32 stage, LLGLenum bind_target) // static (duplicated for speed and to avoid GL_TEXTURE_2D default argument which requires GL header dependency) void LLImageGL::unbindTexture(S32 stage) { - // LLGLSLShader can return -1 - if (stage >= 0) - { - gGL.flush(); - glActiveTextureARB(GL_TEXTURE0_ARB + stage); - glClientActiveTextureARB(GL_TEXTURE0_ARB + stage); - glBindTexture(GL_TEXTURE_2D, 0); - sCurrentBoundTextures[stage] = 0; - } + unbindTexture(stage, GL_TEXTURE_2D); } // static @@ -419,8 +424,6 @@ BOOL LLImageGL::bindTextureInternal(const S32 stage) const } - glActiveTextureARB(GL_TEXTURE0_ARB + stage); - if (sCurrentBoundTextures[stage] && sCurrentBoundTextures[stage] == mTexName) { // already set! @@ -434,10 +437,20 @@ BOOL LLImageGL::bindTextureInternal(const S32 stage) const #endif gGL.flush(); + if (stage > 0) + { + glActiveTextureARB(GL_TEXTURE0_ARB + stage); + } + glBindTexture(mBindTarget, mTexName); sCurrentBoundTextures[stage] = mTexName; sBindCount++; + if (stage > 0) + { + glActiveTextureARB(GL_TEXTURE0_ARB); + } + if (mLastBindTime != sLastFrameTime) { // we haven't accounted for this texture yet this frame @@ -451,7 +464,15 @@ BOOL LLImageGL::bindTextureInternal(const S32 stage) const else { gGL.flush(); + if (stage > 0) + { + glActiveTextureARB(GL_TEXTURE0_ARB+stage); + } glBindTexture(mBindTarget, 0); + if (stage > 0) + { + glActiveTextureARB(GL_TEXTURE0_ARB+stage); + } sCurrentBoundTextures[stage] = 0; return FALSE; } @@ -985,6 +1006,21 @@ BOOL LLImageGL::setDiscardLevel(S32 discard_level) } } +BOOL LLImageGL::isValidForSculpt(S32 discard_level, S32 image_width, S32 image_height, S32 ncomponents) +{ + assert_glerror(); + S32 gl_discard = discard_level - mCurrentDiscardLevel; + LLGLint glwidth = 0; + glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_WIDTH, (GLint*)&glwidth); + LLGLint glheight = 0; + glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_HEIGHT, (GLint*)&glheight); + LLGLint glcomponents = 0 ; + glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_INTERNAL_FORMAT, (GLint*)&glcomponents); + assert_glerror(); + + return glwidth >= image_width && glheight >= image_height && (GL_RGB8 == glcomponents || GL_RGBA8 == glcomponents) ; +} + BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compressed_ok) { if (discard_level < 0) @@ -1033,12 +1069,22 @@ BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, (GLint*)&glbytes); imageraw->allocateDataSize(width, height, ncomponents, glbytes); glGetCompressedTexImageARB(mTarget, gl_discard, (GLvoid*)(imageraw->getData())); + if(glGetError() != GL_NO_ERROR) + { + llwarns << "Error happens when reading back the compressed texture image." << llendl ; + imageraw->deleteData() ; + } stop_glerror(); } else { imageraw->allocateDataSize(width, height, ncomponents); glGetTexImage(GL_TEXTURE_2D, gl_discard, mFormatPrimary, mFormatType, (GLvoid*)(imageraw->getData())); + if(glGetError() != GL_NO_ERROR) + { + llwarns << "Error happens when reading back the texture image." << llendl ; + imageraw->deleteData() ; + } stop_glerror(); } @@ -1057,7 +1103,6 @@ void LLImageGL::destroyGLTexture() { unbindTexture(i, GL_TEXTURE_2D); stop_glerror(); - glActiveTextureARB(GL_TEXTURE0_ARB); } } diff --git a/linden/indra/llrender/llimagegl.h b/linden/indra/llrender/llimagegl.h index efe94c2..b386294 100644 --- a/linden/indra/llrender/llimagegl.h +++ b/linden/indra/llrender/llimagegl.h @@ -131,6 +131,8 @@ public: BOOL getUseDiscard() const { return mUseMipMaps && !mDontDiscard; } BOOL getDontDiscard() const { return mDontDiscard; } + BOOL isValidForSculpt(S32 discard_level, S32 image_width, S32 image_height, S32 ncomponents) ; + protected: void init(BOOL usemipmaps); virtual void cleanup(); // Clean up the LLImageGL so it can be reinitialized. Be careful when using this in derived class destructors diff --git a/linden/indra/llrender/llrendertarget.h b/linden/indra/llrender/llrendertarget.h index 918a604..d16d986 100644 --- a/linden/indra/llrender/llrendertarget.h +++ b/linden/indra/llrender/llrendertarget.h @@ -71,7 +71,7 @@ public: //allocate resources for rendering //must be called before use //multiple calls will release previously allocated resources - void allocate(U32 resx, U32 resy, U32 color_fmt, BOOL depth, U32 usage = GL_TEXTURE_2D, BOOL use_fbo = TRUE); + void allocate(U32 resx, U32 resy, U32 color_fmt, BOOL depth, U32 usage = GL_TEXTURE_2D, BOOL use_fbo = FALSE); //allocate a depth texture void allocateDepth(); diff --git a/linden/indra/llrender/llvertexbuffer.cpp b/linden/indra/llrender/llvertexbuffer.cpp index f3c6997..d165c01 100644 --- a/linden/indra/llrender/llvertexbuffer.cpp +++ b/linden/indra/llrender/llvertexbuffer.cpp @@ -38,6 +38,7 @@ #include "llglheaders.h" #include "llmemory.h" #include "llmemtype.h" +#include "llglimmediate.h" //============================================================================ @@ -76,6 +77,141 @@ S32 LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_MAX] = sizeof(LLVector4), // TYPE_CLOTHWEIGHT, }; +U32 LLVertexBuffer::sGLMode[LLVertexBuffer::NUM_MODES] = +{ + GL_TRIANGLES, + GL_TRIANGLE_STRIP, + GL_TRIANGLE_FAN, + GL_POINTS, + GL_LINES, + GL_LINE_STRIP +}; + +//static +void LLVertexBuffer::setupClientArrays(U32 data_mask) +{ + if (LLGLImmediate::sStarted) + { + llerrs << "Cannot use LLGLImmediate and LLVertexBuffer simultaneously!" << llendl; + } + + if (sLastMask != data_mask) + { + U32 mask[] = + { + MAP_VERTEX, + MAP_NORMAL, + MAP_TEXCOORD, + MAP_COLOR + }; + + GLenum array[] = + { + GL_VERTEX_ARRAY, + GL_NORMAL_ARRAY, + GL_TEXTURE_COORD_ARRAY, + GL_COLOR_ARRAY + }; + + for (U32 i = 0; i < 4; ++i) + { + if (sLastMask & mask[i]) + { //was enabled + if (!(data_mask & mask[i]) && i > 0) + { //needs to be disabled + glDisableClientState(array[i]); + } + else + { //needs to be enabled, make sure it was (DEBUG TEMPORARY) + if (i > 0 && !glIsEnabled(array[i])) + { + llerrs << "Bad client state! " << array[i] << " disabled." << llendl; + } + } + } + else + { //was disabled + if (data_mask & mask[i]) + { //needs to be enabled + glEnableClientState(array[i]); + } + else if (glIsEnabled(array[i])) + { //needs to be disabled, make sure it was (DEBUG TEMPORARY) + llerrs << "Bad client state! " << array[i] << " enabled." << llendl; + } + } + } + + if (sLastMask & MAP_TEXCOORD2) + { + if (!(data_mask & MAP_TEXCOORD2)) + { + glClientActiveTextureARB(GL_TEXTURE1_ARB); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + } + else if (data_mask & MAP_TEXCOORD2) + { + glClientActiveTextureARB(GL_TEXTURE1_ARB); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + + sLastMask = data_mask; + } +} + +void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const +{ + if (start >= (U32) mRequestedNumVerts || + end >= (U32) mRequestedNumVerts) + { + llerrs << "Bad vertex buffer draw range: [" << start << ", " << end << "]" << llendl; + } + + if (indices_offset >= (U32) mRequestedNumIndices || + indices_offset + count > (U32) mRequestedNumIndices) + { + llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl; + } + + if (mGLIndices != sGLRenderIndices) + { + llerrs << "Wrong index buffer bound." << llendl; + } + + if (mGLBuffer != sGLRenderBuffer) + { + llerrs << "Wrong vertex buffer bound." << llendl; + } + + glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, + ((U16*) getIndicesPointer()) + indices_offset); +} + +void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const +{ + if (indices_offset >= (U32) mRequestedNumIndices || + indices_offset + count > (U32) mRequestedNumIndices) + { + llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl; + } + + if (mGLIndices != sGLRenderIndices) + { + llerrs << "Wrong index buffer bound." << llendl; + } + + if (mGLBuffer != sGLRenderBuffer) + { + llerrs << "Wrong vertex buffer bound." << llendl; + } + + glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, + ((U16*) getIndicesPointer()) + indices_offset); +} + //static void LLVertexBuffer::initClass(bool use_vbo) { @@ -102,7 +238,8 @@ void LLVertexBuffer::unbind() sGLRenderBuffer = 0; sGLRenderIndices = 0; - sLastMask = 0; + + setupClientArrays(0); } //static @@ -118,22 +255,14 @@ void LLVertexBuffer::cleanupClass() void LLVertexBuffer::startRender() { LLMemType mt(LLMemType::MTYPE_VERTEX_DATA); - if (sEnableVBOs) - { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); - sVBOActive = FALSE; - sIBOActive = FALSE; - } - + + unbind(); sRenderActive = TRUE; - sGLRenderBuffer = 0; - sGLRenderIndices = 0; - sLastMask = 0; } void LLVertexBuffer::stopRender() { + unbind(); sRenderActive = FALSE; } @@ -615,6 +744,16 @@ U8* LLVertexBuffer::mapBuffer(S32 access) llerrs << "Mapped two VBOs at the same time!" << llendl; } sMapped = TRUE;*/ + if (!mMappedData) + { + llerrs << "glMapBuffer returned NULL (no vertex data)" << llendl; + } + + if (!mMappedIndexData) + { + llerrs << "glMapBuffer returned NULL (no index data)" << llendl; + } + sMappedCount++; } @@ -666,7 +805,12 @@ template struct VertexBufferStrider strider_t& strider, S32 index) { - vbo.mapBuffer(); + if (vbo.mapBuffer() == NULL) + { + llwarns << "mapBuffer failed!" << llendl; + return FALSE; + } + if (type == LLVertexBuffer::TYPE_INDEX) { S32 stride = sizeof(T); @@ -828,6 +972,8 @@ void LLVertexBuffer::setBuffer(U32 data_mask) sIBOActive = FALSE; } } + + setupClientArrays(data_mask); if (mGLIndices) { @@ -846,8 +992,6 @@ void LLVertexBuffer::setBuffer(U32 data_mask) sSetCount++; } } - - sLastMask = data_mask; } // virtual (default) @@ -871,10 +1015,10 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) const { glClientActiveTextureARB(GL_TEXTURE1_ARB); glTexCoordPointer(2,GL_FLOAT, stride, (void*)(base + mOffsets[TYPE_TEXCOORD2])); + glClientActiveTextureARB(GL_TEXTURE0_ARB); } if (data_mask & MAP_TEXCOORD) { - glClientActiveTextureARB(GL_TEXTURE0_ARB); glTexCoordPointer(2,GL_FLOAT, stride, (void*)(base + mOffsets[TYPE_TEXCOORD])); } if (data_mask & MAP_COLOR) diff --git a/linden/indra/llrender/llvertexbuffer.h b/linden/indra/llrender/llvertexbuffer.h index 3031b2d..453f3ac 100644 --- a/linden/indra/llrender/llvertexbuffer.h +++ b/linden/indra/llrender/llvertexbuffer.h @@ -84,6 +84,7 @@ public: static void initClass(bool use_vbo); static void cleanupClass(); + static void setupClientArrays(U32 data_mask); static void startRender(); //between start and stop render, no client copies will occur static void stopRender(); //any buffer not copied to GL will be rendered from client memory static void clientCopy(F64 max_time = 0.005); //copy data from client to GL @@ -123,6 +124,15 @@ public: MAP_UNMAPPED = 0x8000 // Indicates that buffer has been logically un-mapped }; + enum { + TRIANGLES = 0, + TRIANGLE_STRIP, + TRIANGLE_FAN, + POINTS, + LINES, + LINE_STRIP, + NUM_MODES + }; protected: friend class LLGLImmediate; @@ -194,6 +204,9 @@ public: void markDirty(U32 vert_index, U32 vert_count, U32 indices_index, U32 indices_count); + void draw(U32 mode, U32 count, U32 indices_offset) const; + void drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const; + protected: S32 mNumVerts; // Number of vertices allocated S32 mNumIndices; // Number of indices allocated @@ -241,6 +254,7 @@ public: static BOOL sEnableVBOs; static S32 sTypeOffsets[TYPE_MAX]; + static U32 sGLMode[NUM_MODES]; static U32 sGLRenderBuffer; static U32 sGLRenderIndices; static BOOL sVBOActive; -- cgit v1.1