summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2009-07-02 17:28:42 -0700
committerEric Anholt <eric@anholt.net>2009-07-02 17:28:42 -0700
commitc3da635874bbc8251605aa841c6567ce1427194f (patch)
tree8d823101a22ead3fa6157e73e08b0fd4c8a361e6
parentaa7c71facfe968af8f82c5a07b02cad039a3134e (diff)
-rw-r--r--tests/all.tests2
-rw-r--r--tests/glean/codedid.cpp4
-rw-r--r--tests/glean/dsconfig.cpp39
-rw-r--r--tests/glean/dsfilt.cpp1
-rw-r--r--tests/glean/environ.cpp10
-rw-r--r--tests/glean/geomrend.cpp9
-rw-r--r--tests/glean/geomutil.cpp4
-rw-r--r--tests/glean/glutils.cpp21
-rw-r--r--tests/glean/main.cpp7
-rw-r--r--tests/glean/options.cpp1
-rw-r--r--tests/glean/options.h7
-rw-r--r--tests/glean/tapi2.cpp4
-rw-r--r--tests/glean/tapi2.h2
-rw-r--r--tests/glean/tbase.h5
-rw-r--r--tests/glean/tbasicperf.h4
-rw-r--r--tests/glean/tbinding.cpp19
-rw-r--r--tests/glean/tbinding.h6
-rw-r--r--tests/glean/tblend.cpp8
-rw-r--r--tests/glean/tbufferobject.cpp336
-rw-r--r--tests/glean/tbufferobject.h76
-rw-r--r--tests/glean/tclipflat.cpp539
-rw-r--r--tests/glean/tclipflat.h77
-rw-r--r--tests/glean/tfbo.cpp370
-rw-r--r--tests/glean/tfragprog1.cpp17
-rw-r--r--tests/glean/tgetstr.cpp4
-rw-r--r--tests/glean/tgetstr.h4
-rw-r--r--tests/glean/tglsl1.cpp377
-rw-r--r--tests/glean/tlogicop.cpp4
-rw-r--r--tests/glean/tmultitest.cpp21
-rw-r--r--tests/glean/toccluqry.cpp118
-rw-r--r--tests/glean/toccluqry.h1
-rw-r--r--tests/glean/tpbo.cpp2531
-rw-r--r--tests/glean/tpbo.h172
-rw-r--r--tests/glean/tpointsprite.cpp9
-rw-r--r--tests/glean/treadpix.cpp7
-rw-r--r--tests/glean/treadpix.h2
-rw-r--r--tests/glean/tshaderapi.cpp2
-rw-r--r--tests/glean/tshaderapi.h2
-rw-r--r--tests/glean/ttexcombine.cpp14
-rw-r--r--tests/glean/ttexcombine.h1
-rw-r--r--tests/glean/ttexenv.cpp10
-rw-r--r--tests/glean/ttexgen.cpp7
-rw-r--r--tests/glean/ttexswizzle.cpp28
-rw-r--r--tests/glean/ttexture_srgb.cpp4
-rw-r--r--tests/glean/ttexunits.cpp32
-rw-r--r--tests/glean/tvertarraybgra.cpp15
-rw-r--r--tests/glean/tvertattrib.cpp6
-rw-r--r--tests/glean/tvertattrib.h3
-rw-r--r--tests/glean/winsys.cpp4
49 files changed, 3276 insertions, 1670 deletions
diff --git a/tests/all.tests b/tests/all.tests
index a83b4b51e..6393f40c1 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -37,6 +37,8 @@ glean['basic'] = GleanTest('basic')
glean['api2'] = GleanTest('api2')
glean['makeCurrent'] = GleanTest('makeCurrent')
glean['blendFunc'] = GleanTest('blendFunc')
+glean['bufferObject'] = GleanTest('bufferObject')
+glean['clipFlag'] = GleanTest('clipFlag')
glean['depthStencil'] = GleanTest('depthStencil')
glean['fbo'] = GleanTest('fbo')
glean['fpexceptions'] = GleanTest('fpexceptions')
diff --git a/tests/glean/codedid.cpp b/tests/glean/codedid.cpp
index 44fe56b80..7921e8298 100644
--- a/tests/glean/codedid.cpp
+++ b/tests/glean/codedid.cpp
@@ -30,13 +30,13 @@
// codedid.h: tool to map integer IDs into colors, and vice-versa
-using namespace std;
-
#include <algorithm>
#include <vector>
#include "codedid.h"
#include "image.h"
+using namespace std;
+
namespace GLEAN {
///////////////////////////////////////////////////////////////////////////////
diff --git a/tests/glean/dsconfig.cpp b/tests/glean/dsconfig.cpp
index 861c0c831..cf2f769c9 100644
--- a/tests/glean/dsconfig.cpp
+++ b/tests/glean/dsconfig.cpp
@@ -32,7 +32,7 @@
// dsconfig.cpp: Implementation of drawing surface configuration utilities
#include "dsconfig.h"
#include <iostream>
-#include <strstream>
+#include <sstream>
#include <string.h>
#include <map>
#include <limits.h>
@@ -121,7 +121,7 @@ typedef enum { // These variable tags are used as array indices,
V_LAST
} CanonVar;
-struct {CanonVar var; char* name;} varNames[] = {
+static struct {CanonVar var; const char* name;} varNames[] = {
{VID, "id"},
{VFBCID, "fbcID"},
{VCANRGBA, "canRGBA"},
@@ -159,7 +159,7 @@ struct {CanonVar var; char* name;} varNames[] = {
{VTRANSI, "transI"}
};
-char* mapVarToName[V_LAST];
+const char* mapVarToName[V_LAST];
map<string, CanonVar> mapNameToVar;
bool mapsInitialized = false;
@@ -416,7 +416,7 @@ DrawingSurfaceConfig::DrawingSurfaceConfig() {
DrawingSurfaceConfig::DrawingSurfaceConfig(int id, ::AGLPixelFormat pfd)
{
- long i;
+ int i;
if (!mapsInitialized)
initializeMaps();
@@ -440,10 +440,10 @@ DrawingSurfaceConfig::DrawingSurfaceConfig(int id, ::AGLPixelFormat pfd)
aux = i;
if (canRGBA) {
- aglDescribePixelFormat( pf, AGL_RED_SIZE, (long *)&r);
- aglDescribePixelFormat( pf, AGL_GREEN_SIZE, (long *)&g);
- aglDescribePixelFormat( pf, AGL_BLUE_SIZE, (long *)&b);
- aglDescribePixelFormat( pf, AGL_ALPHA_SIZE, (long *)&a);
+ aglDescribePixelFormat( pf, AGL_RED_SIZE, &r);
+ aglDescribePixelFormat( pf, AGL_GREEN_SIZE, &g);
+ aglDescribePixelFormat( pf, AGL_BLUE_SIZE, &b);
+ aglDescribePixelFormat( pf, AGL_ALPHA_SIZE, &a);
//this is a workaround for some versions of AGL
if (r == 10)
@@ -457,13 +457,13 @@ DrawingSurfaceConfig::DrawingSurfaceConfig(int id, ::AGLPixelFormat pfd)
samples = 0; // XXX implement properly for AGL
- aglDescribePixelFormat( pf, AGL_DEPTH_SIZE, (long *)& z);
- aglDescribePixelFormat( pf, AGL_STENCIL_SIZE, (long *)& s);
+ aglDescribePixelFormat( pf, AGL_DEPTH_SIZE, & z);
+ aglDescribePixelFormat( pf, AGL_STENCIL_SIZE, & s);
- aglDescribePixelFormat( pf, AGL_ACCUM_RED_SIZE, (long *)& accR);
- aglDescribePixelFormat( pf, AGL_ACCUM_GREEN_SIZE, (long *)& accG);
- aglDescribePixelFormat( pf, AGL_ACCUM_BLUE_SIZE, (long *)& accB);
- aglDescribePixelFormat( pf, AGL_ACCUM_ALPHA_SIZE, (long *)& accA);
+ aglDescribePixelFormat( pf, AGL_ACCUM_RED_SIZE, & accR);
+ aglDescribePixelFormat( pf, AGL_ACCUM_GREEN_SIZE, & accG);
+ aglDescribePixelFormat( pf, AGL_ACCUM_BLUE_SIZE, & accB);
+ aglDescribePixelFormat( pf, AGL_ACCUM_ALPHA_SIZE, & accA);
aglDescribePixelFormat( pf, AGL_WINDOW, &i);
canWindow = i;
@@ -650,11 +650,7 @@ DrawingSurfaceConfig::DrawingSurfaceConfig(string& str) {
///////////////////////////////////////////////////////////////////////////////
string
DrawingSurfaceConfig::canonicalDescription() {
-
- // Would rather use ostringstream, but it's not available in
- // egcs 1.1.2.
- char buf[1024];
- ostrstream s(buf, sizeof(buf));
+ ostringstream s;
# if defined(__X11__)
s << mapVarToName[VID] << ' ' << visID;
@@ -721,7 +717,6 @@ DrawingSurfaceConfig::canonicalDescription() {
<< ' ' << mapVarToName[VTRANSA] << ' ' << transA
<< ' ' << mapVarToName[VTRANSI] << ' ' << transI;
- s << '\0';
return s.str();
} // DrawingSurfaceConfig::canonicalDescription
@@ -731,8 +726,7 @@ DrawingSurfaceConfig::canonicalDescription() {
///////////////////////////////////////////////////////////////////////////////
string
DrawingSurfaceConfig::conciseDescription() {
- char buf[1024];
- ostrstream s(buf, sizeof(buf));
+ ostringstream s;
if (canRGBA && canCI)
s << "dual ";
@@ -848,7 +842,6 @@ DrawingSurfaceConfig::conciseDescription() {
s << ", id " << pfdID;
# endif
- s << '\0';
return s.str();
} // DrawingSurfaceConfig::conciseDescription
diff --git a/tests/glean/dsfilt.cpp b/tests/glean/dsfilt.cpp
index 6b1795b42..fe5ed2660 100644
--- a/tests/glean/dsfilt.cpp
+++ b/tests/glean/dsfilt.cpp
@@ -34,7 +34,6 @@
// dsfilt.cpp: Implementation of drawing surface configuration filtering
#include <iostream>
-#include <strstream>
#include <ctype.h>
#include <stdlib.h>
#include <algorithm>
diff --git a/tests/glean/environ.cpp b/tests/glean/environ.cpp
index fac0f6690..8c1e4d3b1 100644
--- a/tests/glean/environ.cpp
+++ b/tests/glean/environ.cpp
@@ -40,6 +40,7 @@
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
+#include <cstdio>
#elif defined(__MS__)
#include <sys/stat.h>
@@ -89,8 +90,13 @@ Environment::Environment(Options& opt):
// Refuse to overwrite one that already exists.
if (opt.mode == Options::run) {
if (opt.overwrite) {
- // XXX a Windows programmer needs to complete this
- abort();
+ char cmd[1000];
+#if defined(_MSC_VER)
+ _snprintf(cmd, 999, "rd /s /q %s", opt.db1Name.c_str());
+#else
+ snprintf(cmd, 999, "rd /s /q %s", opt.db1Name.c_str());
+#endif
+ system(cmd);
}
if (!CreateDirectory(opt.db1Name.c_str(),0)) {
if (GetLastError() == ERROR_ALREADY_EXISTS)
diff --git a/tests/glean/geomrend.cpp b/tests/glean/geomrend.cpp
index e8142a508..fceb24d75 100644
--- a/tests/glean/geomrend.cpp
+++ b/tests/glean/geomrend.cpp
@@ -34,8 +34,6 @@
// vertex arrays with glDrawElements, and any of the preceding
// methods stuffed in a display list.
-using namespace std;
-
#include "geomrend.h"
#include "rand.h"
#include "glutils.h"
@@ -45,6 +43,8 @@ using namespace std;
#include <float.h>
#include <cassert>
+using namespace std;
+
namespace GLEAN {
@@ -292,6 +292,8 @@ bool GeomRenderer::renderPrimitives(GLenum mode)
bool GeomRenderer::generateDisplayList(GLenum mode, GLint& listHandleOut)
{
+ bool result;
+
if (!isReadyToRender())
{
return false;
@@ -299,7 +301,8 @@ bool GeomRenderer::generateDisplayList(GLenum mode, GLint& listHandleOut)
listHandleOut = glGenLists(1);
glNewList(listHandleOut, GL_COMPILE);
- assert(renderPrimitives(mode));
+ result = renderPrimitives(mode);
+ assert(result);
glEndList();
return true;
diff --git a/tests/glean/geomutil.cpp b/tests/glean/geomutil.cpp
index ab8ab2dc5..01645f7fe 100644
--- a/tests/glean/geomutil.cpp
+++ b/tests/glean/geomutil.cpp
@@ -30,8 +30,6 @@
// geomutil.cpp: frequently-used geometric operations
-using namespace std;
-
#include "geomutil.h"
#include "rand.h"
#include <cassert>
@@ -40,6 +38,8 @@ using namespace std;
#include <float.h>
#include <stdio.h>
+using namespace std;
+
namespace GLEAN {
///////////////////////////////////////////////////////////////////////////////
diff --git a/tests/glean/glutils.cpp b/tests/glean/glutils.cpp
index 26d348831..2c8ab600a 100644
--- a/tests/glean/glutils.cpp
+++ b/tests/glean/glutils.cpp
@@ -141,26 +141,7 @@ void
# error "Need GetProcAddress (or equivalent) for BeOS"
return 0;
#elif defined(__AGL__)
- // Very quick hack to keep things running for a few hours until
- // a better solution is in place:
- if (!strcmp(name, "glLockArraysEXT"))
- return reinterpret_cast<void (*)()> (glLockArraysEXT);
- else if (!strcmp(name, "glUnlockArraysEXT"))
- return reinterpret_cast<void (*)()> (glUnlockArraysEXT);
- else if (!strcmp(name, "glActiveTextureARB"))
- return reinterpret_cast<void (*)()> (glActiveTextureARB);
- else if (!strcmp(name, "glMultiTexCoord2fARB"))
- return reinterpret_cast<void (*)()> (glMultiTexCoord2fARB);
- else if (!strcmp(name, "glLockArraysEXT"))
- return reinterpret_cast<void (*)()> (glLockArraysEXT);
- else if (!strcmp(name, "glUnlockArraysEXT"))
- return reinterpret_cast<void (*)()> (glUnlockArraysEXT);
- else if (!strcmp(name, "glLockArraysEXT"))
- return reinterpret_cast<void (*)()> (glLockArraysEXT);
- else if (!strcmp(name, "glUnlockArraysEXT"))
- return reinterpret_cast<void (*)()> (glUnlockArraysEXT);
- else
- return 0;
+ return reinterpret_cast<void (*)()>(glutGetProcAddress(name));
#endif
} // getProcAddress
diff --git a/tests/glean/main.cpp b/tests/glean/main.cpp
index 77fae4ff8..6e4b5b231 100644
--- a/tests/glean/main.cpp
+++ b/tests/glean/main.cpp
@@ -31,8 +31,6 @@
// main.cpp: main program for Glean
-using namespace std;
-
#include <cassert>
#include <cstring>
#include <iostream>
@@ -46,6 +44,8 @@ using namespace std;
#include "lex.h"
#include "dsfilt.h"
+using namespace std;
+
using namespace GLEAN;
char* mandatoryArg(int argc, char* argv[], int i);
@@ -81,6 +81,8 @@ main(int argc, char* argv[]) {
} else if (!strcmp(argv[i], "-o")
|| !strcmp(argv[i], "--overwrite")) {
o.overwrite = true;
+ } else if (!strcmp(argv[i], "--quick")) {
+ o.quick = true;
} else if (!strcmp(argv[i], "-c")
|| !strcmp(argv[i], "--compare")) {
o.mode = Options::compare;
@@ -322,6 +324,7 @@ usage(char* command) {
" --visuals 'filter-string' # select subset of visuals (FBConfigs,\n"
" # pixel formats) to test\n"
" (-t|--tests) {(+|-)test} # choose tests to include (+) or exclude (-)\n"
+" --quick # run fewer tests to reduce test time\n"
" --listtests # list test names and exit\n"
" --help # display usage information\n"
#if defined(__X11__)
diff --git a/tests/glean/options.cpp b/tests/glean/options.cpp
index 7e97e5fa7..bf7dd31ac 100644
--- a/tests/glean/options.cpp
+++ b/tests/glean/options.cpp
@@ -48,6 +48,7 @@ Options::Options() {
visFilter = "1";
selectedTests.resize(0);
overwrite = false;
+ quick = false;
# if defined(__X11__)
{
char* display = getenv("DISPLAY");
diff --git a/tests/glean/options.h b/tests/glean/options.h
index 8027069c8..ea84348e6 100644
--- a/tests/glean/options.h
+++ b/tests/glean/options.h
@@ -48,11 +48,11 @@
#ifndef __options_h__
#define __options_h__
-using namespace std;
-
#include <string>
#include <vector>
+using namespace std;
+
namespace GLEAN {
class Options {
@@ -82,6 +82,9 @@ class Options {
// Sorted list of tests to be executed.
bool overwrite; // overwrite old results database if exists
+
+ bool quick; // run fewer/quicker tests when possible
+
#if defined(__X11__)
string dpyName; // Name of the X11 display providing the
// OpenGL implementation to be tested.
diff --git a/tests/glean/tapi2.cpp b/tests/glean/tapi2.cpp
index 8367d74d1..15fe59d44 100644
--- a/tests/glean/tapi2.cpp
+++ b/tests/glean/tapi2.cpp
@@ -104,7 +104,7 @@ static PFNGLDRAWBUFFERSPROC glDrawBuffers_func = NULL;
// \param errorFunc returns name of API function in case of error
// \return true for success, false for error
bool
-API2Test::getFunctions_2_0(char **errorFunc)
+API2Test::getFunctions_2_0(const char **errorFunc)
{
#define GET(PTR, TYPE, STR) \
PTR = (TYPE) GLUtils::getProcAddress(STR); \
@@ -187,7 +187,7 @@ API2Test::setup(void)
return false;
}
- char *errorFunc;
+ const char *errorFunc;
if (!getFunctions_2_0(&errorFunc)) {
env->log << "Unable to get pointer to OpenGL 2.0 function '"
<< errorFunc
diff --git a/tests/glean/tapi2.h b/tests/glean/tapi2.h
index c4df77193..cb898f5d6 100644
--- a/tests/glean/tapi2.h
+++ b/tests/glean/tapi2.h
@@ -54,7 +54,7 @@ private:
typedef bool (API2Test::*TestFunc)(void);
GLfloat tolerance[5];
- bool getFunctions_2_0(char **errorFunc);
+ bool getFunctions_2_0(const char **errorFunc);
GLuint loadAndCompileShader(GLenum target, const char *str);
GLuint createProgram(GLuint vertShader, GLuint fragShader);
diff --git a/tests/glean/tbase.h b/tests/glean/tbase.h
index 2cf72dd1e..ecd3e17ac 100644
--- a/tests/glean/tbase.h
+++ b/tests/glean/tbase.h
@@ -123,9 +123,6 @@ and tbasic.cpp.
#include "test.h"
-class GLEAN::DrawingSurfaceConfig; // Forward reference.
-
-
// Macro for constructor for Glean test taking width, height and one config flag
#define GLEAN_CLASS_WHO(TEST, RESULT, WIDTH, HEIGHT, ONE) \
TEST(const char* aName, const char* aFilter, \
@@ -168,6 +165,8 @@ class GLEAN::DrawingSurfaceConfig; // Forward reference.
namespace GLEAN {
+class DrawingSurfaceConfig; // Forward reference.
+
class BaseResult : public Result {
// Class for a single test result. All basic tests have a
// drawing surface configuration, plus other information
diff --git a/tests/glean/tbasicperf.h b/tests/glean/tbasicperf.h
index f53a64160..62fdbb65b 100644
--- a/tests/glean/tbasicperf.h
+++ b/tests/glean/tbasicperf.h
@@ -47,10 +47,10 @@
#include "tbase.h"
-class DrawingSurfaceConfig; // Forward reference.
-
namespace GLEAN {
+class DrawingSurfaceConfig; // Forward reference.
+
class BasicPerfResult: public BaseResult {
public:
bool pass;
diff --git a/tests/glean/tbinding.cpp b/tests/glean/tbinding.cpp
index 6aedd0253..c73cfae48 100644
--- a/tests/glean/tbinding.cpp
+++ b/tests/glean/tbinding.cpp
@@ -88,7 +88,6 @@ MakeCurrentTest::runOne(MakeCurrentResult& r, Window& w) {
// The rendering contexts to be used:
vector<RenderingContext*> rcs;
- // Short descriptions of the rendering contexts:
RandomBitsDouble rRand(config.r, 712105);
RandomBitsDouble gRand(config.g, 63230);
@@ -153,8 +152,24 @@ failed:
r.pass = false;
cleanup:
for (i = 0; i < static_cast<int>(rcs.size()); ++i)
- if (rcs[i])
+ if (rcs[i]) {
+ // We need to make sure that no GL commands are
+ // pending when the window is destroyed, or we
+ // risk a GLXBadCurrentWindow error at some
+ // indeterminate time in the future when
+ // glXMakeCurrent() is executed.
+ // In theory, if glReadPixels() is the last
+ // command executed by a test, then an implicit
+ // flush has occurred, and the command queue is
+ // empty. In practice, we have to protect
+ // against the possibility that the implicit
+ // flush is not enough to avoid the error.
+ ws.makeCurrent(*rcs[i], w);
+ glFinish();
+ ws.makeCurrent();
+
delete rcs[i];
+ }
} // MakeCurrentTest::runOne
///////////////////////////////////////////////////////////////////////////////
diff --git a/tests/glean/tbinding.h b/tests/glean/tbinding.h
index 835bf7a3b..021b85466 100644
--- a/tests/glean/tbinding.h
+++ b/tests/glean/tbinding.h
@@ -36,11 +36,11 @@
#include "tbasic.h"
-class DrawingSurfaceConfig; // Forward reference.
-class GLEAN::Window;
-
namespace GLEAN {
+class DrawingSurfaceConfig; // Forward reference.
+class Window;
+
#define drawingSize 64
class MakeCurrentResult: public BaseResult {
diff --git a/tests/glean/tblend.cpp b/tests/glean/tblend.cpp
index b94c82f48..9b4c458ec 100644
--- a/tests/glean/tblend.cpp
+++ b/tests/glean/tblend.cpp
@@ -37,16 +37,18 @@
#define ELEMENTS(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
+namespace GLEAN {
static PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate_func = NULL;
static PFNGLBLENDCOLORPROC glBlendColor_func = NULL;
static PFNGLBLENDEQUATIONPROC glBlendEquation_func = NULL;
static PFNGLBLENDEQUATIONSEPARATEPROC glBlendEquationSeparate_func = NULL;
+}
//namespace {
struct enumNameMapping {
GLenum token;
- char* name;
+ const char* name;
};
enumNameMapping factorNames[] = {
@@ -77,7 +79,7 @@ enumNameMapping blendopNames[] = {
};
-char*
+const char*
factorToName(GLenum factor) {
for (unsigned int i = 0; i < ELEMENTS(factorNames); ++i)
if (factorNames[i].token == factor)
@@ -93,7 +95,7 @@ nameToFactor(string& name) {
return GL_ZERO;
} // nameToFactor
-char *
+const char *
opToName(GLenum op) {
for (unsigned int i = 0; i < ELEMENTS(blendopNames); ++i)
if (blendopNames[i].token == op)
diff --git a/tests/glean/tbufferobject.cpp b/tests/glean/tbufferobject.cpp
new file mode 100644
index 000000000..6ab2ea2a2
--- /dev/null
+++ b/tests/glean/tbufferobject.cpp
@@ -0,0 +1,336 @@
+// BEGIN_COPYRIGHT -*- glean -*-
+//
+// Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the
+// Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL VMWARE BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// END_COPYRIGHT
+
+// tbufferobject.c - test various buffer object features/extensions
+// Author: Brian Paul
+
+
+#define GL_GLEXT_PROTOTYPES
+#include <cassert>
+#include <cmath>
+#include <cstring>
+#include <stdlib.h>
+#include "tbufferobject.h"
+
+
+namespace GLEAN {
+
+
+// GL_ARB_vertex/fragment_program
+static PFNGLGENBUFFERSARBPROC glGenBuffersARB_func = NULL;
+static PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB_func = NULL;
+static PFNGLBINDBUFFERARBPROC glBindBufferARB_func = NULL;
+static PFNGLBUFFERDATAARBPROC glBufferDataARB_func = NULL;
+static PFNGLMAPBUFFERARBPROC glMapBufferARB_func = NULL;
+static PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB_func = NULL;
+
+// GL_ARB_copy_buffer
+static PFNGLCOPYBUFFERSUBDATAPROC glCopyBufferSubData_func = NULL;
+
+// GL_ARB_map_buffer_range
+static PFNGLMAPBUFFERRANGEPROC glMapBufferRange_func = NULL;
+static PFNGLFLUSHMAPPEDBUFFERRANGEPROC glFlushMappedBufferRange_func = NULL;
+
+
+BufferObjectResult::BufferObjectResult()
+{
+ pass = false;
+}
+
+
+bool
+BufferObjectTest::setup(void)
+{
+ have_ARB_vertex_buffer_object = GLUtils::haveExtension("GL_ARB_vertex_buffer_object");
+ have_ARB_pixel_buffer_object = GLUtils::haveExtension("GL_ARB_pixel_buffer_object");
+ have_ARB_copy_buffer = GLUtils::haveExtension("GL_ARB_copy_buffer");
+ have_ARB_map_buffer_range = GLUtils::haveExtension("GL_ARB_map_buffer_range");
+
+ if (have_ARB_vertex_buffer_object) {
+ target1 = GL_ARRAY_BUFFER_ARB;
+ target2 = GL_ELEMENT_ARRAY_BUFFER_ARB;
+ }
+ else if (have_ARB_pixel_buffer_object) {
+ target1 = GL_PIXEL_PACK_BUFFER_ARB;
+ target2 = GL_PIXEL_UNPACK_BUFFER_ARB;
+ }
+ else {
+ return false;
+ }
+
+
+ glGenBuffersARB_func = (PFNGLGENBUFFERSARBPROC) GLUtils::getProcAddress("glGenBuffersARB");
+ glDeleteBuffersARB_func = (PFNGLDELETEBUFFERSARBPROC) GLUtils::getProcAddress("glDeleteBuffersARB");
+ glBindBufferARB_func = (PFNGLBINDBUFFERARBPROC) GLUtils::getProcAddress("glBindBufferARB");
+ glBufferDataARB_func = (PFNGLBUFFERDATAARBPROC) GLUtils::getProcAddress("glBufferDataARB");
+ glMapBufferARB_func = (PFNGLMAPBUFFERARBPROC) GLUtils::getProcAddress("glMapBufferARB");
+ glUnmapBufferARB_func = (PFNGLUNMAPBUFFERARBPROC) GLUtils::getProcAddress("glUnmapBufferARB");
+
+ if (have_ARB_copy_buffer) {
+ glCopyBufferSubData_func = (PFNGLCOPYBUFFERSUBDATAPROC) GLUtils::getProcAddress("glCopyBufferSubData");
+ }
+
+ if (have_ARB_map_buffer_range) {
+ glMapBufferRange_func = (PFNGLMAPBUFFERRANGEPROC) GLUtils::getProcAddress("glMapBufferRange");
+ glFlushMappedBufferRange_func = (PFNGLFLUSHMAPPEDBUFFERRANGEPROC) GLUtils::getProcAddress("glFlushMappedBufferRange");
+ }
+
+ return true;
+}
+
+
+// test GL_ARB_copy_buffer
+bool
+BufferObjectTest::testCopyBuffer(void)
+{
+ static const GLsizei size1 = 4200, size2 = 3800;
+ GLubyte buf1[size1], buf2[size2];
+ GLuint bufs[2];
+ GLubyte *map;
+ GLint i;
+ bool pass;
+
+ glGenBuffersARB_func(2, bufs);
+
+ // setup first buffer
+ glBindBufferARB_func(target1, bufs[0]);
+ glBufferDataARB_func(target1, size1, NULL, GL_STATIC_DRAW);
+ map = (GLubyte *) glMapBufferARB_func(target1, GL_WRITE_ONLY_ARB);
+ for (i = 0; i < size1; i++) {
+ map[i] = buf1[i] = i & 0xff;
+ }
+ glUnmapBufferARB_func(target1);
+
+ // setup second buffer
+ glBindBufferARB_func(target2, bufs[1]);
+ glBufferDataARB_func(target2, size2, NULL, GL_STATIC_DRAW);
+ map = (GLubyte *) glMapBufferARB_func(target2, GL_WRITE_ONLY_ARB);
+ for (i = 0; i < size2; i++) {
+ map[i] = buf2[i] = 0;
+ }
+ glUnmapBufferARB_func(target2);
+
+ // copy random sections of first buffer to second buffer
+ for (i = 0; i < 50; i++) {
+ const int min = size1 < size2 ? size1 : size2;
+ int size = rand.next() % min;
+ int srcOffset = rand.next() % (size1 - size);
+ int dstOffset = rand.next() % (size2 - size);
+
+ assert(srcOffset + size <= size1);
+ assert(dstOffset + size <= size2);
+
+ // test copy from first buffer to second
+ glCopyBufferSubData_func(target1, // src target
+ target2, // dst target
+ srcOffset, // src start
+ dstOffset, // dst start
+ size);
+
+ // update the validation/reference buffer in the same way
+ memcpy(buf2 + dstOffset, buf1 + srcOffset, size);
+ }
+
+ // no errors should have been generated.
+ if (glGetError()) {
+ env->log << "Unexpected GL error in copy buffer test.\n";
+ return false;
+ }
+
+ // check results in second buffer object
+ map = (GLubyte *) glMapBufferARB_func(target2, GL_READ_ONLY_ARB);
+ pass = true;
+ for (i = 0; i < size2; i++) {
+ if (map[i] != buf2[i]) {
+ printf("%d: %d != %d\n", i, map[i], buf2[i]);
+ pass = false;
+ break;
+ }
+ }
+ glUnmapBufferARB_func(target2);
+
+ glDeleteBuffersARB_func(2, bufs);
+
+ return pass;
+}
+
+
+// Test GL_ARB_map_buffer_range
+// This isn't exhaustive, but covers the basics.
+bool
+BufferObjectTest::testMapBufferRange(void)
+{
+ static const GLsizei size = 30000;
+ GLubyte buf[size];
+ GLuint buffer;
+ GLubyte *map;
+ GLint i, j;
+ bool pass = true;
+
+ // create buffer
+ glGenBuffersARB_func(1, &buffer);
+ glBindBufferARB_func(target1, buffer);
+ glBufferDataARB_func(target1, size, NULL, GL_STATIC_DRAW);
+
+ // initialize to zeros
+ map = (GLubyte *) glMapBufferRange_func(target1, 0, size, GL_MAP_WRITE_BIT);
+ for (i = 0; i < size; i++) {
+ map[i] = buf[i] = 0;
+ }
+ glUnmapBufferARB_func(target1);
+
+ // write to random ranges
+ for (i = 0; i < 50; i++) {
+ const int mapSize = rand.next() % size;
+ const int mapOffset = rand.next() % (size - mapSize);
+
+ assert(mapOffset + mapSize <= size);
+
+ map = (GLubyte *)
+ glMapBufferRange_func(target1, mapOffset, mapSize,
+ GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
+
+ for (j = 0; j < mapSize; j++) {
+ map[j] = buf[mapOffset + j] = (mapOffset + j) & 0xff;
+ }
+
+ glFlushMappedBufferRange_func(target1, 0, mapSize);
+
+ glUnmapBufferARB_func(target1);
+ }
+
+ if (glGetError())
+ pass = false;
+
+ // read/check random ranges
+ for (i = 0; i < 50 && pass; i++) {
+ const int mapSize = rand.next() % size;
+ const int mapOffset = rand.next() % (size - mapSize);
+
+ assert(mapOffset + mapSize <= size);
+
+ map = (GLubyte *) glMapBufferRange_func(target1, mapOffset,
+ mapSize, GL_MAP_READ_BIT);
+
+ for (j = 0; j < mapSize; j++) {
+ if (map[j] != buf[mapOffset + j]) {
+ pass = false;
+ break;
+ }
+ }
+ glUnmapBufferARB_func(target1);
+ }
+
+ glDeleteBuffersARB_func(1, &buffer);
+
+ if (glGetError())
+ pass = false;
+
+ return pass;
+}
+
+
+void
+BufferObjectTest::runOne(BufferObjectResult &r, Window &w)
+{
+ (void) w; // silence warning
+ r.pass = true;
+
+ if (!setup()) {
+ // if neither GL_ARB_vertex/pixel_buffer_object are supported, do nothing
+ r.pass = true;
+ return;
+ }
+
+ if (r.pass && have_ARB_copy_buffer)
+ r.pass = testCopyBuffer();
+
+ if (r.pass && have_ARB_map_buffer_range)
+ r.pass = testMapBufferRange();
+}
+
+
+void
+BufferObjectTest::logOne(BufferObjectResult &r)
+{
+ logPassFail(r);
+ logConcise(r);
+}
+
+
+void
+BufferObjectTest::compareOne(BufferObjectResult &oldR,
+ BufferObjectResult &newR)
+{
+ comparePassFail(oldR, newR);
+}
+
+
+void
+BufferObjectResult::putresults(ostream &s) const
+{
+ if (pass) {
+ s << "PASS\n";
+ }
+ else {
+ s << "FAIL\n";
+ }
+}
+
+
+bool
+BufferObjectResult::getresults(istream &s)
+{
+ char result[1000];
+ s >> result;
+
+ if (strcmp(result, "FAIL") == 0) {
+ pass = false;
+ }
+ else {
+ pass = true;
+ }
+ return s.good();
+}
+
+
+// The test object itself:
+BufferObjectTest bufferObjectTest("bufferObject",
+ "window, rgb",
+ "", // no extension tests
+ "Test buffer object features and extensions such as:\n"
+ " GL_ARB_vertex_buffer_object\n"
+ " GL_ARB_pixel_buffer_object\n"
+ " GL_ARB_copy_buffer\n"
+ " GL_ARB_map_buffer_range\n");
+
+
+
+} // namespace GLEAN
+
+
diff --git a/tests/glean/tbufferobject.h b/tests/glean/tbufferobject.h
new file mode 100644
index 000000000..f2dacad3c
--- /dev/null
+++ b/tests/glean/tbufferobject.h
@@ -0,0 +1,76 @@
+// BEGIN_COPYRIGHT -*- glean -*-
+//
+// Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the
+// Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL VMWARE BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// END_COPYRIGHT
+
+#ifndef __tbufferobject_h__
+#define __tbufferobject_h__
+
+#include "tbase.h"
+#include "rand.h"
+
+namespace GLEAN {
+
+#define windowSize 100
+
+class BufferObjectResult: public BaseResult
+{
+public:
+ bool pass;
+
+ BufferObjectResult();
+
+ virtual void putresults(ostream& s) const;
+ virtual bool getresults(istream& s);
+};
+
+
+class BufferObjectTest: public BaseTest<BufferObjectResult>
+{
+public:
+ GLEAN_CLASS_WH(BufferObjectTest, BufferObjectResult,
+ windowSize, windowSize);
+
+private:
+ bool have_ARB_vertex_buffer_object;
+ bool have_ARB_pixel_buffer_object;
+ bool have_ARB_copy_buffer;
+ bool have_ARB_map_buffer_range;
+
+ GLenum target1, target2;
+
+ RandomBase rand;
+
+ bool setup(void);
+
+ bool testCopyBuffer(void);
+ bool testMapBufferRange(void);
+};
+
+} // namespace GLEAN
+
+#endif // __tbufferobject_h__
+
diff --git a/tests/glean/tclipflat.cpp b/tests/glean/tclipflat.cpp
new file mode 100644
index 000000000..3246fbf8f
--- /dev/null
+++ b/tests/glean/tclipflat.cpp
@@ -0,0 +1,539 @@
+// BEGIN_COPYRIGHT -*- glean -*-
+//
+// Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the
+// Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL VMWARE BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// END_COPYRIGHT
+
+
+// Test that the correct provoking vertex is used when a tri/quad/polygon
+// is clipped for glShadeModel(GL_FLAT).
+//
+// Test with glDrawArrays and glBegin/End. Test GL_CCW and GL_CW winding.
+// Back-face polygon culling is enabled so if the winding order of any
+// primitive is incorrect, nothing may be drawn.
+//
+// XXX We should also test with two-sided lighting.
+//
+// If GL_EXT_provoking_vertex is supported, that feature is tested as well.
+//
+// Author: Brian Paul
+
+
+#include <cassert>
+#include <cstring>
+#include "tclipflat.h"
+
+
+namespace GLEAN {
+
+
+static PFNGLPROVOKINGVERTEXEXTPROC ProvokingVertexEXT_func = NULL;
+
+
+// Note: all correctly rendered tris/quad/polygons will be green.
+// Any other color indicates that the wrong vertex color was used.
+
+
+// GL_TRIANGLES: provoking vertex = last of tri
+static const GLfloat TriVerts[6][5] =
+ {
+ // R G B X Y
+ { 1, 0, 0, -1, -1 },
+ { 0, 0, 1, 1, -1 },
+ { 0, 1, 0, 1, 1 }, // PV
+
+ { 0, 0, 1, 1, 1 },
+ { 1, 0, 0, -1, 1 },
+ { 0, 1, 0, -1, -1 } // PV
+ };
+
+// GL_TRIANGLES: first provoking vertex
+static const GLfloat TriVertsFirstPV[6][5] =
+ {
+ { 0, 1, 0, 1, 1 }, // PV
+ { 1, 0, 0, -1, -1 },
+ { 0, 0, 1, 1, -1 },
+
+ { 0, 1, 0, -1, -1 }, // PV
+ { 0, 0, 1, 1, 1 },
+ { 1, 0, 0, -1, 1 }
+ };
+
+
+// GL_TRIANGLE_STRIP: provoking vertex = last of tri
+static const GLfloat TriStripVerts[6][5] =
+ {
+ { 1, 0, 0, -1, -1 },
+ { 0, 0, 1, 1, -1 },
+ { 0, 1, 0, -1, 0 }, // PV
+ { 0, 1, 0, 1, 0 }, // PV
+ { 0, 1, 0, -1, 1 }, // PV
+ { 0, 1, 0, 1, 1 } // PV
+ };
+
+// GL_TRIANGLE_STRIP: first provoking vertex
+static const GLfloat TriStripVertsFirstPV[6][5] =
+ {
+ { 0, 1, 0, -1, -1 }, // PV
+ { 0, 1, 0, 1, -1 }, // PV
+ { 0, 1, 0, -1, 0 }, // PV
+ { 0, 1, 0, 1, 0 }, // PV
+ { 1, 0, 0, -1, 1 },
+ { 0, 0, 1, 1, 1 }
+ };
+
+
+// GL_TRIANGLE_FAN: provoking vertex = last of tri
+static const GLfloat TriFanVerts[4][5] =
+ {
+ { 1, 0, 0, -1, -1 },
+ { 0, 0, 1, 1, -1 },
+ { 0, 1, 0, 1, 1 }, // PV
+ { 0, 1, 0, -1, 1 } // PV
+ };
+
+// GL_TRIANGLE_FAN: first provoking vertex
+static const GLfloat TriFanVertsFirstPV[4][5] =
+ {
+ { 0, 0, 1, 1, -1 },
+ { 0, 1, 0, 1, 1 }, // PV
+ { 0, 1, 0, -1, 1 }, // PV
+ { 1, 0, 0, -1, -1 }
+ };
+
+
+// GL_QUADS: provoking vertex = last of quad
+static const GLfloat QuadVerts[4][5] =
+ {
+ { 1, 0, 0, -1, -1 },
+ { 0, 0, 1, 1, -1 },
+ { 1, 1, 0, 1, 1 },
+ { 0, 1, 0, -1, 1 } // PV
+ };
+
+// GL_QUADS: first provoking vertex
+static const GLfloat QuadVertsFirstPV[4][5] =
+ {
+ { 0, 1, 0, -1, 1 }, // PV
+ { 1, 0, 0, -1, -1 },
+ { 0, 0, 1, 1, -1 },
+ { 1, 1, 0, 1, 1 }
+ };
+
+
+// GL_QUAD_STRIP: provoking vertex = last of quad
+static const GLfloat QuadStripVerts[6][5] =
+ {
+ { 1, 0, 0, -1, -1 },
+ { 0, 0, 1, 1, -1 },
+ { 1, 1, 0, -1, 0 },
+ { 0, 1, 0, 1, 0 }, // PV
+ { 1, 1, 0, -1, 1 },
+ { 0, 1, 0, 1, 1 } // PV
+ };
+
+// GL_QUAD_STRIP: first provoking vertex
+static const GLfloat QuadStripVertsFirstPV[6][5] =
+ {
+ { 0, 1, 0, -1, -1 }, // PV
+ { 1, 1, 0, 1, -1 },
+ { 0, 1, 0, -1, 0 }, // PV
+ { 1, 0, 0, 1, 0 },
+ { 0, 0, 1, -1, 1 },
+ { 1, 0, 0, 1, 1 }
+ };
+
+
+// GL_POLYGON: provoking vertex = first vertex
+static const GLfloat PolygonVerts[4][5] =
+ {
+ { 0, 1, 0, -1, -1 }, // PV
+ { 1, 0, 0, 1, -1 },
+ { 0, 0, 1, 1, 1 },
+ { 1, 1, 0, -1, 1 }
+ };
+
+
+#define Elements(array) (sizeof(array) / sizeof(array[0]))
+
+
+ClipFlatResult::ClipFlatResult()
+{
+ pass = false;
+}
+
+
+void
+ClipFlatTest::setup(void)
+{
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1.25, 1.25, -1.25, 1.25, -1, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glShadeModel(GL_FLAT);
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+
+ glFrontFace(GL_CW);
+ glCullFace(GL_FRONT);
+ glEnable(GL_CULL_FACE);
+
+ provoking_vertex_first = GLUtils::haveExtension("GL_EXT_provoking_vertex");
+
+ if (provoking_vertex_first) {
+ ProvokingVertexEXT_func = reinterpret_cast<PFNGLPROVOKINGVERTEXEXTPROC>
+ (GLUtils::getProcAddress("glProvokingVertexEXT"));
+
+ GLboolean k;
+ glGetBooleanv(GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT, &k);
+ quads_follows_pv_convention = k;
+ }
+}
+
+
+// Draw with glDrawArrays()
+void
+ClipFlatTest::drawArrays(GLenum mode, const GLfloat *verts, GLuint count)
+{
+ glColorPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), verts + 0);
+ glVertexPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), verts + 3);
+ glEnable(GL_COLOR_ARRAY);
+ glEnable(GL_VERTEX_ARRAY);
+
+ glDrawArrays(mode, 0, count);
+
+ glDisable(GL_COLOR_ARRAY);
+ glDisable(GL_VERTEX_ARRAY);
+}
+
+
+// Draw with glBegin/End()
+void
+ClipFlatTest::drawBeginEnd(GLenum mode, const GLfloat *verts, GLuint count)
+{
+ GLuint i;
+
+ glBegin(mode);
+ for (i = 0; i < count; i++) {
+ glColor3fv(verts + i * 5);
+ glVertex2fv(verts + i * 5 + 3);
+ }
+ glEnd();
+}
+
+
+// Read pixels and check pixels. All pixels should be green or black.
+// Any other color indicates a failure.
+bool
+ClipFlatTest::checkResult(Window &w, GLfloat badColor[3])
+{
+ GLubyte image[windowSize * windowSize * 3];
+ GLuint i, j;
+ GLboolean anyGreen = GL_FALSE;
+
+ badColor[0] = badColor[1] = badColor[2] = 0.0f;
+
+ glReadPixels(0, 0, windowSize, windowSize,
+ GL_RGB, GL_UNSIGNED_BYTE, image);
+
+ w.swap();
+
+ for (i = 0; i < windowSize; i++) {
+ for (j = 0; j < windowSize; j++) {
+ GLuint k = (i * windowSize + j) * 3;
+
+ if (image[k + 0] == 0 &&
+ image[k + 1] == 0 &&
+ image[k + 2] == 0) {
+ // black - OK
+ }
+ else if (image[k + 0] == 0 &&
+ image[k + 1] == 255 &&
+ image[k + 0] == 0) {
+ // green - OK
+ anyGreen = GL_TRUE;
+ }
+ else {
+ // any other color = failure
+ badColor[0] = image[k + 0] / 255.0;
+ badColor[1] = image[k + 1] / 255.0;
+ badColor[2] = image[k + 2] / 255.0;
+ // sleep(10);
+ return false;
+ }
+ }
+ }
+ return anyGreen;
+}
+
+
+void
+ClipFlatTest::reportFailure(GLenum mode, GLuint arrayMode, GLuint facing,
+ const GLfloat badColor[3])
+{
+ const char *m, *d, *f;
+
+ switch (mode) {
+ case GL_TRIANGLES:
+ m = "GL_TRIANGLES";
+ break;
+ case GL_TRIANGLE_STRIP:
+ m = "GL_TRIANGLE_STRIP";
+ break;
+ case GL_TRIANGLE_FAN:
+ m = "GL_TRIANGLE_FAN";
+ break;
+ case GL_QUADS:
+ m = "GL_QUADS";
+ break;
+ case GL_QUAD_STRIP:
+ m = "GL_QUAD_STRIP";
+ break;
+ case GL_POLYGON:
+ m = "GL_POLYGON";
+ break;
+ default:
+ m = "???";
+ }
+
+ if (arrayMode)
+ d = "glDrawArrays";
+ else
+ d = "glBegin/End";
+
+ if (facing == 0)
+ f = "GL_CCW";
+ else
+ f = "GL_CW";
+
+ env->log << name << ": Failure for "
+ << d << "(" << m << "), glFrontFace("
+ << f << ")\n";
+
+ if (testing_first_pv)
+ env->log << "\tGL_EXT_provoking_vertex test: GL_FIRST_VERTEX_CONVENTION_EXT mode\n";
+
+ env->log << "\tExpected color (0, 1, 0) but found ("
+ << badColor[0] << ", "
+ << badColor[1] << ", "
+ << badColor[2] << ")\n";
+}
+
+
+// Test drawing/clipping at nine positions of which 8 will be clipped.
+bool
+ClipFlatTest::testPositions(Window &w, GLenum mode,
+ const GLfloat *verts, GLuint count)
+{
+ GLfloat x, y;
+ GLuint arrayMode, facing;
+
+ // glBegin mode and glDrawArrays mode:
+ for (arrayMode = 0; arrayMode < 2; arrayMode++) {
+
+ // Test CW, CCW winding (should make no difference)
+ for (facing = 0; facing < 2; facing++) {
+
+ if (facing == 0) {
+ glFrontFace(GL_CCW);
+ glCullFace(GL_BACK);
+ }
+ else {
+ glFrontFace(GL_CW);
+ glCullFace(GL_FRONT);
+ }
+
+ // Test clipping at 9 locations.
+ // Only the center location will be unclipped.
+ for (y = -1.0; y <= 1.0; y += 1.0) {
+ for (x = -1.0; x <= 1.0; x += 1.0) {
+ glPushMatrix();
+ glTranslatef(x, y, 0.0);
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ if (arrayMode)
+ drawArrays(mode, verts, count);
+ else
+ drawBeginEnd(mode, verts, count);
+
+ glPopMatrix();
+
+ GLfloat badColor[3];
+ if (!checkResult(w, badColor)) {
+ reportFailure(mode, arrayMode, facing, badColor);
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return true;
+}
+
+
+void
+ClipFlatTest::runOne(ClipFlatResult &r, Window &w)
+{
+ setup();
+
+ testing_first_pv = false;
+ r.pass = true;
+
+ if (r.pass)
+ r.pass = testPositions(w, GL_TRIANGLES,
+ (GLfloat *) TriVerts,
+ Elements(TriVerts));
+
+ if (r.pass)
+ r.pass = testPositions(w, GL_TRIANGLE_STRIP,
+ (GLfloat *) TriStripVerts,
+ Elements(TriStripVerts));
+
+ if (r.pass)
+ r.pass = testPositions(w, GL_TRIANGLE_FAN,
+ (GLfloat *) TriFanVerts,
+ Elements(TriFanVerts));
+
+ if (r.pass)
+ r.pass = testPositions(w, GL_QUADS,
+ (GLfloat *) QuadVerts,
+ Elements(QuadVerts));
+
+ if (r.pass)
+ r.pass = testPositions(w, GL_QUAD_STRIP,
+ (GLfloat *) QuadStripVerts,
+ Elements(QuadStripVerts));
+
+ if (r.pass)
+ r.pass = testPositions(w, GL_POLYGON,
+ (GLfloat *) PolygonVerts,
+ Elements(PolygonVerts));
+
+ if (provoking_vertex_first) {
+ ProvokingVertexEXT_func(GL_FIRST_VERTEX_CONVENTION_EXT);
+ testing_first_pv = true;
+
+ if (r.pass)
+ r.pass = testPositions(w, GL_TRIANGLES,
+ (GLfloat *) TriVertsFirstPV,
+ Elements(TriVertsFirstPV));
+
+ if (r.pass)
+ r.pass = testPositions(w, GL_TRIANGLE_STRIP,
+ (GLfloat *) TriStripVertsFirstPV,
+ Elements(TriStripVertsFirstPV));
+
+ if (r.pass)
+ r.pass = testPositions(w, GL_TRIANGLE_FAN,
+ (GLfloat *) TriFanVertsFirstPV,
+ Elements(TriFanVertsFirstPV));
+
+ if (r.pass) {
+ if (quads_follows_pv_convention)
+ r.pass = testPositions(w, GL_QUADS,
+ (GLfloat *) QuadVertsFirstPV,
+ Elements(QuadVertsFirstPV));
+ else
+ r.pass = testPositions(w, GL_QUADS,
+ (GLfloat *) QuadVerts,
+ Elements(QuadVerts));
+ }
+
+ if (r.pass) {
+ if (quads_follows_pv_convention)
+ r.pass = testPositions(w, GL_QUAD_STRIP,
+ (GLfloat *) QuadStripVertsFirstPV,
+ Elements(QuadStripVertsFirstPV));
+ else
+ r.pass = testPositions(w, GL_QUAD_STRIP,
+ (GLfloat *) QuadStripVerts,
+ Elements(QuadStripVerts));
+ }
+
+ if (r.pass) {
+ r.pass = testPositions(w, GL_POLYGON,
+ (GLfloat *) PolygonVerts,
+ Elements(PolygonVerts));
+ }
+ }
+}
+
+
+void
+ClipFlatTest::logOne(ClipFlatResult &r)
+{
+ logPassFail(r);
+ logConcise(r);
+}
+
+
+void
+ClipFlatTest::compareOne(ClipFlatResult &oldR,
+ ClipFlatResult &newR)
+{
+ comparePassFail(oldR, newR);
+}
+
+
+void
+ClipFlatResult::putresults(ostream &s) const
+{
+ if (pass) {
+ s << "PASS\n";
+ }
+ else {
+ s << "FAIL\n";
+ }
+}
+
+
+bool
+ClipFlatResult::getresults(istream &s)
+{
+ char result[1000];
+ s >> result;
+
+ if (strcmp(result, "FAIL") == 0) {
+ pass = false;
+ }
+ else {
+ pass = true;
+ }
+ return s.good();
+}
+
+
+// The test object itself:
+ClipFlatTest newTest("clipFlat", "window, rgb",
+ "",
+ "Test clipping with flat shading (provoking vertex).\n");
+
+
+
+} // namespace GLEAN
+
+
diff --git a/tests/glean/tclipflat.h b/tests/glean/tclipflat.h
new file mode 100644
index 000000000..98cd8312e
--- /dev/null
+++ b/tests/glean/tclipflat.h
@@ -0,0 +1,77 @@
+// BEGIN_COPYRIGHT -*- glean -*-
+//
+// Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the
+// Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL VMWARE BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// END_COPYRIGHT
+
+// tclipflat.h: Test clipping and flat shading
+
+#ifndef __tclipflat_h__
+#define __tclipflat_h__
+
+#include "tbase.h"
+
+namespace GLEAN {
+
+#define windowSize 100
+
+class ClipFlatResult: public BaseResult
+{
+public:
+ bool pass;
+
+ ClipFlatResult();
+
+ virtual void putresults(ostream& s) const;
+ virtual bool getresults(istream& s);
+};
+
+
+class ClipFlatTest: public BaseTest<ClipFlatResult>
+{
+public:
+ GLEAN_CLASS_WH(ClipFlatTest, ClipFlatResult,
+ windowSize, windowSize);
+
+private:
+ bool provoking_vertex_first;
+ bool quads_follows_pv_convention;
+ bool testing_first_pv;
+
+ void drawArrays(GLenum mode, const GLfloat *verts, GLuint count);
+ void drawBeginEnd(GLenum mode, const GLfloat *verts, GLuint count);
+ bool testPositions(Window &w, GLenum mode,
+ const GLfloat *verts, GLuint count);
+ void reportFailure(GLenum mode, GLuint arrayMode, GLuint facing,
+ const GLfloat badColor[3]);
+ bool checkResult(Window &w, GLfloat badColor[3]);
+
+ void setup(void);
+};
+
+} // namespace GLEAN
+
+#endif // __tclipflat_h__
+
diff --git a/tests/glean/tfbo.cpp b/tests/glean/tfbo.cpp
index ddfea1ccc..fd044b8c5 100644
--- a/tests/glean/tfbo.cpp
+++ b/tests/glean/tfbo.cpp
@@ -43,8 +43,33 @@
namespace GLEAN
{
-static int useFramebuffer;
+// GL_VERSION_1_2
+static PFNGLTEXIMAGE3DPROC glTexImage3D_func = NULL;
+static PFNGLCOPYTEXSUBIMAGE3DPROC glCopyTexSubImage3D_func = NULL;
+
+// GL_VERSION_1_3
+static PFNGLACTIVETEXTUREPROC glActiveTexture_func = NULL;
+static PFNGLMULTITEXCOORD2FPROC glMultiTexCoord2f_func = NULL;
+
+// GL_EXT_framebuffer_object
+static PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT_func = NULL;
+static PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT_func = NULL;
+static PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT_func = NULL;
+static PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT_func = NULL;
+static PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT_func = NULL;
+static PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT_func = NULL;
+static PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT_func = NULL;
+static PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT_func = NULL;
+static PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT_func = NULL;
+static PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT_func = NULL;
+static PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT_func = NULL;
+static PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT_func = NULL;
+static PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT_func = NULL;
+static PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT_func = NULL;
+static int useFramebuffer;
bool
FBOTest::setup(void)
@@ -97,6 +122,49 @@ FBOTest::setup(void)
else
printf("GL_ARB_framebuffer_object is not supported\n");
+ glTexImage3D_func = (PFNGLTEXIMAGE3DPROC) GLUtils::getProcAddress("glTexImage3D");
+ assert(glTexImage3D_func);
+ glCopyTexSubImage3D_func = (PFNGLCOPYTEXSUBIMAGE3DPROC) GLUtils::getProcAddress("glCopyTexSubImage3D");
+ assert(glCopyTexSubImage3D_func);
+
+ glActiveTexture_func = (PFNGLACTIVETEXTUREPROC) GLUtils::getProcAddress("glActiveTexture");
+ assert(glActiveTexture_func);
+ glMultiTexCoord2f_func = (PFNGLMULTITEXCOORD2FPROC) GLUtils::getProcAddress("glMultiTexCoord2f");
+ assert(glMultiTexCoord2f_func);
+
+ glIsRenderbufferEXT_func = (PFNGLISRENDERBUFFEREXTPROC) GLUtils::getProcAddress("glIsRenderbufferEXT");
+ assert(glIsRenderbufferEXT_func);
+ glBindRenderbufferEXT_func = (PFNGLBINDRENDERBUFFEREXTPROC) GLUtils::getProcAddress("glBindRenderbufferEXT");
+ assert(glBindRenderbufferEXT_func);
+ glDeleteRenderbuffersEXT_func = (PFNGLDELETERENDERBUFFERSEXTPROC) GLUtils::getProcAddress("glDeleteRenderbuffersEXT");
+ assert(glDeleteRenderbuffersEXT_func);
+ glGenRenderbuffersEXT_func = (PFNGLGENRENDERBUFFERSEXTPROC) GLUtils::getProcAddress("glGenRenderbuffersEXT");
+ assert(glGenRenderbuffersEXT_func);
+ glRenderbufferStorageEXT_func = (PFNGLRENDERBUFFERSTORAGEEXTPROC) GLUtils::getProcAddress("glRenderbufferStorageEXT");
+ assert(glRenderbufferStorageEXT_func);
+ glGetRenderbufferParameterivEXT_func = (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) GLUtils::getProcAddress("glGetRenderbufferParameterivEXT");
+ assert(glGetRenderbufferParameterivEXT_func);
+ glIsFramebufferEXT_func = (PFNGLISFRAMEBUFFEREXTPROC) GLUtils::getProcAddress("glIsFramebufferEXT");
+ assert(glIsFramebufferEXT_func);
+ glBindFramebufferEXT_func = (PFNGLBINDFRAMEBUFFEREXTPROC) GLUtils::getProcAddress("glBindFramebufferEXT");
+ assert(glBindFramebufferEXT_func);
+ glDeleteFramebuffersEXT_func = (PFNGLDELETEFRAMEBUFFERSEXTPROC) GLUtils::getProcAddress("glDeleteFramebuffersEXT");
+ assert(glDeleteFramebuffersEXT_func);
+ glGenFramebuffersEXT_func = (PFNGLGENFRAMEBUFFERSEXTPROC) GLUtils::getProcAddress("glGenFramebuffersEXT");
+ assert(glGenFramebuffersEXT_func);
+ glCheckFramebufferStatusEXT_func = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) GLUtils::getProcAddress("glCheckFramebufferStatusEXT");
+ assert(glCheckFramebufferStatusEXT_func);
+ glFramebufferTexture1DEXT_func = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) GLUtils::getProcAddress("glFramebufferTexture1DEXT");
+ assert(glFramebufferTexture1DEXT_func);
+ glFramebufferTexture2DEXT_func = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) GLUtils::getProcAddress("glFramebufferTexture2DEXT");
+ assert(glFramebufferTexture2DEXT_func);
+ glFramebufferTexture3DEXT_func = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) GLUtils::getProcAddress("glFramebufferTexture3DEXT");
+ assert(glFramebufferTexture3DEXT_func);
+ glFramebufferRenderbufferEXT_func = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) GLUtils::getProcAddress("glFramebufferRenderbufferEXT");
+ assert(glFramebufferRenderbufferEXT_func);
+ glGetFramebufferAttachmentParameterivEXT_func = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) GLUtils::getProcAddress("glGetFramebufferAttachmentParameterivEXT");
+ assert(glGetFramebufferAttachmentParameterivEXT_func);
+
return true;
}
@@ -177,41 +245,45 @@ FBOTest::checkResult(const GLfloat color[4], const int depth,
}
-#define CHECK_FRAMEBUFFER_STATUS(func) \
-{ \
- GLenum status; \
- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); \
- switch(status) { \
- case GL_FRAMEBUFFER_COMPLETE_EXT: \
- /*printf(" (%s:%d)GL_FRAMEBUFFER_COMPLETE_EXT\n", func, __LINE__);*/ \
- break; \
- case GL_FRAMEBUFFER_UNSUPPORTED_EXT: \
- printf(" (%s:%d)GL_FRAMEBUFFER_UNSUPPORTED_EXT\n", func, __LINE__); \
- /* choose different formats */ \
- break; \
- case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: \
- printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT\n", func, __LINE__); \
- break; \
- case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: \
- printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT\n", func, __LINE__); \
- break; \
- case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: \
- printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n", func, __LINE__); \
- break; \
- case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: \
- printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT\n", func, __LINE__);\
- break; \
- case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: \
- printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT\n", func, __LINE__);\
- break; \
- case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: \
- printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT\n", func, __LINE__);\
- break; \
- default: \
- /* programming error; will fail on all hardware */ \
- printf(" (%s:%d)programming error\n", func, __LINE__); \
- break; \
- } \
+// Check FB status, print unexpected results to stdout.
+static GLenum
+CheckFramebufferStatus(const char *func, int line)
+{
+ GLenum status;
+ status = glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT);
+
+ switch(status) {
+ case GL_FRAMEBUFFER_COMPLETE_EXT:
+ /*printf(" (%s:%d)GL_FRAMEBUFFER_COMPLETE_EXT\n", func, line);*/
+ break;
+ case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
+ printf(" (%s:%d)GL_FRAMEBUFFER_UNSUPPORTED_EXT\n", func, line);
+ /* choose different formats */
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
+ printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT\n", func, line);
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
+ printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT\n", func, line);
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
+ printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n", func, line);
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
+ printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT\n", func, line);
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
+ printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT\n", func, line);
+ break;
+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
+ printf(" (%s:%d)GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT\n", func, line);
+ break;
+ default:
+ /* programming error; will fail on all hardware */
+ printf(" (%s:%d)programming error\n", func, line);
+ break;
+ }
+ return status;
}
@@ -255,23 +327,23 @@ FBOTest::testSanity(void)
return false;
}
- glGenFramebuffersEXT(1, fbs);
+ glGenFramebuffersEXT_func(1, fbs);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, (GLint *) & fb_binding);
if (fb_binding != fbs[0]) {
printf(" fb_binding = %d\n", fb_binding);
REPORT_FAILURE("Binding framebuffer failed");
return false;
}
- if (glIsFramebufferEXT(fbs[0]) != GL_TRUE)
+ if (glIsFramebufferEXT_func(fbs[0]) != GL_TRUE)
{
REPORT_FAILURE("Call glIsFramebufferEXT failed");
return false;
}
- glDeleteFramebuffersEXT(1, fbs);
+ glDeleteFramebuffersEXT_func(1, fbs);
GLint maxRenderbufferSize;
@@ -290,7 +362,7 @@ FBOTest::testSanity(void)
void
FBOTest::reset(void)
{
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, 0);
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
}
@@ -309,7 +381,7 @@ FBOTest::testRender2SingleTexture(void)
GLuint textures[1];
int mode;
int maxzoffset = -1;
-
+ GLenum status;
glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &maxzoffset);
if (maxzoffset > 16)
@@ -318,15 +390,15 @@ FBOTest::testRender2SingleTexture(void)
for (depthBuffer = 0; depthBuffer < 2; depthBuffer++) {
for (stencilBuffer = 0; stencilBuffer < 2; stencilBuffer++) {
for (mode = 0; mode < 4; mode++) {
- if (mode == 2&&maxzoffset <= 0)
+
+ //
+ // Setup state to test
+ //
+ if (mode == 2 && maxzoffset <= 0)
continue;
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT |
- GL_DEPTH_BUFFER_BIT |
- GL_STENCIL_BUFFER_BIT);
if (useFramebuffer)
- glGenFramebuffersEXT(1, fbs);
+ glGenFramebuffersEXT_func(1, fbs);
glGenTextures(1, textures);
glBindTexture(textureModes[mode],
@@ -353,7 +425,7 @@ FBOTest::testRender2SingleTexture(void)
GL_RGB, GL_INT, NULL);
break;
case GL_TEXTURE_3D:
- glTexImage3D(GL_TEXTURE_3D,
+ glTexImage3D_func(GL_TEXTURE_3D,
0, GL_RGB,
TEXSIZE,
TEXSIZE,
@@ -396,7 +468,7 @@ FBOTest::testRender2SingleTexture(void)
if (useFramebuffer) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
int height = TEXSIZE;
if (textureModes[mode] == GL_TEXTURE_1D)
@@ -405,28 +477,28 @@ FBOTest::testRender2SingleTexture(void)
if (depthBuffer) {
int params;
- glGenRenderbuffersEXT(1, depth_rb);
+ glGenRenderbuffersEXT_func(1, depth_rb);
- glBindRenderbufferEXT
+ glBindRenderbufferEXT_func
(GL_RENDERBUFFER_EXT,
depth_rb[0]);
- if (glIsRenderbufferEXT(depth_rb[0]) != GL_TRUE)
+ if (glIsRenderbufferEXT_func(depth_rb[0]) != GL_TRUE)
{
REPORT_FAILURE("Call glIsRenderbufferEXT failed\n");
return false;
}
- glRenderbufferStorageEXT
+ glRenderbufferStorageEXT_func
(GL_RENDERBUFFER_EXT,
GL_DEPTH_COMPONENT,
TEXSIZE, height);
- glFramebufferRenderbufferEXT
+ glFramebufferRenderbufferEXT_func
(GL_FRAMEBUFFER_EXT,
GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT,
depth_rb[0]);
- glGetRenderbufferParameterivEXT
+ glGetRenderbufferParameterivEXT_func
(GL_RENDERBUFFER_EXT,
GL_RENDERBUFFER_WIDTH_EXT,
&params);
@@ -436,7 +508,7 @@ FBOTest::testRender2SingleTexture(void)
printf("width = %d\n", params);
return false;
}
- glGetRenderbufferParameterivEXT
+ glGetRenderbufferParameterivEXT_func
(GL_RENDERBUFFER_EXT,
GL_RENDERBUFFER_HEIGHT_EXT,
&params);
@@ -451,18 +523,18 @@ FBOTest::testRender2SingleTexture(void)
int type;
type = -1;
- glGenRenderbuffersEXT(1, stencil_rb);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, stencil_rb[0]);
- glRenderbufferStorageEXT
+ glGenRenderbuffersEXT_func(1, stencil_rb);
+ glBindRenderbufferEXT_func(GL_RENDERBUFFER_EXT, stencil_rb[0]);
+ glRenderbufferStorageEXT_func
(GL_RENDERBUFFER_EXT,
GL_STENCIL_INDEX,
TEXSIZE, height);
- glFramebufferRenderbufferEXT
+ glFramebufferRenderbufferEXT_func
(GL_FRAMEBUFFER_EXT,
GL_STENCIL_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT,
stencil_rb[0]);
- glGetFramebufferAttachmentParameterivEXT
+ glGetFramebufferAttachmentParameterivEXT_func
(GL_FRAMEBUFFER_EXT,
GL_STENCIL_ATTACHMENT_EXT,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT,
@@ -475,18 +547,17 @@ FBOTest::testRender2SingleTexture(void)
}
}
-
switch (textureModes[mode]) {
case GL_TEXTURE_1D:
int name;
name = -1;
- glFramebufferTexture1DEXT
+ glFramebufferTexture1DEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_1D,
textures[0], 0);
- glGetFramebufferAttachmentParameterivEXT
+ glGetFramebufferAttachmentParameterivEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT,
@@ -503,12 +574,12 @@ FBOTest::testRender2SingleTexture(void)
int level;
level = -1;
- glFramebufferTexture2DEXT
+ glFramebufferTexture2DEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D,
textures[0], 0);
- glGetFramebufferAttachmentParameterivEXT
+ glGetFramebufferAttachmentParameterivEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT,
@@ -525,7 +596,7 @@ FBOTest::testRender2SingleTexture(void)
int zoffset;
zoffset = -1;
- glFramebufferTexture3DEXT
+ glFramebufferTexture3DEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_3D,
@@ -533,7 +604,7 @@ FBOTest::testRender2SingleTexture(void)
0,
maxzoffset-1);
- glGetFramebufferAttachmentParameterivEXT
+ glGetFramebufferAttachmentParameterivEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT,
@@ -549,12 +620,12 @@ FBOTest::testRender2SingleTexture(void)
case GL_TEXTURE_CUBE_MAP:
int face = 0;
- glFramebufferTexture2DEXT
+ glFramebufferTexture2DEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
textures[0], 0);
- glGetFramebufferAttachmentParameterivEXT
+ glGetFramebufferAttachmentParameterivEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT,
@@ -571,9 +642,20 @@ FBOTest::testRender2SingleTexture(void)
break;
}
- CHECK_FRAMEBUFFER_STATUS("FBOTest::testRender2SingleTexture");
+ status = CheckFramebufferStatus("FBOTest::testRender2SingleTexture", __LINE__);
}
+ else {
+ status = GL_FRAMEBUFFER_COMPLETE_EXT;
+ }
+
+
+ if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
+ continue;
+
+ //
+ // Render, test the results
+ //
if (depthBuffer) {
glClear(GL_DEPTH_BUFFER_BIT);
@@ -665,7 +747,7 @@ FBOTest::testRender2SingleTexture(void)
glBindTexture(textureModes[mode],
textures[0]);
if (useFramebuffer) {
- glBindFramebufferEXT
+ glBindFramebufferEXT_func
(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(textureModes
[mode], textures[0]);
@@ -687,7 +769,7 @@ FBOTest::testRender2SingleTexture(void)
TEXSIZE, 0);
break;
case GL_TEXTURE_3D:
- glCopyTexSubImage3D
+ glCopyTexSubImage3D_func
(GL_TEXTURE_3D,
0, 0, 0,
0, 0, 0,
@@ -747,11 +829,11 @@ FBOTest::testRender2SingleTexture(void)
glDeleteTextures(1, textures);
if (useFramebuffer)
- glDeleteFramebuffersEXT(1, fbs);
+ glDeleteFramebuffersEXT_func(1, fbs);
if (depthBuffer)
- glDeleteRenderbuffersEXT(1, depth_rb);
+ glDeleteRenderbuffersEXT_func(1, depth_rb);
if (stencilBuffer)
- glDeleteRenderbuffersEXT(1, stencil_rb);
+ glDeleteRenderbuffersEXT_func(1, stencil_rb);
// getchar();
if (checkResult(colors[RED], depthBuffer, stencilBuffer) == false) {
@@ -801,7 +883,7 @@ FBOTest::testRender2MultiTexture(void)
numFBO = 1;
if (useFramebuffer)
- glGenFramebuffersEXT(numFBO, fbs);
+ glGenFramebuffersEXT_func(numFBO, fbs);
GLint maxTexUnits;
@@ -817,7 +899,7 @@ FBOTest::testRender2MultiTexture(void)
else
idx = i;
- glActiveTexture(GL_TEXTURE0 + idx);
+ glActiveTexture_func(GL_TEXTURE0 + idx);
glBindTexture(GL_TEXTURE_2D, textures[idx]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
TEXSIZE, TEXSIZE, 0, GL_RGB,
@@ -825,18 +907,18 @@ FBOTest::testRender2MultiTexture(void)
if (useFramebuffer) {
if (mode == MULTI_FBO)
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[i]);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[i]);
else
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
if (mode != SINGLE_COLOR_ATTACH)
- glFramebufferTexture2DEXT
+ glFramebufferTexture2DEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT + i,
GL_TEXTURE_2D,
textures[idx], 0);
else
- glFramebufferTexture2DEXT
+ glFramebufferTexture2DEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D,
@@ -849,7 +931,7 @@ FBOTest::testRender2MultiTexture(void)
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
}
- CHECK_FRAMEBUFFER_STATUS("FBOTest::testRender2MultiTexture");
+ CheckFramebufferStatus("FBOTest::testRender2MultiTexture", __LINE__);
}
}
@@ -866,18 +948,18 @@ FBOTest::testRender2MultiTexture(void)
if (useFramebuffer) {
if (mode == MULTI_FBO)
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[i]);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[i]);
else
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
if (mode == MULTI_COLOR_ATTACH) {
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + idx);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + idx);
}
- CHECK_FRAMEBUFFER_STATUS("FBOTest::testRender2MultiTexture");
+ CheckFramebufferStatus("FBOTest::testRender2MultiTexture", __LINE__);
if (mode == SINGLE_COLOR_ATTACH) {
- glFramebufferTexture2DEXT
+ glFramebufferTexture2DEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D,
@@ -903,7 +985,7 @@ FBOTest::testRender2MultiTexture(void)
glEnable(GL_TEXTURE_2D);
if (useFramebuffer) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, textures[idx]);
}
else {
@@ -916,7 +998,7 @@ FBOTest::testRender2MultiTexture(void)
}
// Clean up
if (useFramebuffer)
- glDeleteFramebuffersEXT(numFBO, fbs);
+ glDeleteFramebuffersEXT_func(numFBO, fbs);
// Render to the window
@@ -928,7 +1010,7 @@ FBOTest::testRender2MultiTexture(void)
else
idx = i;
- glActiveTexture(GL_TEXTURE0 + idx);
+ glActiveTexture_func(GL_TEXTURE0 + idx);
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -941,13 +1023,13 @@ FBOTest::testRender2MultiTexture(void)
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
- glMultiTexCoord2f(GL_TEXTURE0 + idx, 0, 0);
+ glMultiTexCoord2f_func(GL_TEXTURE0 + idx, 0, 0);
glVertex3f(0, 0, 1);
- glMultiTexCoord2f(GL_TEXTURE0 + idx, 1, 0);
+ glMultiTexCoord2f_func(GL_TEXTURE0 + idx, 1, 0);
glVertex3f(TEXSIZE, 0, 1);
- glMultiTexCoord2f(GL_TEXTURE0 + idx, 1, 1);
+ glMultiTexCoord2f_func(GL_TEXTURE0 + idx, 1, 1);
glVertex3f(TEXSIZE, TEXSIZE, 1);
- glMultiTexCoord2f(GL_TEXTURE0 + idx, 0, 1);
+ glMultiTexCoord2f_func(GL_TEXTURE0 + idx, 0, 1);
glVertex3f(0, TEXSIZE, 1);
glEnd();
@@ -962,7 +1044,7 @@ FBOTest::testRender2MultiTexture(void)
}
glDisable(GL_TEXTURE_2D);
- glActiveTexture(GL_TEXTURE0);
+ glActiveTexture_func(GL_TEXTURE0);
}
glDeleteTextures(maxTexUnits, textures);
@@ -980,7 +1062,7 @@ FBOTest::testRender2depthTexture(void)
reset();
if (useFramebuffer)
- glGenFramebuffersEXT(1, fbs);
+ glGenFramebuffersEXT_func(1, fbs);
glGenTextures(1, textures);
glBindTexture(GL_TEXTURE_2D, textures[0]);
@@ -988,14 +1070,14 @@ FBOTest::testRender2depthTexture(void)
TEXSIZE, 0, GL_DEPTH_COMPONENT, GL_INT, NULL);
if (useFramebuffer) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT,
GL_DEPTH_ATTACHMENT_EXT,
GL_TEXTURE_2D, textures[0], 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
- CHECK_FRAMEBUFFER_STATUS("FBOTest::testRender2depthTexture");
+ CheckFramebufferStatus("FBOTest::testRender2depthTexture", __LINE__);
}
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
@@ -1014,7 +1096,7 @@ FBOTest::testRender2depthTexture(void)
glEnd();
if (useFramebuffer) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
}
else {
@@ -1055,7 +1137,7 @@ FBOTest::testRender2depthTexture(void)
// Clean up
if (useFramebuffer)
- glDeleteFramebuffersEXT(1, fbs);
+ glDeleteFramebuffersEXT_func(1, fbs);
glDeleteTextures(1, textures);
// Check result
@@ -1079,13 +1161,13 @@ FBOTest::testRender2MipmapTexture(void)
reset();
if (useFramebuffer)
- glGenFramebuffersEXT(1, fbs);
+ glGenFramebuffersEXT_func(1, fbs);
glGenTextures(1, textures);
glBindTexture(GL_TEXTURE_2D, textures[0]);
if (useFramebuffer)
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
glDisable(GL_TEXTURE_2D);
@@ -1095,11 +1177,11 @@ FBOTest::testRender2MipmapTexture(void)
if (useFramebuffer) {
glTexImage2D(GL_TEXTURE_2D, level, GL_RGB,
i, i, 0, GL_RGB, GL_INT, NULL);
- glFramebufferTexture2DEXT
+ glFramebufferTexture2DEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, textures[0], level);
- CHECK_FRAMEBUFFER_STATUS("FBOTest::testRender2MipmapTexture");
+ CheckFramebufferStatus("FBOTest::testRender2MipmapTexture", __LINE__);
glColor4fv(colors[RED + (level % (WHITE - RED))]);
glClearColor(0.0, 0.0, 0.0, 0.0);
@@ -1133,7 +1215,7 @@ FBOTest::testRender2MipmapTexture(void)
}
if (useFramebuffer) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
}
glEnable(GL_TEXTURE_2D);
@@ -1167,7 +1249,7 @@ FBOTest::testRender2MipmapTexture(void)
// Clean up
if (useFramebuffer)
- glDeleteFramebuffersEXT(1, fbs);
+ glDeleteFramebuffersEXT_func(1, fbs);
glDeleteTextures(1, textures);
// Check result
@@ -1209,13 +1291,13 @@ FBOTest::testErrorHandling(void)
// At least one image attached to the framebuffer
- glGenFramebuffersEXT(1, fbs);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glGenFramebuffersEXT_func(1, fbs);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glDeleteFramebuffersEXT(1, fbs);
+ status = glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, 0);
+ glDeleteFramebuffersEXT_func(1, fbs);
if (status !=
GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT) {
REPORT_FAILURE
@@ -1225,25 +1307,25 @@ FBOTest::testErrorHandling(void)
// All attached images have the same width and height,
// unless GL_ARB_framebuffer object is supported.
- glGenFramebuffersEXT(1, fbs);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glGenFramebuffersEXT_func(1, fbs);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
glGenTextures(2, textures);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE,
TEXSIZE, 0, GL_RGB, GL_INT, NULL);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, textures[0], 0);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE / 2,
TEXSIZE / 2, 0, GL_RGB, GL_INT, NULL);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT
+ maxColorAttachment - 1,
GL_TEXTURE_2D, textures[1], 0);
- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glDeleteFramebuffersEXT(1, fbs);
+ status = glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, 0);
+ glDeleteFramebuffersEXT_func(1, fbs);
glDeleteTextures(2, textures);
if (!haveARBfbo &&
status != GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT) {
@@ -1255,25 +1337,25 @@ FBOTest::testErrorHandling(void)
// All images attached to the attachment points
// COLOR_ATTACHMENT0_EXT through COLOR_ATTACHMENTn_EXT must
// have the same internal format, unless ARB_fbo is supported.
- glGenFramebuffersEXT(1, fbs);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glGenFramebuffersEXT_func(1, fbs);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
glGenTextures(2, textures);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE,
TEXSIZE, 0, GL_RGB, GL_INT, NULL);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, textures[0], 0);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXSIZE,
TEXSIZE, 0, GL_RGBA, GL_INT, NULL);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ glFramebufferTexture2DEXT_func(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT
+ maxColorAttachment - 1,
GL_TEXTURE_2D, textures[1], 0);
- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glDeleteFramebuffersEXT(1, fbs);
+ status = glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, 0);
+ glDeleteFramebuffersEXT_func(1, fbs);
glDeleteTextures(2, textures);
if (!haveARBfbo &&
status != GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT) {
@@ -1286,13 +1368,13 @@ FBOTest::testErrorHandling(void)
// The value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT must not
// be NONE for any color attachment point(s) named by
// DRAW_BUFFERi.
- glGenFramebuffersEXT(1, fbs);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glGenFramebuffersEXT_func(1, fbs);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT +
maxColorAttachment - 1);
- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glDeleteFramebuffersEXT(1, fbs);
+ status = glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, 0);
+ glDeleteFramebuffersEXT_func(1, fbs);
if (status != GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT) {
REPORT_FAILURE
("All any buffer named by glDrawBuffers is missing, status should be GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT");
@@ -1302,14 +1384,14 @@ FBOTest::testErrorHandling(void)
// If READ_BUFFER is not NONE, then the value of
// FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT must not be NONE for
// the color attachment point named by READ_BUFFER.
- glGenFramebuffersEXT(1, fbs);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glGenFramebuffersEXT_func(1, fbs);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT +
maxColorAttachment - 1);
- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glDeleteFramebuffersEXT(1, fbs);
+ status = glCheckFramebufferStatusEXT_func(GL_FRAMEBUFFER_EXT);
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, 0);
+ glDeleteFramebuffersEXT_func(1, fbs);
if (status != GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT) {
REPORT_FAILURE
("If buffer named by glReadBuffers is missing, status should be GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT");
@@ -1358,7 +1440,7 @@ FBOTest::testPerformance(MultiTestResult & r)
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
if (mode)
- glGenFramebuffersEXT(1, fbs);
+ glGenFramebuffersEXT_func(1, fbs);
glGenTextures(1, textures);
glBindTexture(GL_TEXTURE_2D, textures[0]);
@@ -1371,19 +1453,19 @@ FBOTest::testPerformance(MultiTestResult & r)
TEXSIZE, 0, GL_RGB, GL_INT, NULL);
if (mode) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbs[0]);
- glFramebufferTexture2DEXT
+ glBindFramebufferEXT_func(GL_FRAMEBUFFER_EXT, fbs[0]);
+ glFramebufferTexture2DEXT_func
(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, textures[0], 0);
- CHECK_FRAMEBUFFER_STATUS("FBOTest::testPerformance");
+ CheckFramebufferStatus("FBOTest::testPerformance", __LINE__);
}
int i;
for (i = 0; i < 1024; i++) {
if (mode)
- glBindFramebufferEXT
+ glBindFramebufferEXT_func
(GL_FRAMEBUFFER_EXT, fbs[0]);
// Render to the texture
@@ -1403,7 +1485,7 @@ FBOTest::testPerformance(MultiTestResult & r)
// Render to the window
if (mode) {
- glBindFramebufferEXT
+ glBindFramebufferEXT_func
(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
}
@@ -1432,7 +1514,7 @@ FBOTest::testPerformance(MultiTestResult & r)
t1 = t.getClock();
glDeleteTextures(1, textures);
if (mode)
- glDeleteFramebuffersEXT(1, fbs);
+ glDeleteFramebuffersEXT_func(1, fbs);
perf[mode] =
(double) TEXSIZE *TEXSIZE * 3 / 1024 / (t1 - t0);
diff --git a/tests/glean/tfragprog1.cpp b/tests/glean/tfragprog1.cpp
index 9abe354c8..101f0bc6b 100644
--- a/tests/glean/tfragprog1.cpp
+++ b/tests/glean/tfragprog1.cpp
@@ -575,6 +575,7 @@ static const FragmentProgram Programs[] = {
DONT_CARE_Z
},
{
+ // this test checks that SOA execution is handled correctly
"swizzled move test",
"!!ARBfp1.0\n"
"TEMP t; \n"
@@ -587,6 +588,22 @@ static const FragmentProgram Programs[] = {
DONT_CARE_Z
},
{
+ // this test checks that SOA execution is handled correctly
+ "swizzled add test",
+ "!!ARBfp1.0\n"
+ "TEMP t; \n"
+ "PARAM p = program.local[1]; \n"
+ "MOV t, p; \n"
+ "ADD t, t, t.yxwz; \n" // "in-place" swizzled add
+ "MOV result.color, t; \n"
+ "END \n",
+ { CLAMP01(Param1[0] + Param1[1]),
+ CLAMP01(Param1[1] + Param1[0]),
+ CLAMP01(Param1[2] + Param1[3]),
+ CLAMP01(Param1[3] + Param1[2]) },
+ DONT_CARE_Z
+ },
+ {
"XPD test 1",
"!!ARBfp1.0\n"
"PARAM p1 = program.local[1]; \n"
diff --git a/tests/glean/tgetstr.cpp b/tests/glean/tgetstr.cpp
index 22c3347d5..48d66342c 100644
--- a/tests/glean/tgetstr.cpp
+++ b/tests/glean/tgetstr.cpp
@@ -28,11 +28,11 @@
// tgetstr.cpp: implementation of OpenGL glGetString() tests
-using namespace std;
-
#include "tgetstr.h"
#include <algorithm>
+using namespace std;
+
namespace GLEAN {
///////////////////////////////////////////////////////////////////////////////
diff --git a/tests/glean/tgetstr.h b/tests/glean/tgetstr.h
index d0465b5db..d2b53110c 100644
--- a/tests/glean/tgetstr.h
+++ b/tests/glean/tgetstr.h
@@ -37,10 +37,10 @@
#include "tbase.h"
-class DrawingSurfaceConfig; // Forward reference.
-
namespace GLEAN {
+class DrawingSurfaceConfig; // Forward reference.
+
class GetStringResult: public BaseResult {
public:
bool pass;
diff --git a/tests/glean/tglsl1.cpp b/tests/glean/tglsl1.cpp
index 42bc9c4ed..64678b958 100644
--- a/tests/glean/tglsl1.cpp
+++ b/tests/glean/tglsl1.cpp
@@ -41,6 +41,13 @@
namespace GLEAN {
+static PFNGLTEXIMAGE3DPROC glTexImage3D_func = NULL;
+
+static PFNGLACTIVETEXTUREPROC glActiveTexture_func = NULL;
+
+static PFNGLPOINTPARAMETERFPROC glPointParameterf_func = NULL;
+static PFNGLPOINTPARAMETERFVPROC glPointParameterfv_func = NULL;
+static PFNGLSECONDARYCOLOR3FVPROC glSecondaryColor3fv_func = NULL;
static PFNGLATTACHSHADERPROC glAttachShader_func = NULL;
static PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation_func = NULL;
@@ -134,6 +141,7 @@ static const GLfloat MatDiffuse[4] = MAT_DIFFUSE;
static const GLfloat LightDiffuse[4] = LIGHT_DIFFUSE;
static const GLfloat Uniform1[4] = UNIFORM1;
+static const GLfloat UniformArray[4] = { 0.1, 0.25, 0.5, 0.75 };
static const GLfloat PointAtten[3] = { PSIZE_ATTEN0, PSIZE_ATTEN1, PSIZE_ATTEN2 };
static const GLfloat FogColor[4] = { FOG_R, FOG_G, FOG_B, FOG_A };
@@ -939,7 +947,7 @@ static const ShaderProgram Programs[] = {
// Flow Control ======================================================
{
- "simple if statement",
+ "simple if statement, fragment shader",
NO_VERTEX_SHADER,
"void main() { \n"
" // this should always be true \n"
@@ -953,6 +961,23 @@ static const ShaderProgram Programs[] = {
},
{
+ "simple if statement, vertex shader",
+ "uniform vec4 uniform1; \n"
+ "void main() { \n"
+ " gl_Position = ftransform(); \n"
+ " gl_FrontColor = vec4(0.0); \n"
+ " // this should always be true \n"
+ " if (uniform1.x >= 0.0) { \n"
+ " gl_FrontColor = vec4(0.5, 0.0, 0.5, 0.0); \n"
+ " } \n"
+ "} \n",
+ NO_FRAGMENT_SHADER,
+ { 0.5, 0.0, 0.5, 0.0 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
"simple if statement (scalar test)",
NO_VERTEX_SHADER,
"void main() { \n"
@@ -967,7 +992,7 @@ static const ShaderProgram Programs[] = {
},
{
- "simple if/else statement",
+ "simple if/else statement, fragment shader",
NO_VERTEX_SHADER,
"void main() { \n"
" // this should always be false \n"
@@ -983,6 +1008,24 @@ static const ShaderProgram Programs[] = {
},
{
+ "simple if/else statement, vertex shader",
+ "uniform vec4 uniform1; \n"
+ "void main() { \n"
+ " gl_Position = ftransform(); \n"
+ " // this should always be true \n"
+ " if (uniform1.x >= 0.0) { \n"
+ " gl_FrontColor = vec4(0.0, 1.0, 0.0, 0.0); \n"
+ " } else { \n"
+ " gl_FrontColor = vec4(1.0, 0.0, 0.0, 0.0); \n"
+ " } \n"
+ "} \n",
+ NO_FRAGMENT_SHADER,
+ { 0.0, 1.0, 0.0, 0.0 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
"while-loop",
NO_VERTEX_SHADER,
"void main() { \n"
@@ -1029,6 +1072,43 @@ static const ShaderProgram Programs[] = {
},
{
+ "while-loop with continue",
+ NO_VERTEX_SHADER,
+ "void main() { \n"
+ " int i = 0; \n"
+ " float sum = 0.0; \n"
+ " while (i < 20) { \n"
+ " ++i; \n"
+ " if (i > 5) \n"
+ " continue; \n"
+ " sum += 0.1; \n"
+ " } \n"
+ " gl_FragColor = vec4(sum); \n"
+ "} \n",
+ { 0.5, 0.5, 0.5, 0.5 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
+ "for-loop with continue",
+ NO_VERTEX_SHADER,
+ "void main() { \n"
+ " int i; \n"
+ " float sum = 0.0; \n"
+ " for (i = 0; i < 20; ++i) { \n"
+ " if (i > 4) \n"
+ " continue; \n"
+ " sum += 0.1; \n"
+ " } \n"
+ " gl_FragColor = vec4(sum); \n"
+ "} \n",
+ { 0.5, 0.5, 0.5, 0.5 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
"do-loop with break",
NO_VERTEX_SHADER,
"void main() { \n"
@@ -1090,6 +1170,23 @@ static const ShaderProgram Programs[] = {
},
{
+ "discard statement in for loop",
+ NO_VERTEX_SHADER,
+ "void main() { \n"
+ " gl_FragColor = vec4(1.0); \n"
+ " int i; \n"
+ " for (i = 0; i < 1000; i++) { \n"
+ " if (i == 9) { \n"
+ " discard; \n"
+ " } \n"
+ " } \n"
+ "} \n",
+ { 0.0, 0.0, 0.0, 0.0 }, // glClear color
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
"conditional expression",
NO_VERTEX_SHADER,
"void main() { \n"
@@ -1127,7 +1224,23 @@ static const ShaderProgram Programs[] = {
},
{
- "array with constant indexing",
+ "constant array with constant indexing, fragment shader",
+ NO_VERTEX_SHADER,
+ "uniform float uniformArray[4]; \n"
+ "void main() { \n"
+ " gl_FragColor.x = uniformArray[0]; \n"
+ " gl_FragColor.y = uniformArray[1]; \n"
+ " gl_FragColor.z = uniformArray[2]; \n"
+ " gl_FragColor.w = uniformArray[3]; \n"
+ "} \n",
+ { UniformArray[0], UniformArray[1],
+ UniformArray[2], UniformArray[3] },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
+ "temp array with constant indexing, fragment shader",
NO_VERTEX_SHADER,
"void main() { \n"
" float ar[4]; \n"
@@ -1146,7 +1259,45 @@ static const ShaderProgram Programs[] = {
},
{
- "array with variable indexing",
+ "constant array with constant indexing, vertex shader",
+ "uniform float uniformArray[4]; \n"
+ "void main() { \n"
+ " gl_FrontColor.x = uniformArray[0]; \n"
+ " gl_FrontColor.y = uniformArray[1]; \n"
+ " gl_FrontColor.z = uniformArray[2]; \n"
+ " gl_FrontColor.w = uniformArray[3]; \n"
+ " gl_Position = ftransform(); \n"
+ "} \n",
+ NO_FRAGMENT_SHADER,
+ { UniformArray[0], UniformArray[1],
+ UniformArray[2], UniformArray[3] },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
+ "temp array with constant indexing, vertex shader",
+ "void main() { \n"
+ " float ar[4]; \n"
+ " ar[0] = 0.5; \n"
+ " ar[1] = 1.0; \n"
+ " ar[2] = 0.25; \n"
+ " ar[3] = 0.2; \n"
+ " gl_FrontColor.x = ar[0]; \n"
+ " gl_FrontColor.y = ar[1]; \n"
+ " gl_FrontColor.z = ar[2]; \n"
+ " gl_FrontColor.w = ar[3]; \n"
+ " gl_Position = ftransform(); \n"
+ "} \n",
+ NO_FRAGMENT_SHADER,
+ { 0.5, 1.0, 0.25, 0.2 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+#if 0
+ {
+ "temp array with variable indexing, fragment shader",
NO_VERTEX_SHADER,
"uniform vec4 uniform1; \n"
"void main() { \n"
@@ -1164,7 +1315,63 @@ static const ShaderProgram Programs[] = {
},
{
- "array with swizzled variable indexing",
+ "temp array with variable indexing, vertex shader",
+ "uniform vec4 uniform1; \n"
+ "void main() { \n"
+ " float ar[4]; \n"
+ " ar[0] = 0.0; \n"
+ " ar[1] = 0.1; \n"
+ " ar[2] = 0.5; \n"
+ " ar[3] = 0.7; \n"
+ " int indx = int(uniform1.y * 8.0); // should be 2 \n"
+ " gl_FrontColor = vec4(ar[indx]); \n"
+ " gl_Position = ftransform(); \n"
+ "} \n",
+ NO_FRAGMENT_SHADER,
+ { 0.5, 0.5, 0.5, 0.5 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+#endif
+ {
+ "constant array with variable indexing, vertex shader",
+ "uniform float uniformArray[4]; \n"
+ "uniform vec4 uniform1; \n"
+ "void main() { \n"
+ " int indx = int(uniform1.y * 8.0); // should be 2 \n"
+ " gl_FrontColor = vec4(uniformArray[indx]); \n"
+ " gl_Position = ftransform(); \n"
+ "} \n",
+ NO_FRAGMENT_SHADER,
+ { 0.5, 0.5, 0.5, 0.5 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
+ // This one tests that a different array index per vertex
+ // works as expected. The left edge of the polygon should
+ // have a gray value = uniformArray[2] while the right
+ // edge of the polygon should have a gray value =
+ // uniformArray[3].
+ "constant array with variable indexing, vertex shader (2)",
+ "uniform float uniformArray[4]; \n"
+ "void main() { \n"
+ " int indx = int(gl_MultiTexCoord0.x + 2.0); // 2 or 3 \n"
+ " gl_FrontColor = vec4(uniformArray[indx]); \n"
+ " gl_Position = ftransform(); \n"
+ "} \n",
+ NO_FRAGMENT_SHADER,
+ // If we read the center pixel we'd get the average of
+ // the Uniform[2] and Uniform[3] values here. But we read
+ // an off-center pixel so this result was found emperically.
+ { 0.6, 0.6, 0.6, 0.6 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
+ "temp array with swizzled variable indexing",
NO_VERTEX_SHADER,
"uniform vec4 uniform1; \n"
"void main() { \n"
@@ -1993,7 +2200,7 @@ static const ShaderProgram Programs[] = {
},
{
- "function with early return",
+ "function with early return (1)",
NO_VERTEX_SHADER,
"float minimum(in float x, in float y) { \n"
" if (x < y) \n"
@@ -2012,6 +2219,44 @@ static const ShaderProgram Programs[] = {
},
{
+ "function with early return (2)", // reverse case of above
+ NO_VERTEX_SHADER,
+ "float minimum(in float x, in float y) { \n"
+ " if (x < y) \n"
+ " return x; \n"
+ " return y; \n"
+ "} \n"
+ "\n"
+ "void main() { \n"
+ " float a = 0.25; \n"
+ " float z = minimum(a, 0.5); \n"
+ " gl_FragColor = vec4(z); \n"
+ "} \n",
+ { 0.25, 0.25, 0.25, 0.25 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
+ "function with early return (3)",
+ NO_VERTEX_SHADER,
+ "float val = 0.5; \n"
+ "void sub(in float x) { \n"
+ " if (x > 0.0) \n"
+ " return; \n"
+ " val = 1.0; \n"
+ "} \n"
+ "\n"
+ "void main() { \n"
+ " sub(1.0); \n"
+ " gl_FragColor = vec4(val); \n"
+ "} \n",
+ { 0.5, 0.5, 0.5, 0.5 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
"nested function calls (1)",
NO_VERTEX_SHADER,
"float half(const in float x) { \n"
@@ -2464,6 +2709,69 @@ static const ShaderProgram Programs[] = {
FLAG_NONE
},
+ {
+ "Preprocessor test (4)",
+ NO_VERTEX_SHADER,
+ "#if 1 \n"
+ "#define FOO(x) x \n"
+ "#else \n"
+ "#define FOO(x) (0.5 * (x)) \n"
+ "#endif \n"
+ "void main() { \n"
+ " gl_FragColor = vec4(FOO(0.25)); \n"
+ "} \n",
+ { 0.25, 0.25, 0.25, 0.25 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
+ "Preprocessor test (5)",
+ NO_VERTEX_SHADER,
+ "#define BAR(x) x \n"
+ "#if 1 \n"
+ "#define FOO(x) BAR(x) \n"
+ "#else \n"
+ "#define FOO(x) (BAR(x) + BAR(x)) \n"
+ "#endif \n"
+ "void main() { \n"
+ " gl_FragColor = vec4(FOO(0.25)); \n"
+ "} \n",
+ { 0.25, 0.25, 0.25, 0.25 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
+ "Preprocessor test (6)",
+ NO_VERTEX_SHADER,
+ "#define BAR(x) x \n"
+ "#if 0 \n"
+ "#define FOO(x) BAR(x) \n"
+ "#else \n"
+ "#define FOO(x) (BAR(x) + BAR(x)) \n"
+ "#endif \n"
+ "void main() { \n"
+ " gl_FragColor = vec4(FOO(0.25)); \n"
+ "} \n",
+ { 0.5, 0.5, 0.5, 0.5 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
+ {
+ "Preprocessor test (7)",
+ NO_VERTEX_SHADER,
+ "#define FOO(x) \\\n"
+ " ((x) + (x)) \n"
+ "void main() { \n"
+ " gl_FragColor = vec4(FOO(0.25)); \n"
+ "} \n",
+ { 0.5, 0.5, 0.5, 0.5 },
+ DONT_CARE_Z,
+ FLAG_NONE
+ },
+
// Illegal shaders ==================================================
{
"undefined variable",
@@ -2562,6 +2870,17 @@ static const ShaderProgram Programs[] = {
FLAG_ILLEGAL_SHADER
},
+ {
+ "TIntermediate::addUnaryMath",
+ NO_VERTEX_SHADER,
+ "void main() { \n"
+ " -vec4(x ? 1.0 : -1.0); \n"
+ "} \n",
+ { 0.5, 0.5, 0.5, 0.5 },
+ DONT_CARE_Z,
+ FLAG_ILLEGAL_SHADER
+ },
+
// GLSL 1.20 tests ======================================================
{
"mat2x4 construct",
@@ -3032,10 +3351,25 @@ static const ShaderProgram Programs[] = {
-// Get ptrs to 2.0 API functions.
+// Get ptrs to API functions.
bool
GLSLTest::getFunctions(void)
{
+ glTexImage3D_func = (PFNGLTEXIMAGE3DPROC) GLUtils::getProcAddress("glTexImage3D");
+ if (!glTexImage3D_func)
+ return false;
+ glActiveTexture_func = (PFNGLACTIVETEXTUREPROC) GLUtils::getProcAddress("glActiveTexture");
+ if (!glActiveTexture_func)
+ return false;
+ glPointParameterf_func = (PFNGLPOINTPARAMETERFPROC) GLUtils::getProcAddress("glPointParameterf");
+ if (!glPointParameterf_func)
+ return false;
+ glPointParameterfv_func = (PFNGLPOINTPARAMETERFVPROC) GLUtils::getProcAddress("glPointParameterfv");
+ if (!glPointParameterfv_func)
+ return false;
+ glSecondaryColor3fv_func = (PFNGLSECONDARYCOLOR3FVPROC) GLUtils::getProcAddress("glSecondaryColor3fv");
+ if (!glSecondaryColor3fv_func)
+ return false;
glAttachShader_func = (PFNGLATTACHSHADERPROC) GLUtils::getProcAddress("glAttachShader");
if (!glAttachShader_func)
return false;
@@ -3164,7 +3498,7 @@ GLSLTest::setupTextures(void)
glGenTextures(1, &obj3D);
glGenTextures(1, &objZ);
- glActiveTexture(GL_TEXTURE0);
+ glActiveTexture_func(GL_TEXTURE0);
//
// 2D texture, w/ mipmap
@@ -3283,7 +3617,7 @@ GLSLTest::setupTextures(void)
}
}
glBindTexture(GL_TEXTURE_3D, obj3D);
- glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 16, 16, 16, 0,
+ glTexImage3D_func(GL_TEXTURE_3D, 0, GL_RGBA, 16, 16, 16, 0,
GL_RGBA, GL_UNSIGNED_BYTE, teximage3D);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -3300,7 +3634,7 @@ GLSLTest::setupTextures(void)
teximageZ[i][j] = 0.75;
}
}
- glActiveTexture(GL_TEXTURE1); // NOTE: Unit 1
+ glActiveTexture_func(GL_TEXTURE1); // NOTE: Unit 1
glBindTexture(GL_TEXTURE_2D, objZ);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 16, 16, 0,
GL_DEPTH_COMPONENT, GL_FLOAT, teximageZ);
@@ -3309,7 +3643,7 @@ GLSLTest::setupTextures(void)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
GL_COMPARE_R_TO_TEXTURE_ARB);
- glActiveTexture(GL_TEXTURE0);
+ glActiveTexture_func(GL_TEXTURE0);
}
@@ -3324,9 +3658,9 @@ GLSLTest::setupTextureMatrix1(void)
0.1, 0.2, 0.3, 1.0 // col 3
};
glMatrixMode(GL_TEXTURE);
- glActiveTexture(GL_TEXTURE1);
+ glActiveTexture_func(GL_TEXTURE1);
glLoadMatrixf(m);
- glActiveTexture(GL_TEXTURE0);
+ glActiveTexture_func(GL_TEXTURE0);
glMatrixMode(GL_MODELVIEW);
}
@@ -3356,17 +3690,17 @@ GLSLTest::setup(void)
// load program inputs
glColor4fv(PrimaryColor);
- glSecondaryColor3fv(SecondaryColor);
+ glSecondaryColor3fv_func(SecondaryColor);
// other GL state
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MatDiffuse);
glPointSize(PSIZE);
- glPointParameterf(GL_POINT_SIZE_MIN, PSIZE_MIN);
- glPointParameterf(GL_POINT_SIZE_MAX, PSIZE_MAX);
- glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, PSIZE_THRESH);
- glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, PointAtten);
+ glPointParameterf_func(GL_POINT_SIZE_MIN, PSIZE_MIN);
+ glPointParameterf_func(GL_POINT_SIZE_MAX, PSIZE_MAX);
+ glPointParameterf_func(GL_POINT_FADE_THRESHOLD_SIZE, PSIZE_THRESH);
+ glPointParameterfv_func(GL_POINT_DISTANCE_ATTENUATION, PointAtten);
glFogf(GL_FOG_START, FOG_START);
glFogf(GL_FOG_END, FOG_END);
glFogfv(GL_FOG_COLOR, FogColor);
@@ -3542,7 +3876,7 @@ GLSLTest::testProgram(const ShaderProgram &p)
};
const GLfloat r = 0.62; // XXX draw 16x16 pixel quad
GLuint fragShader = 0, vertShader = 0, program = 0;
- GLint u1, utex1d, utex2d, utex3d, utexZ, umat4, umat4t;
+ GLint u1, uArray, utex1d, utex2d, utex3d, utexZ, umat4, umat4t;
GLint umat2x4, umat2x4t, umat4x3, umat4x3t;
bool retVal = false;
@@ -3634,6 +3968,10 @@ GLSLTest::testProgram(const ShaderProgram &p)
if (u1 >= 0)
glUniform4fv_func(u1, 1, Uniform1);
+ uArray = glGetUniformLocation_func(program, "uniformArray");
+ if (uArray >= 0)
+ glUniform1fv_func(uArray, 4, UniformArray);
+
utex1d = glGetUniformLocation_func(program, "tex1d");
if (utex1d >= 0)
glUniform1i_func(utex1d, 0); // bind to tex unit 0
@@ -3759,6 +4097,7 @@ GLSLTest::runOne(MultiTestResult &r, Window &w)
// If you just want to run a single sub-test, assign the name to singleTest.
const char *singleTest = getenv("GLSL_TEST");
if (singleTest) {
+ env->log << "glsl1: Running single test: " << singleTest << "\n";
for (int i = 0; Programs[i].name; i++) {
if (strcmp(Programs[i].name, singleTest) == 0) {
r.numPassed = testProgram(Programs[i]);
diff --git a/tests/glean/tlogicop.cpp b/tests/glean/tlogicop.cpp
index 470654a7a..507a73b14 100644
--- a/tests/glean/tlogicop.cpp
+++ b/tests/glean/tlogicop.cpp
@@ -38,7 +38,7 @@
namespace {
-struct logicopNameMapping {GLenum op; char* name;};
+struct logicopNameMapping {GLenum op; const char* name;};
logicopNameMapping logicopNames[] = {
{GL_CLEAR, "GL_CLEAR"},
{GL_SET, "GL_SET"},
@@ -58,7 +58,7 @@ logicopNameMapping logicopNames[] = {
{GL_OR_INVERTED, "GL_OR_INVERTED"}
};
-char*
+const char*
logicopToName(GLenum op) {
for (unsigned int i = 0;
i < sizeof(logicopNames) / sizeof(logicopNames[0]); ++i) {
diff --git a/tests/glean/tmultitest.cpp b/tests/glean/tmultitest.cpp
index c98d7ec31..a95bd173a 100644
--- a/tests/glean/tmultitest.cpp
+++ b/tests/glean/tmultitest.cpp
@@ -26,6 +26,7 @@
//
// END_COPYRIGHT
+#include <cstring>
#include "tmultitest.h"
namespace GLEAN {
@@ -41,16 +42,28 @@ MultiTestResult::MultiTestResult()
void
MultiTestResult::putresults(ostream &s) const
{
- s << pass;
- s << numPassed;
- s << numFailed;
+ if (pass) {
+ s << "PASS\n";
+ }
+ else {
+ s << "FAIL\n";
+ }
+ s << numPassed << '\n';
+ s << numFailed << '\n';
}
bool
MultiTestResult::getresults(istream &s)
{
- s >> pass;
+ char result[1000];
+ s >> result;
+ if (strcmp(result, "FAIL") == 0) {
+ pass = false;
+ }
+ else {
+ pass = true;
+ }
s >> numPassed;
s >> numFailed;
return s.good();
diff --git a/tests/glean/toccluqry.cpp b/tests/glean/toccluqry.cpp
index a362fc130..4d4904528 100644
--- a/tests/glean/toccluqry.cpp
+++ b/tests/glean/toccluqry.cpp
@@ -38,19 +38,36 @@
#include <cstring>
#include <stdio.h>
#include <cmath>
+#include "rand.h"
#include "toccluqry.h"
#define START_QUERY(id)\
- glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id);
+ glBeginQueryARB_func(GL_SAMPLES_PASSED_ARB, id);
#define TERM_QUERY()\
- glEndQueryARB(GL_SAMPLES_PASSED_ARB);\
+ glEndQueryARB_func(GL_SAMPLES_PASSED_ARB);\
namespace GLEAN {
+
+// GL_VERSION_1_5
+static PFNGLBEGINQUERYPROC glBeginQuery_func = NULL;
+static PFNGLENDQUERYPROC glEndQuery_func = NULL;
+
+// GL_ARB_occlusion_query
+static PFNGLGENQUERIESARBPROC glGenQueriesARB_func = NULL;
+static PFNGLDELETEQUERIESARBPROC glDeleteQueriesARB_func = NULL;
+static PFNGLISQUERYARBPROC glIsQueryARB_func = NULL;
+static PFNGLBEGINQUERYARBPROC glBeginQueryARB_func = NULL;
+static PFNGLENDQUERYARBPROC glEndQueryARB_func = NULL;
+static PFNGLGETQUERYIVARBPROC glGetQueryivARB_func = NULL;
+static PFNGLGETQUERYOBJECTIVARBPROC glGetQueryObjectivARB_func = NULL;
+static PFNGLGETQUERYOBJECTUIVARBPROC glGetQueryObjectuivARB_func = NULL;
+
+
/* Generate a box which will be occluded by the occluder */
void OccluQryTest::gen_box(GLfloat left, GLfloat right,
GLfloat top, GLfloat btm)
@@ -77,8 +94,34 @@ bool OccluQryTest::chk_ext()
}
+void OccluQryTest::setup()
+{
+ glBeginQuery_func = (PFNGLBEGINQUERYPROC) GLUtils::getProcAddress("glBeginQuery");
+ assert(glBeginQuery_func);
+ glEndQuery_func = (PFNGLENDQUERYPROC) GLUtils::getProcAddress("glEndQuery");
+ assert(glEndQuery_func);
+
+ glGenQueriesARB_func = (PFNGLGENQUERIESARBPROC) GLUtils::getProcAddress("glGenQueriesARB");
+ assert(glGenQueriesARB_func);
+ glDeleteQueriesARB_func = (PFNGLDELETEQUERIESARBPROC) GLUtils::getProcAddress("glDeleteQueriesARB");
+ assert(glDeleteQueriesARB_func);
+ glIsQueryARB_func = (PFNGLISQUERYARBPROC) GLUtils::getProcAddress("glIsQueryARB");
+ assert(glIsQueryARB_func);
+ glBeginQueryARB_func = (PFNGLBEGINQUERYARBPROC) GLUtils::getProcAddress("glBeginQueryARB");
+ assert(glBeginQueryARB_func);
+ glEndQueryARB_func = (PFNGLENDQUERYARBPROC) GLUtils::getProcAddress("glEndQueryARB");
+ assert(glEndQueryARB_func);
+ glGetQueryivARB_func = (PFNGLGETQUERYIVARBPROC) GLUtils::getProcAddress("glGetQueryivARB");
+ assert(glGetQueryivARB_func);
+ glGetQueryObjectivARB_func = (PFNGLGETQUERYOBJECTIVARBPROC) GLUtils::getProcAddress("glGetQueryObjectivARB");
+ assert(glGetQueryObjectivARB_func);
+ glGetQueryObjectuivARB_func = (PFNGLGETQUERYOBJECTUIVARBPROC) GLUtils::getProcAddress("glGetQueryObjectuivARB");
+ assert(glGetQueryObjectuivARB_func);
+}
+
GLuint OccluQryTest::find_unused_id()
{
+ RandomBits idRand(32, 183485);
unsigned int id;
int counter = 0;
@@ -86,8 +129,8 @@ GLuint OccluQryTest::find_unused_id()
while (1) {
/* assuming that at least 2^32-1 <id> can be generated */
- id = random() % (((unsigned long) 1 << 32) - 1);
- if (id != 0 && glIsQueryARB(id) == GL_FALSE)
+ id = idRand.next();
+ if (id != 0 && glIsQueryARB_func(id) == GL_FALSE)
return id;
if (++ counter >= MAX_FIND_ID_ROUND) {
fprintf(stderr,
@@ -152,9 +195,9 @@ bool OccluQryTest::conformOQ_GetObjivAval_multi1(GLuint id)
glPopMatrix();
do {
- glGetQueryObjectivARB(id, GL_QUERY_RESULT_AVAILABLE_ARB, &ready);
+ glGetQueryObjectivARB_func(id, GL_QUERY_RESULT_AVAILABLE_ARB, &ready);
} while (!ready);
- glGetQueryObjectuivARB(id, GL_QUERY_RESULT_ARB, &passed);
+ glGetQueryObjectuivARB_func(id, GL_QUERY_RESULT_ARB, &passed);
// 'passed' should be zero
return passed > 0 ? false : true;
@@ -217,16 +260,16 @@ bool OccluQryTest::conformOQ_GetObjivAval_multi2()
glPopMatrix();
- glGetQueryObjectuivARB(id1, GL_QUERY_RESULT_ARB, &passed1);
- glGetQueryObjectuivARB(id2, GL_QUERY_RESULT_ARB, &passed2);
- glGetQueryObjectuivARB(id3, GL_QUERY_RESULT_ARB, &passed3);
+ glGetQueryObjectuivARB_func(id1, GL_QUERY_RESULT_ARB, &passed1);
+ glGetQueryObjectuivARB_func(id2, GL_QUERY_RESULT_ARB, &passed2);
+ glGetQueryObjectuivARB_func(id3, GL_QUERY_RESULT_ARB, &passed3);
glDepthMask(GL_TRUE);
- glDeleteQueriesARB(1, &id1);
- glDeleteQueriesARB(1, &id2);
- glDeleteQueriesARB(1, &id3);
+ glDeleteQueriesARB_func(1, &id1);
+ glDeleteQueriesARB_func(1, &id2);
+ glDeleteQueriesARB_func(1, &id3);
glPopMatrix();
glMatrixMode( GL_PROJECTION );
@@ -260,7 +303,7 @@ bool OccluQryTest::conformOQ_GetQry_CnterBit()
/* get the minimum bit number supported by the implementation,
* and check the legality of result of GL_QUERY_COUNTER_BITS_ARB */
- glGetQueryivARB(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &bit_num);
+ glGetQueryivARB_func(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &bit_num);
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims);
err = glGetError();
if (err == GL_INVALID_OPERATION || err == GL_INVALID_ENUM)
@@ -288,14 +331,14 @@ bool OccluQryTest::conformOQ_Begin_unused_id()
if (id == 0)
return false;
- glBeginQuery(GL_SAMPLES_PASSED_ARB, id);
+ glBeginQuery_func(GL_SAMPLES_PASSED_ARB, id);
- if (glIsQueryARB(id) == GL_FALSE) {
+ if (glIsQueryARB_func(id) == GL_FALSE) {
fprintf(stderr, "F: Begin with a unused id failed.\n");
pass = false;
}
- glEndQuery(GL_SAMPLES_PASSED_ARB);
+ glEndQuery_func(GL_SAMPLES_PASSED_ARB);
return pass;
}
@@ -307,7 +350,7 @@ bool OccluQryTest::conformOQ_EndAfter(GLuint id)
START_QUERY(id);
TERM_QUERY();
- glEndQueryARB(GL_SAMPLES_PASSED_ARB);
+ glEndQueryARB_func(GL_SAMPLES_PASSED_ARB);
if (glGetError() != GL_INVALID_OPERATION) {
fprintf(stderr, "F: No GL_INVALID_OPERATION generated if "
@@ -327,7 +370,7 @@ bool OccluQryTest::conformOQ_GenIn(GLuint id)
START_QUERY(id);
- glGenQueriesARB(1, &id);
+ glGenQueriesARB_func(1, &id);
if (glGetError() != GL_INVALID_OPERATION) {
fprintf(stderr, "F: No GL_INVALID_OPERATION generated if "
"GenQueries in the progress of another.\n");
@@ -349,7 +392,7 @@ bool OccluQryTest::conformOQ_DeleteIn(GLuint id)
START_QUERY(id);
if (id > 0) {
- glDeleteQueriesARB(1, &id);
+ glDeleteQueriesARB_func(1, &id);
if (glGetError() != GL_INVALID_OPERATION) {
fprintf(stderr, "F: No GL_INVALID_OPERATION generated if "
@@ -374,7 +417,7 @@ bool OccluQryTest::conformOQ_BeginIn(GLuint id)
/* Issue another BeginQueryARB while another query is already in
progress */
- glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id);
+ glBeginQueryARB_func(GL_SAMPLES_PASSED_ARB, id);
if (glGetError() != GL_INVALID_OPERATION) {
fprintf(stderr, "F: No GL_INVALID_OPERATION generated if "
@@ -396,11 +439,11 @@ bool OccluQryTest::conformOQ_GetObjAvalIn(GLuint id)
START_QUERY(id);
- glGetQueryObjectivARB(id, GL_QUERY_RESULT_AVAILABLE_ARB, &param);
+ glGetQueryObjectivARB_func(id, GL_QUERY_RESULT_AVAILABLE_ARB, &param);
if (glGetError() != GL_INVALID_OPERATION)
pass = false;
- glGetQueryObjectuivARB(id, GL_QUERY_RESULT_AVAILABLE_ARB, (GLuint *)&param);
+ glGetQueryObjectuivARB_func(id, GL_QUERY_RESULT_AVAILABLE_ARB, (GLuint *)&param);
if (glGetError() != GL_INVALID_OPERATION)
pass = false;
@@ -424,11 +467,11 @@ bool OccluQryTest::conformOQ_GetObjResultIn(GLuint id)
START_QUERY(id);
- glGetQueryObjectivARB(id, GL_QUERY_RESULT_ARB, &param);
+ glGetQueryObjectivARB_func(id, GL_QUERY_RESULT_ARB, &param);
if (glGetError() != GL_INVALID_OPERATION)
pass = false;
- glGetQueryObjectuivARB(id, GL_QUERY_RESULT_ARB, (GLuint *)&param);
+ glGetQueryObjectuivARB_func(id, GL_QUERY_RESULT_ARB, (GLuint *)&param);
if (glGetError() != GL_INVALID_OPERATION)
pass = false;
@@ -458,7 +501,7 @@ bool OccluQryTest::conformOQ_GetObjivAval(GLuint id)
if (id_tmp == 0)
return false;
- glGetQueryObjectivARB(id_tmp, GL_QUERY_RESULT_AVAILABLE_ARB, &param);
+ glGetQueryObjectivARB_func(id_tmp, GL_QUERY_RESULT_AVAILABLE_ARB, &param);
if (glGetError() != GL_INVALID_OPERATION) {
fprintf(stderr, "F: No GL_INVALID_OPERATION generated if "
@@ -486,8 +529,8 @@ bool OccluQryTest::conformOQ_Gen_Delete(unsigned int id_n)
return false;
}
- glGenQueriesARB(id_n, ids1);
- glGenQueriesARB(id_n, ids2);
+ glGenQueriesARB_func(id_n, ids1);
+ glGenQueriesARB_func(id_n, ids2);
/* compare whether <id> generated during the previous 2 rounds are
* duplicated */
@@ -509,7 +552,7 @@ bool OccluQryTest::conformOQ_Gen_Delete(unsigned int id_n)
#if 0
/* Checkout whether the Query ID just generated is valid */
for (i = 0; i < id_n; i ++) {
- if (glIsQueryARB(ids1[i]) == GL_FALSE) {
+ if (glIsQueryARB_func(ids1[i]) == GL_FALSE) {
fprintf(stderr, "F: id [%d] just generated is not valid.\n",
ids1[i]);
pass = false;
@@ -519,9 +562,9 @@ bool OccluQryTest::conformOQ_Gen_Delete(unsigned int id_n)
/* if <id> is a non-zero value that is not the name of a query object,
* IsQueryARB returns FALSE. */
- glDeleteQueriesARB(id_n, ids1);
+ glDeleteQueriesARB_func(id_n, ids1);
for (i = 0; i < id_n; i ++) {
- if (glIsQueryARB(ids1[i]) == GL_TRUE) {
+ if (glIsQueryARB_func(ids1[i]) == GL_TRUE) {
fprintf(stderr, "F: id [%d] just deleted is still valid.\n",
ids1[i]);
pass = false;
@@ -529,7 +572,7 @@ bool OccluQryTest::conformOQ_Gen_Delete(unsigned int id_n)
}
/* Delete only for sanity purpose */
- glDeleteQueriesARB(id_n, ids2);
+ glDeleteQueriesARB_func(id_n, ids2);
if (ids1)
free(ids1);
@@ -542,7 +585,7 @@ bool OccluQryTest::conformOQ_Gen_Delete(unsigned int id_n)
return false;
for (i = 0; i < id_n; i ++) {
- glGenQueriesARB(1, ids1 + i);
+ glGenQueriesARB_func(1, ids1 + i);
for (j = 0; j < i; j ++) {
if (ids1[i] == ids1[j]) {
fprintf(stderr, "E: duplicated id generated [ %u ]",
@@ -552,7 +595,7 @@ bool OccluQryTest::conformOQ_Gen_Delete(unsigned int id_n)
}
}
- glDeleteQueriesARB(id_n, ids1);
+ glDeleteQueriesARB_func(id_n, ids1);
if (ids1)
free(ids1);
@@ -563,7 +606,7 @@ bool OccluQryTest::conformOQ_Gen_Delete(unsigned int id_n)
/* If <id> is zero, IsQueryARB should return FALSE.*/
bool OccluQryTest::conformOQ_IsIdZero(void)
{
- if (glIsQueryARB(0) == GL_TRUE) {
+ if (glIsQueryARB_func(0) == GL_TRUE) {
fprintf(stderr, "F: zero is treated as a valid id by"
"IsQueryARB().\n");
return false;
@@ -577,7 +620,7 @@ bool OccluQryTest::conformOQ_IsIdZero(void)
* should be generated. */
bool OccluQryTest::conformOQ_BeginIdZero(void)
{
- glBeginQueryARB(GL_SAMPLES_PASSED_ARB, 0);
+ glBeginQueryARB_func(GL_SAMPLES_PASSED_ARB, 0);
if (glGetError() != GL_INVALID_OPERATION) {
fprintf(stderr, "F: No GL_INVALID_OPERATION generated if "
"BeginQuery with zero ID.\n");
@@ -596,8 +639,9 @@ void OccluQryTest::runOne(MultiTestResult &r, Window &w)
if (!chk_ext())
return;
+ setup();
glEnable(GL_DEPTH_TEST);
- glGenQueriesARB(1, &queryId);
+ glGenQueriesARB_func(1, &queryId);
if (queryId == 0)
return;
@@ -645,7 +689,7 @@ void OccluQryTest::runOne(MultiTestResult &r, Window &w)
result = conformOQ_BeginIdZero();
reportPassFail(r, result, "conformOQ_BeginIdZero");
- glDeleteQueriesARB(1, &queryId);
+ glDeleteQueriesARB_func(1, &queryId);
r.pass = (r.numFailed == 0);
#endif
diff --git a/tests/glean/toccluqry.h b/tests/glean/toccluqry.h
index c4f74e3f4..2dc382d70 100644
--- a/tests/glean/toccluqry.h
+++ b/tests/glean/toccluqry.h
@@ -64,6 +64,7 @@ class OccluQryTest: public MultiTest {
void gen_box(GLfloat left, GLfloat right, GLfloat top, GLfloat btm);
GLuint find_unused_id();
bool chk_ext();
+ void setup();
void reportPassFail(MultiTestResult &r, bool pass, const char *msg) const;
};
diff --git a/tests/glean/tpbo.cpp b/tests/glean/tpbo.cpp
index 5ae7a5745..f2ac7a8ba 100644
--- a/tests/glean/tpbo.cpp
+++ b/tests/glean/tpbo.cpp
@@ -1,1248 +1,1283 @@
-// BEGIN_COPYRIGHT -*- glean -*-
-//
-// Copyrigth (C) 2007 Intel Corporation
-// Copyright (C) 1999 Allen Akin All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or
-// sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the
-// Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
-// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
-// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
-// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-// DEALINGS IN THE SOFTWARE.
-//
-// END_COPYRIGHT
-//
-// Authors:
-// Shuang He <shuang.he@intel.com>
-//
-// tpbo.cpp: Test OpenGL Extension GL_ARB_pixel_buffer_object
-
-
-#define GL_GLEXT_PROTOTYPES
-
-#include <stdlib.h>
-#include <cstring>
-#include <cassert>
-#include <math.h>
-#include "tpbo.h"
-#include "timer.h"
-
-
-namespace GLEAN
-{
-
-static int usePBO;
-#define BUFFER_OFFSET(i) ((char *)NULL + (i))
-
-bool PBOTest::setup(void)
-{
- glMatrixMode(GL_PROJECTION);
-
- glLoadIdentity();
- gluOrtho2D(0, 100, 0, 100);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glDrawBuffer(GL_FRONT);
- glReadBuffer(GL_FRONT);
-
- // compute error tolerances (may need fine-tuning)
- int
- bufferBits[5];
-
- glGetIntegerv(GL_RED_BITS, &bufferBits[0]);
- glGetIntegerv(GL_GREEN_BITS, &bufferBits[1]);
- glGetIntegerv(GL_BLUE_BITS, &bufferBits[2]);
- glGetIntegerv(GL_ALPHA_BITS, &bufferBits[3]);
- glGetIntegerv(GL_DEPTH_BITS, &bufferBits[4]);
-
- tolerance[0] = 2.0 / (1 << bufferBits[0]);
- tolerance[1] = 2.0 / (1 << bufferBits[1]);
- tolerance[2] = 2.0 / (1 << bufferBits[2]);
- if (bufferBits[3])
- tolerance[3] = 2.0 / (1 << bufferBits[3]);
- else
- tolerance[3] = 1.0;
- if (bufferBits[4])
- tolerance[4] = 16.0 / (1 << bufferBits[4]);
- else
- tolerance[4] = 1.0;
-
- // Check if GL_ARB_pixel_buffer_object is supported
- if (!strstr((char *) glGetString(GL_EXTENSIONS), "GL_ARB_pixel_buffer_object")) {
- //printf("GL_ARB_pixel_buffer_object is not supported\n");
- usePBO = 0;
- return false;
- }
- else {
- //printf("GL_ARB_pixel_buffer_object is supported\n");
- usePBO = 1;
- }
-
- return true;
-}
-
-
-void
-PBOTest::reportFailure(const char *msg, const int line) const
-{
- env->log << "FAILURE: " << msg << " (at tpbo.cpp:" << line << ")\n";
-}
-
-void
-PBOTest::reportFailure(const char *msg, const GLenum target, const int line) const
-{
- env->log << "FAILURE: " << msg;
- if (target == GL_FRAGMENT_SHADER)
- env->log << " (fragment)";
- else
- env->log << " (vertex)";
- env->log << " (at tpbo.cpp:" << line << ")\n";
-}
-
-#define REPORT_FAILURE(MSG) reportFailure(MSG, __LINE__)
-#define REPORT_FAILURE_T(MSG, TARGET) reportFailure(MSG, TARGET, __LINE__)
-// Compare actual and expected colors
-bool PBOTest::equalColors(const GLfloat act[3], const GLfloat exp[3]) const
-{
- if ((fabsf(act[0] - exp[0]) > tolerance[0])
- || (fabsf(act[1] - exp[1]) > tolerance[1])
- || (fabsf(act[2] - exp[2]) > tolerance[2])) {
- return false;
- }
- else
- return true;
-}
-
-bool PBOTest::equalColors1(const GLubyte act[3], const GLubyte exp[3]) const
-{
- if ((act[0] != exp[0])
- || (act[1] != exp[1])
- || (act[2] != exp[2])) {
- return false;
- }
- else
- return true;
-}
-
-
-
-#define TEXSIZE 64
-
-bool PBOTest::testSanity(void)
-{
- GLuint pbs[1];
- GLuint pb_binding;
-
- if (!usePBO)
- return true;
-
- // Check default binding
- glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, (GLint *) & pb_binding);
- if (pb_binding != 0) {
- REPORT_FAILURE("Failed to bind unpack pixel buffer object");
- return false;
- }
-
- glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING_ARB, (GLint *) & pb_binding);
- if (pb_binding != 0) {
- REPORT_FAILURE("Failed to bind pack pixel buffer object");
- return false;
- }
-
- glGenBuffersARB(1, pbs);
-
- if (glIsBufferARB(pbs[0]) != GL_TRUE) {
- REPORT_FAILURE("Failed to call glIsBuffersARB");
- return false;
- }
-
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbs[0]);
- glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, (GLint *) & pb_binding);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
- if (pb_binding != pbs[0]) {
- REPORT_FAILURE("Failed to bind unpack pixel buffer object");
- return false;
- }
-
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbs[0]);
- glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING_ARB, (GLint *) & pb_binding);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
- if (pb_binding != pbs[0]) {
- REPORT_FAILURE("Failed to bind unpack pixel buffer object");
- return false;
- }
-
- glDeleteBuffersARB(1, pbs);
-
- if (glIsBufferARB(pbs[0]) == GL_TRUE) {
- REPORT_FAILURE("Failed to call glIsBuffersARB");
- return false;
- }
-
- return true;
-}
-
-
-bool PBOTest::testDrawPixels(void)
-{
- int useUnpackBuffer;
- int usePackBuffer;
- GLuint pb_pack[1];
- GLuint pb_unpack[1];
- GLubyte buf[windowSize * windowSize * 4];
- GLubyte t[TEXSIZE * TEXSIZE * 4];
- int i, j;
- GLubyte * pboPackMem = NULL;
- GLubyte black[3] = { 0, 0, 0 };
-
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
- for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1; useUnpackBuffer++) {
- for (usePackBuffer = 0; usePackBuffer < usePBO + 1; usePackBuffer++) {
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- if (useUnpackBuffer) {
- glGenBuffersARB(1, pb_unpack);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb_unpack[0]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- TEXSIZE * TEXSIZE * 4 * sizeof(GLubyte), NULL,
- GL_STREAM_DRAW);
- }
- GLubyte *pboMem = NULL;
- if (useUnpackBuffer) {
- pboMem = (GLubyte *) glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_WRITE_ONLY);
- }
- else {
- pboMem = t;
- }
-
- for (i = 0; i < TEXSIZE; i++)
- for (j = 0; j < TEXSIZE; j++) {
- pboMem[4 * (i * TEXSIZE + j)] = i % 256;
- pboMem[4 * (i * TEXSIZE + j) + 1] = i % 256;
- pboMem[4 * (i * TEXSIZE + j) + 2] = i % 256;
- pboMem[4 * (i * TEXSIZE + j) + 3] = 0;
- }
-
- if (useUnpackBuffer) {
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- }
-
- if (useUnpackBuffer) {
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb_unpack[0]);
- glDrawPixels(TEXSIZE, TEXSIZE, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- }
- else
- glDrawPixels(TEXSIZE, TEXSIZE, GL_BGRA, GL_UNSIGNED_BYTE, pboMem);
-
- // Check the result
- if (usePackBuffer) {
- glGenBuffersARB(1, pb_pack);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, pb_pack[0]);
- glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT,
- windowSize * windowSize * 4 *
- sizeof(GL_UNSIGNED_BYTE), NULL, GL_STREAM_DRAW);
- glReadPixels(0, 0, windowSize, windowSize, GL_BGRA,
- GL_UNSIGNED_BYTE, NULL);
- pboPackMem = (GLubyte *) glMapBufferARB(GL_PIXEL_PACK_BUFFER_EXT,
- GL_READ_ONLY);
- }
- else {
- pboPackMem = buf;
- glReadPixels(0, 0, windowSize, windowSize, GL_BGRA,
- GL_UNSIGNED_BYTE, pboPackMem);
- }
-
- for (j = 0; j < windowSize; j++) {
- for (i = 0; i < windowSize; i++) {
- GLubyte exp[3];
- exp[0] = j % 256;
- exp[1] = j % 256;
- exp[2] = j % 256;
-
- if (i < TEXSIZE && j < TEXSIZE) {
- if (equalColors1(&pboPackMem[(j * windowSize + i) * 4], exp)
- != true) {
- REPORT_FAILURE("glDrawPixels failed");
- printf(" got (%d, %d) = [%d, %d, %d], ", i, j,
- pboPackMem[(j * windowSize + i) * 4],
- pboPackMem[(j * windowSize + i) * 4 + 1],
- pboPackMem[(j * windowSize + i) * 4 + 2]);
- printf("should be [%d, %d, %d]\n",
- exp[0], exp[1], exp[2]);
-
- return false;
- }
- }
- else {
- if (equalColors1(&pboPackMem[(j * windowSize + i) * 4],
- black) != true) {
- REPORT_FAILURE("glDrawPixels failed");
- printf("(%d, %d) = [%d, %d, %d], ", i, j,
- pboPackMem[(j * windowSize + i) * 4],
- pboPackMem[(j * windowSize + i) * 4 + 1],
- pboPackMem[(j * windowSize + i) * 4 + 2]);
- printf("should be [0.0, 0.0, 0.0]\n");
- return false;
- }
-
- }
- }
- }
-
-
- if (usePackBuffer) {
- glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, 0);
- glDeleteBuffersARB(1, pb_pack);
- }
-
- if (useUnpackBuffer) {
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glDeleteBuffersARB(1, pb_unpack);
- }
-
- }
- }
-
- return true;
-}
-
-
-bool PBOTest::testPixelMap(void)
-{
- int useUnpackBuffer;
- int usePackBuffer;
- GLuint pb_pack[1];
- GLuint pb_unpack[1];
- int i;
- int size;
- int max;
-
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
- glGetIntegerv(GL_MAX_PIXEL_MAP_TABLE, &max);
-
- for (usePackBuffer = 0; usePackBuffer < usePBO + 1; usePackBuffer++) {
- for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1;
- useUnpackBuffer++) {
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- if (useUnpackBuffer) {
- glGenBuffersARB(1, pb_unpack);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb_unpack[0]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, max * sizeof(GLushort),
- NULL, GL_STREAM_DRAW);
- }
- GLushort *pboMem = NULL;
- if (useUnpackBuffer) {
- pboMem = (GLushort *) glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_WRITE_ONLY);
- }
- else {
- pboMem = (GLushort *) malloc(sizeof(GLushort) * max);
- }
- for (i = 0; i < max; i++)
- pboMem[i] = max - i - 1;
-
- if (useUnpackBuffer) {
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
- glPixelMapusv(GL_PIXEL_MAP_R_TO_R, max, NULL);
- glPixelMapusv(GL_PIXEL_MAP_G_TO_G, max, NULL);
- glPixelMapusv(GL_PIXEL_MAP_B_TO_B, max, NULL);
- glPixelMapusv(GL_PIXEL_MAP_A_TO_A, max, NULL);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- }
- else {
- glPixelMapusv(GL_PIXEL_MAP_R_TO_R, max, pboMem);
- glPixelMapusv(GL_PIXEL_MAP_G_TO_G, max, pboMem);
- glPixelMapusv(GL_PIXEL_MAP_B_TO_B, max, pboMem);
- glPixelMapusv(GL_PIXEL_MAP_A_TO_A, max, pboMem);
- free(pboMem);
- }
-
-
- glGetIntegerv(GL_PIXEL_MAP_R_TO_R_SIZE, &size);
- if (size != max) {
- REPORT_FAILURE("glPixelMap failed");
- return false;
- }
- glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
-
- // Read back pixel map
- if (usePackBuffer) {
- glGenBuffersARB(1, pb_pack);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, pb_pack[0]);
- glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT, max * sizeof(GLushort),
- NULL, GL_STREAM_DRAW);
- glGetPixelMapusv(GL_PIXEL_MAP_R_TO_R, NULL);
- pboMem = (GLushort *) glMapBufferARB(GL_PIXEL_PACK_BUFFER_EXT,
- GL_READ_ONLY);
- }
- else {
- pboMem = (GLushort *) malloc(sizeof(GLushort) * max);
- glGetPixelMapusv(GL_PIXEL_MAP_R_TO_R, pboMem);
- }
-
- for (i = 0; i < max; i++) {
- if (pboMem[i] != (255 - i)) {
- REPORT_FAILURE("get PixelMap failed");
- return false;
- }
- }
-
-
- if (usePackBuffer) {
- glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_EXT);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
- glDeleteBuffersARB(1, pb_pack);
- }
- else {
- free(pboMem);
- }
-
- if (useUnpackBuffer) {
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glDeleteBuffersARB(1, pb_unpack);
- }
-
- }
- }
-
- return true;
-}
-
-bool PBOTest::testBitmap(void)
-{
- GLuint pb_unpack[1];
- GLuint pb_pack[1];
- int useUnpackBuffer = usePBO;
- int usePackBuffer = 0;
- GLubyte bitmap[TEXSIZE * TEXSIZE / 8];
- GLfloat buf[windowSize * windowSize * 3];
- GLfloat white[3] = { 1.0, 1.0, 1.0 };
- GLfloat black[3] = { 0.0, 0.0, 0.0 };
- int i, j;
- GLubyte *pboUnpackMem = NULL;
- GLfloat *pboPackMem = NULL;
-
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
- for (usePackBuffer = 0; usePackBuffer < usePBO + 1; usePackBuffer++) {
- for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1;
- useUnpackBuffer++) {
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
-
- if (useUnpackBuffer) {
- glGenBuffersARB(1, pb_unpack);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, pb_unpack[0]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, TEXSIZE * TEXSIZE, NULL,
- GL_STREAM_DRAW);
- pboUnpackMem = (GLubyte *) glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_WRITE_ONLY);
- }
- else {
- pboUnpackMem = bitmap;
- }
-
- for (i = 0; i < TEXSIZE * TEXSIZE / 8; i++) {
- pboUnpackMem[i] = 0xAA;
- }
-
-
- glColor4f(1.0, 1.0, 1.0, 0.0);
- glRasterPos2f(0.0, 0.0);
- if (useUnpackBuffer) {
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
- glBitmap(TEXSIZE, TEXSIZE, 0, 0, 0, 0, NULL);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- }
- else
- glBitmap(TEXSIZE, TEXSIZE, 0, 0, 0, 0, pboUnpackMem);
-
- // Check the result
- if (usePackBuffer) {
- glGenBuffersARB(1, pb_pack);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, pb_pack[0]);
- glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT,
- windowSize * windowSize * 4 * sizeof(GLfloat),
- NULL,
- GL_STREAM_DRAW);
- glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT,
- NULL);
- pboPackMem =
- (GLfloat *) glMapBufferARB(GL_PIXEL_PACK_BUFFER_EXT,
- GL_READ_ONLY);
- }
- else {
- pboPackMem = buf;
- glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT,
- pboPackMem);
- }
-
- for (j = 0; j < windowSize; j++) {
- for (i = 0; i < windowSize; i++) {
- const GLfloat *exp;
- if ((i & 1))
- exp = black;
- else
- exp = white;
- if (i < TEXSIZE && j < TEXSIZE) {
- if (equalColors(&pboPackMem[(j * windowSize + i) * 3], exp)
- != true) {
- REPORT_FAILURE("glBitmap failed");
- printf(" got (%d, %d) = [%f, %f, %f], ", i, j,
- pboPackMem[(j * windowSize + i) * 3],
- pboPackMem[(j * windowSize + i) * 3 + 1],
- pboPackMem[(j * windowSize + i) * 3 + 2]);
- printf("should be [%f, %f, %f]\n",
- exp[0], exp[1], exp[2]);
-
- return false;
- }
- }
- else {
- if (equalColors
- (&pboPackMem[(j * windowSize + i) * 3],
- black) != true) {
- REPORT_FAILURE("glBitmap failed");
- printf("(%d, %d) = [%f, %f, %f], ", i, j,
- pboPackMem[(j * windowSize + i) * 3],
- pboPackMem[(j * windowSize + i) * 3 + 1],
- pboPackMem[(j * windowSize + i) * 3 + 2]);
- printf("should be [0.0, 0.0, 0.0]\n");
- return false;
- }
-
- }
- }
- }
- if (usePackBuffer) {
- glUnmapBuffer(GL_PIXEL_PACK_BUFFER_EXT);
- glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, 0);
- glDeleteBuffersARB(1, pb_pack);
- }
-
- if (useUnpackBuffer) {
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glDeleteBuffersARB(1, pb_unpack);
- }
- }
- }
- return true;
-}
-
-
-bool PBOTest::testTexImage(void)
-{
- int breakCOWPBO, breakCOWTexture;
- int useTexUnpackBuffer, useTexPackBuffer;
- GLuint unpack_pb[1];
- GLuint pack_pb[1];
- GLfloat t1[TEXSIZE * TEXSIZE * 3];
- GLfloat t2[TEXSIZE * TEXSIZE * 3];
- GLfloat *pboMem = NULL;
- int i, j;
- GLfloat green[3] = { 1.0, 1.0, 0.0 };
- GLfloat black[3] = { 0.0, 0.0, 0.0 };
- GLfloat buf[windowSize * windowSize * 3];
-
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
-
- for (useTexPackBuffer = 0; useTexPackBuffer < usePBO + 1;
- useTexPackBuffer++) {
- for (useTexUnpackBuffer = 0; useTexUnpackBuffer < usePBO + 1;
- useTexUnpackBuffer++) {
- for (breakCOWPBO = 0; breakCOWPBO < useTexUnpackBuffer + 1;
- breakCOWPBO++) {
- for (breakCOWTexture = 0;
- breakCOWTexture < useTexUnpackBuffer + 1;
- breakCOWTexture++) {
- if (useTexUnpackBuffer) {
- glGenBuffersARB(1, unpack_pb);
- if (glIsBufferARB(unpack_pb[0]) == false)
- return false;
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, unpack_pb[0]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- TEXSIZE * TEXSIZE * 3 * sizeof(GLfloat), NULL,
- GL_STREAM_DRAW);
- }
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- GL_NEAREST);
-
- if (useTexUnpackBuffer) {
- pboMem =
- (GLfloat *) glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_WRITE_ONLY);
- }
- else {
- pboMem = t1;
- }
-
- for (i = 0; i < TEXSIZE * TEXSIZE; i++) {
- pboMem[3 * i] = 1.0;
- pboMem[3 * i + 1] = 1.0;
- pboMem[3 * i + 2] = 0.0;
- }
-
- if (useTexUnpackBuffer) {
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE, TEXSIZE, 0,
- GL_RGB, GL_FLOAT, NULL);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- }
- else
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE, TEXSIZE, 0,
- GL_RGB, GL_FLOAT, pboMem);
-
- if (useTexUnpackBuffer) {
- if (breakCOWPBO) {
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, unpack_pb[0]);
- pboMem =
- (GLfloat *) glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_WRITE_ONLY);
- for (i = 0; i < TEXSIZE * TEXSIZE * 3; i++)
- pboMem[i] = 0.2;
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- }
- }
-
- if (useTexUnpackBuffer) {
- if (breakCOWTexture) {
- GLfloat temp[1 * 1 * 3];
- for (i = 0; i < 1 * 1 * 3; i++)
- temp[i] = 0.8;
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGB,
- GL_FLOAT, temp);
- }
- }
-
- // Check PBO's content
- if (useTexUnpackBuffer) {
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, unpack_pb[0]);
- pboMem = (GLfloat *) glMapBuffer(GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_READ_ONLY);
- if (breakCOWPBO) {
- for (i = 0; i < TEXSIZE * TEXSIZE * 3; i++)
- if (fabsf(pboMem[i] - 0.2) > tolerance[0]) {
- REPORT_FAILURE
- ("PBO modified by someone else, there must be something wrong");
- return false;
- }
- }
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- }
-
-
- // Read texture back
- if (useTexPackBuffer) {
- glGenBuffersARB(1, pack_pb);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, pack_pb[0]);
- glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT,
- TEXSIZE * TEXSIZE * 3 * sizeof(GLfloat), NULL,
- GL_STREAM_DRAW);
- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, NULL);
- pboMem = (GLfloat *) glMapBufferARB(GL_PIXEL_PACK_BUFFER_EXT,
- GL_READ_ONLY);
- }
- else {
- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, t2);
- pboMem = t2;
- }
-
- // Check texture image
- for (i = 0; i < TEXSIZE * TEXSIZE; i++) {
- if (i == 0 && breakCOWTexture && useTexUnpackBuffer) {
- GLfloat exp[3] = { 0.8, 0.8, 0.8 };
- if (equalColors(&pboMem[i * 3], exp) != true) {
- REPORT_FAILURE("glGetTexImage failed");
- printf(" got (%d) = [%f, %f, %f], ", i,
- pboMem[i * 3],
- pboMem[i * 3 + 1], pboMem[i * 3 + 2]);
- printf("should be [%f, %f, %f]\n",
- exp[0], exp[1], exp[2]);
-
- return false;
- }
- }
- else {
- GLfloat exp[3] = { 1.0, 1.0, 0.0 };
- if (equalColors(&pboMem[i * 3], exp) != true) {
- REPORT_FAILURE("glGetTexImage failed");
- printf(" got (%d) = [%f, %f, %f], ", i,
- pboMem[i * 3],
- pboMem[i * 3 + 1], pboMem[i * 3 + 2]);
- printf("should be [%f, %f, %f]\n",
- exp[0], exp[1], exp[2]);
-
- return false;
- }
- }
- }
-
- if (useTexPackBuffer) {
- glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_EXT);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
- glDeleteBuffersARB(1, pack_pb);
- }
- if (useTexUnpackBuffer) {
- glDeleteBuffersARB(1, unpack_pb);
- }
-
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_POLYGON);
- glTexCoord2f(0, 0);
- glVertex2f(0, 0);
- glTexCoord2f(1, 0);
- glVertex2f(TEXSIZE, 0);
- glTexCoord2f(1, 1);
- glVertex2f(TEXSIZE, TEXSIZE);
- glTexCoord2f(0, 1);
- glVertex2f(0, TEXSIZE);
- glEnd();
-
- glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT,
- buf);
- for (j = 0; j < windowSize; j++) {
- for (i = 0; i < windowSize; i++) {
- if (i == 0 && j == 0 && breakCOWTexture
- && useTexUnpackBuffer) {
- GLfloat exp[3] = { 0.8, 0.8, 0.8 };
- if (equalColors(&buf[(j * windowSize + i) * 3], exp)
- != true) {
- REPORT_FAILURE("glTexImage failed");
- printf(" got (%d, %d) = [%f, %f, %f], ", i, j,
- buf[(j * windowSize + i) * 3],
- buf[(j * windowSize + i) * 3 + 1],
- buf[(j * windowSize + i) * 3 + 2]);
- printf("should be [%f, %f, %f]\n",
- exp[0], exp[1], exp[2]);
-
- return false;
- }
- }
- else if (i < TEXSIZE && j < TEXSIZE) {
- if (equalColors(&buf[(j * windowSize + i) * 3], green)
- != true) {
- REPORT_FAILURE("glTexImage failed");
- printf(" got (%d, %d) = [%f, %f, %f], ", i, j,
- buf[(j * windowSize + i) * 3],
- buf[(j * windowSize + i) * 3 + 1],
- buf[(j * windowSize + i) * 3 + 2]);
- printf("should be [%f, %f, %f]\n",
- green[0], green[1], green[2]);
-
- return false;
- }
- }
- else {
- if (equalColors(&buf[(j * windowSize + i) * 3], black)
- != true) {
- REPORT_FAILURE("glTexImage failed");
- printf("(%d, %d) = [%f, %f, %f], ", i, j,
- buf[(j * windowSize + i) * 3],
- buf[(j * windowSize + i) * 3 + 1],
- buf[(j * windowSize + i) * 3 + 2]);
- printf("should be [0.0, 0.0, 0.0]\n");
-
- return false;
- }
- }
- }
- }
- }
- }
- }
- }
-
- return true;
-}
-
-bool PBOTest::testTexSubImage(void)
-{
- GLuint pbs[1];
- GLfloat t[TEXSIZE * TEXSIZE * 3];
- int i, j;
- int useUnpackBuffer = 0;
- GLfloat green[3] = { 0.0, 1.0, 0.0 };
- GLfloat black[3] = { 0.0, 0.0, 0.0 };
-
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
- for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1; useUnpackBuffer++) {
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
-
- if (useUnpackBuffer) {
- glGenBuffersARB(1, pbs);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, pbs[0]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, TEXSIZE * TEXSIZE * 3 * sizeof(GLfloat),
- NULL, GL_STREAM_DRAW);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- }
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE, TEXSIZE, 0, GL_RGB,
- GL_FLOAT, NULL);
-
- GLfloat *pboMem = NULL;
- if (useUnpackBuffer) {
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, pbs[0]);
- pboMem = (GLfloat *) glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_WRITE_ONLY);
- }
- else {
- pboMem = t;
- }
-
- for (i = 0; i < TEXSIZE * TEXSIZE; i++) {
- pboMem[3 * i] = 0.0;
- pboMem[3 * i + 1] = 1.0;
- pboMem[3 * i + 2] = 0.0;
- }
-
- if (useUnpackBuffer) {
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE, TEXSIZE, GL_RGB,
- GL_FLOAT, NULL);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- }
- else
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE, TEXSIZE, GL_RGB,
- GL_FLOAT, pboMem);
-
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_POLYGON);
- glTexCoord2f(0, 0);
- glVertex2f(0, 0);
- glTexCoord2f(1, 0);
- glVertex2f(10, 0);
- glTexCoord2f(1, 1);
- glVertex2f(10, 10);
- glTexCoord2f(0, 1);
- glVertex2f(0, 10);
- glEnd();
- glDisable(GL_TEXTURE_2D);
-
- GLfloat buf[windowSize * windowSize * 3];
-
- glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT, buf);
- for (j = 0; j < windowSize; j++) {
- for (i = 0; i < windowSize; i++) {
- if (i < 10 && j < 10) {
- if (equalColors(&buf[(j * windowSize + i) * 3], green) != true) {
- REPORT_FAILURE("glTexSubImage failed");
- printf(" got (%d, %d) = [%f, %f, %f], ", i, j,
- buf[(j * windowSize + i) * 3],
- buf[(j * windowSize + i) * 3 + 1],
- buf[(j * windowSize + i) * 3 + 2]);
- printf("should be [%f, %f, %f]\n",
- green[0], green[1], green[2]);
-
- return false;
- }
- }
- else {
- if (equalColors(&buf[(j * windowSize + i) * 3], black) != true) {
- REPORT_FAILURE("glTexSubImage failed");
- printf("(%d, %d) = [%f, %f, %f], ", i, j,
- buf[(j * windowSize + i) * 3],
- buf[(j * windowSize + i) * 3 + 1],
- buf[(j * windowSize + i) * 3 + 2]);
- printf("should be [0.0, 0.0, 0.0]\n");
-
- return false;
- }
-
- }
- }
- }
- }
- return true;
-}
-
-bool PBOTest::testPolygonStip(void)
-{
- int useUnpackBuffer = 0;
- int usePackBuffer = 0;
- GLuint unpack_pb[1];
- GLuint pack_pb[1];
- GLubyte t1[32 * 32 / 8];
- GLubyte t2[32 * 32 / 8];
- GLubyte *pboMem = NULL;
- int i, j;
- GLfloat white[3] = { 1.0, 1.0, 1.0 };
- GLfloat black[3] = { 0.0, 0.0, 0.0 };
-
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
- for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1; useUnpackBuffer++) {
- for (usePackBuffer = 0; usePackBuffer < usePBO + 1; usePackBuffer++) {
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
-
- if (useUnpackBuffer) {
- glGenBuffersARB(1, unpack_pb);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, unpack_pb[0]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, 32 * 32 / 8, NULL,
- GL_STREAM_DRAW);
- pboMem = (GLubyte *) glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_WRITE_ONLY);
- }
- else {
- pboMem = t1;
- }
-
-
- // Fill in the stipple pattern
- for (i = 0; i < 32 * 32 / 8; i++) {
- pboMem[i] = 0xAA;
- }
-
- if (useUnpackBuffer) {
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
- glPolygonStipple(NULL);
- }
- else {
- glPolygonStipple(pboMem);
- }
-
- // Read back the stipple pattern
- if (usePackBuffer) {
- glGenBuffersARB(1, pack_pb);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, pack_pb[0]);
- glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT, 32 * 32 / 8, NULL,
- GL_STREAM_DRAW);
- glGetPolygonStipple(NULL);
- pboMem = (GLubyte *) glMapBufferARB(GL_PIXEL_PACK_BUFFER_EXT,
- GL_READ_ONLY);
- }
- else {
- glGetPolygonStipple(t2);
- pboMem = t2;
- }
-
- for (i = 0; i < 32 * 32 / 8; i++) {
- if (pboMem[i] != 0xAA) {
- REPORT_FAILURE("glGetPolygonStipple failed");
- return false;
- }
- }
-
-
- if (useUnpackBuffer) {
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glDeleteBuffersARB(1, unpack_pb);
- }
- if (usePackBuffer) {
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
- glDeleteBuffersARB(1, pack_pb);
- }
-
- glEnable(GL_POLYGON_STIPPLE);
- glBegin(GL_POLYGON);
- glVertex2f(0, 0);
- glVertex2f(10, 0);
- glVertex2f(10, 10);
- glVertex2f(0, 10);
- glEnd();
-
- glDisable(GL_POLYGON_STIPPLE);
-
- // Check the result
- GLfloat buf[windowSize * windowSize * 3];
-
- glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT, buf);
-
- for (j = 0; j < windowSize; j++) {
- for (i = 0; i < windowSize; i++) {
- const GLfloat *exp;
- if (i & 1)
- exp = black;
- else
- exp = white;
- if (i < 10 && j < 10) {
- if (equalColors(&buf[(j * windowSize + i) * 3], exp) !=
- true) {
- REPORT_FAILURE("glGetPolygonStipple failed");
- printf("(%d, %d) = [%f, %f, %f], ", i, j,
- buf[(j * windowSize + i) * 3],
- buf[(j * windowSize + i) * 3 + 1],
- buf[(j * windowSize + i) * 3 + 2]);
- printf("should be [1.0, 1.0, 1.0]\n");
- return false;
- }
- }
- else {
- if (equalColors(&buf[(j * windowSize + i) * 3], black) !=
- true) {
- REPORT_FAILURE("glGetPolygonStipple failed");
- printf("(%d, %d) = [%f, %f, %f], ", i, j,
- buf[(j * windowSize + i) * 3],
- buf[(j * windowSize + i) * 3 + 1],
- buf[(j * windowSize + i) * 3 + 2]);
- printf("should be [0.0, 0.0, 0.0]\n");
- return false;
- }
-
- }
- }
- }
-
- }
- }
-
- return true;
-}
-
-
-bool PBOTest::testErrorHandling(void)
-{
- GLuint fbs[1];
-
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
- if (usePBO) {
- /* test that glDrawPixels from too small of buffer raises error */
- glGenBuffersARB(1, fbs);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, fbs[0]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, 32 * 32 * 4, NULL,
- GL_STREAM_DRAW);
- glDrawPixels(32, 32 + 1, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
- if (glGetError() != GL_INVALID_OPERATION)
- return false;
-
- glDeleteBuffersARB(1, fbs);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, 0);
-
- /* test that glReadPixels into too small of buffer raises error */
- glGenBuffersARB(1, fbs);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER, fbs[0]);
- glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT, 32 * 32 * 4, NULL,
- GL_STREAM_DRAW);
- glReadPixels(0, 0, 32, 32 + 1, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
- if (glGetError() != GL_INVALID_OPERATION)
- return false;
-
- glDeleteBuffersARB(1, fbs);
- glBindBufferARB(GL_PIXEL_PACK_BUFFER, 0);
- }
- return true;
-}
-
-bool PBOTest::testFunctionality(MultiTestResult & r)
-{
- static SubTestFunc
- funcs[] = {
- &GLEAN::PBOTest::testSanity,
- &GLEAN::PBOTest::testBitmap,
- &GLEAN::PBOTest::testDrawPixels,
- &GLEAN::PBOTest::testPixelMap,
- &GLEAN::PBOTest::testTexImage,
- &GLEAN::PBOTest::testTexSubImage,
- &GLEAN::PBOTest::testPolygonStip,
- &GLEAN::PBOTest::testErrorHandling,
- NULL
- };
-
- for (int i = 0; funcs[i]; i++)
- if ((this->*funcs[i]) ())
- r.numPassed++;
- else
- r.numFailed++;
- return true;
-}
-
-enum {
- BLACK,
- RED,
- GREEN,
- BLUE,
-WHITE };
-
-GLfloat colors1[][4] = {
- {0.0, 0.0, 0.0, 0.0},
- {1.0, 0.0, 0.0, 1.0},
- {0.0, 1.0, 0.0, 1.0},
- {0.0, 0.0, 1.0, 1.0},
- {1.0, 1.0, 1.0, 1.0}
-};
-
-#define TEXSIZE1 64
-bool PBOTest::testPerformance(MultiTestResult & r)
-{
- GLuint pbs[1];
- GLuint textures[1];
- GLubyte data[TEXSIZE1 * TEXSIZE1 * 4];
- int mode;
- int i, j;
- Timer t;
- double t0, t1, perf[2];
- GLubyte *pboMem = NULL;
-
- (void) r;
-
- for (mode = 0; mode < usePBO + 1; mode++) {
- t0 = t.getClock();
-
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- if (mode) {
- glGenBuffersARB(1, pbs);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, pbs[0]);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER,
- TEXSIZE1 * TEXSIZE1 * 4 * sizeof(GLubyte), NULL,
- GL_STREAM_DRAW);
- }
- glGenTextures(1, textures);
- glBindTexture(GL_TEXTURE_2D, textures[0]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXSIZE1,
- TEXSIZE1, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
- for (i = 0; i < 1024; i++) {
- if (mode) {
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, pbs[0]);
- pboMem =
- (GLubyte *) glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT,
- GL_WRITE_ONLY);
- }
- else {
- pboMem = data;
- }
-
- for (j = 0; j < TEXSIZE1 * TEXSIZE1; j++) {
- pboMem[4 * j] = 255;
- pboMem[4 * j + 1] = 255;
- pboMem[4 * j + 2] = 0;
- pboMem[4 * j + 3] = 0;
- }
-
- if (mode) {
- glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE1,
- TEXSIZE1, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, 0);
- }
- else {
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE1,
- TEXSIZE1, GL_BGRA, GL_UNSIGNED_BYTE, data);
- }
-
-
- // Actually apply the texture
- glEnable(GL_TEXTURE_2D);
- glColor4fv(colors1[WHITE]);
-
- glBegin(GL_POLYGON);
- glTexCoord2f(0.0, 0.0);
- glVertex2f(0, 0);
- glTexCoord2f(1.0, 0.0);
- glVertex2f(1, 0);
- glTexCoord2f(1.0, 1.0);
- glVertex2f(1, 1);
- glTexCoord2f(0.0, 1.0);
- glVertex2f(0, 1);
- glEnd();
- glFlush();
- glDisable(GL_TEXTURE_2D);
- }
- t1 = t.getClock();
- glDeleteTextures(1, textures);
- if (mode)
- glDeleteBuffersARB(1, pbs);
-
- perf[mode] = (double) TEXSIZE1 * TEXSIZE1 * 3 * sizeof(GLfloat) / 1024 / (t1 - t0);
-
- }
-
- if (perf[1] < perf[0] && usePBO) {
- env->log << name << ": NOTE "
- << "perf[0] = " << perf[0] <<
- " MB/s, which is in normal mode" << endl;
- env->log << name << ": NOTE " << "perf[1] = " <<
- perf[1] << " MB/s, which is using PBO" << endl;
- }
-
- return true;
-}
-
-
-
-// Run all the subtests, incrementing numPassed, numFailed
-void
-PBOTest::runSubTests(MultiTestResult & r)
-{
- static TestFunc funcs[] = {
- &GLEAN::PBOTest::testFunctionality,
- &GLEAN::PBOTest::testPerformance,
- NULL
- };
-
- for (int i = 0; funcs[i]; i++)
- if ((this->*funcs[i]) (r))
- r.numPassed++;
- else
- r.numFailed++;
-}
-
-
-void
-PBOTest::runOne(MultiTestResult & r, Window & w)
-{
- (void) w;
-
- if (!setup()) {
- r.pass = false;
- return;
- }
-
- runSubTests(r);
-
- r.pass = (r.numFailed == 0);
-}
-
-
-// The test object itself:
-PBOTest pboTest("pbo", "window, rgb, z", "", // no extension filter
- "pbo test: Test OpenGL Extension GL_ARB_pixel_buffer_object\n");
-
-
-
-} // namespace GLEAN
+// BEGIN_COPYRIGHT -*- glean -*-
+//
+// Copyrigth (C) 2007 Intel Corporation
+// Copyright (C) 1999 Allen Akin All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the
+// Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// END_COPYRIGHT
+//
+// Authors:
+// Shuang He <shuang.he@intel.com>
+//
+// tpbo.cpp: Test OpenGL Extension GL_ARB_pixel_buffer_object
+
+
+#define GL_GLEXT_PROTOTYPES
+
+#include <stdlib.h>
+#include <cstring>
+#include <cassert>
+#include <math.h>
+#include "tpbo.h"
+#include "timer.h"
+
+
+namespace GLEAN
+{
+// GL_VERSION_1_5
+static PFNGLBINDBUFFERPROC glBindBuffer_func = NULL;
+static PFNGLMAPBUFFERPROC glMapBuffer_func = NULL;
+static PFNGLUNMAPBUFFERPROC glUnmapBuffer_func = NULL;
+
+// GL_ARB_vertex_buffer_object
+static PFNGLBINDBUFFERARBPROC glBindBufferARB_func = NULL;
+static PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB_func = NULL;
+static PFNGLGENBUFFERSARBPROC glGenBuffersARB_func = NULL;
+static PFNGLISBUFFERARBPROC glIsBufferARB_func = NULL;
+static PFNGLBUFFERDATAARBPROC glBufferDataARB_func = NULL;
+static PFNGLMAPBUFFERARBPROC glMapBufferARB_func = NULL;
+static PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB_func = NULL;
+
+static int usePBO;
+#define BUFFER_OFFSET(i) ((char *)NULL + (i))
+
+bool PBOTest::setup(void)
+{
+ glMatrixMode(GL_PROJECTION);
+
+ glLoadIdentity();
+ gluOrtho2D(0, 100, 0, 100);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glDrawBuffer(GL_FRONT);
+ glReadBuffer(GL_FRONT);
+
+ // compute error tolerances (may need fine-tuning)
+ int
+ bufferBits[5];
+
+ glGetIntegerv(GL_RED_BITS, &bufferBits[0]);
+ glGetIntegerv(GL_GREEN_BITS, &bufferBits[1]);
+ glGetIntegerv(GL_BLUE_BITS, &bufferBits[2]);
+ glGetIntegerv(GL_ALPHA_BITS, &bufferBits[3]);
+ glGetIntegerv(GL_DEPTH_BITS, &bufferBits[4]);
+
+ tolerance[0] = 2.0 / (1 << bufferBits[0]);
+ tolerance[1] = 2.0 / (1 << bufferBits[1]);
+ tolerance[2] = 2.0 / (1 << bufferBits[2]);
+ if (bufferBits[3])
+ tolerance[3] = 2.0 / (1 << bufferBits[3]);
+ else
+ tolerance[3] = 1.0;
+ if (bufferBits[4])
+ tolerance[4] = 16.0 / (1 << bufferBits[4]);
+ else
+ tolerance[4] = 1.0;
+
+ // Check if GL_ARB_pixel_buffer_object is supported
+ if (!strstr((char *) glGetString(GL_EXTENSIONS), "GL_ARB_pixel_buffer_object")) {
+ //printf("GL_ARB_pixel_buffer_object is not supported\n");
+ usePBO = 0;
+ return false;
+ }
+ else {
+ //printf("GL_ARB_pixel_buffer_object is supported\n");
+ usePBO = 1;
+ }
+
+ glBindBuffer_func = (PFNGLBINDBUFFERPROC) GLUtils::getProcAddress("glBindBuffer");
+ assert(glBindBuffer_func);
+ glMapBuffer_func = (PFNGLMAPBUFFERPROC) GLUtils::getProcAddress("glMapBuffer");
+ assert(glMapBuffer_func);
+ glUnmapBuffer_func = (PFNGLUNMAPBUFFERPROC) GLUtils::getProcAddress("glUnmapBuffer");
+ assert(glUnmapBuffer_func);
+
+ glBindBufferARB_func = (PFNGLBINDBUFFERARBPROC) GLUtils::getProcAddress("glBindBufferARB");
+ assert(glBindBufferARB_func);
+ glDeleteBuffersARB_func = (PFNGLDELETEBUFFERSARBPROC) GLUtils::getProcAddress("glDeleteBuffersARB");
+ assert(glDeleteBuffersARB_func);
+ glGenBuffersARB_func = (PFNGLGENBUFFERSARBPROC) GLUtils::getProcAddress("glGenBuffersARB");
+ assert(glGenBuffersARB_func);
+ glIsBufferARB_func = (PFNGLISBUFFERARBPROC) GLUtils::getProcAddress("glIsBufferARB");
+ assert(glIsBufferARB_func);
+ glBufferDataARB_func = (PFNGLBUFFERDATAARBPROC) GLUtils::getProcAddress("glBufferDataARB");
+ assert(glBufferDataARB_func);
+ glMapBufferARB_func = (PFNGLMAPBUFFERARBPROC) GLUtils::getProcAddress("glMapBufferARB");
+ assert(glMapBufferARB_func);
+ glUnmapBufferARB_func = (PFNGLUNMAPBUFFERARBPROC) GLUtils::getProcAddress("glUnmapBufferARB");
+ assert(glUnmapBufferARB_func);
+
+ return true;
+}
+
+
+void
+PBOTest::reportFailure(const char *msg, const int line) const
+{
+ env->log << "FAILURE: " << msg << " (at tpbo.cpp:" << line << ")\n";
+}
+
+void
+PBOTest::reportFailure(const char *msg, const GLenum target, const int line) const
+{
+ env->log << "FAILURE: " << msg;
+ if (target == GL_FRAGMENT_SHADER)
+ env->log << " (fragment)";
+ else
+ env->log << " (vertex)";
+ env->log << " (at tpbo.cpp:" << line << ")\n";
+}
+
+#define REPORT_FAILURE(MSG) reportFailure(MSG, __LINE__)
+#define REPORT_FAILURE_T(MSG, TARGET) reportFailure(MSG, TARGET, __LINE__)
+// Compare actual and expected colors
+bool PBOTest::equalColors(const GLfloat act[3], const GLfloat exp[3]) const
+{
+ if ((fabsf(act[0] - exp[0]) > tolerance[0])
+ || (fabsf(act[1] - exp[1]) > tolerance[1])
+ || (fabsf(act[2] - exp[2]) > tolerance[2])) {
+ return false;
+ }
+ else
+ return true;
+}
+
+bool PBOTest::equalColors1(const GLubyte act[3], const GLubyte exp[3]) const
+{
+ if ((act[0] != exp[0])
+ || (act[1] != exp[1])
+ || (act[2] != exp[2])) {
+ return false;
+ }
+ else
+ return true;
+}
+
+
+
+#define TEXSIZE 64
+
+bool PBOTest::testSanity(void)
+{
+ GLuint pbs[1];
+ GLuint pb_binding;
+
+ if (!usePBO)
+ return true;
+
+ // Check default binding
+ glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, (GLint *) & pb_binding);
+ if (pb_binding != 0) {
+ REPORT_FAILURE("Failed to bind unpack pixel buffer object");
+ return false;
+ }
+
+ glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING_ARB, (GLint *) & pb_binding);
+ if (pb_binding != 0) {
+ REPORT_FAILURE("Failed to bind pack pixel buffer object");
+ return false;
+ }
+
+ glGenBuffersARB_func(1, pbs);
+
+ if (glIsBufferARB_func(pbs[0]) != GL_TRUE) {
+ REPORT_FAILURE("Failed to call glIsBuffersARB");
+ return false;
+ }
+
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, pbs[0]);
+ glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, (GLint *) & pb_binding);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ if (pb_binding != pbs[0]) {
+ REPORT_FAILURE("Failed to bind unpack pixel buffer object");
+ return false;
+ }
+
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, pbs[0]);
+ glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING_ARB, (GLint *) & pb_binding);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+ if (pb_binding != pbs[0]) {
+ REPORT_FAILURE("Failed to bind unpack pixel buffer object");
+ return false;
+ }
+
+ glDeleteBuffersARB_func(1, pbs);
+
+ if (glIsBufferARB_func(pbs[0]) == GL_TRUE) {
+ REPORT_FAILURE("Failed to call glIsBuffersARB");
+ return false;
+ }
+
+ return true;
+}
+
+
+bool PBOTest::testDrawPixels(void)
+{
+ int useUnpackBuffer;
+ int usePackBuffer;
+ GLuint pb_pack[1];
+ GLuint pb_unpack[1];
+ GLubyte buf[windowSize * windowSize * 4];
+ GLubyte t[TEXSIZE * TEXSIZE * 4];
+ int i, j;
+ GLubyte * pboPackMem = NULL;
+ GLubyte black[3] = { 0, 0, 0 };
+
+ glBindBuffer_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glBindBuffer_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+
+ for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1; useUnpackBuffer++) {
+ for (usePackBuffer = 0; usePackBuffer < usePBO + 1; usePackBuffer++) {
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ if (useUnpackBuffer) {
+ glGenBuffersARB_func(1, pb_unpack);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, pb_unpack[0]);
+ glBufferDataARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ TEXSIZE * TEXSIZE * 4 * sizeof(GLubyte), NULL,
+ GL_STREAM_DRAW);
+ }
+ GLubyte *pboMem = NULL;
+ if (useUnpackBuffer) {
+ pboMem = (GLubyte *) glMapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ GL_WRITE_ONLY);
+ }
+ else {
+ pboMem = t;
+ }
+
+ for (i = 0; i < TEXSIZE; i++)
+ for (j = 0; j < TEXSIZE; j++) {
+ pboMem[4 * (i * TEXSIZE + j)] = i % 256;
+ pboMem[4 * (i * TEXSIZE + j) + 1] = i % 256;
+ pboMem[4 * (i * TEXSIZE + j) + 2] = i % 256;
+ pboMem[4 * (i * TEXSIZE + j) + 3] = 0;
+ }
+
+ if (useUnpackBuffer) {
+ glUnmapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ }
+
+ if (useUnpackBuffer) {
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, pb_unpack[0]);
+ glDrawPixels(TEXSIZE, TEXSIZE, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ }
+ else
+ glDrawPixels(TEXSIZE, TEXSIZE, GL_BGRA, GL_UNSIGNED_BYTE, pboMem);
+
+ // Check the result
+ if (usePackBuffer) {
+ glGenBuffersARB_func(1, pb_pack);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, pb_pack[0]);
+ glBufferDataARB_func(GL_PIXEL_PACK_BUFFER_ARB,
+ windowSize * windowSize * 4 *
+ sizeof(GL_UNSIGNED_BYTE), NULL, GL_STREAM_DRAW);
+ glReadPixels(0, 0, windowSize, windowSize, GL_BGRA,
+ GL_UNSIGNED_BYTE, NULL);
+ pboPackMem = (GLubyte *) glMapBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB,
+ GL_READ_ONLY);
+ }
+ else {
+ pboPackMem = buf;
+ glReadPixels(0, 0, windowSize, windowSize, GL_BGRA,
+ GL_UNSIGNED_BYTE, pboPackMem);
+ }
+
+ for (j = 0; j < windowSize; j++) {
+ for (i = 0; i < windowSize; i++) {
+ GLubyte exp[3];
+ exp[0] = j % 256;
+ exp[1] = j % 256;
+ exp[2] = j % 256;
+
+ if (i < TEXSIZE && j < TEXSIZE) {
+ if (equalColors1(&pboPackMem[(j * windowSize + i) * 4], exp)
+ != true) {
+ REPORT_FAILURE("glDrawPixels failed");
+ printf(" got (%d, %d) = [%d, %d, %d], ", i, j,
+ pboPackMem[(j * windowSize + i) * 4],
+ pboPackMem[(j * windowSize + i) * 4 + 1],
+ pboPackMem[(j * windowSize + i) * 4 + 2]);
+ printf("should be [%d, %d, %d]\n",
+ exp[0], exp[1], exp[2]);
+
+ return false;
+ }
+ }
+ else {
+ if (equalColors1(&pboPackMem[(j * windowSize + i) * 4],
+ black) != true) {
+ REPORT_FAILURE("glDrawPixels failed");
+ printf("(%d, %d) = [%d, %d, %d], ", i, j,
+ pboPackMem[(j * windowSize + i) * 4],
+ pboPackMem[(j * windowSize + i) * 4 + 1],
+ pboPackMem[(j * windowSize + i) * 4 + 2]);
+ printf("should be [0.0, 0.0, 0.0]\n");
+ return false;
+ }
+
+ }
+ }
+ }
+
+
+ if (usePackBuffer) {
+ glBindBuffer_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+ glDeleteBuffersARB_func(1, pb_pack);
+ }
+
+ if (useUnpackBuffer) {
+ glBindBuffer_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glDeleteBuffersARB_func(1, pb_unpack);
+ }
+
+ }
+ }
+
+ return true;
+}
+
+
+bool PBOTest::testPixelMap(void)
+{
+ int useUnpackBuffer;
+ int usePackBuffer;
+ GLuint pb_pack[1];
+ GLuint pb_unpack[1];
+ int i;
+ int size;
+ int max;
+
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+
+ glGetIntegerv(GL_MAX_PIXEL_MAP_TABLE, &max);
+
+ for (usePackBuffer = 0; usePackBuffer < usePBO + 1; usePackBuffer++) {
+ for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1;
+ useUnpackBuffer++) {
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ if (useUnpackBuffer) {
+ glGenBuffersARB_func(1, pb_unpack);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, pb_unpack[0]);
+ glBufferDataARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, max * sizeof(GLushort),
+ NULL, GL_STREAM_DRAW);
+ }
+ GLushort *pboMem = NULL;
+ if (useUnpackBuffer) {
+ pboMem = (GLushort *) glMapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ GL_WRITE_ONLY);
+ }
+ else {
+ pboMem = (GLushort *) malloc(sizeof(GLushort) * max);
+ }
+ for (i = 0; i < max; i++)
+ pboMem[i] = max - i - 1;
+
+ if (useUnpackBuffer) {
+ glUnmapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB);
+ glPixelMapusv(GL_PIXEL_MAP_R_TO_R, max, NULL);
+ glPixelMapusv(GL_PIXEL_MAP_G_TO_G, max, NULL);
+ glPixelMapusv(GL_PIXEL_MAP_B_TO_B, max, NULL);
+ glPixelMapusv(GL_PIXEL_MAP_A_TO_A, max, NULL);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ }
+ else {
+ glPixelMapusv(GL_PIXEL_MAP_R_TO_R, max, pboMem);
+ glPixelMapusv(GL_PIXEL_MAP_G_TO_G, max, pboMem);
+ glPixelMapusv(GL_PIXEL_MAP_B_TO_B, max, pboMem);
+ glPixelMapusv(GL_PIXEL_MAP_A_TO_A, max, pboMem);
+ free(pboMem);
+ }
+
+
+ glGetIntegerv(GL_PIXEL_MAP_R_TO_R_SIZE, &size);
+ if (size != max) {
+ REPORT_FAILURE("glPixelMap failed");
+ return false;
+ }
+ glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
+
+ // Read back pixel map
+ if (usePackBuffer) {
+ glGenBuffersARB_func(1, pb_pack);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, pb_pack[0]);
+ glBufferDataARB_func(GL_PIXEL_PACK_BUFFER_ARB, max * sizeof(GLushort),
+ NULL, GL_STREAM_DRAW);
+ glGetPixelMapusv(GL_PIXEL_MAP_R_TO_R, NULL);
+ pboMem = (GLushort *) glMapBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB,
+ GL_READ_ONLY);
+ }
+ else {
+ pboMem = (GLushort *) malloc(sizeof(GLushort) * max);
+ glGetPixelMapusv(GL_PIXEL_MAP_R_TO_R, pboMem);
+ }
+
+ for (i = 0; i < max; i++) {
+ if (pboMem[i] != (255 - i)) {
+ REPORT_FAILURE("get PixelMap failed");
+ return false;
+ }
+ }
+
+
+ if (usePackBuffer) {
+ glUnmapBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+ glDeleteBuffersARB_func(1, pb_pack);
+ }
+ else {
+ free(pboMem);
+ }
+
+ if (useUnpackBuffer) {
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glDeleteBuffersARB_func(1, pb_unpack);
+ }
+
+ }
+ }
+
+ return true;
+}
+
+bool PBOTest::testBitmap(void)
+{
+ GLuint pb_unpack[1];
+ GLuint pb_pack[1];
+ int useUnpackBuffer = usePBO;
+ int usePackBuffer = 0;
+ GLubyte bitmap[TEXSIZE * TEXSIZE / 8];
+ GLfloat buf[windowSize * windowSize * 3];
+ GLfloat white[3] = { 1.0, 1.0, 1.0 };
+ GLfloat black[3] = { 0.0, 0.0, 0.0 };
+ int i, j;
+ GLubyte *pboUnpackMem = NULL;
+ GLfloat *pboPackMem = NULL;
+
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+
+ for (usePackBuffer = 0; usePackBuffer < usePBO + 1; usePackBuffer++) {
+ for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1;
+ useUnpackBuffer++) {
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ if (useUnpackBuffer) {
+ glGenBuffersARB_func(1, pb_unpack);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, pb_unpack[0]);
+ glBufferDataARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, TEXSIZE * TEXSIZE, NULL,
+ GL_STREAM_DRAW);
+ pboUnpackMem = (GLubyte *) glMapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ GL_WRITE_ONLY);
+ }
+ else {
+ pboUnpackMem = bitmap;
+ }
+
+ for (i = 0; i < TEXSIZE * TEXSIZE / 8; i++) {
+ pboUnpackMem[i] = 0xAA;
+ }
+
+
+ glColor4f(1.0, 1.0, 1.0, 0.0);
+ glRasterPos2f(0.0, 0.0);
+ if (useUnpackBuffer) {
+ glUnmapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB);
+ glBitmap(TEXSIZE, TEXSIZE, 0, 0, 0, 0, NULL);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ }
+ else
+ glBitmap(TEXSIZE, TEXSIZE, 0, 0, 0, 0, pboUnpackMem);
+
+ // Check the result
+ if (usePackBuffer) {
+ glGenBuffersARB_func(1, pb_pack);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, pb_pack[0]);
+ glBufferDataARB_func(GL_PIXEL_PACK_BUFFER_ARB,
+ windowSize * windowSize * 4 * sizeof(GLfloat),
+ NULL,
+ GL_STREAM_DRAW);
+ glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT,
+ NULL);
+ pboPackMem =
+ (GLfloat *) glMapBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB,
+ GL_READ_ONLY);
+ }
+ else {
+ pboPackMem = buf;
+ glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT,
+ pboPackMem);
+ }
+
+ for (j = 0; j < windowSize; j++) {
+ for (i = 0; i < windowSize; i++) {
+ const GLfloat *exp;
+ if ((i & 1))
+ exp = black;
+ else
+ exp = white;
+ if (i < TEXSIZE && j < TEXSIZE) {
+ if (equalColors(&pboPackMem[(j * windowSize + i) * 3], exp)
+ != true) {
+ REPORT_FAILURE("glBitmap failed");
+ printf(" got (%d, %d) = [%f, %f, %f], ", i, j,
+ pboPackMem[(j * windowSize + i) * 3],
+ pboPackMem[(j * windowSize + i) * 3 + 1],
+ pboPackMem[(j * windowSize + i) * 3 + 2]);
+ printf("should be [%f, %f, %f]\n",
+ exp[0], exp[1], exp[2]);
+
+ return false;
+ }
+ }
+ else {
+ if (equalColors
+ (&pboPackMem[(j * windowSize + i) * 3],
+ black) != true) {
+ REPORT_FAILURE("glBitmap failed");
+ printf("(%d, %d) = [%f, %f, %f], ", i, j,
+ pboPackMem[(j * windowSize + i) * 3],
+ pboPackMem[(j * windowSize + i) * 3 + 1],
+ pboPackMem[(j * windowSize + i) * 3 + 2]);
+ printf("should be [0.0, 0.0, 0.0]\n");
+ return false;
+ }
+
+ }
+ }
+ }
+ if (usePackBuffer) {
+ glUnmapBuffer_func(GL_PIXEL_PACK_BUFFER_ARB);
+ glBindBuffer_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+ glDeleteBuffersARB_func(1, pb_pack);
+ }
+
+ if (useUnpackBuffer) {
+ glBindBuffer_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glDeleteBuffersARB_func(1, pb_unpack);
+ }
+ }
+ }
+ return true;
+}
+
+
+bool PBOTest::testTexImage(void)
+{
+ int breakCOWPBO, breakCOWTexture;
+ int useTexUnpackBuffer, useTexPackBuffer;
+ GLuint unpack_pb[1];
+ GLuint pack_pb[1];
+ GLfloat t1[TEXSIZE * TEXSIZE * 3];
+ GLfloat t2[TEXSIZE * TEXSIZE * 3];
+ GLfloat *pboMem = NULL;
+ int i, j;
+ GLfloat green[3] = { 1.0, 1.0, 0.0 };
+ GLfloat black[3] = { 0.0, 0.0, 0.0 };
+ GLfloat buf[windowSize * windowSize * 3];
+
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ for (useTexPackBuffer = 0; useTexPackBuffer < usePBO + 1;
+ useTexPackBuffer++) {
+ for (useTexUnpackBuffer = 0; useTexUnpackBuffer < usePBO + 1;
+ useTexUnpackBuffer++) {
+ for (breakCOWPBO = 0; breakCOWPBO < useTexUnpackBuffer + 1;
+ breakCOWPBO++) {
+ for (breakCOWTexture = 0;
+ breakCOWTexture < useTexUnpackBuffer + 1;
+ breakCOWTexture++) {
+ if (useTexUnpackBuffer) {
+ glGenBuffersARB_func(1, unpack_pb);
+ if (glIsBufferARB_func(unpack_pb[0]) == false)
+ return false;
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, unpack_pb[0]);
+ glBufferDataARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ TEXSIZE * TEXSIZE * 3 * sizeof(GLfloat), NULL,
+ GL_STREAM_DRAW);
+ }
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ GL_NEAREST);
+
+ if (useTexUnpackBuffer) {
+ pboMem =
+ (GLfloat *) glMapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ GL_WRITE_ONLY);
+ }
+ else {
+ pboMem = t1;
+ }
+
+ for (i = 0; i < TEXSIZE * TEXSIZE; i++) {
+ pboMem[3 * i] = 1.0;
+ pboMem[3 * i + 1] = 1.0;
+ pboMem[3 * i + 2] = 0.0;
+ }
+
+ if (useTexUnpackBuffer) {
+ glUnmapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE, TEXSIZE, 0,
+ GL_RGB, GL_FLOAT, NULL);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ }
+ else
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE, TEXSIZE, 0,
+ GL_RGB, GL_FLOAT, pboMem);
+
+ if (useTexUnpackBuffer) {
+ if (breakCOWPBO) {
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, unpack_pb[0]);
+ pboMem =
+ (GLfloat *) glMapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ GL_WRITE_ONLY);
+ for (i = 0; i < TEXSIZE * TEXSIZE * 3; i++)
+ pboMem[i] = 0.2;
+ glUnmapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ }
+ }
+
+ if (useTexUnpackBuffer) {
+ if (breakCOWTexture) {
+ GLfloat temp[1 * 1 * 3];
+ for (i = 0; i < 1 * 1 * 3; i++)
+ temp[i] = 0.8;
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGB,
+ GL_FLOAT, temp);
+ }
+ }
+
+ // Check PBO's content
+ if (useTexUnpackBuffer) {
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, unpack_pb[0]);
+ pboMem = (GLfloat *) glMapBuffer_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ GL_READ_ONLY);
+ if (breakCOWPBO) {
+ for (i = 0; i < TEXSIZE * TEXSIZE * 3; i++)
+ if (fabsf(pboMem[i] - 0.2) > tolerance[0]) {
+ REPORT_FAILURE
+ ("PBO modified by someone else, there must be something wrong");
+ return false;
+ }
+ }
+ glUnmapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ }
+
+
+ // Read texture back
+ if (useTexPackBuffer) {
+ glGenBuffersARB_func(1, pack_pb);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, pack_pb[0]);
+ glBufferDataARB_func(GL_PIXEL_PACK_BUFFER_ARB,
+ TEXSIZE * TEXSIZE * 3 * sizeof(GLfloat), NULL,
+ GL_STREAM_DRAW);
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, NULL);
+ pboMem = (GLfloat *) glMapBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB,
+ GL_READ_ONLY);
+ }
+ else {
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, t2);
+ pboMem = t2;
+ }
+
+ // Check texture image
+ for (i = 0; i < TEXSIZE * TEXSIZE; i++) {
+ if (i == 0 && breakCOWTexture && useTexUnpackBuffer) {
+ GLfloat exp[3] = { 0.8, 0.8, 0.8 };
+ if (equalColors(&pboMem[i * 3], exp) != true) {
+ REPORT_FAILURE("glGetTexImage failed");
+ printf(" got (%d) = [%f, %f, %f], ", i,
+ pboMem[i * 3],
+ pboMem[i * 3 + 1], pboMem[i * 3 + 2]);
+ printf("should be [%f, %f, %f]\n",
+ exp[0], exp[1], exp[2]);
+
+ return false;
+ }
+ }
+ else {
+ GLfloat exp[3] = { 1.0, 1.0, 0.0 };
+ if (equalColors(&pboMem[i * 3], exp) != true) {
+ REPORT_FAILURE("glGetTexImage failed");
+ printf(" got (%d) = [%f, %f, %f], ", i,
+ pboMem[i * 3],
+ pboMem[i * 3 + 1], pboMem[i * 3 + 2]);
+ printf("should be [%f, %f, %f]\n",
+ exp[0], exp[1], exp[2]);
+
+ return false;
+ }
+ }
+ }
+
+ if (useTexPackBuffer) {
+ glUnmapBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+ glDeleteBuffersARB_func(1, pack_pb);
+ }
+ if (useTexUnpackBuffer) {
+ glDeleteBuffersARB_func(1, unpack_pb);
+ }
+
+ glEnable(GL_TEXTURE_2D);
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0, 0);
+ glVertex2f(0, 0);
+ glTexCoord2f(1, 0);
+ glVertex2f(TEXSIZE, 0);
+ glTexCoord2f(1, 1);
+ glVertex2f(TEXSIZE, TEXSIZE);
+ glTexCoord2f(0, 1);
+ glVertex2f(0, TEXSIZE);
+ glEnd();
+
+ glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT,
+ buf);
+ for (j = 0; j < windowSize; j++) {
+ for (i = 0; i < windowSize; i++) {
+ if (i == 0 && j == 0 && breakCOWTexture
+ && useTexUnpackBuffer) {
+ GLfloat exp[3] = { 0.8, 0.8, 0.8 };
+ if (equalColors(&buf[(j * windowSize + i) * 3], exp)
+ != true) {
+ REPORT_FAILURE("glTexImage failed");
+ printf(" got (%d, %d) = [%f, %f, %f], ", i, j,
+ buf[(j * windowSize + i) * 3],
+ buf[(j * windowSize + i) * 3 + 1],
+ buf[(j * windowSize + i) * 3 + 2]);
+ printf("should be [%f, %f, %f]\n",
+ exp[0], exp[1], exp[2]);
+
+ return false;
+ }
+ }
+ else if (i < TEXSIZE && j < TEXSIZE) {
+ if (equalColors(&buf[(j * windowSize + i) * 3], green)
+ != true) {
+ REPORT_FAILURE("glTexImage failed");
+ printf(" got (%d, %d) = [%f, %f, %f], ", i, j,
+ buf[(j * windowSize + i) * 3],
+ buf[(j * windowSize + i) * 3 + 1],
+ buf[(j * windowSize + i) * 3 + 2]);
+ printf("should be [%f, %f, %f]\n",
+ green[0], green[1], green[2]);
+
+ return false;
+ }
+ }
+ else {
+ if (equalColors(&buf[(j * windowSize + i) * 3], black)
+ != true) {
+ REPORT_FAILURE("glTexImage failed");
+ printf("(%d, %d) = [%f, %f, %f], ", i, j,
+ buf[(j * windowSize + i) * 3],
+ buf[(j * windowSize + i) * 3 + 1],
+ buf[(j * windowSize + i) * 3 + 2]);
+ printf("should be [0.0, 0.0, 0.0]\n");
+
+ return false;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
+bool PBOTest::testTexSubImage(void)
+{
+ GLuint pbs[1];
+ GLfloat t[TEXSIZE * TEXSIZE * 3];
+ int i, j;
+ int useUnpackBuffer = 0;
+ GLfloat green[3] = { 0.0, 1.0, 0.0 };
+ GLfloat black[3] = { 0.0, 0.0, 0.0 };
+
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+
+ for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1; useUnpackBuffer++) {
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ if (useUnpackBuffer) {
+ glGenBuffersARB_func(1, pbs);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, pbs[0]);
+ glBufferDataARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, TEXSIZE * TEXSIZE * 3 * sizeof(GLfloat),
+ NULL, GL_STREAM_DRAW);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ }
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXSIZE, TEXSIZE, 0, GL_RGB,
+ GL_FLOAT, NULL);
+
+ GLfloat *pboMem = NULL;
+ if (useUnpackBuffer) {
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, pbs[0]);
+ pboMem = (GLfloat *) glMapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ GL_WRITE_ONLY);
+ }
+ else {
+ pboMem = t;
+ }
+
+ for (i = 0; i < TEXSIZE * TEXSIZE; i++) {
+ pboMem[3 * i] = 0.0;
+ pboMem[3 * i + 1] = 1.0;
+ pboMem[3 * i + 2] = 0.0;
+ }
+
+ if (useUnpackBuffer) {
+ glUnmapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE, TEXSIZE, GL_RGB,
+ GL_FLOAT, NULL);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ }
+ else
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE, TEXSIZE, GL_RGB,
+ GL_FLOAT, pboMem);
+
+ glEnable(GL_TEXTURE_2D);
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0, 0);
+ glVertex2f(0, 0);
+ glTexCoord2f(1, 0);
+ glVertex2f(10, 0);
+ glTexCoord2f(1, 1);
+ glVertex2f(10, 10);
+ glTexCoord2f(0, 1);
+ glVertex2f(0, 10);
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+
+ GLfloat buf[windowSize * windowSize * 3];
+
+ glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT, buf);
+ for (j = 0; j < windowSize; j++) {
+ for (i = 0; i < windowSize; i++) {
+ if (i < 10 && j < 10) {
+ if (equalColors(&buf[(j * windowSize + i) * 3], green) != true) {
+ REPORT_FAILURE("glTexSubImage failed");
+ printf(" got (%d, %d) = [%f, %f, %f], ", i, j,
+ buf[(j * windowSize + i) * 3],
+ buf[(j * windowSize + i) * 3 + 1],
+ buf[(j * windowSize + i) * 3 + 2]);
+ printf("should be [%f, %f, %f]\n",
+ green[0], green[1], green[2]);
+
+ return false;
+ }
+ }
+ else {
+ if (equalColors(&buf[(j * windowSize + i) * 3], black) != true) {
+ REPORT_FAILURE("glTexSubImage failed");
+ printf("(%d, %d) = [%f, %f, %f], ", i, j,
+ buf[(j * windowSize + i) * 3],
+ buf[(j * windowSize + i) * 3 + 1],
+ buf[(j * windowSize + i) * 3 + 2]);
+ printf("should be [0.0, 0.0, 0.0]\n");
+
+ return false;
+ }
+
+ }
+ }
+ }
+ }
+ return true;
+}
+
+bool PBOTest::testPolygonStip(void)
+{
+ int useUnpackBuffer = 0;
+ int usePackBuffer = 0;
+ GLuint unpack_pb[1];
+ GLuint pack_pb[1];
+ GLubyte t1[32 * 32 / 8];
+ GLubyte t2[32 * 32 / 8];
+ GLubyte *pboMem = NULL;
+ int i, j;
+ GLfloat white[3] = { 1.0, 1.0, 1.0 };
+ GLfloat black[3] = { 0.0, 0.0, 0.0 };
+
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+
+ for (useUnpackBuffer = 0; useUnpackBuffer < usePBO + 1; useUnpackBuffer++) {
+ for (usePackBuffer = 0; usePackBuffer < usePBO + 1; usePackBuffer++) {
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ if (useUnpackBuffer) {
+ glGenBuffersARB_func(1, unpack_pb);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, unpack_pb[0]);
+ glBufferDataARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 32 * 32 / 8, NULL,
+ GL_STREAM_DRAW);
+ pboMem = (GLubyte *) glMapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ GL_WRITE_ONLY);
+ }
+ else {
+ pboMem = t1;
+ }
+
+
+ // Fill in the stipple pattern
+ for (i = 0; i < 32 * 32 / 8; i++) {
+ pboMem[i] = 0xAA;
+ }
+
+ if (useUnpackBuffer) {
+ glUnmapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB);
+ glPolygonStipple(NULL);
+ }
+ else {
+ glPolygonStipple(pboMem);
+ }
+
+ // Read back the stipple pattern
+ if (usePackBuffer) {
+ glGenBuffersARB_func(1, pack_pb);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, pack_pb[0]);
+ glBufferDataARB_func(GL_PIXEL_PACK_BUFFER_ARB, 32 * 32 / 8, NULL,
+ GL_STREAM_DRAW);
+ glGetPolygonStipple(NULL);
+ pboMem = (GLubyte *) glMapBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB,
+ GL_READ_ONLY);
+ }
+ else {
+ glGetPolygonStipple(t2);
+ pboMem = t2;
+ }
+
+ for (i = 0; i < 32 * 32 / 8; i++) {
+ if (pboMem[i] != 0xAA) {
+ REPORT_FAILURE("glGetPolygonStipple failed");
+ return false;
+ }
+ }
+
+
+ if (useUnpackBuffer) {
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glDeleteBuffersARB_func(1, unpack_pb);
+ }
+ if (usePackBuffer) {
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+ glDeleteBuffersARB_func(1, pack_pb);
+ }
+
+ glEnable(GL_POLYGON_STIPPLE);
+ glBegin(GL_POLYGON);
+ glVertex2f(0, 0);
+ glVertex2f(10, 0);
+ glVertex2f(10, 10);
+ glVertex2f(0, 10);
+ glEnd();
+
+ glDisable(GL_POLYGON_STIPPLE);
+
+ // Check the result
+ GLfloat buf[windowSize * windowSize * 3];
+
+ glReadPixels(0, 0, windowSize, windowSize, GL_RGB, GL_FLOAT, buf);
+
+ for (j = 0; j < windowSize; j++) {
+ for (i = 0; i < windowSize; i++) {
+ const GLfloat *exp;
+ if (i & 1)
+ exp = black;
+ else
+ exp = white;
+ if (i < 10 && j < 10) {
+ if (equalColors(&buf[(j * windowSize + i) * 3], exp) !=
+ true) {
+ REPORT_FAILURE("glGetPolygonStipple failed");
+ printf("(%d, %d) = [%f, %f, %f], ", i, j,
+ buf[(j * windowSize + i) * 3],
+ buf[(j * windowSize + i) * 3 + 1],
+ buf[(j * windowSize + i) * 3 + 2]);
+ printf("should be [1.0, 1.0, 1.0]\n");
+ return false;
+ }
+ }
+ else {
+ if (equalColors(&buf[(j * windowSize + i) * 3], black) !=
+ true) {
+ REPORT_FAILURE("glGetPolygonStipple failed");
+ printf("(%d, %d) = [%f, %f, %f], ", i, j,
+ buf[(j * windowSize + i) * 3],
+ buf[(j * windowSize + i) * 3 + 1],
+ buf[(j * windowSize + i) * 3 + 2]);
+ printf("should be [0.0, 0.0, 0.0]\n");
+ return false;
+ }
+
+ }
+ }
+ }
+
+ }
+ }
+
+ return true;
+}
+
+
+bool PBOTest::testErrorHandling(void)
+{
+ GLuint fbs[1];
+
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER_ARB, 0);
+
+ if (usePBO) {
+ /* test that glDrawPixels from too small of buffer raises error */
+ glGenBuffersARB_func(1, fbs);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER, fbs[0]);
+ glBufferDataARB_func(GL_PIXEL_UNPACK_BUFFER_ARB, 32 * 32 * 4, NULL,
+ GL_STREAM_DRAW);
+ glDrawPixels(32, 32 + 1, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+ if (glGetError() != GL_INVALID_OPERATION)
+ return false;
+
+ glDeleteBuffersARB_func(1, fbs);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER, 0);
+
+ /* test that glReadPixels into too small of buffer raises error */
+ glGenBuffersARB_func(1, fbs);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER, fbs[0]);
+ glBufferDataARB_func(GL_PIXEL_PACK_BUFFER_ARB, 32 * 32 * 4, NULL,
+ GL_STREAM_DRAW);
+ glReadPixels(0, 0, 32, 32 + 1, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+ if (glGetError() != GL_INVALID_OPERATION)
+ return false;
+
+ glDeleteBuffersARB_func(1, fbs);
+ glBindBufferARB_func(GL_PIXEL_PACK_BUFFER, 0);
+ }
+ return true;
+}
+
+bool PBOTest::testFunctionality(MultiTestResult & r)
+{
+ static SubTestFunc
+ funcs[] = {
+ &GLEAN::PBOTest::testSanity,
+ &GLEAN::PBOTest::testBitmap,
+ &GLEAN::PBOTest::testDrawPixels,
+ &GLEAN::PBOTest::testPixelMap,
+ &GLEAN::PBOTest::testTexImage,
+ &GLEAN::PBOTest::testTexSubImage,
+ &GLEAN::PBOTest::testPolygonStip,
+ &GLEAN::PBOTest::testErrorHandling,
+ NULL
+ };
+
+ for (int i = 0; funcs[i]; i++)
+ if ((this->*funcs[i]) ())
+ r.numPassed++;
+ else
+ r.numFailed++;
+ return true;
+}
+
+enum {
+ BLACK,
+ RED,
+ GREEN,
+ BLUE,
+WHITE };
+
+GLfloat colors1[][4] = {
+ {0.0, 0.0, 0.0, 0.0},
+ {1.0, 0.0, 0.0, 1.0},
+ {0.0, 1.0, 0.0, 1.0},
+ {0.0, 0.0, 1.0, 1.0},
+ {1.0, 1.0, 1.0, 1.0}
+};
+
+#define TEXSIZE1 64
+bool PBOTest::testPerformance(MultiTestResult & r)
+{
+ GLuint pbs[1];
+ GLuint textures[1];
+ GLubyte data[TEXSIZE1 * TEXSIZE1 * 4];
+ int mode;
+ int i, j;
+ Timer t;
+ double t0, t1, perf[2];
+ GLubyte *pboMem = NULL;
+
+ (void) r;
+
+ for (mode = 0; mode < usePBO + 1; mode++) {
+ t0 = t.getClock();
+
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ if (mode) {
+ glGenBuffersARB_func(1, pbs);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER, pbs[0]);
+ glBufferDataARB_func(GL_PIXEL_UNPACK_BUFFER,
+ TEXSIZE1 * TEXSIZE1 * 4 * sizeof(GLubyte), NULL,
+ GL_STREAM_DRAW);
+ }
+ glGenTextures(1, textures);
+ glBindTexture(GL_TEXTURE_2D, textures[0]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXSIZE1,
+ TEXSIZE1, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ for (i = 0; i < 1024; i++) {
+ if (mode) {
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER, pbs[0]);
+ pboMem =
+ (GLubyte *) glMapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB,
+ GL_WRITE_ONLY);
+ }
+ else {
+ pboMem = data;
+ }
+
+ for (j = 0; j < TEXSIZE1 * TEXSIZE1; j++) {
+ pboMem[4 * j] = 255;
+ pboMem[4 * j + 1] = 255;
+ pboMem[4 * j + 2] = 0;
+ pboMem[4 * j + 3] = 0;
+ }
+
+ if (mode) {
+ glUnmapBufferARB_func(GL_PIXEL_UNPACK_BUFFER_ARB);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE1,
+ TEXSIZE1, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+ glBindBufferARB_func(GL_PIXEL_UNPACK_BUFFER, 0);
+ }
+ else {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE1,
+ TEXSIZE1, GL_BGRA, GL_UNSIGNED_BYTE, data);
+ }
+
+
+ // Actually apply the texture
+ glEnable(GL_TEXTURE_2D);
+ glColor4fv(colors1[WHITE]);
+
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0.0, 0.0);
+ glVertex2f(0, 0);
+ glTexCoord2f(1.0, 0.0);
+ glVertex2f(1, 0);
+ glTexCoord2f(1.0, 1.0);
+ glVertex2f(1, 1);
+ glTexCoord2f(0.0, 1.0);
+ glVertex2f(0, 1);
+ glEnd();
+ glFlush();
+ glDisable(GL_TEXTURE_2D);
+ }
+ t1 = t.getClock();
+ glDeleteTextures(1, textures);
+ if (mode)
+ glDeleteBuffersARB_func(1, pbs);
+
+ perf[mode] = (double) TEXSIZE1 * TEXSIZE1 * 3 * sizeof(GLfloat) / 1024 / (t1 - t0);
+
+ }
+
+ if (perf[1] < perf[0] && usePBO) {
+ env->log << name << ": NOTE "
+ << "perf[0] = " << perf[0] <<
+ " MB/s, which is in normal mode" << endl;
+ env->log << name << ": NOTE " << "perf[1] = " <<
+ perf[1] << " MB/s, which is using PBO" << endl;
+ }
+
+ return true;
+}
+
+
+
+// Run all the subtests, incrementing numPassed, numFailed
+void
+PBOTest::runSubTests(MultiTestResult & r)
+{
+ static TestFunc funcs[] = {
+ &GLEAN::PBOTest::testFunctionality,
+ &GLEAN::PBOTest::testPerformance,
+ NULL
+ };
+
+ for (int i = 0; funcs[i]; i++)
+ if ((this->*funcs[i]) (r))
+ r.numPassed++;
+ else
+ r.numFailed++;
+}
+
+
+void
+PBOTest::runOne(MultiTestResult & r, Window & w)
+{
+ (void) w;
+
+ if (!setup()) {
+ r.pass = false;
+ return;
+ }
+
+ runSubTests(r);
+
+ r.pass = (r.numFailed == 0);
+}
+
+
+// The test object itself:
+PBOTest pboTest("pbo", "window, rgb, z", "", // no extension filter
+ "pbo test: Test OpenGL Extension GL_ARB_pixel_buffer_object\n");
+
+
+
+} // namespace GLEAN
diff --git a/tests/glean/tpbo.h b/tests/glean/tpbo.h
index 46321bf6a..cda1a49ed 100644
--- a/tests/glean/tpbo.h
+++ b/tests/glean/tpbo.h
@@ -1,86 +1,86 @@
-// BEGIN_COPYRIGHT -*- glean -*-
-//
-// Copyrigth (C) 2007 Intel Corporation
-// Copyright (C) 1999 Allen Akin All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or
-// sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the
-// Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
-// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
-// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
-// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-// DEALINGS IN THE SOFTWARE.
-//
-// END_COPYRIGHT
-//
-// Authors:
-// Shuang He <shuang.he@intel.com>
-//
-// tfbo.h: Test OpenGL Extension GL_ARB_pixel_buffer_objec
-
-#ifndef __pfbo_h__
-#define __pfbo_h__
-
-#include "tmultitest.h"
-
-namespace GLEAN {
-
-#define windowSize 100
-
-
-class PBOTest: public MultiTest
-{
-public:
- PBOTest(const char* testName, const char* filter,
- const char *extensions, const char* description):
- MultiTest(testName, filter, extensions, description)
- {
- }
-
- virtual void runOne(MultiTestResult &r, Window &w);
-
-private:
- typedef bool (PBOTest::*TestFunc)(MultiTestResult &r);
- typedef bool (PBOTest::*SubTestFunc)(void);
-
- GLfloat tolerance[5];
-
- bool testFunctionality(MultiTestResult &r);
- bool testPerformance(MultiTestResult &r);
- bool testSanity(void);
- bool testErrorHandling(void);
- bool testDrawPixels(void);
- bool testPixelMap(void);
- bool testBitmap(void);
- bool testTexImage(void);
- bool testTexSubImage(void);
- bool testPolygonStip(void);
-
- void runSubTests(MultiTestResult &r);
-
- bool setup(void);
- bool checkResult(const GLfloat exp[4], const int depth, const int stencil) const;
- bool equalColors(const GLfloat a[4], const GLfloat b[4]) const;
- bool equalColors1(const GLubyte a[4], const GLubyte b[4]) const;
-
- void reportFailure(const char *msg, int line) const;
- void reportFailure(const char *msg, GLenum target, int line) const;
-};
-
-} // namespace GLEAN
-
-#endif // __tpbo_h__
+// BEGIN_COPYRIGHT -*- glean -*-
+//
+// Copyrigth (C) 2007 Intel Corporation
+// Copyright (C) 1999 Allen Akin All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the
+// Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// END_COPYRIGHT
+//
+// Authors:
+// Shuang He <shuang.he@intel.com>
+//
+// tfbo.h: Test OpenGL Extension GL_ARB_pixel_buffer_objec
+
+#ifndef __pfbo_h__
+#define __pfbo_h__
+
+#include "tmultitest.h"
+
+namespace GLEAN {
+
+#define windowSize 100
+
+
+class PBOTest: public MultiTest
+{
+public:
+ PBOTest(const char* testName, const char* filter,
+ const char *extensions, const char* description):
+ MultiTest(testName, filter, extensions, description)
+ {
+ }
+
+ virtual void runOne(MultiTestResult &r, Window &w);
+
+private:
+ typedef bool (PBOTest::*TestFunc)(MultiTestResult &r);
+ typedef bool (PBOTest::*SubTestFunc)(void);
+
+ GLfloat tolerance[5];
+
+ bool testFunctionality(MultiTestResult &r);
+ bool testPerformance(MultiTestResult &r);
+ bool testSanity(void);
+ bool testErrorHandling(void);
+ bool testDrawPixels(void);
+ bool testPixelMap(void);
+ bool testBitmap(void);
+ bool testTexImage(void);
+ bool testTexSubImage(void);
+ bool testPolygonStip(void);
+
+ void runSubTests(MultiTestResult &r);
+
+ bool setup(void);
+ bool checkResult(const GLfloat exp[4], const int depth, const int stencil) const;
+ bool equalColors(const GLfloat a[4], const GLfloat b[4]) const;
+ bool equalColors1(const GLubyte a[4], const GLubyte b[4]) const;
+
+ void reportFailure(const char *msg, int line) const;
+ void reportFailure(const char *msg, GLenum target, int line) const;
+};
+
+} // namespace GLEAN
+
+#endif // __tpbo_h__
diff --git a/tests/glean/tpointsprite.cpp b/tests/glean/tpointsprite.cpp
index 280984c29..8cb25740f 100644
--- a/tests/glean/tpointsprite.cpp
+++ b/tests/glean/tpointsprite.cpp
@@ -50,6 +50,8 @@
namespace GLEAN {
+static PFNGLPOINTPARAMETERFPROC glPointParameterf_func = NULL;
+
//background color
static GLfloat bgColor[4] = {0.0, 0.0, 0.0, 0.0};
@@ -337,6 +339,9 @@ PointSpriteTest::runOne(MultiTestResult &r, Window &w)
(void) w;
+ glPointParameterf_func = (PFNGLPOINTPARAMETERFPROC) GLUtils::getProcAddress("glPointParameterf");
+ assert(glPointParameterf_func);
+
CheckDefaultState(r);
glDrawBuffer(GL_FRONT);
@@ -371,9 +376,9 @@ PointSpriteTest::runOne(MultiTestResult &r, Window &w)
{
if (coordOrigin)
- glPointParameterf(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT);
+ glPointParameterf_func(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT);
else
- glPointParameterf(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
+ glPointParameterf_func(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
pointSize = 1.85;
for (; pointSize <= maxPointSize; pointSize += 2.0)
diff --git a/tests/glean/treadpix.cpp b/tests/glean/treadpix.cpp
index 3c146d425..c983f3122 100644
--- a/tests/glean/treadpix.cpp
+++ b/tests/glean/treadpix.cpp
@@ -382,7 +382,7 @@ ReadPixSanityTest::compareOne(ReadPixSanityResult& oldR, ReadPixSanityResult& ne
} // ReadPixSanityTest::compareOne
void
-ReadPixSanityTest::summarize(char* label, bool oldPass, bool newPass) {
+ReadPixSanityTest::summarize(const char* label, bool oldPass, bool newPass) {
if (oldPass == newPass) {
if (env->options.verbosity)
env->log << "\t"
@@ -497,6 +497,11 @@ readPixSanityTest("readPixSanity", "1",
namespace {
+// Mac OS header file AssertMacros.h defines check as a macro.
+#ifdef check
+#undef check
+#endif
+
template<class T>
void
check(GLEAN::ExactRGBAResult::Flavor& r, GLEAN::DrawingSurfaceConfig& config,
diff --git a/tests/glean/treadpix.h b/tests/glean/treadpix.h
index 8dc8d9e01..6f65b2a52 100644
--- a/tests/glean/treadpix.h
+++ b/tests/glean/treadpix.h
@@ -168,7 +168,7 @@ public:
void checkDepth(ReadPixSanityResult& r, Window& w);
void checkStencil(ReadPixSanityResult& r, Window& w);
void checkIndex(ReadPixSanityResult& r, Window& w);
- void summarize(char* label, bool oldPass, bool newPass);
+ void summarize(const char* label, bool oldPass, bool newPass);
}; // class ReadPixSanityTest
extern ReadPixSanityTest readPixSanityTest;
diff --git a/tests/glean/tshaderapi.cpp b/tests/glean/tshaderapi.cpp
index 643bb6214..662428c06 100644
--- a/tests/glean/tshaderapi.cpp
+++ b/tests/glean/tshaderapi.cpp
@@ -193,7 +193,7 @@ ShaderAPITest::assert_error_test(const char *file, int line, GLenum expect)
void
-ShaderAPITest::check_status(GLuint id, GLenum pname, void (*query)(GLuint, GLenum, GLint *))
+ShaderAPITest::check_status(GLuint id, GLenum pname, void (APIENTRY *query)(GLuint, GLenum, GLint *))
{
GLint status;
diff --git a/tests/glean/tshaderapi.h b/tests/glean/tshaderapi.h
index e1fc9c1db..37254ecbb 100644
--- a/tests/glean/tshaderapi.h
+++ b/tests/glean/tshaderapi.h
@@ -65,7 +65,7 @@ private:
void assert_no_error_test(const char *file, int line);
void assert_error_test(const char *file, int line, GLenum expect);
- void check_status(GLuint id, GLenum pname, void (*query)(GLuint, GLenum, GLint *));
+ void check_status(GLuint id, GLenum pname, void (APIENTRY *query)(GLuint, GLenum, GLint *));
void check_compile_status(GLuint id);
void check_link_status(GLuint id);
diff --git a/tests/glean/ttexcombine.cpp b/tests/glean/ttexcombine.cpp
index ed2ed33b4..be9b42112 100644
--- a/tests/glean/ttexcombine.cpp
+++ b/tests/glean/ttexcombine.cpp
@@ -878,7 +878,7 @@ TexCombineTest::CountTestCombinations(const test_param testParams[]) const {
}
numTests *= values;
}
- return numTests;
+ return numTests / testStride;
}
@@ -1116,7 +1116,7 @@ TexCombineTest::RunSingleTextureTest(glmachine &machine,
const int numTests = CountTestCombinations(testParams);
//printf("Testing %d combinations\n", numTests);
- for (int test = 0; test < numTests; test++) {
+ for (int test = 0; test < numTests; test += testStride) {
// 0. Setup state
ResetMachine(machine);
SetupTestEnv(machine, 0, test, testParams);
@@ -1194,7 +1194,7 @@ TexCombineTest::CountMultiTextureTestCombinations(const glmachine &machine) cons
for (int i = 0; i < numUnits; i++)
numTests *= (haveDot3 ? 7 : 5);
- return numTests;
+ return numTests / testStride;
}
@@ -1224,7 +1224,7 @@ TexCombineTest::RunMultiTextureTest(glmachine &machine, BasicResult &r,
//printf("Testing %d multitexture combinations\n", numTests);
SetupColors(machine);
- for (int testNum = 0; testNum < numTests; testNum++) {
+ for (int testNum = 0; testNum < numTests; testNum += testStride) {
// 0. Set up texture units
ResetMachine(machine);
int divisor = 1;
@@ -1495,6 +1495,12 @@ TexCombineTest::runOne(BasicResult& r, Window& w) {
ResetMachine(Machine);
Machine.NumTexUnits = 1;
+ // If quick mode, run fewer tests
+ if (env->options.quick)
+ testStride = 11; // a prime number
+ else
+ testStride = 1;
+
// Do single texture unit tests first.
bool passed = RunSingleTextureTest(Machine, ReplaceParams, r, w);
if (passed)
diff --git a/tests/glean/ttexcombine.h b/tests/glean/ttexcombine.h
index 59b3b33b9..fd840e183 100644
--- a/tests/glean/ttexcombine.h
+++ b/tests/glean/ttexcombine.h
@@ -104,6 +104,7 @@ class TexCombineTest: public BasicTest {
bool haveCrossbar;
GLfloat mTolerance[4];
GLuint mTextures[MAX_TEX_UNITS];
+ int testStride;
void ResetMachine(glmachine &machine);
void ComputeTexCombine(const glmachine &machine, int texUnit,
diff --git a/tests/glean/ttexenv.cpp b/tests/glean/ttexenv.cpp
index 6a8f8d886..e8fc4e86c 100644
--- a/tests/glean/ttexenv.cpp
+++ b/tests/glean/ttexenv.cpp
@@ -499,8 +499,10 @@ TexEnvTest::MatrixTest(GLenum envMode, GLenum texFormat,
}
glEnd();
- GLfloat image[256][256][4];
- glReadPixels(0, 0, 256, 256, GL_RGBA, GL_FLOAT, image);
+ const GLsizei width = 256;
+ const GLsizei height = 256;
+ GLfloat *image = new GLfloat[width*height*4];
+ glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, image);
w.swap(); // lets us watch the progress
@@ -517,7 +519,7 @@ TexEnvTest::MatrixTest(GLenum envMode, GLenum texFormat,
// fetch actual pixel
int x = col * 3 + 1;
int y = row * 3 + 1;
- const GLfloat *actual = image[y][x];
+ const GLfloat *actual = image + y*width*4 + x*4;
// compare
if (!TestColor(expected, actual)) {
@@ -559,10 +561,12 @@ TexEnvTest::MatrixTest(GLenum envMode, GLenum texFormat,
<< actual[1] << ", "
<< actual[2] << ", "
<< actual[3] << ")\n";
+ delete[] image;
return false;
}
}
}
+ delete[] image;
return true;
}
diff --git a/tests/glean/ttexgen.cpp b/tests/glean/ttexgen.cpp
index 55dd7fae8..e81c2a5b2 100644
--- a/tests/glean/ttexgen.cpp
+++ b/tests/glean/ttexgen.cpp
@@ -339,16 +339,19 @@ TexgenTest::logOne(BasicResult& r) {
void
TexgenTest::renderSphere(int retainedMode, GeomRenderer& sphereRenderer)
{
+ bool result;
if (retainedMode)
{
GLint displayList;
- assert(sphereRenderer.generateDisplayList(GL_TRIANGLES, displayList));
+ result = sphereRenderer.generateDisplayList(GL_TRIANGLES, displayList);
+ assert(result);
glCallList(displayList);
glDeleteLists(displayList, 1);
}
else
{
- assert(sphereRenderer.renderPrimitives(GL_TRIANGLES));
+ result = sphereRenderer.renderPrimitives(GL_TRIANGLES);
+ assert(result);
}
} // TexgenTest::renderSphere
diff --git a/tests/glean/ttexswizzle.cpp b/tests/glean/ttexswizzle.cpp
index 6bd1304a9..ca56d9334 100644
--- a/tests/glean/ttexswizzle.cpp
+++ b/tests/glean/ttexswizzle.cpp
@@ -45,20 +45,11 @@
#include "image.h"
-// In case glext.h isn't new enough:
-#ifndef GL_EXT_texture_swizzle
-
-#define GL_TEXTURE_SWIZZLE_R_EXT 0x8E42
-#define GL_TEXTURE_SWIZZLE_G_EXT 0x8E43
-#define GL_TEXTURE_SWIZZLE_B_EXT 0x8E44
-#define GL_TEXTURE_SWIZZLE_A_EXT 0x8E45
-#define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46
-
-#endif
-
-
namespace GLEAN {
+static PFNGLPROGRAMSTRINGARBPROC glProgramStringARB_func = NULL;
+static PFNGLBINDPROGRAMARBPROC glBindProgramARB_func = NULL;
+static PFNGLGENPROGRAMSARBPROC glGenProgramsARB_func = NULL;
static const int TexSize = 16;
@@ -335,9 +326,9 @@ TexSwizzleTest::TestSwizzlesWithProgram(void)
"END\n";
GLuint prog;
- glGenProgramsARB(1, &prog);
- glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog);
- glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+ glGenProgramsARB_func(1, &prog);
+ glBindProgramARB_func(GL_FRAGMENT_PROGRAM_ARB, prog);
+ glProgramStringARB_func(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(text), (const GLubyte *) text);
assert(glGetError() == GL_NO_ERROR);
@@ -355,6 +346,13 @@ TexSwizzleTest::TestSwizzlesWithProgram(void)
void
TexSwizzleTest::Setup(void)
{
+ glProgramStringARB_func = (PFNGLPROGRAMSTRINGARBPROC) GLUtils::getProcAddress("glProgramStringARB");
+ assert(glProgramStringARB_func);
+ glBindProgramARB_func = (PFNGLBINDPROGRAMARBPROC) GLUtils::getProcAddress("glBindProgramARB");
+ assert(glBindProgramARB_func);
+ glGenProgramsARB_func = (PFNGLGENPROGRAMSARBPROC) GLUtils::getProcAddress("glGenProgramsARB");
+ assert(glGenProgramsARB_func);
+
// setup transformation
glViewport(0, 0, windowSize, windowSize);
glMatrixMode(GL_MODELVIEW);
diff --git a/tests/glean/ttexture_srgb.cpp b/tests/glean/ttexture_srgb.cpp
index 4fa5b9d1a..e27081b2e 100644
--- a/tests/glean/ttexture_srgb.cpp
+++ b/tests/glean/ttexture_srgb.cpp
@@ -37,8 +37,6 @@
#include "rand.h"
-#ifdef GL_EXT_texture_sRGB
-
namespace GLEAN {
@@ -371,5 +369,3 @@ TextureSRGBTest srgbTest("texture_srgb", "window, rgb",
} // namespace GLEAN
-
-#endif // GL_EXT_texture_sRGB
diff --git a/tests/glean/ttexunits.cpp b/tests/glean/ttexunits.cpp
index e84c94e1d..e06519afb 100644
--- a/tests/glean/ttexunits.cpp
+++ b/tests/glean/ttexunits.cpp
@@ -40,6 +40,9 @@
namespace GLEAN {
+static PFNGLACTIVETEXTUREPROC glActiveTexture_func = NULL;
+static PFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture_func = NULL;
+
void
TexUnitsTest::reportFailure(const char *msg) const
@@ -53,7 +56,11 @@ void
TexUnitsTest::reportFailure(const char *msg, GLint unit) const
{
char s[100];
+#if defined(_MSC_VER)
+ _snprintf(s, sizeof(s), msg, unit);
+#else
snprintf(s, sizeof(s), msg, unit);
+#endif
env->log << "FAILURE:\n";
env->log << "\t" << s << "\n";
}
@@ -74,6 +81,11 @@ TexUnitsTest::setup(void)
glGetIntegerv(GL_MAX_TEXTURE_COORDS, &maxCoordUnits);
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxUnits);
+ glActiveTexture_func = (PFNGLACTIVETEXTUREPROC) GLUtils::getProcAddress("glActiveTexture");
+ assert(glActiveTexture_func);
+ glClientActiveTexture_func = (PFNGLCLIENTACTIVETEXTUREPROC) GLUtils::getProcAddress("glClientActiveTexture");
+ assert(glClientActiveTexture_func);
+
return true;
}
@@ -110,7 +122,7 @@ TexUnitsTest::testActiveTexture(void)
// test glActiveTexture()
for (i = 0; i < maxUnits; i++) {
- glActiveTexture(GL_TEXTURE0 + i);
+ glActiveTexture_func(GL_TEXTURE0 + i);
if (glGetError()) {
reportFailure("glActiveTexture(GL_TEXTURE%d) failed", i);
return false;
@@ -125,7 +137,7 @@ TexUnitsTest::testActiveTexture(void)
}
// this should fail:
- glActiveTexture(GL_TEXTURE0 + maxUnits);
+ glActiveTexture_func(GL_TEXTURE0 + maxUnits);
if (glGetError() != GL_INVALID_ENUM) {
reportFailure("glActiveTexture(GL_TEXTURE%d) failed to generate an error",
maxUnits);
@@ -135,7 +147,7 @@ TexUnitsTest::testActiveTexture(void)
// test glClientActiveTexture()
for (i = 0; i < maxCoordUnits; i++) {
- glClientActiveTexture(GL_TEXTURE0 + i);
+ glClientActiveTexture_func(GL_TEXTURE0 + i);
if (glGetError()) {
reportFailure("glClientActiveTexture(GL_TEXTURE%d) failed", i);
return false;
@@ -150,7 +162,7 @@ TexUnitsTest::testActiveTexture(void)
}
// this should fail:
- glClientActiveTexture(GL_TEXTURE0 + maxUnits);
+ glClientActiveTexture_func(GL_TEXTURE0 + maxUnits);
if (glGetError() != GL_INVALID_ENUM) {
reportFailure("glClientActiveTexture(GL_TEXTURE%d) failed to generate an error", maxUnits);
return false;
@@ -165,12 +177,12 @@ TexUnitsTest::testTextureMatrices(void)
{
GLint i;
- glActiveTexture(GL_TEXTURE0);
+ glActiveTexture_func(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
// set texture matrices
for (i = 0; i < maxCoordUnits; i++) {
- glActiveTexture(GL_TEXTURE0 + i);
+ glActiveTexture_func(GL_TEXTURE0 + i);
// generate matrix
GLfloat m[16];
@@ -183,7 +195,7 @@ TexUnitsTest::testTextureMatrices(void)
// query texture matrices
for (i = 0; i < maxCoordUnits; i++) {
- glActiveTexture(GL_TEXTURE0 + i);
+ glActiveTexture_func(GL_TEXTURE0 + i);
// get matrix and check it
GLfloat m[16];
@@ -217,12 +229,12 @@ TexUnitsTest::testTextureCoordGen(void)
{
GLint i;
- glActiveTexture(GL_TEXTURE0);
+ glActiveTexture_func(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
// test texgen enable/disable
for (i = 0; i < maxUnits; i++) {
- glActiveTexture(GL_TEXTURE0 + i);
+ glActiveTexture_func(GL_TEXTURE0 + i);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
@@ -258,7 +270,7 @@ TexUnitsTest::testTexcoordArrays(void)
GLint i;
for (i = 0; i < maxCoordUnits; i++) {
- glClientActiveTexture(GL_TEXTURE0 + i);
+ glClientActiveTexture_func(GL_TEXTURE0 + i);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (glGetError()) {
diff --git a/tests/glean/tvertarraybgra.cpp b/tests/glean/tvertarraybgra.cpp
index 737af0c44..f13b461ee 100644
--- a/tests/glean/tvertarraybgra.cpp
+++ b/tests/glean/tvertarraybgra.cpp
@@ -63,6 +63,11 @@ VertArrayBGRATest::reportError(const char *msg)
bool
VertArrayBGRATest::testAPI(void)
{
+ // Get glSecondaryColorPointer() functon
+ PFNGLSECONDARYCOLORPOINTERPROC SecondaryColorPointer = NULL;
+ SecondaryColorPointer = (PFNGLSECONDARYCOLORPOINTERPROC)
+ GLUtils::getProcAddress("glSecondaryColorPointer");
+
// Get glVertexAttrib() function
PFNGLVERTEXATTRIBPOINTERARBPROC VertexAttribPointer = NULL;
const char *version = (const char *) glGetString(GL_VERSION);
@@ -84,10 +89,12 @@ VertArrayBGRATest::testAPI(void)
return false;
}
- glSecondaryColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, 0, array);
- if (glGetError()) {
- reportError("glSecondaryColorPointer(size=GL_BGRA) generated an error.");
- return false;
+ if (SecondaryColorPointer) {
+ SecondaryColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, 0, array);
+ if (glGetError()) {
+ reportError("glSecondaryColorPointer(size=GL_BGRA) generated an error.");
+ return false;
+ }
}
if (VertexAttribPointer) {
diff --git a/tests/glean/tvertattrib.cpp b/tests/glean/tvertattrib.cpp
index 6dadf9046..9b87cd995 100644
--- a/tests/glean/tvertattrib.cpp
+++ b/tests/glean/tvertattrib.cpp
@@ -79,7 +79,7 @@ namespace GLEAN {
#define NUM_2_0_ATTRIB_FUNCS 36
static const char *
-AttribFuncNames[NUM_NV_ATTRIB_FUNCS + NUM_ARB_ATTRIB_FUNCS + NUM_2_0_ATTRIB_FUNCS] = {
+AttribFuncNames[] = {
"glVertexAttrib1fNV",
"glVertexAttrib2fNV",
"glVertexAttrib3fNV",
@@ -168,7 +168,7 @@ AttribFuncNames[NUM_NV_ATTRIB_FUNCS + NUM_ARB_ATTRIB_FUNCS + NUM_2_0_ATTRIB_FUNC
"glVertexAttrib2sv",
"glVertexAttrib3sv",
"glVertexAttrib4sv",
- "glVertexAttrib4Nsv"
+ "glVertexAttrib4Nsv",
"glVertexAttrib4Nub",
"glVertexAttrib4Nubv",
"glVertexAttrib4ubv",
@@ -1546,7 +1546,7 @@ void
VertAttribTest::runOne(VertAttribResult& r, Window&)
{
- assert(sizeof(AttribFuncNames) / sizeof(char *) ==
+ assert(sizeof(AttribFuncNames) / sizeof(AttribFuncNames[0]) ==
NUM_NV_ATTRIB_FUNCS + NUM_ARB_ATTRIB_FUNCS + NUM_2_0_ATTRIB_FUNCS);
r.pass = true;
diff --git a/tests/glean/tvertattrib.h b/tests/glean/tvertattrib.h
index 3729dc009..1eb4b6ebb 100644
--- a/tests/glean/tvertattrib.h
+++ b/tests/glean/tvertattrib.h
@@ -32,6 +32,9 @@
#include "tbase.h"
+// Avoid name collision on Windows
+#undef OPTIONAL
+
namespace GLEAN {
diff --git a/tests/glean/winsys.cpp b/tests/glean/winsys.cpp
index e91b4eea5..866bb813a 100644
--- a/tests/glean/winsys.cpp
+++ b/tests/glean/winsys.cpp
@@ -31,8 +31,6 @@
// winsys.cpp: implementation of window-system services class
-using namespace std;
-
#include <iostream>
#include "options.h"
#include "winsys.h"
@@ -41,6 +39,8 @@ using namespace std;
#include "dsurf.h"
#include "rc.h"
+using namespace std;
+
namespace GLEAN {