PageRenderTime 601ms CodeModel.GetById 163ms app.highlight 203ms RepoModel.GetById 145ms app.codeStats 1ms

/opengles/src/ContextFloat.cpp

http://ftk.googlecode.com/
C++ | 604 lines | 416 code | 127 blank | 61 comment | 42 complexity | c5585430a7f2a85edd0375b6b22ec5a9 MD5 | raw file
  1// ==========================================================================
  2//
  3// ContextFloat.cpp	Rendering Context Class for 3D Rendering Library
  4//
  5//					Emulation of EGL Floating Point Primitives
  6//
  7// --------------------------------------------------------------------------
  8//
  9// 08-02-2003	Hans-Martin Will	initial version
 10//
 11// --------------------------------------------------------------------------
 12//
 13// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
 14// 
 15// Redistribution and use in source and binary forms, with or without 
 16// modification, are permitted provided that the following conditions are 
 17// met:
 18// 
 19//	 *  Redistributions of source code must retain the above copyright
 20// 		notice, this list of conditions and the following disclaimer. 
 21//   *	Redistributions in binary form must reproduce the above copyright
 22// 		notice, this list of conditions and the following disclaimer in the 
 23// 		documentation and/or other materials provided with the distribution. 
 24// 
 25// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 26// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 28// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 29// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 30// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 31// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 32// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 33// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 34// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 35// THE POSSIBILITY OF SUCH DAMAGE.
 36//
 37// ==========================================================================
 38
 39
 40#include "stdafx.h"
 41#include "Context.h"
 42
 43
 44using namespace EGL;
 45
 46
 47void Context :: AlphaFunc (GLenum func, GLclampf ref) {
 48	AlphaFuncx(func, EGL_FixedFromFloat(ref));
 49}
 50
 51void Context :: ClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
 52	ClearColorx(EGL_FixedFromFloat(red), EGL_FixedFromFloat(green), 
 53		EGL_FixedFromFloat(blue), EGL_FixedFromFloat(alpha));
 54}
 55
 56void Context :: ClearDepthf (GLclampf depth) {
 57	ClearDepthx(EGL_FixedFromFloat(depth));
 58}
 59
 60void Context :: Color4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
 61	Color4x(EGL_FixedFromFloat(red), EGL_FixedFromFloat(green), 
 62		EGL_FixedFromFloat(blue), EGL_FixedFromFloat(alpha));
 63}
 64
 65void Context :: DepthRangef (GLclampf zNear, GLclampf zFar) {
 66	DepthRangex(EGL_FixedFromFloat(zNear), EGL_FixedFromFloat(zFar));
 67}
 68
 69void Context :: Fogf (GLenum pname, GLfloat param) {
 70	switch (pname) {
 71		case GL_FOG_MODE:
 72			Fogx(pname, EGL_FixedFromFloat(param));
 73			break;
 74
 75		case GL_FOG_START:
 76		case GL_FOG_END:
 77		case GL_FOG_DENSITY:
 78			Fogx(pname, EGL_FixedFromFloat(param));
 79			break;
 80
 81		default:
 82			RecordError(GL_INVALID_ENUM);
 83	}
 84}
 85
 86void Context :: Fogfv (GLenum pname, const GLfloat *params) {
 87
 88	GLfixed param;
 89
 90	switch (pname) {
 91	case GL_FOG_MODE:
 92		param = static_cast<GLenum>(*params);
 93		Fogxv(pname, &param);
 94		break;
 95
 96	case GL_FOG_DENSITY:
 97	case GL_FOG_START:
 98	case GL_FOG_END:
 99	//case GL_FOG_INDEX:
100		param = EGL_FixedFromFloat(*params);
101		Fogxv(pname, &param);
102		break;
103
104	case GL_FOG_COLOR:
105		GLfixed fixed_params[4];
106
107		for (int index = 0; index < 4; ++index) {
108			fixed_params[index] = EGL_FixedFromFloat(params[index]);
109		}
110
111		Fogxv(pname, fixed_params);
112		break;
113	}
114}
115
116void Context :: Frustumf (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) {
117	Frustumx(EGL_FixedFromFloat(left), EGL_FixedFromFloat(right),
118		EGL_FixedFromFloat(bottom), EGL_FixedFromFloat(top), 
119		EGL_FixedFromFloat(zNear), EGL_FixedFromFloat(zFar));
120}
121
122void Context :: LightModelf (GLenum pname, GLfloat param) {
123	LightModelx(pname, EGL_FixedFromFloat(param));
124}
125
126void Context :: LightModelfv (GLenum pname, const GLfloat *params) {
127
128	int index;
129
130	switch (pname) {
131	case GL_LIGHT_MODEL_AMBIENT:
132		GLfixed fixed_params[4];
133
134		for (index = 0; index < 4; ++index) {
135			fixed_params[index] = EGL_FixedFromFloat(params[index]);
136		}
137
138		LightModelxv(pname, fixed_params);
139		break;
140
141	//case GL_LIGHT_MODEL_LOCAL_VIEWER:
142	case GL_LIGHT_MODEL_TWO_SIDE:
143	//case GL_LIGHT_MODEL_COLOR_CONTROL:
144		GLfixed param;
145		param = EGL_FixedFromFloat(*params);
146		LightModelxv(pname, &param);
147		break;
148	}
149}
150
151void Context :: Lightf (GLenum light, GLenum pname, GLfloat param) {
152	Lightx(light, pname, EGL_FixedFromFloat(param));
153}
154
155void Context :: Lightfv (GLenum light, GLenum pname, const GLfloat *params) {
156	//void Context :: Lightxv (GLenum light, GLenum pname, const GLfixed *params);
157	GLfixed fixed_params[4];
158	int index;
159
160	switch (pname) {
161	case GL_AMBIENT:
162	case GL_DIFFUSE:
163	case GL_SPECULAR:
164//	case GL_EMISSION:
165	case GL_POSITION:
166		for (index = 0; index < 4; ++index) {
167			fixed_params[index] = EGL_FixedFromFloat(params[index]);
168		}
169
170		Lightxv(light, pname, fixed_params);
171		break;
172
173	case GL_SPOT_DIRECTION:
174		for (index = 0; index < 3; ++index) {
175			fixed_params[index] = EGL_FixedFromFloat(params[index]);
176		}
177
178		Lightxv(light, pname, fixed_params);
179		break;
180
181//	case GL_SHININESS:
182	case GL_SPOT_EXPONENT:
183	case GL_SPOT_CUTOFF:
184	case GL_CONSTANT_ATTENUATION:
185	case GL_LINEAR_ATTENUATION:
186	case GL_QUADRATIC_ATTENUATION:
187		fixed_params[0] = EGL_FixedFromFloat(params[0]);
188		Lightxv(light, pname, fixed_params);
189		break;
190
191	/*
192	case GL_COLOR_INDEXES:
193		for (index = 0; index < 3; ++index) {
194			fixed_params[index] = EGL_FixedFromFloat(params[index]);
195		}
196
197		glLightxv(light, pname, fixed_params);
198		break;
199	*/
200	}
201}
202
203void Context :: LineWidth (GLfloat width) {
204	LineWidthx(EGL_FixedFromFloat(width));
205}
206
207void Context :: LoadMatrixf (const GLfloat *m) {
208	GLfixed mx[16];
209
210	for (int index = 0; index < 16; ++index) {
211		mx[index] = EGL_FixedFromFloat(m[index]);
212	}
213
214	LoadMatrixx(mx);
215}
216
217void Context :: Materialf (GLenum face, GLenum pname, GLfloat param) {
218	Materialx(face, pname, EGL_FixedFromFloat(param));
219}
220
221void Context :: Materialfv (GLenum face, GLenum pname, const GLfloat *params) {
222	GLfixed fixed_params[4];
223	int index;
224
225	switch (pname) {
226	case GL_AMBIENT:
227	case GL_DIFFUSE:
228	case GL_AMBIENT_AND_DIFFUSE:
229	case GL_SPECULAR:
230	case GL_EMISSION:
231		for (index = 0; index < 4; ++index) {
232			fixed_params[index] = EGL_FixedFromFloat(params[index]);
233		}
234
235		Materialxv(face, pname, fixed_params);
236		break;
237
238	case GL_SHININESS:
239		fixed_params[0] = EGL_FixedFromFloat(params[0]);
240		Materialxv(face, pname, fixed_params);
241		break;
242
243	/*
244	case GL_COLOR_INDEXES:
245		for (index = 0; index < 3; ++index) {
246			fixed_params[index] = EGL_FixedFromFloat(params[index]);
247		}
248
249		glMaterialxv(light, pname, fixed_params);
250		break;
251	*/
252	}
253}
254
255void Context :: MultMatrixf (const GLfloat *m) {
256	GLfixed mx[16];
257
258	for (int index = 0; index < 16; ++index) {
259		mx[index] = EGL_FixedFromFloat(m[index]);
260	}
261
262	MultMatrixx(mx);
263}
264
265void Context :: MultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) {
266	MultiTexCoord4x(target, 
267		EGL_FixedFromFloat(s), EGL_FixedFromFloat(t),
268		EGL_FixedFromFloat(r), EGL_FixedFromFloat(q));
269}
270
271void Context :: Normal3f (GLfloat nx, GLfloat ny, GLfloat nz) {
272	Normal3x(EGL_FixedFromFloat(nx), EGL_FixedFromFloat(ny), EGL_FixedFromFloat(nz));
273}
274
275void Context :: Orthof (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) {
276	Orthox(EGL_FixedFromFloat(left), EGL_FixedFromFloat(right),
277		EGL_FixedFromFloat(bottom), EGL_FixedFromFloat(top),
278		EGL_FixedFromFloat(zNear), EGL_FixedFromFloat(zFar));
279}
280
281void Context :: PointSize (GLfloat size) {
282	PointSizex(EGL_FixedFromFloat(size));
283}
284
285void Context :: PolygonOffset (GLfloat factor, GLfloat units) {
286	PolygonOffsetx(EGL_FixedFromFloat(factor), EGL_FixedFromFloat(units));
287}
288
289void Context :: Rotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
290	Rotatex(EGL_FixedFromFloat(angle), EGL_FixedFromFloat(x),
291		EGL_FixedFromFloat(y), EGL_FixedFromFloat(z));
292}
293
294void Context :: SampleCoverage (GLclampf value, GLboolean invert) {
295	SampleCoveragex(EGL_FixedFromFloat(value), invert);
296}
297
298void Context :: Scalef (GLfloat x, GLfloat y, GLfloat z) {
299	Scalex(EGL_FixedFromFloat(x), EGL_FixedFromFloat(y), EGL_FixedFromFloat(z));
300}
301
302void Context :: TexEnvf (GLenum target, GLenum pname, GLfloat param) {
303
304	switch (pname) {
305	case GL_RGB_SCALE:
306	case GL_ALPHA_SCALE:
307		TexEnvx(target, pname, EGL_FixedFromFloat(param));
308		break;
309
310	default:
311		TexEnvx(target, pname, (GLfixed) param);
312		break;
313	}
314}
315
316void Context :: TexEnvfv (GLenum target, GLenum pname, const GLfloat *params) {
317	GLfixed fixed_params[4];
318	int index;
319
320	switch (pname) {
321		case GL_TEXTURE_ENV_COLOR:
322			for (index = 0; index < 4; ++index) {
323				fixed_params[index] = EGL_FixedFromFloat(params[index]);
324			}
325
326			TexEnvxv(target, pname, fixed_params);
327			break;
328
329		default:
330			TexEnvf(target, pname, *params);
331			break;
332	}
333}
334
335
336void Context :: TexParameterf (GLenum target, GLenum pname, GLfloat param) {
337	switch (pname) {
338		case GL_TEXTURE_MIN_FILTER:
339		case GL_TEXTURE_MAG_FILTER:
340		case GL_TEXTURE_WRAP_S:
341		case GL_TEXTURE_WRAP_T:
342		case GL_GENERATE_MIPMAP:
343			TexParameterx(target, pname, (GLfixed) param);
344			break;
345
346		default:
347			RecordError(GL_INVALID_ENUM);
348	}
349}
350
351void Context :: Translatef (GLfloat x, GLfloat y, GLfloat z) {
352	Translatex(EGL_FixedFromFloat(x), EGL_FixedFromFloat(y), EGL_FixedFromFloat(z));
353}
354
355void Context :: ClipPlanef(GLenum plane, const GLfloat *equation) {
356	EGL_Fixed fixedEqn[4];
357
358	for (size_t index = 0; index < 4; ++index) {
359		fixedEqn[index] = EGL_FixedFromFloat(equation[index]);
360	}
361
362	ClipPlanex(plane, fixedEqn);
363}
364
365void Context :: DrawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) {
366	assert(0);
367}
368
369void Context :: DrawTexfv(GLfloat *coords) {
370	assert(0);
371}
372
373void Context :: GetClipPlanef(GLenum plane, GLfloat eqn[4]) {
374	if (plane < GL_CLIP_PLANE0 || plane >= GL_CLIP_PLANE0 + NUM_CLIP_PLANES) {
375		RecordError(GL_INVALID_ENUM);
376		return;
377	}
378
379	size_t index = plane - GL_CLIP_PLANE0;
380	eqn[0] = EGL_FloatFromFixed(m_ClipPlanes[index].x());
381	eqn[1] = EGL_FloatFromFixed(m_ClipPlanes[index].y());
382	eqn[2] = EGL_FloatFromFixed(m_ClipPlanes[index].z());
383	eqn[3] = EGL_FloatFromFixed(m_ClipPlanes[index].w());
384}
385
386
387namespace {
388	void CopyFixed(const GLfixed * in, GLfloat * out, size_t size) {
389		while (size--) {
390			*out++ = EGL_FloatFromFixed(*in++);
391		}
392	}
393}
394
395
396void Context :: GetFloatv(GLenum pname, GLfloat *params) {
397
398	GLfixed buffer[16];
399
400	switch (pname) {
401	case GL_FOG_DENSITY:
402	case GL_FOG_START:
403	case GL_FOG_END:
404	case GL_POLYGON_OFFSET_UNITS:
405	case GL_POLYGON_OFFSET_FACTOR:
406	case GL_SAMPLE_COVERAGE_VALUE:
407	case GL_POINT_SIZE:
408	case GL_LINE_WIDTH:
409	case GL_POINT_SIZE_MIN:
410	case GL_POINT_SIZE_MAX:
411	case GL_POINT_FADE_THRESHOLD_SIZE:
412		if (GetFixedv(pname, buffer)) {
413			CopyFixed(buffer, params, 1);
414		}
415
416		break;
417
418	case GL_ALIASED_LINE_WIDTH_RANGE:
419	case GL_ALIASED_POINT_SIZE_RANGE:
420	case GL_SMOOTH_LINE_WIDTH_RANGE:
421	case GL_SMOOTH_POINT_SIZE_RANGE:
422	case GL_DEPTH_RANGE:
423		if (GetFixedv(pname, buffer)) {
424			CopyFixed(buffer, params, 2);
425		}
426
427		break;
428
429	case GL_CURRENT_NORMAL:
430	case GL_POINT_DISTANCE_ATTENUATION:
431		if (GetFixedv(pname, buffer)) {
432			CopyFixed(buffer, params, 3);
433		}
434
435		break;
436
437	case GL_CURRENT_COLOR:
438	case GL_CURRENT_TEXTURE_COORDS:
439	case GL_FOG_COLOR:
440	case GL_LIGHT_MODEL_AMBIENT:
441	case GL_COLOR_CLEAR_VALUE:
442		if (GetFixedv(pname, buffer)) {
443			CopyFixed(buffer, params, 4);
444		}
445
446		break;
447
448	case GL_MODELVIEW_MATRIX:
449	case GL_PROJECTION_MATRIX:
450	case GL_TEXTURE_MATRIX:
451		if (GetFixedv(pname, buffer)) {
452			CopyFixed(buffer, params, 16);
453		}
454
455		break;
456	}
457
458}
459
460void Context :: GetLightfv(GLenum light, GLenum pname, GLfloat *params) {
461
462	GLfixed buffer[16];
463
464	switch (pname) {
465	case GL_AMBIENT:
466	case GL_DIFFUSE:
467	case GL_SPECULAR:
468	case GL_POSITION:
469		if (GetLightxv(light, pname, buffer)) {
470			CopyFixed(buffer, params, 4);
471		}
472
473		break;
474
475	case GL_SPOT_DIRECTION:
476		if (GetLightxv(light, pname, buffer)) {
477			CopyFixed(buffer, params, 3);
478		}
479
480		break;
481
482	case GL_SPOT_EXPONENT:
483	case GL_SPOT_CUTOFF:
484	case GL_CONSTANT_ATTENUATION:
485	case GL_LINEAR_ATTENUATION:
486	case GL_QUADRATIC_ATTENUATION:
487		if (GetLightxv(light, pname, buffer)) {
488			CopyFixed(buffer, params, 1);
489		}
490
491		break;
492
493	default:
494		RecordError(GL_INVALID_ENUM);
495		return;
496	}
497}
498
499void Context :: GetMaterialfv(GLenum face, GLenum pname, GLfloat *params) {
500
501	GLfixed buffer[16];
502
503	switch (pname) {
504	case GL_AMBIENT:
505	case GL_DIFFUSE:
506	case GL_SPECULAR:
507	case GL_EMISSION:
508		if (GetMaterialxv(face, pname, buffer)) {
509			CopyFixed(buffer, params, 4);
510		}
511
512		break;
513
514	case GL_SHININESS:
515		if (GetMaterialxv(face, pname, buffer)) {
516			CopyFixed(buffer, params, 1);
517		}
518
519		break;
520
521	default:
522		RecordError(GL_INVALID_ENUM);
523		return;
524	}
525}
526
527void Context :: GetTexEnvfv(GLenum env, GLenum pname, GLfloat *params) {
528
529	GLfixed buffer[16];
530
531	switch (env) {
532	case GL_TEXTURE_ENV:
533		switch (pname) {
534		case GL_TEXTURE_ENV_COLOR:
535			if (GetTexEnvxv(env, pname, buffer)) {
536				CopyFixed(buffer, params, 4);
537			}
538
539			break;
540
541		case GL_RGB_SCALE:
542		case GL_ALPHA_SCALE:
543			if (GetTexEnvxv(env, pname, buffer)) {
544				params[0] = EGL_FloatFromFixed(buffer[0]);
545			}
546
547			break;
548
549		default:
550			RecordError(GL_INVALID_ENUM);
551			break;
552		}
553
554		break;
555
556	default:
557		RecordError(GL_INVALID_ENUM);
558		break;
559	}
560
561}
562
563void Context :: GetTexParameterfv(GLenum target, GLenum pname, GLfloat *params) {
564
565	if (target != GL_TEXTURE_2D) {
566		RecordError(GL_INVALID_ENUM);
567		return;
568	}
569
570#if 0
571	switch (pname) {
572
573	default:
574#endif
575		RecordError(GL_INVALID_ENUM);
576#if 0
577		break;
578	}
579#endif
580}
581
582void Context :: PointParameterf(GLenum pname, GLfloat param) {
583	PointParameterx(pname, EGL_FixedFromFloat(param));
584}
585
586void Context :: PointParameterfv(GLenum pname, const GLfloat *params) {
587	switch (pname) {
588	case GL_POINT_DISTANCE_ATTENUATION:
589		{
590			GLfixed fixedParams[3];
591
592			for (size_t index = 0; index < 3; ++index) {
593				fixedParams[index] = EGL_FixedFromFloat(params[index]);
594			}
595
596			PointParameterxv(pname, fixedParams);
597		}
598
599		break;
600
601	default:
602		PointParameterx(pname, EGL_FixedFromFloat(*params));
603	}
604}