#include <GLRenderTarget.h>
Inheritance diagram for GLRenderTarget:

This is a texture that can be written to and then bound later for use as a normal texture.
Definition at line 18 of file GLRenderTarget.h.
Public Member Functions | |
| virtual void | bind () const |
| Bind this texture. | |
| uint | height () const |
| Return the height of the texture. | |
| uint | id () const |
| Return the texture ID. | |
| virtual boolean | isValid () const |
| Is this a valid texture? | |
| const char * | name () const |
| Get the name. | |
| void | prepare () const |
| Bind the target. | |
| virtual uint | type () const |
| Get the type, e.g. GL_TEXTURE_2D. | |
| void | upload () const |
| Copy the framebuffer. | |
| uint | width () const |
| Return the width of the texture. | |
Static Public Member Functions | |
| static GLRenderTarget * | Create (const std::string &szName, uint width, uint height, uint channels) |
| Create a render target. | |
| static void | SetDefaultTarget () |
| Set the default target. | |
Protected Member Functions | |
| GLRenderTarget (const char *szName, uint ID, uint CBuf, uint DBuf, uint W, uint H) | |
| Constructor. | |
| virtual | ~GLRenderTarget () |
| Destructor. | |
Static Protected Member Functions | |
| static uint | GetFormat (uint bpp) |
| Get the format. | |
| static byte * | LoadImageData (const std::string &szName, uint &width, uint &height, uint &bytespp) |
| Load image data. | |
Protected Attributes | |
| uint | m_ColourBuffer |
| The colour and depth buffer IDs. | |
| uint | m_DepthBuffer |
| uint | m_Height |
| uint | m_ID |
| The texture ID. | |
| std::string | m_Name |
| The name. | |
| uint | m_Width |
| GLRenderTarget * GLRenderTarget::Create | ( | const std::string & | szName, | |
| uint | width, | |||
| uint | height, | |||
| uint | channels | |||
| ) | [static] |
Create a render target.
Use GL_DEPTH_COMPONENT in channels and type for shadow maps
Definition at line 26 of file GLRenderTarget.cpp.
References GLRenderTarget(), SetDefaultTarget(), and IGLTexture::type().
Referenced by GLSpotLight::createShadowMaps(), and Logic::Logic().
00027 { 00028 uint ID = 0; 00029 uint ColourBuffer = 0; 00030 uint DepthBuffer = 0; 00031 00032 #ifdef NO_FRAMEBUFFER_OBJS 00033 00034 // If the channels flag is > 4, then we should have a special 00035 // flag in type. (Thanks to GameTutorials.com for this) 00036 uint type = GL_RGBA; 00037 uint bytespp = channels; 00038 switch ( channels ) 00039 { 00040 case 1: type = GL_LUMINANCE; break; 00041 case 2: type = GL_LUMINANCE_ALPHA; break; 00042 case 3: type = GL_RGB; break; 00043 case 4: type = GL_RGBA; break; 00044 default: 00045 type = channels; 00046 bytespp = 1; 00047 break; 00048 } 00049 00050 // Create the buffer 00051 byte * tex = new byte[width * height * bytespp]; 00052 if ( !tex ) 00053 { 00054 LOG( szName.c_str(), "Failed to create RTT buffer" ); 00055 return 0; 00056 } 00057 00058 // Generate a texture 00059 glGenTextures( 1, &ID ); 00060 00061 // Bind it 00062 glBindTexture( GL_TEXTURE_2D, ID ); 00063 00064 // Create the image 00065 glTexImage2D( GL_TEXTURE_2D, 0, channels, width, height, 0, type, GL_UNSIGNED_BYTE, tex ); 00066 00067 // Set the parameters 00068 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 00069 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 00070 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); 00071 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); 00072 00073 // glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE ); 00074 00075 // Delete the array 00076 delete [] tex; 00077 00078 LOG( "RTT", "Created target %s", szName.c_str() ); 00079 00080 #else 00081 00082 // Create the colour buffer 00083 glGenFramebuffersEXT( 1, &ColourBuffer ); 00084 00085 // Create a depth buffer 00086 glGenRenderbuffersEXT( 1, &DepthBuffer ); 00087 00088 // Create a texture for our colour buffer 00089 glGenTextures( 1, &ID ); 00090 00091 // Bind the colour buffer so we can set our texture parameters 00092 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, ColourBuffer ); 00093 00094 // Bind the texture 00095 glBindTexture( GL_TEXTURE_2D, ID ); 00096 00097 // Set the filtering level 00098 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00099 00100 // Set the texture parameters 00101 glTexImage2D(GL_TEXTURE_2D, 0, channels, width, height, 0, type, GL_INT, 0 ); 00102 00103 // Attach the framebuffer to the texture 00104 glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, ID, 0); 00105 00106 // Bind the depth buffer 00107 glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, DepthBuffer ); 00108 00109 // Set the storage type 00110 glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height ); 00111 00112 // Bind the buffer to the framebuffer 00113 glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, DepthBuffer ); 00114 00115 // Check the status 00116 if ( glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ) != GL_FRAMEBUFFER_COMPLETE_EXT ) 00117 { 00118 LOG( "RT", "Couldn't construct full framebuffer of size %dx%d", width, height ); 00119 return 0; 00120 } 00121 00122 LOG( "RTT", "Constructed FBO target %s", szName.c_str() ); 00123 00124 #endif 00125 00126 // Set the default target 00127 SetDefaultTarget(); 00128 00129 // Create the target 00130 return new GLRenderTarget( szName.c_str(), ID, ColourBuffer, DepthBuffer, width, height ); 00131 }
1.5.1-p1