OSGTextureBuffer.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <cstdlib>
00044 #include <cstdio>
00045 
00046 #include <OSGConfig.h>
00047 #include <OSGGL.h>
00048 #include <OSGGLEXT.h>
00049 
00050 #include "OSGTextureBuffer.h"
00051 #include "OSGWindow.h"
00052 #include "OSGDrawEnv.h"
00053 #include "OSGTextureObjChunk.h"
00054 
00055 OSG_USING_NAMESPACE
00056 
00057 
00058 UInt32 TextureBuffer::_uiFramebuffer_object_extension = 
00059     Window::invalidExtensionID;
00060 
00061 UInt32 TextureBuffer::_uiFuncFramebufferTexture1D =  Window::invalidFunctionID;
00062 UInt32 TextureBuffer::_uiFuncFramebufferTexture2D =  Window::invalidFunctionID;
00063 UInt32 TextureBuffer::_uiFuncFramebufferTexture3D =  Window::invalidFunctionID;
00064 
00065 
00066 typedef void (OSG_APIENTRY *GLFramebufferTexture1DEXTProcT)(
00067     GLenum target, 
00068     GLenum attachment, 
00069     GLenum textarget, 
00070     GLuint texture, 
00071     GLint level);
00072 
00073 typedef void (OSG_APIENTRY *GLFramebufferTexture2DEXTProcT)(
00074     GLenum target, 
00075     GLenum attachment, 
00076     GLenum textarget, 
00077     GLuint texture, 
00078     GLint level);
00079 
00080 typedef void (OSG_APIENTRY *GLFramebufferTexture3DEXTProcT)(
00081     GLenum target, 
00082     GLenum attachment, 
00083     GLenum textarget, 
00084     GLuint texture, 
00085     GLint level, 
00086     GLint zoffset);
00087 
00088 // Documentation for this class is emited in the
00089 // OSGTextureBufferBase.cpp file.
00090 // To modify it, please change the .fcd file (OSGTextureBuffer.fcd) and
00091 // regenerate the base file.
00092 
00093 void TextureBuffer::bind(DrawEnv *pEnv, UInt32 index)
00094 {
00095     Window *pWindow = pEnv->getWindow();
00096 
00097     if(_sfTexture.getValue() != NullFC)
00098     {
00099         pWindow->validateGLObject(_sfTexture.getValue()->getGLId(), pEnv);
00100 
00101         GLenum target;
00102 
00103         if(getTexTarget() != GL_NONE)
00104         {
00105             target = getTexTarget();
00106         }
00107         else
00108         {
00109             target = _sfTexture.getValue()->determineTextureTarget(pWindow);
00110         }
00111             
00112         switch(target)
00113         {
00114             case GL_TEXTURE_1D:
00115             {
00116                 GLFramebufferTexture1DEXTProcT 
00117                     glFramebufferTexture1DEXTProc =
00118 
00119                     (GLFramebufferTexture1DEXTProcT) pWindow->getFunction(
00120                         _uiFuncFramebufferTexture1D);
00121 
00122                 glFramebufferTexture1DEXTProc(GL_FRAMEBUFFER_EXT, 
00123                                               index,
00124                                               target,
00125                                               pWindow->getGLObjectId(
00126                                                     _sfTexture.getValue()->getGLId()),
00127                                               getLevel());
00128              }
00129             break;
00130                 
00131             case GL_TEXTURE_2D:
00132             case GL_TEXTURE_RECTANGLE_ARB:
00133             case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
00134             case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
00135             case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
00136             case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
00137             case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
00138             case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
00139             {
00140                 GLFramebufferTexture2DEXTProcT 
00141                     glFramebufferTexture2DEXTProc =
00142 
00143                     (GLFramebufferTexture2DEXTProcT) pWindow->getFunction(
00144                         _uiFuncFramebufferTexture2D);
00145 
00146                 glFramebufferTexture2DEXTProc(GL_FRAMEBUFFER_EXT, 
00147                                               index,
00148                                               target,
00149                                               pWindow->getGLObjectId(
00150                                                     _sfTexture.getValue()->getGLId()),
00151                                               getLevel());
00152             }
00153             break;
00154                 
00155             case GL_TEXTURE_3D:
00156                 break;
00157         }
00158     }
00159 }
00160 
00161 void TextureBuffer::validate(DrawEnv *pEnv)
00162 {
00163     Window *pWindow = pEnv->getWindow();
00164 
00165     if(_sfTexture.getValue() != NullFC)
00166     {
00167         pWindow->validateGLObject(_sfTexture.getValue()->getGLId(), pEnv);
00168     }
00169 }
00170 
00171 /*----------------------- constructors & destructors ----------------------*/
00172 
00173 TextureBuffer::TextureBuffer(void) :
00174     Inherited()
00175 {
00176 }
00177 
00178 TextureBuffer::TextureBuffer(const TextureBuffer &source) :
00179     Inherited(source)
00180 {
00181 }
00182 
00183 TextureBuffer::~TextureBuffer(void)
00184 {
00185 }
00186 
00187 /*----------------------------- class specific ----------------------------*/
00188 
00189 void TextureBuffer::initMethod(InitPhase ePhase)
00190 {
00191     Inherited::initMethod(ePhase);
00192 
00193     if(ePhase == TypeObject::SystemPost)
00194     {
00195         _uiFramebuffer_object_extension = 
00196             Window::registerExtension("GL_EXT_framebuffer_object");
00197 
00198         _uiFuncFramebufferTexture1D =
00199             Window::registerFunction (
00200                 OSG_DLSYM_UNDERSCORE"glFramebufferTexture1DEXT", 
00201                 _uiFramebuffer_object_extension);
00202 
00203         _uiFuncFramebufferTexture2D =
00204             Window::registerFunction (
00205                 OSG_DLSYM_UNDERSCORE"glFramebufferTexture2DEXT", 
00206                 _uiFramebuffer_object_extension);
00207 
00208         _uiFuncFramebufferTexture3D =
00209             Window::registerFunction (
00210                 OSG_DLSYM_UNDERSCORE"glFramebufferTexture3DEXT", 
00211                 _uiFramebuffer_object_extension);
00212     }
00213 
00214 }
00215 
00216 void TextureBuffer::changed(ConstFieldMaskArg whichField, 
00217                             UInt32            origin,
00218                             BitVector         details)
00219 {
00220     Inherited::changed(whichField, origin, details);
00221 }
00222 
00223 void TextureBuffer::dump(      UInt32    , 
00224                          const BitVector ) const
00225 {
00226     SLOG << "Dump TextureBuffer NI" << std::endl;
00227 }
00228 
00229