1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
49 #include "OSGGLFuncProtos.h"
51 #include "OSGTextureBuffer.h"
52 #include "OSGWindow.h"
53 #include "OSGDrawEnv.h"
54 #include "OSGTextureObjChunk.h"
59 UInt32
TextureBuffer::_uiFramebuffer_object_extension
=
60 Window::invalidExtensionID
;
62 UInt32
TextureBuffer::_uiFuncFramebufferTexture1D
= Window::invalidFunctionID
;
63 UInt32
TextureBuffer::_uiFuncFramebufferTexture2D
= Window::invalidFunctionID
;
64 UInt32
TextureBuffer::_uiFuncFramebufferTexture3D
= Window::invalidFunctionID
;
65 UInt32
TextureBuffer::_uiFuncFramebufferTextureLayer
= Window::invalidFunctionID
;
66 UInt32
TextureBuffer::_uiFuncGenerateMipmap
= Window::invalidFunctionID
;
68 // Documentation for this class is emited in the
69 // OSGTextureBufferBase.cpp file.
70 // To modify it, please change the .fcd file (OSGTextureBuffer.fcd) and
71 // regenerate the base file.
73 void TextureBuffer::bind(DrawEnv
*pEnv
, UInt32 index
)
75 Window
*pWindow
= pEnv
->getWindow();
77 if(_sfTexture
.getValue() != NULL
)
79 pWindow
->validateGLObject(_sfTexture
.getValue()->getGLId(), pEnv
);
83 if(getTexTarget() != GL_NONE
)
85 target
= getTexTarget();
89 target
= _sfTexture
.getValue()->determineTextureTarget(pWindow
);
97 OSGGETGLFUNCBYID_GL3( glFramebufferTexture1D
,
98 osgGlFramebufferTexture1D
,
99 _uiFuncFramebufferTexture1D
,
102 osgGlFramebufferTexture1D(
106 pWindow
->getGLObjectId(_sfTexture
.getValue()->getGLId()),
113 case GL_TEXTURE_RECTANGLE_ARB
:
114 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
115 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
116 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
117 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
118 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
119 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
121 OSGGETGLFUNCBYID_GL3_ES( glFramebufferTexture2D
,
122 osgGlFramebufferTexture2D
,
123 _uiFuncFramebufferTexture2D
,
126 osgGlFramebufferTexture2D(
130 pWindow
->getGLObjectId(_sfTexture
.getValue()->getGLId()),
137 OSGGETGLFUNCBYID_GL3( glFramebufferTexture3D
,
138 osgGlFramebufferTexture3D
,
139 _uiFuncFramebufferTexture3D
,
142 osgGlFramebufferTexture3D(
146 pWindow
->getGLObjectId(_sfTexture
.getValue()->getGLId()),
152 case GL_TEXTURE_2D_ARRAY
:
153 case GL_TEXTURE_CUBE_MAP_ARRAY
:
155 OSGGETGLFUNCBYID_GL3( glFramebufferTextureLayer
,
156 osgGlFramebufferTextureLayer
,
157 _uiFuncFramebufferTextureLayer
,
160 osgGlFramebufferTextureLayer(
163 pWindow
->getGLObjectId(_sfTexture
.getValue()->getGLId()),
173 void TextureBuffer::validate(DrawEnv
*pEnv
)
175 Window
*pWindow
= pEnv
->getWindow();
177 if(_sfTexture
.getValue() != NULL
)
179 pWindow
->validateGLObject(_sfTexture
.getValue()->getGLId(), pEnv
);
183 void TextureBuffer::resizeBuffers(UInt32 uiWidth
, UInt32 uiHeight
)
185 TextureObjChunk
*pTex
= this->getTexture();
190 Image
*pImg
= pTex
->getImage();
195 pImg
->set(pImg
->getPixelFormat(), //Image::OSG_RGB_PF,
199 pImg
->getMipMapCount(),
200 pImg
->getFrameCount (),
201 pImg
->getFrameDelay (),
203 pImg
->getDataType (), //Image::OSG_UINT8_IMAGEDATA,
205 pImg
->getSideCount ());
208 GLenum
TextureBuffer::getBufferFormat(void) const
210 TextureObjChunk
*pTex
= this->getTexture();
215 if(pTex
->getInternalFormat() != GL_NONE
)
216 return pTex
->getInternalFormat();
218 Image
*pImg
= pTex
->getImage();
223 return pImg
->getPixelFormat();
227 void TextureBuffer::processPreDeactivate(DrawEnv
*pEnv
, UInt32 index
)
229 if(_sfReadBack
.getValue() == true)
231 TextureObjChunk
*pTexObj
= this->getTexture();
236 Image
*pTexImg
= pTexObj
->getImage();
241 if(pTexImg
->getData() == NULL
)
243 SINFO
<< "TextureBuffer::render: (Re)Allocating image "
247 pTexImg
->set(pTexImg
->getPixelFormat(),
248 pTexImg
->getWidth (),
249 pTexImg
->getHeight (),
250 pTexImg
->getDepth (),
251 pTexImg
->getMipMapCount(),
252 pTexImg
->getFrameCount (),
253 pTexImg
->getFrameDelay (),
255 pTexImg
->getDataType (),
257 pTexImg
->getSideCount () );
260 UInt32 mipMapLevel
= _sfLevel
.getValue();
264 Window
*pWindow
= pEnv
->getWindow();
266 if(_sfTexTarget
.getValue() != GL_NONE
)
268 target
= _sfTexTarget
.getValue();
272 target
= _sfTexture
.getValue()->determineTextureTarget(pWindow
);
277 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
280 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
283 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
286 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
289 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
292 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
297 // select GL_COLORATTACHMENTn and read data into image
302 pTexImg
->getWidth (),
303 pTexImg
->getHeight (),
304 pTexImg
->getPixelFormat(),
305 pTexImg
->getDataType (),
306 pTexImg
->editData (mipMapLevel
, frame
, side
));
309 glReadBuffer(GL_NONE
);
314 void TextureBuffer::processPostDeactivate(DrawEnv
*pEnv
)
316 Window
*win
= pEnv
->getWindow();
318 // If there are TextureBuffers with mipmap filters attached,
319 // the mipmaps need to be regenerated
320 TextureObjChunk
*pTexObj
= this->getTexture();
325 GLenum target
= pTexObj
->determineTextureTarget(win
);
327 if(target
== GL_TEXTURE_2D
&&
328 (pTexObj
->getMinFilter() == GL_NEAREST_MIPMAP_NEAREST
||
329 pTexObj
->getMinFilter() == GL_LINEAR_MIPMAP_NEAREST
||
330 pTexObj
->getMinFilter() == GL_NEAREST_MIPMAP_LINEAR
||
331 pTexObj
->getMinFilter() == GL_LINEAR_MIPMAP_LINEAR
) )
333 OSGGETGLFUNCBYID_GL3_ES( glGenerateMipmap
,
335 _uiFuncGenerateMipmap
,
338 glBindTexture(target
, win
->getGLObjectId(pTexObj
->getGLId()));
340 osgGlGenerateMipmap(target
);
344 /*----------------------- constructors & destructors ----------------------*/
346 TextureBuffer::TextureBuffer(void) :
351 TextureBuffer::TextureBuffer(const TextureBuffer
&source
) :
356 TextureBuffer::~TextureBuffer(void)
360 /*----------------------------- class specific ----------------------------*/
362 void TextureBuffer::initMethod(InitPhase ePhase
)
364 Inherited::initMethod(ePhase
);
366 if(ePhase
== TypeObject::SystemPost
)
368 _uiFramebuffer_object_extension
=
369 Window::registerExtension("GL_ARB_framebuffer_object");
371 _uiFuncFramebufferTexture1D
=
372 Window::registerFunction (
373 OSG_DLSYM_UNDERSCORE
"glFramebufferTexture1D",
374 _uiFramebuffer_object_extension
);
376 _uiFuncFramebufferTexture2D
=
377 Window::registerFunction (
378 OSG_DLSYM_UNDERSCORE
"glFramebufferTexture2D",
379 _uiFramebuffer_object_extension
);
381 _uiFuncFramebufferTexture3D
=
382 Window::registerFunction (
383 OSG_DLSYM_UNDERSCORE
"glFramebufferTexture3D",
384 _uiFramebuffer_object_extension
);
386 _uiFuncFramebufferTextureLayer
=
387 Window::registerFunction (
388 OSG_DLSYM_UNDERSCORE
"glFramebufferTextureLayer",
389 _uiFramebuffer_object_extension
);
391 _uiFuncGenerateMipmap
=
392 Window::registerFunction (
393 OSG_DLSYM_UNDERSCORE
"glGenerateMipmap",
394 _uiFramebuffer_object_extension
);
399 void TextureBuffer::changed(ConstFieldMaskArg whichField
,
403 Inherited::changed(whichField
, origin
, details
);
406 void TextureBuffer::dump( UInt32
,
407 const BitVector
) const
409 SLOG
<< "Dump TextureBuffer NI" << std::endl
;