summaryrefslogtreecommitdiffstats
path: root/src/VBox/GuestHost/OpenGL/state_tracker/convert.py
blob: 1adbf4e6c2740a436673cba80404f3d20d99b491 (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
# Copyright (c) 2001, Stanford University
# All rights reserved.
#
# See the file LICENSE.txt for information on redistributing this software.

from __future__ import print_function
import sys

# Two different paths to the packer and opengl_stub directories since this
# script will be called from both cr/state_tracker/ and cr/spu/tilesort/.
sys.path.append( '../packer' )
sys.path.append( '../../packer' )
sys.path.append( '../glapi_parser' )
sys.path.append( '../../glapi_parser' )
from pack_currenttypes import *
import apiutil

apiutil.CopyrightC()

print('''
#include "state/cr_statetypes.h"

static double __read_double( const void *src )
{
    const unsigned int *ui = (const unsigned int *) src;
    double d;
    ((unsigned int *) &d)[0] = ui[0];
    ((unsigned int *) &d)[1] = ui[1];
    return d;
}
''')

for k in sorted(gltypes.keys()):
	for i in range(1,5):
		print('static void __convert_%s%d (GLfloat *dst, const %s *src) {' % (k,i,gltypes[k]['type']))
		if k == 'd':
		  for j in range(i-1):
		    print('\t*dst++ = (GLfloat) __read_double(src++);')
		  print('\t*dst = (GLfloat) __read_double(src);')
		else:
		  for j in range(i-1):
		    print('\t*dst++ = (GLfloat) *src++;')
		  print('\t*dst = (GLfloat) *src;')
		print('}\n')

scale = {
	'ub' : 'CR_MAXUBYTE',
	'b'  : 'CR_MAXBYTE',
	'us' : 'CR_MAXUSHORT',
	's'  : 'CR_MAXSHORT',
	'ui' : 'CR_MAXUINT',
	'i'  : 'CR_MAXINT',
	'f'  : '',
	'd'  : ''
}

for k in sorted(gltypes.keys()):
	if k != 'f' and k != 'd' and k != 'l':
		if k[0:1] == "N":
			k2 = k[1:]
		else:
			k2 = k
		for i in range(1,5):
			print('static void __convert_rescale_%s%d (GLfloat *dst, const %s *src) {' % (k,i,gltypes[k2]['type']))
			for j in range(i-1):
				print('\t*dst++ = ((GLfloat) *src++) / %s;' % scale[k2])
			print('\t*dst = ((GLfloat) *src) / %s;' % scale[k2])
			print('}\n')

print('''

static void __convert_boolean (GLboolean *dst, const GLboolean *src) {
	*dst = *src;
}
''')