source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTexture.h @ 2808

Revision 2808, 7.2 KB checked in by mattausch, 16 years ago (diff)
Line 
1//------------------------------------------------------------------------------
2// File : rendertexture.h
3//------------------------------------------------------------------------------
4// Copyright 2002 Mark J. Harris and
5// The University of North Carolina at Chapel Hill
6//------------------------------------------------------------------------------
7// Permission to use, copy, modify, distribute and sell this software and its
8// documentation for any purpose is hereby granted without fee, provided that
9// the above copyright notice appear in all copies and that both that copyright
10// notice and this permission notice appear in supporting documentation.
11// Binaries may be compiled with this software without any royalties or
12// restrictions.
13//
14// The author(s) and The University of North Carolina at Chapel Hill make no
15// representations about the suitability of this software for any purpose.
16// It is provided "as is" without express or implied warranty.
17// -----------------------------------------------------------------------------
18// Credits:
19// Original RenderTexture code: Mark J. Harris
20// Original Render-to-depth-texture support: Thorsten Scheuermann
21// Linux Copy-to-texture: Eric Werness
22// Various Bug Fixes: Daniel (Redge) Sperl
23//                    Bill Baxter
24//
25// -----------------------------------------------------------------------------
26/**
27 * @file RenderTexture.h
28 *
29 * Interface definition for class RenderTexture.  A multi-format render to
30 * texture wrapper.
31 */
32#ifndef __RENDERTEXTURE_HPP__
33#define __RENDERTEXTURE_HPP__
34
35#include <GL/glew.h>
36#ifdef _WIN32
37#include <GL/wglew.h>
38#else
39#include <GL/glxew.h>
40#endif
41
42class RenderTexture
43{
44public: // enums
45  enum UpdateMode
46  {
47    RT_RENDER_TO_TEXTURE,
48    RT_COPY_TO_TEXTURE
49  };
50 
51public: // interface
52  RenderTexture(int iWidth, int iHeight,
53                bool bIsTexture = true,
54                bool bIsDepthTexture = false);
55  ~RenderTexture();
56
57  //! Call this once before use.  Set bShare to true to share lists, textures,
58  //! and program objects between the render texture context and the
59  //! current active GL context.
60  bool Initialize(bool bShare             = true,
61                  bool bDepth             = false,
62                  bool bStencil           = false,
63                  bool bMipmap            = false,
64                  bool bAnisoFilter       = false,
65                  unsigned int iRBits     = 8,
66                  unsigned int iGBits     = 8,
67                  unsigned int iBBits     = 8,
68                  unsigned int iABits     = 8,
69                  // Only Win32 has RT now, so only make it default there
70#ifdef _WIN32
71                  UpdateMode   updateMode = RT_RENDER_TO_TEXTURE
72#else
73                              UpdateMode   updateMode = RT_COPY_TO_TEXTURE
74#endif
75);
76
77  // !Change the render texture resolution.
78  bool Reset(int iWidth, int iHeight, bool bIsTexture = true,
79             bool bIsDepthTexture = false);
80
81  // !Begin drawing to the texture. (i.e. use as "output" texture)
82  bool BeginCapture();
83  // !End drawing to the texture.
84  bool EndCapture();
85
86  // [Redge] 'const's added
87  // !Bind the texture to the active texture unit for use as an "input" texture
88  void Bind() const;   // [Redge] moved definition to cpp-file (since it's longer now)
89  // !Bind the depth texture to the active texture unit for use as an "input" texture
90  void BindDepth() const;  // [Redge] moved definition to cpp-file
91
92  //! Enables the texture target appropriate for this render texture.
93  void EnableTextureTarget() const { if (_bInitialized) glEnable(_iTextureTarget); }
94  //! Disables the texture target appropriate for this render texture.
95  void DisableTextureTarget() const { if (_bInitialized) glDisable(_iTextureTarget); }
96  // [/Redge]
97
98  //! Returns the texture ID.  Useful in Cg applications.
99  unsigned int GetTextureID() const { return _iTextureID; }
100  //! Returns the depth texture ID.  Useful in Cg applications.
101  unsigned int GetDepthTextureID() const { return _iDepthTextureID; }
102  //! Returns the texture target this texture is bound to.
103  unsigned int GetTextureTarget() const { return _iTextureTarget; }
104
105  //! Returns the width of the offscreen buffer.
106  int GetWidth() const   { return _iWidth;  }
107  //! Returns the width of the offscreen buffer.
108  int GetHeight() const  { return _iHeight; }     
109
110  //! Returns the number of red bits allocated.
111  int GetRedBits() const   { return _iBits[0]; }
112  //! Returns the number of green bits allocated.
113  int GetGreenBits() const { return _iBits[1]; }
114  //! Returns the number of blue bits allocated.
115  int GetBlueBits() const  { return _iBits[2]; }
116  //! Returns the number of alpha bits allocated.
117  int GetAlphaBits() const { return _iBits[3]; }
118  //! Returns the number of depth bits allocated.
119  int GetDepthBits() const { return _iBits[4]; }
120  //! Returns the number of stencil bits allocated.
121  int GetStencilBits() const { return _iBits[5]; }
122
123  //! True if this RenderTexture has been properly initialized.
124  bool IsInitialized() const      { return _bInitialized; }
125  //! True if this is a texture and not just an offscreen buffer.
126  bool IsTexture() const          { return _bIsTexture; }
127  //! True if this is a depth texture and not just an offscreen buffer.
128  bool IsDepthTexture() const     { return _bIsDepthTexture; }
129  //! True if this is a floating point buffer / texture.
130  bool IsFloatTexture() const     { return _bFloat; }
131  //! True if this texture has non-power-of-two dimensions.
132  bool IsRectangleTexture() const { return _bRectangle; }
133  //! True if this pbuffer has a depth buffer.
134  bool HasDepth() const           { return _bHasDepth; }
135  //! True if this pbuffer has a stencil buffer.
136  bool HasStencil() const         { return _bHasStencil; }
137  //! True if this texture has mipmaps.
138  bool IsMipmapped() const        { return _bMipmap; }
139  //! True if this texture is anisotropically filtered.
140  bool HasAnisoFilter() const     { return _bAnisoFilter; }
141
142protected: // methods
143  bool         _Invalidate();
144#ifdef _WIN32
145  void         _wglGetLastError();
146#endif
147
148protected: // data
149  int          _iWidth;     // width of the pbuffer
150  int          _iHeight;    // height of the pbuffer
151
152  bool         _bIsTexture;
153  bool         _bIsDepthTexture;
154  bool         _bHasArbDepthTexture; // [Redge]
155
156  UpdateMode   _eUpdateMode;
157 
158  bool         _bInitialized;
159
160  unsigned int _iBits[6];
161  bool         _bFloat;
162  bool         _bRectangle;
163  bool         _bHasDepth;
164  bool         _bHasStencil;
165  bool         _bMipmap;
166  bool         _bAnisoFilter;
167 
168#ifdef _WIN32
169  HDC          _hDC;        // Handle to a device context.
170  HGLRC        _hGLContext; // Handle to a GL context.
171  HPBUFFERARB  _hPBuffer;   // Handle to a pbuffer.
172
173  HDC          _hPreviousDC;
174  HGLRC        _hPreviousContext;
175#else
176  Display      *_pDpy;
177  GLXContext   _hGLContext;
178  GLXPbuffer   _hPBuffer;
179
180  GLXDrawable  _hPreviousDrawable;
181  GLXContext   _hPreviousContext;
182#endif
183 
184  GLenum       _iTextureTarget;
185  unsigned int _iTextureID;
186  unsigned int _iDepthTextureID;
187
188  unsigned short* _pPoorDepthTexture; // [Redge]
189};
190
191#endif //__RENDERTEXTURE_HPP__
Note: See TracBrowser for help on using the repository browser.