summaryrefslogtreecommitdiff
path: root/tests/spec/ext_transform_feedback/ext_transform_feedback-api.c
blob: 72f8ffa791d9f025f5299756a0afa1d02b4faf9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*
 * Copyright © 2011 Intel Corporation
 *
 * 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 (including the next
 * paragraph) 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
 * THE AUTHORS OR COPYRIGHT HOLDERS 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.
 */

/** @file api.c
 *
 * Tests API support for EXT_Transform_feedback
 */

#include "piglit-util.h"

#define GL_GLEXT_PROTOTYPES
#include "glew.h"

#define BUF_WIDTH 15
#define BUF_HEIGHT 15
int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
int piglit_width = BUF_WIDTH;
int piglit_height = BUF_WIDTH;

/**
 * New <target> parameter for BindBuffer, BufferData,
 *     BufferSubData, MapBuffer, UnmapBuffer, GetBufferSubData,
 *     GetBufferPointerv, BindBufferRangeEXT, BindBufferOffsetEXT and
 *     BindBufferBaseEXT:
 *
 *     TRANSFORM_FEEDBACK_BUFFER_EXT
 */

static bool
test_new_tokens_feedback_buffer_ext()
{
    bool pass = true;
    GLuint buffer;
    void *data;
    GLenum valid_target = GL_TRANSFORM_FEEDBACK_BUFFER_EXT;
    GLenum valid_accesses[] = {
        GL_READ_ONLY,
        GL_WRITE_ONLY,
        GL_READ_WRITE,
    };
    GLenum error;
    int i;

    glGenBuffers(1, &buffer);
    /* BindBuffer test */
    glBindBuffer(valid_target, buffer);
    error = glGetError();
    if (error == GL_INVALID_ENUM) {
        pass = false;
    }

    /* Test MapBuffer/UnmapBuffer with all kind of accesses */
    for (i=0; i < sizeof(valid_accesses) / sizeof(valid_accesses[0]); i++) {
        data = glMapBuffer(buffer, valid_accesses[i]);
        /* TODO: check if data is set correctly - perhaps for operational test */
        error = glGetError();
        if (error == GL_INVALID_ENUM) {
            pass = false;
        }

        /* UnmapBuffer */
        glUnmapBuffer(buffer);
        error = glGetError();
        if (error == GL_INVALID_ENUM) {
            pass = false;
        }
    }

    /* Test GetBufferSubData */
    /*
    glGetBufferSubData(valid_target, 0, 0, data);
    error = glGetError();
    if (error == GL_INVALID_ENUM) {
        pass = false;
    }
    */

    /* TODO: test GetBufferPointerv */

    /* New function calls provided by the extension */
    /* TODO: test GetBindBufferRangeEXT */
    /* TODO: test GetBindBufferOffsetEXT */
    /* TODO: test GetBindBufferBaseEXT */

    glDeleteBuffers(1, &buffer);

    return pass;
}

/**
 * New <param> parameter for:
 *     GetIntegerIndexedvEXT and GetBooleanIndexedvEX:
 *
 *     TRANSFORM_FEEDBACK_BUFFER_START_EXT
 *     TRANSFORM_FEEDBACK_BUFFER_SIZE_EXT
 *
 */

static bool
test_new_tokens_feedback_buffer_start_size()
{
    bool pass = true;

    /* TODO: those functions will become available when the extension will be
     * implemented in mesa */

    return pass;
}

/**
 *
 * New <param> parameter for:
 *     GetIntegerIndexedvEXT and GetBooleanIndexedvEXT:
 * Also, new <pname> parameter for:
 *     GetBooleanv, GetDoublev, GetIntegerv, and GetFloatv:
 *
 *     TRANSFORM_FEEDBACK_BUFFER_BINDING_EXT
 *
 */

static bool
test_new_tokens_feedback_buffer_binding()
{
    bool pass = true;
    return pass;
}

/**
 * New <bufferMode> parameters for TransformFeedbackVaryingsEXT:
 *
 *     INTERLEAVED_ATTRIBS_EXT
 *     SEPARATE_ATTRIBS_EXT
 *
 *
 */

static bool
test_new_tokens_feedback_attribs()
{
    bool pass = true;
    return pass;
}

/**
 * New <cap> parameter for Enable, Disable, and IsEnabled:
 *     RASTERIZER_DISCARD_EXT
 *
 */

static bool
test_new_tokens_enable_disable()
{
    bool pass = true;
    GLenum error;
    GLenum capability = GL_RASTERIZER_DISCARD_EXT;

    /* glEnable */
    glEnable(capability);
    error = glGetError();
    if (error == GL_INVALID_ENUM) {
        pass = false;
    }
    /* glIsEnabled */
    glIsEnabled(capability);
    error = glGetError();
    if (error == GL_INVALID_ENUM) {
        pass = false;
    }
    /* glDisable */
    glDisable(capability);
    error = glGetError();
    if (error == GL_INVALID_ENUM) {
        pass = false;
    }

    return pass;
}

