Finished LLGLTexture. Migrated opengl related code from llui.h/cpp to llrender2dutils.h/cpp. Moved lluiimage to llrender library.
This commit is contained in:
@@ -31,11 +31,14 @@ set(llrender_SOURCE_FILES
|
||||
llfontregistry.cpp
|
||||
llgldbg.cpp
|
||||
llglslshader.cpp
|
||||
llgltexture.cpp
|
||||
llimagegl.cpp
|
||||
llpostprocess.cpp
|
||||
llrender2dutils.cpp
|
||||
llrendersphere.cpp
|
||||
llshadermgr.cpp
|
||||
lltexture.cpp
|
||||
lluiimage.cpp
|
||||
llvertexbuffer.cpp
|
||||
)
|
||||
|
||||
@@ -57,9 +60,11 @@ set(llrender_HEADER_FILES
|
||||
llimagegl.h
|
||||
llpostprocess.h
|
||||
llrender.h
|
||||
llrender2dutils.h
|
||||
llrendersphere.h
|
||||
llshadermgr.h
|
||||
lltexture.h
|
||||
lluiimage.h
|
||||
llvertexbuffer.h
|
||||
)
|
||||
|
||||
|
||||
398
indra/llrender/llgltexture.cpp
Normal file
398
indra/llrender/llgltexture.cpp
Normal file
@@ -0,0 +1,398 @@
|
||||
/**
|
||||
* @file llgltexture.cpp
|
||||
* @brief Opengl texture implementation
|
||||
*
|
||||
* $LicenseInfo:firstyear=2000&license=viewerlgpl$
|
||||
* Second Life Viewer Source Code
|
||||
* Copyright (C) 2010, Linden Research, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
#include "linden_common.h"
|
||||
#include "llgltexture.h"
|
||||
|
||||
|
||||
// static
|
||||
S32 LLGLTexture::getTotalNumOfCategories()
|
||||
{
|
||||
return MAX_GL_IMAGE_CATEGORY - (BOOST_HIGH - BOOST_SCULPTED) + 2 ;
|
||||
}
|
||||
|
||||
// static
|
||||
//index starts from zero.
|
||||
S32 LLGLTexture::getIndexFromCategory(S32 category)
|
||||
{
|
||||
return (category < BOOST_HIGH) ? category : category - (BOOST_HIGH - BOOST_SCULPTED) + 1 ;
|
||||
}
|
||||
|
||||
//static
|
||||
S32 LLGLTexture::getCategoryFromIndex(S32 index)
|
||||
{
|
||||
return (index < BOOST_HIGH) ? index : index + (BOOST_HIGH - BOOST_SCULPTED) - 1 ;
|
||||
}
|
||||
|
||||
LLGLTexture::LLGLTexture(BOOL usemipmaps)
|
||||
{
|
||||
init();
|
||||
mUseMipMaps = usemipmaps;
|
||||
}
|
||||
|
||||
LLGLTexture::LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps)
|
||||
{
|
||||
init();
|
||||
mFullWidth = width ;
|
||||
mFullHeight = height ;
|
||||
mUseMipMaps = usemipmaps ;
|
||||
mComponents = components ;
|
||||
setTexelsPerImage();
|
||||
}
|
||||
|
||||
LLGLTexture::LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps)
|
||||
{
|
||||
init();
|
||||
mUseMipMaps = usemipmaps ;
|
||||
// Create an empty image of the specified size and width
|
||||
mGLTexturep = new LLImageGL(raw, usemipmaps) ;
|
||||
}
|
||||
|
||||
LLGLTexture::~LLGLTexture()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void LLGLTexture::init()
|
||||
{
|
||||
mBoostLevel = LLGLTexture::BOOST_NONE;
|
||||
|
||||
mFullWidth = 0;
|
||||
mFullHeight = 0;
|
||||
mTexelsPerImage = 0 ;
|
||||
mUseMipMaps = FALSE ;
|
||||
mComponents = 0 ;
|
||||
|
||||
mTextureState = NO_DELETE ;
|
||||
mDontDiscard = FALSE;
|
||||
mNeedsGLTexture = FALSE ;
|
||||
}
|
||||
|
||||
void LLGLTexture::cleanup()
|
||||
{
|
||||
if(mGLTexturep)
|
||||
{
|
||||
mGLTexturep->cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
// virtual
|
||||
void LLGLTexture::dump()
|
||||
{
|
||||
if(mGLTexturep)
|
||||
{
|
||||
mGLTexturep->dump();
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLTexture::setBoostLevel(S32 level)
|
||||
{
|
||||
if(mBoostLevel != level)
|
||||
{
|
||||
mBoostLevel = level ;
|
||||
if(mBoostLevel != LLGLTexture::BOOST_NONE)
|
||||
{
|
||||
setNoDelete() ;
|
||||
}
|
||||
if(gAuditTexture)
|
||||
{
|
||||
setCategory(mBoostLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLTexture::forceActive()
|
||||
{
|
||||
mTextureState = ACTIVE ;
|
||||
}
|
||||
|
||||
void LLGLTexture::setActive()
|
||||
{
|
||||
if(mTextureState != NO_DELETE)
|
||||
{
|
||||
mTextureState = ACTIVE ;
|
||||
}
|
||||
}
|
||||
|
||||
//set the texture to stay in memory
|
||||
void LLGLTexture::setNoDelete()
|
||||
{
|
||||
mTextureState = NO_DELETE ;
|
||||
}
|
||||
|
||||
void LLGLTexture::generateGLTexture()
|
||||
{
|
||||
if(mGLTexturep.isNull())
|
||||
{
|
||||
mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps) ;
|
||||
}
|
||||
}
|
||||
|
||||
LLImageGL* LLGLTexture::getGLTexture() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::createGLTexture()
|
||||
{
|
||||
if(mGLTexturep.isNull())
|
||||
{
|
||||
generateGLTexture() ;
|
||||
}
|
||||
|
||||
return mGLTexturep->createGLTexture() ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename, BOOL to_create, S32 category)
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category) ;
|
||||
|
||||
if(ret)
|
||||
{
|
||||
mFullWidth = mGLTexturep->getCurrentWidth() ;
|
||||
mFullHeight = mGLTexturep->getCurrentHeight() ;
|
||||
mComponents = mGLTexturep->getComponents() ;
|
||||
setTexelsPerImage();
|
||||
}
|
||||
|
||||
return ret ;
|
||||
}
|
||||
|
||||
void LLGLTexture::setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes)
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes) ;
|
||||
}
|
||||
void LLGLTexture::setAddressMode(LLTexUnit::eTextureAddressMode mode)
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
mGLTexturep->setAddressMode(mode) ;
|
||||
}
|
||||
void LLGLTexture::setFilteringOption(LLTexUnit::eTextureFilterOptions option)
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
mGLTexturep->setFilteringOption(option) ;
|
||||
}
|
||||
|
||||
//virtual
|
||||
S32 LLGLTexture::getWidth(S32 discard_level) const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
return mGLTexturep->getWidth(discard_level) ;
|
||||
}
|
||||
|
||||
//virtual
|
||||
S32 LLGLTexture::getHeight(S32 discard_level) const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
return mGLTexturep->getHeight(discard_level) ;
|
||||
}
|
||||
|
||||
S32 LLGLTexture::getMaxDiscardLevel() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
return mGLTexturep->getMaxDiscardLevel() ;
|
||||
}
|
||||
S32 LLGLTexture::getDiscardLevel() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
return mGLTexturep->getDiscardLevel() ;
|
||||
}
|
||||
S8 LLGLTexture::getComponents() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getComponents() ;
|
||||
}
|
||||
|
||||
LLGLuint LLGLTexture::getTexName() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getTexName() ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::hasGLTexture() const
|
||||
{
|
||||
if(mGLTexturep.notNull())
|
||||
{
|
||||
return mGLTexturep->getHasGLTexture() ;
|
||||
}
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::getBoundRecently() const
|
||||
{
|
||||
if(mGLTexturep.notNull())
|
||||
{
|
||||
return mGLTexturep->getBoundRecently() ;
|
||||
}
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
LLTexUnit::eTextureType LLGLTexture::getTarget(void) const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
return mGLTexturep->getTarget() ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, bool fast_update)
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height, fast_update) ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height, bool fast_update)
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height, fast_update) ;
|
||||
}
|
||||
|
||||
void LLGLTexture::setGLTextureCreated (bool initialized)
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
mGLTexturep->setGLTextureCreated (initialized) ;
|
||||
}
|
||||
|
||||
void LLGLTexture::setCategory(S32 category)
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
mGLTexturep->setCategory(category) ;
|
||||
}
|
||||
|
||||
LLTexUnit::eTextureAddressMode LLGLTexture::getAddressMode(void) const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getAddressMode() ;
|
||||
}
|
||||
|
||||
S32 LLGLTexture::getTextureMemory() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->mTextureMemory ;
|
||||
}
|
||||
|
||||
LLGLenum LLGLTexture::getPrimaryFormat() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getPrimaryFormat() ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::getIsAlphaMask() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getIsAlphaMask() ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::getMask(const LLVector2 &tc)
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getMask(tc) ;
|
||||
}
|
||||
|
||||
F32 LLGLTexture::getTimePassedSinceLastBound()
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getTimePassedSinceLastBound() ;
|
||||
}
|
||||
BOOL LLGLTexture::getMissed() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getMissed() ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::isJustBound() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->isJustBound() ;
|
||||
}
|
||||
|
||||
void LLGLTexture::forceUpdateBindStats(void) const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->forceUpdateBindStats() ;
|
||||
}
|
||||
|
||||
/*U32 LLGLTexture::getTexelsInAtlas() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getTexelsInAtlas() ;
|
||||
}
|
||||
|
||||
U32 LLGLTexture::getTexelsInGLTexture() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getTexelsInGLTexture() ;
|
||||
}
|
||||
|
||||
BOOL LLGLTexture::isGLTextureCreated() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->isGLTextureCreated() ;
|
||||
}
|
||||
|
||||
S32 LLGLTexture::getDiscardLevelInAtlas() const
|
||||
{
|
||||
llassert(mGLTexturep.notNull()) ;
|
||||
|
||||
return mGLTexturep->getDiscardLevelInAtlas() ;
|
||||
}*/
|
||||
|
||||
void LLGLTexture::destroyGLTexture()
|
||||
{
|
||||
if(mGLTexturep.notNull() && mGLTexturep->getHasGLTexture())
|
||||
{
|
||||
mGLTexturep->destroyGLTexture() ;
|
||||
mTextureState = DELETED ;
|
||||
}
|
||||
}
|
||||
|
||||
void LLGLTexture::setTexelsPerImage()
|
||||
{
|
||||
S32 fullwidth = llmin(mFullWidth,(S32)MAX_IMAGE_SIZE_DEFAULT);
|
||||
S32 fullheight = llmin(mFullHeight,(S32)MAX_IMAGE_SIZE_DEFAULT);
|
||||
mTexelsPerImage = (F32)fullwidth * fullheight;
|
||||
}
|
||||
@@ -79,92 +79,104 @@ public:
|
||||
MAX_GL_IMAGE_CATEGORY
|
||||
};
|
||||
|
||||
//static S32 getTotalNumOfCategories() ;
|
||||
//static S32 getIndexFromCategory(S32 category) ;
|
||||
//static S32 getCategoryFromIndex(S32 index) ;
|
||||
static S32 getTotalNumOfCategories() ;
|
||||
static S32 getIndexFromCategory(S32 category) ;
|
||||
static S32 getCategoryFromIndex(S32 index) ;
|
||||
|
||||
protected:
|
||||
virtual ~LLGLTexture() {};
|
||||
virtual ~LLGLTexture();
|
||||
LOG_CLASS(LLGLTexture);
|
||||
|
||||
public:
|
||||
//LLGLTexture(BOOL usemipmaps = TRUE);
|
||||
//LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
|
||||
//LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) ;
|
||||
LLGLTexture(BOOL usemipmaps = TRUE);
|
||||
LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
|
||||
LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) ;
|
||||
|
||||
virtual void dump() = 0; // debug info to llinfos
|
||||
virtual void dump(); // debug info to llinfos
|
||||
|
||||
virtual const LLUUID& getID() const = 0;
|
||||
|
||||
virtual void setBoostLevel(S32 level) = 0;
|
||||
virtual S32 getBoostLevel() = 0;
|
||||
void setBoostLevel(S32 level);
|
||||
S32 getBoostLevel() { return mBoostLevel; }
|
||||
|
||||
virtual S32 getFullWidth() const = 0;
|
||||
virtual S32 getFullHeight() const = 0;
|
||||
S32 getFullWidth() const { return mFullWidth; }
|
||||
S32 getFullHeight() const { return mFullHeight; }
|
||||
|
||||
virtual void generateGLTexture() = 0;
|
||||
virtual void destroyGLTexture() = 0;
|
||||
void generateGLTexture() ;
|
||||
void destroyGLTexture() ;
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//functions to access LLImageGL
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//*virtual*/S32 getWidth(S32 discard_level = -1) const;
|
||||
//*virtual*/S32 getHeight(S32 discard_level = -1) const;
|
||||
/*virtual*/S32 getWidth(S32 discard_level = -1) const;
|
||||
/*virtual*/S32 getHeight(S32 discard_level = -1) const;
|
||||
|
||||
virtual BOOL hasGLTexture() const = 0;
|
||||
virtual LLGLuint getTexName() const = 0;
|
||||
virtual BOOL createGLTexture() = 0;
|
||||
virtual BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0, BOOL to_create = TRUE, S32 category = LLGLTexture::OTHER) = 0;
|
||||
BOOL hasGLTexture() const ;
|
||||
LLGLuint getTexName() const ;
|
||||
BOOL createGLTexture() ;
|
||||
BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0, BOOL to_create = TRUE, S32 category = LLGLTexture::OTHER);
|
||||
|
||||
virtual void setFilteringOption(LLTexUnit::eTextureFilterOptions option) = 0;
|
||||
virtual void setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE) = 0;
|
||||
virtual void setAddressMode(LLTexUnit::eTextureAddressMode mode) = 0;
|
||||
virtual BOOL setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, bool fast_update = false) = 0;
|
||||
virtual BOOL setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height, bool fast_update = false) = 0;
|
||||
virtual void setGLTextureCreated (bool initialized) = 0;
|
||||
virtual void setCategory(S32 category) = 0;
|
||||
void setFilteringOption(LLTexUnit::eTextureFilterOptions option);
|
||||
void setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE);
|
||||
void setAddressMode(LLTexUnit::eTextureAddressMode mode);
|
||||
BOOL setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, bool fast_update = false);
|
||||
BOOL setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height, bool fast_update = false);
|
||||
void setGLTextureCreated (bool initialized);
|
||||
void setCategory(S32 category) ;
|
||||
|
||||
virtual LLTexUnit::eTextureAddressMode getAddressMode(void) const = 0;
|
||||
virtual S32 getMaxDiscardLevel() const = 0;
|
||||
virtual S32 getDiscardLevel() const = 0;
|
||||
virtual S8 getComponents() const = 0;
|
||||
virtual BOOL getBoundRecently() const = 0;
|
||||
virtual S32 getTextureMemory() const = 0;
|
||||
virtual LLGLenum getPrimaryFormat() const = 0;
|
||||
virtual BOOL getIsAlphaMask() const = 0;
|
||||
virtual LLTexUnit::eTextureType getTarget(void) const = 0;
|
||||
virtual BOOL getMask(const LLVector2 &tc) = 0;
|
||||
virtual F32 getTimePassedSinceLastBound() = 0;
|
||||
virtual BOOL getMissed() const = 0;
|
||||
virtual BOOL isJustBound()const = 0;
|
||||
virtual void forceUpdateBindStats(void) const = 0;
|
||||
LLTexUnit::eTextureAddressMode getAddressMode(void) const ;
|
||||
S32 getMaxDiscardLevel() const;
|
||||
S32 getDiscardLevel() const;
|
||||
S8 getComponents() const;
|
||||
BOOL getBoundRecently() const;
|
||||
S32 getTextureMemory() const ;
|
||||
LLGLenum getPrimaryFormat() const;
|
||||
BOOL getIsAlphaMask() const ;
|
||||
LLTexUnit::eTextureType getTarget(void) const ;
|
||||
BOOL getMask(const LLVector2 &tc);
|
||||
F32 getTimePassedSinceLastBound();
|
||||
BOOL getMissed() const ;
|
||||
BOOL isJustBound()const ;
|
||||
void forceUpdateBindStats(void) const;
|
||||
|
||||
//virtual U32 getTexelsInAtlas() const = 0;
|
||||
//virtual U32 getTexelsInGLTexture() const = 0;
|
||||
//virtual BOOL isGLTextureCreated() const = 0;
|
||||
//virtual S32 getDiscardLevelInAtlas() const = 0;
|
||||
/*U32 getTexelsInAtlas() const ;
|
||||
U32 getTexelsInGLTexture() const ;
|
||||
BOOL isGLTextureCreated() const ;
|
||||
S32 getDiscardLevelInAtlas() const ;*/
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//end of functions to access LLImageGL
|
||||
//---------------------------------------------------------------------------------------------
|
||||
|
||||
//-----------------
|
||||
//*virtual*/ void setActive() = 0;
|
||||
virtual void forceActive() = 0;
|
||||
virtual void setNoDelete() = 0;
|
||||
virtual void dontDiscard() = 0;
|
||||
virtual BOOL getDontDiscard() const = 0;
|
||||
/*virtual*/ void setActive() ;
|
||||
void forceActive() ;
|
||||
void setNoDelete() ;
|
||||
void dontDiscard() { mDontDiscard = 1; mTextureState = NO_DELETE; }
|
||||
BOOL getDontDiscard() const { return mDontDiscard; }
|
||||
//-----------------
|
||||
|
||||
private:
|
||||
virtual void cleanup() = 0;
|
||||
virtual void init(bool firstinit) = 0;
|
||||
void cleanup();
|
||||
void init();
|
||||
|
||||
protected:
|
||||
|
||||
virtual void setTexelsPerImage() = 0;
|
||||
void setTexelsPerImage();
|
||||
|
||||
//note: do not make this function public.
|
||||
//*virtual*/ LLImageGL* getGLTexture() const = 0;
|
||||
/*virtual*/ LLImageGL* getGLTexture() const ;
|
||||
|
||||
protected:
|
||||
S32 mBoostLevel; // enum describing priority level
|
||||
S32 mFullWidth;
|
||||
S32 mFullHeight;
|
||||
BOOL mUseMipMaps ;
|
||||
S8 mComponents;
|
||||
F32 mTexelsPerImage; // Texels per image.
|
||||
mutable S8 mNeedsGLTexture;
|
||||
|
||||
//GL texture
|
||||
LLPointer<LLImageGL> mGLTexturep ;
|
||||
S8 mDontDiscard; // Keep full res version of this image (for UI, etc)
|
||||
|
||||
protected:
|
||||
typedef enum
|
||||
@@ -175,6 +187,8 @@ protected:
|
||||
ACTIVE, //just being used, can become inactive if not being used for a certain time (10 seconds).
|
||||
NO_DELETE = 99 //stay in memory, can not be removed.
|
||||
} LLGLTextureState;
|
||||
LLGLTextureState mTextureState ;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
1624
indra/llrender/llrender2dutils.cpp
Normal file
1624
indra/llrender/llrender2dutils.cpp
Normal file
File diff suppressed because it is too large
Load Diff
164
indra/llrender/llrender2dutils.h
Normal file
164
indra/llrender/llrender2dutils.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* @file llrender2dutils.h
|
||||
* @brief GL function declarations for immediate-mode gl drawing.
|
||||
*
|
||||
* $LicenseInfo:firstyear=2012&license=viewerlgpl$
|
||||
* Second Life Viewer Source Code
|
||||
* Copyright (C) 2010, Linden Research, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
// All immediate-mode gl drawing should happen here.
|
||||
|
||||
|
||||
#ifndef LL_RENDER2DUTILS_H
|
||||
#define LL_RENDER2DUTILS_H
|
||||
|
||||
#include "llpointer.h" // LLPointer<>
|
||||
#include "llrect.h"
|
||||
#include "llglslshader.h"
|
||||
|
||||
class LLColor4;
|
||||
class LLVector3;
|
||||
class LLVector2;
|
||||
class LLUIImage;
|
||||
class LLUUID;
|
||||
|
||||
extern const LLColor4 UI_VERTEX_COLOR;
|
||||
|
||||
BOOL ui_point_in_rect(S32 x, S32 y, S32 left, S32 top, S32 right, S32 bottom);
|
||||
void gl_state_for_2d(S32 width, S32 height);
|
||||
|
||||
void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2);
|
||||
void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2, const LLColor4 &color );
|
||||
void gl_triangle_2d(S32 x1, S32 y1, S32 x2, S32 y2, S32 x3, S32 y3, const LLColor4& color, BOOL filled);
|
||||
void gl_rect_2d_simple( S32 width, S32 height );
|
||||
|
||||
void gl_draw_x(const LLRect& rect, const LLColor4& color);
|
||||
|
||||
void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, BOOL filled = TRUE );
|
||||
void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, BOOL filled = TRUE );
|
||||
void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, S32 pixel_offset = 0, BOOL filled = TRUE );
|
||||
void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, S32 pixel_offset = 0, BOOL filled = TRUE );
|
||||
void gl_rect_2d(const LLRect& rect, BOOL filled = TRUE );
|
||||
void gl_rect_2d(const LLRect& rect, const LLColor4& color, BOOL filled = TRUE );
|
||||
void gl_rect_2d_checkerboard(const LLRect& parent_screen_rect, const LLRect& rect, GLfloat alpha = 1.0f);
|
||||
|
||||
void gl_drop_shadow(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &start_color, S32 lines);
|
||||
|
||||
void gl_circle_2d(F32 x, F32 y, F32 radius, S32 steps, BOOL filled);
|
||||
void gl_arc_2d(F32 center_x, F32 center_y, F32 radius, S32 steps, BOOL filled, F32 start_angle, F32 end_angle);
|
||||
void gl_deep_circle( F32 radius, F32 depth );
|
||||
void gl_ring( F32 radius, F32 width, const LLColor4& center_color, const LLColor4& side_color, S32 steps, BOOL render_center );
|
||||
void gl_corners_2d(S32 left, S32 top, S32 right, S32 bottom, S32 length, F32 max_frac);
|
||||
void gl_washer_2d(F32 outer_radius, F32 inner_radius, S32 steps, const LLColor4& inner_color, const LLColor4& outer_color);
|
||||
void gl_washer_segment_2d(F32 outer_radius, F32 inner_radius, F32 start_radians, F32 end_radians, S32 steps, const LLColor4& inner_color, const LLColor4& outer_color);
|
||||
void gl_washer_spokes_2d(F32 outer_radius, F32 inner_radius, S32 count, const LLColor4& inner_color, const LLColor4& outer_color);
|
||||
void gl_draw_image(S32 x, S32 y, LLTexture* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
|
||||
void gl_draw_scaled_image(S32 x, S32 y, S32 width, S32 height, LLTexture* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
|
||||
void gl_draw_rotated_image(S32 x, S32 y, F32 degrees, LLTexture* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
|
||||
void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height, F32 degrees,LLTexture* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
|
||||
void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 border_width, S32 border_height, S32 width, S32 height, LLTexture* image, const LLColor4 &color, BOOL solid_color = FALSE, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
|
||||
void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 width, S32 height, LLTexture* image, const LLColor4 &color, BOOL solid_color = FALSE, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f), const LLRectf& scale_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
|
||||
|
||||
void gl_stippled_line_3d( const LLVector3& start, const LLVector3& end, const LLColor4& color, F32 phase = 0.f );
|
||||
|
||||
void gl_rect_2d_simple_tex( S32 width, S32 height );
|
||||
|
||||
// segmented rectangles
|
||||
|
||||
/*
|
||||
TL |______TOP_________| TR
|
||||
/| |\
|
||||
_/_|__________________|_\_
|
||||
L| | MIDDLE | |R
|
||||
_|_|__________________|_|_
|
||||
\ | BOTTOM | /
|
||||
BL\|__________________|/ BR
|
||||
| |
|
||||
*/
|
||||
|
||||
typedef enum e_rounded_edge
|
||||
{
|
||||
ROUNDED_RECT_LEFT = 0x1,
|
||||
ROUNDED_RECT_TOP = 0x2,
|
||||
ROUNDED_RECT_RIGHT = 0x4,
|
||||
ROUNDED_RECT_BOTTOM = 0x8,
|
||||
ROUNDED_RECT_ALL = 0xf
|
||||
}ERoundedEdge;
|
||||
|
||||
|
||||
void gl_segmented_rect_2d_tex(const S32 left, const S32 top, const S32 right, const S32 bottom, const S32 texture_width, const S32 texture_height, const S32 border_size, const U32 edges = ROUNDED_RECT_ALL);
|
||||
void gl_segmented_rect_2d_fragment_tex(const S32 left, const S32 top, const S32 right, const S32 bottom, const S32 texture_width, const S32 texture_height, const S32 border_size, const F32 start_fragment, const F32 end_fragment, const U32 edges = ROUNDED_RECT_ALL);
|
||||
void gl_segmented_rect_3d_tex(const LLVector2& border_scale, const LLVector3& border_width, const LLVector3& border_height, const LLVector3& width_vec, const LLVector3& height_vec, U32 edges = ROUNDED_RECT_ALL);
|
||||
void gl_segmented_rect_3d_tex_top(const LLVector2& border_scale, const LLVector3& border_width, const LLVector3& border_height, const LLVector3& width_vec, const LLVector3& height_vec);
|
||||
|
||||
inline void gl_rect_2d( const LLRect& rect, BOOL filled )
|
||||
{
|
||||
gl_rect_2d( rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, filled );
|
||||
}
|
||||
|
||||
inline void gl_rect_2d_offset_local( const LLRect& rect, S32 pixel_offset, BOOL filled)
|
||||
{
|
||||
gl_rect_2d_offset_local( rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, pixel_offset, filled );
|
||||
}
|
||||
|
||||
class LLImageProviderInterface;
|
||||
|
||||
class LLRender2D
|
||||
{
|
||||
LOG_CLASS(LLRender2D);
|
||||
public:
|
||||
static void initClass(LLImageProviderInterface* image_provider,
|
||||
const LLVector2* scale_factor);
|
||||
static void cleanupClass();
|
||||
|
||||
static void pushMatrix();
|
||||
static void popMatrix();
|
||||
static void loadIdentity();
|
||||
static void translate(F32 x, F32 y, F32 z = 0.0f);
|
||||
|
||||
static void setLineWidth(F32 width);
|
||||
static void setScaleFactor(const LLVector2& scale_factor);
|
||||
|
||||
static LLPointer<LLUIImage> getUIImageByID(const LLUUID& image_id, S32 priority = 0);
|
||||
static LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority = 0);
|
||||
|
||||
static LLVector2 sGLScaleFactor;
|
||||
private:
|
||||
static LLImageProviderInterface* sImageProvider;
|
||||
};
|
||||
|
||||
class LLImageProviderInterface
|
||||
{
|
||||
protected:
|
||||
LLImageProviderInterface() {};
|
||||
virtual ~LLImageProviderInterface() {};
|
||||
public:
|
||||
virtual LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority) = 0;
|
||||
virtual LLPointer<LLUIImage> getUIImageByID(const LLUUID& id, S32 priority) = 0;
|
||||
virtual void cleanUp() = 0;
|
||||
};
|
||||
|
||||
|
||||
extern LLGLSLShader gSolidColorProgram;
|
||||
extern LLGLSLShader gUIProgram;
|
||||
|
||||
#endif // LL_RENDER2DUTILS_H
|
||||
|
||||
154
indra/llrender/lluiimage.cpp
Normal file
154
indra/llrender/lluiimage.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* @file lluiimage.cpp
|
||||
* @brief UI implementation
|
||||
*
|
||||
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
|
||||
* Second Life Viewer Source Code
|
||||
* Copyright (C) 2010, Linden Research, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
// Utilities functions the user interface needs
|
||||
|
||||
//#include "llviewerprecompiledheaders.h"
|
||||
#include "linden_common.h"
|
||||
|
||||
// Project includes
|
||||
#include "lluiimage.h"
|
||||
#include "llrender2dutils.h"
|
||||
|
||||
LLUIImage::LLUIImage(const std::string& name, LLPointer<LLTexture> image)
|
||||
: mName(name),
|
||||
mImage(image),
|
||||
mScaleRegion(0.f, 1.f, 1.f, 0.f),
|
||||
mClipRegion(0.f, 1.f, 1.f, 0.f),
|
||||
mUniformScaling(TRUE),
|
||||
mNoClip(TRUE),
|
||||
mImageLoaded(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
LLUIImage::~LLUIImage()
|
||||
{
|
||||
delete mImageLoaded;
|
||||
}
|
||||
|
||||
void LLUIImage::setClipRegion(const LLRectf& region)
|
||||
{
|
||||
mClipRegion = region;
|
||||
mNoClip = mClipRegion.mLeft == 0.f
|
||||
&& mClipRegion.mRight == 1.f
|
||||
&& mClipRegion.mBottom == 0.f
|
||||
&& mClipRegion.mTop == 1.f;
|
||||
}
|
||||
|
||||
void LLUIImage::setScaleRegion(const LLRectf& region)
|
||||
{
|
||||
mScaleRegion = region;
|
||||
mUniformScaling = mScaleRegion.mLeft == 0.f
|
||||
&& mScaleRegion.mRight == 1.f
|
||||
&& mScaleRegion.mBottom == 0.f
|
||||
&& mScaleRegion.mTop == 1.f;
|
||||
}
|
||||
|
||||
//TODO: move drawing implementation inside class
|
||||
void LLUIImage::draw(S32 x, S32 y, const LLColor4& color) const
|
||||
{
|
||||
gl_draw_scaled_image(x, y, getWidth(), getHeight(), mImage, color, mClipRegion);
|
||||
}
|
||||
|
||||
void LLUIImage::draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const
|
||||
{
|
||||
if (mUniformScaling)
|
||||
{
|
||||
gl_draw_scaled_image(x, y, width, height, mImage, color, mClipRegion);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_draw_scaled_image_with_border(
|
||||
x, y,
|
||||
width, height,
|
||||
mImage,
|
||||
color,
|
||||
FALSE,
|
||||
mClipRegion,
|
||||
mScaleRegion);
|
||||
}
|
||||
}
|
||||
|
||||
void LLUIImage::drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const
|
||||
{
|
||||
gl_draw_scaled_image_with_border(
|
||||
x, y,
|
||||
width, height,
|
||||
mImage,
|
||||
color,
|
||||
TRUE,
|
||||
mClipRegion,
|
||||
mScaleRegion);
|
||||
}
|
||||
|
||||
void LLUIImage::drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const
|
||||
{
|
||||
LLRect border_rect;
|
||||
border_rect.setOriginAndSize(x, y, width, height);
|
||||
border_rect.stretch(border_width, border_width);
|
||||
drawSolid(border_rect, color);
|
||||
}
|
||||
|
||||
S32 LLUIImage::getWidth() const
|
||||
{
|
||||
// return clipped dimensions of actual image area
|
||||
return llround((F32)mImage->getWidth(0) * mClipRegion.getWidth());
|
||||
}
|
||||
|
||||
S32 LLUIImage::getHeight() const
|
||||
{
|
||||
// return clipped dimensions of actual image area
|
||||
return llround((F32)mImage->getHeight(0) * mClipRegion.getHeight());
|
||||
}
|
||||
|
||||
S32 LLUIImage::getTextureWidth() const
|
||||
{
|
||||
return mImage->getWidth(0);
|
||||
}
|
||||
|
||||
S32 LLUIImage::getTextureHeight() const
|
||||
{
|
||||
return mImage->getHeight(0);
|
||||
}
|
||||
|
||||
boost::signals2::connection LLUIImage::addLoadedCallback( const image_loaded_signal_t::slot_type& cb )
|
||||
{
|
||||
if (!mImageLoaded)
|
||||
{
|
||||
mImageLoaded = new image_loaded_signal_t();
|
||||
}
|
||||
return mImageLoaded->connect(cb);
|
||||
}
|
||||
|
||||
|
||||
void LLUIImage::onImageLoaded()
|
||||
{
|
||||
if (mImageLoaded)
|
||||
{
|
||||
(*mImageLoaded)();
|
||||
}
|
||||
}
|
||||
|
||||
93
indra/llrender/lluiimage.h
Normal file
93
indra/llrender/lluiimage.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @file lluiimage.h
|
||||
* @brief wrapper for images used in the UI that handles smart scaling, etc.
|
||||
*
|
||||
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
|
||||
* Second Life Viewer Source Code
|
||||
* Copyright (C) 2010, Linden Research, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation;
|
||||
* version 2.1 of the License only.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
|
||||
* $/LicenseInfo$
|
||||
*/
|
||||
|
||||
#ifndef LL_LLUIIMAGE_H
|
||||
#define LL_LLUIIMAGE_H
|
||||
|
||||
#include "v4color.h"
|
||||
#include "llpointer.h"
|
||||
#include "llrefcount.h"
|
||||
#include "llrefcount.h"
|
||||
#include "llrect.h"
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/signals2.hpp>
|
||||
#include "lltexture.h"
|
||||
|
||||
extern const LLColor4 UI_VERTEX_COLOR;
|
||||
|
||||
class LLUIImage : public LLRefCount
|
||||
{
|
||||
public:
|
||||
typedef boost::signals2::signal<void (void)> image_loaded_signal_t;
|
||||
|
||||
LLUIImage(const std::string& name, LLPointer<LLTexture> image);
|
||||
virtual ~LLUIImage();
|
||||
|
||||
void setClipRegion(const LLRectf& region);
|
||||
void setScaleRegion(const LLRectf& region);
|
||||
|
||||
LLPointer<LLTexture> getImage() { return mImage; }
|
||||
const LLPointer<LLTexture>& getImage() const { return mImage; }
|
||||
|
||||
void draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color = UI_VERTEX_COLOR) const;
|
||||
void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const;
|
||||
void draw(const LLRect& rect, const LLColor4& color = UI_VERTEX_COLOR) const { draw(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); }
|
||||
|
||||
void drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const;
|
||||
void drawSolid(const LLRect& rect, const LLColor4& color) const { drawSolid(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); }
|
||||
void drawSolid(S32 x, S32 y, const LLColor4& color) const { drawSolid(x, y, getWidth(), getHeight(), color); }
|
||||
|
||||
void drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const;
|
||||
void drawBorder(const LLRect& rect, const LLColor4& color, S32 border_width) const { drawBorder(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color, border_width); }
|
||||
void drawBorder(S32 x, S32 y, const LLColor4& color, S32 border_width) const { drawBorder(x, y, getWidth(), getHeight(), color, border_width); }
|
||||
|
||||
const std::string& getName() const { return mName; }
|
||||
|
||||
virtual S32 getWidth() const;
|
||||
virtual S32 getHeight() const;
|
||||
|
||||
// returns dimensions of underlying textures, which might not be equal to ui image portion
|
||||
S32 getTextureWidth() const;
|
||||
S32 getTextureHeight() const;
|
||||
|
||||
boost::signals2::connection addLoadedCallback( const image_loaded_signal_t::slot_type& cb );
|
||||
|
||||
void onImageLoaded();
|
||||
|
||||
protected:
|
||||
image_loaded_signal_t* mImageLoaded;
|
||||
|
||||
std::string mName;
|
||||
LLRectf mScaleRegion;
|
||||
LLRectf mClipRegion;
|
||||
LLPointer<LLTexture> mImage;
|
||||
BOOL mUniformScaling;
|
||||
BOOL mNoClip;
|
||||
};
|
||||
|
||||
|
||||
typedef LLPointer<LLUIImage> LLUIImagePtr;
|
||||
#endif
|
||||
Reference in New Issue
Block a user