Subversion

gpucv

[/] [experimental/] [trunk/] [gpucv/] [src/] [lib/] [GPUCVTexture/] [DataDsc_GLTex.cpp] - Rev 271 Go to most recent revision

Compare with Previous - Blame


#include <GPUCVTexture/TextureRecycler.h>
#include <GPUCVTexture/Texture.h>
#include "GPUCVTexture/TextureRenderManager.h"

#include <GPUCVTexture/DataDsc_GLTex.h>
#include <GPUCVTexture/DataDsc_GLBuff.h>
#include <GPUCVTexture/DataDsc_CPU.h>

//==================================================
DataDsc_GLTex::DataDsc_GLTex()
        : DataDsc_Base("DataDsc_GLTex")
        ,m_textureId(0)
    ,m_textureId_ARB(0)
        ,m_textureAttachedID(NO_ATTACHEMENT)
    ,m_textureType(GetHardProfile()->GetTextType())
    ,m_internalFormat(-1)
        ,m_needReload(true)
        ,m_texCoord(NULL)
        ,m_autoMipMap(false)
{
}
//==================================================
DataDsc_GLTex::~DataDsc_GLTex(void)
{
        Free();
}
//==================================================
/*virtual*/
DataDsc_Base * DataDsc_GLTex::CloneToNew(bool _datatransfer/*=true*/)
{
        DataDsc_GLTex * TempTex = new DataDsc_GLTex();
        return TempTex->Clone(this,_datatransfer);
}
//==================================================
/*virtual*/
DataDsc_GLTex*	DataDsc_GLTex::Clone(DataDsc_GLTex* _source, bool _datatransfer/*=true*/)
{
        CLASS_FCT_SET_NAME("Clone");
        CLASS_FCT_PROF_CREATE_START();
        CLASS_DEBUG("");
        _GPUCV_GL_ERROR_TEST();

        DataDsc_Base::Clone(_source, _datatransfer);
        //don't copy texture ID, we create a new one.
        m_textureId_ARB = _source->m_textureId_ARB;
        m_textureAttachedID = _source->m_textureAttachedID;
        m_textureType = _source->m_textureType;
        m_internalFormat = _source->m_internalFormat;
        m_autoMipMap = _source->m_autoMipMap;
        _SetTextCoord(_source->_GetTextCoord());

        //
        Free();
        Allocate();
        if(_datatransfer)
        {
                SetRenderToTexture();
                InitGLView();
                        _source->DrawFullQuad(_source->_GetWidth(), _source->_GetHeight());
                UnsetRenderToTexture();
                _GPUCV_GL_ERROR_TEST();
                SetDataFlag(true);
        }
        
        return this;
}
//==================================================
/*virtual*/
bool DataDsc_GLTex::CopyTo(DataDsc_Base* _destination, bool _datatransfer/*=true*/)
{
        CLASS_FCT_SET_NAME_TPL_STR(_destination->GetDscType(),"CopyTo");
        TEXTUREDESC_COPY_START(_destination,_datatransfer);
        _GPUCV_GL_ERROR_TEST();

        //copy to texture
                DataDsc_GLTex * TempGL = dynamic_cast<DataDsc_GLTex *>(_destination);
                if(TempGL)
                {//clone texture
                        return TempGL->Clone(this, _datatransfer);
                }
        //====================

        //copy to a GL_BUFFER
                DataDsc_GLBuff * TempGLbuff = dynamic_cast<DataDsc_GLBuff *>(_destination);
                if(TempGLbuff)
                {//
                        CLASS_DEBUG("");
                        TempGLbuff->TransferFormat(this);
                        TempGLbuff->_SetType(DataDsc_GLBuff::PIXEL_PACK_BUFFER);
                        //buffer will be used inside OpenGL
                        TempGLbuff->_SetTransferMode(DataDsc_GLBuff::DYNAMIC_COPY);
                        TempGLbuff->Allocate();
                        TempGLbuff->_Bind();
                        TempGLbuff->_Writedata(NULL, GetDataSize(), false);
                        TempGLbuff->_UnBind();
                        if(_datatransfer && this->HaveData())
                        {
                                _GPUCV_GL_ERROR_TEST();
                                _Bind();
                                        TempGLbuff->_Bind();
                                                glGetTexImage(_GetTexType(), 0, GetPixelFormat(), GetPixelType(), NULL);
                                        TempGLbuff->_UnBind();
                                _UnBind();
                                _GPUCV_GL_ERROR_TEST();
                        }
                        return true;
                }
        //====================

        //copy to CPU
                DataDsc_CPU * TempCPU = dynamic_cast<DataDsc_CPU *>(_destination);
                if(TempCPU)
                {//read data back to CPU
                        TempCPU->Allocate();
                        if(HaveData() && _datatransfer)
                        {
                                CLASS_DEBUG("");
                                _ReadData(TempCPU->_GetPixelsData());
                                TempCPU->SetDataFlag(true);
                                return true;
                        }
                }
        //====================


        //don't know how to copy...must be done in another object

        return false;
}
//==================================================
/*virtual*/
bool DataDsc_GLTex::CopyFrom(DataDsc_Base* _source, bool _datatransfer/*=true*/)
{
        CLASS_FCT_SET_NAME_TPL_STR(_source->GetDscType(),"CopyTo");
        TEXTUREDESC_COPY_START(_source,_datatransfer);
        _GPUCV_GL_ERROR_TEST();

        //copy from texture
                DataDsc_GLTex * TempGL = dynamic_cast<DataDsc_GLTex *>(_source);
                if(TempGL)
                {//clone texture
                        Allocate();
                        return Clone(TempGL, _datatransfer);			
                }
        //====================

        //copy from a GL_BUFFER
                DataDsc_GLBuff * TempGLbuff = dynamic_cast<DataDsc_GLBuff *>(_source);
                if(TempGLbuff)
                {//
                        CLASS_DEBUG("");
                        TransferFormat(TempGLbuff);
                        Allocate();
                        if(_datatransfer && TempGLbuff->HaveData())
                        {
                                _GPUCV_GL_ERROR_TEST();
                                SetRenderToTexture();
                                        InitGLView();
                                        //glClearColor(1.,0.,1.,0.);
                                        //glClear(GL_COLOR_BUFFER_BIT);
                                        //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
                                        //glDisable( GL_DEPTH_TEST);
                                        TempGLbuff->_Bind();
                                        glCopyPixels(0,0, _GetWidth(), _GetHeight(), GL_COLOR);
                                        TempGLbuff->_UnBind();
                                        _GPUCV_GL_ERROR_TEST();
                                UnsetRenderToTexture();
                        }
                        return true;
                }
        //====================

        //copy from CPU => load data into texture
                DataDsc_CPU * TempCPU = dynamic_cast<DataDsc_CPU *>(_source);
                if(TempCPU)
                {
                        TransferFormat(_source);
                        Allocate();	
                        CLASS_DEBUG("");
                        _Writedata((const PIXEL_STORAGE_TYPE **)TempCPU->_GetPixelsData(), _datatransfer);
                        return true;
                }
        //====================


        //don't know how to copy...must be done in another object
        return false;
}
//==================================================
/*virtual*/
void DataDsc_GLTex::Allocate(void)
{
        CLASS_FCT_SET_NAME("Allocate");
        CLASS_FCT_PROF_CREATE_START();
        
        if(_GetReloadFlag() || !IsAllocated())
        {
                CLASS_DEBUG("");
                _GPUCV_GL_ERROR_TEST();
                m_textureId = TextureRecycler::GetNewTexture();
                CLASS_ASSERT(m_textureId, "DataDsc_GLTex::Allocate()=> Allocation failed");
                //if(GetParent()->GetOption(DataContainer::DEST_IMG))
                        //allocate with empty data
                        _Writedata(NULL, false);
                //else
                //	_Writedata(_data, true);
                _Bind();
                _SetTexParami(GL_TEXTURE_MIN_FILTER,GL_NEAREST);
                _SetTexParami(GL_TEXTURE_MAG_FILTER,GL_NEAREST);	
                _SetTexParami( GL_TEXTURE_WRAP_S,GL_CLAMP);	
                _SetTexParami( GL_TEXTURE_WRAP_T,GL_CLAMP);	
                _SetReloadFlag(false);
                _GPUCV_GL_ERROR_TEST();
                        
                //GPUCVTEXTURE_DEBUG(this, GetValStr() << "::DataDsc_GLTex::_CreateLocation("<< GetTextureLocationStr(LOC_GPU)<<")");
        }
}