/**
 * New <pname> parameter for GetBooleanv, GetDoublev, GetIntegerv,
 *     and GetFloatv:
 *
 *     MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT
 *     MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT
 *     MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT
 *     RASTERIZER_DISCARD_EXT
 *
 *
 */

static bool
test_new_tokens_get_v()
{
    bool pass = true;
    GLenum valid_targets[] = {
        GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT,
        GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT,
        GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT,
        GL_RASTERIZER_DISCARD_EXT,
    };
    GLenum error;
    GLboolean pvalue_b;
    GLdouble pvalue_d;
    GLint pvalue_i;
    GLfloat pvalue_f;
    int i;

    for (i=0; i < sizeof(valid_targets) / sizeof(valid_targets[0]); i++) {
        /* Getting objects */
        glGetBooleanv(valid_targets[i], &pvalue_b);
        error = glGetError();
        if (error == GL_INVALID_ENUM) {
            pass = false;
        }
        glGetDoublev(valid_targets[i], &pvalue_d);
        error = glGetError();
        if (error == GL_INVALID_ENUM) {
            pass = false;
        }
        glGetIntegerv(valid_targets[i], &pvalue_i);
        error = glGetError();
        if (error == GL_INVALID_ENUM) {
            pass = false;
        }
        glGetFloatv(valid_targets[i], &pvalue_f);
        error = glGetError();
        if (error == GL_INVALID_ENUM) {
            pass = false;
        }
    }
    return pass;
}

/**
 * New <pname> parameter for GetProgramiv:
 *
 *     TRANSFORM_FEEDBACK_VARYINGS_EXT
 *     TRANSFORM_FEEDBACK_BUFFER_MODE_EXT
 *     TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH_EXT
 */
static bool
test_new_tokens_feedback_getprogramiv()
{
    bool pass = true;
    return pass;
}

/**
 * New <target> parameters for glBeginQuery / glEndQuery:
 *
 *    PRIMITIVES_GENERATED_EXT
 *    TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT
 */
static bool
test_begin_end_query()
{
    bool pass = true;
    const GLenum valid_targets[] = {
        GL_PRIMITIVES_GENERATED_EXT,
        GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT,
        };

    const GLenum invalid_targets[] = {
        0,
        -1,
        GL_SEPARATE_ATTRIBS_EXT,
    };
    GLuint query;
    int i;
    GLenum error;

    /* Generate query object */
    glGenQueries(1, &query);

    /**
     * Test for BeginQuery/EndQuery targets with valid id
     */
    for (i=0; i < sizeof(valid_targets) / sizeof(valid_targets[0]); i++) {
        glBeginQuery(valid_targets[i], query);
        error = glGetError();
        if (error == GL_INVALID_OPERATION) {
            pass = false;
        }
        glEndQuery(valid_targets[i]);
    }

    /**
     * Test for BeginQuery/EndQuery targets with id of 0
     * this test is expected to fail when:
     *  - there is any active query object out there
     *  - its id is not 0
     */
    for (i=0; i < sizeof(valid_targets) / sizeof(valid_targets[0]); i++) {
        /* 1st case */
        /* TODO: verify if query is not 0 */
        glBeginQuery(valid_targets[i], query);
        glBeginQuery(valid_targets[i], 0);
        error = glGetError();
        if (error != GL_INVALID_OPERATION) {
            pass = false;
        }
        glEndQuery(valid_targets[i]);

        /* 2nd case */
        glBeginQuery(valid_targets[i], 0);
        error = glGetError();
        if (error != GL_INVALID_OPERATION) {
            pass = false;
        }
        glEndQuery(valid_targets[i]);
    }

    /**
     * Test for BeginQuery/EndQuery with invalid targets
     * this test is expected to fail
     */
    for (i=0; i < sizeof(invalid_targets) / sizeof(invalid_targets[0]); i++) {
        glBeginQuery(invalid_targets[i], query);
        error = glGetError();
        if (error != GL_INVALID_OPERATION) {
            pass = false;
        }
        glEndQuery(invalid_targets[i]);
    }

    glDeleteQueries(1, &query);

	return pass;
}

static bool
test()
{
	bool pass, result=true;

    pass = test_new_tokens_feedback_buffer_ext();
    if (pass != true)
        result = false;
    pass = test_new_tokens_feedback_buffer_start_size();
    if (pass != true)
        result = false;
    pass = test_new_tokens_feedback_buffer_binding();
    if (pass != true)
        result = false;
    pass = test_new_tokens_feedback_attribs();
    if (pass != true)
        result = false;
    pass = test_new_tokens_enable_disable();
    if (pass != true)
        result = false;
    pass = test_new_tokens_get_v();
    if (pass != true)
        result = false;
    pass = test_new_tokens_feedback_getprogramiv();
    if (pass != true)
        result = false;
    pass = test_begin_end_query();
    if (pass != true)
        result = false;

	return result;
}

void piglit_init(int argc, char **argv)
{
	bool pass = true;

    glewInit();
	piglit_require_extension("GL_EXT_transform_feedback");

	pass = test();

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}

enum piglit_result
piglit_display(void)
{
	/* UNREACHED */
	return PIGLIT_FAIL;
}