From 006acbb9463af33a8b45aa0b3a298604eba72d82 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 21 Jun 2008 02:33:51 +0000 Subject: 2nd big refactoring. Goals are orthogonal components for: - OS Windowing system - NEWT, X11, Windows, MacOsX - GL Windowing GLUE - EGL, GLX, WGL, CGL - GL profiles - core and util packages - generate all Java components from any platform All above goals are achieved. TODO: - Native compilation fix and test - Check/Fix Win32, MacOSX and the mobile devices - .. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1665 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../sun/opengl/impl/glu/gl2/nurbs/GL2Backend.java | 49 ++ .../impl/glu/gl2/nurbs/GL2CurveEvaluator.java | 205 +++++ .../impl/glu/gl2/nurbs/GL2SurfaceEvaluator.java | 217 ++++++ .../opengl/impl/glu/gl2/nurbs/GLUgl2nurbsImpl.java | 862 +++++++++++++++++++++ 4 files changed, 1333 insertions(+) create mode 100755 src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GL2Backend.java create mode 100755 src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GL2CurveEvaluator.java create mode 100755 src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GL2SurfaceEvaluator.java create mode 100755 src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GLUgl2nurbsImpl.java (limited to 'src/classes/com/sun/opengl/impl/glu/gl2') diff --git a/src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GL2Backend.java b/src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GL2Backend.java new file mode 100755 index 000000000..d54f1c56f --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GL2Backend.java @@ -0,0 +1,49 @@ +package com.sun.opengl.impl.glu.gl2.nurbs; +import com.sun.opengl.impl.glu.nurbs.*; + +/* + ** 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. + */ + +/** + * Class responsible for rendering + * @author Tomas Hrasky + * + */ +public class GL2Backend extends Backend { + public GL2Backend() { + super(); + curveEvaluator = new GL2CurveEvaluator(); + surfaceEvaluator = new GL2SurfaceEvaluator(); + } +} diff --git a/src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GL2CurveEvaluator.java b/src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GL2CurveEvaluator.java new file mode 100755 index 000000000..5be4f9049 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/glu/gl2/nurbs/GL2CurveEvaluator.java @@ -0,0 +1,205 @@ +package com.sun.opengl.impl.glu.gl2.nurbs; +import com.sun.opengl.impl.glu.nurbs.*; + +/* + ** 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. + */ + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.glu.GLU; +import javax.media.opengl.glu.gl2.GLUgl2; + +/** + * Class rendering curves with OpenGL + * @author Tomáš Hráský + * + */ +class GL2CurveEvaluator implements CurveEvaluator { + + /** + * Output triangles (for callback) or render curve + */ + private boolean output_triangles; + + /** + * OpenGL object + */ + private GL2 gl; + + /** + * Not used + */ + private int vertex_flag; + + /** + * Not used + */ + private int normal_flag; + + /** + * Not used + */ + private int color_flag; + + /** + * Not used + */ + private int texcoord_flag; + + /** + * Number of bezier arc - used for color distinguishing of arcs forming NURBS curve + */ + private int poradi; + + /** + * Makes new Evaluator + */ + public GL2CurveEvaluator() { + gl = GLUgl2.getCurrentGL2(); + } + + /** + * Pushes eval bit + */ + public void bgnmap1f() { + // DONE + if (output_triangles) { + vertex_flag = 0; + normal_flag = 0; + color_flag = 0; + texcoord_flag = 0; + } else { + gl.glPushAttrib(GL2.GL_EVAL_BIT); + } + + } + + /** + * Pops all OpenGL attributes + */ + public void endmap1f() { + // DONE + if (output_triangles) { + + } else { + gl.glPopAttrib(); + } + + } + + /** + * Initializes opengl evaluator + * @param type curve type + * @param ulo lowest u + * @param uhi highest u + * @param stride control point coords + * @param order curve order + * @param ps control points + */ + public void map1f(int type, float ulo, float uhi, int stride, int order, + CArrayOfFloats ps) { + if (output_triangles) { + // TODO code for callback (output_triangles probably indicates callback) + // System.out.println("TODO curveevaluator.map1f-output_triangles"); + } else { + gl.glMap1f(type, ulo, uhi, stride, order, ps.getArray(), ps + .getPointer()); + + // DEBUG - drawing bézier control points + // gl.glColor3d(.5,.5,.5); + // gl.glPointSize(5); + // gl.glBegin(GL2.GL_POINTS); + // float[] ctrlpoints=ps.getArray(); + // for(int i=ps.getPointer();i 0) { + do_nurbserror(6); + endcurve(); + } + inCurve = 1; + currentCurve = o_curve; + + currentCurve.curvetype = CT_NONE; + + if (inTrim) { + if (!nextCurve.equals(o_curve)) { + isCurveModified = 1; + nextCurve = o_curve; + } + } else { + if (!playBack) + bgnrender(); + isDataValid = 1; + } + nextCurve = o_curve.next; + // kind of solution of union + nextPwlcurve = o_curve.o_pwlcurve; + nextNurbscurve = o_curve.o_nurbscurve; + } + + /** + * Begins new surface + * + * @param o_surface + * surface object + */ + public void do_bgnsurface(O_surface o_surface) { + // DONE + if (inSurface > 0) { + do_nurbserror(27); + endsurface(); + } + inSurface = 1; + if (!playBack) + bgnrender(); + + isTrimModified = false; + isDataSurfaceModified = false; + isDataValid = 1; + numTrims = 0; + currentSurface = o_surface; + nextTrim = o_surface.o_trim; + nextNurbssurface = o_surface.o_nurbssurface; + } + + /** + * End a curve + */ + public void endcurve() { + // DONE + thread2("do_endcurve"); + } + + /** + * Ends surface + */ + public void do_endsurface() { + // DONE + if (inTrim) { + do_nurbserror(12); + endtrim(); + } + + if (inSurface <= 0) { + do_nurbserror(13); + return; + } + + inSurface = 0; + + nextNurbssurface = null; + + if (isDataValid <= 0) { + return; + } + + if (nextTrim != null) { + isTrimModified = true; + nextTrim = null; + } + + // TODO errval ?? + if (numTrims > 0) { + // System.out.println("TODO glunurbs.do_endsurface - numtrims > 0"); + } + + subdivider.beginQuilts(new GL2Backend()); + for (O_nurbssurface n = currentSurface.o_nurbssurface; n != null; n = n.next) { + subdivider.addQuilt(n.bezier_patches); + } + subdivider.endQuilts(); + subdivider.drawSurfaces(); + if (!playBack) + endrender(); + + } + + /** + * Ends a curve + */ + public void do_endcurve() { + // DONE + // // System.out.println("do_endcurve"); + if (inCurve <= 0) { + do_nurbserror(7); + return; + } + inCurve = 0; + + nextCurve = null; + + if (currentCurve.curvetype == CT_NURBSCURVE) { + // nextNurbscurve = null; + // currentCurve.o_nurbscurve=null; + } else { + // nextPwlcurve = null; + // currentCurve.o_pwlcurve=null; + } + if (!inTrim) { + if (isDataValid <= 0) { + return; + } + // TODO errval? + if (currentCurve.curvetype == CT_NURBSCURVE) { + subdivider.beginQuilts(new GL2Backend()); + + for (O_nurbscurve n = currentCurve.o_nurbscurve; n != null; n = n.next) + subdivider.addQuilt(n.bezier_curves); + + subdivider.endQuilts(); + subdivider.drawCurves(); + if (!playBack) + endrender(); + } else { + if (!playBack) + endrender(); + do_nurbserror(9); + } + } + + } + + /** + * Method for handling error codes + * + * @param i + * error code + */ + private void do_nurbserror(int i) { + // TODO nurberror + // System.out.println("TODO nurbserror " + i); + } + + /** + * Begin rendering + */ + private void bgnrender() { + // DONE + if (autoloadmode) { + loadGLMatrices(); + } + } + + /** + * Load matrices from OpenGL state machine + */ + private void loadGLMatrices() { + // TODO Auto-generated method stub + // System.out.println("TODO glunurbs.loadGLMatrices"); + } + + /** + * End rendering + */ + private void endrender() { + // DONE + } + + /** + * Make a NURBS curve + * + * @param nknots + * number of knots in knot vector + * @param knot + * knot vector + * @param stride + * number of control points coordinates + * @param ctlarray + * control points + * @param order + * order of the curve + * @param realType + * type of the curve + */ + public void nurbscurve(int nknots, float[] knot, int stride, + float[] ctlarray, int order, int realType) { + // DONE + Mapdesc mapdesc = maplist.locate(realType); + if (mapdesc == null) { + do_nurbserror(35); + isDataValid = 0; + return; + } + if (ctlarray == null) { + do_nurbserror(36); + isDataValid = 0; + return; + } + if (stride < 0) { + do_nurbserror(34); + isDataValid = 0; + return; + } + Knotvector knots = new Knotvector(nknots, stride, order, knot); + + if (!do_check_knots(knots, "curve")) + return; + + O_nurbscurve o_nurbscurve = new O_nurbscurve(realType); + o_nurbscurve.bezier_curves = new Quilt(mapdesc); + CArrayOfFloats ctrlcarr = new CArrayOfFloats(ctlarray); + o_nurbscurve.bezier_curves.toBezier(knots, ctrlcarr, mapdesc + .getNCoords()); + thread("do_nurbscurve", o_nurbscurve); + } + + /** + * Check knot vector specification + * + * @param knots + * knot vector + * @param msg + * error message + * @return knot vector is / is not valid + */ + public boolean do_check_knots(Knotvector knots, String msg) { + // DONE + int status = knots.validate(); + if (status > 0) { + do_nurbserror(status); + if (renderhints.errorchecking != NurbsConsts.N_NOMSG) + knots.show(msg); + } + return (status > 0) ? false : true; + } + + /** + * Draw a curve + * + * @param o_nurbscurve + * NURBS curve object + */ + public void do_nurbscurve(O_nurbscurve o_nurbscurve) { + // DONE + + if (inCurve <= 0) { + bgncurve(); + inCurve = 2; + } + + if (o_nurbscurve.used) { + do_nurbserror(23); + isDataValid = 0; + return; + } else + o_nurbscurve.used = true; + + if (currentCurve.curvetype == CT_NONE) { + currentCurve.curvetype = CT_NURBSCURVE; + } else if (currentCurve.curvetype != CT_NURBSCURVE) { + do_nurbserror(24); + isDataValid = 0; + return; + } + + // it was necessary to overcome problem with pointer to pointer here + + // if(!o_nurbscurve.equals(nextNurbscurve)){ + if (!o_nurbscurve.equals(currentCurve.o_nurbscurve)) { + isCurveModified = 1; + currentCurve.o_nurbscurve = o_nurbscurve; + // nextNurbscurve=o_nurbscurve; + + } + + nextNurbscurve = o_nurbscurve.next; + + if (!currentCurve.equals(o_nurbscurve.owner)) { + isCurveModified = 1; + o_nurbscurve.owner = currentCurve; + } + + if (o_nurbscurve.owner == null) + isCurveModified = 1; + + if (inCurve == 2) + endcurve(); + } + + /** + * Draw NURBS surface + * + * @param o_nurbssurface + * NURBS surface object + */ + public void do_nurbssurface(O_nurbssurface o_nurbssurface) { + // DONE + if (inSurface <= 0) { + bgnsurface(); + inSurface = 2; + } + if (o_nurbssurface.used) { + do_nurbserror(25); + isDataValid = 0; + return; + } else + o_nurbssurface.used = true; + + if (!o_nurbssurface.equals(nextNurbscurve)) { + isSurfaceModified = true; + // nextNurbssurface=o_nurbssurface; + currentSurface.o_nurbssurface = o_nurbssurface; + } + + if (!currentSurface.equals(o_nurbssurface.owner)) { + isSurfaceModified = true; + o_nurbssurface.owner = currentSurface; + } + + nextNurbssurface = o_nurbssurface.next; + + if (inSurface == 2) + endsurface(); + } + + /** + * (Re)Inicialize maps + */ + public void redefineMaps() { + // DONE + maplist.initialize(); + } + + /** + * Define a map of given properties + * + * @param type + * map type + * @param rational + * is rational + * @param ncoords + * number of control point coordinates + */ + public void defineMap(int type, int rational, int ncoords) { + // DONE + maplist.define(type, rational, ncoords); + } + + /** + * Set NURBS property + * + * @param type + * property type + * @param tag + * property tag + * @param value + * property value + */ + public void setnurbsproperty(int type, int tag, float value) { + // DONE + Mapdesc mapdesc = maplist.locate(type); + if (mapdesc == null) { + do_nurbserror(35); + return; + } + if (!mapdesc.isProperty(tag)) { + do_nurbserror(26); + return; + } + Property prop = new Property(type, tag, value); + thread("do_setnurbsproperty2", prop); + } + + /** + * Set parameters of existing property + * + * @param prop + * property + */ + public void do_setnurbsproperty2(Property prop) { + Mapdesc mapdesc = maplist.find(prop.type); + mapdesc.setProperty(prop.tag, prop.value); + } + + /** + * Set given property to rendering hints + * + * @param prop + * property to be set + */ + public void do_setnurbsproperty(Property prop) { + // DONE + renderhints.setProperty(prop); + // TODO freeproperty? + } + + /** + * Sets wheteher we use domain distance sampling + * + * @param i + * domain distance sampling flag + */ + public void set_is_domain_distance_sampling(int i) { + // DONE + subdivider.set_is_domain_distance_sampling(i); + } + + /** + * Begin new surface + */ + public void bgnsurface() { + // DONE + O_surface o_surface = new O_surface(); + // TODO nuid + // System.out.println("TODO glunurbs.bgnsurface nuid"); + thread("do_bgnsurface", o_surface); + } + + /** + * End current surface + */ + public void endsurface() { + // DONE + thread2("do_endsurface"); + } + + /** + * End surface trimming + */ + private void endtrim() { + // TODO Auto-generated method stub + // System.out.println("TODO glunurbs.endtrim"); + } + + /** + * Make NURBS surface + * + * @param sknot_count + * number of knots in s direction + * @param sknot + * knot vector in s direction + * @param tknot_count + * number of knots in t direction + * @param tknot + * knot vector in t direction + * @param s_stride + * number of coords of control points in s direction + * @param t_stride + * number of coords of control points in t direction + * @param ctlarray + * control points + * @param sorder + * order of curve in s direction + * @param torder + * order of curve in t direction + * @param type + * NURBS surface type (rational,...) + */ + public void nurbssurface(int sknot_count, float[] sknot, int tknot_count, + float[] tknot, int s_stride, int t_stride, float[] ctlarray, + int sorder, int torder, int type) { + // DONE + Mapdesc mapdesc = maplist.locate(type); + if (mapdesc == null) { + do_nurbserror(35); + isDataValid = 0; + return; + } + if (s_stride < 0 || t_stride < 0) { + do_nurbserror(34); + isDataValid = 0; + return; + } + Knotvector sknotvector = new Knotvector(sknot_count, s_stride, sorder, + sknot); + if (!do_check_knots(sknotvector, "surface")) + return; + Knotvector tknotvector = new Knotvector(tknot_count, t_stride, torder, + tknot); + if (!do_check_knots(tknotvector, "surface")) + return; + + O_nurbssurface o_nurbssurface = new O_nurbssurface(type); + o_nurbssurface.bezier_patches = new Quilt(mapdesc); + + CArrayOfFloats ctrlarr = new CArrayOfFloats(ctlarray); + o_nurbssurface.bezier_patches.toBezier(sknotvector, tknotvector, + ctrlarr, mapdesc.getNCoords()); + thread("do_nurbssurface", o_nurbssurface); + } +} -- cgit v1.2.3