osg.FrameBufferAttachment
是 OpenSceneGraph 中代表帧缓冲附件的类。它可以用于将图像纹理、渲染缓冲区或纹理数组作为帧缓冲的一部分。
FrameBufferAttachment(Texture* texture, GLenum attachment);
FrameBufferAttachment(RenderBuffer* renderBuffer, GLenum attachment);
setAttachment
inline void setAttachment(GLenum attachment) { _attachment=attachment; }
设置帧缓冲附件的 GL 枚举文件中的附件点值。
getAttachment
inline GLenum getAttachment() const { return _attachment; }
获取帧缓冲附件的 GL 枚举文件中的附件点值。
getTexture
inline Texture* getTexture() const { return _texture.get(); }
获取帧缓冲附件的纹理。
getRenderBuffer
inline RenderBuffer* getRenderBuffer() const { return _renderBuffer.get(); }
获取帧缓冲附件的渲染缓冲区。
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
// ...
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setTextureSize(width, height);
texture->setInternalFormat(GL_RGBA);
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);
texture->setUnRefImageDataAfterApply(true);
texture->setResizeNonPowerOfTwoHint(false);
osg::ref_ptr<osg::FrameBufferAttachment> fba = new osg::FrameBufferAttachment(texture, GL_COLOR_ATTACHMENT0);
GLuint renderBufferID;
glGenRenderbuffers(1, &renderBufferID);
glBindRenderbuffer(GL_RENDERBUFFER, renderBufferID);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
osg::ref_ptr<osg::RenderBuffer> renderBuffer = new osg::RenderBuffer;
renderBuffer->setInternalFormat(GL_DEPTH_COMPONENT);
renderBuffer->setFrameBufferObject(renderBufferID);
osg::ref_ptr<osg::FrameBufferAttachment> fba = new osg::FrameBufferAttachment(renderBuffer, GL_DEPTH_ATTACHMENT);