diff options
author | Michael Pohoreski <ptolemy@lindenlab.com> | 2019-11-20 17:10:22 -0800 |
---|---|---|
committer | Michael Pohoreski <ptolemy@lindenlab.com> | 2019-11-20 17:10:22 -0800 |
commit | 4b205db468fd371dfe1bb30bb887e2ccbd7044ec (patch) | |
tree | 6d83efd5ebc0c2a462f33f1b385c5b415a93cb49 /indra/llrender | |
parent | 18eb8ac90ce409ba620f6fe8ff487e6195d9c3eb (diff) | |
parent | 24920de799c8e2dd26854923c7a10fc4a551dd5d (diff) |
Merged lindenlab/viewer-eep into default
Diffstat (limited to 'indra/llrender')
-rw-r--r-- | indra/llrender/llrender2dutils.cpp | 93 | ||||
-rw-r--r-- | indra/llrender/llrender2dutils.h | 45 | ||||
-rw-r--r-- | indra/llrender/lluiimage.cpp | 12 |
3 files changed, 98 insertions, 52 deletions
diff --git a/indra/llrender/llrender2dutils.cpp b/indra/llrender/llrender2dutils.cpp index 4e2ebfd51e..4eb0203245 100644 --- a/indra/llrender/llrender2dutils.cpp +++ b/indra/llrender/llrender2dutils.cpp @@ -46,8 +46,6 @@ // Globals // const LLColor4 UI_VERTEX_COLOR(1.f, 1.f, 1.f, 1.f); -/*static*/ LLVector2 LLRender2D::sGLScaleFactor(1.f, 1.f); -/*static*/ LLImageProviderInterface* LLRender2D::sImageProvider = NULL; // // Functions @@ -108,10 +106,11 @@ void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, S32 pixe top += LLFontGL::sCurOrigin.mY; gGL.loadUIIdentity(); - gl_rect_2d(llfloor((F32)left * LLRender2D::sGLScaleFactor.mV[VX]) - pixel_offset, - llfloor((F32)top * LLRender2D::sGLScaleFactor.mV[VY]) + pixel_offset, - llfloor((F32)right * LLRender2D::sGLScaleFactor.mV[VX]) + pixel_offset, - llfloor((F32)bottom * LLRender2D::sGLScaleFactor.mV[VY]) - pixel_offset, + LLRender2D *r2d_inst = LLRender2D::getInstance(); + gl_rect_2d(llfloor((F32)left * r2d_inst->mGLScaleFactor.mV[VX]) - pixel_offset, + llfloor((F32)top * r2d_inst->mGLScaleFactor.mV[VY]) + pixel_offset, + llfloor((F32)right * r2d_inst->mGLScaleFactor.mV[VX]) + pixel_offset, + llfloor((F32)bottom * r2d_inst->mGLScaleFactor.mV[VY]) - pixel_offset, filled); gGL.popUIMatrix(); } @@ -800,7 +799,7 @@ void gl_stippled_line_3d( const LLVector3& start, const LLVector3& end, const LL } gGL.end(); - LLRender2D::setLineWidth(1.f); + LLRender2D::getInstance()->setLineWidth(1.f); } void gl_arc_2d(F32 center_x, F32 center_y, F32 radius, S32 steps, BOOL filled, F32 start_angle, F32 end_angle) @@ -967,7 +966,7 @@ void gl_rect_2d_checkerboard(const LLRect& rect, GLfloat alpha) } else { //polygon stipple is deprecated, use "Checker" texture - LLPointer<LLUIImage> img = LLRender2D::getUIImage("Checker"); + LLPointer<LLUIImage> img = LLRender2D::getInstance()->getUIImage("Checker"); gGL.getTexUnit(0)->bind(img->getImage()); gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_WRAP); gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); @@ -1567,25 +1566,26 @@ void gl_segmented_rect_3d_tex(const LLRectf& clip_rect, const LLRectf& center_uv } -// static -void LLRender2D::initClass(LLImageProviderInterface* image_provider, - const LLVector2* scale_factor) +LLRender2D::LLRender2D(LLImageProviderInterface* image_provider) { - sGLScaleFactor = (scale_factor == NULL) ? LLVector2(1.f, 1.f) : *scale_factor; - sImageProvider = image_provider; + mGLScaleFactor = LLVector2(1.f, 1.f); + mImageProvider = image_provider; + if(mImageProvider) + { + mImageProvider->addOnRemovalCallback(resetProvider); + } } -// static -void LLRender2D::cleanupClass() +LLRender2D::~LLRender2D() { - if(sImageProvider) + if(mImageProvider) { - sImageProvider->cleanUp(); + mImageProvider->cleanUp(); + mImageProvider->deleteOnRemovalCallback(resetProvider); } } -//static void LLRender2D::translate(F32 x, F32 y, F32 z) { gGL.translateUI(x,y,z); @@ -1594,14 +1594,12 @@ void LLRender2D::translate(F32 x, F32 y, F32 z) LLFontGL::sCurDepth += z; } -//static void LLRender2D::pushMatrix() { gGL.pushUIMatrix(); LLFontGL::sOriginStack.push_back(std::make_pair(LLFontGL::sCurOrigin, LLFontGL::sCurDepth)); } -//static void LLRender2D::popMatrix() { gGL.popUIMatrix(); @@ -1610,7 +1608,6 @@ void LLRender2D::popMatrix() LLFontGL::sOriginStack.pop_back(); } -//static void LLRender2D::loadIdentity() { gGL.loadUIIdentity(); @@ -1619,25 +1616,22 @@ void LLRender2D::loadIdentity() LLFontGL::sCurDepth = 0.f; } -//static void LLRender2D::setScaleFactor(const LLVector2 &scale_factor) { - sGLScaleFactor = scale_factor; + mGLScaleFactor = scale_factor; } -//static void LLRender2D::setLineWidth(F32 width) { gGL.flush(); - glLineWidth(width * lerp(sGLScaleFactor.mV[VX], sGLScaleFactor.mV[VY], 0.5f)); + glLineWidth(width * lerp(mGLScaleFactor.mV[VX], mGLScaleFactor.mV[VY], 0.5f)); } -//static LLPointer<LLUIImage> LLRender2D::getUIImageByID(const LLUUID& image_id, S32 priority) { - if (sImageProvider) + if (mImageProvider) { - return sImageProvider->getUIImageByID(image_id, priority); + return mImageProvider->getUIImageByID(image_id, priority); } else { @@ -1645,12 +1639,49 @@ LLPointer<LLUIImage> LLRender2D::getUIImageByID(const LLUUID& image_id, S32 prio } } -//static LLPointer<LLUIImage> LLRender2D::getUIImage(const std::string& name, S32 priority) { - if (!name.empty() && sImageProvider) - return sImageProvider->getUIImage(name, priority); + if (!name.empty() && mImageProvider) + return mImageProvider->getUIImage(name, priority); else return NULL; } +// static +void LLRender2D::resetProvider() +{ + if (LLRender2D::instanceExists) + { + LLRender2D::getInstance()->mImageProvider = NULL; + } +} + +// class LLImageProviderInterface + +LLImageProviderInterface::~LLImageProviderInterface() +{ + for (callback_list_t::iterator iter = mCallbackList.begin(); iter != mCallbackList.end();) + { + callback_list_t::iterator curiter = iter++; + (*curiter)(); + } +} + +void LLImageProviderInterface::addOnRemovalCallback(callback_t func) +{ + if (!func) + { + return; + } + mCallbackList.push_back(func); +} + +void LLImageProviderInterface::deleteOnRemovalCallback(callback_t func) +{ + callback_list_t::iterator iter = std::find(mCallbackList.begin(), mCallbackList.end(), func); + if (iter != mCallbackList.end()) + { + mCallbackList.erase(iter); + } +} + diff --git a/indra/llrender/llrender2dutils.h b/indra/llrender/llrender2dutils.h index cce3b4ed51..70ab006fd6 100644 --- a/indra/llrender/llrender2dutils.h +++ b/indra/llrender/llrender2dutils.h @@ -121,39 +121,54 @@ inline void gl_rect_2d_offset_local( const LLRect& rect, S32 pixel_offset, BOOL class LLImageProviderInterface; -class LLRender2D +class LLRender2D : public LLParamSingleton<LLRender2D> { + LLSINGLETON(LLRender2D, LLImageProviderInterface* image_provider); LOG_CLASS(LLRender2D); + ~LLRender2D(); public: - static void initClass(LLImageProviderInterface* image_provider, - const LLVector2* scale_factor); - static void cleanupClass(); + void pushMatrix(); + void popMatrix(); + void loadIdentity(); + void translate(F32 x, F32 y, F32 z = 0.0f); - static void pushMatrix(); - static void popMatrix(); - static void loadIdentity(); - static void translate(F32 x, F32 y, F32 z = 0.0f); + void setLineWidth(F32 width); + void setScaleFactor(const LLVector2& scale_factor); - static void setLineWidth(F32 width); - static void setScaleFactor(const LLVector2& scale_factor); + LLPointer<LLUIImage> getUIImageByID(const LLUUID& image_id, S32 priority = 0); + LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority = 0); - static LLPointer<LLUIImage> getUIImageByID(const LLUUID& image_id, S32 priority = 0); - static LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority = 0); + LLVector2 mGLScaleFactor; + +protected: + // since LLRender2D has no control of image provider's lifecycle + // we need a way to tell LLRender2D that provider died and + // LLRender2D needs to be updated. + static void resetProvider(); - static LLVector2 sGLScaleFactor; private: - static LLImageProviderInterface* sImageProvider; + LLImageProviderInterface* mImageProvider; }; class LLImageProviderInterface { protected: LLImageProviderInterface() {}; - virtual ~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; + + // to notify holders when pointer gets deleted + typedef void(*callback_t)(); + void addOnRemovalCallback(callback_t func); + void deleteOnRemovalCallback(callback_t func); + +private: + + typedef std::list< callback_t > callback_list_t; + callback_list_t mCallbackList; }; diff --git a/indra/llrender/lluiimage.cpp b/indra/llrender/lluiimage.cpp index db69806097..424672fe8e 100644 --- a/indra/llrender/lluiimage.cpp +++ b/indra/llrender/lluiimage.cpp @@ -81,12 +81,12 @@ void LLUIImage::draw3D(const LLVector3& origin_agent, const LLVector3& x_axis, c } } - LLRender2D::pushMatrix(); + LLRender2D::getInstance()->pushMatrix(); { LLVector3 rect_origin = origin_agent + (rect.mLeft * x_axis) + (rect.mBottom * y_axis); - LLRender2D::translate(rect_origin.mV[VX], - rect_origin.mV[VY], - rect_origin.mV[VZ]); + LLRender2D::getInstance()->translate(rect_origin.mV[VX], + rect_origin.mV[VY], + rect_origin.mV[VZ]); gGL.getTexUnit(0)->bind(getImage()); gGL.color4fv(color.mV); @@ -103,7 +103,7 @@ void LLUIImage::draw3D(const LLVector3& origin_agent, const LLVector3& x_axis, c rect.getWidth() * x_axis, rect.getHeight() * y_axis); - } LLRender2D::popMatrix(); + } LLRender2D::getInstance()->popMatrix(); } //#include "lluiimage.inl" @@ -138,7 +138,7 @@ namespace LLInitParam return; } - LLUIImage* imagep = LLRender2D::getUIImage(name()); + LLUIImage* imagep = LLRender2D::getInstance()->getUIImage(name()); if (imagep) { updateValue(imagep); |