1 // OpenCSG - library for image-based CSG rendering for OpenGL
2 // Copyright (C) 2006-2016, Florian Kirsch
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License,
6 // Version 2, as published by the Free Software Foundation.
7 // As a special exception, you have permission to link this library
8 // with the CGAL library and distribute executables.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 //
20 // pBufferTexture.h
21 //
22 // RenderTexture wrapper class implementing the offscreen buffer interface
23 //
24 
25 #ifndef __OpenCSG__pbuffer_texture_h__
26 #define __OpenCSG__pbuffer_texture_h__
27 
28 #include "opencsgConfig.h"
29 #include "offscreenBuffer.h"
30 
31 #ifdef OPENCSG_HAVE_PBUFFER
32 
33 class RenderTexture;
34 
35 namespace OpenCSG {
36 
37     namespace OpenGL {
38 
39         class PBufferTexture : public OffscreenBuffer {
40         public:
41             // ctor / dtor
42             PBufferTexture();
43             virtual ~PBufferTexture();
44 
45             /// Nothing to do here.
46             virtual bool ReadCurrent();
47 
48             /// Call this once before use.  Set bShare to true to share lists, textures,
49             /// and program objects between the render texture context and the
50             /// current active GL context.
51             virtual bool Initialize(int width, int height, bool shareObjects=true, bool copyContext=false);
52 
53             /// checks whether Initialize has been called before or not
54             virtual bool IsInitialized() const;
55 
56             /// Change the render texture format.
57             virtual bool Reset();
58             /// Change the size of the render texture.
59             virtual bool Resize(int width, int height);
60 
61             /// Begin drawing to the texture. (i.e. use as "output" texture)
62             virtual bool BeginCapture();
63             /// End drawing to the texture.
64             virtual bool EndCapture();
65 
66             /// Bind the texture to the active texture unit for use as an "input" texture
67             virtual void Bind() const;
68 
69             /// Enables the texture target appropriate for this render texture.
70             virtual void EnableTextureTarget() const;
71             /// Disables the texture target appropriate for this render texture.
72             virtual void DisableTextureTarget() const;
73 
74             /// Returns the texture target this texture is bound to.
75             virtual unsigned int GetTextureTarget() const;
76             /// Returns the width of the offscreen buffer.
77             virtual int GetWidth() const;
78             /// Returns the width of the offscreen buffer.
79             virtual int GetHeight() const;
80 
81             /// PBuffers have a separate rendering context (which is, in the case
82             /// of OpenCSG, shared with the main context, i.e., we can use display
83             /// lists uva. in both contexts
haveSeparateContext()84             virtual bool haveSeparateContext() const { return true; }
85 
86         protected:
87             RenderTexture* r;
88             const char*    s;
89 
90         private:
91             PBufferTexture(const PBufferTexture&);
92             PBufferTexture& operator=(const PBufferTexture&);
93 
94         };
95 
96     } // namespace OpenGL
97 
98 } // namespace OpenCSG
99 
100 #endif // OPENCSG_HAVE_PBUFFER
101 
102 #endif // __OpenCSG__pbuffer_texture_h__
103