//==================================================
/*virtual*/
void DataDsc_GLTex::Free()
{
        CLASS_FCT_SET_NAME("Free");
        CLASS_FCT_PROF_CREATE_START();
        _SetReloadFlag(true);//must be reloaded if we want to use it
        if(IsAllocated())
        {
                _GPUCV_GL_ERROR_TEST();
                CLASS_DEBUG("");
                TextureRecycler::AddFreeTexture(m_textureId);
                m_textureId = 0;
                DataDsc_Base::Free();
                _GPUCV_GL_ERROR_TEST();
        }
}
//==================================================
/*virtual*/
bool DataDsc_GLTex::IsAllocated()const
{
        if(!_GetReloadFlag() || _GetId())
                return true;
        else
                return false;
}
//==================================================
/*virtual*/
void DataDsc_GLTex::SetFormat(const GLuint _pixelFormat,const GLuint _pixelType)
{
        if((m_glPixelFormat	!= _pixelFormat) 
                || (m_glPixelType	!= _pixelType))
                        _SetReloadFlag(true);


        DataDsc_Base::SetFormat(_pixelFormat,_pixelType);
        _SetInternalPixelFormat(ProcessingGPU()->ConvertGLFormatToInternalFormat(_pixelFormat, _pixelType));
}
//==================================================
/*static virtual*/
void DataDsc_GLTex::ConvertPixelFormat_GLToLocal(const GLuint _pixelFormat)
{
        //m_glPixelFormat = _pixelFormat;
}
//==================================================
/*static virtual*/
GLuint	DataDsc_GLTex::ConvertPixelFormat_LocalToGL(void)
{
        return m_glPixelFormat;
}
//==================================================
/*static virtual*/
void	DataDsc_GLTex::ConvertPixelType_GLToLocal(const GLuint _pixelType)
{
        m_glPixelType = _pixelType;
}
//==================================================
/*static virtual*/
GLuint	DataDsc_GLTex::ConvertPixelType_LocalToGL(void)
{
        return m_glPixelType;
}
//==================================================


//==================================================
//==================================================
//Local functions
//==================================================
//==================================================
/*virtual*/
void DataDsc_GLTex::_Bind(void)
{
        _GPUCV_GL_ERROR_TEST();
        if(m_needReload)//need to be reloaded
        {
        //	CLASS_WARNING(this, GetValStr() + std::string("DataDsc_GLTex::Bind() => m_needReload to 1, need to be reloaded before binding"));
        }
        if(!m_textureId)
        {
        //	CLASS_WARNING(this, GetValStr() + "DataDsc_GLTex::Bind() => no texture ID");
        }
        glEnable(m_textureType);
        glBindTexture(m_textureType, m_textureId);
        _GPUCV_GL_ERROR_TEST();
}
//==================================================
/*virtual*/
void DataDsc_GLTex::_UnBind(void)
{
                glBindTexture(m_textureType, 0);
}
//========================================================
void DataDsc_GLTex::_BindARB()
{
                //_GPUCVTEXTURE_GL_ERROR_TEST(this);
                if(!_GetARBId())//need to be reloaded
                {
                        //CLASS_WARNING("DataDsc_GLTex::BindARB() => no ARB texture ID");
                }
                _GPUCV_GL_ERROR_TEST();
                glActiveTextureARB(_GetARBId());
            _Bind();
                _GPUCV_GL_ERROR_TEST();
}
//========================================================
void DataDsc_GLTex::_UnBindARB()
{
        glActiveTextureARB(_GetARBId());
        _UnBind();
}

//==================================================
void	DataDsc_GLTex::_SetInternalPixelFormat(const GLuint _internalPixelFormat)
{
        if(m_internalFormat != _internalPixelFormat)
                _SetReloadFlag(true);
        m_internalFormat = _internalPixelFormat;
}
//==================================================
GLuint	DataDsc_GLTex::_GetInternalPixelFormat()const
{
        return m_internalFormat;
}
//==================================================
void DataDsc_GLTex::_SetColorAttachment(attachmentEXT _clr)
{
        m_textureAttachedID = _clr;
}
//========================================================
DataDsc_GLTex::attachmentEXT DataDsc_GLTex::_GetColorAttachment()const
{
        return m_textureAttachedID;
}
GLuint  DataDsc_GLTex::_GetARBId()const
{	
        return m_textureId_ARB;
}
//========================================================
void DataDsc_GLTex::_SetARBId(GLuint _texARBID)
{	
        m_textureId_ARB = _texARBID;
}
//========================================================
GLuint  DataDsc_GLTex::_GetId()const
{
        return m_textureId;
}
//========================================================
void DataDsc_GLTex::_SetId(GLuint _texID)
{
        m_textureId = _texID;
}
//========================================================
GLuint DataDsc_GLTex::_GetTexType()const
{
        return m_textureType;
}
//========================================================
void DataDsc_GLTex::_SetTexType(GLuint _TexType)
{
        m_textureType = _TexType;
}
//========================================================
void DataDsc_GLTex::_SetTexParami(GLuint _ParamType, GLint _Value)
{
#if _GPUCV_DEBUG_MODE
        CLASS_FCT_SET_NAME("_SetTexParami");
        //test value...
        switch(_ParamType)
        {
                case GL_TEXTURE_MIN_FILTER:
                case GL_TEXTURE_MAG_FILTER:
                case GL_TEXTURE_WRAP_S:
                case GL_TEXTURE_WRAP_T:
                case GL_TEXTURE_BORDER_COLOR:
                case GL_TEXTURE_PRIORITY:
                        break;
                default:
                        CLASS_DEBUG("Unknown param");
                        return;
        }
#endif
        glTexParameteri(m_textureType, _ParamType , _Value);
}
//========================================================
void DataDsc_GLTex::_GetTexParami(GLuint _ParamType, GLint *_Value)
{
#if _GPUCV_DEBUG_MODE
        CLASS_FCT_SET_NAME("_GetTexParami");
        switch(_ParamType)
        {
                case GL_TEXTURE_MIN_FILTER:
                case GL_TEXTURE_MAG_FILTER:
                case GL_TEXTURE_WRAP_S:
                case GL_TEXTURE_WRAP_T:
                case GL_TEXTURE_BORDER_COLOR:
                case GL_TEXTURE_PRIORITY:
                        break;
                default:
                        CLASS_DEBUG("Unknown param");
                        return;
        }
#endif
        glGetTexParameteriv(m_textureType, _ParamType, _Value);
}
//========================================================
void DataDsc_GLTex::_Writedata(const PIXEL_STORAGE_TYPE ** _data, const bool _dataTransfer/*=true*/)
{
        CLASS_FCT_SET_NAME("_Writedata");
        CLASS_FCT_PROF_CREATE_START();

        _GPUCV_GL_ERROR_TEST();
        
        if(_dataTransfer && !_data)
        {
                CLASS_WARNING("No texture data to transfer");
        }
        //TextSize<GLsizei> * TempSize = dynamic_cast<TextSize<GLsizei> *>(GetParent());

        //check properties
        CLASS_ASSERT(m_textureType>0, "Unknown texture type");
        CLASS_ASSERT(m_internalFormat>0, "Unknown internal format");
        CLASS_ASSERT(_GetHeight()*_GetWidth()>0, "Null size");
        CLASS_ASSERT(m_glPixelFormat>0, "Unknown pixel format");
        CLASS_ASSERT(m_glPixelType>0, "Unknown pixel type");

        _GPUCV_GL_ERROR_TEST();
                m_needReload = false;//no need anymore to reload
                _Bind();
                
                const PIXEL_STORAGE_TYPE * CurrData = (_dataTransfer)? *_data:NULL;
#if _GPUCV_GL_USE_MIPMAPING
                if(GetParent())
                        if(GetParent()->GetOption(DataContainer::DEST_IMG))
                                CurrData = NULL;//no data transfer if destination image.
                
                if(m_autoMipMap)
                {//generate mipmaps
                        if(MainGPU()->m_glExtension.GetSGISTextureLOD())
                        {//hardware compatible : http://www.nvidia.com/dev_content/nvopenglspecs/GL_SGIS_generate_mipmap.txt
                                _SetTexParami(GL_GENERATE_MIPMAP_SGIS, true);
                                glTexImage2D (m_textureType, 0,
                                        m_internalFormat, 
                                        _GetWidth(),_GetHeight(),
                                        0,
                                        m_glPixelFormat,m_glPixelType, CurrData);
                        }
                        else
                        {
                                if (gluBuild2DMipmaps(m_textureType, 
                                        _GetInternalPixelFormat(),
                                        _GetWidth(),_GetHeight(),
                                        m_glPixelFormat,
                                        m_glPixelType,
                                        CurrData) !=0)//build it
                                {
                                        GPUCV_ERROR("Error while generating MipMap");
                                }
                                glGenerateMipmapEXT(m_textureType);
                        }
                        _SetTexParami(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);//set filter settings
                }
                else
#endif
                {
                        CLASS_DEBUG(*this);
                        glTexImage2D (m_textureType, 0,
                                        m_internalFormat, 
                                        _GetWidth(),_GetHeight(),
                                        0,
                                        m_glPixelFormat,m_glPixelType, CurrData);
                }

#if 0//__GPUTEXTURE_DEBUG_IMG_TRANSFER
                GPUCV_LOCAL_DEBUG(GetValStr()<< "\n\t" << "TRANSFER: " << 
                                GetTextureLocationStr(LOC_CPU) <<
                                " ==> " <<
                                GetTextureLocationStr(LOC_GPU) <<
                                " (data transfer request=" 
                                << _dataTransfer 
                                << ", data transfered=" 
                                << std::string((CurrData)? "true": "false")
                                << std::string("), glTexImage2D()")
                                );
#endif
        _UnBind();
        m_needReload =false;//must be set again to false. because of _SetPixelsData that set it true.
        _GPUCV_GL_ERROR_TEST();
}
//=================================================================
PIXEL_STORAGE_TYPE ** 
DataDsc_GLTex::_ReadData(PIXEL_STORAGE_TYPE **_Pixelsdata, GLuint _xmin/*=0*/, GLuint _xmax/*=0*/, GLuint _ymin/*=0*/, GLuint _ymax/*=0*/)
{
        CLASS_FCT_SET_NAME("_ReadData");
        CLASS_FCT_PROF_CREATE_START();
        CLASS_ASSERT(_Pixelsdata, "No memory allocated to read pixels");
        CLASS_ASSERT(*_Pixelsdata, "No memory allocated to read pixels");

        _GPUCV_GL_ERROR_TEST();
        //GLuint xmin = 0;//_xmin;
        GLuint xmax = (_xmax)?_xmax:_GetWidth();
        //GLuint ymin = 0;//_ymin
        GLuint ymax = (_ymax)?_ymax:_GetHeight();

        //_GPUCVTEXTURE_GL_ERROR_TEST(this);

        bool RenderBufferBinded = true;//RenderBufferManager()->IsTextureBinded(this);

        if(!RenderBufferBinded)
        {
                SetRenderToTexture();// RenderBufferManager()->SetContext(this);
                // if FBO are compatible, the filter result is set in the texture as well as in the FBO
                // then we only need to read those informations
                // else we have to show this image on a quad to be able to read its data

                if (RenderBufferManager()->GetType()== TextureRenderBuffer::RENDER_OBJ_PBUFF)
                {
                        //TextSize<GLsizei> textureSize(xmax, ymax);
                        InitGLView();
                        DrawFullQuad(xmax, ymax);
                }
        }
        else
        {
                _Bind();
        }
                CLASS_DEBUG(*this);
                glGetTexImage(_GetTexType(), 0, GetPixelFormat(), GetPixelType(), *_Pixelsdata);
                _UnBind();

        if(!RenderBufferBinded)
                UnsetRenderToTexture();//RenderBufferManager()->UnSetContext();
        //else
                
                        
        //_GPUCVTEXTURE_GL_ERROR_TEST(this);
        _GPUCV_GL_ERROR_TEST();
          return _Pixelsdata;
}
//=================================================================
void DataDsc_GLTex::_GlMultiTexCoordARB(GLuint _coordID)
{
        CLASS_ASSERT(_GetTextCoord(), "DataContainer::_GlMultiTexCoordARB()=> Trying to use multitexture coordonate without local texture coordonnate");
        _GetTextCoord()->glMultiTexCoordARB(m_textureId_ARB, _coordID);
}

//=================================================================
void DataDsc_GLTex::DrawFullQuad(const int _width, const int _height)
{
        CLASS_FCT_SET_NAME("DrawFullQuad");
        //_GPUCVTEXTURE_GL_ERROR_TEST(_Tex);
        glPushMatrix();
    glColor4f(1., 1., 1., 1.);
        if(HaveData())
                _Bind();
        else
        {
                CLASS_ERROR("Drawing a quad with empty data?");
        }

    glBegin(GL_QUADS);
        {
                //the difference between GL_TEXTURE_2D and GL_TEXTURE_RECTANGLE_ARB has been managed into the texture coordonnate system of the texture.
                        if (_GetTexType() ==  GL_TEXTURE_2D || _GetTexType() ==  GL_TEXTURE_RECTANGLE_ARB)
                        {
                                TextCoord<double> * Coord = _GetTextCoord();
                                if(!Coord)
                                {
                                        Coord = &TextCoord<double>();
                                        if(_GetTexType() ==  GL_TEXTURE_RECTANGLE_ARB)
                                        {
                                                TextCoord<double>::TplVector2D TempScale(_GetWidth(), _GetHeight());
                                                Coord->Scale(TempScale);
                                        }
                                }
                                Coord->glTexCoord(0); glVertex3fv(&GPUCVDftQuadVertexes[0]);
                                Coord->glTexCoord(1); glVertex3fv(&GPUCVDftQuadVertexes[3]);
                                Coord->glTexCoord(2); glVertex3fv(&GPUCVDftQuadVertexes[6]);
                                Coord->glTexCoord(3); glVertex3fv(&GPUCVDftQuadVertexes[9]);
                        }
                        else
                        {
                                CLASS_ASSERT(0, "Unknown texture type:");
                                //Print();
                        }		
        }
    glEnd();
        glPopMatrix();
        if(HaveData())
                _UnBind();
        //_GPUCVTEXTURE_GL_ERROR_TEST(_Tex);
}
//=================================================================
void DataDsc_GLTex::DrawFullQuad(float centerX, float centerY, float scaleX, float scaleY, float width, float height)
{
        glPushMatrix();
        glTranslatef(centerX, centerY, 0.);
        glScalef(scaleX, scaleY, 1.);
        DrawFullQuad((int) width, (int) height);
        glPopMatrix();
}
//=================================================================
void DataDsc_GLTex::InitGLView()
{
        TexCoordType * CurTexCoord = _GetTextCoord();
        //Is specific Text coordonnates set?
        if(CurTexCoord)
        {

                if(m_textureType == GL_TEXTURE_2D)
                        //InitGLView(CurTexCoord->operator [](0).x*Width, CurTexCoord->operator [](1).x*Width, CurTexCoord->operator [](0).y*Height, CurTexCoord->operator [](2).y*Height);
                        ::InitGLView((int)*CurTexCoord->operator [](0)*_GetWidth(), (int)*CurTexCoord->operator [](2)*_GetWidth(), (int)*CurTexCoord->operator [](1)*_GetHeight(), (int)*CurTexCoord->operator [](5)*_GetHeight());
                else if (m_textureType == GL_TEXTURE_RECTANGLE_ARB)
                        //InitGLView(CurTexCoord->operator [](0).x, CurTexCoord->operator [](1).x, CurTexCoord->operator [](0).y, CurTexCoord->operator [](2).y);
                        ::InitGLView((int)*CurTexCoord->operator [](0), (int)*CurTexCoord->operator [](2), (int)*CurTexCoord->operator [](1),(int) *CurTexCoord->operator [](5));

        }
        else
                ::InitGLView(0, _GetWidth(), 0, _GetHeight());
}
//=================================================================
void		DataDsc_GLTex::SetRenderToTexture()
{
        CLASS_FCT_SET_NAME("SetRenderToTexture");
        CLASS_DEBUG("===============");\
        GetGpuCVSettings()->IncreaseIndentSize();\
        if(!_GetId() || _GetReloadFlag())
        {//no texture
                Allocate();	//SetLocation(LOC_GPU, false);
                _SetReloadFlag(false);
        }
        RenderBufferManager()->SetContext(this);
        SetDataFlag(true);
}
//=================================================
void DataDsc_GLTex::UnsetRenderToTexture()
{
        CLASS_FCT_SET_NAME("UnsetRenderToTexture");
        RenderBufferManager()->GetResult();
        RenderBufferManager()->UnSetContext();
#if _GPUCV_GL_USE_MIPMAPING
        if(m_autoMipMap)//generate LODs when we finish the render to texture.
                glGenerateMipmapEXT(m_textureType);
#endif
        GetGpuCVSettings()->DecreaseIndentSize();\
        CLASS_DEBUG("===============");\
}

