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 "OSGLayeredTextureBuffer.h"
52 #include "OSGWindow.h"
53 #include "OSGDrawEnv.h"
54 #include "OSGTextureObjChunk.h"
59 typedef void (OSG_APIENTRY
*osgGlFramebufferTextureProc
) (GLenum target
,
65 UInt32
LayeredTextureBuffer::_uiGeoShader4_extension
=
66 Window::invalidExtensionID
;
68 UInt32
LayeredTextureBuffer::_uiFramebuffer_object_extension
=
69 Window::invalidExtensionID
;
71 UInt32
LayeredTextureBuffer::_uiFuncFramebufferTexture
=
72 Window::invalidFunctionID
;
74 UInt32
LayeredTextureBuffer::_uiFuncGenerateMipmap
=
75 Window::invalidFunctionID
;
77 // Documentation for this class is emited in the
78 // OSGLayeredTextureBufferBase.cpp file.
79 // To modify it, please change the .fcd file (OSGLayeredTextureBuffer.fcd) and
80 // regenerate the base file.
82 void LayeredTextureBuffer::bind(DrawEnv
*pEnv
, UInt32 index
)
84 Window
*pWindow
= pEnv
->getWindow();
86 if(_sfTexture
.getValue() != NULL
)
88 pWindow
->validateGLObject(_sfTexture
.getValue()->getGLId(), pEnv
);
92 if(getTexTarget() != GL_NONE
)
94 target
= getTexTarget();
98 target
= _sfTexture
.getValue()->determineTextureTarget(pWindow
);
103 case GL_TEXTURE_CUBE_MAP_ARRAY
:
104 case GL_TEXTURE_2D_ARRAY
:
107 OSGGETGLFUNCBYID_GL3( glFramebufferTexture
,
108 osgGlFramebufferTexture
,
109 _uiFuncFramebufferTexture
,
112 osgGlFramebufferTexture(
115 pWindow
->getGLObjectId(_sfTexture
.getValue()->getGLId()),
123 void LayeredTextureBuffer::validate(DrawEnv
*pEnv
)
125 Window
*pWindow
= pEnv
->getWindow();
127 if(_sfTexture
.getValue() != NULL
)
129 pWindow
->validateGLObject(_sfTexture
.getValue()->getGLId(), pEnv
);
133 void LayeredTextureBuffer::resizeBuffers(UInt32 uiWidth
, UInt32 uiHeight
)
135 TextureObjChunk
*pTex
= this->getTexture();
140 Image
*pImg
= pTex
->getImage();
145 pImg
->set(pImg
->getPixelFormat(), //Image::OSG_RGB_PF,
149 pImg
->getMipMapCount(),
150 pImg
->getFrameCount (),
151 pImg
->getFrameDelay (),
153 pImg
->getDataType (), //Image::OSG_UINT8_IMAGEDATA,
155 pImg
->getSideCount ());
158 GLenum
LayeredTextureBuffer::getBufferFormat(void) const
160 TextureObjChunk
*pTex
= this->getTexture();
165 if(pTex
->getInternalFormat() != GL_NONE
)
166 return pTex
->getInternalFormat();
168 Image
*pImg
= pTex
->getImage();
173 return pImg
->getPixelFormat();
177 void LayeredTextureBuffer::processPreDeactivate(DrawEnv
*pEnv
, UInt32 index
)
180 if(_sfReadBack
.getValue() == true)
182 TextureObjChunk
*pTexObj
= this->getTexture();
187 Image
*pTexImg
= pTexObj
->getImage();
189 if(pTexImg
->getData() == NULL
)
191 SINFO
<< "TextureBuffer::render: (Re)Allocating image "
195 pTexImg
->set(pTexImg
->getPixelFormat(),
196 pTexImg
->getWidth (),
197 pTexImg
->getHeight (),
198 pTexImg
->getDepth (),
199 pTexImg
->getMipMapCount(),
200 pTexImg
->getFrameCount (),
201 pTexImg
->getFrameDelay (),
203 pTexImg
->getDataType (),
205 pTexImg
->getSideCount () );
208 UInt32 mipMapLevel
= _sfLevel
.getValue();
212 Window
*pWindow
= pEnv
->getWindow();
214 if(_sfTexTarget
.getValue() != GL_NONE
)
216 target
= _sfTexTarget
.getValue();
220 target
= _sfTexture
.getValue()->determineTextureTarget(pWindow
);
225 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
228 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
231 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
234 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
237 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
240 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
245 // select GL_COLORATTACHMENTn and read data into image
250 pTexImg
->getWidth (),
251 pTexImg
->getHeight (),
252 pTexImg
->getPixelFormat(),
253 pTexImg
->getDataType (),
254 pTexImg
->editData (mipMapLevel
, frame
, side
));
257 glReadBuffer(GL_NONE
);
263 void LayeredTextureBuffer::processPostDeactivate(DrawEnv
*pEnv
)
265 Window
*win
= pEnv
->getWindow();
267 // If there are TextureBuffers with mipmap filters attached,
268 // the mipmaps need to be regenerated
269 TextureObjChunk
*pTexObj
= this->getTexture();
274 GLenum target
= pTexObj
->determineTextureTarget(win
);
275 if((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
276 target
== GL_TEXTURE_2D_ARRAY
||
277 target
== GL_TEXTURE_3D
) &&
278 (pTexObj
->getMinFilter() == GL_NEAREST_MIPMAP_NEAREST
||
279 pTexObj
->getMinFilter() == GL_LINEAR_MIPMAP_NEAREST
||
280 pTexObj
->getMinFilter() == GL_NEAREST_MIPMAP_LINEAR
||
281 pTexObj
->getMinFilter() == GL_LINEAR_MIPMAP_LINEAR
) )
283 OSGGETGLFUNCBYID_GL3_ES( glGenerateMipmap
,
285 _uiFuncGenerateMipmap
,
288 glBindTexture(target
, win
->getGLObjectId(pTexObj
->getGLId()));
290 osgGlGenerateMipmap(target
);
294 /*----------------------- constructors & destructors ----------------------*/
296 LayeredTextureBuffer::LayeredTextureBuffer(void) :
301 LayeredTextureBuffer::LayeredTextureBuffer(const LayeredTextureBuffer
&source
) :
306 LayeredTextureBuffer::~LayeredTextureBuffer(void)
310 /*----------------------------- class specific ----------------------------*/
312 void LayeredTextureBuffer::initMethod(InitPhase ePhase
)
314 Inherited::initMethod(ePhase
);
316 if(ePhase
== TypeObject::SystemPost
)
318 _uiGeoShader4_extension
=
319 Window::registerExtension("GL_ARB_geometry_shader4");
321 _uiFramebuffer_object_extension
=
322 Window::registerExtension("GL_ARB_framebuffer_object");
324 _uiFuncFramebufferTexture
=
325 Window::registerFunction (
326 OSG_DLSYM_UNDERSCORE
"glFramebufferTexture",
327 _uiGeoShader4_extension
);
329 _uiFuncGenerateMipmap
=
330 Window::registerFunction (
331 OSG_DLSYM_UNDERSCORE
"glGenerateMipmap",
332 _uiFramebuffer_object_extension
);
337 void LayeredTextureBuffer::changed(ConstFieldMaskArg whichField
,
341 Inherited::changed(whichField
, origin
, details
);
344 void LayeredTextureBuffer::dump( UInt32
,
345 const BitVector
) const
347 SLOG
<< "Dump TextureBuffer NI" << std::endl
;