1 // BEGIN_COPYRIGHT -*- glean -*-
3 // Copyrigth (C) 2007 Intel Corporation
4 // Copyright (C) 1999 Allen Akin All Rights Reserved.
6 // Permission is hereby granted, free of charge, to any person
7 // obtaining a copy of this software and associated documentation
8 // files (the "Software"), to deal in the Software without
9 // restriction, including without limitation the rights to use,
10 // copy, modify, merge, publish, distribute, sublicense, and/or
11 // sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
20 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
21 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 // DEALINGS IN THE SOFTWARE.
31 // Shuang He <shuang.he@intel.com>
33 // tfbo.cpp: Test OpenGL Extension GL_EXT_framebuffer_object
36 #define GL_GLEXT_PROTOTYPES
48 static PFNGLTEXIMAGE3DPROC glTexImage3D_func
= NULL
;
49 static PFNGLCOPYTEXSUBIMAGE3DPROC glCopyTexSubImage3D_func
= NULL
;
52 static PFNGLACTIVETEXTUREPROC glActiveTexture_func
= NULL
;
53 static PFNGLMULTITEXCOORD2FPROC glMultiTexCoord2f_func
= NULL
;
55 // GL_EXT_framebuffer_object
56 static PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT_func
= NULL
;
57 static PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT_func
= NULL
;
58 static PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT_func
= NULL
;
59 static PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT_func
= NULL
;
60 static PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT_func
= NULL
;
61 static PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT_func
= NULL
;
62 static PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT_func
= NULL
;
63 static PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT_func
= NULL
;
64 static PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT_func
= NULL
;
65 static PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT_func
= NULL
;
66 static PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT_func
= NULL
;
67 static PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT_func
= NULL
;
68 static PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT_func
= NULL
;
69 static PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT_func
= NULL
;
70 static PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT_func
= NULL
;
71 static PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT_func
= NULL
;
73 static int useFramebuffer
;
78 // setup vertex transform (we'll draw a quad in middle of window)
79 glMatrixMode(GL_PROJECTION
);
82 gluOrtho2D(0, 100, 0, 100);
83 glMatrixMode(GL_MODELVIEW
);
85 glDrawBuffer(GL_FRONT
);
86 glReadBuffer(GL_FRONT
);
90 // compute error tolerances (may need fine-tuning)
93 glGetIntegerv(GL_RED_BITS
, &bufferBits
[0]);
94 glGetIntegerv(GL_GREEN_BITS
, &bufferBits
[1]);
95 glGetIntegerv(GL_BLUE_BITS
, &bufferBits
[2]);
96 glGetIntegerv(GL_ALPHA_BITS
, &bufferBits
[3]);
97 glGetIntegerv(GL_DEPTH_BITS
, &bufferBits
[4]);
99 tolerance
[0] = 3.0 / (1 << bufferBits
[0]);
100 tolerance
[1] = 3.0 / (1 << bufferBits
[1]);
101 tolerance
[2] = 3.0 / (1 << bufferBits
[2]);
103 tolerance
[3] = 3.0 / (1 << bufferBits
[3]);
107 tolerance
[4] = 16.0 / (1 << bufferBits
[4]);
111 // Check if GL_EXT_framebuffer_object is supported
112 if (GLUtils::haveExtension("GL_EXT_framebuffer_object")) {
113 printf("GL_EXT_framebuffer_object is supported\n");
117 printf("GL_EXT_framebuffer_object is not supported\n");
122 haveARBfbo
= GLUtils::haveExtension("GL_ARB_framebuffer_object");
124 printf("GL_ARB_framebuffer_object is supported\n");
126 printf("GL_ARB_framebuffer_object is not supported\n");
128 glTexImage3D_func
= (PFNGLTEXIMAGE3DPROC
) GLUtils::getProcAddress("glTexImage3D");
129 assert(glTexImage3D_func
);
130 glCopyTexSubImage3D_func
= (PFNGLCOPYTEXSUBIMAGE3DPROC
) GLUtils::getProcAddress("glCopyTexSubImage3D");
131 assert(glCopyTexSubImage3D_func
);
133 glActiveTexture_func
= (PFNGLACTIVETEXTUREPROC
) GLUtils::getProcAddress("glActiveTexture");
134 assert(glActiveTexture_func
);
135 glMultiTexCoord2f_func
= (PFNGLMULTITEXCOORD2FPROC
) GLUtils::getProcAddress("glMultiTexCoord2f");
136 assert(glMultiTexCoord2f_func
);
138 glIsRenderbufferEXT_func
= (PFNGLISRENDERBUFFEREXTPROC
) GLUtils::getProcAddress("glIsRenderbufferEXT");
139 assert(glIsRenderbufferEXT_func
);
140 glBindRenderbufferEXT_func
= (PFNGLBINDRENDERBUFFEREXTPROC
) GLUtils::getProcAddress("glBindRenderbufferEXT");
141 assert(glBindRenderbufferEXT_func
);
142 glDeleteRenderbuffersEXT_func
= (PFNGLDELETERENDERBUFFERSEXTPROC
) GLUtils::getProcAddress("glDeleteRenderbuffersEXT");
143 assert(glDeleteRenderbuffersEXT_func
);
144 glGenRenderbuffersEXT_func
= (PFNGLGENRENDERBUFFERSEXTPROC
) GLUtils::getProcAddress("glGenRenderbuffersEXT");
145 assert(glGenRenderbuffersEXT_func
);
146 glRenderbufferStorageEXT_func
= (PFNGLRENDERBUFFERSTORAGEEXTPROC
) GLUtils::getProcAddress("glRenderbufferStorageEXT");
147 assert(glRenderbufferStorageEXT_func
);
148 glGetRenderbufferParameterivEXT_func
= (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC
) GLUtils::getProcAddress("glGetRenderbufferParameterivEXT");
149 assert(glGetRenderbufferParameterivEXT_func
);
150 glIsFramebufferEXT_func
= (PFNGLISFRAMEBUFFEREXTPROC
) GLUtils::getProcAddress("glIsFramebufferEXT");
151 assert(glIsFramebufferEXT_func
);
152 glBindFramebufferEXT_func
= (PFNGLBINDFRAMEBUFFEREXTPROC
) GLUtils::getProcAddress("glBindFramebufferEXT");
153 assert(glBindFramebufferEXT_func
);
154 glDeleteFramebuffersEXT_func
= (PFNGLDELETEFRAMEBUFFERSEXTPROC
) GLUtils::getProcAddress("glDeleteFramebuffersEXT");
155 assert(glDeleteFramebuffersEXT_func
);
156 glGenFramebuffersEXT_func
= (PFNGLGENFRAMEBUFFERSEXTPROC
) GLUtils::getProcAddress("glGenFramebuffersEXT");
157 assert(glGenFramebuffersEXT_func
);
158 glCheckFramebufferStatusEXT_func
= (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC
) GLUtils::getProcAddress("glCheckFramebufferStatusEXT");
159 assert(glCheckFramebufferStatusEXT_func
);
160 glFramebufferTexture1DEXT_func
= (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC
) GLUtils::getProcAddress("glFramebufferTexture1DEXT");
161 assert(glFramebufferTexture1DEXT_func
);
162 glFramebufferTexture2DEXT_func
= (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC
) GLUtils::getProcAddress("glFramebufferTexture2DEXT");
163 assert(glFramebufferTexture2DEXT_func
);
164 glFramebufferTexture3DEXT_func
= (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC
) GLUtils::getProcAddress("glFramebufferTexture3DEXT");
165 assert(glFramebufferTexture3DEXT_func
);
166 glFramebufferRenderbufferEXT_func
= (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC
) GLUtils::getProcAddress("glFramebufferRenderbufferEXT");
167 assert(glFramebufferRenderbufferEXT_func
);
168 glGetFramebufferAttachmentParameterivEXT_func
= (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC
) GLUtils::getProcAddress("glGetFramebufferAttachmentParameterivEXT");
169 assert(glGetFramebufferAttachmentParameterivEXT_func
);
176 FBOTest::reportFailure(const char *msg
, const int line
) const
178 env
->log
<< "FAILURE: " << msg
<< " (at tfbo.cpp:" << line
183 FBOTest::reportFailure(const char *msg
, const GLenum target
, const int line
) const
185 env
->log
<< "FAILURE: " << msg
;
186 if (target
== GL_FRAGMENT_SHADER
)
187 env
->log
<< " (fragment)";
189 env
->log
<< " (vertex)";
190 env
->log
<< " (at tfbo.cpp:" << line
<< ")\n";
193 #define REPORT_FAILURE(MSG) reportFailure(MSG, __LINE__)
194 #define REPORT_FAILURE_T(MSG, TARGET) reportFailure(MSG, TARGET, __LINE__)
195 // Compare actual and expected colors
197 FBOTest::equalColors(const GLfloat act
[3], const GLfloat exp
[3]) const
199 if ((fabsf(act
[0] - exp
[0]) > tolerance
[0])
200 || (fabsf(act
[1] - exp
[1]) > tolerance
[1])
201 || (fabsf(act
[2] - exp
[2]) > tolerance
[2])) {
212 |--------------------|
217 FBOTest::checkResult(const GLfloat color
[4], const int depth
,
218 const int stencil
) const
220 GLfloat buf
[TEXSIZE
* TEXSIZE
* 3];
222 const GLfloat black
[4] = { 0.0, 0.0, 0.0, 0.0 };
225 glReadPixels(0, 0, TEXSIZE
, TEXSIZE
, GL_RGB
, GL_FLOAT
, buf
);
227 for (j
= 0; j
< TEXSIZE
; j
++) {
228 for (i
= 0; i
< TEXSIZE
; i
++) {
231 if (i
* 4 >= TEXSIZE
&& i
* 8 < TEXSIZE
* 5
234 if (i
* 2 >= TEXSIZE
&& i
* 8 < TEXSIZE
* 7
239 if (!equalColors(buf
+ (j
* TEXSIZE
+ i
) * 3, exp
)) {
240 printf(" depth = %d, stencil = %d\n",
242 printf(" (%d, %d) = [%f, %f, %f], is expected to be[%f, %f, %f]\n", i
, j
, buf
[(j
* TEXSIZE
+ i
) * 3], buf
[(j
* TEXSIZE
+ i
) * 3 + 1], buf
[(j
* TEXSIZE
+ i
) * 3 + 2], exp
[0], exp
[1], exp
[2]);
251 // Check FB status, print unexpected results to stdout.
253 CheckFramebufferStatus(const char *func
, int line
)
256 status
= glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT
);
259 case GL_FRAMEBUFFER_COMPLETE_EXT
:
260 /*printf(" (%s:%d)GL_FRAMEBUFFER_COMPLETE_EXT\n", func, line);*/
262 case GL_FRAMEBUFFER_UNSUPPORTED_EXT
:
263 printf(" (%s:%d)GL_FRAMEBUFFER_UNSUPPORTED_EXT\n", func
, line
);
264 /* choose different formats */
266 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
:
267 printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT\n", func
, line
);
269 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
:
270 printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT\n", func
, line
);
272 case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
:
273 printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n", func
, line
);
275 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
:
276 printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT\n", func
, line
);
278 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
:
279 printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT\n", func
, line
);
281 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
:
282 printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT\n", func
, line
);
285 /* programming error; will fail on all hardware */
286 printf(" (%s:%d)programming error\n", func
, line
);
294 { BLACK
, RED
, GREEN
, BLUE
, WHITE
};
296 GLfloat colors
[][4] = {
297 {0.0, 0.0, 0.0, 0.0},
298 {1.0, 0.0, 0.0, 1.0},
299 {0.0, 1.0, 0.0, 1.0},
300 {0.0, 0.0, 1.0, 1.0},
307 FBOTest::testSanity(void)
310 GLuint maxColorAttachment
;
316 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT
,
317 (GLint
*) & maxColorAttachment
);
318 if (maxColorAttachment
< 1) {
320 ("Failed to get max color attachment points");
325 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT
, (GLint
*) & fb_binding
);
326 if (fb_binding
!= 0) {
327 printf(" fb_binding = %d\n", fb_binding
);
329 ("The default framebuffer binding should be 0");
333 glGenFramebuffersEXT_func(1, fbs
);
336 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
337 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT
, (GLint
*) & fb_binding
);
338 if (fb_binding
!= fbs
[0]) {
339 printf(" fb_binding = %d\n", fb_binding
);
340 REPORT_FAILURE("Binding framebuffer failed");
343 if (glIsFramebufferEXT_func(fbs
[0]) != GL_TRUE
)
345 REPORT_FAILURE("Call glIsFramebufferEXT failed");
349 glDeleteFramebuffersEXT_func(1, fbs
);
351 GLint maxRenderbufferSize
;
353 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT
, &maxRenderbufferSize
);
354 if (maxRenderbufferSize
< 1) {
355 printf(" maxRenderbufferSize = %d\n",
356 maxRenderbufferSize
);
357 REPORT_FAILURE("Get max Renderbuffer Size failed");
368 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, 0);
369 glDisable(GL_DEPTH_TEST
);
370 glDisable(GL_STENCIL_TEST
);
373 GLenum textureModes
[] = { GL_TEXTURE_1D
, GL_TEXTURE_2D
, GL_TEXTURE_3D
,
374 GL_TEXTURE_CUBE_MAP
};
377 FBOTest::testRender2SingleTexture(void)
379 GLint depthBuffer
= 0;
380 GLint stencilBuffer
= 0;
383 GLuint stencil_rb
[1];
389 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE
, &maxzoffset
);
393 for (depthBuffer
= 0; depthBuffer
< 2; depthBuffer
++) {
394 for (stencilBuffer
= 0; stencilBuffer
< 2; stencilBuffer
++) {
395 for (mode
= 0; mode
< 4; mode
++) {
398 // Setup state to test
400 if (mode
== 2 && maxzoffset
<= 0)
404 glGenFramebuffersEXT_func(1, fbs
);
405 glGenTextures(1, textures
);
407 glBindTexture(textureModes
[mode
],
409 glTexParameteri(textureModes
[mode
],
410 GL_TEXTURE_MIN_FILTER
,
412 glTexParameteri(textureModes
[mode
],
413 GL_TEXTURE_MAG_FILTER
,
416 switch (textureModes
[mode
]) {
418 glTexImage1D(GL_TEXTURE_1D
,
421 GL_RGB
, GL_INT
, NULL
);
424 glTexImage2D(GL_TEXTURE_2D
,
428 GL_RGB
, GL_INT
, NULL
);
431 glTexImage3D_func(GL_TEXTURE_3D
,
436 GL_RGB
, GL_INT
, NULL
);
438 case GL_TEXTURE_CUBE_MAP
:
440 (GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
443 0, GL_RGB
, GL_INT
, NULL
);
445 (GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
448 0, GL_RGB
, GL_INT
, NULL
);
450 (GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
453 0, GL_RGB
, GL_INT
, NULL
);
455 (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
458 0, GL_RGB
, GL_INT
, NULL
);
460 (GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
463 0, GL_RGB
, GL_INT
, NULL
);
465 (GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
468 0, GL_RGB
, GL_INT
, NULL
);
473 if (useFramebuffer
) {
474 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
475 int height
= TEXSIZE
;
477 if (textureModes
[mode
] == GL_TEXTURE_1D
)
483 glGenRenderbuffersEXT_func(1, depth_rb
);
486 glBindRenderbufferEXT_func
487 (GL_RENDERBUFFER_EXT
,
489 if (glIsRenderbufferEXT_func(depth_rb
[0]) != GL_TRUE
)
491 REPORT_FAILURE("Call glIsRenderbufferEXT failed\n");
495 glRenderbufferStorageEXT_func
496 (GL_RENDERBUFFER_EXT
,
499 glFramebufferRenderbufferEXT_func
501 GL_DEPTH_ATTACHMENT_EXT
,
504 glGetRenderbufferParameterivEXT_func
505 (GL_RENDERBUFFER_EXT
,
506 GL_RENDERBUFFER_WIDTH_EXT
,
508 if (params
!= TEXSIZE
) {
509 REPORT_FAILURE("Get Renderbuffer width failed");
510 printf("glGetRenderbufferParameterivEXT: %s\n", gluErrorString(glGetError()));
511 printf("width = %d\n", params
);
514 glGetRenderbufferParameterivEXT_func
515 (GL_RENDERBUFFER_EXT
,
516 GL_RENDERBUFFER_HEIGHT_EXT
,
518 if (params
!= height
) {
519 REPORT_FAILURE("Get Renderbuffer height failed");
520 printf("glGetRenderbufferParameterivEXT: %s\n", gluErrorString(glGetError()));
529 glGenRenderbuffersEXT_func(1, stencil_rb
);
530 glBindRenderbufferEXT_func(GL_RENDERBUFFER_EXT
, stencil_rb
[0]);
531 glRenderbufferStorageEXT_func
532 (GL_RENDERBUFFER_EXT
,
535 glFramebufferRenderbufferEXT_func
537 GL_STENCIL_ATTACHMENT_EXT
,
540 glGetFramebufferAttachmentParameterivEXT_func
542 GL_STENCIL_ATTACHMENT_EXT
,
543 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT
,
545 if (type
!= GL_RENDERBUFFER_EXT
) {
546 REPORT_FAILURE("Get Framebuffer attached object type failed");
547 printf("glGetFramebufferParameterivEXT: %s\n", gluErrorString(glGetError()));
548 printf("type = %d\n", type
);
553 switch (textureModes
[mode
]) {
558 glFramebufferTexture1DEXT_func
560 GL_COLOR_ATTACHMENT0_EXT
,
563 glGetFramebufferAttachmentParameterivEXT_func
565 GL_COLOR_ATTACHMENT0_EXT
,
566 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT
,
568 if ((GLuint
)name
!= textures
[0]) {
569 REPORT_FAILURE("Get Framebuffer attached texture name failed");
570 printf("glGetFramebufferParameterivEXT: %s\n", gluErrorString(glGetError()));
571 printf("name = %d\n", name
);
580 glFramebufferTexture2DEXT_func
582 GL_COLOR_ATTACHMENT0_EXT
,
585 glGetFramebufferAttachmentParameterivEXT_func
587 GL_COLOR_ATTACHMENT0_EXT
,
588 GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT
,
591 REPORT_FAILURE("Get Framebuffer attached texture level failed");
592 printf("glGetFramebufferParameterivEXT: %s\n", gluErrorString(glGetError()));
593 printf("level = %d\n", level
);
602 glFramebufferTexture3DEXT_func
604 GL_COLOR_ATTACHMENT0_EXT
,
610 glGetFramebufferAttachmentParameterivEXT_func
612 GL_COLOR_ATTACHMENT0_EXT
,
613 GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT
,
616 if (zoffset
!= maxzoffset
-1) {
617 REPORT_FAILURE("Get Framebuffer attached 3D texture z-offset failed");
618 printf("glGetFramebufferParameterivEXT: %s\n", gluErrorString(glGetError()));
619 printf("zoffset = %d\n", zoffset
);
623 case GL_TEXTURE_CUBE_MAP
:
626 glFramebufferTexture2DEXT_func
628 GL_COLOR_ATTACHMENT0_EXT
,
629 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
631 glGetFramebufferAttachmentParameterivEXT_func
633 GL_COLOR_ATTACHMENT0_EXT
,
634 GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT
,
637 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
)
639 REPORT_FAILURE("Get Framebuffer attached cube map face failed");
640 printf("glGetFramebufferParameterivEXT: %s\n", gluErrorString(glGetError()));
641 printf("face = %d\n", face
);
648 status
= CheckFramebufferStatus("FBOTest::testRender2SingleTexture", __LINE__
);
651 status
= GL_FRAMEBUFFER_COMPLETE_EXT
;
655 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
)
660 // Render, test the results
664 glClear(GL_DEPTH_BUFFER_BIT
);
666 glEnable(GL_DEPTH_TEST
);
667 glDepthFunc(GL_ALWAYS
);
668 switch (textureModes
[mode
]) {
671 glVertex3f(TEXSIZE
/ 4, 0, 0.3);
672 glVertex3f(TEXSIZE
* 5 / 8, 0, 0.3);
677 case GL_TEXTURE_CUBE_MAP
:
679 glVertex3f(TEXSIZE
/ 4, 0, 0.3);
680 glVertex3f(TEXSIZE
* 5 / 8, 0, 0.3);
681 glVertex3f(TEXSIZE
* 5 / 8, TEXSIZE
, 0.3);
682 glVertex3f(TEXSIZE
/ 4, TEXSIZE
, 0.3);
688 glDepthFunc(GL_LESS
);
692 glClear(GL_STENCIL_BUFFER_BIT
);
693 // Init stencil buffer
694 glEnable(GL_STENCIL_TEST
);
695 glStencilFunc(GL_ALWAYS
, 0x1, 0x1);
697 GL_KEEP
, GL_REPLACE
);
698 switch (textureModes
[mode
]) {
701 glVertex3f(TEXSIZE
/ 2, 0, 0.3);
702 glVertex3f(TEXSIZE
* 7 / 8, 0, 0.3);
707 case GL_TEXTURE_CUBE_MAP
:
709 glVertex3f(TEXSIZE
/ 2, 0, 0.3);
710 glVertex3f(TEXSIZE
* 7 / 8, 0, 0.3);
711 glVertex3f(TEXSIZE
* 7 / 8, TEXSIZE
, 0.3);
712 glVertex3f(TEXSIZE
/ 2, TEXSIZE
, 0.3);
719 glStencilFunc(GL_NOTEQUAL
, 0x1, 0x1);
722 // Render to the texture
723 glBindTexture(textureModes
[mode
], 0);
724 glDisable(textureModes
[mode
]);
725 glColor4fv(colors
[RED
]);
726 glClearColor(0.0, 0.0, 0.0, 0.0);
727 glClear(GL_COLOR_BUFFER_BIT
);
729 switch (textureModes
[mode
]) {
732 glVertex3f(0, 0, 0.2);
733 glVertex3f(TEXSIZE
, 0, 0.2);
738 case GL_TEXTURE_CUBE_MAP
:
740 glVertex3f(0, 0, 0.2);
741 glVertex3f(TEXSIZE
, 0, 0.2);
742 glVertex3f(TEXSIZE
, TEXSIZE
, 0.2);
743 glVertex3f(0, TEXSIZE
, 0.2);
748 // Render to the window
749 glEnable(textureModes
[mode
]);
750 glBindTexture(textureModes
[mode
],
752 if (useFramebuffer
) {
753 glBindFramebufferEXT_func
754 (GL_FRAMEBUFFER_EXT
, 0);
755 glBindTexture(textureModes
756 [mode
], textures
[0]);
759 switch (textureModes
[mode
]) {
775 glCopyTexSubImage3D_func
781 case GL_TEXTURE_CUBE_MAP
:
783 (GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
793 glDisable(GL_DEPTH_TEST
);
795 glDisable(GL_STENCIL_TEST
);
797 glEnable(textureModes
[mode
]);
798 glColor4fv(colors
[WHITE
]);
799 glClearColor(0.0, 0.0, 0.0, 0.0);
800 glClear(GL_COLOR_BUFFER_BIT
);
802 glTexParameteri (textureModes
[mode
], GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
803 glTexParameteri (textureModes
[mode
], GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
804 glTexParameteri (textureModes
[mode
], GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
806 if (textureModes
[mode
] !=
807 GL_TEXTURE_CUBE_MAP
) {
808 GLfloat depth
= 0.99+0.01;
810 glTexCoord3f(0.0, 0.0, depth
);
812 glTexCoord3f(1.0, 0.0, depth
);
813 glVertex2f(TEXSIZE
, 0);
814 glTexCoord3f(1.0, 1.0, depth
);
815 glVertex2f(TEXSIZE
, TEXSIZE
);
816 glTexCoord3f(0.0, 1.0, depth
);
817 glVertex2f(0, TEXSIZE
);
822 glTexCoord3f(-1.0, 1.0, 1.0);
824 glTexCoord3f(1.0, 1.0, 1.0);
825 glVertex2f(TEXSIZE
, 0);
826 glTexCoord3f(1.0, -1.0, 1.0);
827 glVertex2f(TEXSIZE
, TEXSIZE
);
828 glTexCoord3f(-1.0, -1.0, 1.0);
829 glVertex2f(0, TEXSIZE
);
833 glDeleteTextures(1, textures
);
835 glDeleteFramebuffersEXT_func(1, fbs
);
837 glDeleteRenderbuffersEXT_func(1, depth_rb
);
839 glDeleteRenderbuffersEXT_func(1, stencil_rb
);
842 if (checkResult(colors
[RED
], depthBuffer
, stencilBuffer
) == false) {
843 REPORT_FAILURE("Render to single texture failed");
844 printf(" mode = %d\n", mode
);
856 FBOTest::testRender2MultiTexture(void)
861 GLint maxColorAttachment
= 8;
864 enum { MULTI_FBO
, SINGLE_COLOR_ATTACH
, MULTI_COLOR_ATTACH
};
871 for (mode
= MULTI_FBO
; mode
< MULTI_COLOR_ATTACH
+ 1; mode
++) {
872 if (useFramebuffer
) {
873 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT
,
874 &maxColorAttachment
);
875 if (maxColorAttachment
< 1) {
876 REPORT_FAILURE("Failed to get max color attachment points");
881 numRender
= maxColorAttachment
;
882 numColorAttach
= maxColorAttachment
;
883 if (mode
== MULTI_FBO
)
884 numFBO
= maxColorAttachment
;
889 glGenFramebuffersEXT_func(numFBO
, fbs
);
893 glGetIntegerv(GL_MAX_TEXTURE_UNITS
, &maxTexUnits
);
894 glGenTextures(maxTexUnits
, textures
);
897 for (i
= 0; i
< numColorAttach
; i
++) {
900 if (i
> maxTexUnits
- 1)
901 idx
= maxTexUnits
- 1;
905 glActiveTexture_func(GL_TEXTURE0
+ idx
);
906 glBindTexture(GL_TEXTURE_2D
, textures
[idx
]);
907 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
,
908 TEXSIZE
, TEXSIZE
, 0, GL_RGB
,
911 if (useFramebuffer
) {
912 if (mode
== MULTI_FBO
)
913 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[i
]);
915 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
917 if (mode
!= SINGLE_COLOR_ATTACH
)
918 glFramebufferTexture2DEXT_func
920 GL_COLOR_ATTACHMENT0_EXT
+ i
,
924 glFramebufferTexture2DEXT_func
926 GL_COLOR_ATTACHMENT0_EXT
,
929 if (mode
!= SINGLE_COLOR_ATTACH
) {
930 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT
+ i
);
931 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT
+ i
);
934 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT
);
935 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT
);
937 CheckFramebufferStatus("FBOTest::testRender2MultiTexture", __LINE__
);
943 for (i
= 0; i
< numRender
; i
++) {
946 if (i
> maxTexUnits
- 1)
947 idx
= maxTexUnits
- 1;
952 if (useFramebuffer
) {
953 if (mode
== MULTI_FBO
)
954 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[i
]);
956 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
958 if (mode
== MULTI_COLOR_ATTACH
) {
959 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT
+ idx
);
960 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT
+ idx
);
963 CheckFramebufferStatus("FBOTest::testRender2MultiTexture", __LINE__
);
964 if (mode
== SINGLE_COLOR_ATTACH
) {
965 glFramebufferTexture2DEXT_func
967 GL_COLOR_ATTACHMENT0_EXT
,
973 glDisable(GL_TEXTURE_2D
);
975 // Render to the texture
976 glColor4fv(colors
[RED
+ i
% (WHITE
- RED
)]);
978 glClearColor(0.0, 0.0, 0.0, 0.0);
979 glClear(GL_COLOR_BUFFER_BIT
);
983 glVertex3f(TEXSIZE
, 0, 1);
984 glVertex3f(TEXSIZE
, TEXSIZE
, 1);
985 glVertex3f(0, TEXSIZE
, 1);
989 glEnable(GL_TEXTURE_2D
);
990 if (useFramebuffer
) {
991 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, 0);
992 glBindTexture(GL_TEXTURE_2D
, textures
[idx
]);
995 glBindTexture(GL_TEXTURE_2D
, textures
[idx
]);
996 glCopyTexImage2D(GL_TEXTURE_2D
, 0,
998 TEXSIZE
, TEXSIZE
, 0);
1004 glDeleteFramebuffersEXT_func(numFBO
, fbs
);
1007 // Render to the window
1008 for (i
= 0; i
< numRender
; i
++) {
1011 if (i
> maxTexUnits
- 1)
1012 idx
= maxTexUnits
- 1;
1016 glActiveTexture_func(GL_TEXTURE0
+ idx
);
1017 glEnable(GL_TEXTURE_2D
);
1018 glTexParameteri(GL_TEXTURE_2D
,
1019 GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1020 glTexParameteri(GL_TEXTURE_2D
,
1021 GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1022 glTexParameteri (GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1023 glTexParameteri (GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1025 glColor4fv(colors
[WHITE
]);
1026 glClearColor(0.0, 0.0, 0.0, 0.0);
1027 glClear(GL_COLOR_BUFFER_BIT
);
1028 glBegin(GL_POLYGON
);
1029 glMultiTexCoord2f_func(GL_TEXTURE0
+ idx
, 0, 0);
1030 glVertex3f(0, 0, 1);
1031 glMultiTexCoord2f_func(GL_TEXTURE0
+ idx
, 1, 0);
1032 glVertex3f(TEXSIZE
, 0, 1);
1033 glMultiTexCoord2f_func(GL_TEXTURE0
+ idx
, 1, 1);
1034 glVertex3f(TEXSIZE
, TEXSIZE
, 1);
1035 glMultiTexCoord2f_func(GL_TEXTURE0
+ idx
, 0, 1);
1036 glVertex3f(0, TEXSIZE
, 1);
1040 int exp
= (i
>= maxTexUnits
- 1) ? maxColorAttachment
- 1 : i
;
1042 if (checkResult(colors
[RED
+ (exp
% (WHITE
- RED
))], 0, 0) == false) {
1043 glDeleteTextures(maxTexUnits
, textures
);
1045 REPORT_FAILURE("Render to multi texture failed");
1049 glDisable(GL_TEXTURE_2D
);
1050 glActiveTexture_func(GL_TEXTURE0
);
1053 glDeleteTextures(maxTexUnits
, textures
);
1061 FBOTest::testRender2depthTexture(void)
1068 glGenFramebuffersEXT_func(1, fbs
);
1070 glGenTextures(1, textures
);
1071 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1072 glTexImage2D(GL_TEXTURE_2D
, 0, GL_DEPTH_COMPONENT
, TEXSIZE
,
1073 TEXSIZE
, 0, GL_DEPTH_COMPONENT
, GL_INT
, NULL
);
1075 if (useFramebuffer
) {
1076 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
1077 glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT
,
1078 GL_DEPTH_ATTACHMENT_EXT
,
1079 GL_TEXTURE_2D
, textures
[0], 0);
1080 glDrawBuffer(GL_NONE
);
1081 glReadBuffer(GL_NONE
);
1083 CheckFramebufferStatus("FBOTest::testRender2depthTexture", __LINE__
);
1085 glClear(GL_DEPTH_BUFFER_BIT
);
1086 glEnable(GL_DEPTH_TEST
);
1088 glDisable(GL_TEXTURE_2D
);
1090 // Render to the texture
1091 glColor4fv(colors
[RED
]);
1092 glClearColor(0.0, 0.0, 0.0, 0.0);
1093 glClear(GL_COLOR_BUFFER_BIT
);
1094 glBegin(GL_POLYGON
);
1095 glVertex3f(TEXSIZE
/ 4, 0, 0.5);
1096 glVertex3f(TEXSIZE
* 5 / 8, 0, 0.5);
1097 glVertex3f(TEXSIZE
* 5 / 8, TEXSIZE
, 0.5);
1098 glVertex3f(TEXSIZE
/ 4, TEXSIZE
, 0.5);
1101 if (useFramebuffer
) {
1102 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, 0);
1103 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1106 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1107 glCopyTexImage2D(GL_TEXTURE_2D
, 0,
1108 GL_DEPTH_COMPONENT
, 0, 0, TEXSIZE
,
1112 glClear(GL_DEPTH_BUFFER_BIT
);
1114 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
1115 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1116 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1117 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_COMPARE_MODE
,
1118 GL_COMPARE_R_TO_TEXTURE
);
1119 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_COMPARE_FUNC
, GL_LESS
);
1120 glTexParameterf(GL_TEXTURE_2D
, GL_DEPTH_TEXTURE_MODE
,
1122 glEnable(GL_TEXTURE_2D
);
1123 glDisable(GL_DEPTH_TEST
);
1125 // Render to the window
1126 glColor4fv(colors
[GREEN
]);
1127 glClearColor(0.0, 0.0, 0.0, 0.0);
1128 glClear(GL_COLOR_BUFFER_BIT
);
1129 glBegin(GL_POLYGON
);
1130 glTexCoord3f(0, 0, 0.75);
1132 glTexCoord3f(1, 0, 0.75);
1133 glVertex2f(TEXSIZE
, 0);
1134 glTexCoord3f(1, 1, 0.75);
1135 glVertex2f(TEXSIZE
, TEXSIZE
);
1136 glTexCoord3f(0, 1, 0.75);
1137 glVertex2f(0, TEXSIZE
);
1143 glDeleteFramebuffersEXT_func(1, fbs
);
1144 glDeleteTextures(1, textures
);
1147 if (checkResult(colors
[WHITE
], 1, 0) == false) {
1148 REPORT_FAILURE("Render to depth texture failed");
1159 FBOTest::testRender2MipmapTexture(void)
1167 glGenFramebuffersEXT_func(1, fbs
);
1169 glGenTextures(1, textures
);
1170 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1173 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
1175 glDisable(GL_TEXTURE_2D
);
1179 for (i
= TEXSIZE
; i
> 0; i
/= 2, level
++) {
1180 if (useFramebuffer
) {
1181 glTexImage2D(GL_TEXTURE_2D
, level
, GL_RGB
,
1182 i
, i
, 0, GL_RGB
, GL_INT
, NULL
);
1183 glFramebufferTexture2DEXT_func
1184 (GL_FRAMEBUFFER_EXT
,
1185 GL_COLOR_ATTACHMENT0_EXT
,
1186 GL_TEXTURE_2D
, textures
[0], level
);
1187 CheckFramebufferStatus("FBOTest::testRender2MipmapTexture", __LINE__
);
1189 glColor4fv(colors
[RED
+ (level
% (WHITE
- RED
))]);
1190 glClearColor(0.0, 0.0, 0.0, 0.0);
1191 glClear(GL_COLOR_BUFFER_BIT
);
1193 glBegin(GL_POLYGON
);
1194 glVertex3f(0, 0, 1);
1195 glVertex3f(TEXSIZE
, 0, 1);
1196 glVertex3f(TEXSIZE
, TEXSIZE
, 1);
1197 glVertex3f(0, TEXSIZE
, 1);
1201 glColor4fv(colors
[RED
+ (level
% (WHITE
- RED
))]);
1202 glClearColor(0.0, 0.0, 0.0, 0.0);
1203 glClear(GL_COLOR_BUFFER_BIT
);
1205 glBegin(GL_POLYGON
);
1206 glVertex3f(0, 0, 1);
1207 glVertex3f(TEXSIZE
, 0, 1);
1208 glVertex3f(TEXSIZE
, TEXSIZE
, 1);
1209 glVertex3f(0, TEXSIZE
, 1);
1213 glTexImage2D(GL_TEXTURE_2D
, level
, GL_RGB
,
1214 i
, i
, 0, GL_RGB
, GL_INT
, NULL
);
1215 glCopyTexImage2D(GL_TEXTURE_2D
, level
,
1216 GL_RGB
, 0, 0, i
, i
, 0);
1220 if (useFramebuffer
) {
1221 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, 0);
1222 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1224 glEnable(GL_TEXTURE_2D
);
1226 // Render to the window
1227 glColor4fv(colors
[GREEN
]);
1228 glClearColor(0.0, 0.0, 0.0, 0.0);
1229 glClear(GL_COLOR_BUFFER_BIT
);
1230 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1231 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
1232 GL_NEAREST_MIPMAP_NEAREST
);
1233 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
1235 for (i
= TEXSIZE
; i
> 0; i
/= 2) {
1236 glBegin(GL_POLYGON
);
1238 glVertex3f(windowSize
/ 2 - i
/ 2,
1239 windowSize
/ 2 - i
/ 2, 1);
1241 glVertex3f(windowSize
/ 2 + i
/ 2,
1242 windowSize
/ 2 - i
/ 2, 1);
1244 glVertex3f(windowSize
/ 2 + i
/ 2,
1245 windowSize
/ 2 + i
/ 2, 1);
1247 glVertex3f(windowSize
/ 2 - i
/ 2,
1248 windowSize
/ 2 + i
/ 2, 1);
1255 glDeleteFramebuffersEXT_func(1, fbs
);
1256 glDeleteTextures(1, textures
);
1260 for (i
= TEXSIZE
; i
> 1; i
/= 2, level
++) {
1263 glReadPixels(windowSize
/ 2 - i
/ 2,
1264 windowSize
/ 2 - i
/ 2, 1, 1, GL_RGB
,
1267 (pixel
, colors
[RED
+ (level
% (WHITE
- RED
))])) {
1268 REPORT_FAILURE("Render to mipmap texture failed");
1269 printf(" level = %d\n", level
);
1280 FBOTest::testErrorHandling(void)
1286 if (useFramebuffer
) {
1287 GLuint maxColorAttachment
;
1289 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT
, (GLint
*) & maxColorAttachment
);
1290 if (maxColorAttachment
< 1) {
1291 REPORT_FAILURE("Failed to get max color attachment points");
1296 // At least one image attached to the framebuffer
1297 glGenFramebuffersEXT_func(1, fbs
);
1298 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
1299 glDrawBuffer(GL_NONE
);
1300 glReadBuffer(GL_NONE
);
1301 status
= glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT
);
1302 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, 0);
1303 glDeleteFramebuffersEXT_func(1, fbs
);
1305 GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
) {
1307 ("If no image is attached to framebuffer, status should be GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");
1311 // All attached images have the same width and height,
1312 // unless GL_ARB_framebuffer object is supported.
1313 glGenFramebuffersEXT_func(1, fbs
);
1314 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
1315 glGenTextures(2, textures
);
1316 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1317 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, TEXSIZE
,
1318 TEXSIZE
, 0, GL_RGB
, GL_INT
, NULL
);
1319 glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT
,
1320 GL_COLOR_ATTACHMENT0_EXT
,
1321 GL_TEXTURE_2D
, textures
[0], 0);
1322 glBindTexture(GL_TEXTURE_2D
, textures
[1]);
1323 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, TEXSIZE
/ 2,
1324 TEXSIZE
/ 2, 0, GL_RGB
, GL_INT
, NULL
);
1325 glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT
,
1326 GL_COLOR_ATTACHMENT0_EXT
1327 + maxColorAttachment
- 1,
1328 GL_TEXTURE_2D
, textures
[1], 0);
1329 status
= glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT
);
1330 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, 0);
1331 glDeleteFramebuffersEXT_func(1, fbs
);
1332 glDeleteTextures(2, textures
);
1334 status
!= GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
) {
1336 ("If renderbuffer sizes don't all match, status should be GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT");
1340 // All images attached to the attachment points
1341 // COLOR_ATTACHMENT0_EXT through COLOR_ATTACHMENTn_EXT must
1342 // have the same internal format, unless ARB_fbo is supported.
1343 glGenFramebuffersEXT_func(1, fbs
);
1344 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
1345 glGenTextures(2, textures
);
1346 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1347 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, TEXSIZE
,
1348 TEXSIZE
, 0, GL_RGB
, GL_INT
, NULL
);
1349 glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT
,
1350 GL_COLOR_ATTACHMENT0_EXT
,
1351 GL_TEXTURE_2D
, textures
[0], 0);
1352 glBindTexture(GL_TEXTURE_2D
, textures
[1]);
1353 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, TEXSIZE
,
1354 TEXSIZE
, 0, GL_RGBA
, GL_INT
, NULL
);
1355 glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT
,
1356 GL_COLOR_ATTACHMENT0_EXT
1357 + maxColorAttachment
- 1,
1358 GL_TEXTURE_2D
, textures
[1], 0);
1359 status
= glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT
);
1360 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, 0);
1361 glDeleteFramebuffersEXT_func(1, fbs
);
1362 glDeleteTextures(2, textures
);
1364 status
!= GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
) {
1366 ("All color renderbuffers must be of same format, status should be GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT");
1371 // The value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT must not
1372 // be NONE for any color attachment point(s) named by
1374 glGenFramebuffersEXT_func(1, fbs
);
1375 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
1376 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT
+
1377 maxColorAttachment
- 1);
1378 status
= glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT
);
1379 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, 0);
1380 glDeleteFramebuffersEXT_func(1, fbs
);
1381 if (status
!= GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
) {
1383 ("All any buffer named by glDrawBuffers is missing, status should be GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT");
1387 // If READ_BUFFER is not NONE, then the value of
1388 // FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT must not be NONE for
1389 // the color attachment point named by READ_BUFFER.
1390 glGenFramebuffersEXT_func(1, fbs
);
1391 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
1392 glDrawBuffer(GL_NONE
);
1393 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT
+
1394 maxColorAttachment
- 1);
1395 status
= glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT
);
1396 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, 0);
1397 glDeleteFramebuffersEXT_func(1, fbs
);
1398 if (status
!= GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
) {
1400 ("If buffer named by glReadBuffers is missing, status should be GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT");
1408 FBOTest::testFunctionality(MultiTestResult
& r
)
1410 static SubTestFunc funcs
[] = {
1411 &GLEAN::FBOTest::testSanity
,
1412 &GLEAN::FBOTest::testRender2SingleTexture
,
1413 &GLEAN::FBOTest::testRender2MultiTexture
,
1414 &GLEAN::FBOTest::testRender2depthTexture
,
1415 &GLEAN::FBOTest::testRender2MipmapTexture
,
1416 &GLEAN::FBOTest::testErrorHandling
,
1420 for (int i
= 0; funcs
[i
]; i
++)
1421 if ((this->*funcs
[i
]) ())
1430 FBOTest::testPerformance(MultiTestResult
& r
)
1437 double t0
, t1
, perf
[2];
1441 for (mode
= 0; mode
< useFramebuffer
+ 1; mode
++) {
1443 glClearColor(0.0, 0.0, 0.0, 1.0);
1444 glClear(GL_COLOR_BUFFER_BIT
);
1446 glGenFramebuffersEXT_func(1, fbs
);
1447 glGenTextures(1, textures
);
1449 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1450 glTexParameteri(GL_TEXTURE_2D
,
1451 GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1452 glTexParameteri(GL_TEXTURE_2D
,
1453 GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1455 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, TEXSIZE
,
1456 TEXSIZE
, 0, GL_RGB
, GL_INT
, NULL
);
1459 glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT
, fbs
[0]);
1460 glFramebufferTexture2DEXT_func
1461 (GL_FRAMEBUFFER_EXT
,
1462 GL_COLOR_ATTACHMENT0_EXT
,
1463 GL_TEXTURE_2D
, textures
[0], 0);
1464 CheckFramebufferStatus("FBOTest::testPerformance", __LINE__
);
1469 for (i
= 0; i
< 1024; i
++) {
1471 glBindFramebufferEXT_func
1472 (GL_FRAMEBUFFER_EXT
, fbs
[0]);
1474 // Render to the texture
1475 glBindTexture(GL_TEXTURE_2D
, 0);
1476 glDisable(GL_TEXTURE_2D
);
1477 glColor4fv(colors
[RED
+ (i
% (WHITE
- RED
))]);
1478 glClearColor(0.0, 0.0, 0.0, 0.0);
1479 glClear(GL_COLOR_BUFFER_BIT
);
1482 glBegin(GL_POLYGON
);
1483 glVertex3f(0, 0, 0.2);
1484 glVertex3f(TEXSIZE
, 0, 0.2);
1485 glVertex3f(TEXSIZE
, TEXSIZE
, 0.2);
1486 glVertex3f(0, TEXSIZE
, 0.2);
1489 // Render to the window
1491 glBindFramebufferEXT_func
1492 (GL_FRAMEBUFFER_EXT
, 0);
1493 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1496 glBindTexture(GL_TEXTURE_2D
, textures
[0]);
1497 glCopyTexImage2D(GL_TEXTURE_2D
, 0,
1499 TEXSIZE
, TEXSIZE
, 0);
1501 glEnable(GL_TEXTURE_2D
);
1502 glColor4fv(colors
[WHITE
]);
1503 glClearColor(0.0, 0.0, 0.0, 0.0);
1504 glClear(GL_COLOR_BUFFER_BIT
);
1506 glBegin(GL_POLYGON
);
1507 glTexCoord3f(0.0, 0.0, 1.0);
1509 glTexCoord3f(1.0, 0.0, 1.0);
1511 glTexCoord3f(1.0, 1.0, 1.0);
1513 glTexCoord3f(0.0, 1.0, 1.0);
1518 glDeleteTextures(1, textures
);
1520 glDeleteFramebuffersEXT_func(1, fbs
);
1523 (double) TEXSIZE
*TEXSIZE
* 3 / 1024 / (t1
- t0
);
1526 if (perf
[1] < perf
[0] && useFramebuffer
) {
1527 env
->log
<< name
<< ": NOTE "
1528 << "perf[0] = " << perf
[0] <<
1529 " MB/s, which is using glCopyTexImage2D" << endl
;
1530 env
->log
<< name
<< ": NOTE " << "perf[1] = " <<
1531 perf
[1] << " MB/s, which is using FBO" << endl
;
1537 // Run all the subtests, incrementing numPassed, numFailed
1539 FBOTest::runSubTests(MultiTestResult
& r
)
1541 static TestFunc funcs
[] = {
1542 &GLEAN::FBOTest::testFunctionality
,
1543 &GLEAN::FBOTest::testPerformance
,
1547 for (int i
= 0; funcs
[i
]; i
++)
1548 if ((this->*funcs
[i
]) (r
))
1556 FBOTest::runOne(MultiTestResult
& r
, Window
& w
)
1567 r
.pass
= (r
.numFailed
== 0);
1571 // The test object itself:
1572 FBOTest
fboTest("fbo", "window, rgb, z", "", // no extension filter
1573 "fbo test: Test OpenGL Extension GL_EXT_framebuffer_object\n");
1577 } // namespace GLEAN