VirtualBox

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

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

crOpenGL/wddm: multithreading fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 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 CR_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 CR_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 CR_GET_PACKER_CONTEXT(pc);
60 if (__handleLightData( light, pname, params ))
61 WRITE_OPCODE( pc, CR_LIGHTFV_OPCODE );
62 CR_UNLOCK_PACKER_CONTEXT(pc);
63}
64
65void PACK_APIENTRY crPackLightiv (GLenum light, GLenum pname, const GLint *params)
66{
67 /* floats and ints are the same size, so the packing should be the same */
68 CR_GET_PACKER_CONTEXT(pc);
69 if (__handleLightData( light, pname, (const GLfloat *) params ))
70 WRITE_OPCODE( pc, CR_LIGHTIV_OPCODE );
71 CR_UNLOCK_PACKER_CONTEXT(pc);
72}
73
74static GLboolean __handleLightModelData( GLenum pname, const GLfloat *params )
75{
76 CR_GET_PACKER_CONTEXT(pc);
77 unsigned int packet_length = sizeof( int ) + sizeof( pname );
78 unsigned int params_length = 0;
79 unsigned char *data_ptr;
80 switch( pname )
81 {
82 case GL_LIGHT_MODEL_AMBIENT:
83 params_length = 4*sizeof( *params );
84 break;
85 case GL_LIGHT_MODEL_TWO_SIDE:
86 case GL_LIGHT_MODEL_LOCAL_VIEWER:
87 params_length = sizeof( *params );
88 break;
89 default:
90 __PackError( __LINE__, __FILE__, GL_INVALID_ENUM,
91 "crPackLightModel(bad pname)" );
92 return GL_FALSE;
93 }
94 packet_length += params_length;
95 CR_GET_BUFFERED_POINTER(pc, packet_length );
96 WRITE_DATA( 0, int, packet_length );
97 WRITE_DATA( sizeof( int ) + 0, GLenum, pname );
98 WRITE_DATA( sizeof( int ) + 4, GLfloat, params[0] );
99 if (params_length > sizeof( *params ))
100 {
101 WRITE_DATA( sizeof( int ) + 8, GLfloat, params[1] );
102 WRITE_DATA( sizeof( int ) + 12, GLfloat, params[2] );
103 WRITE_DATA( sizeof( int ) + 16, GLfloat, params[3] );
104 }
105 return GL_TRUE;
106}
107
108void PACK_APIENTRY crPackLightModelfv (GLenum pname, const GLfloat *params)
109{
110 CR_GET_PACKER_CONTEXT(pc);
111 if (__handleLightModelData( pname, params ))
112 WRITE_OPCODE( pc, CR_LIGHTMODELFV_OPCODE );
113 CR_UNLOCK_PACKER_CONTEXT(pc);
114}
115
116void PACK_APIENTRY crPackLightModeliv (GLenum pname, const GLint *params)
117{
118 /* floats and ints are the same size, so the packing should be the same */
119 CR_GET_PACKER_CONTEXT(pc);
120 if (__handleLightModelData( pname, (const GLfloat *) params ))
121 WRITE_OPCODE( pc, CR_LIGHTMODELIV_OPCODE );
122 CR_UNLOCK_PACKER_CONTEXT(pc);
123}
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