- Timestamp:
- 08/22/08 13:20:06 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
r2859 r2861 9 9 { 10 10 11 GLenum color_attachment[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT}; 11 12 12 13 void PrintFBOStatus(GLenum status) … … 15 16 { 16 17 case GL_FRAMEBUFFER_COMPLETE_EXT: 17 cout << "frame buffer object c reated successfully" << endl;18 cout << "frame buffer object complete" << endl; 18 19 break; 19 20 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: … … 45 46 46 47 ColorBufferObject::ColorBufferObject(int w, int h, 47 FORMAT c,48 FORMAT format, 48 49 WRAP_TYPE wrapType, 49 50 FILTER_TYPE filterType, 50 51 bool useMipMap, 51 bool useMultiSampling) 52 bool useMultiSampling, 53 int attachment_idx) 52 54 { 55 GLuint glformat, internalFormat; 56 57 58 switch (format) 59 { 60 case BUFFER_UBYTE: 61 glformat = GL_UNSIGNED_BYTE; internalFormat = GL_RGBA8; break; 62 case BUFFER_FLOAT_16: 63 glformat = GL_FLOAT; internalFormat = GL_RGBA16F_ARB; break; 64 case BUFFER_FLOAT_32: 65 glformat = GL_FLOAT; internalFormat = GL_RGBA32F_ARB; break; 66 default: 67 glformat = GL_UNSIGNED_BYTE; internalFormat = GL_RGBA8; 68 cerr << "should not come here" << endl; 69 } 70 53 71 glGenRenderbuffersEXT(1, &mId); 54 72 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mId); 55 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h);73 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalFormat, w, h); 56 74 57 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_RENDERBUFFER_EXT, mId);75 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, color_attachment[attachment_idx], GL_RENDERBUFFER_EXT, mId); 58 76 59 77 glGenTextures(1, &mTexId); 60 78 glBindTexture(GL_TEXTURE_2D, mTexId); 61 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 62 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, mTexId, 0); 79 //glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, GL_RGBA, glformat, NULL); 80 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, GL_RGBA, glformat, NULL); 81 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, color_attachment[attachment_idx], GL_TEXTURE_2D, mTexId, 0); 63 82 64 83 GLuint filterParam; … … 72 91 case FILTER_MIPMAP_LINEAR: 73 92 filterParam = GL_LINEAR_MIPMAP_LINEAR; break; 93 default: 94 filterParam = GL_NEAREST; 95 cerr << "should not come here" << endl; 74 96 } 75 97 … … 96 118 97 119 98 FrameBufferObject::FrameBufferObject(int w, int h, bool useDepth,DEPTH_FORMAT d)120 FrameBufferObject::FrameBufferObject(int w, int h, DEPTH_FORMAT d) 99 121 : mWidth(w), mHeight(h) 100 122 { … … 102 124 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mId); 103 125 104 126 cout << "creating fbo" << endl; 127 105 128 /////////// 106 129 //-- create depth buffer 107 130 108 if ( useDepth)131 if (d != DEPTH_NONE) 109 132 { 110 133 glGenRenderbuffersEXT(1, &mDepthId); 111 134 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mDepthId); 135 136 cout << "adding depth buffer" << endl; 112 137 113 138 GLuint depthFormat; … … 121 146 case DEPTH_32: 122 147 depthFormat = GL_DEPTH_COMPONENT32; break; 148 default: 149 cerr << "should not come here" << endl; 123 150 } 124 151 … … 126 153 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mDepthId); 127 154 } 128 129 // print status130 PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));131 155 } 132 156 … … 138 162 bool useMultiSampling) 139 163 { 164 cout << "adding color buffer" << endl; 165 166 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mId); 167 168 int idx = (int)mColorBuffers.size(); 140 169 ColorBufferObject *colorBuf = 141 new ColorBufferObject(mWidth, mHeight, col, wrapType, filterType, useMipMap, useMultiSampling); 170 new ColorBufferObject(mWidth, mHeight, col, wrapType, filterType, useMipMap, useMultiSampling, idx); 171 142 172 mColorBuffers.push_back(colorBuf); 143 173 144 return (int)mColorBuffers.size() - 1; 174 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 175 176 return idx; 177 } 178 179 180 void FrameBufferObject::Bind() const 181 { 182 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mId); 183 } 184 185 186 void FrameBufferObject::Release() 187 { 188 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 145 189 } 146 190
Note: See TracChangeset
for help on using the changeset viewer.