00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _SO_FRAME_BUFFER_H_
00024 #define _SO_FRAME_BUFFER_H_
00025
00026 #include <Inventor/SbBasic.h>
00027 #include <Inventor/SbLinear.h>
00028 #include <Inventor/sys/SoGLType.h>
00029
00030 #include <Inventor/SoGLRenderToBuffer.h>
00031
00032 #include <Inventor/STL/vector>
00033
00034 class SoGLRenderBuffer;
00035 class SoState;
00036 class SoGLTexture;
00037 class SoGLObjectCache;
00038
00039 #ifdef _WIN32
00040 #pragma warning( push )
00041 #pragma warning(disable:4251)
00042 #endif
00043 class SoDEPRECATED SoFrameBufferObject : public SoGLRenderToBuffer {
00067
00068 public:
00070 enum Attachment
00071 {
00073 COLOR_ATTACHMENT0,
00075 COLOR_ATTACHMENT1,
00077 COLOR_ATTACHMENT2,
00079 COLOR_ATTACHMENT3,
00081 COLOR_ATTACHMENT4,
00083 COLOR_ATTACHMENT5,
00085 COLOR_ATTACHMENT6,
00087 COLOR_ATTACHMENT7,
00089 COLOR_ATTACHMENT8,
00091 COLOR_ATTACHMENT9,
00093 COLOR_ATTACHMENT10,
00095 COLOR_ATTACHMENT11,
00097 COLOR_ATTACHMENT12,
00099 COLOR_ATTACHMENT13,
00101 COLOR_ATTACHMENT14,
00103 COLOR_ATTACHMENT15,
00105 DEPTH_ATTACHMENT,
00107 STENCIL_ATTACHMENT,
00109 DEPTH_STENCIL_ATTACHMENT,
00111 LAST_ATTACHMENT
00112 };
00113
00119 SoFrameBufferObject();
00120
00124 ~SoFrameBufferObject();
00125
00129 static void initClass();
00130
00134 static void exitClass();
00135
00141 static SbBool isAvailable( SoState* state = NULL );
00142
00148 static SbBool isMultisamplingAvailable( SoState* state = NULL );
00149
00153 static int getMaxSamples( SoState* state = NULL );
00154
00158 void setSamplesCount(int samples);
00159
00165 int getActualSamplesCount() const;
00166
00170 SbBool resize(const SbVec2s &size);
00171
00175 SbVec2s getSize() const;
00176
00181 void setRenderToTexture(SbBool enable, TextureFormat format = TEXTURE_RGB,
00182 TextureTarget target = TEXTURE_2D, SbBool autoMipmap = FALSE,
00183 SbBool hasDepth = FALSE);
00184
00188 GLuint getTexture() const;
00189
00193 GLenum getTextureFormat() const;
00194
00198 GLenum getTextureTarget() const;
00199
00203 SbBool bind(SoState* state = NULL, bool bindMultisampleFBO = true);
00204
00208 void unbind();
00209
00216 void flush(SoState* state = NULL);
00217
00222 SbBool bindToTexture(SbBool bindDepth = FALSE, GLuint texObj=-1);
00223
00229 SbBool create(SbVec2s size);
00230
00236 SbBool create(SbVec2i32 size);
00237
00243 SbBool resize(const SbVec2i32 &size);
00244
00250 const SbVec2i32& getSize_i32() const;
00251
00252 #if 1 SoDEPRECATED
00255 SbBool makeCurrent();
00256 SoDEPRECATED
00258 void disable();
00259 SoDEPRECATED
00261 void setGraphicConfigTemplate(SoGLGraphicConfigTemplate* gTemplate);
00262 SoDEPRECATED
00264 SoGLGraphicConfigTemplate* getGraphicConfigTemplate();
00265 SoDEPRECATED
00267 void setPixelFormat(int format);
00268 SoDEPRECATED
00270 int getPixelFormat();
00271 SoDEPRECATED
00273 SbBool releaseTexImage(SbBool bindDepth = FALSE );
00274 SoDEPRECATED
00276 SbBool selectCubeMapFace(CubeMapTextureFace face);
00277 SoDEPRECATED
00279 void setDisplayConnection(SbGlContextHelper::Display) { };
00280 SoDEPRECATED
00282 void setContextForSharing(SoGLContext * SO_UNUSED_PARAM(context)) { };
00283
00284 #endif
00286 private:
00287
00289 GLuint getId(SoState* state = NULL);
00290
00292 GLenum getStatus() const;
00293
00297 bool isValid() const;
00298
00302 SoGLRenderBuffer* getDepthRenderBuffer() const
00303 { return m_depthRenderBuffer;}
00304
00310 bool attachTexture2D(Attachment attachment, GLenum target,
00311 GLuint texId, int level);
00316 bool attachTexture1D(Attachment attachement, GLuint texId, int level);
00317
00322 bool attachTexture2D(Attachment attachement, GLuint texId, int level);
00323
00328 bool attachTexture2DArray(Attachment attachement, GLuint texId, int level, int layer);
00329
00334 bool attachTexture3D(Attachment attachement, GLuint texId, int level, int zoffset);
00335
00341 bool attachTextureCubeMap(Attachment attachment, GLuint texId, int level,
00342 CubeMapTextureFace face);
00343
00348 bool attachTexture1D(SoState* state, Attachment attachement,
00349 SoGLTexture* tex, int level);
00350
00355 bool attachTexture2D(SoState* state, Attachment attachement, SoGLTexture* tex, int level);
00356
00361 bool attachTexture2DArray(SoState* state, Attachment attachement, SoGLTexture* tex,
00362 int level, int layer);
00363
00368 bool attachTexture3D(SoState* state, Attachment attachement, SoGLTexture* tex,
00369 int level, int zoffset);
00370
00376 bool attachTexture(SoState* state, Attachment att, SoGLTexture* tex, int level = 0, int layer = 0);
00377
00383 bool attachTextureCubeMap(SoState* state, Attachment attachment, SoGLTexture* tex,
00384 int level, CubeMapTextureFace face);
00385
00390 bool attachRenderBuffer(SoState* state, Attachment attachement, SoGLRenderBuffer* renderBuffer);
00391
00396 bool attachRenderBuffer(Attachment attachement, GLuint renderBufferId);
00397
00401 SoGLTexture* getTextureAttachment(Attachment attachment);
00402
00406 SoGLRenderBuffer* getRenderBufferAttachment(Attachment attachment);
00407
00412 SbBool checkStatus() const;
00413
00415 bool isValid(SoState* state);
00416
00420 static GLenum getGLAttachment(Attachment attachment);
00421
00422
00423 private:
00424
00425 SbBool bindInternal(SoState* state = NULL, bool bindMultisampleFBO = true);
00426
00427 bool attachRenderBuffer(Attachment attachment, GLuint renderBufferId, bool createMultisampled);
00428
00433 TextureFormat graphicConfigTemplateToTextureFormat(SoGLGraphicConfigTemplate *gct);
00434
00439 TextureFormat getDepth(SoGLGraphicConfigTemplate *gct);
00440
00444 int getMaxPow2Bits(SbVec4i32 bits);
00445
00450 bool update(SoState* state = NULL);
00451
00455 void setupMSAA(SoState* state);
00456
00460 void blitMSAA(SoState* state);
00461
00465 void clearMSAA(SoState* state);
00466
00467
00468 SbVec2i32 m_size;
00469 bool m_needResize;
00470
00471 SbBool m_renderToTexture;
00472 SbBool m_autoMipmap;
00473 SbBool m_hasDepth;
00474 GLenum m_textureFormat;
00475 TextureFormat m_textureFormatIV;
00476 GLenum m_textureTarget;
00477
00478
00479 GLuint m_internalTexID;
00480 SoGLRenderBuffer* m_depthRenderBuffer;
00481
00482 SoGLObjectCache* m_fboCache;
00483
00484
00485 bool m_needUpdate;
00486
00487
00488 std::vector<GLint> m_previousFboIds;
00489
00490
00491
00492 std::vector<SoGLTexture*> m_attachedTextures;
00493 std::vector<SoGLRenderBuffer*> m_attachedRenderBuffers;
00494
00495
00496 int m_numSamples;
00497 SoGLObjectCache* m_fboMSAACache;
00498 std::vector<SoGLRenderBuffer*> m_attachedMSAARenderBuffers;
00499
00500 SoGLRenderBuffer* m_depthRenderBufferMSAA;
00501 SoGLRenderBuffer* m_internalTexMSAA;
00502
00503
00504 bool m_fboBlited;
00505
00506 static int s_framebuffer_extensionID;
00507 static int s_framebuffer_blit_extensionID;
00508 static int s_framebuffer_multisample_extensionID;
00509 static int s_ogl12_extensionID;
00510 };
00511
00512
00513
00514 #ifdef _WIN32
00515 #pragma warning( pop )
00516 #endif
00517
00518 #endif // _SO_FRAME_BUFFER_H_
00519
00520
00521