gl_graphic_core.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Kutumov Alexey                                  *
00003  *   ru.pixel@gmail.com                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00033 #include "gl_graphic_core/gl_graphic_core.h"
00034 #include "gl_graphic_core/gl_texture.h"
00035 #include "gl_graphic_core/gl_framebuffer.h"
00036 
00037 #include "gpucalc/log_manager.h"
00038 #include "gpucalc/string_util.h"
00039 #include "gpucalc/application.h"
00040 #include "gpucalc/shader_system.h"
00041 
00042 #include <GL/glew.h>
00043 
00044 #define GLUT_NO_LIB_PRAGMA // 
00045 #include <GL/glut.h>
00046 
00047 
00048 
00049 namespace gpucalc
00050 {
00051  GLGraphicCore::GLGraphicCore(): GraphicCore(_GLGraphicCoreObjectName), mGLUTWindow(0),
00052   mGLVendor(DEFAULT), mGLMaxFrameBufferAttachmentPoints(0), mGLMaxTextureSize(0),
00053   mGLDefaultWidth(0.0f), mGLDefaultHeight(0.0f), mIsStarted(false), mGLTextureMap(),
00054   mGLFrameBufferMap(), mAcceptableShaderSystemIDSet(), mActiveFrameBuffer(0), mActiveTexture(0)
00055  {
00056  }
00057 
00058 
00059  GLGraphicCore::~GLGraphicCore()
00060  {
00061   if (mIsStarted)
00062   {
00063    stop();
00064   }
00065  }
00066 
00067 
00068  void GLGraphicCore::start(int argc, char * argv [])
00069  {
00070         if (mIsStarted) return;
00071   glutInit(&argc, argv);
00072   mGLUTWindow = glutCreateWindow("GL Graphic Core Window");
00073   glutHideWindow();
00074   LogManager::getSingleton().logMessage(this, "Using \"glut\" library for setting up GL window and context", LML_Trivial);
00075   LogManager::getSingleton().logMessage(this, "glut GL window created successfully", LML_Trivial);
00076   LogManager::getSingleton().logMessage(this, "Using \"glew\" library for obtaining advanced functions and capabilities of OpenGL...", LML_Trivial);
00077   GLenum err = glewInit();
00078   if (err != GLEW_OK)
00079   {
00080    Except<ERR_RENDERINGAPI_ERROR>(this, (char *)glewGetErrorString(err), "GLGraphicCore::start()", __FILE__, __LINE__);
00081   }
00082 
00083   if (GLEW_VERSION_2_0)
00084   {
00085    if (GLEW_VERSION_2_1)
00086    {
00087     LogManager::getSingleton().logMessage(this, "This GPU supports OpenGL 2.1, looking good!");
00088    }
00089    else
00090    {
00091     LogManager::getSingleton().logMessage(this, "This GPU supports OpenGL 2.0.");
00092    }
00093   }
00094   else
00095   {
00096    Warning<ERR_RENDERINGAPI_ERROR>(this, "This GPU does not support OpenGL 2.0 and later, shading may be unavailable.", "GLGraphicCore::start()", __FILE__, __LINE__);
00097   }
00098 
00099   LogManager::getSingleton().logMessage(this, std::string("Renderer: ") +
00100    (char *)glGetString(GL_RENDERER), LML_Trivial);
00101 
00102   LogManager::getSingleton().logMessage(this, std::string("Version:  ") +
00103    (char * )glGetString(GL_VERSION), LML_Trivial);
00104   
00105   std::string GLVendorString = std::string((char *)glGetString(GL_VENDOR));
00106   mGLVendor = this->FindCorrectVendor(GLVendorString);
00107   LogManager::getSingleton().logMessage(this, std::string("Vendor:   ") +
00108    GLVendorString, LML_Trivial);
00109 
00110   this->checkErrors("GLGraphicCore::start()");
00111 
00112   glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &mGLMaxFrameBufferAttachmentPoints);
00113 
00114   LogManager::getSingleton().logMessage(this, "Max number of attachment points is: " +
00115    auxillary::StringUtil::toString(mGLMaxFrameBufferAttachmentPoints));
00116 
00117 
00118   glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &mGLMaxTextureSize);
00119 
00120   LogManager::getSingleton().logMessage(this, "Max size of texture is: " +
00121    auxillary::StringUtil::toString(mGLMaxTextureSize));
00122 
00123 
00124   this->checkErrors("GLGraphicCore::start()");
00125 
00126   mIsStarted = true;
00127 
00128   this->addAcceptableShaderSystemID("GLGLSLShaderSystem");
00129   this->addAcceptableShaderSystemID("GLCgShaderSystem");
00130   LogManager::getSingleton().logMessage(this, "---===========================================---");
00131   LogManager::getSingleton().logMessage(this, "---===       GL Graphic Core started       ===---");
00132   LogManager::getSingleton().logMessage(this, "---===========================================---");
00133  }
00134 
00135 
00136  void GLGraphicCore::stop()
00137  {
00138   assert(mIsStarted && "GLGraphicCore is not started!!!");
00139   clearContainer(mGLTextureMap);
00140   clearContainer(mGLFrameBufferMap);
00141   glutDestroyWindow(mGLUTWindow);
00142   LogManager::getSingleton().logMessage(this, "---===========================================---");
00143   LogManager::getSingleton().logMessage(this, "---===       GL Graphic Core stopped       ===---");
00144   LogManager::getSingleton().logMessage(this, "---===========================================---");
00145   mIsStarted = false;
00146  }
00147 
00148 
00149  void GLGraphicCore::setMatrixMode(float Width, float Height)
00150  {
00151   assert(mIsStarted && "GLGraphicCore is not started!!!");
00152   mGLDefaultWidth = Width;
00153   mGLDefaultHeight = Height;
00154 
00155   glMatrixMode(GL_PROJECTION);
00156   glLoadIdentity();
00157   gluOrtho2D(0.0f, Width, 0.0f, Height);
00158   glMatrixMode(GL_MODELVIEW);
00159   glLoadIdentity();
00160   glViewport(0, 0, Width, Height);
00161   LogManager::getSingleton().logMessage(this, "ViewPort size: " +
00162    auxillary::StringUtil::toString(Width) + " X " + auxillary::StringUtil::toString(Height), LML_Trivial);
00163  }
00164 
00165 
00166  void GLGraphicCore::draw(float TexCoordX, float TexCoordY)
00167  {
00168   assert(mIsStarted && "GLGraphicCore is not started!!!");
00169   glBegin(GL_QUADS);
00170   {
00171    glTexCoord2f(0.0f, 0.0f);   glVertex2f(0.0f, 0.0f);
00172    glTexCoord2f(TexCoordX, 0.0f);  glVertex2f(mGLDefaultWidth, 0.0f);
00173    glTexCoord2f(TexCoordX, TexCoordY); glVertex2f(mGLDefaultWidth, mGLDefaultHeight);
00174    glTexCoord2f(0.0f, TexCoordY);  glVertex2f(0.0f, mGLDefaultHeight);
00175   }
00176   glEnd();
00177   glFlush();
00178   glFinish();
00179   this->checkErrors("GLGraphicCore::draw()");
00180   LogManager::getSingleton().logMessage(this, "Texture coords: " +
00181    auxillary::StringUtil::toString(TexCoordX) + " X " + auxillary::StringUtil::toString(TexCoordY), LML_Trivial);
00182  }
00183 
00184 
00185  Texture * GLGraphicCore::create(const std::string & TextureName, TextureUsage Usage)
00186  {
00187   assert(mIsStarted && "GLGraphicCore is not started!!!");
00188   GLTextureMap::iterator i = mGLTextureMap.find(TextureName);
00189   if (i != mGLTextureMap.end())
00190   {
00191    Except<ERR_DUPLICATE_ITEM>(this, "Texture object with name \"" + TextureName + "\" already exists!",
00192     "GLGraphicCore::create()", __FILE__, __LINE__);
00193    return 0;
00194   }
00195   else
00196   {
00197    GLTexture * Result = new GLTexture(TextureName, Usage, this);
00198    mGLTextureMap.insert(GLTextureMap::value_type(TextureName, Result));
00199    LogManager::getSingleton().logMessage(this, "Texture object \"" + TextureName + "\" created.", LML_Trivial);
00200    return Result;
00201   }
00202  }
00203 
00204 
00205  void GLGraphicCore::initialize(const Data & data, Texture & texture)
00206  {
00207   ConvertToTexture(data, static_cast<GLTexture &>(texture));
00208   texture.initialize();
00209  }
00210 
00211 
00212  Texture * GLGraphicCore::getTextureByName(const std::string & TextureName) const
00213  {
00214   assert(mIsStarted && "GLGraphicCore is not started!!!");
00215   GLTextureMap::const_iterator i = mGLTextureMap.find(TextureName);
00216   if (i != mGLTextureMap.end())
00217   {
00218    return i->second;
00219   }
00220   else
00221   {
00222    Except<ERR_ITEM_NOT_FOUND>(this, "Texture with name \"" + TextureName + "\" does not exists!", "GLGraphicCore::getTextureByName()", __FILE__, __LINE__);
00223    return 0;
00224   }
00225  }
00226 
00227 
00228  bool GLGraphicCore::isTextureCreated(const std::string & TextureName) const
00229  {
00230   assert(mIsStarted && "GLGraphicCore is not started!!!");
00231   return (mGLTextureMap.find(TextureName) != mGLTextureMap.end());
00232  }
00233 
00234 
00235  FrameBuffer * GLGraphicCore::create(const std::string & FrameBufferName)
00236  {
00237   assert(mIsStarted && "GLGraphicCore is not started!!!");
00238   GLFrameBufferMap::iterator i = mGLFrameBufferMap.find(FrameBufferName);
00239 
00240   if (i != mGLFrameBufferMap.end())
00241   {
00242    Except<ERR_DUPLICATE_ITEM>(this, "FrameBuffer object with name \"" + FrameBufferName + "\" already exists!",
00243     "GLGraphicCore::createFrameBuffer()", __FILE__, __LINE__);
00244    return 0;
00245   }
00246   else
00247   {
00248    GLFrameBuffer * Result = new GLFrameBuffer(FrameBufferName, static_cast<unsigned int>(mGLMaxFrameBufferAttachmentPoints), this);
00249    Result->initialize();
00250    mGLFrameBufferMap.insert(std::make_pair(FrameBufferName, Result));
00251    LogManager::getSingleton().logMessage(this, "Framebuffer object \"" + FrameBufferName + "\" created.", LML_Trivial);
00252    return Result;
00253   }
00254  }
00255 
00256 
00257  FrameBuffer * GLGraphicCore::getFrameBufferByName(const std::string & FrameBufferName) const
00258  {
00259   assert(mIsStarted && "GLGraphicCore is not started!!!");
00260   GLFrameBufferMap::const_iterator i = mGLFrameBufferMap.find(FrameBufferName);
00261   if (i != mGLFrameBufferMap.end())
00262   {
00263    return i->second;
00264   }
00265   else
00266   {
00267    Except<ERR_ITEM_NOT_FOUND>(this, "FrameBuffer with name \"" + FrameBufferName + "\" does not exists!",
00268     "GLGraphicCore::getFrameBufferByName()", __FILE__, __LINE__);
00269    return 0;
00270   }
00271  }
00272 
00273 
00274  bool GLGraphicCore::isFrameBufferCreated(const std::string & FrameBufferName) const
00275  {
00276   assert(mIsStarted && "GLGraphicCore is not started!!!");
00277   return (mGLFrameBufferMap.find(FrameBufferName) != mGLFrameBufferMap.end());
00278  }
00279 
00280  
00281  void GLGraphicCore::destroy(Texture * texture)
00282  {
00283   assert(mIsStarted && "GLGraphicCore is not started!!!");
00284   if (!removeFromContainer(texture->getObjectName(), mGLTextureMap))
00285   {
00286    Warning<ERR_INVALIDPARAMS>(this, "Texture object \"" + texture->getObjectName() + "\" was created outside GLGraphicCore!!! Destroying anyway.",
00287     "GLGraphicCore::deleteTexture", __FILE__, __LINE__);
00288   }
00289   std::string name = texture->getObjectName();
00290   delete texture;
00291   LogManager::getSingleton().logMessage(this, "Texture \"" + name + "\" deleted.", LML_Trivial);
00292  }
00293 
00294 
00295  void GLGraphicCore::destroy(FrameBuffer * fb)
00296  {
00297   assert(mIsStarted && "GLGraphicCore is not started!!!");
00298   if (!removeFromContainer(fb->getObjectName(), mGLFrameBufferMap))
00299   {
00300    Warning<ERR_INVALIDPARAMS>(this, "FrameBuffer object \"" + fb->getObjectName() + "\" was created outside GLGraphicCore!",
00301     "GLGraphicCore::deleteFrameBuffer", __FILE__, __LINE__);
00302 
00303   }
00304   std::string name = fb->getObjectName();
00305   delete fb;
00306   LogManager::getSingleton().logMessage(this, "FrameBuffer \"" + name + "\" deleted.", LML_Trivial);
00307  }
00308 
00309 
00310  void GLGraphicCore::bind(Texture * texture)
00311  {
00312   assert(texture && "Texture does not created!!!");
00313   if (texture != mActiveTexture)
00314   {
00315    GLTexture * glTexture = static_cast<GLTexture *>(texture);
00316    glBindTexture(glTexture->getGLTextureTarget(), glTexture->getGLTextureID());
00317    mActiveTexture = texture;
00318   }
00319  }
00320 
00321 
00322  void GLGraphicCore::unbind(Texture * texture)
00323  {
00324   assert(texture && "Texture does not created!!!");
00325   if (texture == mActiveTexture)
00326   {
00327    GLTexture * glTexture = static_cast<GLTexture *>(texture);
00328    glBindTexture(glTexture->getGLTextureTarget(), 0);
00329    mActiveTexture = 0;
00330   }
00331  }
00332 
00333 
00334  void GLGraphicCore::bind(FrameBuffer * framebuffer)
00335  {
00336   assert(framebuffer && "FrameBuffer does not created!!!");
00337   if (framebuffer != mActiveFrameBuffer)
00338   {
00339    GLFrameBuffer * glFrameBuffer = static_cast<GLFrameBuffer *>(framebuffer);
00340    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, glFrameBuffer->mGLFrameBufferID);
00341    mActiveFrameBuffer = framebuffer;
00342   }
00343  }
00344 
00345 
00346  void GLGraphicCore::unbind(FrameBuffer * framebuffer)
00347  {
00348   assert(framebuffer && "FrameBuffer does not created!!!");
00349   if (framebuffer == mActiveFrameBuffer)
00350   {
00351    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
00352    mActiveFrameBuffer = 0;
00353   }
00354  }
00355 
00356 
00357  void GLGraphicCore::checkErrors(const std::string & where)
00358  {
00359   GLenum err_code = glGetError();
00360   switch (err_code)
00361   {
00362    case GL_NO_ERROR:
00363     return;
00364 
00365    case GL_INVALID_ENUM:
00366        Except<ERR_RENDERINGAPI_ERROR>(this, "Enum argument out of range!", where, __FILE__, __LINE__);
00367     return;
00368 
00369    case GL_INVALID_VALUE:
00370     Except<ERR_RENDERINGAPI_ERROR>(this, "Numeric argument out of range!", where, __FILE__, __LINE__);
00371     return;
00372 
00373    case GL_INVALID_OPERATION:
00374     Except<ERR_RENDERINGAPI_ERROR>(this, "Operation illegal in current state!", where, __FILE__, __LINE__);
00375     return;
00376 
00377    case GL_STACK_OVERFLOW:
00378     Except<ERR_RENDERINGAPI_ERROR>(this, "Command would cause a stack overflow!", where, __FILE__, __LINE__);
00379     return;
00380 
00381    case GL_STACK_UNDERFLOW:
00382     Except<ERR_RENDERINGAPI_ERROR>(this, "Command would cause a stack underflow!", where, __FILE__, __LINE__);
00383     return;
00384 
00385    case GL_OUT_OF_MEMORY:
00386     Except<ERR_RENDERINGAPI_ERROR>(this, "Not enough memory left to execute command!", where, __FILE__, __LINE__);
00387     return;
00388 
00389    case GL_TABLE_TOO_LARGE:
00390     Except<ERR_RENDERINGAPI_ERROR>(this, "The specified table is too large!", where, __FILE__, __LINE__);
00391     return;
00392 
00393    default:
00394     Except<ERR_RENDERINGAPI_ERROR>(this, "Unknown error or no error!", where, __FILE__, __LINE__);
00395     return;
00396   }
00397  }
00398 
00399 
00400  Vendor GLGraphicCore::FindCorrectVendor(const std::string & GLVendorString)
00401  {
00402   if (!(auxillary::StringUtil::toLower(GLVendorString).find("nvidia") == std::string::npos))
00403   {
00404    return NVIDIA;
00405   }
00406 
00407   if (!(auxillary::StringUtil::toLower(GLVendorString).find("ati") == std::string::npos))
00408   {
00409    return ATI;
00410   }
00411 
00412   if (!(auxillary::StringUtil::toLower(GLVendorString).find("mesa") == std::string::npos))
00413   {
00414    return MESA;
00415   }
00416 
00417   if (!(auxillary::StringUtil::toLower(GLVendorString).find("gdi") == std::string::npos))
00418   {
00419    return GDI;
00420   }
00421 
00422   return DEFAULT;
00423  }
00424 
00425 
00426  bool GLGraphicCore::isAcceptSystem(const ShaderSystem * System) const
00427  {
00428   return (mAcceptableShaderSystemIDSet.find(System->getObjectName()) != mAcceptableShaderSystemIDSet.end());
00429  }
00430 
00431 
00432  void GLGraphicCore::addAcceptableShaderSystemID(const std::string & ShaderSystemID)
00433  {
00434   mAcceptableShaderSystemIDSet.insert(ShaderSystemID);
00435  }
00436 
00437 
00438  void GLGraphicCore::ConvertToTexture(const Data & data, GLTexture & texture)
00439  {
00440   assert(mIsStarted && "GLGraphicCore is not started!!!");
00441   texture.mGLPointer = data.pointer();
00442 
00443   texture.mActualLengthGPU = data.getActualLengthCPU() / data.getNumberOfComponents();
00444   texture.mDimension = data.getArrayDataType();
00445   texture.mNumberOfComponents = data.getNumberOfComponents();
00446   texture.mTypeSize = data.getTypeSize();
00447 
00448   texture.mSizeX = data.getSizeX();
00449   texture.mSizeY = data.getSizeY();
00450   texture.mSizeZ = data.getSizeZ();
00451 
00452   switch (this->getVendor())
00453   {
00454    case NVIDIA:
00455    case MESA:
00456    case GDI:
00457     ConvertToNVTexture(data, texture);
00458     break;
00459 
00460    case ATI:
00461     ConvertToATITexture(data, texture);
00462     break;
00463 
00464    default:
00465     Except<ERR_NOT_IMPLEMENTED>(this, "Vendors different from ATI, NVIDIA, MESA or GDI are not implemented!",
00466      "GLDataConverter::ConvertToTexture()", __FILE__, __LINE__);
00467   }
00468  }
00469 
00470 
00471  void GLGraphicCore::ConvertToNVTexture(const Data & data, GLTexture & texture)
00472  {
00473   assert(mIsStarted && "GLGraphicCore is not started!!!");
00474   switch (data.getNumberOfComponents())
00475   {
00476    case 1:
00477     texture.mGLTextureFormat = GL_LUMINANCE;
00478     break;
00479     
00480    case 2:
00481     texture.mGLTextureFormat = GL_LUMINANCE_ALPHA;
00482     break;
00483 
00484    case 3:
00485     texture.mGLTextureFormat = GL_RGB;
00486     break;
00487 
00488    case 4:
00489     texture.mGLTextureFormat = GL_RGBA;
00490     break;
00491 
00492    default:
00493     Except<ERR_INVALIDPARAMS>(this, "Wrong number of components!", "GLDataConverter::ToNVTexture", __FILE__, __LINE__);
00494     break;
00495   }
00496 
00497 
00498   switch (data.getArrayDataType())
00499   {
00500    case Array1D:
00501     texture.mGLTextureTarget = GL_TEXTURE_1D;
00502     break;
00503     
00504    case Array2D:
00505     texture.mGLTextureTarget = GL_TEXTURE_RECTANGLE_NV;
00506     break;
00507 
00508    case Array3D:
00509     texture.mGLTextureTarget = GL_TEXTURE_3D;
00510     break;
00511 
00512    default:
00513     Except<ERR_INVALIDPARAMS>(this, "Wrong array data type!", "GLDataConverter::ToNVTexture", __FILE__, __LINE__);
00514     break;
00515   }
00516 
00517 
00518   switch (data.getValueType())
00519   {
00520    case FloatType:
00521     texture.mGLTextureType = GL_FLOAT;
00522     switch (texture.getNumberOfComponents())
00523     {
00524      case 1:
00525       texture.mGLTextureInternalFormat = GL_FLOAT_R32_NV;
00526       break;
00527       
00528      case 2:
00529       texture.mGLTextureInternalFormat = GL_FLOAT_RG32_NV;
00530       break;
00531       
00532      case 3:
00533       texture.mGLTextureInternalFormat = GL_FLOAT_RGB32_NV;
00534       break;
00535 
00536      case 4:
00537       texture.mGLTextureInternalFormat = GL_FLOAT_RGBA32_NV;
00538       break;
00539       
00540      default:
00541       Except<ERR_INVALIDPARAMS>(this, "Wrong number of components!", "GLDataConverter::ToNVTexture", __FILE__, __LINE__);
00542       break;
00543     }
00544     break;
00545 
00546 
00547    case UnsignedCharType:
00548     texture.mGLTextureType = GL_UNSIGNED_BYTE;
00549     switch (texture.getNumberOfComponents())
00550     {
00551      case 1:
00552       texture.mGLTextureInternalFormat = GL_LUMINANCE8;
00553       break;
00554       
00555      case 2:
00556       texture.mGLTextureInternalFormat = GL_LUMINANCE8_ALPHA8;
00557       break;
00558       
00559      case 3:
00560       texture.mGLTextureInternalFormat = GL_RGB8;
00561       break;
00562 
00563      case 4:
00564       texture.mGLTextureInternalFormat = GL_RGBA8;
00565       break;
00566       
00567      default:
00568       break;
00569     }
00570     break;
00571 
00572 
00573    default:
00574     Except<ERR_NOT_IMPLEMENTED>(this, "ValueType is not implemented!", "GLDataConverter::ToNVTexture", __FILE__, __LINE__);
00575     break;
00576   }
00577  }
00578 
00579 
00580  void GLGraphicCore::ConvertToATITexture(const Data & data, GLTexture & texture)
00581  {
00582   assert(mIsStarted && "GLGraphicCore is not started!!!");
00583   switch (data.getNumberOfComponents())
00584   {
00585    case 1:
00586     texture.mGLTextureFormat = GL_LUMINANCE;
00587     break;
00588     
00589    case 2:
00590     texture.mGLTextureFormat = GL_LUMINANCE_ALPHA;
00591     break;
00592 
00593    case 3:
00594     texture.mGLTextureFormat = GL_RGB;
00595     break;
00596 
00597    case 4:
00598     texture.mGLTextureFormat = GL_RGBA;
00599     break;
00600 
00601    default:
00602     Except<ERR_INVALIDPARAMS>(this, "Wrong number of components!", "GLDataConverter::ToNVTexture", __FILE__, __LINE__);
00603     break;
00604   }
00605 
00606 
00607   switch (data.getArrayDataType())
00608   {
00609    case Array1D:
00610     texture.mGLTextureTarget = GL_TEXTURE_1D;
00611     break;
00612     
00613    case Array2D:
00614     texture.mGLTextureTarget = GL_TEXTURE_RECTANGLE_ARB; // it is the same value that GL_TEXTURE_RECTANGLE_NV
00615     break;
00616 
00617    case Array3D:
00618     texture.mGLTextureTarget = GL_TEXTURE_3D;
00619     break;
00620 
00621    default:
00622     Except<ERR_INVALIDPARAMS>(this, "Wrong array data type!", "GLDataConverter::ToNVTexture", __FILE__, __LINE__);
00623     break;
00624   }
00625 
00626 
00627   switch (data.getValueType())
00628   {
00629    case FloatType:
00630     texture.mGLTextureType = GL_FLOAT;
00631     switch (texture.getNumberOfComponents())
00632     {
00633      case 1:
00634       texture.mGLTextureInternalFormat = GL_LUMINANCE_FLOAT32_ATI;
00635       break;
00636 
00637      case 2:
00638       texture.mGLTextureInternalFormat = GL_LUMINANCE_ALPHA_FLOAT32_ATI;
00639       break;
00640 
00641      case 3:
00642       texture.mGLTextureInternalFormat = GL_RGB_FLOAT32_ATI;
00643       break;
00644 
00645      case 4:
00646       texture.mGLTextureInternalFormat = GL_RGBA_FLOAT32_ATI;
00647       break;
00648 
00649      default:
00650       break;
00651     }
00652     break;
00653 
00654 
00655    case UnsignedCharType:
00656     texture.mGLTextureType = GL_UNSIGNED_BYTE;
00657     switch (texture.getNumberOfComponents())
00658     {
00659      case 1:
00660       texture.mGLTextureInternalFormat = GL_LUMINANCE8;
00661       break;
00662 
00663      case 2:
00664       texture.mGLTextureInternalFormat = GL_LUMINANCE8_ALPHA8;
00665       break;
00666 
00667      case 3:
00668       texture.mGLTextureInternalFormat = GL_RGB8;
00669       break;
00670 
00671      case 4:
00672       texture.mGLTextureInternalFormat = GL_RGBA8;
00673       break;
00674 
00675      default:
00676       break;
00677     }
00678     break;
00679 
00680 
00681    default:
00682     Except<ERR_NOT_IMPLEMENTED>(this, "ValueType is not implemented!", "GLDataConverter::ToNVTexture", __FILE__, __LINE__);
00683     break;
00684   }
00685  }
00686 }

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