File: PBufferTexture2D.h

package info (click to toggle)
openscenegraph 1.2.0-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 26,924 kB
  • ctags: 25,229
  • sloc: cpp: 239,326; ansic: 2,178; sh: 1,990; yacc: 548; perl: 237; makefile: 227; lex: 151
file content (58 lines) | stat: -rw-r--r-- 2,130 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
 *
 * This application is open source and may be redistributed and/or modified   
 * freely and without restriction, both in commericial and non commericial applications,
 * as long as this copyright notice is maintained.
 * 
 * This application is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

#ifndef PBUFFER_TEXTURE_2D_DEF
#define PBUFFER_TEXTURE_2D_DEF

#include <Producer/RenderSurface>
#include <osg/Texture2D>

class PBufferTexture2D : public osg::Texture2D
{
    public:
        PBufferTexture2D( Producer::RenderSurface *pbuffer ):
            _pbuffer(pbuffer) {}

        virtual void apply(osg::State& state) const
        {
            const unsigned int contextID = state.getContextID();

            TextureObject* textureObject = getTextureObject(contextID);
            if( textureObject == 0 )
            {
                GLuint format = 
                    _pbuffer->getRenderToTextureMode() == Producer::RenderSurface::RenderToRGBTexture ? GL_RGB:
                    _pbuffer->getRenderToTextureMode() == Producer::RenderSurface::RenderToRGBATexture ? GL_RGBA : 0 ;
                unsigned int width  = _pbuffer->getWindowWidth();
                unsigned int height = _pbuffer->getWindowHeight();

                _textureObjectBuffer[contextID] = textureObject = 
                    generateTextureObject( contextID, GL_TEXTURE_2D, 1, format, width, height, 1, 0 );

                textureObject->bind();
                applyTexParameters( GL_TEXTURE_2D, state);

                glTexImage2D( GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, 0 );
                textureObject->setAllocated(true);
            }
            else
            {
                textureObject->bind();
                _pbuffer->bindPBufferToTexture( Producer::RenderSurface::FrontBuffer );
            }
        }

    private:
        Producer::ref_ptr<Producer::RenderSurface> _pbuffer;
};

#endif