This commit is contained in:
pelya
2012-10-17 21:23:08 +03:00
parent 73d3bdb324
commit d3ad4a40fe
203 changed files with 51890 additions and 1 deletions

View File

@@ -3,7 +3,7 @@
APP_MODULES := application sdl-1.2 sdl_main stlport jpeg png ogg flac vorbis freetype tremor ogg
# To filter out static libs from all libs in makefile
APP_AVAILABLE_STATIC_LIBS := jpeg png tremor freetype xerces ogg tremor vorbis flac boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread
APP_AVAILABLE_STATIC_LIBS := jpeg png tremor freetype xerces ogg tremor vorbis flac boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread glu
APP_ABI := armeabi

View File

@@ -0,0 +1,21 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := glu
APP_SUBDIRS := src
APP_SUBDIRS := $(patsubst $(LOCAL_PATH)/%, %, $(shell find $(LOCAL_PATH)/src -type d))
LOCAL_C_INCLUDES := $(foreach D, $(APP_SUBDIRS), $(LOCAL_PATH)/$(D))
LOCAL_CFLAGS := -O3 -std=gnu99
LOCAL_CPP_EXTENSION := .cpp
LOCAL_SRC_FILES := $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.cpp))))
LOCAL_SRC_FILES += $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.c))))
LOCAL_SHARED_LIBRARIES :=
include $(BUILD_STATIC_LIBRARY)

27
project/jni/glu/LICENSE Normal file
View File

@@ -0,0 +1,27 @@
SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice including the dates of first publication and
either this permission notice or a reference to
http://oss.sgi.com/projects/FreeB/
shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Except as contained in this notice, the name of Silicon Graphics, Inc.
shall not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization from
Silicon Graphics, Inc.

25
project/jni/glu/README Normal file
View File

@@ -0,0 +1,25 @@
GLU ES (version 1.5)
This port is based on original GLU 1.3 and has original libutil, libtess and
and nurbs libraries.
Currently QNX 6.4.x native target builds and Win32 (for PowerVR OpenGL ES 1.1
emulator) are supported.
History:
1.5 - NURBS support has added. Updated HTML documentation to reflect the
changes. New tests were added for NURBS.
1.4 - miscellaneous non-critical fixes, HTML documentation has been added.
Support for PowerVR OpenGL ES 1.1 emulator for Win32 has been added.
1.3 - libtess and tesselation tests (QNX native and SDL 1.3) have been added.
1.2 - SDL 1.3 based tests were added.
1.1 - Removed some texture formats, which are not supported by OpenGL ES 1.x,
added arrays manipulation to the quadric functions. Sphere flat shading
fixes. Disk texturing with inner radius more than 0.0f fixes. Updated
tests.
1.0 - Initial public release.
// 11.11.2009
// Mike Gorchak <mike@malva.ua>, <lestat@i.com.ua>

View File

@@ -0,0 +1 @@
../../src/glues.h

1
project/jni/glu/src/glu.h Symbolic link
View File

@@ -0,0 +1 @@
glues.h

406
project/jni/glu/src/glues.h Normal file
View File

@@ -0,0 +1,406 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glues_h__
#define __glues_h__
#if defined(__USE_SDL_GLES__)
#include <SDL/SDL_opengles.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#elif defined (__QNXNTO__) || defined (__ANDROID__)
#include <GLES/gl.h>
#include <GLES/glext.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#ifndef APIENTRY
#define APIENTRY GL_APIENTRY
#endif
#ifndef APIENTRYP
#define APIENTRYP GL_APIENTRYP
#endif
#elif defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
/* mainly for PowerVR OpenGL ES 1.x win32 emulator */
#include <GLES\gl.h>
#include <GLES\glext.h>
#undef APIENTRY
#define APIENTRY
#if defined(GLUES_EXPORTS)
#define GLAPI __declspec(dllexport)
#else
#define GLAPI __declspec(dllimport)
#endif
#else
#error "Platform is unsupported"
#endif
#ifndef APIENTRYP
#define APIENTRYP APIENTRY *
#endif /* APIENTRYP */
#ifdef __cplusplus
extern "C" {
#endif
/*************************************************************/
/* Extensions */
#define GLU_EXT_object_space_tess 1
#define GLU_EXT_nurbs_tessellator 1
/* Boolean */
#define GLU_FALSE 0
#define GLU_TRUE 1
/* Version */
#define GLU_VERSION_1_1 1
#define GLU_VERSION_1_2 1
#define GLU_VERSION_1_3 1
/* StringName */
#define GLU_VERSION 100800
#define GLU_EXTENSIONS 100801
/* ErrorCode */
#define GLU_INVALID_ENUM 100900
#define GLU_INVALID_VALUE 100901
#define GLU_OUT_OF_MEMORY 100902
#define GLU_INCOMPATIBLE_GL_VERSION 100903
#define GLU_INVALID_OPERATION 100904
/* QuadricDrawStyle */
#define GLU_POINT 100010
#define GLU_LINE 100011
#define GLU_FILL 100012
#define GLU_SILHOUETTE 100013
/* QuadricCallback */
#define GLU_ERROR 100103
/* QuadricNormal */
#define GLU_SMOOTH 100000
#define GLU_FLAT 100001
#define GLU_NONE 100002
/* QuadricOrientation */
#define GLU_OUTSIDE 100020
#define GLU_INSIDE 100021
/*************************************************************/
#ifdef __cplusplus
class GLUquadric;
class GLUtesselator;
class GLUnurbs;
#else
typedef struct GLUquadric GLUquadric;
typedef struct GLUtesselator GLUtesselator;
typedef struct GLUnurbs GLUnurbs;
#endif
typedef GLUquadric GLUquadricObj;
typedef GLUtesselator GLUtesselatorObj;
typedef GLUtesselator GLUtriangulatorObj;
typedef GLUnurbs GLUnurbsObj;
/* Internal convenience typedefs */
typedef void (APIENTRYP _GLUfuncptr)();
GLAPI GLboolean APIENTRY gluCheckExtension(const GLubyte* extName, const GLubyte* extString);
GLAPI void APIENTRY gluCylinder(GLUquadric* quad, GLfloat base, GLfloat top, GLfloat height, GLint slices, GLint stacks);
GLAPI void APIENTRY gluDeleteQuadric(GLUquadric* quad);
GLAPI void APIENTRY gluDisk(GLUquadric* quad, GLfloat inner, GLfloat outer, GLint slices, GLint loops);
GLAPI const GLubyte* APIENTRY gluErrorString(GLenum error);
GLAPI const GLubyte * APIENTRY gluGetString(GLenum name);
GLAPI void APIENTRY gluLookAt(GLfloat eyeX, GLfloat eyeY, GLfloat eyeZ, GLfloat centerX, GLfloat centerY, GLfloat centerZ, GLfloat upX, GLfloat upY, GLfloat upZ);
GLAPI GLUquadric* APIENTRY gluNewQuadric(void);
GLAPI void APIENTRY gluOrtho2D(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top);
GLAPI void APIENTRY gluPartialDisk(GLUquadric* quad, GLfloat inner, GLfloat outer, GLint slices, GLint loops, GLfloat start, GLfloat sweep);
GLAPI void APIENTRY gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar);
GLAPI void APIENTRY gluPickMatrix(GLfloat x, GLfloat y, GLfloat delX, GLfloat delY, GLint *viewport);
GLAPI GLint APIENTRY gluProject(GLfloat objX, GLfloat objY, GLfloat objZ, const GLfloat *model, const GLfloat *proj, const GLint *view, GLfloat* winX, GLfloat* winY, GLfloat* winZ);
GLAPI void APIENTRY gluQuadricCallback(GLUquadric* quad, GLenum which, _GLUfuncptr CallBackFunc);
GLAPI void APIENTRY gluQuadricDrawStyle(GLUquadric* quad, GLenum draw);
GLAPI void APIENTRY gluQuadricNormals(GLUquadric* quad, GLenum normal);
GLAPI void APIENTRY gluQuadricOrientation(GLUquadric* quad, GLenum orientation);
GLAPI void APIENTRY gluQuadricTexture(GLUquadric* quad, GLboolean texture);
GLAPI void APIENTRY gluSphere(GLUquadric* quad, GLfloat radius, GLint slices, GLint stacks);
GLAPI GLint APIENTRY gluUnProject(GLfloat winX, GLfloat winY, GLfloat winZ, const GLfloat *model, const GLfloat *proj, const GLint *view, GLfloat* objX, GLfloat* objY, GLfloat* objZ);
GLAPI GLint APIENTRY gluUnProject4(GLfloat winX, GLfloat winY, GLfloat winZ, GLfloat clipW, const GLfloat *model, const GLfloat *proj, const GLint *view, GLfloat nearVal, GLfloat farVal, GLfloat* objX, GLfloat* objY, GLfloat* objZ, GLfloat* objW);
GLAPI GLint APIENTRY gluScaleImage(GLenum format, GLsizei widthin,
GLsizei heightin, GLenum typein,
const void* datain, GLsizei widthout,
GLsizei heightout, GLenum typeout, void* dataout);
GLAPI GLint APIENTRY gluBuild2DMipmapLevels(GLenum target, GLint internalFormat,
GLsizei width, GLsizei height, GLenum format,
GLenum type, GLint userLevel, GLint baseLevel,
GLint maxLevel, const void *data);
GLAPI GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat,
GLsizei width, GLsizei height, GLenum format,
GLenum type, const void* data);
#define GLU_TESS_MAX_COORD 1.0e37f
/* TessCallback */
#define GLU_TESS_BEGIN 100100
#define GLU_BEGIN 100100
#define GLU_TESS_VERTEX 100101
#define GLU_VERTEX 100101
#define GLU_TESS_END 100102
#define GLU_END 100102
#define GLU_TESS_ERROR 100103
#define GLU_TESS_EDGE_FLAG 100104
#define GLU_EDGE_FLAG 100104
#define GLU_TESS_COMBINE 100105
#define GLU_TESS_BEGIN_DATA 100106
#define GLU_TESS_VERTEX_DATA 100107
#define GLU_TESS_END_DATA 100108
#define GLU_TESS_ERROR_DATA 100109
#define GLU_TESS_EDGE_FLAG_DATA 100110
#define GLU_TESS_COMBINE_DATA 100111
/* TessContour */
#define GLU_CW 100120
#define GLU_CCW 100121
#define GLU_INTERIOR 100122
#define GLU_EXTERIOR 100123
#define GLU_UNKNOWN 100124
/* TessProperty */
#define GLU_TESS_WINDING_RULE 100140
#define GLU_TESS_BOUNDARY_ONLY 100141
#define GLU_TESS_TOLERANCE 100142
/* TessError */
#define GLU_TESS_ERROR1 100151
#define GLU_TESS_ERROR2 100152
#define GLU_TESS_ERROR3 100153
#define GLU_TESS_ERROR4 100154
#define GLU_TESS_ERROR5 100155
#define GLU_TESS_ERROR6 100156
#define GLU_TESS_ERROR7 100157
#define GLU_TESS_ERROR8 100158
#define GLU_TESS_MISSING_BEGIN_POLYGON 100151
#define GLU_TESS_MISSING_BEGIN_CONTOUR 100152
#define GLU_TESS_MISSING_END_POLYGON 100153
#define GLU_TESS_MISSING_END_CONTOUR 100154
#define GLU_TESS_COORD_TOO_LARGE 100155
#define GLU_TESS_NEED_COMBINE_CALLBACK 100156
/* TessWinding */
#define GLU_TESS_WINDING_ODD 100130
#define GLU_TESS_WINDING_NONZERO 100131
#define GLU_TESS_WINDING_POSITIVE 100132
#define GLU_TESS_WINDING_NEGATIVE 100133
#define GLU_TESS_WINDING_ABS_GEQ_TWO 100134
GLAPI void APIENTRY gluBeginPolygon(GLUtesselator* tess);
GLAPI void APIENTRY gluDeleteTess(GLUtesselator* tess);
GLAPI void APIENTRY gluEndPolygon(GLUtesselator* tess);
GLAPI void APIENTRY gluGetTessProperty(GLUtesselator* tess, GLenum which, GLfloat* data);
GLAPI GLUtesselator* APIENTRY gluNewTess(void);
GLAPI void APIENTRY gluNextContour(GLUtesselator* tess, GLenum type);
GLAPI void APIENTRY gluTessBeginContour(GLUtesselator* tess);
GLAPI void APIENTRY gluTessBeginPolygon(GLUtesselator* tess, GLvoid* data);
GLAPI void APIENTRY gluTessCallback(GLUtesselator* tess, GLenum which, _GLUfuncptr CallBackFunc);
GLAPI void APIENTRY gluTessEndContour(GLUtesselator* tess);
GLAPI void APIENTRY gluTessEndPolygon(GLUtesselator* tess);
GLAPI void APIENTRY gluTessNormal(GLUtesselator* tess, GLfloat valueX, GLfloat valueY, GLfloat valueZ);
GLAPI void APIENTRY gluTessProperty(GLUtesselator* tess, GLenum which, GLfloat data);
GLAPI void APIENTRY gluTessVertex(GLUtesselator* tess, GLfloat* location, GLvoid* data);
/* NurbsDisplay */
/* GLU_FILL */
#define GLU_OUTLINE_POLYGON 100240
#define GLU_OUTLINE_PATCH 100241
/* NurbsCallback */
#define GLU_NURBS_ERROR 100103
#define GLU_ERROR 100103
#define GLU_NURBS_BEGIN 100164
#define GLU_NURBS_BEGIN_EXT 100164
#define GLU_NURBS_VERTEX 100165
#define GLU_NURBS_VERTEX_EXT 100165
#define GLU_NURBS_NORMAL 100166
#define GLU_NURBS_NORMAL_EXT 100166
#define GLU_NURBS_COLOR 100167
#define GLU_NURBS_COLOR_EXT 100167
#define GLU_NURBS_TEXTURE_COORD 100168
#define GLU_NURBS_TEX_COORD_EXT 100168
#define GLU_NURBS_END 100169
#define GLU_NURBS_END_EXT 100169
#define GLU_NURBS_BEGIN_DATA 100170
#define GLU_NURBS_BEGIN_DATA_EXT 100170
#define GLU_NURBS_VERTEX_DATA 100171
#define GLU_NURBS_VERTEX_DATA_EXT 100171
#define GLU_NURBS_NORMAL_DATA 100172
#define GLU_NURBS_NORMAL_DATA_EXT 100172
#define GLU_NURBS_COLOR_DATA 100173
#define GLU_NURBS_COLOR_DATA_EXT 100173
#define GLU_NURBS_TEXTURE_COORD_DATA 100174
#define GLU_NURBS_TEX_COORD_DATA_EXT 100174
#define GLU_NURBS_END_DATA 100175
#define GLU_NURBS_END_DATA_EXT 100175
/* NurbsError */
#define GLU_NURBS_ERROR1 100251
#define GLU_NURBS_ERROR2 100252
#define GLU_NURBS_ERROR3 100253
#define GLU_NURBS_ERROR4 100254
#define GLU_NURBS_ERROR5 100255
#define GLU_NURBS_ERROR6 100256
#define GLU_NURBS_ERROR7 100257
#define GLU_NURBS_ERROR8 100258
#define GLU_NURBS_ERROR9 100259
#define GLU_NURBS_ERROR10 100260
#define GLU_NURBS_ERROR11 100261
#define GLU_NURBS_ERROR12 100262
#define GLU_NURBS_ERROR13 100263
#define GLU_NURBS_ERROR14 100264
#define GLU_NURBS_ERROR15 100265
#define GLU_NURBS_ERROR16 100266
#define GLU_NURBS_ERROR17 100267
#define GLU_NURBS_ERROR18 100268
#define GLU_NURBS_ERROR19 100269
#define GLU_NURBS_ERROR20 100270
#define GLU_NURBS_ERROR21 100271
#define GLU_NURBS_ERROR22 100272
#define GLU_NURBS_ERROR23 100273
#define GLU_NURBS_ERROR24 100274
#define GLU_NURBS_ERROR25 100275
#define GLU_NURBS_ERROR26 100276
#define GLU_NURBS_ERROR27 100277
#define GLU_NURBS_ERROR28 100278
#define GLU_NURBS_ERROR29 100279
#define GLU_NURBS_ERROR30 100280
#define GLU_NURBS_ERROR31 100281
#define GLU_NURBS_ERROR32 100282
#define GLU_NURBS_ERROR33 100283
#define GLU_NURBS_ERROR34 100284
#define GLU_NURBS_ERROR35 100285
#define GLU_NURBS_ERROR36 100286
#define GLU_NURBS_ERROR37 100287
/* NurbsProperty */
#define GLU_AUTO_LOAD_MATRIX 100200
#define GLU_CULLING 100201
#define GLU_SAMPLING_TOLERANCE 100203
#define GLU_DISPLAY_MODE 100204
#define GLU_PARAMETRIC_TOLERANCE 100202
#define GLU_SAMPLING_METHOD 100205
#define GLU_U_STEP 100206
#define GLU_V_STEP 100207
#define GLU_NURBS_MODE 100160
#define GLU_NURBS_MODE_EXT 100160
#define GLU_NURBS_TESSELLATOR 100161
#define GLU_NURBS_TESSELLATOR_EXT 100161
#define GLU_NURBS_RENDERER 100162
#define GLU_NURBS_RENDERER_EXT 100162
/* NurbsSampling */
#define GLU_OBJECT_PARAMETRIC_ERROR 100208
#define GLU_OBJECT_PARAMETRIC_ERROR_EXT 100208
#define GLU_OBJECT_PATH_LENGTH 100209
#define GLU_OBJECT_PATH_LENGTH_EXT 100209
#define GLU_PATH_LENGTH 100215
#define GLU_PARAMETRIC_ERROR 100216
#define GLU_DOMAIN_DISTANCE 100217
/* NurbsTrim */
#define GLU_MAP1_TRIM_2 100210
#define GLU_MAP1_TRIM_3 100211
GLAPI void APIENTRY gluBeginCurve(GLUnurbs* nurb);
GLAPI void APIENTRY gluBeginSurface(GLUnurbs* nurb);
GLAPI void APIENTRY gluBeginTrim(GLUnurbs* nurb);
GLAPI void APIENTRY gluDeleteNurbsRenderer(GLUnurbs* nurb);
GLAPI void APIENTRY gluEndCurve(GLUnurbs* nurb);
GLAPI void APIENTRY gluEndSurface(GLUnurbs* nurb);
GLAPI void APIENTRY gluEndTrim(GLUnurbs* nurb);
GLAPI void APIENTRY gluGetNurbsProperty(GLUnurbs* nurb, GLenum property, GLfloat* data);
GLAPI void APIENTRY gluLoadSamplingMatrices(GLUnurbs* nurb, const GLfloat* model, const GLfloat* perspective, const GLint* view);
GLAPI GLUnurbs* APIENTRY gluNewNurbsRenderer(void);
GLAPI void APIENTRY gluNurbsCallback(GLUnurbs* nurb, GLenum which, _GLUfuncptr CallBackFunc);
GLAPI void APIENTRY gluNurbsCallbackData(GLUnurbs* nurb, GLvoid* userData);
GLAPI void APIENTRY gluNurbsCallbackDataEXT(GLUnurbs* nurb, GLvoid* userData);
GLAPI void APIENTRY gluNurbsCurve(GLUnurbs* nurb, GLint knotCount, GLfloat* knots, GLint stride, GLfloat* control, GLint order, GLenum type);
GLAPI void APIENTRY gluNurbsProperty(GLUnurbs* nurb, GLenum property, GLfloat value);
GLAPI void APIENTRY gluNurbsSurface(GLUnurbs* nurb, GLint sKnotCount, GLfloat* sKnots, GLint tKnotCount, GLfloat* tKnots, GLint sStride, GLint tStride, GLfloat* control, GLint sOrder, GLint tOrder, GLenum type);
GLAPI void APIENTRY gluPwlCurve(GLUnurbs* nurb, GLint count, GLfloat* data, GLint stride, GLenum type);
/* OpenGL (and OpenGL ES 1.1 for OpenGL ES 1.0) emulation layer */
#define GLU_AUTO_NORMAL 0x0D80
#define GLU_MAP1_COLOR_4 0x0D90
#define GLU_MAP1_INDEX 0x0D91
#define GLU_MAP1_NORMAL 0x0D92
#define GLU_MAP1_TEXTURE_COORD_1 0x0D93
#define GLU_MAP1_TEXTURE_COORD_2 0x0D94
#define GLU_MAP1_TEXTURE_COORD_3 0x0D95
#define GLU_MAP1_TEXTURE_COORD_4 0x0D96
#define GLU_MAP1_VERTEX_3 0x0D97
#define GLU_MAP1_VERTEX_4 0x0D98
#define GLU_MAP2_COLOR_4 0x0DB0
#define GLU_MAP2_INDEX 0x0DB1
#define GLU_MAP2_NORMAL 0x0DB2
#define GLU_MAP2_TEXTURE_COORD_1 0x0DB3
#define GLU_MAP2_TEXTURE_COORD_2 0x0DB4
#define GLU_MAP2_TEXTURE_COORD_3 0x0DB5
#define GLU_MAP2_TEXTURE_COORD_4 0x0DB6
#define GLU_MAP2_VERTEX_3 0x0DB7
#define GLU_MAP2_VERTEX_4 0x0DB8
#ifndef GL_MODELVIEW_MATRIX
#define GL_MODELVIEW_MATRIX 0x0BA6
#endif /* GL_MODELVIEW_MATRIX */
#ifndef GL_PROJECTION_MATRIX
#define GL_PROJECTION_MATRIX 0x0BA7
#endif /* GL_PROJECTION_MATRIX */
#ifndef GL_VIEWPORT
#define GL_VIEWPORT 0x0BA2
#endif /* GL_VIEWPORT */
GLAPI void APIENTRY gluEnable(GLenum cap);
GLAPI void APIENTRY gluDisable(GLenum cap);
GLAPI void APIENTRY gluGetFloatv(GLenum pname, GLfloat* params);
GLAPI void APIENTRY gluGetIntegerv(GLenum pname, GLint* params);
GLAPI void APIENTRY gluViewport(GLint x, GLint y, GLsizei width, GLsizei height);
#ifdef __cplusplus
}
#endif
#endif /* __glues_h__ */

View File

@@ -0,0 +1,149 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include <stdio.h>
#include <stdlib.h>
#include "glues_error.h"
static unsigned char* __gluNurbsErrors[]=
{
(unsigned char*) " ",
(unsigned char*) "spline order un-supported",
(unsigned char*) "too few knots",
(unsigned char*) "valid knot range is empty",
(unsigned char*) "decreasing knot sequence knot",
(unsigned char*) "knot multiplicity greater than order of spline",
(unsigned char*) "gluEndCurve() must follow gluBeginCurve()",
(unsigned char*) "gluBeginCurve() must precede gluEndCurve()",
(unsigned char*) "missing or extra geometric data",
(unsigned char*) "can't draw piecewise linear trimming curves",
(unsigned char*) "missing or extra domain data",
(unsigned char*) "missing or extra domain data",
(unsigned char*) "gluEndTrim() must precede gluEndSurface()",
(unsigned char*) "gluBeginSurface() must precede gluEndSurface()",
(unsigned char*) "curve of improper type passed as trim curve",
(unsigned char*) "gluBeginSurface() must precede gluBeginTrim()",
(unsigned char*) "gluEndTrim() must follow gluBeginTrim()",
(unsigned char*) "gluBeginTrim() must precede gluEndTrim()",
(unsigned char*) "invalid or missing trim curve",
(unsigned char*) "gluBeginTrim() must precede gluPwlCurve()",
(unsigned char*) "piecewise linear trimming curve referenced twice",
(unsigned char*) "piecewise linear trimming curve and nurbs curve mixed",
(unsigned char*) "improper usage of trim data type",
(unsigned char*) "nurbs curve referenced twice",
(unsigned char*) "nurbs curve and piecewise linear trimming curve mixed",
(unsigned char*) "nurbs surface referenced twice",
(unsigned char*) "invalid property",
(unsigned char*) "gluEndSurface() must follow gluBeginSurface()",
(unsigned char*) "intersecting or misoriented trim curves",
(unsigned char*) "intersecting trim curves",
(unsigned char*) "UNUSED",
(unsigned char*) "unconnected trim curves",
(unsigned char*) "unknown knot error",
(unsigned char*) "negative vertex count encountered",
(unsigned char*) "negative byte-stride encounteed",
(unsigned char*) "unknown type descriptor",
(unsigned char*) "null control point reference",
(unsigned char*) "duplicate point on piecewise linear trimming curve",
};
const unsigned char* __gluNURBSErrorString(int errnum)
{
return __gluNurbsErrors[errnum];
}
static unsigned char* __gluTessErrors[]=
{
(unsigned char*) " ",
(unsigned char*) "gluTessBeginPolygon() must precede a gluTessEndPolygon()",
(unsigned char*) "gluTessBeginContour() must precede a gluTessEndContour()",
(unsigned char*) "gluTessEndPolygon() must follow a gluTessBeginPolygon()",
(unsigned char*) "gluTessEndContour() must follow a gluTessBeginContour()",
(unsigned char*) "a coordinate is too large",
(unsigned char*) "need combine callback",
};
const unsigned char* __gluTessErrorString(int errnum)
{
return __gluTessErrors[errnum];
}
struct token_string
{
GLuint Token;
const char* String;
};
static const struct token_string Errors[]=
{
/* GL */
{GL_NO_ERROR, "no error"},
{GL_INVALID_ENUM, "invalid enumerant"},
{GL_INVALID_VALUE, "invalid value"},
{GL_INVALID_OPERATION, "invalid operation"},
{GL_STACK_OVERFLOW, "stack overflow"},
{GL_STACK_UNDERFLOW, "stack underflow"},
{GL_OUT_OF_MEMORY, "out of memory"},
/* GLU */
{ GLU_INVALID_ENUM, "invalid enumerant"},
{ GLU_INVALID_VALUE, "invalid value"},
{ GLU_OUT_OF_MEMORY, "out of memory"},
{ GLU_INCOMPATIBLE_GL_VERSION, "incompatible gl version"},
{ GLU_INVALID_OPERATION, "invalid operation"},
{ ~0, NULL } /* end of list indicator */
};
GLAPI const GLubyte* APIENTRY gluErrorString(GLenum errorCode)
{
int i;
for (i=0; Errors[i].String; i++)
{
if (Errors[i].Token==errorCode)
{
return (const GLubyte*) Errors[i].String;
}
}
if ((errorCode>=GLU_NURBS_ERROR1) && (errorCode<=GLU_NURBS_ERROR37))
{
return (const GLubyte*)__gluNURBSErrorString(errorCode-(GLU_NURBS_ERROR1-1));
}
if ((errorCode>=GLU_TESS_ERROR1) && (errorCode<=GLU_TESS_ERROR6))
{
return (const GLubyte*) __gluTessErrorString(errorCode-(GLU_TESS_ERROR1-1));
}
return (const GLubyte*)0;
}

View File

@@ -0,0 +1,139 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*
* OpenGL ES CM 1.0 port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __GLUES_REGISTRY_H__
#define __GLUES_REGISTRY_H__
#if defined(__USE_SDL_GLES__)
#include <SDL/SDL_opengles.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#elif defined (__QNXNTO__) || defined (__ANDROID__)
#include <GLES/gl.h>
#include <GLES/glext.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#ifndef APIENTRY
#define APIENTRY GL_APIENTRY
#endif
#ifndef APIENTRYP
#define APIENTRYP GL_APIENTRYP
#endif
#elif defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
/* mainly for PowerVR OpenGL ES 1.x win32 emulator */
#include <GLES\gl.h>
#undef APIENTRY
#define APIENTRY
#if defined(GLUES_EXPORTS)
#define GLAPI __declspec(dllexport)
#else
#define GLAPI __declspec(dllimport)
#endif
#else
#error "Platform is unsupported"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* ErrorCode */
#define GLU_INVALID_ENUM 100900
#define GLU_INVALID_VALUE 100901
#define GLU_OUT_OF_MEMORY 100902
#define GLU_INCOMPATIBLE_GL_VERSION 100903
#define GLU_INVALID_OPERATION 100904
/* TessError */
#define GLU_TESS_ERROR1 100151
#define GLU_TESS_ERROR2 100152
#define GLU_TESS_ERROR3 100153
#define GLU_TESS_ERROR4 100154
#define GLU_TESS_ERROR5 100155
#define GLU_TESS_ERROR6 100156
#define GLU_TESS_ERROR7 100157
#define GLU_TESS_ERROR8 100158
#define GLU_TESS_MISSING_BEGIN_POLYGON 100151
#define GLU_TESS_MISSING_BEGIN_CONTOUR 100152
#define GLU_TESS_MISSING_END_POLYGON 100153
#define GLU_TESS_MISSING_END_CONTOUR 100154
#define GLU_TESS_COORD_TOO_LARGE 100155
#define GLU_TESS_NEED_COMBINE_CALLBACK 100156
/* NurbsError */
#define GLU_NURBS_ERROR1 100251
#define GLU_NURBS_ERROR2 100252
#define GLU_NURBS_ERROR3 100253
#define GLU_NURBS_ERROR4 100254
#define GLU_NURBS_ERROR5 100255
#define GLU_NURBS_ERROR6 100256
#define GLU_NURBS_ERROR7 100257
#define GLU_NURBS_ERROR8 100258
#define GLU_NURBS_ERROR9 100259
#define GLU_NURBS_ERROR10 100260
#define GLU_NURBS_ERROR11 100261
#define GLU_NURBS_ERROR12 100262
#define GLU_NURBS_ERROR13 100263
#define GLU_NURBS_ERROR14 100264
#define GLU_NURBS_ERROR15 100265
#define GLU_NURBS_ERROR16 100266
#define GLU_NURBS_ERROR17 100267
#define GLU_NURBS_ERROR18 100268
#define GLU_NURBS_ERROR19 100269
#define GLU_NURBS_ERROR20 100270
#define GLU_NURBS_ERROR21 100271
#define GLU_NURBS_ERROR22 100272
#define GLU_NURBS_ERROR23 100273
#define GLU_NURBS_ERROR24 100274
#define GLU_NURBS_ERROR25 100275
#define GLU_NURBS_ERROR26 100276
#define GLU_NURBS_ERROR27 100277
#define GLU_NURBS_ERROR28 100278
#define GLU_NURBS_ERROR29 100279
#define GLU_NURBS_ERROR30 100280
#define GLU_NURBS_ERROR31 100281
#define GLU_NURBS_ERROR32 100282
#define GLU_NURBS_ERROR33 100283
#define GLU_NURBS_ERROR34 100284
#define GLU_NURBS_ERROR35 100285
#define GLU_NURBS_ERROR36 100286
#define GLU_NURBS_ERROR37 100287
GLAPI const GLubyte* APIENTRY gluErrorString(GLenum errorCode);
#ifdef __cplusplus
}
#endif
#endif /* __GLUES_REGISTRY_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,94 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*
* OpenGL ES CM 1.0 port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __GLUES_MIPMAP_H__
#define __GLUES_MIPMAP_H__
#if defined(__USE_SDL_GLES__)
#include <SDL/SDL_opengles.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#elif defined (__QNXNTO__) || defined (__ANDROID__)
#include <GLES/gl.h>
#include <GLES/glext.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#ifndef APIENTRY
#define APIENTRY GL_APIENTRY
#endif
#ifndef APIENTRYP
#define APIENTRYP GL_APIENTRYP
#endif
#elif defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
/* mainly for PowerVR OpenGL ES 1.x win32 emulator */
#include <GLES\gl.h>
#undef APIENTRY
#define APIENTRY
#if defined(GLUES_EXPORTS)
#define GLAPI __declspec(dllexport)
#else
#define GLAPI __declspec(dllimport)
#endif
#else
#error "Platform is unsupported"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* ErrorCode */
#define GLU_INVALID_ENUM 100900
#define GLU_INVALID_VALUE 100901
#define GLU_OUT_OF_MEMORY 100902
#define GLU_INCOMPATIBLE_GL_VERSION 100903
#define GLU_INVALID_OPERATION 100904
GLAPI GLint APIENTRY gluScaleImage(GLenum format, GLsizei widthin,
GLsizei heightin, GLenum typein,
const void* datain, GLsizei widthout,
GLsizei heightout, GLenum typeout, void* dataout);
GLAPI GLint APIENTRY gluBuild2DMipmapLevels(GLenum target, GLint internalFormat,
GLsizei width, GLsizei height, GLenum format,
GLenum type, GLint userLevel, GLint baseLevel,
GLint maxLevel, const void *data);
GLAPI GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat,
GLsizei width, GLsizei height, GLenum format,
GLenum type, const void* data);
#ifdef __cplusplus
}
#endif
#endif /* __GLUES_REGISTRY_H__ */

View File

@@ -0,0 +1,378 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include <math.h>
#include "glues_project.h"
/*
** Make m an identity matrix
*/
static void __gluMakeIdentityf(GLfloat m[16])
{
m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
}
GLAPI void APIENTRY
gluOrtho2D(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top)
{
glOrthof(left, right, bottom, top, -1, 1);
}
#define __glPi 3.14159265358979323846
GLAPI void APIENTRY
gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)
{
GLfloat m[4][4];
GLfloat sine, cotangent, deltaZ;
GLfloat radians=(GLfloat)(fovy/2.0f*__glPi/180.0f);
deltaZ=zFar-zNear;
sine=(GLfloat)sin(radians);
if ((deltaZ==0.0f) || (sine==0.0f) || (aspect==0.0f))
{
return;
}
cotangent=(GLfloat)(cos(radians)/sine);
__gluMakeIdentityf(&m[0][0]);
m[0][0] = cotangent / aspect;
m[1][1] = cotangent;
m[2][2] = -(zFar + zNear) / deltaZ;
m[2][3] = -1.0f;
m[3][2] = -2.0f * zNear * zFar / deltaZ;
m[3][3] = 0;
glMultMatrixf(&m[0][0]);
}
static void normalize(GLfloat v[3])
{
GLfloat r;
r=(GLfloat)sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
if (r==0.0f)
{
return;
}
v[0]/=r;
v[1]/=r;
v[2]/=r;
}
static void cross(GLfloat v1[3], GLfloat v2[3], GLfloat result[3])
{
result[0] = v1[1]*v2[2] - v1[2]*v2[1];
result[1] = v1[2]*v2[0] - v1[0]*v2[2];
result[2] = v1[0]*v2[1] - v1[1]*v2[0];
}
GLAPI void APIENTRY
gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx,
GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy,
GLfloat upz)
{
GLfloat forward[3], side[3], up[3];
GLfloat m[4][4];
forward[0] = centerx - eyex;
forward[1] = centery - eyey;
forward[2] = centerz - eyez;
up[0] = upx;
up[1] = upy;
up[2] = upz;
normalize(forward);
/* Side = forward x up */
cross(forward, up, side);
normalize(side);
/* Recompute up as: up = side x forward */
cross(side, forward, up);
__gluMakeIdentityf(&m[0][0]);
m[0][0] = side[0];
m[1][0] = side[1];
m[2][0] = side[2];
m[0][1] = up[0];
m[1][1] = up[1];
m[2][1] = up[2];
m[0][2] = -forward[0];
m[1][2] = -forward[1];
m[2][2] = -forward[2];
glMultMatrixf(&m[0][0]);
glTranslatef(-eyex, -eyey, -eyez);
}
static void __gluMultMatrixVecf(const GLfloat matrix[16], const GLfloat in[4],
GLfloat out[4])
{
int i;
for (i=0; i<4; i++)
{
out[i] = in[0] * matrix[0*4+i] +
in[1] * matrix[1*4+i] +
in[2] * matrix[2*4+i] +
in[3] * matrix[3*4+i];
}
}
/*
** Invert 4x4 matrix.
** Contributed by David Moore (See Mesa bug #6748)
*/
static int __gluInvertMatrixf(const GLfloat m[16], GLfloat invOut[16])
{
GLfloat inv[16], det;
int i;
inv[0] = m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15]
+ m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10];
inv[4] = -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15]
- m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10];
inv[8] = m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15]
+ m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9];
inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14]
- m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9];
inv[1] = -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15]
- m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10];
inv[5] = m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15]
+ m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10];
inv[9] = -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15]
- m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9];
inv[13] = m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14]
+ m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9];
inv[2] = m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15]
+ m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6];
inv[6] = -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15]
- m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6];
inv[10] = m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15]
+ m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5];
inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14]
- m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5];
inv[3] = -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11]
- m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6];
inv[7] = m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11]
+ m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6];
inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11]
- m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5];
inv[15] = m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10]
+ m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5];
det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12];
if (det == 0)
return GL_FALSE;
det=1.0f/det;
for (i = 0; i < 16; i++)
invOut[i] = inv[i] * det;
return GL_TRUE;
}
static void __gluMultMatricesf(const GLfloat a[16], const GLfloat b[16],
GLfloat r[16])
{
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
r[i*4+j] = a[i*4+0]*b[0*4+j] +
a[i*4+1]*b[1*4+j] +
a[i*4+2]*b[2*4+j] +
a[i*4+3]*b[3*4+j];
}
}
}
GLAPI GLint APIENTRY
gluProject(GLfloat objx, GLfloat objy, GLfloat objz,
const GLfloat modelMatrix[16],
const GLfloat projMatrix[16],
const GLint viewport[4],
GLfloat* winx, GLfloat* winy, GLfloat* winz)
{
GLfloat in[4];
GLfloat out[4];
in[0]=objx;
in[1]=objy;
in[2]=objz;
in[3]=1.0;
__gluMultMatrixVecf(modelMatrix, in, out);
__gluMultMatrixVecf(projMatrix, out, in);
if (in[3] == 0.0)
{
return(GL_FALSE);
}
in[0]/=in[3];
in[1]/=in[3];
in[2]/=in[3];
/* Map x, y and z to range 0-1 */
in[0]=in[0]*0.5f+0.5f;
in[1]=in[1]*0.5f+0.5f;
in[2]=in[2]*0.5f+0.5f;
/* Map x,y to viewport */
in[0]=in[0] * viewport[2] + viewport[0];
in[1]=in[1] * viewport[3] + viewport[1];
*winx=in[0];
*winy=in[1];
*winz=in[2];
return(GL_TRUE);
}
GLAPI GLint APIENTRY
gluUnProject(GLfloat winx, GLfloat winy, GLfloat winz,
const GLfloat modelMatrix[16],
const GLfloat projMatrix[16],
const GLint viewport[4],
GLfloat* objx, GLfloat* objy, GLfloat* objz)
{
GLfloat finalMatrix[16];
GLfloat in[4];
GLfloat out[4];
__gluMultMatricesf(modelMatrix, projMatrix, finalMatrix);
if (!__gluInvertMatrixf(finalMatrix, finalMatrix))
{
return(GL_FALSE);
}
in[0]=winx;
in[1]=winy;
in[2]=winz;
in[3]=1.0;
/* Map x and y from window coordinates */
in[0] = (in[0] - viewport[0]) / viewport[2];
in[1] = (in[1] - viewport[1]) / viewport[3];
/* Map to range -1 to 1 */
in[0] = in[0] * 2 - 1;
in[1] = in[1] * 2 - 1;
in[2] = in[2] * 2 - 1;
__gluMultMatrixVecf(finalMatrix, in, out);
if (out[3] == 0.0)
{
return(GL_FALSE);
}
out[0] /= out[3];
out[1] /= out[3];
out[2] /= out[3];
*objx = out[0];
*objy = out[1];
*objz = out[2];
return(GL_TRUE);
}
GLAPI GLint APIENTRY
gluUnProject4(GLfloat winx, GLfloat winy, GLfloat winz, GLfloat clipw,
const GLfloat modelMatrix[16],
const GLfloat projMatrix[16],
const GLint viewport[4],
GLclampf nearVal, GLclampf farVal,
GLfloat *objx, GLfloat *objy, GLfloat *objz,
GLfloat *objw)
{
GLfloat finalMatrix[16];
GLfloat in[4];
GLfloat out[4];
__gluMultMatricesf(modelMatrix, projMatrix, finalMatrix);
if (!__gluInvertMatrixf(finalMatrix, finalMatrix))
{
return(GL_FALSE);
}
in[0]=winx;
in[1]=winy;
in[2]=winz;
in[3]=clipw;
/* Map x and y from window coordinates */
in[0] = (in[0] - viewport[0]) / viewport[2];
in[1] = (in[1] - viewport[1]) / viewport[3];
in[2] = (in[2] - nearVal) / (farVal - nearVal);
/* Map to range -1 to 1 */
in[0] = in[0] * 2 - 1;
in[1] = in[1] * 2 - 1;
in[2] = in[2] * 2 - 1;
__gluMultMatrixVecf(finalMatrix, in, out);
if (out[3] == 0.0)
{
return(GL_FALSE);
}
*objx = out[0];
*objy = out[1];
*objz = out[2];
*objw = out[3];
return(GL_TRUE);
}
GLAPI void APIENTRY
gluPickMatrix(GLfloat x, GLfloat y, GLfloat deltax, GLfloat deltay,
GLint viewport[4])
{
if (deltax <= 0 || deltay <= 0)
{
return;
}
/* Translate and scale the picked region to the entire window */
glTranslatef((viewport[2] - 2 * (x - viewport[0])) / deltax,
(viewport[3] - 2 * (y - viewport[1])) / deltay, 0);
glScalef(viewport[2] / deltax, viewport[3] / deltay, 1.0);
}

View File

@@ -0,0 +1,92 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*
* OpenGL ES CM 1.0 port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __GLUES_PROJECT_H__
#define __GLUES_PROJECT_H__
#if defined(__USE_SDL_GLES__)
#include <SDL/SDL_opengles.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#elif defined (__QNXNTO__) || defined (__ANDROID__)
#include <GLES/gl.h>
#include <GLES/glext.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#ifndef APIENTRY
#define APIENTRY GL_APIENTRY
#endif
#ifndef APIENTRYP
#define APIENTRYP GL_APIENTRYP
#endif
#elif defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
/* mainly for PowerVR OpenGL ES 1.x win32 emulator */
#include <GLES\gl.h>
#undef APIENTRY
#define APIENTRY
#if defined(GLUES_EXPORTS)
#define GLAPI __declspec(dllexport)
#else
#define GLAPI __declspec(dllimport)
#endif
#else
#error "Platform is unsupported"
#endif
#ifdef __cplusplus
extern "C" {
#endif
GLAPI void APIENTRY gluOrtho2D(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top);
GLAPI void APIENTRY gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar);
GLAPI void APIENTRY gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery, GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz);
GLAPI GLint APIENTRY gluProject(GLfloat objx, GLfloat objy, GLfloat objz,
const GLfloat modelMatrix[16], const GLfloat projMatrix[16],
const GLint viewport[4], GLfloat* winx, GLfloat* winy, GLfloat* winz);
GLAPI GLint APIENTRY gluUnProject(GLfloat winx, GLfloat winy, GLfloat winz,
const GLfloat modelMatrix[16], const GLfloat projMatrix[16],
const GLint viewport[4], GLfloat* objx, GLfloat* objy, GLfloat* objz);
GLAPI GLint APIENTRY gluUnProject4(GLfloat winx, GLfloat winy, GLfloat winz, GLfloat clipw,
const GLfloat modelMatrix[16], const GLfloat projMatrix[16],
const GLint viewport[4], GLclampf nearVal, GLclampf farVal,
GLfloat* objx, GLfloat* objy, GLfloat* objz, GLfloat* objw);
GLAPI void APIENTRY gluPickMatrix(GLfloat x, GLfloat y, GLfloat deltax, GLfloat deltay, GLint viewport[4]);
#ifdef __cplusplus
}
#endif
#endif /* __GLUES_PROJECT_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,135 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*
* OpenGL ES CM 1.0 port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __GLUES_QUAD_H__
#define __GLUES_QUAD_H__
#if defined(__USE_SDL_GLES__)
#include <SDL/SDL_opengles.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#elif defined (__QNXNTO__) || defined (__ANDROID__)
#include <GLES/gl.h>
#include <GLES/glext.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#ifndef APIENTRY
#define APIENTRY GL_APIENTRY
#endif
#ifndef APIENTRYP
#define APIENTRYP GL_APIENTRYP
#endif
#elif defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
/* mainly for PowerVR OpenGL ES 1.x win32 emulator */
#include <GLES\gl.h>
#undef APIENTRY
#define APIENTRY
#if defined(GLUES_EXPORTS)
#define GLAPI __declspec(dllexport)
#else
#define GLAPI __declspec(dllimport)
#endif
#else
#error "Platform is unsupported"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* ErrorCode */
#define GLU_INVALID_ENUM 100900
#define GLU_INVALID_VALUE 100901
#define GLU_OUT_OF_MEMORY 100902
#define GLU_INCOMPATIBLE_GL_VERSION 100903
#define GLU_INVALID_OPERATION 100904
/* QuadricDrawStyle */
#define GLU_POINT 100010
#define GLU_LINE 100011
#define GLU_FILL 100012
#define GLU_SILHOUETTE 100013
/* QuadricCallback */
#define GLU_ERROR 100103
/* QuadricNormal */
#define GLU_SMOOTH 100000
#define GLU_FLAT 100001
#define GLU_NONE 100002
/* QuadricOrientation */
#define GLU_OUTSIDE 100020
#define GLU_INSIDE 100021
#ifdef __cplusplus
class GLUquadric;
#else
typedef struct GLUquadric GLUquadric;
#endif
typedef GLUquadric GLUquadricObj;
#ifndef APIENTRYP
#define APIENTRYP APIENTRY *
#endif /* APIENTRYP */
/* Internal convenience typedefs */
typedef void (APIENTRYP _GLUfuncptr)();
GLAPI GLUquadric* APIENTRY gluNewQuadric(void);
GLAPI void APIENTRY gluDeleteQuadric(GLUquadric* state);
GLAPI void APIENTRY gluQuadricCallback(GLUquadric* qobj, GLenum which,
_GLUfuncptr fn);
GLAPI void APIENTRY gluQuadricNormals(GLUquadric* qobj, GLenum normals);
GLAPI void APIENTRY gluQuadricTexture(GLUquadric* qobj, GLboolean textureCoords);
GLAPI void APIENTRY gluQuadricOrientation(GLUquadric* qobj, GLenum orientation);
GLAPI void APIENTRY gluQuadricDrawStyle(GLUquadric* qobj, GLenum drawStyle);
GLAPI void APIENTRY gluCylinder(GLUquadric* qobj, GLfloat baseRadius,
GLfloat topRadius, GLfloat height,
GLint slices, GLint stacks);
GLAPI void APIENTRY gluDisk(GLUquadric* qobj, GLfloat innerRadius,
GLfloat outerRadius, GLint slices, GLint loops);
GLAPI void APIENTRY gluPartialDisk(GLUquadric* qobj, GLfloat innerRadius,
GLfloat outerRadius, GLint slices,
GLint loops, GLfloat startAngle,
GLfloat sweepAngle);
GLAPI void APIENTRY gluSphere(GLUquadric* qobj, GLfloat radius, GLint slices,
GLint stacks);
#ifdef __cplusplus
}
#endif
#endif /* __GLUES_QUAD_H__ */

View File

@@ -0,0 +1,99 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*
* OpenGL ES CM 1.0 port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "glues_registry.h"
static const GLubyte versionString[]="1.3 GLU ES-CM";
static const GLubyte extensionString[]="GLU_EXT_object_space_tess GLU_EXT_nurbs_tessellator";
GLAPI const GLubyte* APIENTRY gluGetString(GLenum name)
{
if (name==GLU_VERSION)
{
return versionString;
}
else
{
if (name==GLU_EXTENSIONS)
{
return extensionString;
}
}
return NULL;
}
/* extName is an extension name.
* extString is a string of extensions separated by blank(s). There may or
* may not be leading or trailing blank(s) in extString.
* This works in cases of extensions being prefixes of another like
* GL_EXT_texture and GL_EXT_texture3D.
* Returns GL_TRUE if extName is found otherwise it returns GL_FALSE.
*/
GLAPI GLboolean APIENTRY gluCheckExtension(const GLubyte* extName, const GLubyte* extString)
{
GLboolean flag=GL_FALSE;
char* word;
char* lookHere;
char* deleteThis;
if (extString==NULL)
{
return GL_FALSE;
}
deleteThis=lookHere=(char*)malloc(strlen((const char*)extString)+1);
if (lookHere==NULL)
{
return GL_FALSE;
}
/* strtok() will modify string, so copy it somewhere */
strcpy(lookHere,(const char*)extString);
while ((word=strtok(lookHere, " "))!=NULL)
{
if (strcmp(word,(const char*)extName)==0)
{
flag=GL_TRUE;
break;
}
lookHere=NULL; /* get next token */
}
free((void*)deleteThis);
return flag;
}

View File

@@ -0,0 +1,87 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*
* OpenGL ES CM 1.0 port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __GLUES_REGISTRY_H__
#define __GLUES_REGISTRY_H__
#if defined(__USE_SDL_GLES__)
#include <SDL/SDL_opengles.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#elif defined (__QNXNTO__) || defined (__ANDROID__)
#include <GLES/gl.h>
#include <GLES/glext.h>
#ifndef GLAPI
#define GLAPI GL_API
#endif
#ifndef APIENTRY
#define APIENTRY GL_APIENTRY
#endif
#ifndef APIENTRYP
#define APIENTRYP GL_APIENTRYP
#endif
#elif defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
/* mainly for PowerVR OpenGL ES 1.x win32 emulator */
#include <GLES\gl.h>
#undef APIENTRY
#define APIENTRY
#if defined(GLUES_EXPORTS)
#define GLAPI __declspec(dllexport)
#else
#define GLAPI __declspec(dllimport)
#endif
#else
#error "Platform is unsupported"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Version */
#define GLU_VERSION_1_1 0x00000001
#define GLU_VERSION_1_2 0x00000001
#define GLU_VERSION_1_3 0x00000001
/* StringName */
#define GLU_VERSION 100800
#define GLU_EXTENSIONS 100801
GLAPI const GLubyte* APIENTRY gluGetString(GLenum name);
GLAPI GLboolean APIENTRY gluCheckExtension(const GLubyte* extName, const GLubyte* extString);
#ifdef __cplusplus
}
#endif
#endif /* __GLUES_REGISTRY_H__ */

View File

@@ -0,0 +1,249 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include "bezierEval.h"
#ifdef __WATCOMC__
#pragma warning 14 10
#endif
#define TOLERANCE 0.0001
#ifndef MAX_ORDER
#define MAX_ORDER 16
#endif
#ifndef MAX_DIMENSION
#define MAX_DIMENSION 4
#endif
static void normalize(float vec[3]);
static void crossProduct(float x[3], float y[3], float ret[3]);
static float binomialCoefficients[8][8]=
{
{1, 0, 0, 0, 0, 0, 0, 0},
{1, 1, 0, 0, 0, 0, 0, 0},
{1, 2, 1, 0, 0, 0, 0, 0},
{1, 3, 3, 1, 0, 0, 0, 0},
{1, 4, 6, 4, 1, 0, 0, 0},
{1, 5, 10, 10, 5, 1, 0, 0},
{1, 6, 15, 20, 15, 6, 1, 0},
{1, 7, 21, 35, 35, 21, 7, 1}
};
void bezierCurveEval(float u0, float u1, int order, float *ctlpoints, int stride, int dimension, float u, float retpoint[])
{
float uprime=(u-u0)/(u1-u0);
float* ctlptr=ctlpoints;
float oneMinusX=1.0f-uprime;
float XPower=1.0f;
int i, k;
for(k=0; k<dimension; k++)
{
retpoint[k]=(*(ctlptr+k));
}
for(i=1; i<order; i++)
{
ctlptr+=stride;
XPower*=uprime;
for(k=0; k<dimension; k++)
{
retpoint[k]=retpoint[k]*oneMinusX+ctlptr[k]*binomialCoefficients[order-1][i]*XPower;
}
}
}
/* order = degree +1 >=1. */
void bezierCurveEvalDer(float u0, float u1, int order, float *ctlpoints, int stride, int dimension, float u, float retDer[])
{
int i, k;
float width=u1-u0;
float* ctlptr=ctlpoints;
float buf[MAX_ORDER][MAX_DIMENSION];
if (order==1)
{
for(k=0; k<dimension; k++)
{
retDer[k]=0;
}
}
for(i=0; i<order-1; i++)
{
for(k=0; k<dimension; k++)
{
buf[i][k]=(ctlptr[stride+k]-ctlptr[k])*(order-1)/width;
}
ctlptr+=stride;
}
bezierCurveEval(u0, u1, order-1, (float*)buf, MAX_DIMENSION, dimension, u, retDer);
}
void bezierCurveEvalDerGen(int der, float u0, float u1, int order, float* ctlpoints, int stride, int dimension, float u, float retDer[])
{
int i, k, r;
float* ctlptr = ctlpoints;
float width=u1-u0;
float buf[MAX_ORDER][MAX_ORDER][MAX_DIMENSION];
if (der<0)
{
der=0;
}
for(i=0; i<order; i++)
{
for(k=0; k<dimension; k++)
{
buf[0][i][k]=ctlptr[k];
}
ctlptr+=stride;
}
for(r=1; r<=der; r++)
{
for(i=0; i<order-r; i++)
{
for(k=0; k<dimension; k++)
{
buf[r][i][k]=(buf[r-1][i+1][k]-buf[r-1][i][k])*(order-r)/width;
}
}
}
bezierCurveEval(u0, u1, order-der, (float*)(buf[der]), MAX_DIMENSION, dimension, u, retDer);
}
/* the Bezier bivarite polynomial is:
* sum[i:0,uorder-1][j:0,vorder-1] { ctlpoints[i*ustride+j*vstride] * B(i)*B(j)
* where B(i) and B(j) are basis functions
*/
void bezierSurfEvalDerGen(int uder, int vder, float u0, float u1, int uorder, float v0, float v1, int vorder, int dimension, float *ctlpoints, int ustride, int vstride, float u, float v, float ret[])
{
int i;
float newPoints[MAX_ORDER][MAX_DIMENSION];
for(i=0; i<uorder; i++)
{
bezierCurveEvalDerGen(vder, v0, v1, vorder, ctlpoints+ustride*i, vstride, dimension, v, newPoints[i]);
}
bezierCurveEvalDerGen(uder, u0, u1, uorder, (float *) newPoints, MAX_DIMENSION, dimension, u, ret);
}
/* division by w is performed */
void bezierSurfEval(float u0, float u1, int uorder, float v0, float v1, int vorder, int dimension, float *ctlpoints, int ustride, int vstride, float u, float v, float ret[])
{
bezierSurfEvalDerGen(0, 0, u0, u1, uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u, v, ret);
if (dimension==4) /* homogeneous */
{
ret[0]/=ret[3];
ret[1]/=ret[3];
ret[2]/=ret[3];
}
}
void bezierSurfEvalNormal(float u0, float u1, int uorder, float v0, float v1, int vorder, int dimension, float *ctlpoints, int ustride, int vstride, float u, float v, float retNormal[])
{
float partialU[4];
float partialV[4];
assert(dimension>=3 && dimension <=4);
bezierSurfEvalDerGen(1,0, u0, u1, uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u, v, partialU);
bezierSurfEvalDerGen(0,1, u0, u1, uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u, v, partialV);
if (dimension == 3) /* inhomogeneous */
{
crossProduct(partialU, partialV, retNormal);
normalize(retNormal);
return;
}
else /* homogeneous */
{
float val[4]; /* the point coordinates (without derivative) */
float newPartialU[MAX_DIMENSION];
float newPartialV[MAX_DIMENSION];
int i;
bezierSurfEvalDerGen(0,0, u0, u1, uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u, v, val);
for(i=0; i<=2; i++)
{
newPartialU[i]=partialU[i]*val[3]-val[i]*partialU[3];
newPartialV[i]=partialV[i]*val[3]-val[i]*partialV[3];
}
crossProduct(newPartialU, newPartialV, retNormal);
normalize(retNormal);
}
}
/* if size is 0, then nothing is done */
static void normalize(float vec[3])
{
float size=(float)sqrt(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]);
if (size<TOLERANCE)
{
return;
}
else
{
vec[0]=vec[0]/size;
vec[1]=vec[1]/size;
vec[2]=vec[2]/size;
}
}
static void crossProduct(float x[3], float y[3], float ret[3])
{
ret[0]=x[1]*y[2]-y[1]*x[2];
ret[1]=x[2]*y[0]-y[2]*x[0];
ret[2]=x[0]*y[1]-y[0]*x[1];
}

View File

@@ -0,0 +1,45 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef _BEZIEREVAL_H
#define _BEZIEREVAL_H
void bezierCurveEval(float u0, float u1, int order, float* ctlpoints, int stride, int dimension, float u, float retpoint[]);
void bezierCurveEvalDer(float u0, float u1, int order, float* ctlpoints, int stride, int dimension, float u, float retDer[]);
void bezierCurveEvalDerGen(int der, float u0, float u1, int order, float* ctlpoints, int stride, int dimension, float u, float retDer[]);
void bezierSurfEvalDerGen(int uder, int vder, float u0, float u1, int uorder, float v0, float v1, int vorder, int dimension, float* ctlpoints, int ustride, int vstride, float u, float v, float ret[]);
void bezierSurfEval(float u0, float u1, int uorder, float v0, float v1, int vorder, int dimension, float* ctlpoints, int ustride, int vstride, float u, float v, float ret[]);
void bezierSurfEvalNormal(float u0, float u1, int uorder, float v0, float v1, int vorder, int dimension, float* ctlpoints, int ustride, int vstride, float u, float v, float retNormal[]);
#endif /* _BEZIEREVAL_H */

View File

@@ -0,0 +1,176 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "glues.h"
#include <stdlib.h>
#include <assert.h>
#include "bezierPatch.h"
#include "bezierEval.h"
/*
* allocate an instance of bezierPatch. The control points are unknown. But
* the space of this array is allocated with size of
* uorder*vorder*dimension
*
*/
bezierPatch* bezierPatchMake(float umin, float vmin, float umax, float vmax, int uorder, int vorder, int dimension)
{
bezierPatch* ret = (bezierPatch*) malloc(sizeof(bezierPatch));
assert(ret);
ret->umin=umin;
ret->vmin=vmin;
ret->umax=umax;
ret->vmax=vmax;
ret->uorder=uorder;
ret->vorder=vorder;
ret->dimension=dimension;
ret->ctlpoints=(float*)malloc(sizeof(float)*dimension*uorder*vorder);
assert(ret->ctlpoints);
ret->next=NULL;
return ret;
}
bezierPatch* bezierPatchMake2(float umin, float vmin, float umax, float vmax, int uorder, int vorder, int dimension, int ustride, int vstride, float* ctlpoints)
{
bezierPatch* ret=(bezierPatch*)malloc(sizeof(bezierPatch));
assert(ret);
ret->umin=umin;
ret->vmin=vmin;
ret->umax=umax;
ret->vmax=vmax;
ret->uorder=uorder;
ret->vorder=vorder;
ret->dimension=dimension;
ret->ctlpoints=(float*)malloc(sizeof(float)*dimension*uorder*vorder);
assert(ret->ctlpoints);
/* copy the control points there */
int the_ustride=vorder*dimension;
int the_vstride=dimension;
for(int i=0; i<uorder; i++)
{
for(int j=0; j<vorder; j++)
{
for(int k=0; k<dimension; k++)
{
ret->ctlpoints[i*the_ustride+j*the_vstride+k]=ctlpoints[i*ustride+j*vstride+k];
}
}
}
ret->next=NULL;
return ret;
}
/*
* deallocate the space as allocated by Make
*/
void bezierPatchDelete(bezierPatch* b)
{
free(b->ctlpoints);
free(b);
}
/* delete the whole linked list */
void bezierPatchDeleteList(bezierPatch* b)
{
bezierPatch* temp;
while (b!=NULL)
{
temp=b;
b=b->next;
bezierPatchDelete(temp);
}
}
bezierPatch* bezierPatchInsert(bezierPatch* list, bezierPatch* b)
{
b->next=list;
return b;
}
void bezierPatchEval(bezierPatch* b, float u, float v, float ret[])
{
if (u>=b->umin && u<=b->umax && v>=b->vmin && v<=b->vmax)
{
bezierSurfEval(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension*b->vorder, b->dimension, u, v, ret);
}
else
{
if (b->next!=NULL)
{
bezierPatchEval(b->next, u, v, ret);
}
else
{
bezierSurfEval(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension*b->vorder, b->dimension, u, v, ret);
}
}
}
/* the returned normal is normlized
*/
void bezierPatchEvalNormal(bezierPatch* b, float u, float v, float ret[])
{
bezierSurfEvalNormal(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret);
if (u>=b->umin && u<=b->umax && v>=b->vmin && v<=b->vmax)
{
bezierSurfEvalNormal(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret);
}
else
{
if (b->next!=NULL)
{
bezierPatchEvalNormal(b->next, u, v, ret);
}
else
{
bezierSurfEvalNormal(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret);
}
}
}

View File

@@ -0,0 +1,87 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef _BEZIERPATCH_H
#define _BEZIERPATCH_H
typedef struct bezierPatch
{
float umin, vmin, umax, vmax;
int uorder; /* order= degree + 1 */
int vorder;
/*
* the control points are stored in a one dimensional array.
* the surface is defined as:
* s(u,v) = sum_{i,j} P(i,j) * B_i(u) * B_j(v).
* where P(i,j) are the control points, B_i(.) are Bezier
* basis functions.
* Each control point can have dimension 3 or 4: (x,y,z,w).
* The components of P(i,j) are stored in a one dimensional
* array:
* ctlpoints[]
* in the order of:
* P[0,0], P[0,1], ..., P[0,vorder-1],
* P[1,0], P[1,1], ..., P[1,vorder-1],
* ...
* P[uorder-1,0], P[uorder-1,1], ..., P[uorder-1,vorder-1].
*/
int dimension;
float* ctlpoints;
/*
* in case we have to manage multiple bezierPatches.
*/
struct bezierPatch* next;
} bezierPatch;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bezierPatch* bezierPatchMake(float umin, float vmin, float umax, float vmax, int urder, int vorder, int dimension);
bezierPatch* bezierPatchMake2(float umin, float vmin, float umax, float vmax, int urder, int vorder, int dimension, int ustride, int vstride, float* ctlpoints);
bezierPatch* bezierPatchInsert(bezierPatch* list, bezierPatch* b);
void bezierPatchDelete(bezierPatch* b);
void bezierPatchDeleteList(bezierPatch* b);
void bezierPatchEval(bezierPatch* b, float u, float v, float ret[]);
void bezierPatchEvalNormal(bezierPatch* b, float u, float v, float retNormal[]);
void bezierPatchEval(bezierPatch* b, float u, float v, float ret[]);
void bezierPatchEvalNormal(bezierPatch* b, float u, float v, float ret[]);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _BEZIERPATCH_H */

View File

@@ -0,0 +1,588 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "glues.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "bezierEval.h"
#include "bezierPatchMesh.h"
#include "gles_evaluator.h"
static int isDegenerate(float A[2], float B[2], float C[2]);
void bezierPatchMeshListDelDeg(bezierPatchMesh* list)
{
bezierPatchMesh* temp;
for (temp=list; temp!=NULL; temp=temp->next)
{
bezierPatchMeshDelDeg(temp);
}
}
void bezierPatchMeshListDelete(bezierPatchMesh* list)
{
if (list==NULL)
{
return;
}
bezierPatchMeshListDelete(list->next);
bezierPatchMeshDelete(list);
}
bezierPatchMesh* bezierPatchMeshListReverse(bezierPatchMesh* list)
{
bezierPatchMesh* ret=NULL;
bezierPatchMesh* temp;
bezierPatchMesh* nextone;
for(temp=list; temp!=NULL; temp=nextone)
{
nextone=temp->next;
ret=bezierPatchMeshListInsert(ret, temp);
}
return ret;
}
/* maptype is either GLU_MAP2_VERTEX_3 or GLU_MAP2_VERTEX_4 */
bezierPatchMesh* bezierPatchMeshMake(int maptype, float umin, float umax, int ustride, int uorder, float vmin, float vmax, int vstride, int vorder, float* ctlpoints, int size_UVarray, int size_length_array)
{
int i, j, k;
int dimension;
int the_ustride;
int the_vstride;
if (maptype==GLU_MAP2_VERTEX_3)
{
dimension=3;
}
else
{
if (maptype==GLU_MAP2_VERTEX_4)
{
dimension = 4;
}
else
{
fprintf(stderr, "error in inMap2f, maptype=%i is wrong, maptype,map is invalid\n", maptype);
return NULL;
}
}
bezierPatchMesh* ret=(bezierPatchMesh*)malloc(sizeof(bezierPatchMesh));
assert(ret);
ret->bpatch_normal=NULL;
ret->bpatch_color=NULL;
ret->bpatch_texcoord=NULL;
ret->bpatch=bezierPatchMake(umin, vmin, umax, vmax, uorder, vorder, dimension);
/* copy the control points there */
the_ustride = vorder * dimension;
the_vstride = dimension;
for(i=0; i<uorder; i++)
{
for(j=0; j<vorder; j++)
{
for(k=0; k<dimension; k++)
{
ret->bpatch->ctlpoints[i*the_ustride+j*the_vstride+k]=ctlpoints[i*ustride+j*vstride+k];
}
}
}
ret->size_UVarray=size_UVarray;
ret->size_length_array=size_length_array;
ret->UVarray=(float*)malloc(sizeof(float)*size_UVarray);
assert(ret->UVarray);
ret->length_array=(int*)malloc(sizeof(int)*size_length_array);
assert(ret->length_array);
ret->type_array=(GLenum*)malloc(sizeof(GLenum)*size_length_array);
assert(ret->type_array);
ret->index_UVarray=0;
ret->index_length_array=0;
ret->vertex_array=NULL;
ret->normal_array=NULL;
ret->color_array=NULL;
ret->texcoord_array=NULL;
ret->next=NULL;
return ret;
}
bezierPatchMesh* bezierPatchMeshMake2(int size_UVarray, int size_length_array)
{
bezierPatchMesh* ret=(bezierPatchMesh*)malloc(sizeof(bezierPatchMesh));
assert(ret);
ret->bpatch=NULL;
ret->bpatch_normal=NULL;
ret->bpatch_color=NULL;
ret->bpatch_texcoord=NULL;
ret->size_UVarray=size_UVarray;
ret->size_length_array=size_length_array;
ret->UVarray=(float*)malloc(sizeof(float)*size_UVarray);
assert(ret->UVarray);
ret->length_array=(int*)malloc(sizeof(int)*size_length_array);
assert(ret->length_array);
ret->type_array=(GLenum*)malloc(sizeof(GLenum)*size_length_array);
assert(ret->type_array);
ret->index_UVarray=0;
ret->index_length_array=0;
ret->vertex_array=NULL;
ret->normal_array=NULL;
ret->color_array=NULL;
ret->texcoord_array=NULL;
ret->next=NULL;
return ret;
}
void bezierPatchMeshPutPatch(bezierPatchMesh* bpm, int maptype, float umin, float umax, int ustride, int uorder, float vmin, float vmax, int vstride, int vorder, float* ctlpoints)
{
switch(maptype)
{
case GLU_MAP2_VERTEX_3:
bpm->bpatch=bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 3, ustride, vstride, ctlpoints);
break;
case GLU_MAP2_VERTEX_4:
bpm->bpatch=bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 4,ustride, vstride, ctlpoints);
break;
case GLU_MAP2_NORMAL:
bpm->bpatch_normal=bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 3, ustride, vstride, ctlpoints);
break;
case GLU_MAP2_INDEX:
bpm->bpatch_color=bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 1, ustride, vstride, ctlpoints);
break;
case GLU_MAP2_COLOR_4:
bpm->bpatch_color=bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 4, ustride, vstride, ctlpoints);
break;
case GLU_MAP2_TEXTURE_COORD_1:
bpm->bpatch_texcoord=bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 1, ustride, vstride, ctlpoints);
break;
case GLU_MAP2_TEXTURE_COORD_2:
bpm->bpatch_texcoord=bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 2, ustride, vstride, ctlpoints);
break;
case GLU_MAP2_TEXTURE_COORD_3:
bpm->bpatch_texcoord=bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 3, ustride, vstride, ctlpoints);
break;
case GLU_MAP2_TEXTURE_COORD_4:
bpm->bpatch_texcoord=bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 4, ustride, vstride, ctlpoints);
break;
default:
fprintf(stderr, "error in bezierPatchMeshPutPatch, maptype=%i is wrong, maptype,map is invalid\n", maptype);
}
}
/* delete everything including the arrays. So if you want to output the
* pointers of the arrays, you should not use this function to deallocate space.
* you should dealocate manually
*/
void bezierPatchMeshDelete(bezierPatchMesh* bpm)
{
if(bpm->bpatch!=NULL)
{
bezierPatchDelete(bpm->bpatch);
}
if (bpm->bpatch_normal!=NULL)
{
bezierPatchDelete(bpm->bpatch_normal);
}
if (bpm->bpatch_color!=NULL)
{
bezierPatchDelete(bpm->bpatch_color);
}
if (bpm->bpatch_texcoord!=NULL)
{
bezierPatchDelete(bpm->bpatch_texcoord);
}
free(bpm->UVarray);
free(bpm->length_array);
free(bpm->vertex_array);
free(bpm->normal_array);
free(bpm->type_array);
free(bpm);
}
/* begin a strip
* type is the primitive type:
*/
void bezierPatchMeshBeginStrip(bezierPatchMesh* bpm, GLenum type)
{
bpm->counter=0;
bpm->type=type;
}
/* signal the end of the current strip */
void bezierPatchMeshEndStrip(bezierPatchMesh* bpm)
{
int i;
/* if there are no vertices in this strip, then nothing needs to be done */
if (bpm->counter==0)
{
return;
}
/* if the length_array is full, it should be expanded */
if(bpm->index_length_array>=bpm->size_length_array)
{
int* temp=(int*)malloc(sizeof(int)*(bpm->size_length_array*2+1));
assert(temp);
GLenum* temp_type=(GLenum*)malloc(sizeof(GLenum)*(bpm->size_length_array*2+1));
assert(temp_type);
/* update the size */
bpm->size_length_array = bpm->size_length_array*2 + 1;
/* copy */
for(i=0; i<bpm->index_length_array; i++)
{
temp[i]=bpm->length_array[i];
temp_type[i]=bpm->type_array[i];
}
/* deallocate old array */
free(bpm->length_array);
free(bpm->type_array);
/* point to the new array which is twice as bigger */
bpm->length_array=temp;
bpm->type_array=temp_type;
}
bpm->type_array[bpm->index_length_array]=bpm->type;
bpm->length_array[bpm->index_length_array++]=bpm->counter;
}
/* insert (u,v) */
void bezierPatchMeshInsertUV(bezierPatchMesh* bpm, float u, float v)
{
int i;
/* if the UVarray is full, it should be expanded */
if (bpm->index_UVarray+1>=bpm->size_UVarray)
{
float* temp=(float*)malloc(sizeof(float)*(bpm->size_UVarray*2+2));
assert(temp);
/* update the size */
bpm->size_UVarray=bpm->size_UVarray*2+2;
/* copy */
for (i=0; i<bpm->index_UVarray; i++)
{
temp[i]=bpm->UVarray[i];
}
/* deallocate old array */
free(bpm->UVarray);
/* pointing to the new arrays */
bpm->UVarray=temp;
}
/*insert the new UV*/
bpm->UVarray[bpm->index_UVarray]=u;
bpm->index_UVarray++;
bpm->UVarray[bpm->index_UVarray]=v;
bpm->index_UVarray++;
/* update counter: one more vertex */
bpm->counter++;
}
/* insert a new patch in front of the current linked list and return the new list */
bezierPatchMesh* bezierPatchMeshListInsert(bezierPatchMesh* list, bezierPatchMesh* bpm)
{
bpm->next=list;
return bpm;
}
int bezierPatchMeshListTotalStrips(bezierPatchMesh* list)
{
int sum=0;
bezierPatchMesh* temp;
for(temp=list; temp!=NULL; temp=temp->next)
{
sum+=temp->index_length_array;
}
return sum;
}
int bezierPatchMeshListTotalVert(bezierPatchMesh* list)
{
int sum=0;
bezierPatchMesh* temp;
for(temp=list; temp!=NULL; temp=temp->next)
{
sum+=temp->index_UVarray;
}
return sum/2;
}
int bezierPatchMeshListNumTriangles(bezierPatchMesh* list)
{
int sum=0;
bezierPatchMesh* temp;
for(temp=list; temp!=NULL; temp=temp->next)
{
sum+=bezierPatchMeshNumTriangles(temp);
}
return sum;
}
int bezierPatchMeshNumTriangles(bezierPatchMesh* bpm)
{
int i;
int sum=0;
for(i=0; i<bpm->index_length_array; i++)
{
switch(bpm->type_array[i])
{
case GL_TRIANGLES:
sum+=bpm->length_array[i]/3;
break;
case GL_TRIANGLE_FAN:
if (bpm->length_array[i]>2)
{
sum+=bpm->length_array[i]-2;
}
break;
case GL_TRIANGLE_STRIP:
if(bpm->length_array[i]>2)
{
sum+=bpm->length_array[i]-2;
}
break;
default:
fprintf(stderr, "error in bezierPatchMeshListNumTriangles, type invalid\n");
break;
}
}
return sum;
}
/*delete degenerate triangles*/
void bezierPatchMeshDelDeg(bezierPatchMesh* bpm)
{
if (bpm==NULL)
{
return;
}
int i, j, k;
int* new_length_array;
GLenum* new_type_array;
int index_new_length_array;
float* new_UVarray;
int index_new_UVarray;
new_length_array=(int*)malloc(sizeof(int)*bpm->index_length_array);
assert(new_length_array);
new_type_array=(GLenum*)malloc(sizeof(GLenum)*bpm->index_length_array);
assert(new_length_array);
new_UVarray=(float*)malloc(sizeof(float)*bpm->index_UVarray);
assert(new_UVarray);
index_new_length_array=0;
index_new_UVarray=0;
k=0;
for(i=0; i<bpm->index_length_array; i++)
{
/* (if not degenerate, we have to copy */
if ((bpm->length_array[i]!=3) || (!isDegenerate(bpm->UVarray+k, bpm->UVarray+k+2, bpm->UVarray+k+4)))
{
for(j=0; j<2*bpm->length_array[i]; j++)
{
new_UVarray[index_new_UVarray++]=bpm->UVarray[k++];
}
new_length_array[index_new_length_array]=bpm->length_array[i];
new_type_array[index_new_length_array]=bpm->type_array[i];
index_new_length_array++;
}
else
{
k+=6;
}
}
free(bpm->UVarray);
free(bpm->length_array);
free(bpm->type_array);
bpm->UVarray=new_UVarray;
bpm->length_array=new_length_array;
bpm->type_array=new_type_array;
bpm->index_UVarray=index_new_UVarray;
bpm->index_length_array=index_new_length_array;
}
/* (u,v) to XYZ
* the xyz and normals are stored in vertex_array,
* and normal_array. the spaces of both are allocated here
*/
void bezierPatchMeshEval(bezierPatchMesh* bpm)
{
int i, j, k, l;
float u, v;
float u0=bpm->bpatch->umin;
float u1=bpm->bpatch->umax;
int uorder=bpm->bpatch->uorder;
float v0=bpm->bpatch->vmin;
float v1=bpm->bpatch->vmax;
int vorder=bpm->bpatch->vorder;
int dimension=bpm->bpatch->dimension;
int ustride=dimension*vorder;
int vstride=dimension;
float* ctlpoints=bpm->bpatch->ctlpoints;
bpm->vertex_array=(float*)malloc(sizeof(float)*(bpm->index_UVarray/2)*3);
assert(bpm->vertex_array);
bpm->normal_array=(float*)malloc(sizeof(float)*(bpm->index_UVarray/2)*3);
assert(bpm->normal_array);
k=0;
l=0;
for (i=0; i<bpm->index_length_array; i++)
{
for(j=0; j<bpm->length_array[i]; j++)
{
u=bpm->UVarray[k];
v=bpm->UVarray[k+1];
bezierSurfEval(u0, u1, uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u, v, bpm->vertex_array+l);
bezierSurfEvalNormal(u0, u1, uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u, v, bpm->normal_array+l);
k+=2;
l+=3;
}
}
}
void bezierPatchMeshListEval(bezierPatchMesh* list)
{
bezierPatchMesh* temp;
for(temp=list; temp!=NULL; temp=temp->next)
{
bezierPatchMeshEval(temp);
}
}
void bezierPatchMeshListCollect(bezierPatchMesh* list, float** vertex_array, float** normal_array, int** length_array, GLenum** type_array, int* num_strips)
{
int i, j, k, l;
bezierPatchMesh* temp;
int total_num_vertices=bezierPatchMeshListTotalVert(list);
(*vertex_array)=(float*)malloc(sizeof(float)*total_num_vertices*3);
assert(*vertex_array);
(*normal_array)=(float*)malloc(sizeof(float)*total_num_vertices*3);
assert(*normal_array);
*num_strips=bezierPatchMeshListTotalStrips(list);
*length_array=(int*)malloc(sizeof(int)*(*num_strips));
assert(*length_array);
*type_array=(GLenum*)malloc(sizeof(GLenum)*(*num_strips));
assert(*type_array);
k=0;
l=0;
for(temp=list; temp!=NULL; temp=temp->next)
{
int x=0;
for(i=0; i<temp->index_length_array; i++)
{
for(j=0; j<temp->length_array[i]; j++)
{
(*vertex_array)[k]=temp->vertex_array[x];
(*vertex_array)[k+1]=temp->vertex_array[x+1];
(*vertex_array)[k+2]=temp->vertex_array[x+2];
(*normal_array)[k]=temp->normal_array[x];
(*normal_array)[k+1]=temp->normal_array[x+1];
(*normal_array)[k+2]=temp->normal_array[x+2];
x+=3;
k+=3;
}
(*type_array)[l]=temp->type_array[i];
(*length_array)[l++]=temp->length_array[i];
}
}
}
static int isDegenerate(float A[2], float B[2], float C[2])
{
if ((A[0]==B[0] && A[1]==B[1]) ||
(A[0]==C[0] && A[1]==C[1]) ||
(B[0]==C[0] && B[1]==C[1]))
{
return 1;
}
else
{
return 0;
}
}

View File

@@ -0,0 +1,106 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef _BEZIERPATCHMESH_H
#define _BEZIERPATCHMESH_H
#include "bezierPatch.h"
typedef struct bezierPatchMesh
{
bezierPatch* bpatch; /* vertex */
bezierPatch* bpatch_normal;
bezierPatch* bpatch_texcoord; /* s,t,r,q */
bezierPatch* bpatch_color; /* RGBA */
float* UVarray; /* all UV components of all vertices of all strips */
int* length_array; /* [i] is the number of vertices in the ith strip */
GLenum* type_array; /* [i] is the type of the ith primitive */
/* to support dynamic insertion */
int size_UVarray;
int index_UVarray;
int size_length_array;
int index_length_array;
int counter; /* track the current strip size */
GLenum type; /* track the current type: 0: GL_TRIANGLES, 1: GL_TRIANGLE_STRIP */
/* we eventually want to evaluate from (u,v) to (x,y,z) and draw them */
float* vertex_array; /* each vertex contains three components */
float* normal_array; /* each normal contains three components */
float* color_array;
float* texcoord_array;
/*in case we need a linked list*/
struct bezierPatchMesh* next;
} bezierPatchMesh;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
bezierPatchMesh* bezierPatchMeshMake(int maptype, float umin, float umax, int ustride, int uorder, float vmin, float vmax, int vstride, int vorder, float *ctlpoints, int size_UVarray, int size_length_array);
/*initilize patches to be null*/
bezierPatchMesh* bezierPatchMeshMake2(int size_UVarray, int size_length_array);
void bezierPatchMeshPutPatch(bezierPatchMesh* bpm, int maptype, float umin, float umax, int ustride, int uorder, float vmin, float vmax, int vstride, int vorder, float* ctlpoints);
void bezierPatchMeshDelete(bezierPatchMesh* bpm);
void bezierPatchMeshBeginStrip(bezierPatchMesh* bpm, GLenum type);
void bezierPatchMeshEndStrip(bezierPatchMesh* bpm);
void bezierPatchMeshInsertUV(bezierPatchMesh* bpm, float u, float v);
bezierPatchMesh* bezierPatchMeshListInsert(bezierPatchMesh* list, bezierPatchMesh* bpm);
int bezierPatchMeshListTotalStrips(bezierPatchMesh* list);
int bezierPatchMeshListTotalVert(bezierPatchMesh* list);
int bezierPatchMeshNumTriangles(bezierPatchMesh* bpm);
int bezierPatchMeshListNumTriangles(bezierPatchMesh* list);
void bezierPatchMeshDelDeg(bezierPatchMesh* bpm);
void bezierPatchMeshEval(bezierPatchMesh* bpm);
void bezierPatchMeshListEval(bezierPatchMesh* list);
void bezierPatchMeshListCollect(bezierPatchMesh* list, float** vertex_array, float** normal_array, int** length_array, GLenum** type_array, int* num_strips);
void bezierPatchMeshListDelDeg(bezierPatchMesh* list);
void bezierPatchMeshListDelete(bezierPatchMesh* list);
bezierPatchMesh* bezierPatchMeshListReverse(bezierPatchMesh* list);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _BEZIERPATCHMESH_H */

View File

@@ -0,0 +1,459 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
/* Polynomial Evaluator Interface */
#include "glues.h"
#include "gles_evaluator.h"
#include "glimports.h"
#include "glrenderer.h"
#include "glcurveval.h"
#include "nurbsconsts.h"
OpenGLCurveEvaluator::OpenGLCurveEvaluator(void)
{
// no default callback functions
beginCallBackN=NULL;
endCallBackN=NULL;
vertexCallBackN=NULL;
normalCallBackN=NULL;
colorCallBackN=NULL;
texcoordCallBackN=NULL;
beginCallBackData=NULL;
endCallBackData=NULL;
vertexCallBackData=NULL;
normalCallBackData=NULL;
colorCallBackData=NULL;
texcoordCallBackData=NULL;
userData=NULL;
vertex_flag=0;
normal_flag=0;
color_flag=0;
texcoord_flag=0;
em_vertex.uprime=-1.0;
em_normal.uprime=-1.0;
em_color.uprime=-1.0;
em_texcoord.uprime=-1.0;
// don't output triangles by default
output_triangles=0;
}
OpenGLCurveEvaluator::~OpenGLCurveEvaluator(void)
{
}
/* added nonsense to avoid the warning messages at compile time */
void OpenGLCurveEvaluator::addMap(CurveMap* m)
{
m=m;
}
void OpenGLCurveEvaluator::range1f(long type, REAL* from, REAL* to)
{
type=type;
from=from;
to=to;
}
void OpenGLCurveEvaluator::domain1f(REAL ulo, REAL uhi)
{
ulo=ulo;
uhi=uhi;
}
void OpenGLCurveEvaluator::bgnline(void)
{
if (output_triangles)
{
beginCallBack(GL_LINE_STRIP, userData);
}
}
void OpenGLCurveEvaluator::endline(void)
{
if (output_triangles)
{
endCallBack(userData);
}
}
/*---------------------------------------------------------------------------
* disable - turn off a curve map
*---------------------------------------------------------------------------
*/
void OpenGLCurveEvaluator::disable(long type)
{
gluDisable((GLenum)type);
}
/*---------------------------------------------------------------------------
* enable - turn on a curve map
*---------------------------------------------------------------------------
*/
void OpenGLCurveEvaluator::enable(long type)
{
gluEnable((GLenum)type);
}
/*-------------------------------------------------------------------------
* mapgrid1f - define a lattice of points with origin and offset
*-------------------------------------------------------------------------
*/
void OpenGLCurveEvaluator::mapgrid1f(long nu, REAL u0, REAL u1)
{
if (output_triangles)
{
global_grid_u0=u0;
global_grid_u1=u1;
global_grid_nu=(int)nu;
}
else
{
global_grid_u0=u0;
global_grid_u1=u1;
global_grid_nu=(int)nu;
}
}
/*-------------------------------------------------------------------------
* bgnmap1 - preamble to curve definition and evaluations
*-------------------------------------------------------------------------
*/
void OpenGLCurveEvaluator::bgnmap1f(long)
{
if (output_triangles)
{
// initialized so that no maps are set initially
vertex_flag=0;
normal_flag=0;
color_flag=0;
texcoord_flag=0;
}
}
/*-------------------------------------------------------------------------
* endmap1 - postamble to a curve map
*-------------------------------------------------------------------------
*/
void OpenGLCurveEvaluator::endmap1f(void)
{
if (output_triangles)
{
}
}
/*-------------------------------------------------------------------------
* map1f - pass a desription of a curve map
*-------------------------------------------------------------------------
*/
void OpenGLCurveEvaluator::map1f(long type, /* map type */
REAL ulo, /* lower parametric bound */
REAL uhi, /* upper parametric bound */
long stride, /* distance to next point in REALS */
long order, /* parametric order */
REAL* pts) /* control points */
{
if (output_triangles)
{
int dimension=0;
int which=0;
switch(type)
{
case GLU_MAP1_VERTEX_3:
which=0;
dimension=3;
break;
case GLU_MAP1_VERTEX_4:
which=0;
dimension=4;
break;
case GLU_MAP1_INDEX:
which=2;
dimension=1;
break;
case GLU_MAP1_COLOR_4:
which=2;
dimension=4;
break;
case GLU_MAP1_NORMAL:
which=1;
dimension=3;
break;
case GLU_MAP1_TEXTURE_COORD_1:
which=3;
dimension=1;
break;
case GLU_MAP1_TEXTURE_COORD_2:
which=3;
dimension=2;
break;
case GLU_MAP1_TEXTURE_COORD_3:
which=3;
dimension=3;
break;
case GLU_MAP1_TEXTURE_COORD_4:
which=3;
dimension=4;
break;
}
inMap1f(which, dimension, ulo, uhi, stride, order, pts);
}
else
{
int dimension=0;
int which=0;
switch(type)
{
case GLU_MAP1_VERTEX_3:
which=0;
dimension=3;
break;
case GLU_MAP1_VERTEX_4:
which=0;
dimension=4;
break;
case GLU_MAP1_INDEX:
which=2;
dimension=1;
break;
case GLU_MAP1_COLOR_4:
which=2;
dimension=4;
break;
case GLU_MAP1_NORMAL:
which=1;
dimension=3;
break;
case GLU_MAP1_TEXTURE_COORD_1:
which=3;
dimension=1;
break;
case GLU_MAP1_TEXTURE_COORD_2:
which=3;
dimension=2;
break;
case GLU_MAP1_TEXTURE_COORD_3:
which=3;
dimension=3;
break;
case GLU_MAP1_TEXTURE_COORD_4:
which=3;
dimension=4;
break;
}
inMap1fr(which, dimension, ulo, uhi, stride, order, pts);
}
}
/*-------------------------------------------------------------------------
* mapmesh1f - evaluate a mesh of points on lattice
*-------------------------------------------------------------------------
*/
void OpenGLCurveEvaluator::mapmesh1f(long style, long from, long to)
{
output_style=style;
if (output_triangles)
{
inMapMesh1f((int)from, (int)to);
}
else
{
inMapMesh1fr((int)from, (int)to);
}
}
/*-------------------------------------------------------------------------
* evalpoint1i - evaluate a point on a curve
*-------------------------------------------------------------------------
*/
void OpenGLCurveEvaluator::evalpoint1i(long i)
{
}
/*-------------------------------------------------------------------------
* evalcoord1f - evaluate a point on a curve
*-------------------------------------------------------------------------
*/
void OpenGLCurveEvaluator::evalcoord1f(long, REAL u)
{
}
void
#ifdef _WIN32
OpenGLCurveEvaluator::putCallBack(GLenum which, void (APIENTRY *fn)())
#else
OpenGLCurveEvaluator::putCallBack(GLenum which, _GLUfuncptr fn)
#endif
{
switch (which)
{
case GLU_NURBS_BEGIN:
beginCallBackN=(void (APIENTRY*)(GLenum))fn;
break;
case GLU_NURBS_END:
endCallBackN=(void (APIENTRY*)(void))fn;
break;
case GLU_NURBS_VERTEX:
vertexCallBackN=(void (APIENTRY*)(const GLfloat*))fn;
break;
case GLU_NURBS_NORMAL:
normalCallBackN=(void (APIENTRY*)(const GLfloat*))fn;
break;
case GLU_NURBS_COLOR:
colorCallBackN=(void (APIENTRY *)(const GLfloat*))fn;
break;
case GLU_NURBS_TEXTURE_COORD:
texcoordCallBackN=(void (APIENTRY*)(const GLfloat*))fn;
break;
case GLU_NURBS_BEGIN_DATA:
beginCallBackData=(void (APIENTRY*)(GLenum, void*))fn;
break;
case GLU_NURBS_END_DATA:
endCallBackData=(void (APIENTRY*)(void*))fn;
break;
case GLU_NURBS_VERTEX_DATA:
vertexCallBackData=(void (APIENTRY*)(const GLfloat*, void*))fn;
break;
case GLU_NURBS_NORMAL_DATA:
normalCallBackData=(void (APIENTRY*)(const GLfloat*, void*))fn;
break;
case GLU_NURBS_COLOR_DATA:
colorCallBackData=(void (APIENTRY*)(const GLfloat*, void*))fn;
break;
case GLU_NURBS_TEXTURE_COORD_DATA:
texcoordCallBackData=(void (APIENTRY*)(const GLfloat*, void*))fn;
break;
}
}
void OpenGLCurveEvaluator::beginCallBack(GLenum which, void* data)
{
if (beginCallBackData)
{
beginCallBackData(which, data);
}
else
{
if (beginCallBackN)
{
beginCallBackN(which);
}
}
}
void OpenGLCurveEvaluator::endCallBack(void* data)
{
if (endCallBackData)
{
endCallBackData(data);
}
else
{
if (endCallBackN)
{
endCallBackN();
}
}
}
void OpenGLCurveEvaluator::vertexCallBack(const GLfloat* vert, void* data)
{
if (vertexCallBackData)
{
vertexCallBackData(vert, data);
}
else
{
if (vertexCallBackN)
{
vertexCallBackN(vert);
}
}
}
void OpenGLCurveEvaluator::normalCallBack(const GLfloat* normal, void* data)
{
if (normalCallBackData)
{
normalCallBackData(normal, data);
}
else
{
if (normalCallBackN)
{
normalCallBackN(normal);
}
}
}
void OpenGLCurveEvaluator::colorCallBack(const GLfloat* color, void* data)
{
if (colorCallBackData)
{
colorCallBackData(color, data);
}
else
{
if (colorCallBackN)
{
colorCallBackN(color);
}
}
}
void OpenGLCurveEvaluator::texcoordCallBack(const GLfloat* texcoord, void* data)
{
if (texcoordCallBackData)
{
texcoordCallBackData(texcoord, data);
}
else
{
if (texcoordCallBackN)
{
texcoordCallBackN(texcoord);
}
}
}

View File

@@ -0,0 +1,154 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __gluglcurveval_h_
#define __gluglcurveval_h_
#include "glues.h"
#include "basiccrveval.h"
class CurveMap;
/*for internal evaluator callback stuff*/
#ifndef IN_MAX_BEZIER_ORDER
#define IN_MAX_BEZIER_ORDER 40 /* XXX should be bigger than machine order */
#endif
#ifndef IN_MAX_DIMENSION
#define IN_MAX_DIMENSION 4
#endif
typedef struct curveEvalMachine
{
REAL uprime; // cached previously evaluated uprime
int k; // the dimension
REAL u1;
REAL u2;
int ustride;
int uorder;
REAL ctlpoints[IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION];
REAL ucoeff[IN_MAX_BEZIER_ORDER]; // cache the polynomial values
} curveEvalMachine;
class OpenGLCurveEvaluator: public BasicCurveEvaluator
{
long output_style; // N_MESHFILL or N_MESHLINE or N_MESHPOINT
public:
OpenGLCurveEvaluator(void);
virtual ~OpenGLCurveEvaluator(void);
void range1f(long, REAL*, REAL*);
void domain1f(REAL, REAL);
void addMap(CurveMap*);
void enable(long);
void disable(long);
void bgnmap1f(long);
void map1f(long, REAL, REAL, long, long, REAL*);
void mapgrid1f(long, REAL, REAL);
void mapmesh1f(long, long, long);
void evalpoint1i(long);
void evalcoord1f(long, REAL);
void endmap1f(void);
void bgnline(void);
void endline(void);
void put_vertices_call_back(int flag)
{
output_triangles=flag;
}
#ifdef _WIN32
void putCallBack(GLenum which, void (APIENTRY* fn)());
#else
void putCallBack(GLenum which, _GLUfuncptr fn);
#endif
void set_callback_userData(void* data)
{
userData=data;
}
/*------------------begin for curveEvalMachine------------*/
curveEvalMachine em_vertex;
curveEvalMachine em_normal;
curveEvalMachine em_color;
curveEvalMachine em_texcoord;
int vertex_flag; // whether there is a vertex map or not
int normal_flag; // whether there is a normal map or not
int color_flag; // whether there is a color map or not
int texcoord_flag; // whether there is a texture map or not
REAL global_grid_u0;
REAL global_grid_u1;
int global_grid_nu;
void inMap1f(int which, int dimension, REAL ulower, REAL uupper, int ustride, int uorder, REAL* ctlpoints);
void inMap1fr(int which, int dimension, REAL ulower, REAL uupper, int ustride, int uorder, REAL* ctlpoints);
void inPreEvaluate(int order, REAL vprime, REAL* coeff);
void inDoDomain1(curveEvalMachine* em, REAL u, REAL* retPoint);
void inDoEvalCoord1(REAL u);
void inDoEvalCoord1r(REAL u, REAL* retPoint);
void inMapMesh1f(int umin, int umax);
void inMapMesh1fr(int umin, int umax);
void (APIENTRY* beginCallBackN)(GLenum type);
void (APIENTRY* endCallBackN)(void);
void (APIENTRY* vertexCallBackN)(const GLfloat* vert);
void (APIENTRY* normalCallBackN)(const GLfloat* normal);
void (APIENTRY* colorCallBackN)(const GLfloat* color);
void (APIENTRY* texcoordCallBackN)(const GLfloat* texcoord);
void (APIENTRY* beginCallBackData)(GLenum type, void* data);
void (APIENTRY* endCallBackData)(void* data);
void (APIENTRY* vertexCallBackData)(const GLfloat* vert, void* data);
void (APIENTRY* normalCallBackData)(const GLfloat* normal, void* data);
void (APIENTRY* colorCallBackData)(const GLfloat* color, void* data);
void (APIENTRY* texcoordCallBackData)(const GLfloat* texcoord, void* data);
void* userData; // the opaque pointer for Data callback functions
void beginCallBack(GLenum type, void* data);
void endCallBack(void* data);
void vertexCallBack(const GLfloat* vert, void *data);
void normalCallBack(const GLfloat* normal, void* data);
void colorCallBack(const GLfloat* color, void* data);
void texcoordCallBack(const GLfloat* texcoord, void* data);
/*------------------end for curveEvalMachine------------*/
private:
int output_triangles; // true 1; false 0
};
#endif /* __gluglcurveval_h_ */

View File

@@ -0,0 +1,268 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* gles_evaluator.cc
* Author: Mike Gorchak, 2009. mike@malva.ua, lestat@i.com.ua
*
*/
#include "glues.h"
#include "gles_evaluator.h"
#include <memory.h>
#include <stdio.h>
GLAPI void APIENTRY gluEnable(GLenum cap)
{
switch (cap)
{
case GLU_MAP1_COLOR_4:
case GLU_MAP1_INDEX:
case GLU_MAP1_NORMAL:
case GLU_MAP1_TEXTURE_COORD_1:
case GLU_MAP1_TEXTURE_COORD_2:
case GLU_MAP1_TEXTURE_COORD_3:
case GLU_MAP1_TEXTURE_COORD_4:
case GLU_MAP1_VERTEX_3:
case GLU_MAP1_VERTEX_4:
case GLU_MAP2_COLOR_4:
case GLU_MAP2_INDEX:
case GLU_MAP2_NORMAL:
case GLU_MAP2_TEXTURE_COORD_1:
case GLU_MAP2_TEXTURE_COORD_2:
case GLU_MAP2_TEXTURE_COORD_3:
case GLU_MAP2_TEXTURE_COORD_4:
case GLU_MAP2_VERTEX_3:
case GLU_MAP2_VERTEX_4:
case GLU_AUTO_NORMAL:
break;
default:
glEnable(cap);
break;
}
}
GLAPI void APIENTRY gluDisable(GLenum cap)
{
switch (cap)
{
case GLU_MAP1_COLOR_4:
case GLU_MAP1_INDEX:
case GLU_MAP1_NORMAL:
case GLU_MAP1_TEXTURE_COORD_1:
case GLU_MAP1_TEXTURE_COORD_2:
case GLU_MAP1_TEXTURE_COORD_3:
case GLU_MAP1_TEXTURE_COORD_4:
case GLU_MAP1_VERTEX_3:
case GLU_MAP1_VERTEX_4:
case GLU_MAP2_COLOR_4:
case GLU_MAP2_INDEX:
case GLU_MAP2_NORMAL:
case GLU_MAP2_TEXTURE_COORD_1:
case GLU_MAP2_TEXTURE_COORD_2:
case GLU_MAP2_TEXTURE_COORD_3:
case GLU_MAP2_TEXTURE_COORD_4:
case GLU_MAP2_VERTEX_3:
case GLU_MAP2_VERTEX_4:
case GLU_AUTO_NORMAL:
break;
default:
glDisable(cap);
break;
}
}
GLfloat lg2table[63]=
{
0.0000000004656612873077392578125f,
0.000000000931322574615478515625f,
0.00000000186264514923095703125f,
0.0000000037252902984619140625f,
0.000000007450580596923828125f,
0.00000001490116119384765625f,
0.0000000298023223876953125f,
0.000000059604644775390625f,
0.00000011920928955078125f,
0.0000002384185791015625f,
0.000000476837158203125f,
0.00000095367431640625f,
0.0000019073486328125f,
0.000003814697265625f,
0.00000762939453125f,
0.0000152587890625f,
0.000030517578125f,
0.00006103515625f,
0.0001220703125f,
0.000244140625f,
0.00048828125f,
0.0009765625f,
0.001953125f, /* 1/512 */
0.00390625f, /* 1/256 */
0.0078125f, /* 1/128 */
0.015625f, /* 1/64 */
0.03125f, /* 1/32 */
0.0625f, /* 1/16 */
0.125f, /* 1/8 */
0.25f, /* 1/4 */
0.5f, /* 1/2 */
0x00000001, /* zero */
0x00000002,
0x00000004,
0x00000008,
0x00000010,
0x00000020,
0x00000040,
0x00000080,
0x00000100,
0x00000200,
0x00000400,
0x00000800,
0x00001000,
0x00002000,
0x00004000,
0x00008000,
0x00010000,
0x00020000,
0x00040000,
0x00080000,
0x00100000,
0x00200000,
0x00400000,
0x00800000,
0x01000000,
0x02000000,
0x04000000,
0x08000000,
0x10000000,
0x20000000,
0x40000000,
0x80000000
};
GLAPI void APIENTRY gluGetFloatv(GLenum pname, GLfloat* params)
{
switch (pname)
{
case GL_MODELVIEW_MATRIX:
case GL_PROJECTION_MATRIX:
/* Check if OpenGL ES 1.1 is used, then call glGetFloatv directly */
#if defined(GL_VERSION_ES_CM_1_1)
/* Just passthrough the request to OpenGL ES 1.1 */
glGetFloatv(pname, params);
return;
#endif /* GL_VERSION_ES_CM_1_1 */
/* Check if OpenGL ES 1.0 is used, then try to emulate glGetFloatv */
#if (defined(GL_OES_VERSION_1_0) || defined(GL_VERSION_ES_CM_1_0)) && !defined(GL_VERSION_ES_CM_1_1)
/* Check for query_matrix extension, which is very usefull in OpenGL ES 1.0 to obtain */
/* GLES 1.0 dynamic state */
#if defined(GL_OES_query_matrix)
{
GLfixed mantissa[16];
GLint exponent[16];
/* Clear the output data, in case if glQueryMatrixxOES() will fail */
memset(params, 0x00, 16*sizeof(GLfloat));
/* Since OpenGL ES 1.0 has no GL_MATRIX_MODE for glGet() we will try to setup */
/* required matrix and then restore modelview matrix, because it must be default */
/* current matrix mode for rendering process. */
switch (pname)
{
case GL_MODELVIEW_MATRIX:
glMatrixMode(GL_MODELVIEW);
break;
case GL_PROJECTION_MATRIX:
glMatrixMode(GL_PROJECTION);
break;
}
/* Query current matrix content */
if (glQueryMatrixxOES(mantissa, exponent)==0)
{
for (int it=0; it<16; it++)
{
params[it]=FX2F(mantissa[it])*lg2table[exponent[it]+31];
}
}
/* Restore "default" matrix mode */
glMatrixMode(GL_MODELVIEW);
}
#else
#error "Do not know how to query modelview and projection matrices"
#endif /* GL_OES_query_matrix */
#endif /* GL_OES_VERSION_1_0 or GL_VERSION_ES_CM_1_0 only */
break;
}
#if defined(GL_VERSION_ES_CM_1_1)
/* Just passthrough the request to OpenGL ES 1.1 */
/* In OpenGL ES 1.0 all other Float requests will be ignored */
glGetFloatv(pname, params);
#endif /* GL_VERSION_ES_CM_1_1 */
}
GLint glu_viewport[4];
GLAPI void APIENTRY gluGetIntegerv(GLenum pname, GLint* params)
{
switch (pname)
{
case GL_VIEWPORT:
#if (defined(GL_OES_VERSION_1_0) || defined(GL_VERSION_ES_CM_1_0)) && !defined(GL_VERSION_ES_CM_1_1)
params[0]=glu_viewport[0];
params[1]=glu_viewport[1];
params[2]=glu_viewport[2];
params[3]=glu_viewport[3];
return;
#endif /* GL_OES_VERSION_1_0 or GL_VERSION_ES_CM_1_0 only */
break;
}
glGetIntegerv(pname, params);
}
GLAPI void APIENTRY gluViewport(GLint x, GLint y, GLsizei width, GLsizei height)
{
glu_viewport[0]=x;
glu_viewport[1]=y;
glu_viewport[2]=(GLint)width;
glu_viewport[3]=(GLint)height;
}

View File

@@ -0,0 +1,43 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* gles_evaluator.h
* Author: Mike Gorchak, 2009. mike@malva.ua, lestat@i.com.ua
*
*/
#ifndef __gles_evaluator_h_
#define __gles_evaluator_h_
/* Fixed point to float point conversion */
#define FX2F(fx) (GLfloat(fx)/65536.0f)
#endif /* __gles_evaluator_h_ */

View File

@@ -0,0 +1,41 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __gluimports_h_
#define __gluimports_h_
#include "mystdlib.h"
#include "mystdio.h"
#endif /* __gluimports_h_ */

View File

@@ -0,0 +1,463 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "glues.h"
#include "gles_evaluator.h"
#include <stdio.h>
#include "glimports.h"
#include "glrenderer.h"
#include "nurbsconsts.h"
GLUnurbs* APIENTRY gluNewNurbsRenderer(void)
{
GLUnurbs* t;
t=new GLUnurbs();
return t;
}
void APIENTRY gluDeleteNurbsRenderer(GLUnurbs* r)
{
delete r;
}
extern "C" void APIENTRY gluDeleteNurbsTessellatorEXT(GLUnurbsObj* r)
{
delete r;
}
void APIENTRY gluBeginSurface(GLUnurbs* r)
{
r->bgnsurface(0);
}
void APIENTRY gluBeginCurve(GLUnurbs* r)
{
r->bgncurve(0);
}
void APIENTRY gluEndCurve(GLUnurbs* r)
{
r->endcurve();
}
void APIENTRY gluEndSurface(GLUnurbs* r)
{
r->endsurface();
}
void APIENTRY gluBeginTrim(GLUnurbs* r)
{
r->bgntrim();
}
void APIENTRY gluEndTrim(GLUnurbs* r)
{
r->endtrim();
}
void APIENTRY gluPwlCurve(GLUnurbs* r, GLint count, INREAL array[], GLint stride, GLenum type)
{
int realType;
switch(type)
{
case GLU_MAP1_TRIM_2:
realType=N_P2D;
break;
case GLU_MAP1_TRIM_3:
realType=N_P2DR;
break;
default:
realType = type;
break;
}
r->pwlcurve(count, array, sizeof(INREAL)*stride, realType);
}
void APIENTRY gluNurbsCurve(GLUnurbs* r, GLint nknots, INREAL knot[], GLint stride,
INREAL ctlarray[], GLint order, GLenum type)
{
int realType;
switch(type)
{
case GLU_MAP1_TRIM_2:
realType=N_P2D;
break;
case GLU_MAP1_TRIM_3:
realType=N_P2DR;
break;
default:
realType=type;
break;
}
r->nurbscurve(nknots, knot, sizeof(INREAL)*stride, ctlarray, order, realType);
}
void APIENTRY gluNurbsSurface(GLUnurbs* r, GLint sknot_count, GLfloat* sknot,
GLint tknot_count, GLfloat* tknot, GLint s_stride,
GLint t_stride, GLfloat* ctlarray, GLint sorder,
GLint torder, GLenum type)
{
r->nurbssurface(sknot_count, sknot, tknot_count, tknot,
sizeof(INREAL)*s_stride, sizeof(INREAL)*t_stride,
ctlarray, sorder, torder, type);
}
void APIENTRY gluLoadSamplingMatrices(GLUnurbs* r, const GLfloat modelMatrix[16],
const GLfloat projMatrix[16], const GLint viewport[4])
{
r->useGLMatrices(modelMatrix, projMatrix, viewport);
}
void APIENTRY gluNurbsProperty(GLUnurbs* r, GLenum property, GLfloat value)
{
GLfloat nurbsValue;
switch(property)
{
case GLU_AUTO_LOAD_MATRIX:
r->setautoloadmode(value);
return;
case GLU_CULLING:
if (value != 0.0)
{
nurbsValue=N_CULLINGON;
}
else
{
nurbsValue = N_NOCULLING;
}
r->setnurbsproperty(GLU_MAP2_VERTEX_3, N_CULLING, nurbsValue);
r->setnurbsproperty(GLU_MAP2_VERTEX_4, N_CULLING, nurbsValue);
r->setnurbsproperty(GLU_MAP1_VERTEX_3, N_CULLING, nurbsValue);
r->setnurbsproperty(GLU_MAP1_VERTEX_4, N_CULLING, nurbsValue);
return;
case GLU_SAMPLING_METHOD:
if (value==GLU_PATH_LENGTH)
{
nurbsValue=N_PATHLENGTH;
}
else
{
if (value==GLU_PARAMETRIC_ERROR)
{
nurbsValue=N_PARAMETRICDISTANCE;
}
else
{
if (value==GLU_DOMAIN_DISTANCE)
{
nurbsValue=N_DOMAINDISTANCE;
r->set_is_domain_distance_sampling(1); // optimzing untrimmed case
}
else
{
if (value==GLU_OBJECT_PARAMETRIC_ERROR)
{
nurbsValue=N_OBJECTSPACE_PARA;
r->setautoloadmode(0.0f);
r->setSamplingMatrixIdentity();
}
else
{
if (value==GLU_OBJECT_PATH_LENGTH)
{
nurbsValue = N_OBJECTSPACE_PATH;
r->setautoloadmode(0.0f);
r->setSamplingMatrixIdentity();
}
else
{
r->postError(GLU_INVALID_VALUE);
return;
}
}
}
}
}
r->setnurbsproperty(GLU_MAP2_VERTEX_3, N_SAMPLINGMETHOD, nurbsValue);
r->setnurbsproperty(GLU_MAP2_VERTEX_4, N_SAMPLINGMETHOD, nurbsValue);
r->setnurbsproperty(GLU_MAP1_VERTEX_3, N_SAMPLINGMETHOD, nurbsValue);
r->setnurbsproperty(GLU_MAP1_VERTEX_4, N_SAMPLINGMETHOD, nurbsValue);
return;
case GLU_SAMPLING_TOLERANCE:
r->setnurbsproperty(GLU_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, value);
r->setnurbsproperty(GLU_MAP2_VERTEX_4, N_PIXEL_TOLERANCE, value);
r->setnurbsproperty(GLU_MAP1_VERTEX_3, N_PIXEL_TOLERANCE, value);
r->setnurbsproperty(GLU_MAP1_VERTEX_4, N_PIXEL_TOLERANCE, value);
return;
case GLU_PARAMETRIC_TOLERANCE:
r->setnurbsproperty(GLU_MAP2_VERTEX_3, N_ERROR_TOLERANCE, value);
r->setnurbsproperty(GLU_MAP2_VERTEX_4, N_ERROR_TOLERANCE, value);
r->setnurbsproperty(GLU_MAP1_VERTEX_3, N_ERROR_TOLERANCE, value);
r->setnurbsproperty(GLU_MAP1_VERTEX_4, N_ERROR_TOLERANCE, value);
return;
case GLU_DISPLAY_MODE:
if (value==GLU_FILL)
{
nurbsValue=N_FILL;
}
else
{
if (value==GLU_OUTLINE_POLYGON)
{
nurbsValue=N_OUTLINE_POLY;
}
else
{
if (value==GLU_OUTLINE_PATCH)
{
nurbsValue=N_OUTLINE_PATCH;
}
else
{
r->postError(GLU_INVALID_VALUE);
return;
}
}
}
r->setnurbsproperty(N_DISPLAY, nurbsValue);
break;
case GLU_U_STEP:
r->setnurbsproperty(GLU_MAP1_VERTEX_3, N_S_STEPS, value);
r->setnurbsproperty(GLU_MAP1_VERTEX_4, N_S_STEPS, value);
r->setnurbsproperty(GLU_MAP2_VERTEX_3, N_S_STEPS, value);
r->setnurbsproperty(GLU_MAP2_VERTEX_4, N_S_STEPS, value);
// added for optimizing untrimmed case
r->set_domain_distance_u_rate(value);
break;
case GLU_V_STEP:
r->setnurbsproperty(GLU_MAP1_VERTEX_3, N_T_STEPS, value);
r->setnurbsproperty(GLU_MAP1_VERTEX_4, N_T_STEPS, value);
r->setnurbsproperty(GLU_MAP2_VERTEX_3, N_T_STEPS, value);
r->setnurbsproperty(GLU_MAP2_VERTEX_4, N_T_STEPS, value);
//added for optimizing untrimmed case
r->set_domain_distance_v_rate(value);
break;
case GLU_NURBS_MODE:
if (value==GLU_NURBS_RENDERER)
{
r->put_callbackFlag(0);
}
else
{
if (value==GLU_NURBS_TESSELLATOR)
{
r->put_callbackFlag(1);
}
else
{
r->postError(GLU_INVALID_ENUM);
}
}
break;
default:
r->postError(GLU_INVALID_ENUM);
return;
}
}
void APIENTRY
gluGetNurbsProperty(GLUnurbs *r, GLenum property, GLfloat *value)
{
GLfloat nurbsValue;
switch(property)
{
case GLU_AUTO_LOAD_MATRIX:
if (r->getautoloadmode())
{
*value=GL_TRUE;
}
else
{
*value=GL_FALSE;
}
break;
case GLU_CULLING:
r->getnurbsproperty(GLU_MAP2_VERTEX_3, N_CULLING, &nurbsValue);
if (nurbsValue==N_CULLINGON)
{
*value=GL_TRUE;
}
else
{
*value = GL_FALSE;
}
break;
case GLU_SAMPLING_METHOD:
r->getnurbsproperty(GLU_MAP2_VERTEX_3, N_SAMPLINGMETHOD, value);
if (*value==N_PATHLENGTH)
{
*value=GLU_PATH_LENGTH;
}
else
{
if (*value==N_PARAMETRICDISTANCE)
{
*value=GLU_PARAMETRIC_ERROR;
}
else
{
if (*value==N_DOMAINDISTANCE)
{
*value=GLU_DOMAIN_DISTANCE;
}
else
{
if (*value==N_OBJECTSPACE_PATH)
{
*value=GLU_OBJECT_PATH_LENGTH;
}
else
{
if (*value==N_OBJECTSPACE_PARA)
{
*value=GLU_OBJECT_PARAMETRIC_ERROR;
}
}
}
}
}
break;
case GLU_SAMPLING_TOLERANCE:
r->getnurbsproperty(GLU_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, value);
break;
case GLU_PARAMETRIC_TOLERANCE:
r->getnurbsproperty(GLU_MAP2_VERTEX_3, N_ERROR_TOLERANCE, value);
break;
case GLU_U_STEP:
r->getnurbsproperty(GLU_MAP2_VERTEX_3, N_S_STEPS, value);
break;
case GLU_V_STEP:
r->getnurbsproperty(GLU_MAP2_VERTEX_3, N_T_STEPS, value);
break;
case GLU_DISPLAY_MODE:
r->getnurbsproperty(N_DISPLAY, &nurbsValue);
if (nurbsValue==N_FILL)
{
*value=GLU_FILL;
}
else
{
if (nurbsValue==N_OUTLINE_POLY)
{
*value=GLU_OUTLINE_POLYGON;
}
else
{
*value=GLU_OUTLINE_PATCH;
}
}
break;
case GLU_NURBS_MODE:
if (r->is_callback())
{
*value=GLU_NURBS_TESSELLATOR;
}
else
{
*value=GLU_NURBS_RENDERER;
}
break;
default:
r->postError(GLU_INVALID_ENUM);
return;
}
}
extern "C" void APIENTRY gluNurbsCallback(GLUnurbs* r, GLenum which, _GLUfuncptr fn)
{
switch(which)
{
case GLU_NURBS_BEGIN:
case GLU_NURBS_END:
case GLU_NURBS_VERTEX:
case GLU_NURBS_NORMAL:
case GLU_NURBS_TEXTURE_COORD:
case GLU_NURBS_COLOR:
case GLU_NURBS_BEGIN_DATA:
case GLU_NURBS_END_DATA:
case GLU_NURBS_VERTEX_DATA:
case GLU_NURBS_NORMAL_DATA:
case GLU_NURBS_TEXTURE_COORD_DATA:
case GLU_NURBS_COLOR_DATA:
r->putSurfCallBack(which, fn);
break;
case GLU_NURBS_ERROR:
r->errorCallback=(void (APIENTRY*)(GLenum e)) fn;
break;
default:
r->postError(GLU_INVALID_ENUM);
return;
}
}
extern "C" void APIENTRY gluNurbsCallbackDataEXT(GLUnurbs* r, void* userData)
{
r->setNurbsCallbackData(userData);
}
extern "C" void APIENTRY gluNurbsCallbackData(GLUnurbs* r, void* userData)
{
gluNurbsCallbackDataEXT(r,userData);
}

View File

@@ -0,0 +1,277 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "glues.h"
#include "gles_evaluator.h"
#include "glimports.h"
#include "glrenderer.h"
GLUnurbs::GLUnurbs(): NurbsTessellator(curveEvaluator, surfaceEvaluator)
{
redefineMaps();
defineMap(GLU_MAP2_NORMAL, 0, 3);
defineMap(GLU_MAP1_NORMAL, 0, 3);
defineMap(GLU_MAP2_TEXTURE_COORD_1, 0, 1);
defineMap(GLU_MAP1_TEXTURE_COORD_1, 0, 1);
defineMap(GLU_MAP2_TEXTURE_COORD_2, 0, 2);
defineMap(GLU_MAP1_TEXTURE_COORD_2, 0, 2);
defineMap(GLU_MAP2_TEXTURE_COORD_3, 0, 3);
defineMap(GLU_MAP1_TEXTURE_COORD_3, 0, 3);
defineMap(GLU_MAP2_TEXTURE_COORD_4, 1, 4);
defineMap(GLU_MAP1_TEXTURE_COORD_4, 1, 4);
defineMap(GLU_MAP2_VERTEX_4, 1, 4);
defineMap(GLU_MAP1_VERTEX_4, 1, 4);
defineMap(GLU_MAP2_VERTEX_3, 0, 3);
defineMap(GLU_MAP1_VERTEX_3, 0, 3);
defineMap(GLU_MAP2_COLOR_4, 0, 4);
defineMap(GLU_MAP1_COLOR_4, 0, 4);
defineMap(GLU_MAP2_INDEX, 0, 1);
defineMap(GLU_MAP1_INDEX, 0, 1);
setnurbsproperty(GLU_MAP1_VERTEX_3, N_SAMPLINGMETHOD, (GLfloat)N_PATHLENGTH);
setnurbsproperty(GLU_MAP1_VERTEX_4, N_SAMPLINGMETHOD, (GLfloat)N_PATHLENGTH);
setnurbsproperty(GLU_MAP2_VERTEX_3, N_SAMPLINGMETHOD, (GLfloat)N_PATHLENGTH);
setnurbsproperty(GLU_MAP2_VERTEX_4, N_SAMPLINGMETHOD, (GLfloat)N_PATHLENGTH);
setnurbsproperty(GLU_MAP1_VERTEX_3, N_PIXEL_TOLERANCE, (GLfloat)50.0f);
setnurbsproperty(GLU_MAP1_VERTEX_4, N_PIXEL_TOLERANCE, (GLfloat)50.0f);
setnurbsproperty(GLU_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, (GLfloat)50.0f);
setnurbsproperty(GLU_MAP2_VERTEX_4, N_PIXEL_TOLERANCE, (GLfloat)50.0f);
setnurbsproperty(GLU_MAP1_VERTEX_3, N_ERROR_TOLERANCE, (GLfloat)0.50f);
setnurbsproperty(GLU_MAP1_VERTEX_4, N_ERROR_TOLERANCE, (GLfloat)0.50f);
setnurbsproperty(GLU_MAP2_VERTEX_3, N_ERROR_TOLERANCE, (GLfloat)0.50f);
setnurbsproperty(GLU_MAP2_VERTEX_4, N_ERROR_TOLERANCE, (GLfloat)0.50f);
setnurbsproperty(GLU_MAP1_VERTEX_3, N_S_STEPS, (GLfloat)100.0f);
setnurbsproperty(GLU_MAP1_VERTEX_4, N_S_STEPS, (GLfloat)100.0f);
setnurbsproperty(GLU_MAP2_VERTEX_3, N_S_STEPS, (GLfloat)100.0f);
setnurbsproperty(GLU_MAP2_VERTEX_4, N_S_STEPS, (GLfloat)100.0f);
// added for optimizing untrimmed case
set_domain_distance_u_rate(100.0f);
setnurbsproperty(GLU_MAP1_VERTEX_3, N_T_STEPS, (GLfloat)100.0f);
setnurbsproperty(GLU_MAP1_VERTEX_4, N_T_STEPS, (GLfloat)100.0f);
setnurbsproperty(GLU_MAP2_VERTEX_3, N_T_STEPS, (GLfloat)100.0f);
setnurbsproperty(GLU_MAP2_VERTEX_4, N_T_STEPS, (GLfloat)100.0f);
// added for optimizing untrimmed case
set_domain_distance_v_rate(100.0f);
set_is_domain_distance_sampling(0); // since the default is path_length
// default autoloadmode is true
autoloadmode=1;
// default callbackFlag is 0
callbackFlag=0;
errorCallback=NULL;
}
void GLUnurbs::bgnrender(void)
{
if (autoloadmode)
{
loadGLMatrices();
}
}
void GLUnurbs::endrender(void)
{
}
void GLUnurbs::errorHandler(int i)
{
int gluError;
gluError=i+(GLU_NURBS_ERROR1-1);
postError(gluError);
}
void GLUnurbs::loadGLMatrices(void)
{
GLfloat vmat[4][4];
GLint viewport[4];
grabGLMatrix((GLfloat(*)[4])vmat);
loadCullingMatrix((GLfloat(*)[4])vmat);
gluGetIntegerv((GLenum)GL_VIEWPORT, (GLint*)viewport);
loadSamplingMatrix((const GLfloat(*)[4])vmat, (const GLint*)viewport);
}
void GLUnurbs::useGLMatrices(const GLfloat modelMatrix[16], const GLfloat projMatrix[16],
const GLint viewport[4])
{
GLfloat vmat[4][4];
multmatrix4d(vmat, (const GLfloat (*)[4])modelMatrix, (const GLfloat (*)[4])projMatrix);
loadCullingMatrix((GLfloat (*)[4])vmat);
loadSamplingMatrix((const GLfloat (*)[4])vmat, (const GLint *)viewport);
}
/*--------------------------------------------------------------------------
* grabGLMatrix
*--------------------------------------------------------------------------
*/
void GLUnurbs::grabGLMatrix(GLfloat vmat[4][4])
{
GLfloat m1[4][4], m2[4][4];
gluGetFloatv((GLenum) GL_MODELVIEW_MATRIX, (GLfloat*)&(m1[0][0]));
gluGetFloatv((GLenum) GL_PROJECTION_MATRIX, (GLfloat*)&(m2[0][0]));
multmatrix4d((GLfloat (*)[4])vmat, (const GLfloat (*)[4])m1, (const GLfloat (*)[4])m2);
}
// for object space tesselation: view independent
void GLUnurbs::setSamplingMatrixIdentity(void)
{
INREAL smat[4][4]=
{
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1}
};
const long rstride=sizeof(smat[0])/sizeof(smat[0][0]);
const long cstride=1;
setnurbsproperty(GLU_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride);
setnurbsproperty(GLU_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride);
setnurbsproperty(GLU_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride);
setnurbsproperty(GLU_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride);
}
void GLUnurbs::loadSamplingMatrix(const GLfloat vmat[4][4], const GLint viewport[4])
{
/* rescale the mapping to correspond to pixels in x/y */
REAL xsize = 0.5f * (REAL) (viewport[2]);
REAL ysize = 0.5f * (REAL) (viewport[3]);
INREAL smat[4][4];
smat[0][0] = vmat[0][0] * xsize;
smat[1][0] = vmat[1][0] * xsize;
smat[2][0] = vmat[2][0] * xsize;
smat[3][0] = vmat[3][0] * xsize;
smat[0][1] = vmat[0][1] * ysize;
smat[1][1] = vmat[1][1] * ysize;
smat[2][1] = vmat[2][1] * ysize;
smat[3][1] = vmat[3][1] * ysize;
smat[0][2] = 0.0;
smat[1][2] = 0.0;
smat[2][2] = 0.0;
smat[3][2] = 0.0;
smat[0][3] = vmat[0][3];
smat[1][3] = vmat[1][3];
smat[2][3] = vmat[2][3];
smat[3][3] = vmat[3][3];
const long rstride=sizeof(smat[0])/sizeof(smat[0][0]);
const long cstride=1;
setnurbsproperty(GLU_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride);
setnurbsproperty(GLU_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride);
setnurbsproperty(GLU_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride);
setnurbsproperty(GLU_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride, cstride);
}
void GLUnurbs::loadCullingMatrix(GLfloat vmat[4][4])
{
INREAL cmat[4][4];
cmat[0][0]=vmat[0][0];
cmat[0][1]=vmat[0][1];
cmat[0][2]=vmat[0][2];
cmat[0][3]=vmat[0][3];
cmat[1][0]=vmat[1][0];
cmat[1][1]=vmat[1][1];
cmat[1][2]=vmat[1][2];
cmat[1][3]=vmat[1][3];
cmat[2][0]=vmat[2][0];
cmat[2][1]=vmat[2][1];
cmat[2][2]=vmat[2][2];
cmat[2][3]=vmat[2][3];
cmat[3][0]=vmat[3][0];
cmat[3][1]=vmat[3][1];
cmat[3][2]=vmat[3][2];
cmat[3][3]=vmat[3][3];
const long rstride=sizeof(cmat[0])/sizeof(cmat[0][0]);
const long cstride=1;
setnurbsproperty(GLU_MAP2_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride, cstride);
setnurbsproperty(GLU_MAP2_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride, cstride);
// added for curves by zl
setnurbsproperty(GLU_MAP1_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride, cstride);
setnurbsproperty(GLU_MAP1_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride, cstride);
}
/*---------------------------------------------------------------------
* A = B * MAT ; transform a 4d vector through a 4x4 matrix
*---------------------------------------------------------------------
*/
void GLUnurbs::transform4d(GLfloat A[4], GLfloat B[4], GLfloat mat[4][4])
{
A[0]=B[0]*mat[0][0]+B[1]*mat[1][0]+B[2]*mat[2][0]+B[3]*mat[3][0];
A[1]=B[0]*mat[0][1]+B[1]*mat[1][1]+B[2]*mat[2][1]+B[3]*mat[3][1];
A[2]=B[0]*mat[0][2]+B[1]*mat[1][2]+B[2]*mat[2][2]+B[3]*mat[3][2];
A[3]=B[0]*mat[0][3]+B[1]*mat[1][3]+B[2]*mat[2][3]+B[3]*mat[3][3];
}
/*---------------------------------------------------------------------
* new = [left][right] ; multiply two matrices together
*---------------------------------------------------------------------
*/
void GLUnurbs::multmatrix4d(GLfloat n[4][4], const GLfloat left[4][4], const GLfloat right[4][4])
{
transform4d((GLfloat*)n[0], (GLfloat*)left[0], (GLfloat(*)[4])right);
transform4d((GLfloat*)n[1], (GLfloat*)left[1], (GLfloat(*)[4])right);
transform4d((GLfloat*)n[2], (GLfloat*)left[2], (GLfloat(*)[4])right);
transform4d((GLfloat*)n[3], (GLfloat*)left[3], (GLfloat(*)[4])right);
}

View File

@@ -0,0 +1,140 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __gluglrenderer_h_
#define __gluglrenderer_h_
#include "glues.h"
#include "nurbstess.h"
#include "glsurfeval.h"
#include "glcurveval.h"
extern "C"
{
typedef void (APIENTRY* errorCallbackType)(GLenum);
}
class GLUnurbs: public NurbsTessellator
{
public:
GLUnurbs(void);
void loadGLMatrices(void);
void useGLMatrices(const GLfloat modelMatrix[16], const GLfloat projMatrix[16],
const GLint viewport[4]);
void setSamplingMatrixIdentity(void);
void errorHandler(int);
void bgnrender(void);
void endrender(void);
void setautoloadmode(INREAL value)
{
if (value)
{
autoloadmode=GL_TRUE;
}
else
{
autoloadmode=GL_FALSE;
}
}
GLboolean getautoloadmode(void) { return autoloadmode; }
errorCallbackType errorCallback;
void postError(int which)
{
if (errorCallback)
{
(errorCallback)((GLenum)which);
}
}
#ifdef _WIN32
void putSurfCallBack(GLenum which, void (APIENTRY* fn)())
#else
void putSurfCallBack(GLenum which, _GLUfuncptr fn)
#endif
{
curveEvaluator.putCallBack(which, fn);
surfaceEvaluator.putCallBack(which, fn);
}
int get_vertices_call_back()
{
return surfaceEvaluator.get_vertices_call_back();
}
void put_vertices_call_back(int flag)
{
surfaceEvaluator.put_vertices_call_back(flag);
}
int get_callback_auto_normal()
{
return surfaceEvaluator.get_callback_auto_normal();
}
void put_callback_auto_normal(int flag)
{
surfaceEvaluator.put_callback_auto_normal(flag);
}
void setNurbsCallbackData(void* userData)
{
curveEvaluator.set_callback_userData(userData);
surfaceEvaluator.set_callback_userData(userData);
}
// NEWCALLBACK
int is_callback()
{
return callbackFlag;
}
void put_callbackFlag(int flag)
{
callbackFlag=flag;
surfaceEvaluator.put_vertices_call_back(flag);
curveEvaluator.put_vertices_call_back(flag);
}
private:
GLboolean autoloadmode;
OpenGLSurfaceEvaluator surfaceEvaluator;
OpenGLCurveEvaluator curveEvaluator;
void loadSamplingMatrix(const GLfloat vmat[4][4], const GLint viewport[4]);
void loadCullingMatrix(GLfloat vmat[4][4]);
static void grabGLMatrix(GLfloat vmat[4][4]);
static void transform4d(GLfloat A[4], GLfloat B[4], GLfloat mat[4][4]);
static void multmatrix4d(GLfloat n[4][4], const GLfloat left[4][4], const GLfloat right[4][4]);
int callbackFlag;
};
#endif /* __gluglrenderer_h_ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,357 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __gluglsurfeval_h_
#define __gluglsurfeval_h_
#include "basicsurfeval.h"
#include "bezierPatchMesh.h" //in case output triangles
#include "glues.h"
class SurfaceMap;
class OpenGLSurfaceEvaluator;
class StoredVertex;
#define TYPECOORD 1
#define TYPEPOINT 2
/* Cache up to 3 vertices from tmeshes */
#define VERTEX_CACHE_SIZE 3
/* for internal evaluator callback stuff */
#ifndef IN_MAX_BEZIER_ORDER
#define IN_MAX_BEZIER_ORDER 40 /* should be bigger than machine order */
#endif
#ifndef IN_MAX_DIMENSION
#define IN_MAX_DIMENSION 4
#endif
typedef struct surfEvalMachine
{
REAL uprime; /* cached previusly evaluated uprime. */
REAL vprime;
int k; /* the dimension */
REAL u1;
REAL u2;
int ustride;
int uorder;
REAL v1;
REAL v2;
int vstride;
int vorder;
REAL ctlPoints[IN_MAX_BEZIER_ORDER*IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION];
REAL ucoeff[IN_MAX_BEZIER_ORDER]; /* cache the polynomial values */
REAL vcoeff[IN_MAX_BEZIER_ORDER];
REAL ucoeffDeriv[IN_MAX_BEZIER_ORDER]; /* cache the polynomial derivatives */
REAL vcoeffDeriv[IN_MAX_BEZIER_ORDER];
} surfEvalMachine;
class StoredVertex
{
public:
StoredVertex() {type=0;}
~StoredVertex(void) {}
void saveEvalCoord(REAL x, REAL y)
{coord[0]=x; coord[1]=y; type=TYPECOORD;}
void saveEvalPoint(long x, long y)
{point[0]=x; point[1]=y; type=TYPEPOINT;}
void invoke(OpenGLSurfaceEvaluator* eval);
private:
int type;
REAL coord[2];
long point[2];
};
class OpenGLSurfaceEvaluator: public BasicSurfaceEvaluator
{
public:
OpenGLSurfaceEvaluator();
virtual ~OpenGLSurfaceEvaluator(void);
void polymode(long style);
long get_output_style();
void range2f(long, REAL*, REAL*);
void domain2f(REAL, REAL, REAL, REAL);
void addMap(SurfaceMap*) { }
void enable(long);
void disable(long);
void bgnmap2f(long);
void map2f(long, REAL, REAL, long, long, REAL, REAL, long, long, REAL*);
void mapgrid2f(long, REAL, REAL, long, REAL, REAL);
void mapmesh2f(long, long, long, long, long);
void evalcoord2f(long, REAL, REAL, REAL*, REAL*);
void evalpoint2i(long, long);
void endmap2f(void);
void bgnline(void);
void endline(void);
void bgnclosedline(void);
void endclosedline(void);
void bgntmesh(void);
void swaptmesh(void);
void endtmesh(void);
void bgnqstrip(void);
void endqstrip(void);
void bgntfan(void);
void endtfan(void);
void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
int n_lower, REAL v_lower, REAL* lower_val);
void evalVStrip(int n_left, REAL u_left, REAL* left_val,
int n_right, REAL u_right, REAL* right_val);
void coord2f(REAL, REAL, REAL* retPoint, REAL* retNormal);
void point2i(long, long);
void newtmeshvert(REAL, REAL, REAL*, REAL*);
void newtmeshvert(long, long);
#ifdef _WIN32
void putCallBack(GLenum which, void (APIENTRY* fn)());
#else
void putCallBack(GLenum which, _GLUfuncptr fn);
#endif
int get_vertices_call_back()
{
return output_triangles;
}
void put_vertices_call_back(int flag)
{
output_triangles=flag;
}
void put_callback_auto_normal(int flag)
{
callback_auto_normal=flag;
}
int get_callback_auto_normal()
{
return callback_auto_normal;
}
void set_callback_userData(void* data)
{
userData=data;
}
private:
StoredVertex* vertexCache[VERTEX_CACHE_SIZE];
int tmeshing;
int which;
int vcount;
GLint gl_polygon_mode[2]; // to save and restore so that no side effect
bezierPatchMesh* global_bpm; // for output triangles
int output_triangles; // true 1 or false 0
long output_style; // N_MESHFILL or N_MESHLINE or N_MESHPOINT
void (APIENTRY* beginCallBackN)(GLenum type);
void (APIENTRY* endCallBackN)(void);
void (APIENTRY* vertexCallBackN)(const GLfloat* vert);
void (APIENTRY* normalCallBackN)(const GLfloat* normal);
void (APIENTRY* colorCallBackN)(const GLfloat* color);
void (APIENTRY* texcoordCallBackN)(const GLfloat* texcoord);
void (APIENTRY* beginCallBackData)(GLenum type, void* data);
void (APIENTRY* endCallBackData)(void* data);
void (APIENTRY* vertexCallBackData)(const GLfloat* vert, void* data);
void (APIENTRY* normalCallBackData)(const GLfloat* normal, void* data);
void (APIENTRY* colorCallBackData)(const GLfloat* color, void* data);
void (APIENTRY* texcoordCallBackData)(const GLfloat* texcoord, void* data);
void beginCallBack(GLenum type, void* data);
void endCallBack(void* data);
void vertexCallBack(const GLfloat* vert, void* data);
void normalCallBack(const GLfloat* normal, void* data);
void colorCallBack(const GLfloat* color, void* data);
void texcoordCallBack(const GLfloat* texcoord, void* data);
void* userData; // the opaque pointer for Data callback functions.
/*************begin for internal evaluators*****************/
/* the following global variables are only defined in this file.
* They are used to cache the precomputed Bezier polynomial values.
* These calues may be used consecutively in which case we don't have
* recompute these values again.
*/
int global_uorder; /* store the uorder in the previous evaluation */
int global_vorder; /* store the vorder in the previous evaluation */
REAL global_uprime;
REAL global_vprime;
REAL global_vprime_BV;
REAL global_uprime_BU;
int global_uorder_BV; /* store the uorder in the previous evaluation */
int global_vorder_BV; /* store the vorder in the previous evaluation */
int global_uorder_BU; /* store the uorder in the previous evaluation */
int global_vorder_BU; /* store the vorder in the previous evaluation */
REAL global_ucoeff[IN_MAX_BEZIER_ORDER]; /* cache the polynomial values */
REAL global_vcoeff[IN_MAX_BEZIER_ORDER];
REAL global_ucoeffDeriv[IN_MAX_BEZIER_ORDER]; /* cache the polynomial derivatives */
REAL global_vcoeffDeriv[IN_MAX_BEZIER_ORDER];
REAL global_BV[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
REAL global_PBV[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
REAL global_BU[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
REAL global_PBU[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION];
REAL* global_baseData;
int global_ev_k; /* the dimension */
REAL global_ev_u1;
REAL global_ev_u2;
int global_ev_ustride;
int global_ev_uorder;
REAL global_ev_v1;
REAL global_ev_v2;
int global_ev_vstride;
int global_ev_vorder;
REAL global_ev_ctlPoints[IN_MAX_BEZIER_ORDER*IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION];
REAL global_grid_u0;
REAL global_grid_u1;
int global_grid_nu;
REAL global_grid_v0;
REAL global_grid_v1;
int global_grid_nv;
/* functions */
void inDoDomain2WithDerivs(int k, REAL u, REAL v, REAL u1, REAL u2, int uorder,
REAL v1, REAL v2, int vorder, REAL* baseData,
REAL* retPoint, REAL* retdu, REAL* retdv);
void inPreEvaluate(int order, REAL vprime, REAL* coeff);
void inPreEvaluateWithDeriv(int order, REAL vprime, REAL* coeff, REAL* coeffDeriv);
void inComputeFirstPartials(REAL* p, REAL* pu, REAL* pv);
void inComputeNormal2(REAL* pu, REAL* pv, REAL* n);
void inDoEvalCoord2(REAL u, REAL v, REAL* retPoint, REAL* retNormal);
void inDoEvalCoord2NOGE(REAL u, REAL v, REAL* retPoint, REAL* retNormal);
void inMap2f(int k, REAL ulower, REAL uupper, int ustride, int uorder,
REAL vlower, REAL vupper, int vstride, int vorder, REAL* ctlPoints);
void inMapGrid2f(int nu, REAL u0, REAL u1, int nv, REAL v0, REAL v1);
void inEvalMesh2(int lowU, int lowV, int highU, int highV);
void inEvalPoint2(int i, int j);
void inEvalCoord2f(REAL u, REAL v, REAL* retPoint, REAL* retNormal);
void inEvalULine(int n_points, REAL v, REAL* u_vals, int stride,
REAL ret_points[][3], REAL ret_normals[][3]);
void inEvalVLine(int n_points, REAL u, REAL* v_vals, int stride,
REAL ret_points[][3], REAL ret_normals[][3]);
void inEvalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
int n_lower, REAL v_lower, REAL* lower_val);
void inEvalVStrip(int n_left, REAL u_left, REAL* left_val, int n_right,
REAL u_right, REAL* right_val);
void inPreEvaluateBV(int k, int uorder, int vorder, REAL vprime, REAL* baseData);
void inPreEvaluateBU(int k, int uorder, int vorder, REAL uprime, REAL* baseData);
void inPreEvaluateBV_intfac(REAL v)
{
inPreEvaluateBV(global_ev_k, global_ev_uorder, global_ev_vorder, (v-global_ev_v1)/(global_ev_v2-global_ev_v1), global_ev_ctlPoints);
}
void inPreEvaluateBU_intfac(REAL u)
{
inPreEvaluateBU(global_ev_k, global_ev_uorder, global_ev_vorder, (u-global_ev_u1)/(global_ev_u2-global_ev_u1), global_ev_ctlPoints);
}
void inDoDomain2WithDerivsBV(int k, REAL u, REAL v, REAL u1, REAL u2, int uorder,
REAL v1, REAL v2, int vorder, REAL* baseData,
REAL* retPoint, REAL* retdu, REAL *retdv);
void inDoDomain2WithDerivsBU(int k, REAL u, REAL v, REAL u1, REAL u2, int uorder,
REAL v1, REAL v2, int vorder, REAL* baseData,
REAL* retPoint, REAL* retdu, REAL *retdv);
void inDoEvalCoord2NOGE_BV(REAL u, REAL v, REAL* retPoint, REAL* retNormal);
void inDoEvalCoord2NOGE_BU(REAL u, REAL v, REAL* retPoint, REAL* retNormal);
void inBPMEval(bezierPatchMesh* bpm);
void inBPMListEval(bezierPatchMesh* list);
/*-------------begin for surfEvalMachine -------------*/
surfEvalMachine em_vertex;
surfEvalMachine em_normal;
surfEvalMachine em_color;
surfEvalMachine em_texcoord;
int auto_normal_flag; // whether to output normal or not in callback
// determined by GLU_AUTO_NORMAL and callback_auto_normal
int callback_auto_normal; // GLU_CALLBACK_AUTO_NORMAL_EXT
int vertex_flag;
int normal_flag;
int color_flag;
int texcoord_flag;
void inMap2fEM(int which, int dimension, REAL ulower, REAL uupper, int ustride,
int uorder, REAL vlower, REAL vupper, int vstride, int vorder, REAL* ctlPoints);
void inDoDomain2WithDerivsEM(surfEvalMachine* em, REAL u, REAL v, REAL* retPoint,
REAL* retdu, REAL* retdv);
void inDoDomain2EM(surfEvalMachine* em, REAL u, REAL v, REAL* retPoint);
void inDoEvalCoord2EM(REAL u, REAL v);
void inBPMEvalEM(bezierPatchMesh* bpm);
void inBPMListEvalEM(bezierPatchMesh* list);
/*-------------end for surfEvalMachine -------------*/
/*************end for internal evaluators*****************/
};
inline void StoredVertex::invoke(OpenGLSurfaceEvaluator* eval)
{
REAL retPoint[4];
REAL retNormal[3];
switch(type)
{
case TYPECOORD:
eval->coord2f(coord[0], coord[1], retPoint, retNormal);
break;
case TYPEPOINT:
eval->point2i(point[0], point[1]);
break;
default:
break;
}
}
#endif /* __gluglsurfeval_h_ */

View File

@@ -0,0 +1,387 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include <stdlib.h>
#include <stdio.h>
#include "glcurveval.h"
/*
*compute the Bezier polynomials C[n,j](v) for all j at v with
*return values stored in coeff[], where
* C[n,j](v) = (n,j) * v^j * (1-v)^(n-j),
* j=0,1,2,...,n.
*order : n+1
*vprime: v
*coeff : coeff[j]=C[n,j](v), this array store the returned values.
*The algorithm is a recursive scheme:
* C[0,0]=1;
* C[n,j](v) = (1-v)*C[n-1,j](v) + v*C[n-1,j-1](v), n>=1
*This code is copied from opengl/soft/so_eval.c:PreEvaluate
*/
void OpenGLCurveEvaluator::inPreEvaluate(int order, REAL vprime, REAL* coeff)
{
int i, j;
REAL oldval, temp;
REAL oneMinusvprime;
/*
* Minor optimization
* Compute orders 1 and 2 outright, and set coeff[0], coeff[1] to
* their i==1 loop values to avoid the initialization and the i==1 loop.
*/
if (order==1)
{
coeff[0]=1.0f;
return;
}
oneMinusvprime=1-vprime;
coeff[0]=oneMinusvprime;
coeff[1]=vprime;
if (order==2)
{
return;
}
for (i=2; i<order; i++)
{
oldval=coeff[0]*vprime;
coeff[0]=oneMinusvprime*coeff[0];
for (j=1; j<i; j++)
{
temp=oldval;
oldval=coeff[j]*vprime;
coeff[j]=temp+oneMinusvprime*coeff[j];
}
coeff[j]=oldval;
}
}
void OpenGLCurveEvaluator::inMap1f(int which, // 0: vert, 1: norm, 2: color, 3: tex
int k, // dimension
REAL ulower,
REAL uupper,
int ustride,
int uorder,
REAL* ctlpoints)
{
int i, x;
curveEvalMachine* temp_em;
switch (which)
{
case 0: // vertex
vertex_flag=1;
temp_em=&em_vertex;
break;
case 1: // normal
normal_flag=1;
temp_em=&em_normal;
break;
case 2: // color
color_flag=1;
temp_em=&em_color;
break;
default:
texcoord_flag=1;
temp_em=&em_texcoord;
break;
}
REAL* data=temp_em->ctlpoints;
temp_em->uprime=-1; // initialized
temp_em->k=k;
temp_em->u1=ulower;
temp_em->u2=uupper;
temp_em->ustride=ustride;
temp_em->uorder=uorder;
/* copy the control points */
for(i=0; i<uorder; i++)
{
for(x=0; x<k; x++)
{
data[x]=ctlpoints[x];
}
ctlpoints+=ustride;
data+=k;
}
}
void OpenGLCurveEvaluator::inMap1fr(int which, // 0: vert, 1: norm, 2: color, 3: tex
int k, // dimension
REAL ulower,
REAL uupper,
int ustride,
int uorder,
REAL* ctlpoints)
{
int i, x;
curveEvalMachine* temp_em;
switch (which)
{
case 0: // vertex
vertex_flag=1;
temp_em=&em_vertex;
break;
case 1: // normal
normal_flag=1;
temp_em=&em_normal;
break;
case 2: // color
color_flag=1;
temp_em=&em_color;
break;
default:
texcoord_flag=1;
temp_em=&em_texcoord;
break;
}
REAL* data=temp_em->ctlpoints;
temp_em->uprime=-1; // initialized
temp_em->k=k;
temp_em->u1=ulower;
temp_em->u2=uupper;
temp_em->ustride=ustride;
temp_em->uorder=uorder;
/* copy the control points */
for(i=0; i<uorder; i++)
{
for(x=0; x<k; x++)
{
data[x]=ctlpoints[x];
}
ctlpoints+=ustride;
data+=k;
}
}
void OpenGLCurveEvaluator::inDoDomain1(curveEvalMachine* em, REAL u, REAL* retPoint)
{
int j, row;
REAL the_uprime;
REAL* data;
if (em->u2==em->u1)
{
return;
}
the_uprime=(u-em->u1)/(em->u2-em->u1);
/* use already cached values if possible */
if (em->uprime!=the_uprime)
{
inPreEvaluate(em->uorder, the_uprime, em->ucoeff);
em->uprime = the_uprime;
}
for(j=0; j<em->k; j++)
{
data=em->ctlpoints+j;
retPoint[j]=0.0f;
for (row=0; row<em->uorder; row++)
{
retPoint[j]+=em->ucoeff[row]*(*data);
data+=em->k;
}
}
}
void OpenGLCurveEvaluator::inDoEvalCoord1(REAL u)
{
REAL temp_vertex[4];
REAL temp_normal[3];
REAL temp_color[4];
REAL temp_texcoord[4];
if (texcoord_flag) // there is a texture map
{
inDoDomain1(&em_texcoord, u, temp_texcoord);
texcoordCallBack(temp_texcoord, userData);
}
if (color_flag) // there is a color map
{
inDoDomain1(&em_color, u, temp_color);
colorCallBack(temp_color, userData);
}
if (normal_flag) // there is a normal map
{
inDoDomain1(&em_normal, u, temp_normal);
normalCallBack(temp_normal, userData);
}
if (vertex_flag)
{
inDoDomain1(&em_vertex, u, temp_vertex);
vertexCallBack(temp_vertex, userData);
}
}
void OpenGLCurveEvaluator::inDoEvalCoord1r(REAL u, REAL* retPoint)
{
inDoDomain1(&em_vertex, u, retPoint);
}
void OpenGLCurveEvaluator::inMapMesh1f(int umin, int umax)
{
REAL du, u;
int i;
if (global_grid_nu==0)
{
return; // no points to output
}
du=(global_grid_u1-global_grid_u0)/(REAL)global_grid_nu;
bgnline();
for(i=umin; i<=umax; i++)
{
u=(i==global_grid_nu)?global_grid_u1:global_grid_u0+i*du;
inDoEvalCoord1(u);
}
endline();
}
void OpenGLCurveEvaluator::inMapMesh1fr(int umin, int umax)
{
REAL du, u;
REAL retPoint[4];
REAL* vertices=NULL;
int i;
GLboolean texcoord_enabled;
GLboolean normal_enabled;
GLboolean vertex_enabled;
GLboolean color_enabled;
if (global_grid_nu==0)
{
return; // no points to output
}
du=(global_grid_u1-global_grid_u0)/(REAL)global_grid_nu;
vertices=(REAL*)malloc((umax-umin+1)*3*sizeof(REAL));
bgnline();
for(i=umin; i<=umax; i++)
{
u=(i==global_grid_nu)?global_grid_u1:global_grid_u0+i*du;
inDoEvalCoord1r(u, retPoint);
vertices[(i-umin)*3 + 0]=retPoint[0];
vertices[(i-umin)*3 + 1]=retPoint[1];
vertices[(i-umin)*3 + 2]=retPoint[2];
}
endline();
/* Store status of enabled arrays */
texcoord_enabled=GL_FALSE; /* glIsEnabled(GL_TEXTURE_COORD_ARRAY); */
normal_enabled=GL_FALSE; /* glIsEnabled(GL_NORMAL_ARRAY); */
vertex_enabled=GL_FALSE; /* glIsEnabled(GL_VERTEX_ARRAY); */
color_enabled=GL_FALSE; /* glIsEnabled(GL_COLOR_ARRAY); */
/* Enable needed and disable unneeded arrays */
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
/* Perform rendering */
if (output_style==N_MESHPOINT)
{
/* Output as points */
glDrawArrays(GL_POINTS, 0, umax-umin+1);
}
else
{
/* Output as line strip */
glDrawArrays(GL_LINE_STRIP, 0, umax-umin+1);
}
/* Disable or re-enable arrays */
if (vertex_enabled)
{
/* Re-enable vertex array */
glEnableClientState(GL_VERTEX_ARRAY);
}
else
{
glDisableClientState(GL_VERTEX_ARRAY);
}
if (texcoord_enabled)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
else
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if (normal_enabled)
{
glEnableClientState(GL_NORMAL_ARRAY);
}
else
{
glDisableClientState(GL_NORMAL_ARRAY);
}
if (color_enabled)
{
glEnableClientState(GL_COLOR_ARRAY);
}
else
{
glDisableClientState(GL_COLOR_ARRAY);
}
free(vertices);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,55 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glumystdio_h_
#define __glumystdio_h_
#ifdef LIBRARYBUILD
#ifndef NDEBUG
#include <stdio.h>
#define _glu_dprintf printf
#else
inline void _glu_dprintf(const char *, ...) { }
#endif
#endif
#ifdef GLBUILD
inline void _glu_dprintf(const char *, ...) { }
#endif
#ifndef NULL
#define NULL 0
#endif
#endif /* __glumystdio_h_ */

View File

@@ -0,0 +1,49 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glumystdlib_h_
#define __glumystdlib_h_
#ifdef LIBRARYBUILD
#include <stdlib.h>
#endif
#ifdef GLBUILD
typedef unsigned int size_t;
extern "C" void abort(void);
extern "C" void* malloc(size_t);
extern "C" void free(void*);
#endif
#endif /* __glumystdlib_h_ */

View File

@@ -0,0 +1,290 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include <stdio.h>
#include "glimports.h"
#include "mystdio.h"
#include "myassert.h"
#include "arc.h"
#include "bin.h"
#include "bezierarc.h"
#include "pwlarc.h"
#include "simplemath.h"
/* local preprocessor definitions */
#define ZERO 0.00001 /* 0.000001 */
const int Arc::bezier_tag=(1<<13);
const int Arc::arc_tag=(1<<3);
const int Arc::tail_tag=(1<<6);
/*--------------------------------------------------------------------------
* makeSide - attach a pwl arc to an arc and mark it as a border arc
*--------------------------------------------------------------------------
*/
void Arc::makeSide(PwlArc* pwl, arc_side side)
{
assert(pwl!=0);
assert(pwlArc==0);
assert(pwl->npts>0);
assert(pwl->pts!=0);
pwlArc=pwl;
clearbezier();
setside(side);
}
/*--------------------------------------------------------------------------
* numpts - count number of points on arc loop
*--------------------------------------------------------------------------
*/
int Arc::numpts(void)
{
Arc_ptr jarc=this;
int npts=0;
do {
npts+=jarc->pwlArc->npts;
jarc=jarc->next;
} while(jarc!=this);
return npts;
}
/*--------------------------------------------------------------------------
* markverts - mark each point with id of arc
*--------------------------------------------------------------------------
*/
void Arc::markverts(void)
{
Arc_ptr jarc=this;
do {
TrimVertex* p=jarc->pwlArc->pts;
for (int i=0; i<jarc->pwlArc->npts; i++)
{
p[i].nuid=jarc->nuid;
}
jarc=jarc->next;
} while(jarc!=this);
}
/*--------------------------------------------------------------------------
* getextrema - find axis extrema on arc loop
*--------------------------------------------------------------------------
*/
void Arc::getextrema(Arc_ptr extrema[4])
{
REAL leftpt, botpt, rightpt, toppt;
extrema[0]=extrema[1]=extrema[2]=extrema[3]=this;
leftpt=rightpt=this->tail()[0];
botpt=toppt=this->tail()[1];
for (Arc_ptr jarc=this->next; jarc!=this; jarc=jarc->next)
{
if (jarc->tail()[0]<leftpt || (jarc->tail()[0]<=leftpt && jarc->rhead()[0]<=leftpt))
{
leftpt=jarc->pwlArc->pts->param[0];
extrema[1]=jarc;
}
if (jarc->tail()[0]>rightpt || (jarc->tail()[0]>=rightpt && jarc->rhead()[0]>=rightpt))
{
rightpt=jarc->pwlArc->pts->param[0];
extrema[3]=jarc;
}
if (jarc->tail()[1]<botpt || (jarc->tail()[1]<=botpt && jarc->rhead()[1]<=botpt))
{
botpt=jarc->pwlArc->pts->param[1];
extrema[2]=jarc;
}
if (jarc->tail()[1]>toppt || (jarc->tail()[1]>=toppt && jarc->rhead()[1]>=toppt))
{
toppt=jarc->pwlArc->pts->param[1];
extrema[0]=jarc;
}
}
}
/*-------------------------------------------------------------------------
* isDisconnected - check if tail of arc and head of prev meet
*-------------------------------------------------------------------------
*/
int Arc::isDisconnected(void)
{
if (pwlArc==0)
{
return 0;
}
if (prev->pwlArc==0)
{
return 0;
}
REAL* p0=tail();
REAL* p1=prev->rhead();
if (((p0[0]-p1[0])>ZERO) || ((p1[0]-p0[0])>ZERO) ||
((p0[1]-p1[1])>ZERO) || ((p1[1]-p0[1])>ZERO))
{
return 1;
}
else
{
/* average two points together */
p0[0]=p1[0]=(p1[0]+p0[0])*0.5f;
p0[1]=p1[1]=(p1[1]+p0[1])*0.5f;
return 0;
}
}
/*-------------------------------------------------------------------------
* neq_vert - assert that two 2D vertices are not equal
*-------------------------------------------------------------------------
*/
inline static int neq_vert(REAL* v1, REAL* v2)
{
return ((v1[0]!=v2[0]) || (v1[1]!=v2[1])) ? 1 : 0;
}
/*-------------------------------------------------------------------------
* check - verify consistency of a loop, including
* 1) if pwl, no two consecutive vertices are identical
* 2) the circular link pointers are valid
* 3) the geometric info at the head and tail are consistent
*-------------------------------------------------------------------------
*/
int Arc::check(void)
{
if (this==0)
{
return 1;
}
Arc_ptr jarc=this;
do {
assert((jarc->pwlArc!=0) || (jarc->bezierArc!=0));
if (jarc->prev==0 || jarc->next==0)
{
return 0;
}
if (jarc->next->prev!=jarc)
{
return 0;
}
if (jarc->pwlArc)
{
if (jarc->prev->pwlArc)
{
if (jarc->tail()[1]!=jarc->prev->rhead()[1])
{
return 0;
}
if (jarc->tail()[0]!=jarc->prev->rhead()[0])
{
return 0;
}
}
if (jarc->next->pwlArc)
{
if (jarc->next->tail()[0]!=jarc->rhead()[0])
{
return 0;
}
if (jarc->next->tail()[1]!=jarc->rhead()[1])
{
return 0;
}
}
if (jarc->isbezier())
{
assert(jarc->pwlArc->npts==2);
assert((jarc->pwlArc->pts[0].param[0]== \
jarc->pwlArc->pts[1].param[0]) || \
(jarc->pwlArc->pts[0].param[1] == \
jarc->pwlArc->pts[1].param[1]));
}
}
jarc=jarc->next;
} while (jarc!=this);
return 1;
}
#define TOL 0.00001
inline long tooclose(REAL x, REAL y)
{
return (glu_abs(x-y)<TOL) ? 1 : 0;
}
/*--------------------------------------------------------------------------
* append - append a jordan arc to a circularly linked list
*--------------------------------------------------------------------------
*/
Arc_ptr Arc::append(Arc_ptr jarc)
{
if (jarc!=0)
{
next=jarc->next;
prev=jarc;
next->prev=prev->next=this;
}
else
{
next=prev=this;
}
return this;
}

View File

@@ -0,0 +1,135 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __gluarc_h_
#define __gluarc_h_
#include "myassert.h"
#include "bufpool.h"
#include "mystdio.h"
#include "types.h"
#include "pwlarc.h"
#include "trimvertex.h"
class Bin;
class Arc;
struct BezierArc;
typedef class Arc* Arc_ptr;
enum arc_side
{
arc_none=0,
arc_right,
arc_top,
arc_left,
arc_bottom
};
/* an arc, in two list, the trim list and bin */
class Arc: public PooledObj
{
public:
static const int bezier_tag;
static const int arc_tag;
static const int tail_tag;
Arc_ptr prev; /* trim list pointer */
Arc_ptr next; /* trim list pointer */
Arc_ptr link; /* bin pointers */
BezierArc* bezierArc; /* associated bezier arc */
PwlArc* pwlArc; /* associated pwl arc */
long type; /* curve type */
long nuid;
inline Arc(Arc*, PwlArc*);
inline Arc(arc_side, long);
Arc_ptr append(Arc_ptr);
int check(void);
int isMonotone(void);
int isDisconnected(void);
int numpts(void);
void markverts(void);
void getextrema(Arc_ptr[4]);
void makeSide(PwlArc*, arc_side);
inline int isTessellated() { return pwlArc ? 1 : 0; }
inline long isbezier() { return type & bezier_tag; }
inline void setbezier() { type |= bezier_tag; }
inline void clearbezier() { type &= ~bezier_tag; }
inline long npts() { return pwlArc->npts; }
inline TrimVertex* pts() { return pwlArc->pts; }
inline REAL* tail() { return pwlArc->pts[0].param; }
inline REAL* head() { return next->pwlArc->pts[0].param; }
inline REAL* rhead() { return pwlArc->pts[pwlArc->npts-1].param; }
inline long ismarked() { return type & arc_tag; }
inline void setmark() { type |= arc_tag; }
inline void clearmark() { type &= (~arc_tag); }
inline void clearside() { type &= ~(0x7 << 8); }
inline void setside(arc_side s) { clearside(); type |= (((long)s)<<8); }
inline arc_side getside() { return (arc_side) ((type>>8) & 0x7); }
inline int getitail() { return type & tail_tag; }
inline void setitail() { type |= tail_tag; }
inline void clearitail() { type &= (~tail_tag); }
};
/*--------------------------------------------------------------------------
* Arc - initialize a new Arc with the same type and uid of
* a given Arc and a given pwl arc
*--------------------------------------------------------------------------
*/
inline Arc::Arc(Arc* j, PwlArc* p)
{
bezierArc=NULL;
pwlArc=p;
type=j->type;
nuid=j->nuid;
}
/*--------------------------------------------------------------------------
* Arc - initialize a new Arc with the same type and uid of
* a given Arc and a given pwl arc
*--------------------------------------------------------------------------
*/
inline Arc::Arc(arc_side side, long _nuid)
{
bezierArc=NULL;
pwlArc=NULL;
type=0;
setside(side);
nuid=_nuid;
}
#endif /* __gluarc_h_ */

View File

@@ -0,0 +1,197 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __gluarcsorter_c_
#define __gluarcsorter_c_
#include "glimports.h"
#include "arc.h"
#include "arcsorter.h"
#include "subdivider.h"
ArcSorter::ArcSorter(Subdivider &s): Sorter(sizeof(Arc**)), subdivider(s)
{
}
int ArcSorter::qscmp(char*, char*)
{
return 0;
}
void ArcSorter::qsort(Arc** a, int n)
{
Sorter::qsort((void*)a, n);
}
void ArcSorter::qsexc(char* i, char* j) // i<-j, j<-i
{
Arc** jarc1=(Arc**)i;
Arc** jarc2=(Arc**)j;
Arc* tmp=*jarc1;
*jarc1=*jarc2;
*jarc2=tmp;
}
void ArcSorter::qstexc(char* i, char* j, char* k) // i<-k, k<-j, j<-i
{
Arc** jarc1=(Arc**)i;
Arc** jarc2=(Arc**)j;
Arc** jarc3=(Arc**)k;
Arc* tmp=*jarc1;
*jarc1=*jarc3;
*jarc3=*jarc2;
*jarc2=tmp;
}
ArcSdirSorter::ArcSdirSorter(Subdivider& s): ArcSorter(s)
{
}
int ArcSdirSorter::qscmp(char* i, char* j)
{
Arc* jarc1=*(Arc**)i;
Arc* jarc2=*(Arc**)j;
int v1=(jarc1->getitail() ? 0 : (jarc1->pwlArc->npts-1));
int v2=(jarc2->getitail() ? 0 : (jarc2->pwlArc->npts-1));
REAL diff=jarc1->pwlArc->pts[v1].param[1] -
jarc2->pwlArc->pts[v2].param[1];
if (diff<0.0)
{
return -1;
}
else
{
if (diff>0.0)
{
return 1;
}
else
{
if (v1==0)
{
if (jarc2->tail()[0]<jarc1->tail()[0])
{
return subdivider.ccwTurn_sl(jarc2, jarc1) ? 1 : -1;
}
else
{
return subdivider.ccwTurn_sr(jarc2, jarc1) ? -1 : 1;
}
}
else
{
if (jarc2->head()[0]<jarc1->head()[0])
{
return subdivider.ccwTurn_sl(jarc1, jarc2) ? -1 : 1;
}
else
{
return subdivider.ccwTurn_sr( jarc1, jarc2 ) ? 1 : -1;
}
}
}
}
}
ArcTdirSorter::ArcTdirSorter(Subdivider& s): ArcSorter(s)
{
}
/*----------------------------------------------------------------------------
* ArcTdirSorter::qscmp -
* compare two axis monotone arcs that are incident
* to the line T == compare_value. Determine which of the
* two intersects that line with a LESSER S value. If
* jarc1 does, return 1. If jarc2 does, return -1.
*---------------------------------------------------------------------------
*/
int ArcTdirSorter::qscmp(char* i, char* j)
{
Arc* jarc1=*(Arc**)i;
Arc* jarc2=*(Arc**)j;
int v1=(jarc1->getitail() ? 0 : (jarc1->pwlArc->npts-1));
int v2=(jarc2->getitail() ? 0 : (jarc2->pwlArc->npts-1));
REAL diff=jarc1->pwlArc->pts[v1].param[0]-
jarc2->pwlArc->pts[v2].param[0];
if (diff<0.0)
{
return 1;
}
else
{
if (diff>0.0)
{
return -1;
}
else
{
if (v1==0)
{
if (jarc2->tail()[1]<jarc1->tail()[1])
{
return subdivider.ccwTurn_tl(jarc2, jarc1) ? 1 : -1;
}
else
{
return subdivider.ccwTurn_tr(jarc2, jarc1) ? -1 : 1;
}
}
else
{
if (jarc2->head()[1]<jarc1->head()[1])
{
return subdivider.ccwTurn_tl(jarc1, jarc2) ? -1 : 1;
}
else
{
return subdivider.ccwTurn_tr(jarc1, jarc2) ? 1 : -1;
}
}
}
}
}
#endif /* __gluarcsorter_c_ */

View File

@@ -0,0 +1,73 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __gluarcsorter_h_
#define __gluarcsorter_h_
#include "sorter.h"
#include "arcsorter.h"
class Arc;
class Subdivider;
class ArcSorter: private Sorter
{
public:
ArcSorter(Subdivider &);
void qsort(Arc** a, int n);
protected:
virtual int qscmp(char*, char*);
Subdivider& subdivider;
private:
void qsexc(char* i, char* j ); // i<-j, j<-i
void qstexc(char* i, char* j, char* k); // i<-k, k<-j, j<-i
};
class ArcSdirSorter: public ArcSorter
{
public:
ArcSdirSorter(Subdivider&);
private:
int qscmp(char*, char*);
};
class ArcTdirSorter: public ArcSorter
{
public:
ArcTdirSorter(Subdivider&);
private:
int qscmp(char*, char*);
};
#endif /* __gluarcsorter_h_ */

View File

@@ -0,0 +1,626 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "glimports.h"
#include "mystdio.h"
#include "myassert.h"
#include "arctess.h"
#include "bufpool.h"
#include "simplemath.h"
#include "bezierarc.h"
#include "trimvertex.h"
#include "trimvertpool.h"
#include <stdio.h>
#define NOELIMINATION
#define steps_function(large, small, rate) (max(1, 1+(int)((large-small)/rate)));
/*-----------------------------------------------------------------------------
* ArcTessellator - construct an ArcTessellator
*-----------------------------------------------------------------------------
*/
ArcTessellator::ArcTessellator( TrimVertexPool& t, Pool& p)
:pwlarcpool(p), trimvertexpool(t)
{
}
/*-----------------------------------------------------------------------------
* ~ArcTessellator - destroy an ArcTessellator
*-----------------------------------------------------------------------------
*/
ArcTessellator::~ArcTessellator(void)
{
}
/*-----------------------------------------------------------------------------
* bezier - construct a bezier arc and attach it to an Arc
*-----------------------------------------------------------------------------
*/
void ArcTessellator::bezier(Arc* arc, REAL s1, REAL s2, REAL t1, REAL t2)
{
assert(arc!=0);
assert(!arc->isTessellated());
TrimVertex* p=trimvertexpool.get(2);
arc->pwlArc=new(pwlarcpool) PwlArc(2, p);
p[0].param[0]=s1;
p[0].param[1]=t1;
p[1].param[0]=s2;
p[1].param[1]=t2;
assert((s1==s2) || (t1==t2));
arc->setbezier();
}
/*-----------------------------------------------------------------------------
* pwl_left - construct a left boundary pwl arc and attach it to an arc
*-----------------------------------------------------------------------------
*/
void ArcTessellator::pwl_left(Arc* arc, REAL s, REAL t1, REAL t2, REAL rate)
{
assert(t2<t1);
int nsteps=steps_function(t1, t2, rate);
REAL stepsize=(t1-t2)/(REAL) nsteps;
TrimVertex* newvert=trimvertexpool.get(nsteps+1);
int i;
for(i=nsteps; i>0; i--)
{
newvert[i].param[0]=s;
newvert[i].param[1]=t2;
t2+=stepsize;
}
newvert[i].param[0]=s;
newvert[i].param[1]=t1;
arc->makeSide(new(pwlarcpool)PwlArc(nsteps+1, newvert), arc_left);
}
/*-----------------------------------------------------------------------------
* pwl_right - construct a right boundary pwl arc and attach it to an arc
*-----------------------------------------------------------------------------
*/
void ArcTessellator::pwl_right(Arc* arc, REAL s, REAL t1, REAL t2, REAL rate)
{
assert(t1<t2);
int nsteps=steps_function(t2, t1, rate);
if (nsteps>256)
{
nsteps=256;
}
REAL stepsize=(t2-t1)/(REAL)nsteps;
TrimVertex* newvert=trimvertexpool.get(nsteps+1);
int i;
for (i=0; i<nsteps; i++)
{
newvert[i].param[0]=s;
newvert[i].param[1]=t1;
t1+=stepsize;
}
newvert[i].param[0]=s;
newvert[i].param[1]=t2;
arc->makeSide(new(pwlarcpool)PwlArc(nsteps+1, newvert), arc_right);
}
/*-----------------------------------------------------------------------------
* pwl_top - construct a top boundary pwl arc and attach it to an arc
*-----------------------------------------------------------------------------
*/
void ArcTessellator::pwl_top(Arc* arc, REAL t, REAL s1, REAL s2, REAL rate)
{
assert(s2<s1);
int nsteps=steps_function(s1, s2, rate);
REAL stepsize=(s1-s2)/(REAL)nsteps;
TrimVertex* newvert=trimvertexpool.get(nsteps+1);
int i;
for (i=nsteps; i>0; i--)
{
newvert[i].param[0]=s2;
newvert[i].param[1]=t;
s2+=stepsize;
}
newvert[i].param[0]=s1;
newvert[i].param[1]=t;
arc->makeSide(new(pwlarcpool)PwlArc(nsteps+1, newvert), arc_top);
}
/*-----------------------------------------------------------------------------
* pwl_bottom - construct a bottom boundary pwl arc and attach it to an arc
*-----------------------------------------------------------------------------
*/
void
ArcTessellator::pwl_bottom(Arc* arc, REAL t, REAL s1, REAL s2, REAL rate)
{
assert(s1<s2);
int nsteps=steps_function(s2, s1, rate);
REAL stepsize=(s2-s1)/(REAL)nsteps;
TrimVertex* newvert=trimvertexpool.get(nsteps+1);
int i;
for (i=0; i<nsteps; i++)
{
newvert[i].param[0]=s1;
newvert[i].param[1]=t;
s1+=stepsize;
}
newvert[i].param[0]=s2;
newvert[i].param[1]=t;
arc->makeSide(new(pwlarcpool)PwlArc(nsteps+1, newvert), arc_bottom);
}
/*-----------------------------------------------------------------------------
* pwl - construct a pwl arc and attach it to an arc
*-----------------------------------------------------------------------------
*/
void ArcTessellator::pwl(Arc* arc, REAL s1, REAL s2, REAL t1, REAL t2, REAL rate)
{
int snsteps=1+(int)(glu_abs(s2-s1)/rate);
int tnsteps=1+(int)(glu_abs(t2-t1)/rate);
int nsteps=max(1, max(snsteps, tnsteps));
REAL sstepsize=(s2-s1)/(REAL)nsteps;
REAL tstepsize=(t2-t1)/(REAL)nsteps;
TrimVertex* newvert=trimvertexpool.get(nsteps+1);
long i;
for (i=0; i<nsteps; i++)
{
newvert[i].param[0]=s1;
newvert[i].param[1]=t1;
s1+=sstepsize;
t1+=tstepsize;
}
newvert[i].param[0]=s2;
newvert[i].param[1]=t2;
arc->pwlArc=new(pwlarcpool)PwlArc(nsteps+1, newvert);
arc->clearbezier();
arc->clearside();
}
/*-----------------------------------------------------------------------------
* tessellateLinear - constuct a linear pwl arc and attach it to an Arc
*-----------------------------------------------------------------------------
*/
void ArcTessellator::tessellateLinear(Arc* arc, REAL geo_stepsize, REAL arc_stepsize, int isrational)
{
assert(arc->pwlArc==NULL);
REAL s1, s2, t1, t2;
//we don't need to scale by arc_stepsize if the trim curve
//is piecewise linear. Reason: In pwl_right, pwl_left, pwl_top, pwl_left,
//and pwl, the nsteps is computed by deltaU (or V) /stepsize.
//The quantity deltaU/arc_stepsize doesn't have any meaning. And
//it causes problems: see bug 517641
REAL stepsize=geo_stepsize; /* * arc_stepsize*/;
BezierArc* b=arc->bezierArc;
if (isrational)
{
s1=b->cpts[0]/b->cpts[2];
t1=b->cpts[1]/b->cpts[2];
s2=b->cpts[b->stride+0]/b->cpts[b->stride+2];
t2=b->cpts[b->stride+1]/b->cpts[b->stride+2];
}
else
{
s1=b->cpts[0];
t1=b->cpts[1];
s2=b->cpts[b->stride+0];
t2=b->cpts[b->stride+1];
}
if (s1==s2)
{
if (t1<t2)
{
pwl_right(arc, s1, t1, t2, stepsize);
}
else
{
pwl_left(arc, s1, t1, t2, stepsize);
}
}
else
{
if (t1==t2)
{
if (s1<s2)
{
pwl_bottom(arc, t1, s1, s2, stepsize);
}
else
{
pwl_top(arc, t1, s1, s2, stepsize);
}
}
else
{
pwl(arc, s1, s2, t1, t2, stepsize);
}
}
}
/*-----------------------------------------------------------------------------
* tessellateNonlinear - constuct a nonlinear pwl arc and attach it to an Arc
*-----------------------------------------------------------------------------
*/
void ArcTessellator::tessellateNonlinear(Arc* arc, REAL geo_stepsize, REAL arc_stepsize, int isrational)
{
assert(arc->pwlArc==NULL);
REAL stepsize=geo_stepsize*arc_stepsize;
BezierArc* bezierArc=arc->bezierArc;
REAL size; //bounding box size of the curve in UV
{
int i, j;
REAL min_u, min_v, max_u,max_v;
min_u=max_u=bezierArc->cpts[0];
min_v=max_v=bezierArc->cpts[1];
for(i=1, j=bezierArc->stride; i<bezierArc->order; i++, j+=bezierArc->stride)
{
if (bezierArc->cpts[j]<min_u)
{
min_u=bezierArc->cpts[j];
}
if (bezierArc->cpts[j]>max_u)
{
max_u=bezierArc->cpts[j];
}
if (bezierArc->cpts[j+1]<min_v)
{
min_v=bezierArc->cpts[j+1];
}
if (bezierArc->cpts[j+1]>max_v)
{
max_v=bezierArc->cpts[j+1];
}
}
size=max_u-min_u;
if (size<max_v-min_v)
{
size=max_v-min_v;
}
}
int nsteps=(int)(size/stepsize);
if (nsteps<=0)
{
nsteps=1;
}
TrimVertex* vert=trimvertexpool.get(nsteps+1);
REAL dp=1.0f/nsteps;
arc->pwlArc=new(pwlarcpool) PwlArc();
arc->pwlArc->pts=vert;
if (isrational)
{
REAL pow_u[MAXORDER], pow_v[MAXORDER], pow_w[MAXORDER];
trim_power_coeffs(bezierArc, pow_u, 0);
trim_power_coeffs(bezierArc, pow_v, 1);
trim_power_coeffs(bezierArc, pow_w, 2);
/* compute first point exactly */
REAL* b=bezierArc->cpts;
vert->param[0]=b[0]/b[2];
vert->param[1]=b[1]/b[2];
/* strength reduction on p = dp * step would introduce error */
int step;
#ifndef NOELIMINATION
int ocanremove=0;
#endif
register long order=bezierArc->order;
for(step=1, ++vert; step<nsteps; step++, vert++)
{
register REAL p=dp*step;
register REAL u=pow_u[0];
register REAL v=pow_v[0];
register REAL w=pow_w[0];
for(register int i=1; i<order; i++)
{
u=u*p+pow_u[i];
v=v*p+pow_v[i];
w=w*p+pow_w[i];
}
vert->param[0]=u/w;
vert->param[1]=v/w;
#ifndef NOELIMINATION
REAL ds=glu_abs(vert[0].param[0]-vert[-1].param[0]);
REAL dt=glu_abs(vert[0].param[1]-vert[-1].param[1]);
int canremove=(ds<geo_stepsize && dt<geo_stepsize) ? 1 : 0;
REAL ods=0.0, odt=0.0;
if (ocanremove && canremove)
{
REAL nds=ds+ods;
REAL ndt=dt+odt;
if (nds<geo_stepsize && ndt<geo_stepsize)
{
// remove previous point
--vert;
vert[0].param[0]=vert[1].param[0];
vert[0].param[1]=vert[1].param[1];
ods=nds;
odt=ndt;
ocanremove=1;
}
else
{
ocanremove=canremove;
ods=ds;
odt=dt;
}
}
else
{
ocanremove=canremove;
ods=ds;
odt=dt;
}
#endif
}
/* compute last point exactly */
b+=(order-1)*bezierArc->stride;
vert->param[0] = b[0]/b[2];
vert->param[1] = b[1]/b[2];
}
else
{
REAL pow_u[MAXORDER], pow_v[MAXORDER];
trim_power_coeffs(bezierArc, pow_u, 0);
trim_power_coeffs(bezierArc, pow_v, 1);
/* compute first point exactly */
REAL* b=bezierArc->cpts;
vert->param[0]=b[0];
vert->param[1]=b[1];
/* strength reduction on p = dp * step would introduce error */
int step;
#ifndef NOELIMINATION
int ocanremove=0;
#endif
register long order=bezierArc->order;
for (step=1, ++vert; step<nsteps; step++, vert++)
{
register REAL p=dp*step;
register REAL u=pow_u[0];
register REAL v=pow_v[0];
for (register int i=1; i<bezierArc->order; i++)
{
u=u*p+pow_u[i];
v=v*p+pow_v[i];
}
vert->param[0]=u;
vert->param[1]=v;
#ifndef NOELIMINATION
REAL ds=glu_abs(vert[0].param[0]-vert[-1].param[0]);
REAL dt=glu_abs(vert[0].param[1]-vert[-1].param[1]);
int canremove=(ds<geo_stepsize && dt<geo_stepsize) ? 1 : 0;
REAL ods=0.0, odt=0.0;
if (ocanremove && canremove)
{
REAL nds=ds+ods;
REAL ndt=dt+odt;
if (nds<geo_stepsize && ndt<geo_stepsize)
{
// remove previous point
--vert;
vert[0].param[0]=vert[1].param[0];
vert[0].param[1]=vert[1].param[1];
ods=nds;
odt=ndt;
ocanremove=1;
}
else
{
ocanremove=canremove;
ods=ds;
odt=dt;
}
}
else
{
ocanremove=canremove;
ods=ds;
odt=dt;
}
#endif
}
/* compute last point exactly */
b+=(order-1)*bezierArc->stride;
vert->param[0]=b[0];
vert->param[1]=b[1];
}
arc->pwlArc->npts=(int)(vert-arc->pwlArc->pts+1);
}
const REAL ArcTessellator::gl_Bernstein[][MAXORDER][MAXORDER]=
{
{
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
},
{
{-1, 1, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
},
{
{1, -2, 1, 0, 0, 0, 0, 0},
{-2, 2, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
},
{
{-1, 3, -3, 1, 0, 0, 0, 0},
{3, -6, 3, 0, 0, 0, 0, 0},
{-3, 3, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
},
{
{1, -4, 6, -4, 1, 0, 0, 0},
{-4, 12, -12, 4, 0, 0, 0, 0},
{6, -12, 6, 0, 0, 0, 0, 0},
{-4, 4, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
},
{
{-1, 5, -10, 10, -5, 1, 0, 0},
{5, -20, 30, -20, 5, 0, 0, 0},
{-10, 30, -30, 10, 0, 0, 0, 0},
{10, -20, 10, 0, 0, 0, 0, 0},
{-5, 5, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
},
{
{1, -6, 15, -20, 15, -6, 1, 0},
{-6, 30, -60, 60, -30, 6, 0, 0},
{15, -60, 90, -60, 15, 0, 0, 0},
{-20, 60, -60, 20, 0, 0, 0, 0},
{15, -30, 15, 0, 0, 0, 0, 0},
{-6, 6, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
},
{
{-1, 7, -21, 35, -35, 21, -7, 1},
{7, -42, 105, -140, 105, -42, 7, 0},
{-21, 105, -210, 210, -105, 21, 0, 0},
{35, -140, 210, -140, 35, 0, 0, 0},
{-35, 105, -105, 35, 0, 0, 0, 0},
{21, -42, 21, 0, 0, 0, 0, 0},
{-7, 7, 0, 0, 0, 0, 0, 0},
{1, 0, 0, 0, 0, 0, 0, 0}
}
};
/*-----------------------------------------------------------------------------
* trim_power_coeffs - compute power basis coefficients from bezier coeffients
*-----------------------------------------------------------------------------
*/
void ArcTessellator::trim_power_coeffs(BezierArc* bez_arc, REAL* p, int coord)
{
register int stride=bez_arc->stride;
register int order=bez_arc->order;
register REAL* base=bez_arc->cpts+coord;
REAL const (*mat)[MAXORDER][MAXORDER]=&gl_Bernstein[order-1];
REAL const (*lrow)[MAXORDER]=&(*mat)[order];
/* WIN32 didn't like the following line within the for-loop */
REAL const (*row)[MAXORDER]=&(*mat)[0];
for (; row!=lrow; row++)
{
register REAL s=0.0;
register REAL* point=base;
register REAL const* mlast=*row+order;
for (REAL const* m=*row; m!=mlast; m++, point+=stride)
{
s+=*(m)*(*point);
}
*(p++)=s;
}
}

View File

@@ -0,0 +1,67 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __gluarctess_h_
#define __gluarctess_h_
#include "defines.h"
#include "types.h"
#include "arc.h"
struct BezierArc;
class Pool;
class TrimVertexPool;
class ArcTessellator
{
public:
ArcTessellator(TrimVertexPool&, Pool&);
~ArcTessellator(void);
void bezier(Arc_ptr, REAL, REAL, REAL, REAL);
void pwl(Arc_ptr, REAL, REAL, REAL, REAL, REAL);
void pwl_left(Arc_ptr, REAL, REAL, REAL, REAL);
void pwl_right(Arc_ptr, REAL, REAL, REAL, REAL);
void pwl_top(Arc_ptr, REAL, REAL, REAL, REAL);
void pwl_bottom(Arc_ptr, REAL, REAL, REAL, REAL);
void tessellateLinear(Arc_ptr, REAL, REAL, int);
void tessellateNonlinear(Arc_ptr, REAL, REAL, int);
private:
static const REAL gl_Bernstein[][MAXORDER][MAXORDER];
Pool& pwlarcpool;
TrimVertexPool& trimvertexpool;
static void trim_power_coeffs(BezierArc*, REAL[MAXORDER], int);
};
#endif /* __gluarctess_h_ */

View File

@@ -0,0 +1,481 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
/* Bezier surface backend - interprets display mode (wireframe, shaded, ...) */
#include <stdio.h>
#include "glimports.h"
#include "mystdio.h"
#include "backend.h"
#include "basiccrveval.h"
#include "basicsurfeval.h"
#include "nurbsconsts.h"
#include "gles_evaluator.h"
#include "glues.h"
/*-------------------------------------------------------------------------
* bgnsurf - preamble to surface definition and evaluations
*-------------------------------------------------------------------------
*/
void Backend::bgnsurf(int wiretris, int wirequads, long nuid)
{
wireframetris=wiretris;
wireframequads=wirequads;
/* in the spec, GLU_DISPLAY_MODE is either
* GLU_FILL
* GLU_OUTLINE_POLY
* GLU_OUTLINE_PATCH.
* In fact, GLU_FILL has the same effect as
* set GL_FRONT_AND_BACK to be GL_FILL
* and GLU_OUTLINE_POLY is the same as set
* GL_FRONT_AND_BACK to be GL_LINE
* It is more efficient to do this once at the beginning of
* each surface than to do it for each primitive.
* The internal has more options: outline_triangle and outline_quad
* can be seperated. But since this is not in spec, and more importantly,
* this is not so useful, so we don't need to keep this option.
*/
surfaceEvaluator.bgnmap2f(nuid);
if (wiretris)
{
surfaceEvaluator.polymode(N_MESHLINE);
}
else
{
surfaceEvaluator.polymode(N_MESHFILL);
}
}
void Backend::patch(REAL ulo, REAL uhi, REAL vlo, REAL vhi)
{
surfaceEvaluator.domain2f(ulo, uhi, vlo, vhi);
}
void Backend::surfbbox(long type, REAL* from, REAL* to)
{
surfaceEvaluator.range2f(type, from, to);
}
/*-------------------------------------------------------------------------
* surfpts - pass a desription of a surface map
*-------------------------------------------------------------------------
*/
void Backend::surfpts(long type, /* geometry, color, texture, normal */
REAL* pts, /* control points */
long ustride, /* distance to next point in u direction */
long vstride, /* distance to next point in v direction */
int uorder, /* u parametric order */
int vorder, /* v parametric order */
REAL ulo, /* u lower bound */
REAL uhi, /* u upper bound */
REAL vlo, /* v lower bound */
REAL vhi) /* v upper bound */
{
surfaceEvaluator.map2f(type, ulo, uhi, ustride, uorder, vlo, vhi, vstride, vorder, pts);
surfaceEvaluator.enable(type);
}
/*-------------------------------------------------------------------------
* surfgrid - define a lattice of points with origin and offset
*-------------------------------------------------------------------------
*/
void Backend::surfgrid(REAL u0, REAL u1, long nu, REAL v0, REAL v1, long nv)
{
surfaceEvaluator.mapgrid2f(nu, u0, u1, nv, v0, v1);
}
/*-------------------------------------------------------------------------
* surfmesh - evaluate a mesh of points on lattice
*-------------------------------------------------------------------------
*/
void Backend::surfmesh(long u, long v, long n, long m)
{
if (wireframequads)
{
surfaceEvaluator.mapmesh2f(N_MESHLINE, u, u+n, v, v+m);
}
else
{
surfaceEvaluator.mapmesh2f(N_MESHFILL, u, u+n, v, v+m);
}
}
/*-------------------------------------------------------------------------
* endsurf - postamble to surface
*-------------------------------------------------------------------------
*/
void Backend::endsurf(void)
{
surfaceEvaluator.endmap2f();
}
/***************************************/
void Backend::bgntfan(void)
{
surfaceEvaluator.bgntfan();
}
void Backend::endtfan(void)
{
surfaceEvaluator.endtfan();
}
void Backend::bgnqstrip(void)
{
surfaceEvaluator.bgnqstrip();
}
void Backend::endqstrip(void)
{
surfaceEvaluator.endqstrip();
}
void Backend::evalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
int n_lower, REAL v_lower, REAL* lower_val)
{
surfaceEvaluator.evalUStrip(n_upper, v_upper, upper_val, n_lower, v_lower, lower_val);
}
void Backend::evalVStrip(int n_left, REAL u_left, REAL* left_val,
int n_right, REAL u_right, REAL* right_val)
{
surfaceEvaluator.evalVStrip(n_left, u_left, left_val, n_right, u_right, right_val);
}
/*-------------------------------------------------------------------------
* bgntmesh - preamble to a triangle mesh
*-------------------------------------------------------------------------
*/
void Backend::bgntmesh(const char* name)
{
if (wireframetris)
{
surfaceEvaluator.bgntmesh();
surfaceEvaluator.polymode(N_MESHLINE);
}
else
{
surfaceEvaluator.bgntmesh();
surfaceEvaluator.polymode(N_MESHFILL);
}
}
void Backend::tmeshvert(GridTrimVertex* v)
{
REAL retPoint[4];
REAL retNormal[3];
if (v->isGridVert())
{
tmeshvert(v->g);
}
else
{
tmeshvert(v->t, retPoint, retNormal);
}
}
void Backend::tmeshvertNOGE(TrimVertex* t)
{
}
// opt for a line with the same u.
void Backend::tmeshvertNOGE_BU(TrimVertex* t)
{
}
// opt for a line with the same v.
void Backend::tmeshvertNOGE_BV(TrimVertex* t)
{
}
void Backend::preEvaluateBU(REAL u)
{
surfaceEvaluator.inPreEvaluateBU_intfac(u);
}
void Backend::preEvaluateBV(REAL v)
{
surfaceEvaluator.inPreEvaluateBV_intfac(v);
}
/*-------------------------------------------------------------------------
* tmeshvert - evaluate a point on a triangle mesh
*-------------------------------------------------------------------------
*/
void Backend::tmeshvert(TrimVertex* t, REAL* retPoint, REAL* retNormal)
{
const REAL u=t->param[0];
const REAL v=t->param[1];
surfaceEvaluator.evalcoord2f(0, u, v, retPoint, retNormal);
}
// the same as tmeshvert(trimvertex), for efficiency purpose
void Backend::tmeshvert(REAL u, REAL v, REAL* retPoint, REAL* retNormal)
{
surfaceEvaluator.evalcoord2f(0, u, v, retPoint, retNormal);
}
/*-------------------------------------------------------------------------
* tmeshvert - evaluate a grid point of a triangle mesh
*-------------------------------------------------------------------------
*/
void Backend::tmeshvert(GridVertex* g)
{
const long u=g->gparam[0];
const long v=g->gparam[1];
surfaceEvaluator.evalpoint2i(u, v);
}
/*-------------------------------------------------------------------------
* swaptmesh - perform a swap of the triangle mesh pointers
*-------------------------------------------------------------------------
*/
void Backend::swaptmesh(void)
{
surfaceEvaluator.swaptmesh();
}
/*-------------------------------------------------------------------------
* endtmesh - postamble to triangle mesh
*-------------------------------------------------------------------------
*/
void Backend::endtmesh(void)
{
surfaceEvaluator.endtmesh();
}
/*-------------------------------------------------------------------------
* bgnoutline - preamble to outlined rendering
*-------------------------------------------------------------------------
*/
void Backend::bgnoutline(void)
{
surfaceEvaluator.bgnline();
}
/*-------------------------------------------------------------------------
* linevert - evaluate a point on an outlined contour
*-------------------------------------------------------------------------
*/
void Backend::linevert(TrimVertex* t, REAL* retPoint, REAL* retNormal)
{
surfaceEvaluator.evalcoord2f(t->nuid, t->param[0], t->param[1], retPoint, retNormal);
}
/*-------------------------------------------------------------------------
* linevert - evaluate a grid point of an outlined contour
*-------------------------------------------------------------------------
*/
void Backend::linevert(GridVertex* g)
{
surfaceEvaluator.evalpoint2i(g->gparam[0], g->gparam[1]);
}
/*-------------------------------------------------------------------------
* endoutline - postamble to outlined rendering
*-------------------------------------------------------------------------
*/
void Backend::endoutline(void)
{
surfaceEvaluator.endline();
}
/*-------------------------------------------------------------------------
* triangle - output a triangle
*-------------------------------------------------------------------------
*/
void Backend::triangle(TrimVertex* a, TrimVertex* b, TrimVertex* c)
{
REAL retPoint[4];
REAL retNormal[3];
REAL vertices[3*3];
REAL normals[3*3];
GLboolean texcoord_enabled;
GLboolean normal_enabled;
GLboolean vertex_enabled;
GLboolean color_enabled;
/* Store status of enabled arrays */
texcoord_enabled=GL_FALSE; /* glIsEnabled(GL_TEXTURE_COORD_ARRAY); */
normal_enabled=GL_FALSE; /* glIsEnabled(GL_NORMAL_ARRAY); */
vertex_enabled=GL_FALSE; /* glIsEnabled(GL_VERTEX_ARRAY); */
color_enabled=GL_FALSE; /* glIsEnabled(GL_COLOR_ARRAY); */
/* Enable needed and disable unneeded arrays */
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
bgntfan();
tmeshvert(a, retPoint, retNormal);
vertices[0]=retPoint[0];
vertices[1]=retPoint[1];
vertices[2]=retPoint[2];
normals[0]=retNormal[0];
normals[1]=retNormal[1];
normals[2]=retNormal[2];
tmeshvert(b, retPoint, retNormal);
vertices[3]=retPoint[0];
vertices[4]=retPoint[1];
vertices[5]=retPoint[2];
normals[3]=retNormal[0];
normals[4]=retNormal[1];
normals[5]=retNormal[2];
tmeshvert(c, retPoint, retNormal);
vertices[6]=retPoint[0];
vertices[7]=retPoint[1];
vertices[8]=retPoint[2];
normals[6]=retNormal[0];
normals[7]=retNormal[1];
normals[8]=retNormal[2];
endtfan();
if (get_output_style()==N_MESHLINE)
{
glDrawArrays(GL_LINE_LOOP, 0, 3);
}
else
{
glDrawArrays(GL_TRIANGLE_FAN, 0, 3);
}
/* Disable or re-enable arrays */
if (vertex_enabled)
{
/* Re-enable vertex array */
glEnableClientState(GL_VERTEX_ARRAY);
}
else
{
glDisableClientState(GL_VERTEX_ARRAY);
}
if (texcoord_enabled)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
else
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if (normal_enabled)
{
glEnableClientState(GL_NORMAL_ARRAY);
}
else
{
glDisableClientState(GL_NORMAL_ARRAY);
}
if (color_enabled)
{
glEnableClientState(GL_COLOR_ARRAY);
}
else
{
glDisableClientState(GL_COLOR_ARRAY);
}
}
long Backend::get_output_style(void)
{
return surfaceEvaluator.get_output_style();
}
void Backend::bgncurv(void)
{
curveEvaluator.bgnmap1f(0);
}
void Backend::segment(REAL ulo, REAL uhi)
{
curveEvaluator.domain1f(ulo, uhi);
}
void Backend::curvpts(long type, /* geometry, color, texture, normal */
REAL* pts, /* control points */
long stride, /* distance to next point */
int order, /* parametric order */
REAL ulo, /* lower parametric bound */
REAL uhi) /* upper parametric bound */
{
curveEvaluator.map1f(type, ulo, uhi, stride, order, pts);
curveEvaluator.enable(type);
}
void Backend::curvgrid(REAL u0, REAL u1, long nu)
{
curveEvaluator.mapgrid1f(nu, u0, u1);
}
void Backend::curvmesh(long from, long n)
{
curveEvaluator.mapmesh1f(N_MESHFILL, from, from+n);
}
void Backend::curvpt(REAL u)
{
curveEvaluator.evalcoord1f(0, u);
}
void Backend::bgnline(void)
{
curveEvaluator.bgnline();
}
void Backend::endline(void)
{
curveEvaluator.endline();
}
void Backend::endcurv(void)
{
curveEvaluator.endmap1f();
}

View File

@@ -0,0 +1,108 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glubackend_h_
#define __glubackend_h_
#include "trimvertex.h"
#include "gridvertex.h"
#include "gridtrimvertex.h"
class BasicCurveEvaluator;
class BasicSurfaceEvaluator;
class Backend
{
private:
BasicCurveEvaluator& curveEvaluator;
BasicSurfaceEvaluator& surfaceEvaluator;
public:
Backend(BasicCurveEvaluator& c, BasicSurfaceEvaluator& e):
curveEvaluator(c), surfaceEvaluator(e) { }
/* surface backend routines */
void bgnsurf(int, int, long);
void patch(REAL, REAL, REAL, REAL);
void surfpts(long, REAL*, long, long, int, int, REAL, REAL, REAL, REAL);
void surfbbox(long, REAL*, REAL*);
void surfgrid(REAL, REAL, long, REAL, REAL, long);
void surfmesh(long, long, long, long);
void bgntmesh(const char*);
void endtmesh(void);
void swaptmesh(void);
void tmeshvert(GridTrimVertex*);
void tmeshvert(TrimVertex*, REAL*, REAL*);
void tmeshvert(GridVertex*);
void tmeshvert(REAL u, REAL v, REAL*, REAL*);
void linevert(TrimVertex*, REAL*, REAL*);
void linevert(GridVertex*);
void bgnoutline(void);
void endoutline(void);
void endsurf(void);
void triangle(TrimVertex*, TrimVertex*, TrimVertex*);
long get_output_style(void);
void bgntfan();
void endtfan();
void bgnqstrip();
void endqstrip();
void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val, int n_lower, REAL v_lower, REAL* lower_val);
void evalVStrip(int n_left, REAL u_left, REAL* left_val, int n_right, REAL v_right, REAL* right_val);
void tmeshvertNOGE(TrimVertex* t);
void tmeshvertNOGE_BU(TrimVertex* t);
void tmeshvertNOGE_BV(TrimVertex* t);
void preEvaluateBU(REAL u);
void preEvaluateBV(REAL v);
/* curve backend routines */
void bgncurv(void);
void segment(REAL, REAL);
void curvpts(long, REAL*, long, int, REAL, REAL);
void curvgrid(REAL, REAL, long);
void curvmesh(long, long);
void curvpt(REAL);
void bgnline(void);
void endline(void);
void endcurv(void);
private:
int wireframetris;
int wireframequads;
int npts;
REAL mesh[3][4];
int meshindex;
};
#endif /* __glubackend_h_ */

View File

@@ -0,0 +1,89 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "mystdio.h"
#include "types.h"
#include "basiccrveval.h"
void BasicCurveEvaluator::domain1f(REAL, REAL)
{
}
void BasicCurveEvaluator::range1f(long , REAL*, REAL*)
{
}
void BasicCurveEvaluator::enable(long)
{
}
void BasicCurveEvaluator::disable(long)
{
}
void BasicCurveEvaluator::bgnmap1f(long)
{
}
void BasicCurveEvaluator::map1f(long, REAL, REAL, long, long, REAL*)
{
}
void BasicCurveEvaluator::mapgrid1f(long, REAL, REAL)
{
}
void BasicCurveEvaluator::mapmesh1f(long, long, long)
{
}
void BasicCurveEvaluator::evalcoord1f(long, REAL)
{
}
void BasicCurveEvaluator::endmap1f(void)
{
}
void BasicCurveEvaluator::bgnline(void)
{
}
void BasicCurveEvaluator::endline(void)
{
}

View File

@@ -0,0 +1,63 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* basiccurveeval.h
*
*/
#ifndef __glubasiccrveval_h_
#define __glubasiccrveval_h_
#include "types.h"
#include "displaymode.h"
#include "cachingeval.h"
class BasicCurveEvaluator: public CachingEvaluator
{
public:
virtual ~BasicCurveEvaluator() { /* silence warning*/ }
virtual void domain1f(REAL, REAL);
virtual void range1f(long, REAL*, REAL*);
virtual void enable(long);
virtual void disable(long);
virtual void bgnmap1f(long);
virtual void map1f(long, REAL, REAL, long, long, REAL*);
virtual void mapgrid1f(long, REAL, REAL);
virtual void mapmesh1f(long, long, long);
virtual void evalcoord1f(long, REAL);
virtual void endmap1f(void);
virtual void bgnline(void);
virtual void endline(void);
};
#endif /* __glubasiccrveval_h_ */

View File

@@ -0,0 +1,143 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "mystdio.h"
#include "types.h"
#include "basicsurfeval.h"
#ifdef __WATCOMC__
#pragma warning 726 10
#endif
void BasicSurfaceEvaluator::domain2f(REAL, REAL, REAL, REAL)
{
}
void BasicSurfaceEvaluator::polymode(long)
{
}
long BasicSurfaceEvaluator::get_output_style()
{
return N_MESHFILL;
}
void BasicSurfaceEvaluator::range2f(long type, REAL* from, REAL* to)
{
}
void BasicSurfaceEvaluator::enable(long)
{
}
void BasicSurfaceEvaluator::disable(long)
{
}
void BasicSurfaceEvaluator::bgnmap2f(long)
{
}
void BasicSurfaceEvaluator::endmap2f(void)
{
}
void BasicSurfaceEvaluator::map2f(long, REAL, REAL, long, long,
REAL, REAL, long, long, REAL*)
{
}
void BasicSurfaceEvaluator::mapgrid2f(long, REAL, REAL, long, REAL, REAL)
{
}
void BasicSurfaceEvaluator::mapmesh2f(long, long, long, long, long)
{
}
void BasicSurfaceEvaluator::evalcoord2f(long, REAL, REAL, REAL*, REAL*)
{
}
void BasicSurfaceEvaluator::evalpoint2i(long, long)
{
}
void BasicSurfaceEvaluator::bgnline(void)
{
}
void BasicSurfaceEvaluator::endline(void)
{
}
void BasicSurfaceEvaluator::bgnclosedline(void)
{
}
void BasicSurfaceEvaluator::endclosedline(void)
{
}
void BasicSurfaceEvaluator::bgntfan(void)
{
}
void BasicSurfaceEvaluator::endtfan(void)
{
}
void BasicSurfaceEvaluator::bgntmesh(void)
{
}
void BasicSurfaceEvaluator::swaptmesh(void)
{
}
void BasicSurfaceEvaluator::endtmesh(void)
{
}
void BasicSurfaceEvaluator::bgnqstrip(void)
{
}
void BasicSurfaceEvaluator::endqstrip(void)
{
}

View File

@@ -0,0 +1,84 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glubasicsurfeval_h_
#define __glubasicsurfeval_h_
#include "types.h"
#include "displaymode.h"
#include "cachingeval.h"
class BasicSurfaceEvaluator: public CachingEvaluator
{
public:
virtual ~BasicSurfaceEvaluator() { /* silence warning*/ }
virtual void range2f(long, REAL*, REAL*);
virtual void domain2f(REAL, REAL, REAL, REAL);
virtual void enable(long);
virtual void disable(long);
virtual void bgnmap2f(long);
virtual void map2f(long, REAL, REAL, long, long, REAL, REAL, long, long, REAL*);
virtual void mapgrid2f(long, REAL, REAL, long, REAL, REAL);
virtual void mapmesh2f(long, long, long, long, long);
virtual void evalcoord2f(long, REAL, REAL, REAL*, REAL*);
virtual void evalpoint2i(long, long);
virtual void endmap2f(void);
virtual void polymode(long);
virtual long get_output_style();
virtual void bgnline(void);
virtual void endline(void);
virtual void bgnclosedline(void);
virtual void endclosedline(void);
virtual void bgntmesh(void);
virtual void swaptmesh(void);
virtual void endtmesh(void);
virtual void bgnqstrip(void);
virtual void endqstrip(void);
virtual void bgntfan(void);
virtual void endtfan(void);
virtual void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val, int n_lower, REAL v_lower, REAL* lower_val)=0;
virtual void evalVStrip(int n_left, REAL u_left, REAL* left_val, int n_right, REAL u_right, REAL* right_val)=0;
virtual void inDoEvalCoord2NOGE(REAL u, REAL v, REAL* ret_point, REAL* ret_normal)=0;
virtual void inDoEvalCoord2NOGE_BU(REAL u, REAL v, REAL* ret_point, REAL* ret_normal)=0;
virtual void inDoEvalCoord2NOGE_BV(REAL u, REAL v, REAL* ret_point, REAL* ret_normal)=0;
virtual void inPreEvaluateBV_intfac(REAL v)=0;
virtual void inPreEvaluateBU_intfac(REAL u)=0;
};
#endif /* __glubasicsurfeval_h_ */

View File

@@ -0,0 +1,52 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glubezierarc_h
#define __glubezierarc_h
#include "myassert.h"
class Mapdesc;
/* a bezier arc */
struct BezierArc: public PooledObj
{
REAL* cpts; /* control points of arc */
int order; /* order of arc */
int stride; /* REAL distance between points */
long type; /* curve type */
Mapdesc* mapdesc;
};
#endif /* __glubezierarc_h */

View File

@@ -0,0 +1,131 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "glimports.h"
#include "mystdio.h"
#include "myassert.h"
#include "bin.h"
/*----------------------------------------------------------------------------
* Constructor and destructor
*----------------------------------------------------------------------------
*/
Bin::Bin()
{
head=NULL;
}
Bin::~Bin()
{
assert(head==NULL);
}
/*----------------------------------------------------------------------------
* remove_this_arc - remove given Arc_ptr from bin
*----------------------------------------------------------------------------
*/
void Bin::remove_this_arc(Arc_ptr arc)
{
Arc_ptr* j;
for (j=&(head); (*j!=0) && (*j!=arc); j=&((*j)->link));
if (*j!=0)
{
if (*j==current)
{
current=(*j)->link;
}
*j=(*j)->link;
}
}
/*----------------------------------------------------------------------------
* numarcs - count number of arcs in bin
*----------------------------------------------------------------------------
*/
int Bin::numarcs()
{
long count=0;
for (Arc_ptr jarc=firstarc(); jarc; jarc=nextarc())
{
count++;
}
return count;
}
/*----------------------------------------------------------------------------
* adopt - place an orphaned arcs into their new parents bin
*----------------------------------------------------------------------------
*/
void Bin::adopt()
{
markall();
Arc_ptr orphan;
while ((orphan=removearc())!=NULL)
{
for (Arc_ptr parent=orphan->next; parent!=orphan; parent=parent->next)
{
if (!parent->ismarked())
{
orphan->link=parent->link;
parent->link=orphan;
orphan->clearmark();
break;
}
}
}
}
/*----------------------------------------------------------------------------
* markall - mark all arcs with an identifying tag
*----------------------------------------------------------------------------
*/
void Bin::markall()
{
for (Arc_ptr jarc=firstarc(); jarc; jarc=nextarc())
{
jarc->setmark();
}
}

View File

@@ -0,0 +1,121 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glubin_h_
#define __glubin_h_
#include "myassert.h"
#include "arc.h"
#include "defines.h"
/* a linked list of jordan arcs */
class Bin
{
private:
Arc_ptr head; /*first arc on list */
Arc_ptr current; /* current arc on list */
public:
Bin();
~Bin();
inline Arc_ptr firstarc(void);
inline Arc_ptr nextarc(void);
inline Arc_ptr removearc(void);
inline int isnonempty(void) { return (head ? 1 : 0); }
inline void addarc(Arc_ptr);
void remove_this_arc(Arc_ptr);
int numarcs(void);
void adopt(void);
void markall(void);
};
/*----------------------------------------------------------------------------
* Bin::addarc - add an Arc_ptr to head of linked list of Arc_ptr
*----------------------------------------------------------------------------
*/
inline void Bin::addarc(Arc_ptr jarc)
{
jarc->link=head;
head=jarc;
}
/*----------------------------------------------------------------------------
* Bin::removearc - remove first Arc_ptr from bin
*----------------------------------------------------------------------------
*/
inline Arc_ptr Bin::removearc(void)
{
Arc_ptr jarc=head;
if (jarc)
{
head=jarc->link;
}
return jarc;
}
/*----------------------------------------------------------------------------
* BinIter::nextarc - return current arc in bin and advance pointer to next arc
*----------------------------------------------------------------------------
*/
inline Arc_ptr Bin::nextarc(void)
{
Arc_ptr jarc=current;
if (jarc)
{
current=jarc->link;
}
return jarc;
}
/*----------------------------------------------------------------------------
* BinIter::firstarc - set current arc to first arc of bin advance to next arc
*----------------------------------------------------------------------------
*/
inline Arc_ptr Bin::firstarc(void)
{
current=head;
return nextarc();
}
#endif /* __glubin_h_ */

View File

@@ -0,0 +1,116 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "glimports.h"
#include "myassert.h"
#include "bufpool.h"
/*-----------------------------------------------------------------------------
* Pool - allocate a new pool of buffers
*-----------------------------------------------------------------------------
*/
Pool::Pool(int _buffersize, int initpoolsize, const char* n)
{
if ((unsigned)_buffersize<sizeof(Buffer))
{
buffersize=sizeof(Buffer);
}
else
{
buffersize=_buffersize;
}
initsize=initpoolsize*buffersize;
nextsize=initsize;
name=n;
magic=is_allocated;
nextblock=0;
curblock=0;
freelist=0;
nextfree=0;
}
/*-----------------------------------------------------------------------------
* ~Pool - free a pool of buffers and the pool itself
*-----------------------------------------------------------------------------
*/
Pool::~Pool(void)
{
assert((this!=0) && (magic==is_allocated));
while (nextblock)
{
delete[] blocklist[--nextblock];
blocklist[nextblock]=0;
}
magic=is_free;
}
void Pool::grow(void)
{
assert((this!=0) && (magic==is_allocated));
curblock=new char[nextsize];
blocklist[nextblock++]=curblock;
nextfree=nextsize;
nextsize*=2;
}
/*-----------------------------------------------------------------------------
* Pool::clear - free buffers associated with pool but keep pool
*-----------------------------------------------------------------------------
*/
void Pool::clear(void)
{
assert((this!=0) && (magic==is_allocated));
while (nextblock)
{
delete[] blocklist[--nextblock];
blocklist[nextblock]=0;
}
curblock=0;
freelist=0;
nextfree=0;
if (nextsize>initsize)
{
nextsize/=2;
}
}

View File

@@ -0,0 +1,142 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glubufpool_h_
#define __glubufpool_h_
#include "myassert.h"
#include "mystdlib.h"
#define NBLOCKS 32
class Buffer
{
friend class Pool;
Buffer* next; /* next buffer on free list */
};
class Pool
{
public:
Pool(int, int, const char*);
~Pool(void);
inline void* new_buffer(void);
inline void free_buffer(void*);
void clear(void);
private:
void grow(void);
protected:
Buffer* freelist; /* linked list of free buffers */
char* blocklist[NBLOCKS]; /* blocks of malloced memory */
int nextblock; /* next free block index */
char* curblock; /* last malloced block */
int buffersize; /* bytes per buffer */
int nextsize; /* size of next block of memory */
int nextfree; /* byte offset past next free buffer */
int initsize;
enum Magic {is_allocated=0xf3a1, is_free=0xf1a2};
const char* name; /* name of the pool */
Magic magic; /* marker for valid pool */
};
/*-----------------------------------------------------------------------------
* Pool::free_buffer - return a buffer to a pool
*-----------------------------------------------------------------------------
*/
inline void Pool::free_buffer(void* b)
{
assert((this!=0) && (magic==is_allocated));
/* add buffer to singly connected free list */
((Buffer*)b)->next=freelist;
freelist=(Buffer*)b;
}
/*-----------------------------------------------------------------------------
* Pool::new_buffer - allocate a buffer from a pool
*-----------------------------------------------------------------------------
*/
inline void* Pool::new_buffer(void)
{
void* buffer;
assert((this!=0) && (magic==is_allocated));
/* find free buffer */
if (freelist)
{
buffer=(void*)freelist;
freelist=freelist->next;
}
else
{
if (!nextfree)
{
grow();
}
nextfree-=buffersize;;
buffer=(void*)(curblock+nextfree);
}
return buffer;
}
class PooledObj
{
public:
inline void* operator new(size_t, Pool&);
inline void* operator new(size_t, void*);
inline void* operator new(size_t s) {return ::new char[s];}
inline void operator delete(void*) {assert(0);}
inline void operator delete(void*, Pool&) {assert(0);}
inline void deleteMe(Pool&);
};
inline void* PooledObj::operator new(size_t, Pool& pool)
{
return pool.new_buffer();
}
inline void PooledObj::deleteMe(Pool& pool)
{
pool.free_buffer((void*) this);
}
#endif /* __glubufpool_h_ */

View File

@@ -0,0 +1,70 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#include "cachingeval.h"
int CachingEvaluator::canRecord(void)
{
return 0;
}
int CachingEvaluator::canPlayAndRecord(void)
{
return 0;
}
int CachingEvaluator::createHandle(int)
{
return 0;
}
void CachingEvaluator::beginOutput(ServiceMode, int)
{
}
void CachingEvaluator::endOutput(void)
{
}
void CachingEvaluator::discardRecording(int)
{
}
void CachingEvaluator::playRecording(int)
{
}

View File

@@ -0,0 +1,52 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glucachingval_h_
#define __glucachingval_h_
class CachingEvaluator
{
public:
virtual ~CachingEvaluator() { /* silence warning*/ }
enum ServiceMode { play, record, playAndRecord };
virtual int canRecord(void);
virtual int canPlayAndRecord(void);
virtual int createHandle(int handle);
virtual void beginOutput(ServiceMode, int handle);
virtual void endOutput(void);
virtual void discardRecording(int handle);
virtual void playRecording(int handle);
};
#endif /* __glucachingval_h_ */

View File

@@ -0,0 +1,427 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* ccw.c++
*
*/
#include "glimports.h"
#include "mystdio.h"
#include "myassert.h"
#include "subdivider.h"
#include "types.h"
#include "arc.h"
#include "trimvertex.h"
#include "simplemath.h"
inline int Subdivider::bbox(TrimVertex* a, TrimVertex* b, TrimVertex* c, int p)
{
return bbox(a->param[p], b->param[p], c->param[p], a->param[1-p], b->param[1-p], c->param[1-p]);
}
int Subdivider::ccwTurn_sr(Arc_ptr j1, Arc_ptr j2) // dir = 1
{
register TrimVertex* v1=&j1->pwlArc->pts[j1->pwlArc->npts-1];
register TrimVertex* v1last=&j1->pwlArc->pts[0];
register TrimVertex* v2=&j2->pwlArc->pts[0];
register TrimVertex* v2last=&j2->pwlArc->pts[j2->pwlArc->npts-1];
register TrimVertex* v1next=v1-1;
register TrimVertex* v2next=v2+1;
int sgn;
assert(v1!=v1last);
assert(v2!=v2last);
// the arcs lie on the line (0 == v1->param[0])
if (v1->param[0]==v1next->param[0] && v2->param[0]==v2next->param[0])
{
return 0;
}
if( v2next->param[0] < v2->param[0] || v1next->param[0] < v1->param[0] )
::mylongjmp( jumpbuffer, 28 );
if( v1->param[1] < v2->param[1] )
return 0;
else if( v1->param[1] > v2->param[1] )
return 1;
while( 1 ) {
if( v1next->param[0] < v2next->param[0] ) {
assert( v1->param[0] <= v1next->param[0] );
assert( v2->param[0] <= v1next->param[0] );
switch( bbox( v2, v2next, v1next, 1 ) ) {
case -1:
return 0;
case 0:
sgn = ccw( v1next, v2, v2next );
if( sgn != -1 ) {
return sgn;
} else {
v1 = v1next--;
if( v1 == v1last ) {
return 0; // ill-conditioned, guess answer
}
}
break;
case 1:
return 1;
}
} else if( v1next->param[0] > v2next->param[0] ) {
assert( v1->param[0] <= v2next->param[0] );
assert( v2->param[0] <= v2next->param[0] );
switch( bbox( v1, v1next, v2next, 1 ) ) {
case -1:
return 1;
case 0:
sgn = ccw( v1next, v1, v2next );
if( sgn != -1 ) {
return sgn;
} else {
v2 = v2next++;
if( v2 == v2last ) {
return 0; // ill-conditioned, guess answer
}
}
break;
case 1:
return 0;
}
} else {
if( v1next->param[1] < v2next->param[1] )
return 0;
else if( v1next->param[1] > v2next->param[1] )
return 1;
else {
v2 = v2next++;
if( v2 == v2last ) {
return 0; // ill-conditioned, guess answer
}
}
}
}
}
int
Subdivider::ccwTurn_sl( Arc_ptr j1, Arc_ptr j2 ) // dir = 0
{
register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1];
register TrimVertex *v1last = &j1->pwlArc->pts[0];
register TrimVertex *v2 = &j2->pwlArc->pts[0];
register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1];
register TrimVertex *v1next = v1-1;
register TrimVertex *v2next = v2+1;
int sgn;
assert( v1 != v1last );
assert( v2 != v2last );
// the arcs lie on the line (0 == v1->param[0])
if( v1->param[0] == v1next->param[0] && v2->param[0] == v2next->param[0] )
return 0;
if( v2next->param[0] > v2->param[0] || v1next->param[0] > v1->param[0] )
::mylongjmp( jumpbuffer, 28 );
if( v1->param[1] < v2->param[1] )
return 1;
else if( v1->param[1] > v2->param[1] )
return 0;
while( 1 ) {
if( v1next->param[0] > v2next->param[0] ) {
assert( v1->param[0] >= v1next->param[0] );
assert( v2->param[0] >= v1next->param[0] );
switch( bbox( v2next, v2, v1next, 1 ) ) {
case -1:
return 1;
case 0:
sgn = ccw( v1next, v2, v2next );
if( sgn != -1 )
return sgn;
else {
v1 = v1next--;
if( v1 == v1last ) {
return 0; // ill-conditioned, guess answer
}
}
break;
case 1:
return 0;
}
} else if( v1next->param[0] < v2next->param[0] ) {
assert( v1->param[0] >= v2next->param[0] );
assert( v2->param[0] >= v2next->param[0] );
switch( bbox( v1next, v1, v2next, 1 ) ) {
case -1:
return 0;
case 0:
sgn = ccw( v1next, v1, v2next );
if( sgn != -1 )
return sgn;
else {
v2 = v2next++;
if( v2 == v2last ) {
return 0; // ill-conditioned, guess answer
}
}
break;
case 1:
return 1;
}
} else {
if( v1next->param[1] < v2next->param[1] )
return 1;
else if( v1next->param[1] > v2next->param[1] )
return 0;
else {
v2 = v2next++;
if( v2 == v2last ) {
return 0; // ill-conditioned, guess answer
}
}
}
}
}
int
Subdivider::ccwTurn_tr( Arc_ptr j1, Arc_ptr j2 ) // dir = 1
{
register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1];
register TrimVertex *v1last = &j1->pwlArc->pts[0];
register TrimVertex *v2 = &j2->pwlArc->pts[0];
register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1];
register TrimVertex *v1next = v1-1;
register TrimVertex *v2next = v2+1;
int sgn;
assert( v1 != v1last );
assert( v2 != v2last );
// the arcs lie on the line (1 == v1->param[1])
if( v1->param[1] == v1next->param[1] && v2->param[1] == v2next->param[1] )
return 0;
if( v2next->param[1] < v2->param[1] || v1next->param[1] < v1->param[1] )
::mylongjmp( jumpbuffer, 28 );
if( v1->param[0] < v2->param[0] )
return 1;
else if( v1->param[0] > v2->param[0] )
return 0;
while( 1 ) {
if( v1next->param[1] < v2next->param[1] ) {
assert( v1->param[1] <= v1next->param[1] );
assert( v2->param[1] <= v1next->param[1] );
switch( bbox( v2, v2next, v1next, 0 ) ) {
case -1:
return 1;
case 0:
sgn = ccw( v1next, v2, v2next );
if( sgn != -1 ) {
return sgn;
} else {
v1 = v1next--;
if( v1 == v1last ) {
return 0; // ill-conditioned, guess answer
}
}
break;
case 1:
return 0;
}
} else if( v1next->param[1] > v2next->param[1] ) {
assert( v1->param[1] <= v2next->param[1] );
assert( v2->param[1] <= v2next->param[1] );
switch( bbox( v1, v1next, v2next, 0 ) ) {
case -1:
return 0;
case 0:
sgn = ccw( v1next, v1, v2next );
if( sgn != -1 ) {
return sgn;
} else {
v2 = v2next++;
if( v2 == v2last ) {
return 0; // ill-conditioned, guess answer
}
}
break;
case 1:
return 1;
}
} else {
if( v1next->param[0] < v2next->param[0] )
return 1;
else if( v1next->param[0] > v2next->param[0] )
return 0;
else {
v2 = v2next++;
if( v2 == v2last ) {
return 0; // ill-conditioned, guess answer
}
}
}
}
}
int
Subdivider::ccwTurn_tl( Arc_ptr j1, Arc_ptr j2 )
{
register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1];
register TrimVertex *v1last = &j1->pwlArc->pts[0];
register TrimVertex *v2 = &j2->pwlArc->pts[0];
register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1];
register TrimVertex *v1next = v1-1;
register TrimVertex *v2next = v2+1;
int sgn;
assert( v1 != v1last );
assert( v2 != v2last );
// the arcs lie on the line (1 == v1->param[1])
if( v1->param[1] == v1next->param[1] && v2->param[1] == v2next->param[1] )
return 0;
if( v2next->param[1] > v2->param[1] || v1next->param[1] > v1->param[1] )
::mylongjmp( jumpbuffer, 28 );
if( v1->param[0] < v2->param[0] )
return 0;
else if( v1->param[0] > v2->param[0] )
return 1;
while( 1 ) {
if( v1next->param[1] > v2next->param[1] ) {
assert( v1->param[1] >= v1next->param[1] );
assert( v2->param[1] >= v1next->param[1] );
switch( bbox( v2next, v2, v1next, 0 ) ) {
case -1:
return 0;
case 0:
sgn = ccw( v1next, v2, v2next );
if( sgn != -1 )
return sgn;
else {
v1 = v1next--;
if( v1 == v1last ) {
return 0; // ill-conditioned, guess answer
}
}
break;
case 1:
return 1;
}
} else if( v1next->param[1] < v2next->param[1] ) {
switch( bbox( v1next, v1, v2next, 0 ) ) {
case -1:
return 1;
case 0:
sgn = ccw( v1next, v1, v2next );
if( sgn != -1 )
return sgn;
else {
v2 = v2next++;
if( v2 == v2last ) {
return 0; // ill-conditioned, guess answer
}
}
break;
case 1:
return 0;
}
} else {
if( v1next->param[0] < v2next->param[0] )
return 0;
else if( v1next->param[0] > v2next->param[0] )
return 1;
else {
v2 = v2next++;
if( v2 == v2last ) {
return 0; // ill-conditioned, guess answer
}
}
}
}
}
int
Subdivider::bbox( register REAL sa, register REAL sb, register REAL sc,
register REAL , register REAL , register REAL )
{
if( sa < sb ) {
if( sc <= sa ) {
return -1;
} else if( sb <= sc ) {
return 1;
} else {
return 0;
}
} else if( sa > sb ) {
if( sc >= sa ) {
return 1;
} else if( sb >= sc ) {
return -1;
} else {
return 0;
}
} else {
if( sc > sa ) {
return 1;
} else if( sb > sc ) {
return -1;
} else {
return 0;
}
}
}
/*----------------------------------------------------------------------------
* ccw - determine how three points are oriented by computing their
* determinant.
* Return 1 if the vertices are ccw oriented,
* 0 if they are cw oriented, or
* -1 if the computation is ill-conditioned.
*----------------------------------------------------------------------------
*/
int
Subdivider::ccw( TrimVertex *a, TrimVertex *b, TrimVertex *c )
{
REAL d = det3( a, b, c );
if( glu_abs(d) < 0.0001 ) return -1;
return (d < 0.0) ? 0 : 1;
}

View File

@@ -0,0 +1,442 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* coveandtiler.c++
*
*/
#include "glimports.h"
#include "myassert.h"
#include "mystdio.h"
#include "coveandtiler.h"
#include "gridvertex.h"
#include "gridtrimvertex.h"
#include "uarray.h"
#include "backend.h"
#include <stdio.h>
const int CoveAndTiler::MAXSTRIPSIZE = 1000;
CoveAndTiler::CoveAndTiler( Backend& b )
: backend( b )
{ }
CoveAndTiler::~CoveAndTiler( void )
{ }
inline void
CoveAndTiler::output( GridVertex &gv )
{
backend.tmeshvert( &gv );
}
inline void CoveAndTiler::output(TrimVertex* tv)
{
REAL retPoint[4];
REAL retNormal[3];
backend.tmeshvert(tv, retPoint, retNormal);
}
inline void
CoveAndTiler::output( GridTrimVertex& g )
{
backend.tmeshvert( &g );
}
void
CoveAndTiler::coveAndTile( void )
{
long ustart = (top.ustart >= bot.ustart) ? top.ustart : bot.ustart;
long uend = (top.uend <= bot.uend) ? top.uend : bot.uend;
if( ustart <= uend ) {
tile( bot.vindex, ustart, uend );
if( top.ustart >= bot.ustart )
coveUpperLeft();
else
coveLowerLeft();
if( top.uend <= bot.uend )
coveUpperRight();
else
coveLowerRight();
} else {
TrimVertex blv, tlv, *bl, *tl;
GridTrimVertex bllv, tllv;
TrimVertex *lf = left.first();
TrimVertex *ll = left.last();
if( lf->param[0] >= ll->param[0] ) {
blv.param[0] = lf->param[0];
blv.param[1] = ll->param[1];
blv.nuid = 0; // XXX
assert( blv.param[1] == bot.vval );
bl = &blv;
tl = lf;
tllv.set( lf );
if( ll->param[0] > uarray.uarray[top.ustart-1] ) {
bllv.set( ll );
assert( ll->param[0] <= uarray.uarray[bot.ustart] );
} else {
bllv.set( top.ustart-1, bot.vindex );
}
coveUpperLeftNoGrid( bl );
} else {
tlv.param[0] = ll->param[0];
tlv.param[1] = lf->param[1];
tlv.nuid = 0; // XXX
assert( tlv.param[1] == top.vval );
tl = &tlv;
bl = ll;
bllv.set( ll );
if( lf->param[0] > uarray.uarray[bot.ustart-1] ) {
assert( lf->param[0] <= uarray.uarray[bot.ustart] );
tllv.set( lf );
} else {
tllv.set( bot.ustart-1, top.vindex );
}
coveLowerLeftNoGrid( tl );
}
TrimVertex brv, trv, *br, *tr;
GridTrimVertex brrv, trrv;
TrimVertex *rf = right.first();
TrimVertex *rl = right.last();
if( rf->param[0] <= rl->param[0] ) {
brv.param[0] = rf->param[0];
brv.param[1] = rl->param[1];
brv.nuid = 0; // XXX
assert( brv.param[1] == bot.vval );
br = &brv;
tr = rf;
trrv.set( rf );
if( rl->param[0] < uarray.uarray[top.uend+1] ) {
assert( rl->param[0] >= uarray.uarray[top.uend] );
brrv.set( rl );
} else {
brrv.set( top.uend+1, bot.vindex );
}
coveUpperRightNoGrid( br );
} else {
trv.param[0] = rl->param[0];
trv.param[1] = rf->param[1];
trv.nuid = 0; // XXX
assert( trv.param[1] == top.vval );
tr = &trv;
br = rl;
brrv.set( rl );
if( rf->param[0] < uarray.uarray[bot.uend+1] ) {
assert( rf->param[0] >= uarray.uarray[bot.uend] );
trrv.set( rf );
} else {
trrv.set( bot.uend+1, top.vindex );
}
coveLowerRightNoGrid( tr );
}
backend.bgntmesh( "doit" );
output(trrv);
output(tllv);
output( tr );
output( tl );
output( br );
output( bl );
output(brrv);
output(bllv);
backend.endtmesh();
}
}
void
CoveAndTiler::tile( long vindex, long ustart, long uend )
{
long numsteps = uend - ustart;
if( numsteps == 0 ) return;
if( numsteps > MAXSTRIPSIZE ) {
long umid = ustart + (uend - ustart) / 2;
tile( vindex, ustart, umid );
tile( vindex, umid, uend );
} else {
backend.surfmesh( ustart, vindex-1, numsteps, 1 );
}
}
void
CoveAndTiler::coveUpperRight( void )
{
GridVertex tgv( top.uend, top.vindex );
GridVertex gv( top.uend, bot.vindex );
right.first();
backend.bgntmesh( "coveUpperRight" );
output( right.next() );
output( tgv );
backend.swaptmesh();
output( gv );
coveUR();
backend.endtmesh();
}
void
CoveAndTiler::coveUpperRightNoGrid( TrimVertex* br )
{
backend.bgntmesh( "coveUpperRight" );
output( right.first() );
output( right.next() );
backend.swaptmesh();
output( br );
coveUR();
backend.endtmesh();
}
void
CoveAndTiler::coveUR( )
{
GridVertex gv( top.uend, bot.vindex );
TrimVertex *vert = right.next();
if( vert == NULL ) return;
assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
if( gv.nextu() >= bot.uend ) {
for( ; vert; vert = right.next() ) {
output( vert );
backend.swaptmesh();
}
} else while( 1 ) {
if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
output( vert );
backend.swaptmesh();
vert = right.next();
if( vert == NULL ) break;
} else {
backend.swaptmesh();
output( gv );
if( gv.nextu() == bot.uend ) {
for( ; vert; vert = right.next() ) {
output( vert );
backend.swaptmesh();
}
break;
}
}
}
}
void
CoveAndTiler::coveUpperLeft( void )
{
GridVertex tgv( top.ustart, top.vindex );
GridVertex gv( top.ustart, bot.vindex );
left.first();
backend.bgntmesh( "coveUpperLeft" );
output( tgv );
output( left.next() );
output( gv );
backend.swaptmesh();
coveUL();
backend.endtmesh();
}
void
CoveAndTiler::coveUpperLeftNoGrid( TrimVertex* bl )
{
backend.bgntmesh( "coveUpperLeftNoGrid" );
output( left.first() );
output( left.next() );
output( bl );
backend.swaptmesh();
coveUL();
backend.endtmesh();
}
void
CoveAndTiler::coveUL()
{
GridVertex gv( top.ustart, bot.vindex );
TrimVertex *vert = left.next();
if( vert == NULL ) return;
assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
if( gv.prevu() <= bot.ustart ) {
for( ; vert; vert = left.next() ) {
backend.swaptmesh();
output( vert );
}
} else while( 1 ) {
if( vert->param[0] > uarray.uarray[gv.gparam[0]] ) {
backend.swaptmesh();
output( vert );
vert = left.next();
if( vert == NULL ) break;
} else {
output( gv );
backend.swaptmesh();
if( gv.prevu() == bot.ustart ) {
for( ; vert; vert = left.next() ) {
backend.swaptmesh();
output( vert );
}
break;
}
}
}
}
void
CoveAndTiler::coveLowerLeft( void )
{
GridVertex bgv( bot.ustart, bot.vindex );
GridVertex gv( bot.ustart, top.vindex );
left.last();
backend.bgntmesh( "coveLowerLeft" );
output( left.prev() );
output( bgv );
backend.swaptmesh();
output( gv );
coveLL();
backend.endtmesh();
}
void
CoveAndTiler::coveLowerLeftNoGrid( TrimVertex* tl )
{
backend.bgntmesh( "coveLowerLeft" );
output( left.last() );
output( left.prev() );
backend.swaptmesh();
output( tl );
coveLL( );
backend.endtmesh();
}
void
CoveAndTiler::coveLL()
{
GridVertex gv( bot.ustart, top.vindex );
TrimVertex *vert = left.prev();
if( vert == NULL ) return;
assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
if( gv.prevu() <= top.ustart ) {
for( ; vert; vert = left.prev() ) {
output( vert );
backend.swaptmesh();
}
} else while( 1 ) {
if( vert->param[0] > uarray.uarray[gv.gparam[0]] ){
output( vert );
backend.swaptmesh();
vert = left.prev();
if( vert == NULL ) break;
} else {
backend.swaptmesh();
output( gv );
if( gv.prevu() == top.ustart ) {
for( ; vert; vert = left.prev() ) {
output( vert );
backend.swaptmesh();
}
break;
}
}
}
}
void CoveAndTiler::coveLowerRight(void)
{
GridVertex bgv(bot.uend, bot.vindex);
GridVertex gv(bot.uend, top.vindex);
right.last();
backend.bgntmesh("coveLowerRight");
output(bgv);
output(right.prev());
output(gv);
backend.swaptmesh();
coveLR();
backend.endtmesh();
}
void
CoveAndTiler::coveLowerRightNoGrid( TrimVertex* tr )
{
backend.bgntmesh( "coveLowerRIght" );
output( right.last() );
output( right.prev() );
output( tr );
backend.swaptmesh();
coveLR();
backend.endtmesh();
}
void
CoveAndTiler::coveLR( )
{
GridVertex gv( bot.uend, top.vindex );
TrimVertex *vert = right.prev();
if( vert == NULL ) return;
assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
if( gv.nextu() >= top.uend ) {
for( ; vert; vert = right.prev() ) {
backend.swaptmesh();
output( vert );
}
} else while( 1 ) {
if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
backend.swaptmesh();
output( vert );
vert = right.prev();
if( vert == NULL ) break;
} else {
output( gv );
backend.swaptmesh();
if( gv.nextu() == top.uend ) {
for( ; vert; vert = right.prev() ) {
backend.swaptmesh();
output( vert );
}
break;
}
}
}
}

View File

@@ -0,0 +1,72 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* coveandtiler.h
*
*/
#ifndef __glucoveandtiler_h
#define __glucoveandtiler_h
#include "trimregion.h"
#include "trimvertex.h"
#include "gridvertex.h"
class Backend;
class GridTrimVertex;
class CoveAndTiler : virtual public TrimRegion {
public:
CoveAndTiler( Backend& );
~CoveAndTiler( void );
void coveAndTile( void );
private:
Backend& backend;
static const int MAXSTRIPSIZE;
void tile( long, long, long );
void coveLowerLeft( void );
void coveLowerRight( void );
void coveUpperLeft( void );
void coveUpperRight( void );
void coveUpperLeftNoGrid( TrimVertex * );
void coveUpperRightNoGrid( TrimVertex * );
void coveLowerLeftNoGrid( TrimVertex * );
void coveLowerRightNoGrid( TrimVertex * );
void coveLL( void );
void coveLR( void );
void coveUL( void );
void coveUR( void );
inline void output( GridTrimVertex& );
inline void output( GridVertex& );
inline void output( TrimVertex* );
};
#endif /* __glucoveandtiler_h */

View File

@@ -0,0 +1,198 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* curve.c++
*
*/
#include "glimports.h"
#include "myassert.h"
#include "mystdio.h"
#include "mymath.h"
#include "curve.h"
#include "mapdesc.h"
#include "types.h"
#include "quilt.h"
#include "nurbsconsts.h"
/*--------------------------------------------------------------------------
* Curve::Curve - copy curve from quilt and transform control points
*--------------------------------------------------------------------------
*/
Curve::Curve( Quilt_ptr geo, REAL pta, REAL ptb, Curve *c )
{
mapdesc = geo->mapdesc;
next = c;
needsSampling = mapdesc->isRangeSampling() ? 1 : 0;
cullval = mapdesc->isCulling() ? CULL_ACCEPT : CULL_TRIVIAL_ACCEPT;
order = geo->qspec[0].order;
stride = MAXCOORDS;
REAL *ps = geo->cpts;
Quiltspec_ptr qs = geo->qspec;
ps += qs->offset;
ps += qs->index * qs->order * qs->stride;
if( needsSampling )
mapdesc->xformSampling( ps, qs->order, qs->stride, spts, stride );
if( cullval == CULL_ACCEPT )
mapdesc->xformCulling( ps, qs->order, qs->stride, cpts, stride );
/* set untrimmed curve range */
range[0] = qs->breakpoints[qs->index];
range[1] = qs->breakpoints[qs->index+1];
range[2] = range[1] - range[0];
if( range[0] != pta ) {
Curve lower( *this, pta, 0 );
lower.next = next;
*this = lower;
}
if( range[1] != ptb ) {
Curve lower( *this, ptb, 0 );
}
}
/*--------------------------------------------------------------------------
* Curve::Curve - subdivide a curve along an isoparametric line
*--------------------------------------------------------------------------
*/
Curve::Curve( Curve& upper, REAL value, Curve *c )
{
Curve &lower = *this;
lower.next = c;
lower.mapdesc = upper.mapdesc;
lower.needsSampling = upper.needsSampling;
lower.order = upper.order;
lower.stride = upper.stride;
lower.cullval = upper.cullval;
REAL d = (value - upper.range[0]) / upper.range[2];
if( needsSampling )
mapdesc->subdivide( upper.spts, lower.spts, d, upper.stride, upper.order );
if( cullval == CULL_ACCEPT )
mapdesc->subdivide( upper.cpts, lower.cpts, d, upper.stride, upper.order );
lower.range[0] = upper.range[0];
lower.range[1] = value;
lower.range[2] = value - upper.range[0];
upper.range[0] = value;
upper.range[2] = upper.range[1] - value;
}
/*--------------------------------------------------------------------------
* Curve::clamp - clamp the sampling rate to a given maximum
*--------------------------------------------------------------------------
*/
void
Curve::clamp( void )
{
if( stepsize < minstepsize )
stepsize = mapdesc->clampfactor * minstepsize;
}
void
Curve::setstepsize( REAL max )
{
stepsize = ( max >= 1.0 ) ? (range[2] / max) : range[2];
minstepsize = stepsize;
}
void
Curve::getstepsize( void )
{
minstepsize= 0;
if( mapdesc->isConstantSampling() ) {
// fixed number of samples per patch in each direction
// maxrate is number of s samples per patch
setstepsize( mapdesc->maxrate );
} else if( mapdesc->isDomainSampling() ) {
// maxrate is number of s samples per unit s length of domain
setstepsize( mapdesc->maxrate * range[2] );
} else {
// upper bound on path length between sample points
assert( order <= MAXORDER );
/* points have been transformed, therefore they are homogeneous */
REAL tmp[MAXORDER][MAXCOORDS];
const int tstride = sizeof(tmp[0]) / sizeof(REAL);
int val = mapdesc->project( spts, stride, &tmp[0][0], tstride, order );
if( val == 0 ) {
// control points cross infinity, therefore derivatives are undefined
setstepsize( mapdesc->maxrate );
} else {
REAL t = mapdesc->getProperty( N_PIXEL_TOLERANCE );
if( mapdesc->isParametricDistanceSampling() ) {
REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 2, range[2] );
stepsize = (d > 0.0) ? sqrtf( 8.0 * t / d ) : range[2];
minstepsize = ( mapdesc->maxrate > 0.0f ) ? (range[2] / mapdesc->maxrate) : 0.0f;
} else if( mapdesc->isPathLengthSampling() ) {
// t is upper bound on path (arc) length
REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 1, range[2] );
stepsize = ( d > 0.0 ) ? (t / d) : range[2];
minstepsize = ( mapdesc->maxrate > 0.0f ) ? (range[2] / mapdesc->maxrate) : 0.0f;
} else {
// control points cross infinity, therefore partials are undefined
setstepsize( mapdesc->maxrate );
}
}
}
}
int
Curve::needsSamplingSubdivision( void )
{
return ( stepsize < minstepsize ) ? 1 : 0;
}
int
Curve::cullCheck( void )
{
if( cullval == CULL_ACCEPT )
cullval = mapdesc->cullCheck( cpts, order, stride );
return cullval;
}

View File

@@ -0,0 +1,70 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* curve.h
*
*/
#ifndef __glucurve_h_
#define __glucurve_h_
#include "types.h"
#include "defines.h"
class Mapdesc;
class Quilt;
class Curve {
public:
friend class Curvelist;
Curve( Quilt *, REAL, REAL, Curve * );
Curve( Curve&, REAL, Curve * );
Curve * next;
private:
Mapdesc * mapdesc;
int stride;
int order;
int cullval;
int needsSampling;
REAL cpts[MAXORDER*MAXCOORDS];
REAL spts[MAXORDER*MAXCOORDS];
REAL stepsize;
REAL minstepsize;
REAL range[3];
void clamp( void );
void setstepsize( REAL );
void getstepsize( void );
int cullCheck( void );
int needsSamplingSubdivision( void );
};
#endif /* __glucurve_h_ */

View File

@@ -0,0 +1,110 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* curvelist.c++
*
*/
#include "glimports.h"
#include "myassert.h"
#include "mystdio.h"
#include "quilt.h"
#include "curvelist.h"
#include "curve.h"
#include "nurbsconsts.h"
#include "types.h"
Curvelist::Curvelist( Quilt *quilts, REAL pta, REAL ptb )
{
curve = 0;
for( Quilt *q = quilts; q; q = q->next )
curve = new Curve( q, pta, ptb, curve );
range[0] = pta;
range[1] = ptb;
range[2] = ptb - pta;
}
Curvelist::Curvelist( Curvelist &upper, REAL value )
{
Curvelist &lower = *this;
curve = 0;
for( Curve *c = upper.curve; c; c = c->next )
curve = new Curve( *c, value, curve );
lower.range[0] = upper.range[0];
lower.range[1] = value;
lower.range[2] = value - upper.range[0];
upper.range[0] = value;
upper.range[2] = upper.range[1] - value;
}
Curvelist::~Curvelist()
{
while( curve ) {
Curve *c = curve;
curve = curve->next;
delete c;
}
}
int
Curvelist::cullCheck( void )
{
for( Curve *c = curve; c; c = c->next )
if( c->cullCheck() == CULL_TRIVIAL_REJECT )
return CULL_TRIVIAL_REJECT;
return CULL_ACCEPT;
}
void
Curvelist::getstepsize( void )
{
stepsize = range[2];
Curve *c;
for( c = curve; c; c = c->next ) {
c->getstepsize();
c->clamp();
stepsize = ((c->stepsize < stepsize) ? c->stepsize : stepsize);
if( c->needsSamplingSubdivision() ) break;
}
needsSubdivision = ( c ) ? 1 : 0;
}
int
Curvelist::needsSamplingSubdivision( void )
{
return needsSubdivision;
}

View File

@@ -0,0 +1,62 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* curvelist.h
*
*/
#ifndef __glucurvelist_h_
#define __glucurvelist_h_
#include "types.h"
#include "defines.h"
class Mapdesc;
class Quilt;
class Curve;
class Curvelist
{
friend class Subdivider;
public:
Curvelist( Quilt *, REAL, REAL );
Curvelist( Curvelist &, REAL );
~Curvelist( void );
int cullCheck( void );
void getstepsize( void );
int needsSamplingSubdivision();
private:
Curve *curve;
float range[3];
int needsSubdivision;
float stepsize;
};
#endif /* __glucurvelist_h_ */

View File

@@ -0,0 +1,103 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* curvesub.c++
*
*/
#include "glimports.h"
#include "myassert.h"
#include "mystdio.h"
#include "subdivider.h"
#include "renderhints.h"
#include "backend.h"
#include "quilt.h"
#include "curvelist.h"
#include "curve.h"
#include "nurbsconsts.h"
/*--------------------------------------------------------------------------
* drawCurves - main curve rendering entry point
*--------------------------------------------------------------------------
*/
void Subdivider::drawCurves(void)
{
REAL from[1], to[1];
Flist bpts;
qlist->getRange(from, to, bpts);
renderhints.init();
backend.bgncurv();
for(int i=bpts.start; i<bpts.end-1; i++)
{
REAL pta, ptb;
pta=bpts.pts[i];
ptb=bpts.pts[i+1];
qlist->downloadAll(&pta, &ptb, backend);
Curvelist curvelist(qlist, pta, ptb);
samplingSplit(curvelist, renderhints.maxsubdivisions);
}
backend.endcurv();
}
/*--------------------------------------------------------------------------
* samplingSplit - recursively subdivide patch, cull check each subpatch
*--------------------------------------------------------------------------
*/
void
Subdivider::samplingSplit( Curvelist& curvelist, int subdivisions )
{
if( curvelist.cullCheck() == CULL_TRIVIAL_REJECT ) return;
curvelist.getstepsize();
if( curvelist.needsSamplingSubdivision() && (subdivisions > 0) ) {
REAL mid = ( curvelist.range[0] + curvelist.range[1] ) * 0.5f;
Curvelist lowerlist( curvelist, mid );
samplingSplit( lowerlist, subdivisions-1 ); // lower
samplingSplit( curvelist, subdivisions-1 ); // upper
} else {
long nu = 1 + ((long) (curvelist.range[2] / curvelist.stepsize));
backend.curvgrid( curvelist.range[0], curvelist.range[1], nu );
backend.curvmesh( 0, nu );
}
}

View File

@@ -0,0 +1,113 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/
/*
*/
#include <stdlib.h>
#include <stdio.h>
#include "glimports.h"
#include "myassert.h"
#include "nurbsconsts.h"
#include "trimvertex.h"
#include "dataTransform.h"
extern directedLine* arcLoopToDLineLoop(Arc_ptr loop);
directedLine* bin_to_DLineLoops(Bin& bin)
{
directedLine *ret=NULL;
directedLine *temp;
bin.markall();
for(Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc()){
if(jarc->ismarked()) {
assert(jarc->check() != 0);
Arc_ptr jarchead = jarc;
do {
jarc->clearmark();
jarc = jarc->next;
} while(jarc != jarchead);
temp = arcLoopToDLineLoop(jarc);
ret = temp->insertPolygon(ret);
}
}
return ret;
}
directedLine* o_pwlcurve_to_DLines(directedLine* original, O_pwlcurve* pwl)
{
directedLine* ret = original;
for(Int i=0; i<pwl->npts-1; i++)
{
sampledLine* sline = new sampledLine(2);
sline->setPoint(0, pwl->pts[i].param);
sline->setPoint(1, pwl->pts[i+1].param);
directedLine* dline = new directedLine(INCREASING, sline);
if(ret == NULL)
ret = dline;
else
ret->insert(dline);
}
return ret;
}
directedLine* o_curve_to_DLineLoop(O_curve* cur)
{
directedLine *ret;
if(cur == NULL)
return NULL;
assert(cur->curvetype == ct_pwlcurve);
ret = o_pwlcurve_to_DLines(NULL, cur->curve.o_pwlcurve);
for(O_curve* temp = cur->next; temp != NULL; temp = temp->next)
{
assert(temp->curvetype == ct_pwlcurve);
ret = o_pwlcurve_to_DLines(ret, temp->curve.o_pwlcurve);
}
return ret;
}
directedLine* o_trim_to_DLineLoops(O_trim* trim)
{
O_trim* temp;
directedLine *ret;
if(trim == NULL)
return NULL;
ret = o_curve_to_DLineLoop(trim->o_curve);
for(temp=trim->next; temp != NULL; temp = temp->next)
{
ret = ret->insertPolygon(o_curve_to_DLineLoop(temp->o_curve));
}
return ret;
}

View File

@@ -0,0 +1,59 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*/
#ifndef _DATA_TRANSFORM_H
#define _DATA_TRANSFORM_H
#include "reader.h"
#include "directedLine.h"
#include "bin.h"
directedLine* bin_to_DLineLoops(Bin& bin);
/*transform the pwlcurve into a number of directedline lines
*insert these directedlines into orignal which is supposed to be
*the part of the trimming loop obtained so far.
*return the updated trimkming loop.
*/
directedLine* o_pwlcurve_to_DLines(directedLine* original, O_pwlcurve* pwl);
/*transform a trim loop (curve) into a directedLine loop
*/
directedLine* o_curve_to_DLineLoop(O_curve* curve);
/*transform a list of trim loops (trim) into
*a list of polygons represented as directedLine*.
*/
directedLine* o_trim_to_DLineLoops(O_trim* trim);
#endif

View File

@@ -0,0 +1,50 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* defines.h
*
*/
#ifndef __gludefines_h_
#define __gludefines_h_
/* culling constants */
#define CULL_TRIVIAL_REJECT 0
#define CULL_TRIVIAL_ACCEPT 1
#define CULL_ACCEPT 2
/* maximum order of a B-Spline */
#define MAXORDER 24
/* maximum dimension of any B-spline range space */
#define MAXCOORDS 5
#endif /* __gludefines_h_ */

View File

@@ -0,0 +1,82 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* displaylist.c++
*
*/
#include "glimports.h"
#include "mystdio.h"
#include "nurbstess.h"
#include "displaylist.h"
DisplayList::DisplayList( NurbsTessellator *_nt ) :
dlnodePool( sizeof( Dlnode ), 1, "dlnodepool" )
{
lastNode = &nodes;
nt = _nt;
}
DisplayList::~DisplayList( void )
{
for( Dlnode *nextNode; nodes; nodes = nextNode ) {
nextNode = nodes->next;
if( nodes->cleanup != 0 ) (nt->*nodes->cleanup)( nodes->arg );
//nodes->deleteMe(dlnodePool);
}
}
void
DisplayList::play( void )
{
for( Dlnode *node = nodes; node; node = node->next )
if( node->work != 0 ) (nt->*node->work)( node->arg );
}
void
DisplayList::endList( void )
{
*lastNode = 0;
}
void
DisplayList::append( PFVS work, void *arg, PFVS cleanup )
{
Dlnode *node = new(dlnodePool) Dlnode( work, arg, cleanup );
*lastNode = node;
lastNode = &(node->next);
}

View File

@@ -0,0 +1,78 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* displaylist.h
*
*/
#ifndef __gludisplaylist_h_
#define __gludisplaylist_h_
#include "glimports.h"
#include "mysetjmp.h"
#include "mystdio.h"
#include "bufpool.h"
class NurbsTessellator;
typedef void (NurbsTessellator::*PFVS)( void * );
struct Dlnode : public PooledObj {
Dlnode( PFVS, void *, PFVS );
PFVS work;
void * arg;
PFVS cleanup;
Dlnode * next;
};
inline
Dlnode::Dlnode( PFVS _work, void *_arg, PFVS _cleanup )
{
work = _work;
arg = _arg;
cleanup = _cleanup;
}
class DisplayList {
public:
DisplayList( NurbsTessellator * );
~DisplayList( void );
void play( void );
void append( PFVS work, void *arg, PFVS cleanup );
void endList( void );
private:
Dlnode *nodes;
Pool dlnodePool;
Dlnode **lastNode;
NurbsTessellator *nt;
};
#endif /* __gludisplaylist_h_ */

View File

@@ -0,0 +1,38 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
#ifndef __gludisplaymode_h_
#define __gludisplaymode_h_
#define N_MESHFILL 0
#define N_MESHLINE 1
#define N_MESHPOINT 2
#endif /* __gludisplaymode_h_ */

View File

@@ -0,0 +1,129 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* flist.c++
*
*/
#include "glimports.h"
#include "myassert.h"
#include "mystdio.h"
#include "flist.h"
/*----------------------------------------------------------------------------
* Flist::Flist - initialize a REAL number array
*----------------------------------------------------------------------------
*/
Flist::Flist(void)
{
npts=0;
pts=0;
start=end=0;
}
/*----------------------------------------------------------------------------
* Flist::~Flist - free a REAL number array
*----------------------------------------------------------------------------
*/
Flist::~Flist(void)
{
if (npts)
{
delete[]pts;
}
}
void Flist::add(REAL x)
{
pts[end++]=x;
assert(end<=npts);
}
/*----------------------------------------------------------------------------
* Flist::filter - remove duplicate numbers from array
*----------------------------------------------------------------------------
*/
void Flist::filter(void)
{
sorter.qsort(pts, end);
start=0;
int j=0;
for (int i=1; i<end; i++)
{
if (pts[i]==pts[i-j-1])
{
j++;
}
pts[i-j]=pts[i];
}
end-=j;
}
/*----------------------------------------------------------------------------
* Flist::grow - ensure that array is large enough
*----------------------------------------------------------------------------
*/
void Flist::grow(int maxpts)
{
if (npts<maxpts)
{
if (npts)
{
delete[] pts;
}
npts=2*maxpts;
pts=new REAL[npts];
assert(pts!=0);
}
start=end=0;
}
/*----------------------------------------------------------------------------
* Flist::taper - ignore head and tail of array
*----------------------------------------------------------------------------
*/
void Flist::taper(REAL from, REAL to)
{
while (pts[start]!=from)
{
start++;
}
while (pts[end-1]!=to)
{
end--;
}
}

View File

@@ -0,0 +1,60 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* flist.h
*
*/
#ifndef __gluflist_h_
#define __gluflist_h_
#include "types.h"
#include "flistsorter.h"
class Flist
{
public:
REAL* pts; /* head of array */
int npts; /* number of points in array */
int start; /* first important point index */
int end; /* last important point index */
Flist(void);
~Flist(void);
void add(REAL x);
void filter(void);
void grow(int);
void taper(REAL, REAL);
protected:
FlistSorter sorter;
};
#endif /* __gluflist_h_ */

View File

@@ -0,0 +1,77 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* flistsorter.c++
*
*/
#include "glimports.h"
#include "flistsorter.h"
FlistSorter::FlistSorter(void): Sorter(sizeof(REAL))
{
}
void FlistSorter::qsort(REAL* p, int n)
{
Sorter::qsort((char*)p, n);
}
int FlistSorter::qscmp(char* i, char* j)
{
REAL f0=*(REAL*)i;
REAL f1=*(REAL*)j;
return (f0<f1) ? -1 : 1;
}
void FlistSorter::qsexc(char* i, char* j)
{
REAL* f0=(REAL*)i;
REAL* f1=(REAL*)j;
REAL tmp=*f0;
*f0=*f1;
*f1=tmp;
}
void FlistSorter::qstexc(char* i, char* j, char* k)
{
REAL* f0=(REAL*)i;
REAL* f1=(REAL*)j;
REAL* f2=(REAL*)k;
REAL tmp=*f0;
*f0=*f2;
*f2=*f1;
*f1=tmp;
}

View File

@@ -0,0 +1,54 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* flistsorter.h
*
*/
#ifndef __gluflistsorter_h_
#define __gluflistsorter_h_
#include "sorter.h"
#include "types.h"
class FlistSorter: public Sorter
{
public:
FlistSorter(void);
virtual ~FlistSorter() { /* silence warning*/ }
void qsort(REAL* a, int n);
protected:
virtual int qscmp(char*, char*);
virtual void qsexc(char* i, char* j); // i<-j, j<-i
virtual void qstexc(char* i, char* j, char* k); // i<-k, k<-j, j<-i
};
#endif /* __gluflistsorter_h_ */

View File

@@ -0,0 +1,46 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* gridline.h
*
*/
#ifndef __glugridline_h_
#define __glugridline_h_
struct Gridline {
long v;
REAL vval;
long vindex;
long ustart;
long uend;
};
#endif /* __glugridline_h_ */

View File

@@ -0,0 +1,88 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* gridtrimvertex.h
*
*/
#ifndef __glugridtrimvertex_h_
#define __glugridtrimvertex_h_
#include "mystdlib.h"
#include "bufpool.h"
#include "trimvertex.h"
#include "gridvertex.h"
class GridTrimVertex: public PooledObj
{
private:
TrimVertex dummyt;
GridVertex dummyg;
public:
GridTrimVertex() { g=0; t=0; }
TrimVertex* t;
GridVertex* g;
inline void set(long, long);
inline void set(REAL, REAL);
inline void set(TrimVertex*);
inline void clear(void) { t=0; g=0; };
inline int isGridVert() { return g ? 1 : 0; }
inline int isTrimVert() { return t ? 1 : 0; }
inline void output();
};
inline void GridTrimVertex::set(long x, long y)
{
g=&dummyg;
dummyg.gparam[0]=x;
dummyg.gparam[1]=y;
}
inline void GridTrimVertex::set(REAL x, REAL y)
{
g=0;
t=&dummyt;
dummyt.param[0]=x;
dummyt.param[1]=y;
dummyt.nuid=0;
}
inline void GridTrimVertex::set(TrimVertex* v)
{
g=0;
t=v;
}
typedef GridTrimVertex* GridTrimVertex_p;
#endif /* __glugridtrimvertex_h_ */

View File

@@ -0,0 +1,49 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* gridvertex.h
*
*/
#ifndef __glugridvertex_h_
#define __glugridvertex_h_
struct GridVertex
{
long gparam[2];
GridVertex(void) {}
GridVertex(long u, long v) { gparam[0]=u, gparam[1]=v; }
void set(long u, long v) { gparam[0]=u, gparam[1]=v; }
long nextu() { return gparam[0]++; }
long prevu() { return gparam[0]--; }
};
#endif /* __glugridvertex_h_ */

View File

@@ -0,0 +1,165 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* hull.c++
*
*/
#include "glimports.h"
#include "myassert.h"
#include "mystdio.h"
#include "hull.h"
#include "gridvertex.h"
#include "gridtrimvertex.h"
#include "gridline.h"
#include "trimline.h"
#include "uarray.h"
#include "trimregion.h"
Hull::Hull( void )
{}
Hull::~Hull( void )
{}
/*----------------------------------------------------------------------
* Hull:init - this routine does the initialization needed before any
* calls to nextupper or nextlower can be made.
*----------------------------------------------------------------------
*/
void
Hull::init( void )
{
TrimVertex *lfirst = left.first();
TrimVertex *llast = left.last();
if( lfirst->param[0] <= llast->param[0] ) {
fakeleft.init( left.first() );
upper.left = &fakeleft;
lower.left = &left;
} else {
fakeleft.init( left.last() );
lower.left = &fakeleft;
upper.left = &left;
}
upper.left->last();
lower.left->first();
if( top.ustart <= top.uend ) {
upper.line = &top;
upper.index = top.ustart;
} else
upper.line = 0;
if( bot.ustart <= bot.uend ) {
lower.line = &bot;
lower.index = bot.ustart;
} else
lower.line = 0;
TrimVertex *rfirst = right.first();
TrimVertex *rlast = right.last();
if( rfirst->param[0] <= rlast->param[0] ) {
fakeright.init( right.last() );
lower.right = &fakeright;
upper.right = &right;
} else {
fakeright.init( right.first() );
upper.right = &fakeright;
lower.right = &right;
}
upper.right->first();
lower.right->last();
}
/*----------------------------------------------------------------------
* nextupper - find next vertex on upper hull of trim region.
* - if vertex is on trim curve, set vtop point to
* that vertex. if vertex is on grid, set vtop to
* point to temporary area and stuff coordinants into
* temporary vertex. Also, place grid coords in temporary
* grid vertex.
*----------------------------------------------------------------------
*/
GridTrimVertex *
Hull::nextupper( GridTrimVertex *gv )
{
if( upper.left ) {
gv->set( upper.left->prev() );
if( gv->isTrimVert() ) return gv;
upper.left = 0;
}
if( upper.line ) {
assert( upper.index <= upper.line->uend );
gv->set( uarray.uarray[upper.index], upper.line->vval );
gv->set( upper.index, upper.line->vindex );
if( upper.index++ == upper.line->uend ) upper.line = 0;
return gv;
}
if( upper.right ) {
gv->set( upper.right->next() );
if( gv->isTrimVert() ) return gv;
upper.right = 0;
}
return 0;
}
GridTrimVertex *
Hull::nextlower( register GridTrimVertex *gv )
{
if( lower.left ) {
gv->set( lower.left->next() );
if( gv->isTrimVert() ) return gv;
lower.left = 0;
}
if( lower.line ) {
gv->set( uarray.uarray[lower.index], lower.line->vval );
gv->set( lower.index, lower.line->vindex );
if( lower.index++ == lower.line->uend ) lower.line = 0;
return gv;
}
if( lower.right ) {
gv->set( lower.right->prev() );
if( gv->isTrimVert() ) return gv;
lower.right = 0;
}
return 0;
}

View File

@@ -0,0 +1,69 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* hull.h
*
*/
#ifndef __gluhull_h_
#define __gluhull_h_
#include "trimline.h"
#include "trimregion.h"
#include "trimvertex.h"
#include "gridtrimvertex.h"
struct Gridline;
class Uarray;
class Hull : virtual public TrimRegion {
public:
Hull( void );
~Hull( void );
void init( void );
GridTrimVertex * nextlower( GridTrimVertex * );
GridTrimVertex * nextupper( GridTrimVertex * );
private:
struct Side {
Trimline *left;
Gridline *line;
Trimline *right;
long index;
};
Side lower;
Side upper;
Trimline fakeleft;
Trimline fakeright;
};
#endif /* __gluhull_h_ */

View File

@@ -0,0 +1,619 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* intersect.c++
*
*/
#include "glimports.h"
#include "myassert.h"
#include "mystdio.h"
#include "subdivider.h"
#include "arc.h"
#include "bin.h"
#include "backend.h"
#include "trimvertpool.h"
/*#define NOTDEF*/
enum i_result { INTERSECT_VERTEX, INTERSECT_EDGE };
/* local functions */
static enum i_result pwlarc_intersect( PwlArc *, int, REAL, int, int[3] );
void
Subdivider::partition( Bin & bin, Bin & left, Bin & intersections,
Bin & right, Bin & unknown, int param, REAL value )
{
Bin headonleft, headonright, tailonleft, tailonright;
for( Arc_ptr jarc = bin.removearc(); jarc; jarc = bin.removearc() ) {
REAL tdiff = jarc->tail()[param] - value;
REAL hdiff = jarc->head()[param] - value;
if( tdiff > 0.0 ) {
if( hdiff > 0.0 ) {
right.addarc( jarc );
} else if( hdiff == 0.0 ) {
tailonright.addarc( jarc );
} else {
Arc_ptr jtemp;
switch( arc_split(jarc, param, value, 0) ) {
case 2:
tailonright.addarc( jarc );
headonleft.addarc( jarc->next );
break;
case 31:
assert( jarc->head()[param] > value );
right.addarc( jarc );
tailonright.addarc( jtemp = jarc->next );
headonleft.addarc( jtemp->next );
break;
case 32:
assert( jarc->head()[param] <= value );
tailonright .addarc( jarc );
headonleft.addarc( jtemp = jarc->next );
left.addarc( jtemp->next );
break;
case 4:
right.addarc( jarc );
tailonright.addarc( jtemp = jarc->next );
headonleft.addarc( jtemp = jtemp->next );
left.addarc( jtemp->next );
}
}
} else if( tdiff == 0.0 ) {
if( hdiff > 0.0 ) {
headonright.addarc( jarc );
} else if( hdiff == 0.0 ) {
unknown.addarc( jarc );
} else {
headonleft.addarc( jarc );
}
} else {
if( hdiff > 0.0 ) {
Arc_ptr jtemp;
switch( arc_split(jarc, param, value, 1) ) {
case 2:
tailonleft.addarc( jarc );
headonright.addarc( jarc->next );
break;
case 31:
assert( jarc->head()[param] < value );
left.addarc( jarc );
tailonleft.addarc( jtemp = jarc->next );
headonright.addarc( jtemp->next );
break;
case 32:
assert( jarc->head()[param] >= value );
tailonleft.addarc( jarc );
headonright.addarc( jtemp = jarc->next );
right.addarc( jtemp->next );
break;
case 4:
left.addarc( jarc );
tailonleft.addarc( jtemp = jarc->next );
headonright.addarc( jtemp = jtemp->next );
right.addarc( jtemp->next );
}
} else if( hdiff == 0.0 ) {
tailonleft.addarc( jarc );
} else {
left.addarc( jarc );
}
}
}
if( param == 0 ) {
classify_headonleft_s( headonleft, intersections, left, value );
classify_tailonleft_s( tailonleft, intersections, left, value );
classify_headonright_s( headonright, intersections, right, value );
classify_tailonright_s( tailonright, intersections, right, value );
} else {
classify_headonleft_t( headonleft, intersections, left, value );
classify_tailonleft_t( tailonleft, intersections, left, value );
classify_headonright_t( headonright, intersections, right, value );
classify_tailonright_t( tailonright, intersections, right, value );
}
}
inline static void
vert_interp( TrimVertex *n, TrimVertex *l, TrimVertex *r, int p, REAL val )
{
assert( val > l->param[p]);
assert( val < r->param[p]);
n->nuid = l->nuid;
n->param[p] = val;
if( l->param[1-p] != r->param[1-p] ) {
REAL ratio = (val - l->param[p]) / (r->param[p] - l->param[p]);
n->param[1-p] = l->param[1-p] +
ratio * (r->param[1-p] - l->param[1-p]);
} else {
n->param[1-p] = l->param[1-p];
}
}
int Subdivider::arc_split(Arc_ptr jarc, int param, REAL value, int dir)
{
int maxvertex = jarc->pwlArc->npts;
Arc_ptr jarc1;
TrimVertex* v = jarc->pwlArc->pts;
int loc[3];
switch( pwlarc_intersect( jarc->pwlArc, param, value, dir, loc ) ) {
// When the parameter value lands on a vertex, life is sweet
case INTERSECT_VERTEX: {
jarc1 = new(arcpool) Arc( jarc, new( pwlarcpool) PwlArc( maxvertex-loc[1], &v[loc[1]] ) );
jarc->pwlArc->npts = loc[1] + 1;
jarc1->next = jarc->next;
jarc1->next->prev = jarc1;
jarc->next = jarc1;
jarc1->prev = jarc;
assert(jarc->check() != 0);
return 2;
}
// When the parameter value intersects an edge, we have to
// interpolate a new vertex. There are special cases
// if the new vertex is adjacent to one or both of the
// endpoints of the arc.
case INTERSECT_EDGE: {
int i, j;
if( dir == 0 ) {
i = loc[0];
j = loc[2];
} else {
i = loc[2];
j = loc[0];
}
#ifndef NOTDEF
// The split is between vertices at index j and i, in that
// order (j < i)
// JEB: This code is my idea of how to do the split without
// increasing the number of links. I'm doing this so that
// the is_rect routine can recognize rectangles created by
// subdivision. In exchange for simplifying the curve list,
// however, it costs in allocated space and vertex copies.
TrimVertex *newjunk = trimvertexpool.get(maxvertex -i+1 /*-j*/);
int k;
for(k=0; k<maxvertex-i; k++)
{
newjunk[k+1] = v[i+k];
newjunk[k+1].nuid = jarc->nuid;
}
TrimVertex *vcopy = trimvertexpool.get(maxvertex);
for(k=0; k<maxvertex; k++)
{
vcopy[k].param[0] = v[k].param[0];
vcopy[k].param[1] = v[k].param[1];
}
jarc->pwlArc->pts=vcopy;
v[i].nuid = jarc->nuid;
v[j].nuid = jarc->nuid;
vert_interp( &newjunk[0], &v[loc[0]], &v[loc[2]], param, value );
if( showingDegenerate() )
backend.triangle( &v[i], &newjunk[0], &v[j] );
vcopy[j+1].param[0]=newjunk[0].param[0];
vcopy[j+1].param[1]=newjunk[0].param[1];
jarc1 = new(arcpool) Arc( jarc,
new(pwlarcpool) PwlArc(maxvertex-i+1 , newjunk ) );
jarc->pwlArc->npts = j+2;
jarc1->next = jarc->next;
jarc1->next->prev = jarc1;
jarc->next = jarc1;
jarc1->prev = jarc;
assert(jarc->check() != 0);
return 2;
#endif //not NOTDEF
// JEB: This is the original version:
#ifdef NOTDEF
Arc_ptr jarc2, jarc3;
TrimVertex *newjunk = trimvertexpool.get(3);
v[i].nuid = jarc->nuid;
v[j].nuid = jarc->nuid;
newjunk[0] = v[j];
newjunk[2] = v[i];
vert_interp( &newjunk[1], &v[loc[0]], &v[loc[2]], param, value );
if( showingDegenerate() )
backend.triangle( &newjunk[2], &newjunk[1], &newjunk[0] );
// New vertex adjacent to both endpoints
if (maxvertex == 2) {
jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) );
jarc->pwlArc->npts = 2;
jarc->pwlArc->pts = newjunk;
jarc1->next = jarc->next;
jarc1->next->prev = jarc1;
jarc->next = jarc1;
jarc1->prev = jarc;
assert(jarc->check() != 0);
return 2;
// New vertex adjacent to ending point of arc
} else if (maxvertex - j == 2) {
jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk ) );
jarc2 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) );
jarc->pwlArc->npts = maxvertex-1;
jarc2->next = jarc->next;
jarc2->next->prev = jarc2;
jarc->next = jarc1;
jarc1->prev = jarc;
jarc1->next = jarc2;
jarc2->prev = jarc1;
assert(jarc->check() != 0);
return 31;
// New vertex adjacent to starting point of arc
} else if (i == 1) {
jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) );
jarc2 = new(arcpool) Arc( jarc,
new(pwlarcpool) PwlArc( maxvertex-1, &jarc->pwlArc->pts[1] ) );
jarc->pwlArc->npts = 2;
jarc->pwlArc->pts = newjunk;
jarc2->next = jarc->next;
jarc2->next->prev = jarc2;
jarc->next = jarc1;
jarc1->prev = jarc;
jarc1->next = jarc2;
jarc2->prev = jarc1;
assert(jarc->check() != 0);
return 32;
// It's somewhere in the middle
} else {
jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk ) );
jarc2 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) );
jarc3 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( maxvertex-i, v+i ) );
jarc->pwlArc->npts = j + 1;
jarc3->next = jarc->next;
jarc3->next->prev = jarc3;
jarc->next = jarc1;
jarc1->prev = jarc;
jarc1->next = jarc2;
jarc2->prev = jarc1;
jarc2->next = jarc3;
jarc3->prev = jarc2;
assert(jarc->check() != 0);
return 4;
}
#endif // NOTDEF
}
default:
return -1; //picked -1 since it's not used
}
}
/*----------------------------------------------------------------------------
* pwlarc_intersect - find intersection of pwlArc and isoparametric line
*----------------------------------------------------------------------------
*/
static enum i_result
pwlarc_intersect(
PwlArc *pwlArc,
int param,
REAL value,
int dir,
int loc[3] )
{
assert( pwlArc->npts > 0 );
if( dir ) {
TrimVertex *v = pwlArc->pts;
int imin = 0;
int imax = pwlArc->npts - 1;
assert( value > v[imin].param[param] );
assert( value < v[imax].param[param] );
while( (imax - imin) > 1 ) {
int imid = (imax + imin)/2;
if( v[imid].param[param] > value )
imax = imid;
else if( v[imid].param[param] < value )
imin = imid;
else {
loc[1] = imid;
return INTERSECT_VERTEX;
}
}
loc[0] = imin;
loc[2] = imax;
return INTERSECT_EDGE;
} else {
TrimVertex *v = pwlArc->pts;
int imax = 0;
int imin = pwlArc->npts - 1;
assert( value > v[imin].param[param] );
assert( value < v[imax].param[param] );
while( (imin - imax) > 1 ) {
int imid = (imax + imin)/2;
if( v[imid].param[param] > value )
imax = imid;
else if( v[imid].param[param] < value )
imin = imid;
else {
loc[1] = imid;
return INTERSECT_VERTEX;
}
}
loc[0] = imin;
loc[2] = imax;
return INTERSECT_EDGE;
}
}
/*----------------------------------------------------------------------------
* arc_classify - determine which side of a line a jarc lies
*----------------------------------------------------------------------------
*/
void
Subdivider::classify_tailonleft_s( Bin& bin, Bin& in, Bin& out, REAL val )
{
/* tail at left, head on line */
Arc_ptr j;
while( (j = bin.removearc()) != NULL ) {
assert( arc_classify( j, 0, val ) == 0x02 );
j->clearitail();
REAL diff = j->next->head()[0] - val;
if( diff > 0.0 ) {
in.addarc( j );
} else if( diff < 0.0 ) {
if( ccwTurn_sl( j, j->next ) )
out.addarc( j );
else
in.addarc( j );
} else {
if( j->next->tail()[1] > j->next->head()[1] )
in.addarc(j);
else
out.addarc(j);
}
}
}
void
Subdivider::classify_tailonleft_t( Bin& bin, Bin& in, Bin& out, REAL val )
{
/* tail at left, head on line */
Arc_ptr j;
while( (j = bin.removearc()) != NULL ) {
assert( arc_classify( j, 1, val ) == 0x02 );
j->clearitail();
REAL diff = j->next->head()[1] - val;
if( diff > 0.0 ) {
in.addarc( j );
} else if( diff < 0.0 ) {
if( ccwTurn_tl( j, j->next ) )
out.addarc( j );
else
in.addarc( j );
} else {
if (j->next->tail()[0] > j->next->head()[0] )
out.addarc( j );
else
in.addarc( j );
}
}
}
void
Subdivider::classify_headonleft_s( Bin& bin, Bin& in, Bin& out, REAL val )
{
/* tail on line, head at left */
Arc_ptr j;
while( (j = bin.removearc()) != NULL ) {
assert( arc_classify( j, 0, val ) == 0x20 );
j->setitail();
REAL diff = j->prev->tail()[0] - val;
if( diff > 0.0 ) {
out.addarc( j );
} else if( diff < 0.0 ) {
if( ccwTurn_sl( j->prev, j ) )
out.addarc( j );
else
in.addarc( j );
} else {
if( j->prev->tail()[1] > j->prev->head()[1] )
in.addarc( j );
else
out.addarc( j );
}
}
}
void
Subdivider::classify_headonleft_t( Bin& bin, Bin& in, Bin& out, REAL val )
{
/* tail on line, head at left */
Arc_ptr j;
while( (j = bin.removearc()) != NULL ) {
assert( arc_classify( j, 1, val ) == 0x20 );
j->setitail();
REAL diff = j->prev->tail()[1] - val;
if( diff > 0.0 ) {
out.addarc( j );
} else if( diff < 0.0 ) {
if( ccwTurn_tl( j->prev, j ) )
out.addarc( j );
else
in.addarc( j );
} else {
if( j->prev->tail()[0] > j->prev->head()[0] )
out.addarc( j );
else
in.addarc( j );
}
}
}
void
Subdivider::classify_tailonright_s( Bin& bin, Bin& in, Bin& out, REAL val )
{
/* tail at right, head on line */
Arc_ptr j;
while( (j = bin.removearc()) != NULL ) {
assert( arc_classify( j, 0, val ) == 0x12);
j->clearitail();
REAL diff = j->next->head()[0] - val;
if( diff > 0.0 ) {
if( ccwTurn_sr( j, j->next ) )
out.addarc( j );
else
in.addarc( j );
} else if( diff < 0.0 ) {
in.addarc( j );
} else {
if( j->next->tail()[1] > j->next->head()[1] )
out.addarc( j );
else
in.addarc( j );
}
}
}
void
Subdivider::classify_tailonright_t( Bin& bin, Bin& in, Bin& out, REAL val )
{
/* tail at right, head on line */
Arc_ptr j;
while( (j = bin.removearc()) != NULL ) {
assert( arc_classify( j, 1, val ) == 0x12);
j->clearitail();
REAL diff = j->next->head()[1] - val;
if( diff > 0.0 ) {
if( ccwTurn_tr( j, j->next ) )
out.addarc( j );
else
in.addarc( j );
} else if( diff < 0.0 ) {
in.addarc( j );
} else {
if( j->next->tail()[0] > j->next->head()[0] )
in.addarc( j );
else
out.addarc( j );
}
}
}
void
Subdivider::classify_headonright_s( Bin& bin, Bin& in, Bin& out, REAL val )
{
/* tail on line, head at right */
Arc_ptr j;
while( (j = bin.removearc()) != NULL ) {
assert( arc_classify( j, 0, val ) == 0x21 );
j->setitail();
REAL diff = j->prev->tail()[0] - val;
if( diff > 0.0 ) {
if( ccwTurn_sr( j->prev, j ) )
out.addarc( j );
else
in.addarc( j );
} else if( diff < 0.0 ) {
out.addarc( j );
} else {
if( j->prev->tail()[1] > j->prev->head()[1] )
out.addarc( j );
else
in.addarc( j );
}
}
}
void
Subdivider::classify_headonright_t( Bin& bin, Bin& in, Bin& out, REAL val )
{
/* tail on line, head at right */
Arc_ptr j;
while( (j = bin.removearc()) != NULL ) {
assert( arc_classify( j, 1, val ) == 0x21 );
j->setitail();
REAL diff = j->prev->tail()[1] - val;
if( diff > 0.0 ) {
if( ccwTurn_tr( j->prev, j ) )
out.addarc( j );
else
in.addarc( j );
} else if( diff < 0.0 ) {
out.addarc( j );
} else {
if( j->prev->tail()[0] > j->prev->head()[0] )
in.addarc( j );
else
out.addarc( j );
}
}
}

View File

@@ -0,0 +1,87 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* jarcloc.h
*
*/
#ifndef __glujarcloc_h_
#define __glujarcloc_h_
#include "arc.h"
class Jarcloc {
private:
Arc_ptr arc;
TrimVertex *p;
TrimVertex *plast;
public:
inline void init( Arc_ptr a, long first, long last ) { arc = a; p=&a->pwlArc->pts[first]; plast = &a->pwlArc->pts[last]; }
inline TrimVertex * getnextpt( void );
inline TrimVertex * getprevpt( void );
inline void reverse();
};
inline void
Jarcloc::reverse()
{
if( plast == &arc->pwlArc->pts[0] )
plast = &arc->pwlArc->pts[arc->pwlArc->npts - 1];
else
plast = &arc->pwlArc->pts[0];
}
inline TrimVertex *
Jarcloc::getnextpt()
{
assert( p <= plast );
if( p == plast ) {
arc = arc->next;
p = &arc->pwlArc->pts[0];
plast = &arc->pwlArc->pts[arc->pwlArc->npts - 1];
assert( p < plast );
}
return p++;
}
inline TrimVertex *
Jarcloc::getprevpt()
{
assert( p >= plast );
if( p == plast ) {
arc = arc->prev;
p = &arc->pwlArc->pts[arc->pwlArc->npts - 1];
plast = &arc->pwlArc->pts[0];
assert( p > plast );
}
return p--;
}
#endif /* __glujarcloc_h_ */

View File

@@ -0,0 +1,132 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* knotvector.c++
*
*/
#include "glimports.h"
#include "mystdio.h"
#include "myassert.h"
#include "knotvector.h"
#include "defines.h"
#ifdef __WATCOMC__
#pragma warning 726 10
#endif
void Knotvector::init( long _knotcount, long _stride, long _order, INREAL *_knotlist )
{
knotcount = _knotcount;
stride = _stride;
order = _order;
knotlist = new Knot[_knotcount];
assert( knotlist != 0 );
for( int i = 0; i != _knotcount; i++ )
knotlist[i] = (Knot) _knotlist[i];
}
Knotvector::Knotvector( void )
{
knotlist = 0;
}
Knotvector::~Knotvector( void )
{
if( knotlist ) delete[] knotlist;
}
int Knotvector::validate( void )
{
/* kindex is used as an array index so subtract one first,
* this propagates throughout the code so study carefully */
long kindex = knotcount-1;
if( order < 1 || order > MAXORDER ) {
// spline order un-supported
return( 1 );
}
if( knotcount < (2 * order) ) {
// too few knots
return( 2 );
}
if( identical( knotlist[kindex-(order-1)], knotlist[order-1]) ) {
// valid knot range is empty
return( 3 );
}
for( long i = 0; i < kindex; i++)
if( knotlist[i] > knotlist[i+1] ) {
// decreasing knot sequence
return( 4 );
}
/* check for valid multiplicity */
/* kindex is currently the index of the last knot.
* In the next loop it is decremented to ignore the last knot
* and the loop stops when kindex is 2 so as to ignore the first
* knot as well. These knots are not used in computing
* knot multiplicities.
*/
long multi = 1;
for( ; kindex >= 1; kindex-- ) {
if( knotlist[kindex] - knotlist[kindex-1] < TOLERANCE ) {
multi++;
continue;
}
if ( multi > order ) {
// knot multiplicity greater than order of spline
return( 5 );
}
multi = 1;
}
if ( multi > order ) {
// knot multiplicity greater than order of spline
return( 5 );
}
return 0;
}
void Knotvector::show( const char *msg )
{
}

View File

@@ -0,0 +1,62 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* knotvector.h
*
*/
#ifndef __gluknotvector_h_
#define __gluknotvector_h_
#include "types.h"
struct Knotvector { /* a knot vector */
Knotvector( void );
~Knotvector( void );
void init( long, long, long, INREAL * );
int validate( void );
void show( const char * );
long order; /* order of spline */
long knotcount; /* number of knots */
long stride; /* bytes between points */
Knot * knotlist; /* global knot vector */
};
/* tolerance to test knot coincidence */
#define TOLERANCE 1.0e-5
inline int
identical( Knot x, Knot y )
{
return ((x-y) < TOLERANCE) ? 1 : 0;
}
#endif /* __gluknotvector_h_ */

View File

@@ -0,0 +1,841 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* mapdesc.c++
*
*/
#include <stdio.h>
#include "glimports.h"
#include "mystdio.h"
#include "myassert.h"
#include "mystring.h"
#include "mymath.h"
#include "backend.h"
#include "nurbsconsts.h"
#include "mapdesc.h"
Mapdesc::Mapdesc( long _type, int _israt, int _ncoords, Backend& b )
: backend( b )
{
type = _type;
isrational = _israt;
ncoords = _ncoords;
hcoords = _ncoords + (_israt ? 0 : 1 );
inhcoords = _ncoords - (_israt ? 1 : 0 );
mask = ((1<<(inhcoords*2))-1);
next = 0;
assert( hcoords <= MAXCOORDS );
assert( inhcoords >= 1 );
pixel_tolerance = 1.0;
error_tolerance = 1.0;
bbox_subdividing = N_NOBBOXSUBDIVISION;
culling_method = N_NOCULLING;
sampling_method = N_NOSAMPLING;
clampfactor = N_NOCLAMPING;
minsavings = N_NOSAVINGSSUBDIVISION;
s_steps = 0.0;
t_steps = 0.0;
maxrate = ( s_steps < 0.0f ) ? 0.0f : s_steps;
maxsrate = ( s_steps < 0.0f ) ? 0.0f : s_steps;
maxtrate = ( t_steps < 0.0f ) ? 0.0f : t_steps;
identify( bmat );
identify( cmat );
identify( smat );
for( int i = 0; i != inhcoords; i++ )
bboxsize[i] = 1.0;
}
void
Mapdesc::setBboxsize( INREAL *mat )
{
for( int i = 0; i != inhcoords; i++ )
bboxsize[i] = (REAL) mat[i];
}
void
Mapdesc::identify( REAL dest[MAXCOORDS][MAXCOORDS] )
{
memset( dest, 0, sizeof( dest ) );
for( int i=0; i != hcoords; i++ )
dest[i][i] = 1.0;
}
void
Mapdesc::surfbbox( REAL bb[2][MAXCOORDS] )
{
backend.surfbbox( type, bb[0], bb[1] );
}
void
Mapdesc::copy( REAL dest[MAXCOORDS][MAXCOORDS], long n, INREAL *src,
long rstride, long cstride )
{
assert( n >= 0 );
for( int i=0; i != n; i++ )
for( int j=0; j != n; j++ )
dest[i][j] = src[i*rstride + j*cstride];
}
/*--------------------------------------------------------------------------
* copyPt - copy a homogeneous point
*--------------------------------------------------------------------------
*/
void
Mapdesc::copyPt( REAL *d, REAL *s )
{
assert( hcoords > 0 );
switch( hcoords ) {
case 4:
d[3] = s[3];
d[2] = s[2];
d[1] = s[1];
d[0] = s[0];
break;
case 3:
d[2] = s[2];
d[1] = s[1];
d[0] = s[0];
break;
case 2:
d[1] = s[1];
d[0] = s[0];
break;
case 1:
d[0] = s[0];
break;
case 5:
d[4] = s[4];
d[3] = s[3];
d[2] = s[2];
d[1] = s[1];
d[0] = s[0];
break;
default:
memcpy( d, s, hcoords * sizeof( REAL ) );
break;
}
}
/*--------------------------------------------------------------------------
* sumPt - compute affine combination of two homogeneous points
*--------------------------------------------------------------------------
*/
void
Mapdesc::sumPt( REAL *dst, REAL *src1, REAL *src2, register REAL alpha, register REAL beta )
{
assert( hcoords > 0 );
switch( hcoords ) {
case 4:
dst[3] = src1[3] * alpha + src2[3] * beta;
dst[2] = src1[2] * alpha + src2[2] * beta;
dst[1] = src1[1] * alpha + src2[1] * beta;
dst[0] = src1[0] * alpha + src2[0] * beta;
break;
case 3:
dst[2] = src1[2] * alpha + src2[2] * beta;
dst[1] = src1[1] * alpha + src2[1] * beta;
dst[0] = src1[0] * alpha + src2[0] * beta;
break;
case 2:
dst[1] = src1[1] * alpha + src2[1] * beta;
dst[0] = src1[0] * alpha + src2[0] * beta;
break;
case 1:
dst[0] = src1[0] * alpha + src2[0] * beta;
break;
case 5:
dst[4] = src1[4] * alpha + src2[4] * beta;
dst[3] = src1[3] * alpha + src2[3] * beta;
dst[2] = src1[2] * alpha + src2[2] * beta;
dst[1] = src1[1] * alpha + src2[1] * beta;
dst[0] = src1[0] * alpha + src2[0] * beta;
break;
default: {
for( int i = 0; i != hcoords; i++ )
dst[i] = src1[i] * alpha + src2[i] * beta;
}
break;
}
}
/*--------------------------------------------------------------------------
* clipbits - compute bit-vector indicating point/window position
* of a (transformed) homogeneous point
*--------------------------------------------------------------------------
*/
unsigned int
Mapdesc::clipbits( REAL *p )
{
assert( inhcoords >= 0 );
assert( inhcoords <= 3 );
register int nc = inhcoords;
register REAL pw = p[nc];
register REAL nw = -pw;
register unsigned int bits = 0;
if( pw == 0.0 ) return mask;
if( pw > 0.0 ) {
switch( nc ) {
case 3:
if( p[2] <= pw ) bits |= (1<<5);
if( p[2] >= nw ) bits |= (1<<4);
if( p[1] <= pw ) bits |= (1<<3);
if( p[1] >= nw ) bits |= (1<<2);
if( p[0] <= pw ) bits |= (1<<1);
if( p[0] >= nw ) bits |= (1<<0);
return bits;
case 2:
if( p[1] <= pw ) bits |= (1<<3);
if( p[1] >= nw ) bits |= (1<<2);
if( p[0] <= pw ) bits |= (1<<1);
if( p[0] >= nw ) bits |= (1<<0);
return bits;
case 1:
if( p[0] <= pw ) bits |= (1<<1);
if( p[0] >= nw ) bits |= (1<<0);
return bits;
default: {
int bit = 1;
for( int i=0; i<nc; i++ ) {
if( p[i] >= nw ) bits |= bit;
bit <<= 1;
if( p[i] <= pw ) bits |= bit;
bit <<= 1;
}
abort();
break;
}
}
} else {
switch( nc ) {
case 3:
if( p[2] <= nw ) bits |= (1<<5);
if( p[2] >= pw ) bits |= (1<<4);
if( p[1] <= nw ) bits |= (1<<3);
if( p[1] >= pw ) bits |= (1<<2);
if( p[0] <= nw ) bits |= (1<<1);
if( p[0] >= pw ) bits |= (1<<0);
return bits;
case 2:
if( p[1] <= nw ) bits |= (1<<3);
if( p[1] >= pw ) bits |= (1<<2);
if( p[0] <= nw ) bits |= (1<<1);
if( p[0] >= pw ) bits |= (1<<0);
return bits;
case 1:
if( p[0] <= nw ) bits |= (1<<1);
if( p[0] >= pw ) bits |= (1<<0);
return bits;
default: {
int bit = 1;
for( int i=0; i<nc; i++ ) {
if( p[i] >= pw ) bits |= bit;
bit <<= 1;
if( p[i] <= nw ) bits |= bit;
bit <<= 1;
}
abort();
break;
}
}
}
return bits;
}
/*--------------------------------------------------------------------------
* xformRational - transform a homogeneous point
*--------------------------------------------------------------------------
*/
void
Mapdesc::xformRational( Maxmatrix mat, REAL *d, REAL *s )
{
assert( hcoords >= 0 );
if( hcoords == 3 ) {
REAL x = s[0];
REAL y = s[1];
REAL z = s[2];
d[0] = x*mat[0][0]+y*mat[1][0]+z*mat[2][0];
d[1] = x*mat[0][1]+y*mat[1][1]+z*mat[2][1];
d[2] = x*mat[0][2]+y*mat[1][2]+z*mat[2][2];
} else if( hcoords == 4 ) {
REAL x = s[0];
REAL y = s[1];
REAL z = s[2];
REAL w = s[3];
d[0] = x*mat[0][0]+y*mat[1][0]+z*mat[2][0]+w*mat[3][0];
d[1] = x*mat[0][1]+y*mat[1][1]+z*mat[2][1]+w*mat[3][1];
d[2] = x*mat[0][2]+y*mat[1][2]+z*mat[2][2]+w*mat[3][2];
d[3] = x*mat[0][3]+y*mat[1][3]+z*mat[2][3]+w*mat[3][3];
} else {
for( int i=0; i != hcoords; i++ ) {
d[i] = 0;
for( int j = 0; j != hcoords; j++ )
d[i] += s[j] * mat[j][i];
}
}
}
/*--------------------------------------------------------------------------
* xformNonrational - transform a inhomogeneous point to a homogeneous point
*--------------------------------------------------------------------------
*/
void
Mapdesc::xformNonrational( Maxmatrix mat, REAL *d, REAL *s )
{
if( inhcoords == 2 ) {
REAL x = s[0];
REAL y = s[1];
d[0] = x*mat[0][0]+y*mat[1][0]+mat[2][0];
d[1] = x*mat[0][1]+y*mat[1][1]+mat[2][1];
d[2] = x*mat[0][2]+y*mat[1][2]+mat[2][2];
} else if( inhcoords == 3 ) {
REAL x = s[0];
REAL y = s[1];
REAL z = s[2];
d[0] = x*mat[0][0]+y*mat[1][0]+z*mat[2][0]+mat[3][0];
d[1] = x*mat[0][1]+y*mat[1][1]+z*mat[2][1]+mat[3][1];
d[2] = x*mat[0][2]+y*mat[1][2]+z*mat[2][2]+mat[3][2];
d[3] = x*mat[0][3]+y*mat[1][3]+z*mat[2][3]+mat[3][3];
} else {
assert( inhcoords >= 0 );
for( int i=0; i != hcoords; i++ ) {
d[i] = mat[inhcoords][i];
for( int j = 0; j < inhcoords; j++ )
d[i] += s[j] * mat[j][i];
}
}
}
/*--------------------------------------------------------------------------
* xformAndCullCheck - transform a set of points that may be EITHER
* homogeneous or inhomogeneous depending on the map description and
* check if they are either completely inside, completely outside,
* or intersecting the viewing frustrum.
*--------------------------------------------------------------------------
*/
int
Mapdesc::xformAndCullCheck(
REAL *pts, int uorder, int ustride, int vorder, int vstride )
{
assert( uorder > 0 );
assert( vorder > 0 );
unsigned int inbits = mask;
unsigned int outbits = 0;
REAL *p = pts;
for( REAL *pend = p + uorder * ustride; p != pend; p += ustride ) {
REAL *q = p;
for( REAL *qend = q + vorder * vstride; q != qend; q += vstride ) {
REAL cpts[MAXCOORDS];
xformCulling( cpts, q );
unsigned int bits = clipbits( cpts );
outbits |= bits;
inbits &= bits;
if( ( outbits == (unsigned int)mask ) && ( inbits != (unsigned int)mask ) ) return CULL_ACCEPT;
}
}
if( outbits != (unsigned int)mask ) {
return CULL_TRIVIAL_REJECT;
} else if( inbits == (unsigned int)mask ) {
return CULL_TRIVIAL_ACCEPT;
} else {
return CULL_ACCEPT;
}
}
/*--------------------------------------------------------------------------
* cullCheck - check if a set of homogeneous transformed points are
* either completely inside, completely outside,
* or intersecting the viewing frustrum.
*--------------------------------------------------------------------------
*/
int
Mapdesc::cullCheck( REAL *pts, int uorder, int ustride, int vorder, int vstride )
{
unsigned int inbits = mask;
unsigned int outbits = 0;
REAL *p = pts;
for( REAL *pend = p + uorder * ustride; p != pend; p += ustride ) {
REAL *q = p;
for( REAL *qend = q + vorder * vstride; q != qend; q += vstride ) {
unsigned int bits = clipbits( q );
outbits |= bits;
inbits &= bits;
if( ( outbits == (unsigned int)mask ) && ( inbits != (unsigned int)mask ) ) return CULL_ACCEPT;
}
}
if( outbits != (unsigned int)mask ) {
return CULL_TRIVIAL_REJECT;
} else if( inbits == (unsigned int)mask ) {
return CULL_TRIVIAL_ACCEPT;
} else {
return CULL_ACCEPT;
}
}
/*--------------------------------------------------------------------------
* cullCheck - check if a set of homogeneous transformed points are
* either completely inside, completely outside,
* or intersecting the viewing frustrum.
*--------------------------------------------------------------------------
*/
int
Mapdesc::cullCheck( REAL *pts, int order, int stride )
{
unsigned int inbits = mask;
unsigned int outbits = 0;
REAL *p = pts;
for( REAL *pend = p + order * stride; p != pend; p += stride ) {
unsigned int bits = clipbits( p );
outbits |= bits;
inbits &= bits;
if( ( outbits == (unsigned int)mask ) && ( inbits != (unsigned int)mask ) ) return CULL_ACCEPT;
}
if( outbits != (unsigned int)mask ) {
return CULL_TRIVIAL_REJECT;
} else if( inbits == (unsigned int)mask ) {
return CULL_TRIVIAL_ACCEPT;
} else {
return CULL_ACCEPT;
}
}
/*--------------------------------------------------------------------------
* xformSampling - transform a set of points that may be EITHER
* homogeneous or inhomogeneous depending on the map description
* into sampling space
*--------------------------------------------------------------------------
*/
void
Mapdesc::xformSampling( REAL *pts, int order, int stride, REAL *sp, int outstride )
{
xformMat( smat, pts, order, stride, sp, outstride );
}
void
Mapdesc::xformBounding( REAL *pts, int order, int stride, REAL *sp, int outstride )
{
xformMat( bmat, pts, order, stride, sp, outstride );
}
/*--------------------------------------------------------------------------
* xformCulling - transform a set of points that may be EITHER
* homogeneous or inhomogeneous depending on the map description
* into culling space
*--------------------------------------------------------------------------
*/
void
Mapdesc::xformCulling( REAL *pts, int order, int stride, REAL *cp, int outstride )
{
xformMat( cmat, pts, order, stride, cp, outstride );
}
/*--------------------------------------------------------------------------
* xformCulling - transform a set of points that may be EITHER
* homogeneous or inhomogeneous depending on the map description
* into culling space
*--------------------------------------------------------------------------
*/
void
Mapdesc::xformCulling( REAL *pts,
int uorder, int ustride,
int vorder, int vstride,
REAL *cp, int outustride, int outvstride )
{
xformMat( cmat, pts, uorder, ustride, vorder, vstride, cp, outustride, outvstride );
}
/*--------------------------------------------------------------------------
* xformSampling - transform a set of points that may be EITHER
* homogeneous or inhomogeneous depending on the map description
* into sampling space
*--------------------------------------------------------------------------
*/
void
Mapdesc::xformSampling( REAL *pts,
int uorder, int ustride,
int vorder, int vstride,
REAL *sp, int outustride, int outvstride )
{
xformMat( smat, pts, uorder, ustride, vorder, vstride, sp, outustride, outvstride );
}
void
Mapdesc::xformBounding( REAL *pts,
int uorder, int ustride,
int vorder, int vstride,
REAL *sp, int outustride, int outvstride )
{
xformMat( bmat, pts, uorder, ustride, vorder, vstride, sp, outustride, outvstride );
}
void
Mapdesc::xformMat(
Maxmatrix mat,
REAL * pts,
int order,
int stride,
REAL * cp,
int outstride )
{
if( isrational ) {
REAL *pend = pts + order * stride;
for( REAL *p = pts ; p != pend; p += stride ) {
xformRational( mat, cp, p );
cp += outstride;
}
} else {
REAL *pend = pts + order * stride;
for( REAL *p = pts ; p != pend; p += stride ) {
xformNonrational( mat, cp, p );
cp += outstride;
}
}
}
void
Mapdesc::xformMat( Maxmatrix mat, REAL *pts,
int uorder, int ustride,
int vorder, int vstride,
REAL *cp, int outustride, int outvstride )
{
if( isrational ) {
REAL *pend = pts + uorder * ustride;
for( REAL *p = pts ; p != pend; p += ustride ) {
REAL *cpts2 = cp;
REAL *qend = p + vorder * vstride;
for( REAL *q = p; q != qend; q += vstride ) {
xformRational( mat, cpts2, q );
cpts2 += outvstride;
}
cp += outustride;
}
} else {
REAL *pend = pts + uorder * ustride;
for( REAL *p = pts ; p != pend; p += ustride ) {
REAL *cpts2 = cp;
REAL *qend = p + vorder * vstride;
for( REAL *q = p; q != qend; q += vstride ) {
xformNonrational( mat, cpts2, q );
cpts2 += outvstride;
}
cp += outustride;
}
}
}
/*--------------------------------------------------------------------------
* subdivide - subdivide a curve along an isoparametric line
*--------------------------------------------------------------------------
*/
void
Mapdesc::subdivide( REAL *src, REAL *dst, REAL v, int stride, int order )
{
REAL mv = 1.0f - v;
for( REAL *send=src+stride*order; src!=send; send-=stride, dst+=stride ) {
copyPt( dst, src );
REAL *qpnt = src + stride;
for( REAL *qp=src; qpnt!=send; qp=qpnt, qpnt+=stride )
sumPt( qp, qp, qpnt, mv, v );
}
}
/*--------------------------------------------------------------------------
* subdivide - subdivide a patch along an isoparametric line
*--------------------------------------------------------------------------
*/
void
Mapdesc::subdivide( REAL *src, REAL *dst, REAL v,
int so, int ss, int to, int ts )
{
REAL mv = 1.0f - v;
for( REAL *slast = src+ss*so; src != slast; src += ss, dst += ss ) {
REAL *sp = src;
REAL *dp = dst;
for( REAL *send = src+ts*to; sp != send; send -= ts, dp += ts ) {
copyPt( dp, sp );
REAL *qp = sp;
for( REAL *qpnt = sp+ts; qpnt != send; qp = qpnt, qpnt += ts )
sumPt( qp, qp, qpnt, mv, v );
}
}
}
#define sign(x) ((x > 0) ? 1 : ((x < 0.0) ? -1 : 0))
/*--------------------------------------------------------------------------
* project - project a set of homogeneous coordinates into inhomogeneous ones
*--------------------------------------------------------------------------
*/
int
Mapdesc::project( REAL *src, int rstride, int cstride,
REAL *dest, int trstride, int tcstride,
int nrows, int ncols )
{
int s = sign( src[inhcoords] );
REAL *rlast = src + nrows * rstride;
REAL *trptr = dest;
for( REAL *rptr=src; rptr != rlast; rptr+=rstride, trptr+=trstride ) {
REAL *clast = rptr + ncols * cstride;
REAL *tcptr = trptr;
for( REAL *cptr = rptr; cptr != clast; cptr+=cstride, tcptr+=tcstride ) {
REAL *coordlast = cptr + inhcoords;
if( sign( *coordlast ) != s ) return 0;
REAL *tcoord = tcptr;
for( REAL *coord = cptr; coord != coordlast; coord++, tcoord++ ) {
*tcoord = *coord / *coordlast;
}
}
}
return 1;
}
/*--------------------------------------------------------------------------
* project - project a set of homogeneous coordinates into inhomogeneous ones
*--------------------------------------------------------------------------
*/
int
Mapdesc::project( REAL *src, int stride, REAL *dest, int tstride, int ncols )
{
int s = sign( src[inhcoords] );
REAL *clast = src + ncols * stride;
for( REAL *cptr = src, *tcptr = dest; cptr != clast; cptr+=stride, tcptr+=tstride ) {
REAL *coordlast = cptr + inhcoords;
if( sign( *coordlast ) != s ) return 0;
for( REAL *coord = cptr, *tcoord = tcptr; coord != coordlast; coord++, tcoord++ )
*tcoord = *coord / *coordlast;
}
return 1;
}
int
Mapdesc::bboxTooBig(
REAL *p,
int rstride,
int cstride,
int nrows,
int ncols,
REAL bb[2][MAXCOORDS] )
{
REAL bbpts[MAXORDER][MAXORDER][MAXCOORDS];
const int trstride = sizeof(bbpts[0]) / sizeof(REAL);
const int tcstride = sizeof(bbpts[0][0]) / sizeof(REAL);
// points have been transformed, therefore they are homogeneous
// project points
int val = project( p, rstride, cstride,
&bbpts[0][0][0], trstride, tcstride, nrows, ncols );
if( val == 0 ) return -1;
// compute bounding box
bbox( bb, &bbpts[0][0][0], trstride, tcstride, nrows, ncols );
// find out if bounding box can't fit in unit cube
if( bbox_subdividing == N_BBOXROUND ) {
for( int k=0; k != inhcoords; k++ )
if( ceilf(bb[1][k]) - floorf(bb[0][k]) > bboxsize[k] ) return 1;
} else {
for( int k=0; k != inhcoords; k++ )
if( bb[1][k] - bb[0][k] > bboxsize[k] ) return 1;
}
return 0;
}
void
Mapdesc::bbox(
REAL bb[2][MAXCOORDS],
REAL *p,
int rstride,
int cstride,
int nrows,
int ncols )
{
int k;
for( k=0; k != inhcoords; k++ )
bb[0][k] = bb[1][k] = p[k];
for( int i=0; i != nrows; i++ )
for( int j=0; j != ncols; j++ )
for( k=0; k != inhcoords; k++ ) {
REAL x = p[i*rstride + j*cstride + k];
if( x < bb[0][k] ) bb[0][k] = x;
else if( x > bb[1][k] ) bb[1][k] = x;
}
}
/*--------------------------------------------------------------------------
* calcVelocityRational - calculate upper bound on first partial derivative
* of a homogeneous set of points and bounds on each row of points.
*--------------------------------------------------------------------------
*/
REAL
Mapdesc::calcVelocityRational( REAL *p, int stride, int ncols )
{
REAL tmp[MAXORDER][MAXCOORDS];
assert( ncols <= MAXORDER );
const int tstride = sizeof(tmp[0]) / sizeof(REAL);
if( project( p, stride, &tmp[0][0], tstride, ncols ) ) {
return calcPartialVelocity( &tmp[0][0], tstride, ncols, 1, 1.0 );
} else { /* XXX */
return calcPartialVelocity( &tmp[0][0], tstride, ncols, 1, 1.0 );
}
}
/*--------------------------------------------------------------------------
* calcVelocityNonrational - calculate upper bound on first partial
* derivative of a inhomogeneous set of points.
*--------------------------------------------------------------------------
*/
REAL
Mapdesc::calcVelocityNonrational( REAL *pts, int stride, int ncols )
{
return calcPartialVelocity( pts, stride, ncols, 1, 1.0 );
}
int
Mapdesc::isProperty( long property )
{
switch ( property ) {
case N_PIXEL_TOLERANCE:
case N_ERROR_TOLERANCE:
case N_CULLING:
case N_BBOX_SUBDIVIDING:
case N_S_STEPS:
case N_T_STEPS:
case N_SAMPLINGMETHOD:
case N_CLAMPFACTOR:
case N_MINSAVINGS:
return 1;
default:
return 0;
}
}
REAL
Mapdesc::getProperty( long property )
{
switch ( property ) {
case N_PIXEL_TOLERANCE:
return pixel_tolerance;
case N_ERROR_TOLERANCE:
return error_tolerance;
case N_CULLING:
return culling_method;
case N_BBOX_SUBDIVIDING:
return bbox_subdividing;
case N_S_STEPS:
return s_steps;
case N_T_STEPS:
return t_steps;
case N_SAMPLINGMETHOD:
return sampling_method;
case N_CLAMPFACTOR:
return clampfactor;
case N_MINSAVINGS:
return minsavings;
default:
abort();
return -1; //not necessary, needed to shut up compiler
}
}
void
Mapdesc::setProperty( long property, REAL value )
{
switch ( property ) {
case N_PIXEL_TOLERANCE:
pixel_tolerance = value;
break;
case N_ERROR_TOLERANCE:
error_tolerance = value;
break;
case N_CULLING:
culling_method = value;
break;
case N_BBOX_SUBDIVIDING:
if( value <= 0.0 ) value = N_NOBBOXSUBDIVISION;
bbox_subdividing = value;
break;
case N_S_STEPS:
if( value < 0.0f ) value = 0.0f;
s_steps = value;
maxrate = ( value < 0.0f ) ? 0.0f : value;
maxsrate = ( value < 0.0f ) ? 0.0f : value;
break;
case N_T_STEPS:
if( value < 0.0f ) value = 0.0f;
t_steps = value;
maxtrate = ( value < 0.0f ) ? 0.0f : value;
break;
case N_SAMPLINGMETHOD:
sampling_method = value;
break;
case N_CLAMPFACTOR:
if( value <= 0.0 ) value = N_NOCLAMPING;
clampfactor = value;
break;
case N_MINSAVINGS:
if( value <= 0.0 ) value = N_NOSAVINGSSUBDIVISION;
minsavings = value;
break;
default:
abort();
break;
}
}

View File

@@ -0,0 +1,271 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* mapdesc.h
*
*/
#ifndef __glumapdesc_h_
#define __glumapdesc_h_
#include "mystdio.h"
#include "types.h"
#include "defines.h"
#include "bufpool.h"
#include "nurbsconsts.h"
typedef REAL Maxmatrix[MAXCOORDS][MAXCOORDS];
class Backend;
class Mapdesc : public PooledObj {
friend class Maplist;
public:
Mapdesc( long, int, int, Backend & );
int isProperty( long );
REAL getProperty( long );
void setProperty( long, REAL );
int isConstantSampling( void );
int isDomainSampling( void );
int isRangeSampling( void );
int isSampling( void );
int isParametricDistanceSampling( void );
int isObjectSpaceParaSampling( void );
int isObjectSpacePathSampling( void );
int isSurfaceAreaSampling( void );
int isPathLengthSampling( void );
int isCulling( void );
int isBboxSubdividing( void );
long getType( void );
/* curve routines */
void subdivide( REAL *, REAL *, REAL, int, int );
int cullCheck( REAL *, int, int );
void xformBounding( REAL *, int, int, REAL *, int );
void xformCulling( REAL *, int, int, REAL *, int );
void xformSampling( REAL *, int, int, REAL *, int );
void xformMat( Maxmatrix, REAL *, int, int, REAL *, int );
REAL calcPartialVelocity ( REAL *, int, int, int, REAL );
int project( REAL *, int, REAL *, int, int );
REAL calcVelocityRational( REAL *, int, int );
REAL calcVelocityNonrational( REAL *, int, int );
/* surface routines */
void subdivide( REAL *, REAL *, REAL, int, int, int, int );
int cullCheck( REAL *, int, int, int, int );
void xformBounding( REAL *, int, int, int, int, REAL *, int, int );
void xformCulling( REAL *, int, int, int, int, REAL *, int, int );
void xformSampling( REAL *, int, int, int, int, REAL *, int, int );
void xformMat( Maxmatrix, REAL *, int, int, int, int, REAL *, int, int );
REAL calcPartialVelocity ( REAL *, REAL *, int, int, int, int, int, int, REAL, REAL, int );
int project( REAL *, int, int, REAL *, int, int, int, int);
void surfbbox( REAL bb[2][MAXCOORDS] );
int bboxTooBig( REAL *, int, int, int, int, REAL [2][MAXCOORDS] );
int xformAndCullCheck( REAL *, int, int, int, int );
void identify( REAL[MAXCOORDS][MAXCOORDS] );
void setBboxsize( INREAL *);
inline void setBmat( INREAL*, long, long );
inline void setCmat( INREAL*, long, long );
inline void setSmat( INREAL*, long, long );
inline int isRational( void );
inline int getNcoords( void );
REAL pixel_tolerance; /* pathlength sampling tolerance */
REAL error_tolerance; /* parametric error sampling tolerance*/
REAL object_space_error_tolerance; /* object space tess*/
REAL clampfactor;
REAL minsavings;
REAL maxrate;
REAL maxsrate;
REAL maxtrate;
REAL bboxsize[MAXCOORDS];
private:
long type;
int isrational;
int ncoords;
int hcoords;
int inhcoords;
int mask;
Maxmatrix bmat;
Maxmatrix cmat;
Maxmatrix smat;
REAL s_steps; /* max samples in s direction */
REAL t_steps; /* max samples in t direction */
REAL sampling_method;
REAL culling_method; /* check for culling */
REAL bbox_subdividing;
Mapdesc * next;
Backend & backend;
void bbox( REAL [2][MAXCOORDS], REAL *, int, int, int, int );
REAL maxDifference( int, REAL *, int );
static void copy( Maxmatrix, long, INREAL *, long, long );
/* individual control point routines */
static void transform4d( float[4], float[4], float[4][4] );
static void multmatrix4d ( float[4][4], const float[4][4],
const float[4][4] );
void copyPt( REAL *, REAL * );
void sumPt( REAL *, REAL *, REAL *, REAL, REAL );
void xformSampling( REAL *, REAL * );
void xformCulling( REAL *, REAL * );
void xformRational( Maxmatrix, REAL *, REAL * );
void xformNonrational( Maxmatrix, REAL *, REAL * );
unsigned int clipbits( REAL * );
};
inline void
Mapdesc::setBmat( INREAL *mat, long rstride, long cstride )
{
copy( bmat, hcoords, mat, rstride, cstride );
}
inline void
Mapdesc::setCmat( INREAL *mat, long rstride, long cstride )
{
copy( cmat, hcoords, mat, rstride, cstride );
}
inline void
Mapdesc::setSmat( INREAL *mat, long rstride, long cstride )
{
copy( smat, hcoords, mat, rstride, cstride );
}
inline long
Mapdesc::getType( void )
{
return type;
}
inline void
Mapdesc::xformCulling( REAL *d, REAL *s )
{
if( isrational )
xformRational( cmat, d, s );
else
xformNonrational( cmat, d, s );
}
inline void
Mapdesc::xformSampling( REAL *d, REAL *s )
{
if( isrational )
xformRational( smat, d, s );
else
xformNonrational( smat, d, s );
}
inline int
Mapdesc::isRational( void )
{
return isrational ? 1 : 0;
}
inline int
Mapdesc::getNcoords( void )
{
return ncoords;
}
inline int
Mapdesc::isConstantSampling( void )
{
return ((sampling_method == N_FIXEDRATE) ? 1 : 0);
}
inline int
Mapdesc::isDomainSampling( void )
{
return ((sampling_method == N_DOMAINDISTANCE) ? 1 : 0);
}
inline int
Mapdesc::isParametricDistanceSampling( void )
{
return ((sampling_method == N_PARAMETRICDISTANCE) ? 1 : 0);
}
inline int
Mapdesc::isObjectSpaceParaSampling( void )
{
return ((sampling_method == N_OBJECTSPACE_PARA) ? 1 : 0);
}
inline int
Mapdesc::isObjectSpacePathSampling( void )
{
return ((sampling_method == N_OBJECTSPACE_PATH) ? 1 : 0);
}
inline int
Mapdesc::isSurfaceAreaSampling( void )
{
return ((sampling_method == N_SURFACEAREA) ? 1 : 0);
}
inline int
Mapdesc::isPathLengthSampling( void )
{
return ((sampling_method == N_PATHLENGTH) ? 1 : 0);
}
inline int
Mapdesc::isRangeSampling( void )
{
return ( isParametricDistanceSampling() || isPathLengthSampling() ||
isSurfaceAreaSampling() ||
isObjectSpaceParaSampling() ||
isObjectSpacePathSampling());
}
inline int
Mapdesc::isSampling( void )
{
return isRangeSampling() || isConstantSampling() || isDomainSampling();
}
inline int
Mapdesc::isCulling( void )
{
return ((culling_method != N_NOCULLING) ? 1 : 0);
}
inline int
Mapdesc::isBboxSubdividing( void )
{
return ((bbox_subdividing != N_NOBBOXSUBDIVISION) ? 1 : 0);
}
#endif /* __glumapdesc_h_ */

View File

@@ -0,0 +1,243 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* mapdescv.c++
*
*/
#include "glimports.h"
#include "mystdio.h"
#include "myassert.h"
#include "mystring.h"
#include "mymath.h"
#include "nurbsconsts.h"
#include "mapdesc.h"
/*--------------------------------------------------------------------------
* calcPartialVelocity - calculate maximum magnitude of a given partial
* derivative
*--------------------------------------------------------------------------
*/
REAL
Mapdesc::calcPartialVelocity (
REAL *p,
int stride,
int ncols,
int partial,
REAL range )
{
REAL tmp[MAXORDER][MAXCOORDS];
REAL mag[MAXORDER];
assert( ncols <= MAXORDER );
int j, k, t;
// copy inhomogeneous control points into temporary array
for( j=0; j != ncols; j++ )
for( k=0; k != inhcoords; k++ )
tmp[j][k] = p[j*stride + k];
for( t=0; t != partial; t++ )
for( j=0; j != ncols-t-1; j++ )
for( k=0; k != inhcoords; k++ )
tmp[j][k] = tmp[j+1][k] - tmp[j][k];
// compute magnitude and store in mag array
for( j=0; j != ncols-partial; j++ ) {
mag[j] = 0.0;
for( k=0; k != inhcoords; k++ )
mag[j] += tmp[j][k] * tmp[j][k];
}
// compute scale factor
REAL fac = 1.0f;
REAL invt = 1.0f / range;
for( t = ncols-1; t != ncols-1-partial; t-- )
fac *= t * invt;
// compute max magnitude of all entries in array
REAL max = 0.0;
for( j=0; j != ncols-partial; j++ )
if( mag[j] > max ) max = mag[j];
max = fac * sqrtf( (float) max );
return max;
}
/*--------------------------------------------------------------------------
* calcPartialVelocity - calculate maximum magnitude of a given partial
* derivative
*--------------------------------------------------------------------------
*/
REAL
Mapdesc::calcPartialVelocity (
REAL *dist,
REAL *p,
int rstride,
int cstride,
int nrows,
int ncols,
int spartial,
int tpartial,
REAL srange,
REAL trange,
int side )
{
REAL tmp[MAXORDER][MAXORDER][MAXCOORDS];
REAL mag[MAXORDER][MAXORDER];
assert( nrows <= MAXORDER );
assert( ncols <= MAXORDER );
REAL *tp = &tmp[0][0][0];
REAL *mp = &mag[0][0];
const int istride = sizeof( tmp[0]) / sizeof( tmp[0][0][0] );
const int jstride = sizeof( tmp[0][0]) / sizeof( tmp[0][0][0] );
/*
const int kstride = sizeof( tmp[0][0][0]) / sizeof( tmp[0][0][0] );
*/
const int mistride = sizeof( mag[0]) / sizeof( mag[0][0] );
const int mjstride = sizeof( mag[0][0]) / sizeof( mag[0][0] );
const int idist = nrows * istride;
const int jdist = ncols * jstride;
/*
const int kdist = inhcoords * kstride;
*/
const int id = idist - spartial * istride;
const int jd = jdist - tpartial * jstride;
{
// copy control points
REAL *ti = tp;
REAL *qi = p;
REAL *til = tp + idist;
for( ; ti != til; ) {
REAL *tj = ti;
REAL *qj = qi;
REAL *tjl = ti + jdist;
for( ; tj != tjl; ) {
for( int k=0; k != inhcoords; k++ ) {
tj[k] = qj[k];
}
tj += jstride;
qj += cstride;
}
ti += istride;
qi += rstride;
}
}
{
// compute (s)-partial derivative control points
REAL *til = tp + idist - istride;
const REAL *till = til - ( spartial * istride );
for( ; til != till; til -= istride )
for( REAL *ti = tp; ti != til; ti += istride )
for( REAL *tj = ti, *tjl = tj + jdist; tj != tjl; tj += jstride )
for( int k=0; k != inhcoords; k++ )
tj[k] = tj[k+istride] - tj[k];
}
{
// compute (s,t)-partial derivative control points
REAL *tjl = tp + jdist - jstride;
const REAL *tjll = tjl - ( tpartial * jstride );
for( ; tjl != tjll; tjl -= jstride )
for( REAL *tj = tp; tj != tjl; tj += jstride )
for( REAL *ti = tj, *til = ti + id; ti != til; ti += istride )
for( int k=0; k != inhcoords; k++ )
ti[k] = ti[k+jstride] - ti[k];
}
REAL max = 0.0;
{
// compute magnitude and store in mag array
memset( (void *) mp, 0, sizeof( mag ) );
for( REAL *ti = tp, *mi = mp, *til = tp + id; ti != til; ti += istride, mi += mistride )
for( REAL *tj = ti, *mj = mi, *tjl = ti + jd; tj != tjl; tj += jstride, mj += mjstride ) {
for( int k=0; k != inhcoords; k++ )
*mj += tj[k] * tj[k];
if( *mj > max ) max = *mj;
}
}
int i, j;
// compute scale factor
REAL fac = 1.0f;
{
REAL invs = 1.0f / srange;
REAL invt = 1.0f / trange;
for( int s = nrows-1, slast = s-spartial; s != slast; s-- )
fac *= s * invs;
for( int t = ncols-1, tlast = t-tpartial; t != tlast; t-- )
fac *= t * invt;
}
if( side == 0 ) {
// compute max magnitude of first and last column
dist[0] = 0.0;
dist[1] = 0.0;
for( i=0; i != nrows-spartial; i++ ) {
j = 0;
if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
j = ncols-tpartial-1;
if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
}
dist[0] = fac * sqrtf( dist[0] );
dist[1] = fac * sqrtf( dist[1] );
} else if( side == 1 ) {
// compute max magnitude of first and last row
dist[0] = 0.0;
dist[1] = 0.0;
for( j=0; j != ncols-tpartial; j++ ) {
i = 0;
if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
i = nrows-spartial-1;
if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
}
dist[0] = fac * sqrtf( dist[0] );
dist[1] = fac * sqrtf( dist[1] );
}
max = fac * sqrtf( (float) max );
return max;
}

View File

@@ -0,0 +1,113 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* maplist.c++
*
*/
#include "glimports.h"
#include "mystdio.h"
#include "myassert.h"
#include "mymath.h"
#include "nurbsconsts.h"
#include "maplist.h"
#include "mapdesc.h"
#include "backend.h"
Maplist::Maplist( Backend& b )
: mapdescPool( sizeof( Mapdesc ), 10, "mapdesc pool" ),
backend( b )
{
maps = 0; lastmap = &maps;
}
void
Maplist::initialize( void )
{
freeMaps();
define( N_P2D, 0, 2 );
define( N_P2DR, 1, 3 );
}
void
Maplist::add( long type, int israt, int ncoords )
{
*lastmap = new(mapdescPool) Mapdesc( type, israt, ncoords, backend );
lastmap = &((*lastmap)->next);
}
void
Maplist::define( long type, int israt, int ncoords )
{
add( type, israt, ncoords );
}
void
Maplist::remove( Mapdesc *m )
{
for( Mapdesc **curmap = &maps; *curmap; curmap = &((*curmap)->next) ) {
if( *curmap == m ) {
*curmap = m->next;
m->deleteMe( mapdescPool );
return;
}
}
abort();
}
void
Maplist::freeMaps( void )
{
mapdescPool.clear();
maps = 0;
lastmap = &maps;
}
Mapdesc *
Maplist::find( long type )
{
Mapdesc *val = locate( type );
assert( val != 0 );
return val;
}
Mapdesc *
Maplist::locate( long type )
{
Mapdesc *m;
for( m = maps; m; m = m->next )
if( m->getType() == type ) break;
return m;
}

View File

@@ -0,0 +1,81 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* maplist.h
*
*/
#ifndef __glumaplist_h_
#define __glumaplist_h_
#include "types.h"
#include "defines.h"
#include "bufpool.h"
class Backend;
class Mapdesc;
class Maplist {
public:
Maplist( Backend & );
void define( long, int, int );
inline void undefine( long );
inline int isMap( long );
void initialize( void );
Mapdesc * find( long );
Mapdesc * locate( long );
private:
Pool mapdescPool;
Mapdesc * maps;
Mapdesc ** lastmap;
Backend & backend;
void add( long, int, int );
void remove( Mapdesc * );
void freeMaps( void );
};
inline int
Maplist::isMap( long type )
{
return (locate( type ) ? 1 : 0);
}
inline void
Maplist::undefine( long type )
{
Mapdesc *m = locate( type );
assert( m != 0 );
remove( m );
}
#endif /* __glumaplist_h_ */

View File

@@ -0,0 +1,483 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* mesher.c++
*
*/
#include "glimports.h"
#include "myassert.h"
#include "mystdio.h"
#include "gridvertex.h"
#include "gridtrimvertex.h"
#include "jarcloc.h"
#include "gridline.h"
#include "trimline.h"
#include "uarray.h"
#include "backend.h"
#include "mesher.h"
#include <stdio.h>
const float Mesher::ZERO = 0.0;
Mesher::Mesher( Backend& b )
: backend( b ),
p( sizeof( GridTrimVertex ), 100, "GridTrimVertexPool" )
{
stacksize = 0;
vdata = 0;
lastedge = 0; //needed to prevent purify UMR
}
Mesher::~Mesher( void )
{
if( vdata ) delete[] vdata;
}
void
Mesher::init( unsigned int npts )
{
p.clear();
if( stacksize < npts ) {
stacksize = 2 * npts;
if( vdata ) delete[] vdata;
vdata = new GridTrimVertex_p[stacksize];
}
}
inline void
Mesher::push( GridTrimVertex *gt )
{
assert( itop+1 != (int)stacksize );
vdata[++itop] = gt;
}
inline void
Mesher::pop( long )
{
}
inline void Mesher::openMesh()
{
backend.bgntmesh("addedge");
}
inline void Mesher::closeMesh()
{
backend.endtmesh();
}
inline void Mesher::swapMesh()
{
backend.swaptmesh();
}
inline void Mesher::clearStack()
{
itop = -1;
last[0] = 0;
}
void
Mesher::finishLower( GridTrimVertex *gtlower )
{
for( push(gtlower);
nextlower( gtlower=new(p) GridTrimVertex );
push(gtlower) )
addLower();
addLast();
}
void
Mesher::finishUpper( GridTrimVertex *gtupper )
{
for( push(gtupper);
nextupper( gtupper=new(p) GridTrimVertex );
push(gtupper) )
addUpper();
addLast();
}
void
Mesher::mesh( void )
{
GridTrimVertex *gtlower, *gtupper;
Hull::init( );
nextupper( gtupper = new(p) GridTrimVertex );
nextlower( gtlower = new(p) GridTrimVertex );
clearStack();
openMesh();
push(gtupper);
nextupper( gtupper = new(p) GridTrimVertex );
nextlower( gtlower );
assert( gtupper->t && gtlower->t );
if( gtupper->t->param[0] < gtlower->t->param[0] ) {
push(gtupper);
lastedge = 1;
if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) {
finishLower(gtlower);
return;
}
} else if( gtupper->t->param[0] > gtlower->t->param[0] ) {
push(gtlower);
lastedge = 0;
if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
finishUpper(gtupper);
return;
}
} else {
if( lastedge == 0 ) {
push(gtupper);
lastedge = 1;
if( nextupper(gtupper=new(p) GridTrimVertex) == 0 ) {
finishLower(gtlower);
return;
}
} else {
push(gtlower);
lastedge = 0;
if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
finishUpper(gtupper);
return;
}
}
}
while ( 1 ) {
if( gtupper->t->param[0] < gtlower->t->param[0] ) {
push(gtupper);
addUpper();
if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) {
finishLower(gtlower);
return;
}
} else if( gtupper->t->param[0] > gtlower->t->param[0] ) {
push(gtlower);
addLower();
if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
finishUpper(gtupper);
return;
}
} else {
if( lastedge == 0 ) {
push(gtupper);
addUpper();
if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) {
finishLower(gtlower);
return;
}
} else {
push(gtlower);
addLower();
if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
finishUpper(gtupper);
return;
}
}
}
}
}
inline int
Mesher::isCcw( int ilast )
{
REAL area = det3( vdata[ilast]->t, vdata[itop-1]->t, vdata[itop-2]->t );
return (area < ZERO) ? 0 : 1;
}
inline int
Mesher::isCw( int ilast )
{
REAL area = det3( vdata[ilast]->t, vdata[itop-1]->t, vdata[itop-2]->t );
return (area > -ZERO) ? 0 : 1;
}
inline int
Mesher::equal( int x, int y )
{
return( last[0] == vdata[x] && last[1] == vdata[y] );
}
inline void
Mesher::copy( int x, int y )
{
last[0] = vdata[x]; last[1] = vdata[y];
}
inline void
Mesher::move( int x, int y )
{
vdata[x] = vdata[y];
}
inline void
Mesher::output( int x )
{
backend.tmeshvert( vdata[x] );
}
/*---------------------------------------------------------------------------
* addedge - addedge an edge to the triangulation
*
* This code has been re-written to generate large triangle meshes
* from a monotone polygon. Although smaller triangle meshes
* could be generated faster and with less code, larger meshes
* actually give better SYSTEM performance. This is because
* vertices are processed in the backend slower than they are
* generated by this code and any decrease in the number of vertices
* results in a decrease in the time spent in the backend.
*---------------------------------------------------------------------------
*/
void
Mesher::addLast( )
{
register int ilast = itop;
if( lastedge == 0 ) {
if( equal( 0, 1 ) ) {
output( ilast );
swapMesh();
for( register int i = 2; i < ilast; i++ ) {
swapMesh();
output( i );
}
copy( ilast, ilast-1 );
} else if( equal( ilast-2, ilast-1) ) {
swapMesh();
output( ilast );
for( register int i = ilast-3; i >= 0; i-- ) {
output( i );
swapMesh();
}
copy( 0, ilast );
} else {
closeMesh(); openMesh();
output( ilast );
output( 0 );
for( register int i = 1; i < ilast; i++ ) {
swapMesh();
output( i );
}
copy( ilast, ilast-1 );
}
} else {
if( equal( 1, 0) ) {
swapMesh();
output( ilast );
for( register int i = 2; i < ilast; i++ ) {
output( i );
swapMesh();
}
copy( ilast-1, ilast );
} else if( equal( ilast-1, ilast-2) ) {
output( ilast );
swapMesh();
for( register int i = ilast-3; i >= 0; i-- ) {
swapMesh();
output( i );
}
copy( ilast, 0 );
} else {
closeMesh(); openMesh();
output( 0 );
output( ilast );
for( register int i = 1; i < ilast; i++ ) {
output( i );
swapMesh();
}
copy( ilast-1, ilast );
}
}
closeMesh();
//for( register long k=0; k<=ilast; k++ ) pop( k );
}
void
Mesher::addUpper( )
{
register int ilast = itop;
if( lastedge == 0 ) {
if( equal( 0, 1 ) ) {
output( ilast );
swapMesh();
for( register int i = 2; i < ilast; i++ ) {
swapMesh();
output( i );
}
copy( ilast, ilast-1 );
} else if( equal( ilast-2, ilast-1) ) {
swapMesh();
output( ilast );
for( register int i = ilast-3; i >= 0; i-- ) {
output( i );
swapMesh();
}
copy( 0, ilast );
} else {
closeMesh(); openMesh();
output( ilast );
output( 0 );
for( register int i = 1; i < ilast; i++ ) {
swapMesh();
output( i );
}
copy( ilast, ilast-1 );
}
lastedge = 1;
//for( register long k=0; k<ilast-1; k++ ) pop( k );
move( 0, ilast-1 );
move( 1, ilast );
itop = 1;
} else {
if( ! isCcw( ilast ) ) return;
do {
itop--;
} while( (itop > 1) && isCcw( ilast ) );
if( equal( ilast-1, ilast-2 ) ) {
output( ilast );
swapMesh();
for( register int i=ilast-3; i>=itop-1; i-- ) {
swapMesh();
output( i );
}
copy( ilast, itop-1 );
} else if( equal( itop, itop-1 ) ) {
swapMesh();
output( ilast );
for( register int i = itop+1; i < ilast; i++ ) {
output( i );
swapMesh();
}
copy( ilast-1, ilast );
} else {
closeMesh(); openMesh();
output( ilast );
output( ilast-1 );
for( register int i=ilast-2; i>=itop-1; i-- ) {
swapMesh();
output( i );
}
copy( ilast, itop-1 );
}
//for( register int k=itop; k<ilast; k++ ) pop( k );
move( itop, ilast );
}
}
void
Mesher::addLower()
{
register int ilast = itop;
if( lastedge == 1 ) {
if( equal( 1, 0) ) {
swapMesh();
output( ilast );
for( register int i = 2; i < ilast; i++ ) {
output( i );
swapMesh();
}
copy( ilast-1, ilast );
} else if( equal( ilast-1, ilast-2) ) {
output( ilast );
swapMesh();
for( register int i = ilast-3; i >= 0; i-- ) {
swapMesh();
output( i );
}
copy( ilast, 0 );
} else {
closeMesh(); openMesh();
output( 0 );
output( ilast );
for( register int i = 1; i < ilast; i++ ) {
output( i );
swapMesh();
}
copy( ilast-1, ilast );
}
lastedge = 0;
//for( register long k=0; k<ilast-1; k++ ) pop( k );
move( 0, ilast-1 );
move( 1, ilast );
itop = 1;
} else {
if( ! isCw( ilast ) ) return;
do {
itop--;
} while( (itop > 1) && isCw( ilast ) );
if( equal( ilast-2, ilast-1) ) {
swapMesh();
output( ilast );
for( register int i=ilast-3; i>=itop-1; i--) {
output( i );
swapMesh( );
}
copy( itop-1, ilast );
} else if( equal( itop-1, itop) ) {
output( ilast );
swapMesh();
for( register int i=itop+1; i<ilast; i++ ) {
swapMesh( );
output( i );
}
copy( ilast, ilast-1 );
} else {
closeMesh(); openMesh();
output( ilast-1 );
output( ilast );
for( register int i=ilast-2; i>=itop-1; i-- ) {
output( i );
swapMesh( );
}
copy( itop-1, ilast );
}
//for( register int k=itop; k<ilast; k++ ) pop( k );
move( itop, ilast );
}
}

View File

@@ -0,0 +1,83 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* mesher.h
*
*/
#ifndef __glumesher_h_
#define __glumesher_h_
#include "hull.h"
class TrimRegion;
class Backend;
class Pool;
// struct GridTrimVertex;
class Mesher : virtual public TrimRegion, public Hull {
public:
Mesher( Backend & );
~Mesher( void );
void init( unsigned int );
void mesh( void );
private:
static const float ZERO;
Backend& backend;
Pool p;
unsigned int stacksize;
GridTrimVertex ** vdata;
GridTrimVertex * last[2];
int itop;
int lastedge;
inline void openMesh( void );
inline void swapMesh( void );
inline void closeMesh( void );
inline int isCcw( int );
inline int isCw( int );
inline void clearStack( void );
inline void push( GridTrimVertex * );
inline void pop( long );
inline void move( int, int );
inline int equal( int, int );
inline void copy( int, int );
inline void output( int );
void addUpper( void );
void addLower( void );
void addLast( void );
void finishUpper( GridTrimVertex * );
void finishLower( GridTrimVertex * );
};
#endif /* __glumesher_h_ */

View File

@@ -0,0 +1,785 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/
#include "monoTriangulation.h"
#include "polyUtil.h"
#include "backend.h"
#include "arc.h"
#include "displaymode.h"
#include "gles_evaluator.h"
#include "glues.h"
#include <stdio.h>
void reflexChain::outputFan(Real v[2], Backend* backend)
{
Int i;
REAL retPoint[4];
REAL retNormal[3];
int it=0;
GLboolean texcoord_enabled;
GLboolean normal_enabled;
GLboolean vertex_enabled;
GLboolean color_enabled;
/* Store status of enabled arrays */
texcoord_enabled=GL_FALSE; /* glIsEnabled(GL_TEXTURE_COORD_ARRAY); */
normal_enabled=GL_FALSE; /* glIsEnabled(GL_NORMAL_ARRAY); */
vertex_enabled=GL_FALSE; /* glIsEnabled(GL_VERTEX_ARRAY); */
color_enabled=GL_FALSE; /* glIsEnabled(GL_COLOR_ARRAY); */
backend->bgntfan();
if (backend->get_output_style()==N_MESHLINE)
{
REAL* vertices=(REAL*)malloc(sizeof(REAL)*3*(index_queue+1)*3);
assert(vertices);
REAL* normals=(REAL*)malloc(sizeof(REAL)*3*(index_queue+1)*3);
assert(normals);
/* Enable needed and disable unneeded arrays */
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
backend->tmeshvert(v[0], v[1], retPoint, retNormal);
/* Store triangle fan center vertex */
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
if (isIncreasing)
{
for(i=0; i<index_queue; i++)
{
if (it%3==0)
{
/* Store triangle fan center vertex */
backend->tmeshvert(v[0], v[1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
/* Store previous vertex */
backend->tmeshvert(queue[i-1][0], queue[i-1][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
/* Store new vertex */
backend->tmeshvert(queue[i][0], queue[i][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
}
else
{
for(i=index_queue-1; i>=0; i--)
{
if (it%3==0)
{
/* Store triangle fan center vertex */
backend->tmeshvert(v[0], v[1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
/* Store previous vertex */
backend->tmeshvert(queue[i+1][0], queue[i+1][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
backend->tmeshvert(queue[i][0], queue[i][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
}
int jt;
for (jt=0; jt<it; jt+=3)
{
glDrawArrays(GL_LINE_LOOP, jt, 3);
}
free(normals);
free(vertices);
}
else
{
REAL* vertices=(REAL*)malloc(sizeof(REAL)*3*(index_queue+1));
assert(vertices);
REAL* normals=(REAL*)malloc(sizeof(REAL)*3*(index_queue+1));
assert(normals);
/* Enable needed and disable unneeded arrays */
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
backend->tmeshvert(v[0], v[1], retPoint, retNormal);
/* Store triangle fan center vertex */
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
if (isIncreasing)
{
for(i=0; i<index_queue; i++)
{
backend->tmeshvert(queue[i][0], queue[i][1], retPoint, retNormal);
/* Store calculated vertex */
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
}
else
{
for(i=index_queue-1; i>=0; i--)
{
backend->tmeshvert(queue[i][0], queue[i][1], retPoint, retNormal);
/* Store calculated vertex */
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
}
glDrawArrays(GL_TRIANGLE_FAN, 0, it);
free(normals);
free(vertices);
}
backend->endtfan();
/* Disable or re-enable arrays */
if (vertex_enabled)
{
/* Re-enable vertex array */
glEnableClientState(GL_VERTEX_ARRAY);
}
else
{
glDisableClientState(GL_VERTEX_ARRAY);
}
if (texcoord_enabled)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
else
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if (normal_enabled)
{
glEnableClientState(GL_NORMAL_ARRAY);
}
else
{
glDisableClientState(GL_NORMAL_ARRAY);
}
if (color_enabled)
{
glEnableClientState(GL_COLOR_ARRAY);
}
else
{
glDisableClientState(GL_COLOR_ARRAY);
}
}
void reflexChain::processNewVertex(Real v[2], Backend* backend)
{
Int i, j, k;
Int isReflex;
REAL retPoint[4];
REAL retNormal[3];
int it=0;
GLboolean texcoord_enabled;
GLboolean normal_enabled;
GLboolean vertex_enabled;
GLboolean color_enabled;
/* Store status of enabled arrays */
texcoord_enabled=GL_FALSE; /* glIsEnabled(GL_TEXTURE_COORD_ARRAY); */
normal_enabled=GL_FALSE; /* glIsEnabled(GL_NORMAL_ARRAY); */
vertex_enabled=GL_FALSE; /* glIsEnabled(GL_VERTEX_ARRAY); */
color_enabled=GL_FALSE; /* glIsEnabled(GL_COLOR_ARRAY); */
/* TrimVertex trimVert; */
/* if there are at most one vertex in the queue, then simply insert */
if (index_queue<=1)
{
insert(v);
return;
}
/* there are at least two vertices in the queue */
j=index_queue-1;
for(i=j; i>=1; i--)
{
if (isIncreasing)
{
isReflex=(area(queue[i-1], queue[i], v)<=0.0f);
}
else /* decreasing */
{
isReflex=(area(v, queue[i], queue[i-1])<=0.0f);
}
if (isReflex)
{
break;
}
}
/*
* if i<j then vertices: i+1--j are convex
* output triangle fan:
* v, and queue[i], i+1, ..., j
*/
if (i<j)
{
backend->bgntfan();
if (backend->get_output_style()==N_MESHLINE)
{
REAL* vertices=(REAL*)malloc(sizeof(REAL)*3*(index_queue+1)*3);
assert(vertices);
REAL* normals=(REAL*)malloc(sizeof(REAL)*3*(index_queue+1)*3);
assert(normals);
int jt;
/* Enable needed and disable unneeded arrays */
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
backend->tmeshvert(v[0], v[1], retPoint, retNormal);
/* Store triangle fan center vertex */
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
if (isIncreasing)
{
for(k=i; k<=j; k++)
{
if (it%3==0)
{
/* Store triangle fan center vertex */
backend->tmeshvert(v[0], v[1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
/* Store previous vertex */
backend->tmeshvert(queue[k-1][0], queue[k-1][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
backend->tmeshvert(queue[k][0], queue[k][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
}
else
{
for(k=j; k>=i; k--)
{
if (it%3==0)
{
/* Store triangle fan center vertex */
backend->tmeshvert(v[0], v[1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
/* Store previous vertex */
backend->tmeshvert(queue[k+1][0], queue[k+1][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
backend->tmeshvert(queue[k][0], queue[k][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
}
for (jt=0; jt<it; jt+=3)
{
glDrawArrays(GL_LINE_LOOP, jt, 3);
}
/* free the arrays */
free(normals);
free(vertices);
}
else
{
REAL* vertices=(REAL*)malloc(sizeof(REAL)*3*(index_queue+1));
assert(vertices);
REAL* normals=(REAL*)malloc(sizeof(REAL)*3*(index_queue+1));
assert(normals);
/* Enable needed and disable unneeded arrays */
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
backend->tmeshvert(v[0], v[1], retPoint, retNormal);
/* Store triangle fan center vertex */
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
if (isIncreasing)
{
for(k=i; k<=j; k++)
{
backend->tmeshvert(queue[k][0], queue[k][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
}
else
{
for(k=j; k>=i; k--)
{
backend->tmeshvert(queue[k][0], queue[k][1], retPoint, retNormal);
vertices[it*3+0]=retPoint[0];
vertices[it*3+1]=retPoint[1];
vertices[it*3+2]=retPoint[2];
normals[it*3+0]=retNormal[0];
normals[it*3+1]=retNormal[1];
normals[it*3+2]=retNormal[2];
it++;
}
}
glDrawArrays(GL_TRIANGLE_FAN, 0, it);
/* free the arrays */
free(normals);
free(vertices);
}
backend->endtfan();
/* Disable or re-enable arrays */
if (vertex_enabled)
{
/* Re-enable vertex array */
glEnableClientState(GL_VERTEX_ARRAY);
}
else
{
glDisableClientState(GL_VERTEX_ARRAY);
}
if (texcoord_enabled)
{
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
else
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if (normal_enabled)
{
glEnableClientState(GL_NORMAL_ARRAY);
}
else
{
glDisableClientState(GL_NORMAL_ARRAY);
}
if (color_enabled)
{
glEnableClientState(GL_COLOR_ARRAY);
}
else
{
glDisableClientState(GL_COLOR_ARRAY);
}
}
/* delete vertices i+1--j from the queue */
index_queue=i+1;
/* finally insert v at the end of the queue */
insert(v);
}
void monoTriangulationRec(Real* topVertex, Real* botVertex,
vertexArray* inc_chain, Int inc_current,
vertexArray* dec_chain, Int dec_current,
Backend* backend)
{
assert( inc_chain != NULL && dec_chain != NULL);
assert( ! (inc_current>=inc_chain->getNumElements() &&
dec_current>=dec_chain->getNumElements()));
Int inc_nVertices;
Int dec_nVertices;
Real** inc_array ;
Real** dec_array ;
Int i;
assert( ! ( (inc_chain==NULL) && (dec_chain==NULL)));
if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/
{
dec_array = dec_chain->getArray();
dec_nVertices = dec_chain->getNumElements();
reflexChain rChain(20,0);
/*put the top vertex into the reflex chain*/
rChain.processNewVertex(topVertex, backend);
/*process all the vertices on the dec_chain*/
for(i=dec_current; i<dec_nVertices; i++){
rChain.processNewVertex(dec_array[i], backend);
}
/*process the bottom vertex*/
rChain.processNewVertex(botVertex, backend);
}
else if(dec_current>= dec_chain->getNumElements()) /*no more vertices on dec_chain*/
{
inc_array = inc_chain->getArray();
inc_nVertices= inc_chain->getNumElements();
reflexChain rChain(20,1);
/*put the top vertex into the reflex chain*/
rChain.processNewVertex(topVertex, backend);
/*process all the vertices on the inc_chain*/
for(i=inc_current; i<inc_nVertices; i++){
rChain.processNewVertex(inc_array[i], backend);
}
/*process the bottom vertex*/
rChain.processNewVertex(botVertex, backend);
}
else /*neither chain is empty*/
{
inc_array = inc_chain -> getArray();
dec_array = dec_chain -> getArray();
inc_nVertices= inc_chain->getNumElements();
dec_nVertices= dec_chain->getNumElements();
/*if top of inc_chain is 'lower' than top of dec_chain, process all the
*vertices on the dec_chain which are higher than top of inc_chain
*/
if(compV2InY(inc_array[inc_current], dec_array[dec_current]) <= 0)
{
reflexChain rChain(20, 0);
rChain.processNewVertex(topVertex, backend);
for(i=dec_current; i<dec_nVertices; i++)
{
if(compV2InY(inc_array[inc_current], dec_array[i]) <= 0)
rChain.processNewVertex(dec_array[i], backend);
else
break;
}
rChain.outputFan(inc_array[inc_current], backend);
monoTriangulationRec(dec_array[i-1], botVertex,
inc_chain, inc_current,
dec_chain, i,
backend);
}
else /*compV2InY(inc_array[inc_current], dec_array[dec_current]) > 0*/
{
reflexChain rChain(20, 1);
rChain.processNewVertex(topVertex, backend);
for(i=inc_current; i<inc_nVertices; i++)
{
if(compV2InY(inc_array[i], dec_array[dec_current]) >0)
rChain.processNewVertex(inc_array[i], backend);
else
break;
}
rChain.outputFan(dec_array[dec_current], backend);
monoTriangulationRec(inc_array[i-1], botVertex,
inc_chain, i,
dec_chain, dec_current,
backend);
}
}/*end case neither is empty*/
}
void monoTriangulationFunBackend(Arc_ptr loop, Int (*compFun)(Real*, Real*), Backend* backend)
{
Int i;
/*find the top vertex, bottom vertex, inccreasing chain, and decreasing chain,
*then call monoTriangulationRec
*/
Arc_ptr tempV;
Arc_ptr topV;
Arc_ptr botV;
topV = botV = loop;
for(tempV = loop->next; tempV != loop; tempV = tempV->next)
{
if(compFun(topV->tail(), tempV->tail())<0) {
topV = tempV;
}
if(compFun(botV->tail(), tempV->tail())>0) {
botV = tempV;
}
}
/*creat increase and decrease chains*/
vertexArray inc_chain(20); /*this is a dynamic array*/
for(i=1; i<=topV->pwlArc->npts-2; i++) { /*the first vertex is the top vertex which doesn't belong to inc_chain*/
inc_chain.appendVertex(topV->pwlArc->pts[i].param);
}
for(tempV = topV->next; tempV != botV; tempV = tempV->next)
{
for(i=0; i<=tempV->pwlArc->npts-2; i++){
inc_chain.appendVertex(tempV->pwlArc->pts[i].param);
}
}
vertexArray dec_chain(20);
for(tempV = topV->prev; tempV != botV; tempV = tempV->prev)
{
for(i=tempV->pwlArc->npts-2; i>=0; i--){
dec_chain.appendVertex(tempV->pwlArc->pts[i].param);
}
}
for(i=botV->pwlArc->npts-2; i>=1; i--){
dec_chain.appendVertex(tempV->pwlArc->pts[i].param);
}
monoTriangulationRecFunBackend(topV->tail(), botV->tail(), &inc_chain, 0, &dec_chain, 0, compFun, backend);
}
/*if compFun == compV2InY, top to bottom: V-monotone
*if compFun == compV2InX, right to left: U-monotone
*/
void monoTriangulationRecFunBackend(Real* topVertex, Real* botVertex,
vertexArray* inc_chain, Int inc_current,
vertexArray* dec_chain, Int dec_current,
Int (*compFun)(Real*, Real*),
Backend* backend)
{
assert( inc_chain != NULL && dec_chain != NULL);
assert( ! (inc_current>=inc_chain->getNumElements() &&
dec_current>=dec_chain->getNumElements()));
Int inc_nVertices;
Int dec_nVertices;
Real** inc_array ;
Real** dec_array ;
Int i;
assert( ! ( (inc_chain==NULL) && (dec_chain==NULL)));
if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/
{
dec_array = dec_chain->getArray();
dec_nVertices = dec_chain->getNumElements();
reflexChain rChain(20,0);
/*put the top vertex into the reflex chain*/
rChain.processNewVertex(topVertex, backend);
/*process all the vertices on the dec_chain*/
for(i=dec_current; i<dec_nVertices; i++){
rChain.processNewVertex(dec_array[i], backend);
}
/*process the bottom vertex*/
rChain.processNewVertex(botVertex, backend);
}
else if(dec_current>= dec_chain->getNumElements()) /*no more vertices on dec_chain*/
{
inc_array = inc_chain->getArray();
inc_nVertices= inc_chain->getNumElements();
reflexChain rChain(20,1);
/*put the top vertex into the reflex chain*/
rChain.processNewVertex(topVertex, backend);
/*process all the vertices on the inc_chain*/
for(i=inc_current; i<inc_nVertices; i++){
rChain.processNewVertex(inc_array[i], backend);
}
/*process the bottom vertex*/
rChain.processNewVertex(botVertex, backend);
}
else /*neither chain is empty*/
{
inc_array = inc_chain -> getArray();
dec_array = dec_chain -> getArray();
inc_nVertices= inc_chain->getNumElements();
dec_nVertices= dec_chain->getNumElements();
/*if top of inc_chain is 'lower' than top of dec_chain, process all the
*vertices on the dec_chain which are higher than top of inc_chain
*/
if(compFun(inc_array[inc_current], dec_array[dec_current]) <= 0)
{
reflexChain rChain(20, 0);
rChain.processNewVertex(topVertex, backend);
for(i=dec_current; i<dec_nVertices; i++)
{
if(compFun(inc_array[inc_current], dec_array[i]) <= 0)
rChain.processNewVertex(dec_array[i], backend);
else
break;
}
rChain.outputFan(inc_array[inc_current], backend);
monoTriangulationRecFunBackend(dec_array[i-1], botVertex,
inc_chain, inc_current,
dec_chain, i,
compFun,
backend);
}
else /*compFun(inc_array[inc_current], dec_array[dec_current]) > 0*/
{
reflexChain rChain(20, 1);
rChain.processNewVertex(topVertex, backend);
for(i=inc_current; i<inc_nVertices; i++)
{
if(compFun(inc_array[i], dec_array[dec_current]) >0)
rChain.processNewVertex(inc_array[i], backend);
else
break;
}
rChain.outputFan(dec_array[dec_current], backend);
monoTriangulationRecFunBackend(inc_array[i-1], botVertex,
inc_chain, i,
dec_chain, dec_current,
compFun,
backend);
}
}/*end case neither is empty*/
}

View File

@@ -0,0 +1,254 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* monotonizer.c++
*
*/
#include "glimports.h"
#include "mystdio.h"
#include "myassert.h"
#include "arc.h"
#include "arctess.h"
#include "bezierarc.h"
#include "bin.h"
#include "mapdesc.h"
#include "nurbsconsts.h"
#include "subdivider.h"
/*-----------------------------------------------------------------------------
* Subdivider::decompose - break all curves into monotone arcs
*-----------------------------------------------------------------------------
*/
int
Subdivider::decompose( Bin& bin, REAL geo_stepsize )
{
Arc_ptr jarc;
for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
if( ! jarc->isTessellated() ) {
/* points have not been transformed, therefore they may be either
homogeneous or inhomogeneous */
tessellate( jarc, geo_stepsize );
if( jarc->isDisconnected() || jarc->next->isDisconnected() )
return 1;
}
}
for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
monotonize( jarc, bin );
}
return 0;
}
void
Subdivider::tessellate( Arc_ptr jarc, REAL geo_stepsize )
{
BezierArc *b = jarc->bezierArc;
Mapdesc *mapdesc = b->mapdesc;
if( mapdesc->isRational() ) {
REAL max = mapdesc->calcVelocityRational( b->cpts, b->stride, b->order );
REAL arc_stepsize = (max > 1.0f) ? (1.0f/max) : 1.0f;
if( jarc->bezierArc->order != 2 )
arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 1 );
else {
arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 1 );
}
} else {
REAL max = mapdesc->calcVelocityNonrational( b->cpts, b->stride, b->order );
REAL arc_stepsize = (max > 1.0f) ? (1.0f/max) : 1.0f;
if( jarc->bezierArc->order != 2 )
arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 0 );
else {
arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 0 );
}
}
}
/*-------------------------------------------------------------------------
* Subdivider::monotonize - break up a jordan arc into s,t-monotone
* components. This code will remove degenerate segments, including
* arcs of only a single point.
*-------------------------------------------------------------------------
*/
void
Subdivider::monotonize( Arc_ptr jarc, Bin& bin )
{
TrimVertex *firstvert = jarc->pwlArc->pts;
TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1);
long uid = jarc->nuid;
arc_side side = jarc->getside();
dir sdir = none;
dir tdir = none;
int degenerate = 1;
int nudegenerate;
int change;
TrimVertex *vert;
for( vert = firstvert; vert != lastvert; vert++ ) {
nudegenerate = 1;
change = 0;
/* check change relative to s axis, clear degenerate bit if needed */
REAL sdiff = vert[1].param[0] - vert[0].param[0];
if( sdiff == 0 ) {
if( sdir != same ) {
sdir = same;
change = 1;
}
} else if( sdiff < 0.0 ) {
if( sdir != down ) {
sdir = down;
change = 1;
}
nudegenerate = 0;
} else {
if( sdir != up ) {
sdir = up;
change = 1;
}
nudegenerate = 0;
}
/* check change relative to t axis, clear degenerate bit if needed */
REAL tdiff = vert[1].param[1] - vert[0].param[1];
if( tdiff == 0 ) {
if( tdir != same ) {
tdir = same;
change = 1;
}
} else if( tdiff < 0.0 ) {
if( tdir != down ) {
tdir = down;
change = 1;
}
nudegenerate = 0;
} else {
if( tdir != up ) {
tdir = up;
change = 1;
}
nudegenerate = 0;
}
if( change ) {
if( ! degenerate ) {
/* make last segment into separate pwl curve */
jarc->pwlArc->npts = (int)(vert - firstvert + 1);
jarc = (new(arcpool) Arc( side, uid ))->append( jarc );
jarc->pwlArc = new(pwlarcpool) PwlArc();
bin.addarc( jarc );
}
firstvert = jarc->pwlArc->pts = vert;
degenerate = nudegenerate;
}
}
jarc->pwlArc->npts = (int)(vert - firstvert + 1);
if( degenerate ) {
/* remove jarc from circularly linked list */
jarc->prev->next = jarc->next;
jarc->next->prev = jarc->prev;
assert( jarc->prev->check( ) != 0 );
assert( jarc->next->check( ) != 0 );
/* remove jarc from bin */
bin.remove_this_arc( jarc );
jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0;
jarc->deleteMe( arcpool );
}
}
/*-------------------------------------------------------------------------
* Subdivider::isMonotone - return true if arc is monotone AND non-degenerate
*-------------------------------------------------------------------------
*/
int
Subdivider::isMonotone( Arc_ptr jarc )
{
TrimVertex *firstvert = jarc->pwlArc->pts;
TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1);
if( firstvert == lastvert ) return 1;
TrimVertex *vert = firstvert;
enum dir sdir;
enum dir tdir;
REAL diff = vert[1].param[0] - vert[0].param[0];
if( diff == 0.0 )
sdir = same;
else if( diff < 0.0 )
sdir = down;
else
sdir = up;
diff = vert[1].param[1] - vert[0].param[1];
if( diff == 0.0 )
tdir = same;
else if( diff < 0.0 )
tdir = down;
else
tdir = up;
if( (sdir == same) && (tdir == same) ) return 0;
for( ++vert ; vert != lastvert; vert++ ) {
diff = vert[1].param[0] - vert[0].param[0];
if( diff == 0.0 ) {
if( sdir != same ) return 0;
} else if( diff < 0.0 ) {
if( sdir != down ) return 0;
} else {
if( sdir != up ) return 0;
}
diff = vert[1].param[1] - vert[0].param[1];
if( diff == 0.0 ) {
if( tdir != same ) return 0;
} else if( diff < 0.0 ) {
if( tdir != down ) return 0;
} else {
if( tdir != up ) return 0;
}
}
return 1;
}

View File

@@ -0,0 +1,64 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* monotonizer.h
*
*/
#ifndef __glumonotonizer_h_
#define __glumonotonizer_h_
#include "mysetjmp.h"
#include "types.h"
class Arc;
class ArcTessellator;
class Pool;
class Bin;
class PwlArcPool;
class Mapdesc;
class Monotonizer {
ArcTessellator& arctessellator;
Pool& arcpool;
Pool& pwlarcpool;
jmp_buf& nurbsJmpBuf;
enum dir { down, same, up, none };
void tessellate( Arc *, REAL );
void monotonize( Arc *, Bin & );
int isMonotone( Arc * );
public:
Monotonizer( ArcTessellator& at, Pool& ap, Pool& p, jmp_buf& j )
: arctessellator(at), arcpool(ap), pwlarcpool(p), nurbsJmpBuf(j) {}
int decompose( Bin &, REAL );
};
#endif /* __glumonotonizer_h_ */

View File

@@ -0,0 +1,41 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* myassert.h
*
*/
#ifndef __glumyassert_h_
#define __glumyassert_h_
#define assert(EX) ((void)0)
#endif /* __glumyassert_h_ */

View File

@@ -0,0 +1,67 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/
/*
*/
#include "mymath.h"
#ifdef NEEDCEILF
float ceilf( float x )
{
if( x < 0 ) {
float nx = -x;
int ix = (int) nx;
return (float) -ix;
} else {
int ix = (int) x;
if( x == (float) ix ) return x;
return (float) (ix+1);
}
}
float floorf( float x )
{
if( x < 0 ) {
float nx = -x;
int ix = (int) nx;
if( nx == (float) ix ) return x;
return (float) -(ix+1);
} else {
int ix = (int) x;
return (float) ix;
}
}
#endif

View File

@@ -0,0 +1,67 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
*
* OpenGL ES 1.0 CM port of GLU by Mike Gorchak <mike@malva.ua>
*/
#ifndef __glumymath_h_
#define __glumymath_h_
#ifdef GLBUILD
#define sqrtf gl_fsqrt
#endif
#if defined(GLBUILD)
#define M_SQRT2 1.41421356237309504880
#define ceilf myceilf
#define floorf myfloorf
#define sqrtf sqrt
extern "C" double sqrt(double);
extern "C" float ceilf(float);
extern "C" float floorf(float);
#define NEEDCEILF
#endif
#ifdef LIBRARYBUILD
#include <math.h>
#endif
#if !defined sqrtf
#define sqrtf(x) ((float)sqrt(x))
#endif
#if !defined ceilf
#define ceilf(x) ((float)ceil(x))
#endif
#if !defined floorf
#define floorf(x) ((float)floor(x))
#endif
#endif /* __glumymath_h_ */

View File

@@ -0,0 +1,74 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* mysetjmp.h
*
*/
#ifndef __glumysetjmp_h_
#define __glumysetjmp_h_
#ifdef GLBUILD
#define setjmp gl_setjmp
#define longjmp gl_longjmp
#endif
#if defined(LIBRARYBUILD) || defined(GLBUILD)
#include <setjmp.h>
#include <stdlib.h>
struct JumpBuffer
{
jmp_buf buf;
};
inline JumpBuffer* newJumpbuffer(void)
{
return (JumpBuffer*)malloc(sizeof(JumpBuffer));
}
inline void deleteJumpbuffer(JumpBuffer* jb)
{
free((void*)jb);
}
inline void mylongjmp(JumpBuffer* j, int code)
{
::longjmp(j->buf, code);
}
inline int mysetjmp(JumpBuffer* j)
{
return setjmp(j->buf);
}
#endif /* LIBRARYBUILD || GLBUILD */
#endif /* __glumysetjmp_h_ */

View File

@@ -0,0 +1,50 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* mystring.h
*
*/
#ifndef __glumystring_h_
#define __glumystring_h_
#ifdef GLBUILD
#define memcpy(a,b,c) bcopy(b,a,c)
#define memset(a,b,c) bzero(a,c)
extern "C" void bcopy(const void*, void*, int);
extern "C" void bzero(void*, int);
#endif
#ifdef LIBRARYBUILD
#include <string.h>
#endif
#endif /* __glumystring_h_ */

View File

@@ -0,0 +1,119 @@
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/*
* nurbsconsts.h
*
*/
#ifndef __glunurbsconsts_h_
#define __glunurbsconsts_h_
/* NURBS Properties - one set per map,
each takes a single INREAL arg */
#define N_SAMPLING_TOLERANCE 1
#define N_S_RATE 6
#define N_T_RATE 7
#define N_CLAMPFACTOR 13
#define N_NOCLAMPING 0.0
#define N_MINSAVINGS 14
#define N_NOSAVINGSSUBDIVISION 0.0
/* NURBS Properties - one set per map,
each takes an enumerated value */
#define N_CULLING 2
#define N_NOCULLING 0.0
#define N_CULLINGON 1.0
#define N_SAMPLINGMETHOD 10
#define N_NOSAMPLING 0.0
#define N_FIXEDRATE 3.0
#define N_DOMAINDISTANCE 2.0
#define N_PARAMETRICDISTANCE 5.0
#define N_PATHLENGTH 6.0
#define N_SURFACEAREA 7.0
#define N_OBJECTSPACE_PARA 8.0
#define N_OBJECTSPACE_PATH 9.0
#define N_BBOX_SUBDIVIDING 17
#define N_NOBBOXSUBDIVISION 0.0
#define N_BBOXTIGHT 1.0
#define N_BBOXROUND 2.0
/* NURBS Rendering Properties - one set per renderer
each takes an enumerated value */
#define N_DISPLAY 3
#define N_FILL 1.0
#define N_OUTLINE_POLY 2.0
#define N_OUTLINE_TRI 3.0
#define N_OUTLINE_QUAD 4.0
#define N_OUTLINE_PATCH 5.0
#define N_OUTLINE_PARAM 6.0
#define N_OUTLINE_PARAM_S 7.0
#define N_OUTLINE_PARAM_ST 8.0
#define N_OUTLINE_SUBDIV 9.0
#define N_OUTLINE_SUBDIV_S 10.0
#define N_OUTLINE_SUBDIV_ST 11.0
#define N_ISOLINE_S 12.0
#define N_ERRORCHECKING 4
#define N_NOMSG 0.0
#define N_MSG 1.0
/* GL 4.0 propeties not defined above */
#ifndef N_PIXEL_TOLERANCE
#define N_PIXEL_TOLERANCE N_SAMPLING_TOLERANCE
#define N_ERROR_TOLERANCE 20
#define N_SUBDIVISIONS 5
#define N_TILES 8
#define N_TMP1 9
#define N_TMP2 N_SAMPLINGMETHOD
#define N_TMP3 11
#define N_TMP4 12
#define N_TMP5 N_CLAMPFACTOR
#define N_TMP6 N_MINSAVINGS
#define N_S_STEPS N_S_RATE
#define N_T_STEPS N_T_RATE
#endif
/* NURBS Rendering Properties - one set per map,
each takes an INREAL matrix argument */
#define N_CULLINGMATRIX 1
#define N_SAMPLINGMATRIX 2
#define N_BBOXMATRIX 3
/* NURBS Rendering Properties - one set per map,
each takes an INREAL vector argument */
#define N_BBOXSIZE 4
/* type argument for trimming curves */
#ifndef N_P2D
#define N_P2D 0x8
#define N_P2DR 0xd
#endif
#endif /* __glunurbsconsts_h_ */

View File

@@ -0,0 +1,532 @@
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
**
** http://oss.sgi.com/projects/FreeB
**
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
**
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
**
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
*/
/*
* nurbsinterfac.c++
*
*/
#include "glimports.h"
#include "mystdio.h"
#include "nurbsconsts.h"
#include "nurbstess.h"
#include "bufpool.h"
#include "quilt.h"
#include "displaylist.h"
#include "knotvector.h"
#include "mapdesc.h"
#define THREAD(work, arg, cleanup) \
if (dl) \
{ \
arg->save=1; \
dl->append((PFVS)&NurbsTessellator::work, (void*) arg, (PFVS)&NurbsTessellator::cleanup); \
} \
else \
{ \
arg->save=0; \
work(arg); \
}
#define THREAD2(work) \
if (dl) \
{ \
dl->append((PFVS)&NurbsTessellator::work, 0, 0 ); \
} \
else \
{ \
work(); \
}
NurbsTessellator::NurbsTessellator(BasicCurveEvaluator& c, BasicSurfaceEvaluator& e):
maplist(backend), backend(c, e), subdivider(renderhints, backend),
o_pwlcurvePool(sizeof(O_pwlcurve), 32, "o_pwlcurvePool"),
o_nurbscurvePool(sizeof(O_nurbscurve), 32, "o_nurbscurvePool"),
o_curvePool(sizeof(O_curve), 32, "o_curvePool"),
o_trimPool(sizeof(O_trim), 32, "o_trimPool"),
o_surfacePool(sizeof(O_surface), 1, "o_surfacePool"),
o_nurbssurfacePool(sizeof(O_nurbssurface), 4, "o_nurbssurfacePool"),
propertyPool(sizeof(Property), 32, "propertyPool"),
quiltPool(sizeof(Quilt), 32, "quiltPool")
{
dl=0;
inSurface=0;
inCurve=0;
inTrim=0;
playBack=0;
jumpbuffer=newJumpbuffer();
subdivider.setJumpbuffer(jumpbuffer);
}
NurbsTessellator::~NurbsTessellator(void)
{
if (inTrim)
{
do_nurbserror(12);
endtrim();
}
if (inSurface)
{
*nextNurbssurface=0;
do_freeall();
}
if (jumpbuffer)
{
deleteJumpbuffer(jumpbuffer);
jumpbuffer=0;
}
}
/*-----------------------------------------------------------------------------
* bgnsurface - allocate and initialize an o_surface structure
*
* Client: GL user
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::bgnsurface(long nuid)
{
O_surface* o_surface=new(o_surfacePool)O_surface;
o_surface->nuid=nuid;
THREAD(do_bgnsurface, o_surface, do_freebgnsurface);
}
/*-----------------------------------------------------------------------------
* bgncurve - allocate an initialize an o_curve structure
*
* Client: GL user
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::bgncurve(long nuid)
{
O_curve* o_curve=new(o_curvePool)O_curve;
o_curve->nuid=nuid;
THREAD(do_bgncurve, o_curve, do_freebgncurve);
}
/*-----------------------------------------------------------------------------
* endcurve -
*
* Client:
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::endcurve(void)
{
THREAD2(do_endcurve);
}
/*-----------------------------------------------------------------------------
* endsurface - user level end of surface call
*
* Client: GL user
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::endsurface(void)
{
THREAD2(do_endsurface);
}
/*-----------------------------------------------------------------------------
* bgntrim - allocate and initialize a new trim loop structure (o_trim )
*
* Client: GL user
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::bgntrim(void)
{
O_trim* o_trim=new(o_trimPool)O_trim;
THREAD(do_bgntrim, o_trim, do_freebgntrim);
}
/*-----------------------------------------------------------------------------
* endtrim -
*
* Client: GL user
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::endtrim(void)
{
THREAD2(do_endtrim);
}
/*-----------------------------------------------------------------------------
* pwlcurve -
*
* count - number of points on curve
* array - array of points on curve
* byte_stride - distance between points in bytes
* type - valid data flag
*
* Client: Gl user
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::pwlcurve(long count, INREAL array[], long byte_stride, long type)
{
Mapdesc* mapdesc=maplist.locate(type);
if (mapdesc==0)
{
do_nurbserror(35);
isDataValid=0;
return;
}
if ((type!=N_P2D) && (type!=N_P2DR))
{
do_nurbserror(22);
isDataValid=0;
return;
}
if (count<0)
{
do_nurbserror(33);
isDataValid=0;
return;
}
if (byte_stride<0)
{
do_nurbserror(34);
isDataValid=0;
return;
}
O_pwlcurve* o_pwlcurve=new(o_pwlcurvePool)O_pwlcurve(type, count, array, byte_stride, extTrimVertexPool.get((int)count));
THREAD(do_pwlcurve, o_pwlcurve, do_freepwlcurve);
}
/*-----------------------------------------------------------------------------
* nurbscurve -
*
* Client: GL user
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::nurbscurve(long nknots, /* number of p knots */
INREAL knot[], /* nondecreasing knot values in p */
long byte_stride, /* distance in bytes between control points */
INREAL ctlarray[], /* pointer to first control point */
long order, /* order of spline */
long type) /* description of range space */
{
Mapdesc* mapdesc=maplist.locate(type);
if (mapdesc==0)
{
do_nurbserror(35);
isDataValid=0;
return;
}
if (ctlarray==0)
{
do_nurbserror(36);
isDataValid=0;
return;
}
if (byte_stride<0)
{
do_nurbserror(34);
isDataValid=0;
return;
}
Knotvector knots;
knots.init(nknots, byte_stride, order, knot);
if (do_check_knots(&knots, "curve"))
{
return;
}
O_nurbscurve* o_nurbscurve=new(o_nurbscurvePool)O_nurbscurve(type);
o_nurbscurve->bezier_curves=new(quiltPool)Quilt(mapdesc);
o_nurbscurve->bezier_curves->toBezier(knots,ctlarray, mapdesc->getNcoords());
THREAD(do_nurbscurve, o_nurbscurve, do_freenurbscurve);
}
/*-----------------------------------------------------------------------------
* nurbssurface -
*
* Client: User routine
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::nurbssurface(long sknot_count, /* number of s knots */
INREAL sknot[], /* nondecreasing knot values in s */
long tknot_count, /* number of t knots */
INREAL tknot[], /* nondecreasing knot values in t */
long s_byte_stride, /* s step size in memory bytes */
long t_byte_stride, /* t step size in memory bytes */
INREAL ctlarray[], /* pointer to first control point */
long sorder, /* order of the spline in s parameter */
long torder, /* order of the spline in t parameter */
long type) /* description of range space */
{
Mapdesc* mapdesc=maplist.locate(type);
if (mapdesc==0)
{
do_nurbserror(35);
isDataValid=0;
return;
}
if (s_byte_stride<0)
{
do_nurbserror(34);
isDataValid=0;
return;
}
if (t_byte_stride<0)
{
do_nurbserror(34);
isDataValid=0;
return;
}
Knotvector sknotvector, tknotvector;
sknotvector.init(sknot_count, s_byte_stride, sorder, sknot);
if (do_check_knots(&sknotvector, "surface"))
{
return;
}
tknotvector.init(tknot_count, t_byte_stride, torder, tknot);
if (do_check_knots(&tknotvector, "surface"))
{
return;
}
O_nurbssurface* o_nurbssurface=new(o_nurbssurfacePool)O_nurbssurface(type);
o_nurbssurface->bezier_patches=new(quiltPool)Quilt(mapdesc);
o_nurbssurface->bezier_patches->toBezier(sknotvector, tknotvector, ctlarray, mapdesc->getNcoords());
THREAD(do_nurbssurface, o_nurbssurface, do_freenurbssurface);
}
/*-----------------------------------------------------------------------------
* setnurbsproperty -
*
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::setnurbsproperty( long tag, INREAL value )
{
if (!renderhints.isProperty(tag))
{
do_nurbserror(26);
}
else
{
Property* prop=new(propertyPool) Property(tag, value);
THREAD(do_setnurbsproperty, prop, do_freenurbsproperty);
}
}
/*-----------------------------------------------------------------------------
* setnurbsproperty -
*
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::setnurbsproperty(long type, long tag, INREAL value)
{
Mapdesc* mapdesc=maplist.locate(type);
if (mapdesc==0)
{
do_nurbserror(35);
return;
}
if (!mapdesc->isProperty(tag))
{
do_nurbserror(26);
return;
}
Property* prop=new(propertyPool)Property(type, tag, value);
THREAD(do_setnurbsproperty2, prop, do_freenurbsproperty);
}
/*-----------------------------------------------------------------------------
* getnurbsproperty -
*
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::getnurbsproperty(long tag, INREAL* value)
{
if (renderhints.isProperty(tag))
{
*value=renderhints.getProperty(tag);
}
else
{
do_nurbserror(26);
}
}
/*-----------------------------------------------------------------------------
* getnurbsproperty -
*
*-----------------------------------------------------------------------------
*/
void NurbsTessellator::getnurbsproperty(long type, long tag, INREAL* value)
{
Mapdesc* mapdesc=maplist.locate(type);
if (mapdesc==0)
{
do_nurbserror(35);
}
if (mapdesc->isProperty(tag))
{
*value=mapdesc->getProperty(tag);
}
else
{
do_nurbserror(26);
}
}
/*--------------------------------------------------------------------------
* setnurbsproperty - accept a user supplied matrix as culling or sampling mat
*--------------------------------------------------------------------------
*/
void NurbsTessellator::setnurbsproperty(long type, long purpose, INREAL* mat)
{
// XXX - cannot be put in display list
Mapdesc* mapdesc=maplist.locate(type);
if (mapdesc==0)
{
do_nurbserror(35);
isDataValid=0;
}
else
{
if (purpose==N_BBOXSIZE)
{
mapdesc->setBboxsize(mat);
}
}
}
/*--------------------------------------------------------------------------
* setnurbsproperty - accept a user supplied matrix as culling or sampling mat
*--------------------------------------------------------------------------
*/
void NurbsTessellator::setnurbsproperty(long type, long purpose, INREAL* mat, long rstride, long cstride)
{
// XXX - cannot be put in display list
Mapdesc* mapdesc=maplist.locate(type);
if (mapdesc==0)
{
do_nurbserror(35);
isDataValid=0;
}
else
{
if (purpose==N_CULLINGMATRIX)
{
mapdesc->setCmat(mat, rstride, cstride);
}
else
{
if (purpose==N_SAMPLINGMATRIX)
{
mapdesc->setSmat(mat, rstride, cstride);
}
else
{
if (purpose==N_BBOXMATRIX)
{
mapdesc->setBmat(mat, rstride, cstride);
}
}
}
}
}
void NurbsTessellator::redefineMaps(void)
{
maplist.initialize();
}
void NurbsTessellator::defineMap(long type, long rational, long ncoords)
{
maplist.define(type, (int)rational, (int)ncoords);
}
void NurbsTessellator::discardRecording(void* _dl)
{
delete (DisplayList*) _dl;
}
void* NurbsTessellator::beginRecording(void)
{
dl=new DisplayList(this);
return (void*)dl;
}
void NurbsTessellator::endRecording(void)
{
dl->endList();
dl=0;
}
void NurbsTessellator::playRecording(void* _dl)
{
playBack=1;
bgnrender();
((DisplayList*)_dl)->play();
endrender();
playBack=0;
}

Some files were not shown because too many files have changed in this diff Show More