fixed: compile issue
[opensg.git] / Source / System / Window / FrameBufferObjects / OSGLayeredTextureBuffer.cpp
blobdb2cd53fa0a004c1ad9e87cfbad6b65eb47db8ab
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
47 #include "OSGGL.h"
48 #include "OSGGLEXT.h"
49 #include "OSGGLFuncProtos.h"
51 #include "OSGLayeredTextureBuffer.h"
52 #include "OSGWindow.h"
53 #include "OSGDrawEnv.h"
54 #include "OSGTextureObjChunk.h"
55 #include "OSGImage.h"
57 OSG_BEGIN_NAMESPACE
59 typedef void (OSG_APIENTRY *osgGlFramebufferTextureProc) (GLenum target,
60 GLenum attachment,
61 GLuint texture,
62 GLint level );
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);
90 GLenum target;
92 if(getTexTarget() != GL_NONE)
94 target = getTexTarget();
96 else
98 target = _sfTexture.getValue()->determineTextureTarget(pWindow);
101 switch(target)
103 case GL_TEXTURE_CUBE_MAP_ARRAY:
104 case GL_TEXTURE_2D_ARRAY:
105 case GL_TEXTURE_3D:
107 OSGGETGLFUNCBYID_GL3( glFramebufferTexture,
108 osgGlFramebufferTexture,
109 _uiFuncFramebufferTexture,
110 pWindow);
112 osgGlFramebufferTexture(
113 GL_FRAMEBUFFER,
114 index,
115 pWindow->getGLObjectId(_sfTexture.getValue()->getGLId()),
118 break;
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();
137 if(pTex == NULL)
138 return;
140 Image *pImg = pTex->getImage();
142 if(pImg == NULL)
143 return;
145 pImg->set(pImg->getPixelFormat(), //Image::OSG_RGB_PF,
146 uiWidth,
147 uiHeight,
148 pImg->getDepth (),
149 pImg->getMipMapCount(),
150 pImg->getFrameCount (),
151 pImg->getFrameDelay (),
152 NULL,
153 pImg->getDataType (), //Image::OSG_UINT8_IMAGEDATA,
154 false,
155 pImg->getSideCount ());
158 GLenum LayeredTextureBuffer::getBufferFormat(void) const
160 TextureObjChunk *pTex = this->getTexture();
162 if(pTex == NULL)
163 return GL_NONE;
165 if(pTex->getInternalFormat() != GL_NONE)
166 return pTex->getInternalFormat();
168 Image *pImg = pTex->getImage();
170 if(pImg == NULL)
171 return GL_NONE;
173 return pImg->getPixelFormat();
177 void LayeredTextureBuffer::processPreDeactivate(DrawEnv *pEnv, UInt32 index)
179 #if 0
180 if(_sfReadBack.getValue() == true)
182 TextureObjChunk *pTexObj = this->getTexture();
184 if(pTexObj == NULL)
185 return;
187 Image *pTexImg = pTexObj->getImage();
189 if(pTexImg->getData() == NULL)
191 SINFO << "TextureBuffer::render: (Re)Allocating image "
192 << "for read-back."
193 << endLog;
195 pTexImg->set(pTexImg->getPixelFormat(),
196 pTexImg->getWidth (),
197 pTexImg->getHeight (),
198 pTexImg->getDepth (),
199 pTexImg->getMipMapCount(),
200 pTexImg->getFrameCount (),
201 pTexImg->getFrameDelay (),
202 NULL,
203 pTexImg->getDataType (),
204 true,
205 pTexImg->getSideCount () );
208 UInt32 mipMapLevel = _sfLevel.getValue();
209 UInt32 frame = 0;
210 UInt32 side = 0;
211 GLenum target;
212 Window *pWindow = pEnv->getWindow();
214 if(_sfTexTarget.getValue() != GL_NONE)
216 target = _sfTexTarget.getValue();
218 else
220 target = _sfTexture.getValue()->determineTextureTarget(pWindow);
223 switch(target)
225 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
226 side = 0;
227 break;
228 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
229 side = 1;
230 break;
231 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
232 side = 2;
233 break;
234 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
235 side = 3;
236 break;
237 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
238 side = 4;
239 break;
240 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
241 side = 5;
242 break;
245 // select GL_COLORATTACHMENTn and read data into image
246 #ifndef OSG_OGL_ES2
247 glReadBuffer(index);
248 #endif
249 glReadPixels(0, 0,
250 pTexImg->getWidth (),
251 pTexImg->getHeight (),
252 pTexImg->getPixelFormat(),
253 pTexImg->getDataType (),
254 pTexImg->editData (mipMapLevel, frame, side));
256 #ifndef OSG_OGL_ES2
257 glReadBuffer(GL_NONE);
258 #endif
260 #endif
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();
271 if(pTexObj == NULL)
272 return;
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,
284 osgGlGenerateMipmap,
285 _uiFuncGenerateMipmap,
286 win);
288 glBindTexture(target, win->getGLObjectId(pTexObj->getGLId()));
290 osgGlGenerateMipmap(target);
294 /*----------------------- constructors & destructors ----------------------*/
296 LayeredTextureBuffer::LayeredTextureBuffer(void) :
297 Inherited()
301 LayeredTextureBuffer::LayeredTextureBuffer(const LayeredTextureBuffer &source) :
302 Inherited(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,
338 UInt32 origin,
339 BitVector details)
341 Inherited::changed(whichField, origin, details);
344 void LayeredTextureBuffer::dump( UInt32 ,
345 const BitVector ) const
347 SLOG << "Dump TextureBuffer NI" << std::endl;
350 OSG_END_NAMESPACE