PageRenderTime 204ms CodeModel.GetById 2ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/opengles/src/ContextPoints.cpp

http://ftk.googlecode.com/
C++ | 242 lines | 146 code | 55 blank | 41 comment | 26 complexity | 2cec7cf0fa7be5fe62734ea1637f44d5 MD5 | raw file
  1// ==========================================================================
  2//
  3// points.cpp	Rendering Context Class for 3D Rendering Library
  4//
  5//				Rendering Operations for Points
  6//
  7// --------------------------------------------------------------------------
  8//
  9// 08-12-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#include "fixed.h"
 43#include "Rasterizer.h"
 44
 45using namespace EGL;
 46
 47
 48void Context :: PointSizex(GLfixed size) { 
 49
 50	if (size <= 0) {
 51		RecordError(GL_INVALID_VALUE);
 52	} else {
 53		m_PointSize = size;
 54	}
 55}
 56
 57
 58inline EGL_Fixed Context :: SelectPointSizeArrayElement(int index) {
 59
 60	if (!m_PointSizeArray.effectivePointer) {
 61		// as long as we do not have anti-aliasing, determining the point size here is fine
 62		return m_PointSize;
 63	} else {
 64		EGL_Fixed coords[1];
 65
 66		m_PointSizeArray.FetchValues(index, coords);
 67		return coords[0];
 68	}
 69}
 70
 71
 72void Context :: RenderPoints(GLint first, GLsizei count) {
 73
 74	m_Rasterizer->PreparePoint();
 75
 76	while (count >= 1) {
 77		count -= 1;
 78
 79		RasterPos pos0;
 80		EGL_Fixed size = SelectPointSizeArrayElement(first);
 81		SelectArrayElement(first++);
 82		CurrentValuesToRasterPos(&pos0);
 83		RenderPoint(pos0, size);
 84	}
 85}
 86
 87
 88void Context :: RenderPoints(GLsizei count, const GLubyte * indices) {
 89
 90	m_Rasterizer->PreparePoint();
 91
 92	while (count >= 1) {
 93		count -= 1;
 94
 95		RasterPos pos0;
 96		EGL_Fixed size = SelectPointSizeArrayElement(*indices);
 97		SelectArrayElement(*indices++);
 98		CurrentValuesToRasterPos(&pos0);
 99		RenderPoint(pos0, size);
100	}
101}
102
103
104void Context :: RenderPoints(GLsizei count, const GLushort * indices) {
105
106	m_Rasterizer->PreparePoint();
107
108	while (count >= 1) {
109		count -= 1;
110
111		RasterPos pos0;
112		EGL_Fixed size = SelectPointSizeArrayElement(*indices);
113		SelectArrayElement(*indices++);
114		CurrentValuesToRasterPos(&pos0);
115		RenderPoint(pos0, size);
116	}
117}
118
119
120void Context :: RenderPoint(RasterPos& point, EGL_Fixed size) {
121
122	// any user defined clip planes?
123	if (m_ClipPlaneEnabled) {
124		for (size_t index = 0, mask = 1; index < NUM_CLIP_PLANES; ++index, mask <<= 1) {
125			if (m_ClipPlaneEnabled & mask) {
126				if (point.m_EyeCoords * m_ClipPlanes[index] < 0) {
127					return;
128				}
129			}
130		}
131	}
132	
133	// in principle, the scissor test can be included in here
134	if (point.m_ClipCoords.x() < -point.m_ClipCoords.w() ||
135		point.m_ClipCoords.x() >  point.m_ClipCoords.w() ||
136		point.m_ClipCoords.y() < -point.m_ClipCoords.w() ||
137		point.m_ClipCoords.y() >  point.m_ClipCoords.w() ||
138		point.m_ClipCoords.z() < -point.m_ClipCoords.w() ||
139		point.m_ClipCoords.z() >  point.m_ClipCoords.w()) 
140		return;
141
142	ClipCoordsToWindowCoords(point);
143	point.m_Color = point.m_FrontColor;
144
145	if (m_PointSizeAttenuate) {
146		EGL_Fixed eyeDistance = EGL_Abs(point.m_EyeCoords.z());
147
148		EGL_Fixed factor =
149			EGL_InvSqrt(m_PointDistanceAttenuation[0] +
150						EGL_Mul(m_PointDistanceAttenuation[1], eyeDistance) +
151						EGL_Mul(m_PointDistanceAttenuation[2], EGL_Mul(eyeDistance, eyeDistance)));
152
153		size = EGL_Mul(size, factor);
154	}
155
156	// as long as we do not have anti-aliasing, determining the effective point size here is fine
157	EGL_Fixed pointSize = EGL_Max(size, EGL_ONE);
158
159	m_Rasterizer->RasterPoint(point, pointSize);
160}
161
162
163void Context :: PointSizePointer(GLenum type, GLsizei stride, const GLvoid *pointer) {
164
165	if (type != GL_FIXED && type != GL_FLOAT) {
166		RecordError(GL_INVALID_ENUM);
167		return;
168	}
169
170	const size_t size = 1;
171
172	if (stride < 0) {
173		RecordError(GL_INVALID_VALUE);
174		return;
175	}
176
177	if (stride == 0) {
178		switch (type) {
179		case GL_BYTE:
180			stride = sizeof (GLbyte) * size;
181			break;
182
183		case GL_SHORT:
184			stride = sizeof (GLshort) * size;
185			break;
186
187		case GL_FIXED:
188			stride = sizeof (GLfixed) * size;
189			break;
190
191		case GL_FLOAT:
192			stride = sizeof (GLfloat) * size;
193			break;
194
195		}
196	}
197
198	m_PointSizeArray.pointer = pointer;
199	m_PointSizeArray.stride = stride;
200	m_PointSizeArray.type = type;
201	m_PointSizeArray.size = size;
202	m_PointSizeArray.boundBuffer = m_CurrentArrayBuffer;
203}
204
205void Context :: PointParameterx(GLenum pname, GLfixed param) {
206	switch (pname) {
207	case GL_POINT_SIZE_MIN:
208		m_PointSizeMin = param;
209		break;
210
211	case GL_POINT_SIZE_MAX:
212		m_PointSizeMax = param;
213		break;
214
215	case GL_POINT_FADE_THRESHOLD_SIZE:
216		m_PointFadeThresholdSize = param;
217		break;
218
219	default:
220		RecordError(GL_INVALID_ENUM);
221		break;
222	}
223}
224
225void Context :: PointParameterxv(GLenum pname, const GLfixed *params) {
226	switch (pname) {
227	case GL_POINT_DISTANCE_ATTENUATION:
228		m_PointDistanceAttenuation[0] = params[0];
229		m_PointDistanceAttenuation[1] = params[1];
230		m_PointDistanceAttenuation[2] = params[2];
231
232		m_PointSizeAttenuate =
233			(params[0] != EGL_ONE || params[1] || params[2]);
234
235		break;
236
237	default:
238		PointParameterx(pname, *params);
239		break;
240	}
241}
242