summaryrefslogtreecommitdiffstats
path: root/src/VBox/GuestHost/OpenGL/util/calllists.c
blob: 6d973c660eefe924a99f2e226e248265d2e79812 (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
/* Copyright (c) 2001, Stanford University
 * All rights reserved
 *
 * See the file LICENSE.txt for information on redistributing this software.
 */

#include "chromium.h"
#include "cr_calllists.h"

#define EXPAND(typeEnum, typeCast, increment, value)     \
    case typeEnum:                                       \
      {                                                  \
        const typeCast *array = (const typeCast *) lists; \
        for (i = 0; i < (GLuint)n; i++, array increment) {        \
          (*callListFunc)(base + (GLuint) value); 	 \
        }                                                \
      }                                                  \
      break

#define EXPAND_WITH_DATA(typeEnum, typeCast, increment, value)     \
    case typeEnum:                                       	\
      {                                                  \
        const typeCast *array = (const typeCast *) lists; \
        for (i = 0; i < (GLuint)n; i++, array increment) {\
          (*callListFunc)(base + (GLuint) value, i, data); \
        }                                                 \
      }                                                    \
      break


int
crExpandCallLists(GLsizei n, GLenum type, const GLvoid *lists, 
    GLuint base, void (*callListFunc)(GLuint list))
{
	GLuint i;

	switch (type) {
		EXPAND(GL_BYTE, GLbyte,++,*array);
		EXPAND(GL_UNSIGNED_BYTE, GLubyte,++,*array);
		EXPAND(GL_SHORT, GLshort,++,*array);
		EXPAND(GL_UNSIGNED_SHORT, GLushort,++,*array);
		EXPAND(GL_INT, GLint,++,*array);
		EXPAND(GL_UNSIGNED_INT, GLuint,++,*array);
		EXPAND(GL_FLOAT, GLfloat,++,*array);

		EXPAND(GL_2_BYTES, GLubyte, +=2, 256*array[0] + array[1]);
		EXPAND(GL_3_BYTES, GLubyte, +=3, 256 * (256 * array[0] + array[1]) + array[2]);
		EXPAND(GL_4_BYTES, GLubyte, +=4, 256 * (256 * (256 * array[0] + array[1]) + array[2]) + array[3]);

		default:
			return GL_INVALID_ENUM;
	}

	return GL_NO_ERROR;
}

int
crExpandCallListsWithData(GLsizei n, GLenum type, const GLvoid *lists, 
    GLuint base, void (*callListFunc)(GLuint list, GLuint index, GLvoid *data), GLvoid *data)
{
	GLuint i;

	switch (type) {
		EXPAND_WITH_DATA(GL_BYTE, GLbyte,++,*array);
		EXPAND_WITH_DATA(GL_UNSIGNED_BYTE, GLubyte,++,*array);
		EXPAND_WITH_DATA(GL_SHORT, GLshort,++,*array);
		EXPAND_WITH_DATA(GL_UNSIGNED_SHORT, GLushort,++,*array);
		EXPAND_WITH_DATA(GL_INT, GLint,++,*array);
		EXPAND_WITH_DATA(GL_UNSIGNED_INT, GLuint,++,*array);
		EXPAND_WITH_DATA(GL_FLOAT, GLfloat,++,*array);

		EXPAND_WITH_DATA(GL_2_BYTES, GLubyte, +=2, 256*array[0] + array[1]);
		EXPAND_WITH_DATA(GL_3_BYTES, GLubyte, +=3, 256 * (256 * array[0] + array[1]) + array[2]);
		EXPAND_WITH_DATA(GL_4_BYTES, GLubyte, +=4, 256 * (256 * (256 * array[0] + array[1]) + array[2]) + array[3]);

		default:
			return GL_INVALID_ENUM;
	}

	return GL_NO_ERROR;
}