//=================================================
DataDsc_GLTex::TexCoordType * DataDsc_GLTex::_GetTextCoord()
{	
        return m_texCoord;	
}
//=================================================
void DataDsc_GLTex::_SetTextCoord(const DataDsc_GLTex::TexCoordType * _texCoord)
{	
        if(!_texCoord)
        {//disable text coord
                delete m_texCoord;
                m_texCoord = NULL;
                return;
        }

        //enable it
        if(!m_texCoord)
                m_texCoord  = new TexCoordType();
        *m_texCoord = *_texCoord;
}
//=================================================
void	DataDsc_GLTex::_UpdateTexCoord()
{
        if(!m_texCoord)
                return;//nothing to update..
#if !USE_DATA_DSC
        if(m_textureType == GL_TEXTURE_2D)
                m_texCoord->Clear();
        else if(m_textureType == GL_TEXTURE_RECTANGLE_ARB)
                m_texCoord->SetCoord(0.,m_width,0.,m_height);
#endif
}
//==================================================
void DataDsc_GLTex::_SetAutoMipMap(bool _val)
{
#if _GPUCV_GL_USE_MIPMAPING
        //Manage MipMap generation...
        if(m_textureId)
                if(MainGPU()->m_glExtension.GetSGISTextureLOD())
                {//hardware compatible : http://www.nvidia.com/dev_content/nvopenglspecs/GL_SGIS_generate_mipmap.txt
                        _Bind();
                        _SetTexParami(GL_GENERATE_MIPMAP_SGIS, _val);
                        _UnBind();
                }
                else
                {
                        if (_val)
                        {
                                glGenerateMipmapEXT(m_textureType);
                        }
                }	
        m_autoMipMap = _val;
#endif
}
//==================================================
std::ostringstream & DataDsc_GLTex::operator << (std::ostringstream & _stream)const
{
        _stream << std::endl;
        _stream << std::endl;
        DataDsc_Base::operator <<(_stream);
        _stream << _GPUCV_INDENT_ <<"DataDsc_GLTex==============" << std::endl;
        _stream << _GPUCV_INDENT_ <<"m_textureId: \t"			<< m_textureId << std::endl;
        _stream << _GPUCV_INDENT_ <<"m_textureId_ARB: \t"		<< m_textureId_ARB << std::endl;
        _stream << _GPUCV_INDENT_ <<"m_textureAttachedID: \t"	<< m_textureAttachedID << std::endl;
        _stream << _GPUCV_INDENT_ <<"m_textureType: \t"			<< m_textureType << std::endl;
        _stream << _GPUCV_INDENT_ <<"m_internalFormat: \t"		<< GetStrGLInternalTextureFormat(m_internalFormat) << std::endl;
        _stream << _GPUCV_INDENT_ <<"m_needReload: \t"			<< m_needReload << std::endl;
        _stream << _GPUCV_INDENT_ <<"DataDsc_GLTex==============" << std::endl;
        return _stream;
}

Powered by WebSVN v1.61