1 // BEGIN_COPYRIGHT -*- glean -*-
3 // Copyright (C) 2008 VMWare, Inc. All Rights Reserved.
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
29 // Test texture unit things
30 // We're generally just testing API-related things, not rendering.
31 // Brian Paul 31 Dec 2008
33 #define GL_GLEXT_PROTOTYPES
38 #include "ttexunits.h"
43 static PFNGLACTIVETEXTUREPROC glActiveTexture_func
= NULL
;
44 static PFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture_func
= NULL
;
48 TexUnitsTest::reportFailure(const char *msg
) const
50 env
->log
<< "FAILURE:\n";
51 env
->log
<< "\t" << msg
<< "\n";
56 TexUnitsTest::reportFailure(const char *msg
, GLint unit
) const
60 _snprintf(s
, sizeof(s
), msg
, unit
);
62 snprintf(s
, sizeof(s
), msg
, unit
);
64 env
->log
<< "FAILURE:\n";
65 env
->log
<< "\t" << s
<< "\n";
70 TexUnitsTest::setup(void)
72 // check that we have OpenGL 2.x or 3.x
73 const char *verString
= (const char *) glGetString(GL_VERSION
);
75 if (verString
[0] != '2' && verString
[0] != '3') {
76 env
->log
<< "OpenGL 2.x or 3.x not supported\n";
80 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
, &maxCombinedUnits
);
81 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS
, &maxImageUnits
);
82 glGetIntegerv(GL_MAX_TEXTURE_COORDS
, &maxCoordUnits
);
83 glGetIntegerv(GL_MAX_TEXTURE_UNITS
, &maxUnits
);
85 glActiveTexture_func
= (PFNGLACTIVETEXTUREPROC
) GLUtils::getProcAddress("glActiveTexture");
86 assert(glActiveTexture_func
);
87 glClientActiveTexture_func
= (PFNGLCLIENTACTIVETEXTUREPROC
) GLUtils::getProcAddress("glClientActiveTexture");
88 assert(glClientActiveTexture_func
);
95 TexUnitsTest::testLimits(void)
97 if (maxImageUnits
< maxUnits
) {
98 reportFailure("GL_MAX_TEXTURE_IMAGE_UNITS < GL_MAX_TEXTURE_UNITS");
101 if (maxCoordUnits
< maxUnits
) {
102 reportFailure("GL_MAX_TEXTURE_COORD_UNITS < GL_MAX_TEXTURE_UNITS");
110 TexUnitsTest::testActiveTexture(void)
114 // clear any error state
118 // test glActiveTexture()
119 for (i
= 0; i
< maxCombinedUnits
; i
++) {
120 glActiveTexture_func(GL_TEXTURE0
+ i
);
122 reportFailure("glActiveTexture(GL_TEXTURE%d) failed", i
);
127 glGetIntegerv(GL_ACTIVE_TEXTURE
, &unit
);
128 if (unit
!= GL_TEXTURE0
+ i
|| glGetError()) {
129 reportFailure("glGetIntegerv(GL_ACTIVE_TEXTURE) failed");
135 glActiveTexture_func(GL_TEXTURE0
+ maxCombinedUnits
);
136 if (glGetError() != GL_INVALID_ENUM
) {
137 reportFailure("glActiveTexture(GL_TEXTURE%d) failed to generate an error",
143 // test glClientActiveTexture()
144 for (i
= 0; i
< maxCoordUnits
; i
++) {
145 glClientActiveTexture_func(GL_TEXTURE0
+ i
);
147 reportFailure("glClientActiveTexture(GL_TEXTURE%d) failed", i
);
152 glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE
, &unit
);
153 if (unit
!= GL_TEXTURE0
+ i
|| glGetError()) {
154 reportFailure("glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE) failed");
160 glClientActiveTexture_func(GL_TEXTURE0
+ maxCoordUnits
);
161 if (glGetError() != GL_INVALID_ENUM
) {
162 reportFailure("glClientActiveTexture(GL_TEXTURE%d) failed to generate an error", maxCoordUnits
);
171 TexUnitsTest::testTextureMatrices(void)
175 glActiveTexture_func(GL_TEXTURE0
);
176 glMatrixMode(GL_TEXTURE
);
178 // set texture matrices
179 for (i
= 0; i
< maxCoordUnits
; i
++) {
180 glActiveTexture_func(GL_TEXTURE0
+ i
);
184 for (int j
= 0; j
< 16; j
++) {
185 m
[j
] = float(i
* 100 + j
);
191 // query texture matrices
192 for (i
= 0; i
< maxCoordUnits
; i
++) {
193 glActiveTexture_func(GL_TEXTURE0
+ i
);
195 // get matrix and check it
197 memset(m
, 0, sizeof(m
));
198 glGetFloatv(GL_TEXTURE_MATRIX
, m
);
201 reportFailure("Query of texture matrix %d raised an error", i
);
205 for (int j
= 0; j
< 16; j
++) {
206 if (m
[j
] != float(i
* 100 + j
)) {
207 reportFailure("Query of texture matrix %d failed", i
);
214 reportFailure("GL error was generated while testing texture matrices");
223 TexUnitsTest::testTextureCoordGen(void)
227 glActiveTexture_func(GL_TEXTURE0
);
228 glMatrixMode(GL_TEXTURE
);
230 // test texgen enable/disable
231 for (i
= 0; i
< maxCombinedUnits
; i
++) {
232 glActiveTexture_func(GL_TEXTURE0
+ i
);
234 glEnable(GL_TEXTURE_GEN_S
);
235 glEnable(GL_TEXTURE_GEN_T
);
236 glEnable(GL_TEXTURE_GEN_R
);
237 glEnable(GL_TEXTURE_GEN_Q
);
238 if (i
< maxCoordUnits
) {
239 // should be no error
241 reportFailure("GL error was generated by enabling GL_TEXTURE_GEN_x, unit %d", i
);
244 glDisable(GL_TEXTURE_GEN_S
);
245 glDisable(GL_TEXTURE_GEN_T
);
246 glDisable(GL_TEXTURE_GEN_R
);
247 glDisable(GL_TEXTURE_GEN_Q
);
250 // should be an error
251 if (glGetError() != GL_INVALID_OPERATION
) {
252 reportFailure("GL error not generated by invalid enable of GL_TEXTURE_GEN_x, unit %d", i
);
263 TexUnitsTest::testTexcoordArrays(void)
267 for (i
= 0; i
< maxCoordUnits
; i
++) {
268 glClientActiveTexture_func(GL_TEXTURE0
+ i
);
270 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
272 reportFailure("GL error was generated by glEnableClientState for unit %d", i
);
275 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
284 TexUnitsTest::runOne(MultiTestResult
&r
, Window
&w
)
298 if (testActiveTexture())
303 if (testTextureMatrices())
308 if (testTextureCoordGen())
313 if (testTexcoordArrays())
318 r
.pass
= (r
.numFailed
== 0);
322 // The test object itself:
323 TexUnitsTest
texUnitTest("texUnits", "window, rgb",
324 "", // no extension filter
325 "texUnits: test texture units.\n"