Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Hardware/Video/OpenGL/Buffers/FrameBufferObject/glFrameBufferObject.cpp

Diff revisions: vs.
  @@ -1,19 +1,20 @@
1 1 #include "Headers/glFrameBufferObject.h"
2 2 #include "Hardware/Video/OpenGL/Headers/glResources.h"
3 + #include "Hardware/Video/OpenGL/Textures/Headers/glSamplerObject.h"
4 +
3 5 #include "core.h"
4 - #include "Hardware/Video/Headers/GFXDevice.h"
5 6 #include "Core/Headers/ParamHandler.h"
7 + #include "Hardware/Video/Headers/GFXDevice.h"
6 8
7 - bool glFrameBufferObject::Create(GLushort width,
8 - GLushort height,
9 - GLubyte imageLayers)
9 + bool glFrameBufferObject::Create(GLushort width, GLushort height, GLubyte imageLayers)
10 10 {
11 11 _width = width;
12 12 _height = height;
13 13 _imageLayers = imageLayers;
14 -
14 + _clearBufferMask = 0;
15 15 assert(!_attachement.empty());
16 -
16 + bool hasColor = false;
17 + bool hasDepth = false;
17 18 if(_frameBufferHandle <= 0){
18 19 GLCheck(glGenFramebuffers(1, &_frameBufferHandle));
19 20 }
  @@ -36,20 +37,24 @@
36 37 GLenum internalFormat = glImageFormatTable[texDescriptor._internalFormat];
37 38 GLenum dataType = glDataFormat[texDescriptor._dataType];
38 39
40 + const SamplerDescriptor& sampler = texDescriptor.getSampler();
41 +
39 42 //generate a new texture attachement
40 43 if(slot != TextureDescriptor::Depth){
41 44 GLCheck(glGenTextures( 1, &_textureId[slot] ));
42 45 GLCheck(glBindTexture(_textureType, _textureId[slot]));
43 46
47 + hasColor = true;
44 48 //anisotrophic filtering is only added to color attachements
45 - if (texDescriptor._anisotrophyLevel > 1 && texDescriptor._generateMipMaps) {
49 + if (sampler.anisotrophyLevel() > 1 && sampler.generateMipMaps()) {
46 50 if(!glewIsSupported("GL_EXT_texture_filter_anisotropic")){
47 51 ERROR_FN(Locale::get("ERROR_NO_ANISO_SUPPORT"));
48 52 }else{
49 - GLCheck(glTexParameteri(_textureType, GL_TEXTURE_MAX_ANISOTROPY_EXT,texDescriptor._anisotrophyLevel));
53 + U8 anisoLevel = std::min<I32>((I32)sampler.anisotrophyLevel(), ParamHandler::getInstance().getParam<U8>("rendering.anisotropicFilteringLevel"));
54 + GLCheck(glTexParameteri(_textureType, GL_TEXTURE_MAX_ANISOTROPY_EXT,anisoLevel));
50 55 }
51 56 }
52 - if(texDescriptor._generateMipMaps){
57 + if(sampler.generateMipMaps()){
53 58 //(depth doesn't need mipmaps)
54 59 GLCheck(glTexParameteri(_textureType, GL_TEXTURE_BASE_LEVEL, texDescriptor._mipMinLevel));
55 60 GLCheck(glTexParameteri(_textureType, GL_TEXTURE_MAX_LEVEL, texDescriptor._mipMaxLevel));
  @@ -57,27 +62,27 @@
57 62 }else{//or a depth texture, depending on the slot
58 63 GLCheck(glGenTextures( 1, &_depthId ));
59 64 GLCheck(glBindTexture(_textureType, _depthId));
60 -
65 + hasDepth = true;
61 66 //depth attachements may need comparison functions
62 - if(texDescriptor._useRefCompare){
67 + if(sampler._useRefCompare){
63 68 GLCheck(glTexParameteri(_textureType, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE));
64 - GLCheck(glTexParameteri(_textureType, GL_TEXTURE_COMPARE_FUNC, glCompareFuncTable[texDescriptor._cmpFunc]));
65 - GLCheck(glTexParameteri(_textureType, GL_DEPTH_TEXTURE_MODE, glImageFormatTable[texDescriptor._depthCompareMode]));
69 + GLCheck(glTexParameteri(_textureType, GL_TEXTURE_COMPARE_FUNC, glCompareFuncTable[sampler._cmpFunc]));
70 + GLCheck(glTexParameteri(_textureType, GL_DEPTH_TEXTURE_MODE, glImageFormatTable[sampler._depthCompareMode]));
66 71 }
67 72 }
68 73
69 74 //General texture parameters for either color or depth
70 - GLCheck(glTexParameterf(_textureType, GL_TEXTURE_MAG_FILTER, glTextureFilterTable[texDescriptor._magFilter]));
71 - GLCheck(glTexParameterf(_textureType, GL_TEXTURE_MIN_FILTER, glTextureFilterTable[texDescriptor._minFilter]));
72 - GLCheck(glTexParameterf(_textureType, GL_TEXTURE_WRAP_S, glWrapTable[texDescriptor._wrapU]));
75 + GLCheck(glTexParameterf(_textureType, GL_TEXTURE_MAG_FILTER, glTextureFilterTable[sampler.magFilter()]));
76 + GLCheck(glTexParameterf(_textureType, GL_TEXTURE_MIN_FILTER, glTextureFilterTable[sampler.minFilter()]));
77 + GLCheck(glTexParameterf(_textureType, GL_TEXTURE_WRAP_S, glWrapTable[sampler.wrapU()]));
73 78
74 79 //Anything other then a 1D texture, needs a T-wrap mode
75 80 if(_textureType != GL_TEXTURE_1D){
76 - GLCheck(glTexParameterf(_textureType, GL_TEXTURE_WRAP_T, glWrapTable[texDescriptor._wrapV]));
81 + GLCheck(glTexParameterf(_textureType, GL_TEXTURE_WRAP_T, glWrapTable[sampler.wrapV()]));
77 82 }
78 83 //3D texture types need a R-wrap mode
79 84 if(_textureType == GL_TEXTURE_3D || _textureType == GL_TEXTURE_CUBE_MAP || _textureType == GL_TEXTURE_CUBE_MAP_ARRAY) {
80 - GLCheck(glTexParameterf(_textureType, GL_TEXTURE_WRAP_R, glWrapTable[texDescriptor._wrapW]));
85 + GLCheck(glTexParameterf(_textureType, GL_TEXTURE_WRAP_R, glWrapTable[sampler.wrapW()]));
81 86 }
82 87
83 88 //generate empty texture data using each texture type's specific function
  @@ -154,7 +159,7 @@
154 159 if(slot != TextureDescriptor::Depth){
155 160 depthAttachment = false;
156 161 //Generate mip maps for color attachements
157 - if(texDescriptor._generateMipMaps){
162 + if(sampler.generateMipMaps()){
158 163 if(glGenerateMipmap != NULL) GLCheck(glGenerateMipmap(_textureType));
159 164 else ERROR_FN(Locale::get("ERROR_NO_MIP_MAPS"));
160 165 }
  @@ -223,13 +228,20 @@
223 228 GLCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthBufferHandle));
224 229 }
225 230 GLCheck(glBindRenderbuffer(GL_RENDERBUFFER,0));
231 + hasDepth = true;
226 232 }
227 233
228 234 //If color writes are disabled, draw only depth info
229 235 if(_disableColorWrites){
230 236 GLCheck(glDrawBuffer(GL_NONE));
231 237 GLCheck(glReadBuffer(GL_NONE));
238 + hasColor = false;
232 239 }
240 +
241 + if(hasColor)
242 + _clearBufferMask = _clearBufferMask | GL_COLOR_BUFFER_BIT;
243 + if(hasDepth)
244 + _clearBufferMask = _clearBufferMask | GL_DEPTH_BUFFER_BIT;
233 245
234 246 checkStatus();
235 247
  @@ -261,17 +273,23 @@
261 273 _depthBufferHandle = 0;
262 274 }
263 275
264 - _width = 0;
265 - _height = 0;
276 + _width = _height = 0;
266 277 }
267 278
268 - void glFrameBufferObject::Bind(GLubyte unit, GLubyte texture) {
279 + void glFrameBufferObject::BlitFrom(FrameBufferObject* inputFBO) const {
280 + GLCheck(glBindFramebuffer(GL_READ_FRAMEBUFFER, inputFBO->getHandle()));
281 + GLCheck(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, this->_frameBufferHandle));
282 + GLCheck(glBlitFramebuffer(0, 0, inputFBO->getWidth(), inputFBO->getHeight(), 0, 0, this->_width, this->_height, GL_COLOR_BUFFER_BIT, GL_NEAREST));
283 + GLCheck(glBindFramebuffer(GL_FRAMEBUFFER, 0));
284 + }
285 +
286 + void glFrameBufferObject::Bind(GLubyte unit, GLubyte texture) const {
269 287 FrameBufferObject::Bind(unit,texture);
270 288 GL_API::setActiveTextureUnit(unit);
271 289 GLCheck(glBindTexture(_textureType, _textureId[texture]));
272 290 }
273 291
274 - void glFrameBufferObject::Unbind(GLubyte unit) {
292 + void glFrameBufferObject::Unbind(GLubyte unit) const {
275 293 FrameBufferObject::Unbind(unit);
276 294 GL_API::setActiveTextureUnit(unit);
277 295 GLCheck(glBindTexture(_textureType, 0 ));
  @@ -279,22 +297,22 @@
279 297
280 298 void glFrameBufferObject::Begin(GLubyte nFace) const {
281 299 assert(nFace<6);
282 - GL_API::setViewport(0,0,_width,_height);
300 + GL_API::setViewport(vec4<U32>(0,0,_width,_height));
283 301 GLCheck(glBindFramebuffer(GL_FRAMEBUFFER, _frameBufferHandle));
284 302 if(_textureType == GL_TEXTURE_CUBE_MAP) {
285 303 GLCheck(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X+nFace, _textureId[0], 0));
286 304 }
287 - GLCheck(glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ));
288 - GL_API::clearColor(0.0f, 0.0f, 0.0f, 1.0f );
305 + GLCheck(glClear(_clearBufferMask));
306 + GL_API::clearColor( _clearColor );
289 307 }
290 308
291 309 void glFrameBufferObject::End(GLubyte nFace) const {
292 310 assert(nFace<6);
293 311 GLCheck(glBindFramebuffer(GL_FRAMEBUFFER, 0));
294 - GL_API::restoreViewport();
312 + GL_API::restoreViewport();
295 313 }
296 314
297 - bool glFrameBufferObject::checkStatus() {
315 + bool glFrameBufferObject::checkStatus() const {
298 316 //Not defined in GLEW
299 317 #define GL_FRAMEBUFFER_INCOMPLETE_FORMATS 0x8CDA
300 318 #define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9
  @@ -343,11 +361,4 @@
343 361 return false;
344 362 }
345 363 };
346 - }
347 -
348 - void glFrameBufferObject::BlitFrom(FrameBufferObject* inputFBO){
349 - GLCheck(glBindFramebuffer(GL_READ_FRAMEBUFFER, inputFBO->getHandle()));
350 - GLCheck(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, this->_frameBufferHandle));
351 - GLCheck(glBlitFramebuffer(0, 0, inputFBO->getWidth(), inputFBO->getHeight(), 0, 0, this->_width, this->_height, GL_COLOR_BUFFER_BIT, GL_NEAREST));
352 - GLCheck(glBindFramebuffer(GL_FRAMEBUFFER, 0));
353 364 }