VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/packer/pack_lights.c@ 33457

Last change on this file since 33457 was 33457, checked in by vboxsync, 14 years ago

crOpenGL: tabs to spaces

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include "packer.h"
8#include "cr_error.h"
9
10static GLboolean __handleLightData( GLenum light, GLenum pname, const GLfloat *params )
11{
12 GET_PACKER_CONTEXT(pc);
13 unsigned int packet_length = sizeof( int ) + sizeof( light ) + sizeof( pname );
14 unsigned int params_length = 0;
15 unsigned char *data_ptr;
16 switch( pname )
17 {
18 case GL_AMBIENT:
19 case GL_DIFFUSE:
20 case GL_SPECULAR:
21 case GL_POSITION:
22 params_length = 4*sizeof( *params );
23 break;
24 case GL_SPOT_DIRECTION:
25 params_length = 3*sizeof( *params );
26 break;
27 case GL_SPOT_EXPONENT:
28 case GL_SPOT_CUTOFF:
29 case GL_CONSTANT_ATTENUATION:
30 case GL_LINEAR_ATTENUATION:
31 case GL_QUADRATIC_ATTENUATION:
32 params_length = sizeof( *params );
33 break;
34 default:
35 __PackError( __LINE__, __FILE__, GL_INVALID_ENUM,
36 "crPackLight(bad pname)" );
37 return GL_FALSE;
38 }
39 packet_length += params_length;
40 GET_BUFFERED_POINTER(pc, packet_length );
41 WRITE_DATA( 0, int, packet_length );
42 WRITE_DATA( sizeof( int ) + 0, GLenum, light );
43 WRITE_DATA( sizeof( int ) + 4, GLenum, pname );
44 WRITE_DATA( sizeof( int ) + 8, GLfloat, params[0] );
45 if (params_length > sizeof( *params ))
46 {
47 WRITE_DATA( sizeof( int ) + 12, GLfloat, params[1] );
48 WRITE_DATA( sizeof( int ) + 16, GLfloat, params[2] );
49 }
50 if (params_length > 3*sizeof( *params ))
51 {
52 WRITE_DATA( sizeof( int ) + 20, GLfloat, params[3] );
53 }
54 return GL_TRUE;
55}
56
57void PACK_APIENTRY crPackLightfv (GLenum light, GLenum pname, const GLfloat *params)
58{
59 GET_PACKER_CONTEXT(pc);
60 if (__handleLightData( light, pname, params ))
61 WRITE_OPCODE( pc, CR_LIGHTFV_OPCODE );
62}
63
64void PACK_APIENTRY crPackLightiv (GLenum light, GLenum pname, const GLint *params)
65{
66 /* floats and ints are the same size, so the packing should be the same */
67 GET_PACKER_CONTEXT(pc);
68 if (__handleLightData( light, pname, (const GLfloat *) params ))
69 WRITE_OPCODE( pc, CR_LIGHTIV_OPCODE );
70}
71
72static GLboolean __handleLightModelData( GLenum pname, const GLfloat *params )
73{
74 GET_PACKER_CONTEXT(pc);
75 unsigned int packet_length = sizeof( int ) + sizeof( pname );
76 unsigned int params_length = 0;
77 unsigned char *data_ptr;
78 switch( pname )
79 {
80 case GL_LIGHT_MODEL_AMBIENT:
81 params_length = 4*sizeof( *params );
82 break;
83 case GL_LIGHT_MODEL_TWO_SIDE:
84 case GL_LIGHT_MODEL_LOCAL_VIEWER:
85 params_length = sizeof( *params );
86 break;
87 default:
88 __PackError( __LINE__, __FILE__, GL_INVALID_ENUM,
89 "crPackLightModel(bad pname)" );
90 return GL_FALSE;
91 }
92 packet_length += params_length;
93 GET_BUFFERED_POINTER(pc, packet_length );
94 WRITE_DATA( 0, int, packet_length );
95 WRITE_DATA( sizeof( int ) + 0, GLenum, pname );
96 WRITE_DATA( sizeof( int ) + 4, GLfloat, params[0] );
97 if (params_length > sizeof( *params ))
98 {
99 WRITE_DATA( sizeof( int ) + 8, GLfloat, params[1] );
100 WRITE_DATA( sizeof( int ) + 12, GLfloat, params[2] );
101 WRITE_DATA( sizeof( int ) + 16, GLfloat, params[3] );
102 }
103 return GL_TRUE;
104}
105
106void PACK_APIENTRY crPackLightModelfv (GLenum pname, const GLfloat *params)
107{
108 GET_PACKER_CONTEXT(pc);
109 if (__handleLightModelData( pname, params ))
110 WRITE_OPCODE( pc, CR_LIGHTMODELFV_OPCODE );
111}
112
113void PACK_APIENTRY crPackLightModeliv (GLenum pname, const GLint *params)
114{
115 /* floats and ints are the same size, so the packing should be the same */
116 GET_PACKER_CONTEXT(pc);
117 if (__handleLightModelData( pname, (const GLfloat *) params ))
118 WRITE_OPCODE( pc, CR_LIGHTMODELIV_OPCODE );
119}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette