📄 graphicscontext3d.java
字号:
/* * $RCSfile: GraphicsContext3D.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.14 $ * $Date: 2007/04/12 17:34:05 $ * $State: Exp $ */package javax.media.j3d;import java.awt.Point;import java.awt.image.BufferedImage;import javax.vecmath.*;import java.util.Vector;import java.util.Enumeration;import java.awt.Dimension;/** * A GraphicsContext3D object is used for immediate mode rendering into * a 3D canvas. It is created by, and associated with, a specific * Canvas3D object. A GraphicsContext3D defines methods to set 3D graphics * state and draw 3D geometric primitives. There are no public * constructors of GraphicsContext3D. An application obtains a 3D graphics * context object from the Canvas3D object that the application wishes * to render into by using the getGraphicsContext3D method. A new graphics * context is created if one does not already exist. A new GraphicsContext3D * initializes its state variables to the following defaults: * <UL> * <LI> Background object: null </LI> * <LI> Fog object: null </LI> * <LI> ModelClip object: null </LI> * <LI> Appearance object: null </LI> * <LI> List of Light objects: empty </LI> * <LI> high-res coordinate: (0, 0, 0) </LI> * <LI> modelTransform: identity </LI> * <LI> AuralAttributes object: null </LI> * <LI> List of Sound objects: empty </LI> * <LI> buffer override: false </LI> * <LI> front buffer rendering: false </LI> * <LI> stereo mode: <code>STEREO_BOTH</code> </LI> * </UL> * * <p> * Note that the drawing methods in this class are not necessarily * executed immediately. They may be buffered up for future * execution. Applications must call the * <code><a href="#flush(boolean)">flush</a>(boolean)</code> * method to ensure that the rendering actually happens. The flush * method is implicitly called in the following cases: * * <ul> * <li>The <code>readRaster</code> method calls * <code>flush(true)</code></li> * <li>The <code>Canvas3D.swap</code> method calls * <code>flush(true)</code></li> * <li>The Java 3D renderer calls <code>flush(true)</code> prior to * swapping the buffer for a double buffered on-screen Canvas3D</li> * <li>The Java 3D renderer calls <code>flush(true)</code> prior to * copying into the off-screen buffer of an off-screen Canvas3D</li> * <li>The Java 3D renderer calls <code>flush(false)</code> after * calling the preRender, renderField, postRender, and postSwap * Canvas3D callback methods.</li> * </ul> * * <p> * A single-buffered, pure-immediate mode application must explicitly * call flush to ensure that the graphics will be rendered to the * Canvas3D. * * @see Canvas3D#getGraphicsContext3D */public class GraphicsContext3D extends Object { /** * Specifies that rendering is done to the left eye. * @see #setStereoMode * @since Java 3D 1.2 */ public static final int STEREO_LEFT = 0; /** * Specifies that rendering is done to the right eye. * @see #setStereoMode * @since Java 3D 1.2 */ public static final int STEREO_RIGHT = 1; /** * Specifies that rendering is done to both eyes. This is the * default. * @see #setStereoMode * @since Java 3D 1.2 */ public static final int STEREO_BOTH = 2; /** * Canvas3D in which this GraphicsContext3D will render. */ Canvas3D canvas3d = null;//// Graphics state//// current user specified graphics state private Background uBackground = null; private Fog uFog = null; private Appearance uAppearance = null; private Vector uLights = new Vector(); private HiResCoord uHiRes = new HiResCoord(); private Vector uSounds = new Vector(); private AuralAttributes uAuralAttributes = null; private boolean uBufferOverride = false; private boolean uFrontBufferRendering = false; private int uStereoMode = STEREO_BOTH; private ModelClip uModelClip = null;// Current rendering graphics state // Current background Background background = null; // Background to use if background is null; BackgroundRetained black = new BackgroundRetained(); // Current fog Fog fog = null; // Current modelClip ModelClip modelClip = null; // Current appearance object Appearance appearance = null; // default appearance retained object AppearanceRetained defaultAppearanceRetained = new AppearanceRetained(); // The vector of lights Vector lights = new Vector(); // Current High resolution coordinate HiResCoord hiRes = new HiResCoord(); // Current modeling transform Transform3D modelTransform = new Transform3D(); Transform3D identityTransform = new Transform3D(); Transform3D modelClipTransform = null; Transform3D normalTransform = null; boolean normalTransformNeedToUpdate = true; // The vector of sounds Vector sounds = new Vector(); // Current AuralAttributes state parameters AuralAttributes auralAttributes = null; // The render object associated with this context LightSet ls = null; // The current list of lights LightRetained[] lightlist = null; // Ambient lights Color3f sceneAmbient = new Color3f(0.0f, 0.0f, 0.0f); // The current number of lights, may be less than lightlist.length int numLights = 0; // Current composite transform: hi-res + modelTransform Transform3D compTransform = new Transform3D(); // Draw transform: hi-res + modelTransform + view Transform3D drawTransform = new Transform3D(); // The view transform (VPC to EC). // NOTE that this is *read-only* Transform3D vpcToEc; // A boolean that indicates the lights have changed boolean lightsChanged = false; // A boolean that indicates the sounds have changed // XXXX: the soundsChanged flag are set like lights methods set // lightsChanged? but where is this supposed to be check??? // lightsChanged tested in 'draw'; but Sound are not processed // in draw. boolean soundsChanged = false; // Buffer override flag; enables frontBufferRendering and stereoMode // attributes. boolean bufferOverride = false; // Forces rendering to the front buffer (if bufferOverride is true) boolean frontBufferRendering = false; // Stereo mode for this buffer (if bufferOverride is true) int stereoMode = STEREO_BOTH; // Read Buffer for reading raster of color image byte[] byteBuffer = new byte[1]; // Read Buffer for reading floating depth image float[] floatBuffer = new float[1]; // Read Buffer for reading integer depth image int[] intBuffer = new int[1]; /** * The cached ColoringAttributes color value. It is * 1.0, 1.0, 1.0 if there is no ColoringAttributes. */ float red = 1.0f; float green = 1.0f; float blue = 1.0f; /** * Cached diffuse color value */ float dRed = 1.0f; float dGreen = 1.0f; float dBlue = 1.0f; /** * The cached TransparencyAttributes transparency value. It is * 0.0 if there is no TransparencyAttributes. */ float alpha = 0.0f; /** * The cached visible flag for geometry. */ boolean visible = true; /** * Cached values for polygonMode, line antialiasing, and point antialiasing */ int polygonMode = PolygonAttributes.POLYGON_FILL; boolean lineAA = false; boolean pointAA = false; /** /** * A boolean indicating whether or not lighting should be on. */ boolean enableLighting = false; private Appearance defaultAppearance = null; private boolean geometryIsLocked = false; private boolean ignoreVertexColors = false; static final int CLEAR = 0; static final int DRAW = 1; static final int SWAP = 2; static final int READ_RASTER = 3; static final int SET_APPEARANCE = 4; static final int SET_BACKGROUND = 5; static final int SET_FOG = 6; static final int SET_LIGHT = 7; static final int INSERT_LIGHT = 8; static final int REMOVE_LIGHT = 9; static final int ADD_LIGHT = 10; static final int SET_HI_RES = 11; static final int SET_MODEL_TRANSFORM = 12; static final int MULTIPLY_MODEL_TRANSFORM = 13; static final int SET_SOUND = 14; static final int INSERT_SOUND = 15; static final int REMOVE_SOUND = 16; static final int ADD_SOUND = 17; static final int SET_AURAL_ATTRIBUTES = 18; static final int SET_BUFFER_OVERRIDE = 19; static final int SET_FRONT_BUFFER_RENDERING = 20; static final int SET_STEREO_MODE = 21; static final int FLUSH = 22; static final int FLUSH2D = 23; static final int DRAWANDFLUSH2D = 24; static final int SET_MODELCLIP = 25; static final int DISPOSE2D = 26; static final int NCOMMANDS = 27; // needs to be incremented // when a new command is to be // added to the list private static Integer[] commands = new Integer[NCOMMANDS]; private static Integer[] stereoModes = { new Integer(STEREO_LEFT), new Integer(STEREO_RIGHT), new Integer(STEREO_BOTH) }; // dirty bits private static final int BUFFER_MODE = 0x1; private int dirtyMask = 0; // multi-texture private int numActiveTexUnit = 0; private int lastActiveTexUnitIndex = 0; // for read raster private volatile boolean readRasterReady = false; // for runMonitor private boolean gcReady = false; private int waiting = 0; /** * Constructs and creates a GraphicsContext3D object with default * values. Users do not call this directly, rather they get a * graphics context from a Canvas3D. */ GraphicsContext3D(Canvas3D canvas3d) { this.canvas3d = canvas3d; } /** * Gets the Canvas3D that created this GraphicsContext3D. * @return the Canvas3D that created this GraphicsContext3D */ public Canvas3D getCanvas3D() { return this.canvas3d; }//// Methods to set/get graphics state// /** * Sets the current Appearance object to the specified * Appearance component object. * The graphics context stores a reference to the specified * Appearance object. This means that the application may modify * individual appearance attributes by using the appropriate * methods on the Appearance object. * If the Appearance object is null, default values will be used * for all appearance attributes - it is as if an * Appearance node were created using the default constructor. * * @param appearance the new Appearance object * * @exception IllegalSharingException if the specified appearance refers * to an ImageComponent2D that is being used by a Canvas3D as * an off-screen buffer. */ public void setAppearance(Appearance appearance) { if(appearance == null) { if(defaultAppearance == null) { defaultAppearance = new Appearance(); } appearance = defaultAppearance; } else { // Check whether any ImageComponent2D referred to by // the new appearance is being used as an off-screen buffer and throw // IllegalSharingException if it is. TextureRetained texRetained; ImageComponent[] images;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -