gpucalc::GLTexture Class Reference

#include <gl_texture.h>

Inheritance diagram for gpucalc::GLTexture:

Inheritance graph

List of all members.

Public Member Functions

void bind ()
 Bind our object.
virtual size_t getActualLengthGPU () const
const std::string & getClassName () const
 Returns name of class of our object.
virtual size_t getComponentSize () const
virtual int getDimension () const
GLenum getGLTextureFormat () const
GLuint getGLTextureID () const
GLenum getGLTextureTarget () const
GLenum getGLTextureType () const
virtual size_t getNumberOfComponents () const
const std::string & getObjectName () const
 Returns name of our object.
virtual int getSizeX () const
virtual int getSizeY () const
virtual int getSizeZ () const
void getSpecificParameter (const std::string &ParameterName, void *ParameterValue)
 Method for obtaining some specific parameters, such as texture specific params, and so on.
virtual size_t getTypeSize () const
void initialize ()
bool isActive () const
bool isInitialized () const
bool isLocked () const
 returns state of object.
bool isRenderTexture () const
 Indicates that this texture is a render target.
bool isUploadedToGPU () const
void reInitialize (const Data &data)
void unbind ()
 Unbind our object.
void uploadToGPU ()
 ~GLTexture ()

Protected Member Functions

void addSpecificParameter (const std::string &ParameterName, void *ParameterValue, size_t Size)
void addSpecificParameter (const std::string &ParameterName, void *ParameterValue, unsigned int Size)
void lock ()
void unlock ()

Protected Attributes

size_t mActualLengthGPU
size_t mComponentSize
size_t mDimension
size_t mNumberOfComponents
size_t mSizeX
size_t mSizeY
size_t mSizeZ
size_t mTypeSize

Private Member Functions

 GLTexture (const std::string &TextureName, TextureUsage Usage, GraphicCore *Core)
void setATIData ()
 ATI specific data uploading.
void setNVData ()
 NVIDIA specific data uploading.

Private Attributes

GraphicCoremDefaultGraphicCore
void * mGLPointer
 Pointer for uploading data to GPU side.
GLenum mGLTextureFormat
GLuint mGLTextureID
 handle to OpenGL texture.
GLint mGLTextureInternalFormat
GLenum mGLTextureTarget
GLenum mGLTextureType
bool mIsUploadedToGPU
TextureUsage mUsage

Friends

class GLGraphicCore


Detailed Description

Definition at line 49 of file gl_texture.h.


Constructor & Destructor Documentation

gpucalc::GLTexture::~GLTexture (  ) 

Definition at line 47 of file gl_texture.cpp.

00048  {
00049   glDeleteTextures(1, &mGLTextureID);
00050   LogManager::getSingleton().logMessage(dynamic_cast<Bindable *>(this), "Texture ID deleted from OpenGL memory.", LML_Normal);
00051  }

gpucalc::GLTexture::GLTexture ( const std::string &  TextureName,
TextureUsage  Usage,
GraphicCore Core 
) [inline, private]

Definition at line 166 of file gl_texture.h.

00166                                                                                    :
00167     Object(_GLTextureClassName, TextureName), Texture(_GLTextureClassName, TextureName, Usage, Core),
00168     mUsage(Usage), mIsUploadedToGPU(false), mGLTextureFormat(0), mGLTextureTarget(0), mGLTextureType(0),
00169     mGLTextureInternalFormat(0), mGLTextureID(0), mGLPointer(0), mDefaultGraphicCore(Core)
00170    {
00171     glGenTextures(1, &mGLTextureID);
00172     addSpecificParameter("GLTextureID", &mGLTextureID, sizeof(mGLTextureID));
00173     LogManager::getSingleton().logMessage(dynamic_cast<Bindable *>(this),
00174      "Generated new OpenGL texture ID: " + auxillary::StringUtil::toString(mGLTextureID), LML_Normal);
00175    }


Member Function Documentation

void gpucalc::Object::addSpecificParameter ( const std::string &  ParameterName,
void *  ParameterValue,
size_t  Size 
) [inline, protected, inherited]

Definition at line 254 of file object.h.

00255    {
00256     SpecificParametersMap::iterator i = mSpecificParameters.find(ParameterName);
00257     if (i != mSpecificParameters.end())
00258     {
00259      mSpecificParameters.erase(i);
00260     }
00261     mSpecificParameters[ParameterName] = Any(ParameterValue, Size);
00262    }

void gpucalc::Texture::addSpecificParameter ( const std::string &  ParameterName,
void *  ParameterValue,
unsigned int  Size 
) [inline, protected, inherited]

Definition at line 120 of file texture.h.

00121    {
00122     Bindable::addSpecificParameter(ParameterName, ParameterValue, Size);
00123    }

void gpucalc::Texture::bind (  )  [inline, virtual, inherited]

Bind our object.

For example, set in some active state (Texture, Shader and so on)

Implements gpucalc::Bindable.

Definition at line 94 of file texture.h.

00095    {
00096     mDefaultGraphicCore->bind(this);
00097    }

virtual size_t gpucalc::GPUResource::getActualLengthGPU (  )  const [inline, virtual, inherited]

Definition at line 105 of file gpu_resource.h.

00106    {
00107     return mActualLengthGPU;
00108    }

const std::string& gpucalc::Object::getClassName (  )  const [inline, inherited]

Returns name of class of our object.

Definition at line 92 of file object.h.

00093    {
00094     return mClassName;
00095    }

virtual size_t gpucalc::GPUResource::getComponentSize (  )  const [inline, virtual, inherited]

Definition at line 99 of file gpu_resource.h.

00100    {
00101     return mComponentSize;
00102    }

virtual int gpucalc::GPUResource::getDimension (  )  const [inline, virtual, inherited]

Definition at line 87 of file gpu_resource.h.

00088    {
00089     return mDimension;
00090    }

GLenum gpucalc::GLTexture::getGLTextureFormat (  )  const [inline]

Definition at line 87 of file gl_texture.h.

00088    {
00089     return mGLTextureFormat;
00090    }

GLuint gpucalc::GLTexture::getGLTextureID (  )  const [inline]

Definition at line 75 of file gl_texture.h.

00076    {
00077     return mGLTextureID;
00078    }

GLenum gpucalc::GLTexture::getGLTextureTarget (  )  const [inline]

Definition at line 81 of file gl_texture.h.

00082    {
00083     return mGLTextureTarget;
00084    }

GLenum gpucalc::GLTexture::getGLTextureType (  )  const [inline]

Definition at line 93 of file gl_texture.h.

00094    {
00095     return mGLTextureType;
00096    }

virtual size_t gpucalc::GPUResource::getNumberOfComponents (  )  const [inline, virtual, inherited]

Definition at line 63 of file gpu_resource.h.

00064    {
00065     return mNumberOfComponents;
00066    }

const std::string& gpucalc::Object::getObjectName (  )  const [inline, inherited]

Returns name of our object.

Definition at line 101 of file object.h.

00102    {
00103     return mObjectName;
00104    }

virtual int gpucalc::GPUResource::getSizeX (  )  const [inline, virtual, inherited]

Definition at line 69 of file gpu_resource.h.

00070    {
00071     return mSizeX;
00072    }

virtual int gpucalc::GPUResource::getSizeY (  )  const [inline, virtual, inherited]

Definition at line 75 of file gpu_resource.h.

00076    {
00077     return mSizeY;
00078    }

virtual int gpucalc::GPUResource::getSizeZ (  )  const [inline, virtual, inherited]

Definition at line 81 of file gpu_resource.h.

00082    {
00083     return mSizeZ;
00084    }

void gpucalc::Object::getSpecificParameter ( const std::string &  ParameterName,
void *  ParameterValue 
) [inline, inherited]

Method for obtaining some specific parameters, such as texture specific params, and so on.

Parameters:
ParameterName - name of parameter, usually it similar to specific method of some object (for example, GLTextureID)
ParameterValue - contain value of named parameter, it must be allocated and have sufficient size.
Todo:
Think for better realization.

Definition at line 128 of file object.h.

00129    {
00130     SpecificParametersMap::iterator i = mSpecificParameters.find(ParameterName);
00131     if (i != mSpecificParameters.end())
00132     {
00133      i->second.copyValue(ParameterValue);
00134     }
00135     else
00136     {
00137      Except<ERR_ITEM_NOT_FOUND>(this, "Parameter \"" + ParameterName + "\" does not exists.", "Object::getSpecificParameter()", __FILE__, __LINE__);
00138     }
00139    }

virtual size_t gpucalc::GPUResource::getTypeSize (  )  const [inline, virtual, inherited]

Definition at line 93 of file gpu_resource.h.

00094    {
00095     return mTypeSize;
00096    }

void gpucalc::GLTexture::initialize (  )  [virtual]

Implements gpucalc::GPUResource.

Definition at line 54 of file gl_texture.cpp.

00055  {
00056   bind();
00057 
00058   glTexParameteri(mGLTextureTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00059   glTexParameteri(mGLTextureTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00060   glTexParameteri(mGLTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP);
00061   glTexParameteri(mGLTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP);
00062 
00063   glTexImage2D(mGLTextureTarget, 0, mGLTextureInternalFormat, mSizeX, mSizeY, 0, mGLTextureFormat, mGLTextureType, 0);
00064   mDefaultGraphicCore->checkErrors("GLTexture::setData");
00065  }

bool gpucalc::Texture::isActive (  )  const [inline, virtual, inherited]

Implements gpucalc::Bindable.

Definition at line 106 of file texture.h.

00107    {
00108     return (this == mDefaultGraphicCore->getActiveTexture());
00109    }

bool gpucalc::GLTexture::isInitialized (  )  const [inline, virtual]

Implements gpucalc::GPUResource.

Definition at line 102 of file gl_texture.h.

00103    {
00104     return true;
00105    }

bool gpucalc::Object::isLocked (  )  const [inline, inherited]

returns state of object.

If object is locked then we cannot change some state of it, because object is used in computation. If object is unlocked then we can change some state of it, object is not in computation.

Definition at line 113 of file object.h.

00114    {
00115     return mIsLocked;
00116    }

bool gpucalc::GLTexture::isRenderTexture (  )  const [inline, virtual]

Indicates that this texture is a render target.

Implements gpucalc::Texture.

Definition at line 60 of file gl_texture.h.

00061    {
00062     return (mUsage == TU_Render);
00063    }

bool gpucalc::GLTexture::isUploadedToGPU (  )  const [inline, virtual]

Implements gpucalc::GPUResource.

Definition at line 69 of file gl_texture.h.

00070    {
00071     return mIsUploadedToGPU;
00072    }

void gpucalc::Object::lock (  )  [inline, protected, inherited]

Definition at line 265 of file object.h.

00266    {
00267     mIsLocked = true;
00268    }

void gpucalc::Texture::reInitialize ( const Data data  )  [inline, inherited]

Definition at line 112 of file texture.h.

00113    {
00114     mDefaultGraphicCore->initialize(data, *this);
00115    }

void gpucalc::GLTexture::setATIData (  )  [private]

ATI specific data uploading.

We bind framebuffer, than we add our texture as render target. After that we perform rendering via glDrawPixels. Finally remove our texture from rendering targets and unbind framebuffer.

Remarks:
This method is hardware accelerated on ATI cards.

Definition at line 127 of file gl_texture.cpp.

00128  {
00129   size_t RequestedLengthGPU = mSizeX * mSizeY;
00130 
00131   if (mActualLengthGPU  == RequestedLengthGPU)
00132   {
00133    FrameBuffer * Helper = mDefaultGraphicCore->getActiveFrameBuffer();
00134    Helper->bind();
00135    {
00136     Helper->drawBuffer(this);
00137     glRasterPos2i(0,0);
00138     glDrawPixels(mSizeX, mSizeY, mGLTextureFormat, mGLTextureType, mGLPointer);
00139     Helper->detach(this);
00140    }
00141    Helper->unbind();
00142    LogManager::getSingleton().logMessage(dynamic_cast<Bindable *>(this), "OpenGL texture uploaded data using ATI specific method. ID: " + 
00143     auxillary::StringUtil::toString(mGLTextureID), LML_Trivial);
00144   }
00145   else
00146   {
00147    Except<ERR_NOT_IMPLEMENTED>(dynamic_cast<Bindable *>(this), "Uploading non-rectangle data is not implemented!", "GLTexture::setATIData()", __FILE__, __LINE__);
00148   }
00149 
00150   //bind();
00151  }

void gpucalc::GLTexture::setNVData (  )  [private]

NVIDIA specific data uploading.

First of all upload maximal rectangle (without last not full row).

Then upload truncated last row.

Definition at line 95 of file gl_texture.cpp.

00096  {
00097   bind();
00098 
00099   size_t RequestedLengthGPU = mSizeX * mSizeY;
00100 
00101   if (mActualLengthGPU != RequestedLengthGPU)
00102   {
00103    Except<ERR_NOT_IMPLEMENTED>(dynamic_cast<Bindable *>(this), "Uploading non-rectangle data is not implemented!", "GLTexture::setNVData()", __FILE__, __LINE__);
00104 
00105    Warning<ERR_INVALIDPARAMS>(dynamic_cast<Bindable *>(this), "We use some external bytes to upload non-rectangle data in GPU-side.", "GLTexture::setNVData()", __FILE__, __LINE__);
00106 
00107    size_t NumberOfFullRows = mActualLengthGPU / mSizeX;
00108    size_t LengthOfLastRow = mActualLengthGPU - NumberOfFullRows * mSizeX;
00109 
00111    glTexSubImage2D(mGLTextureTarget, 0, 0, 0, mSizeX, NumberOfFullRows, mGLTextureFormat, mGLTextureType, mGLPointer);
00112 
00114    size_t PointerOffset = NumberOfFullRows * mSizeX * mNumberOfComponents * mTypeSize;
00115    glTexSubImage2D(mGLTextureTarget, 0, 0, NumberOfFullRows, LengthOfLastRow, 1, mGLTextureFormat, mGLTextureType,
00116     static_cast<char *>(mGLPointer) + PointerOffset);
00117   }
00118   else
00119   {
00120    glTexSubImage2D(mGLTextureTarget, 0, 0, 0, mSizeX, mSizeY, mGLTextureFormat, mGLTextureType, mGLPointer);
00121    LogManager::getSingleton().logMessage(dynamic_cast<Bindable *>(this), "OpenGL texture uploaded data using NVIDIA specific method. ID: " + 
00122     auxillary::StringUtil::toString(mGLTextureID), LML_Trivial);
00123   }
00124  }

void gpucalc::Texture::unbind (  )  [inline, virtual, inherited]

Unbind our object.

For example, set in some inactive state (Texture, Shader and so on)

Implements gpucalc::Bindable.

Definition at line 100 of file texture.h.

00101    {
00102     mDefaultGraphicCore->unbind(this);
00103    }

void gpucalc::Object::unlock (  )  [inline, protected, inherited]

Definition at line 271 of file object.h.

00272    {
00273     mIsLocked = false;
00274    }

void gpucalc::GLTexture::uploadToGPU (  )  [virtual]

Implements gpucalc::GPUResource.

Definition at line 68 of file gl_texture.cpp.

00069  {
00070   if (!mIsUploadedToGPU)
00071   {
00072    switch (mDefaultGraphicCore->getVendor())
00073    {
00074     case NVIDIA:
00075     case MESA:
00076     case ATI:
00077      setNVData();
00078      break;
00079 
00080     //case ATI:
00081     // setATIData();
00082     // break;
00083 
00084     default:
00085      Except<ERR_NOT_IMPLEMENTED>(dynamic_cast<Bindable *>(this), "Uploading data for non-nvidia and non-ati cards is not implemented!", "GLTexture::setData()", __FILE__, __LINE__);
00086      break;
00087    }
00088    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
00089    mIsUploadedToGPU = true;
00090    mDefaultGraphicCore->checkErrors("GLTexture::uploadToGPU()");
00091   }
00092  }


Friends And Related Function Documentation

friend class GLGraphicCore [friend]

Definition at line 54 of file gl_texture.h.


Member Data Documentation

size_t gpucalc::GPUResource::mActualLengthGPU [protected, inherited]

Definition at line 132 of file gpu_resource.h.

size_t gpucalc::GPUResource::mComponentSize [protected, inherited]

Definition at line 131 of file gpu_resource.h.

Reimplemented from gpucalc::Texture.

Definition at line 144 of file gl_texture.h.

size_t gpucalc::GPUResource::mDimension [protected, inherited]

Definition at line 129 of file gpu_resource.h.

Pointer for uploading data to GPU side.

Definition at line 141 of file gl_texture.h.

Definition at line 118 of file gl_texture.h.

handle to OpenGL texture.

This number identifies texture in OpenGL memory.

Definition at line 135 of file gl_texture.h.

Definition at line 127 of file gl_texture.h.

Definition at line 121 of file gl_texture.h.

Definition at line 124 of file gl_texture.h.

Definition at line 114 of file gl_texture.h.

size_t gpucalc::GPUResource::mNumberOfComponents [protected, inherited]

Definition at line 125 of file gpu_resource.h.

size_t gpucalc::GPUResource::mSizeX [protected, inherited]

Definition at line 126 of file gpu_resource.h.

size_t gpucalc::GPUResource::mSizeY [protected, inherited]

Definition at line 127 of file gpu_resource.h.

size_t gpucalc::GPUResource::mSizeZ [protected, inherited]

Definition at line 128 of file gpu_resource.h.

size_t gpucalc::GPUResource::mTypeSize [protected, inherited]

Definition at line 130 of file gpu_resource.h.

Definition at line 111 of file gl_texture.h.


The documentation for this class was generated from the following files:

Generated on Thu Mar 5 22:36:44 2009 for gpucalc by  doxygen 1.5.6