[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view View.java, 1.202, 1.203
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2007-05-07 13:39:39
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14127/src/net/sourceforge/bprocessor/gl/view Modified Files: View.java Log Message: added displaylists on surfaces and forward update call from glView to view to clear these in a consdervative manner. Better performance. Made drawGeneralEdge use drawEdge method with EdgeAttribute as well, seem to work, but look out for edge flaws :-D Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.202 retrieving revision 1.203 diff -C2 -d -r1.202 -r1.203 *** View.java 4 May 2007 11:59:26 -0000 1.202 --- View.java 7 May 2007 13:39:38 -0000 1.203 *************** *** 344,357 **** /** Temporary constructors. Will be drawn but not put in database */ ! private Set tempConstructors; /** Temporary edges. Will be drawn but not put in database */ ! private Set tempEdges; /** Temporary surfaces. Will be drawn but not put in database */ ! private Set tempSurfaces; /** Temporary verticies. Will be drawn but not put in database */ ! private Set tempVertices; /** Maps entities to a color */ --- 344,357 ---- /** Temporary constructors. Will be drawn but not put in database */ ! private Set<Constructor> tempConstructors; /** Temporary edges. Will be drawn but not put in database */ ! private Set<Edge> tempEdges; /** Temporary surfaces. Will be drawn but not put in database */ ! private Set<Surface> tempSurfaces; /** Temporary verticies. Will be drawn but not put in database */ ! private Set<Vertex> tempVertices; /** Maps entities to a color */ *************** *** 367,371 **** * FIXME this should be a list to be able to control ordering. */ ! private Set glObjects3D; /** --- 367,371 ---- * FIXME this should be a list to be able to control ordering. */ ! private Set<GlObject> glObjects3D; /** *************** *** 381,384 **** --- 381,386 ---- private HashMap<Surface, Integer> displayLists = new HashMap<Surface, Integer>(); + private List<Integer> deletedLists = new LinkedList<Integer>(); + static { setTransparency(100); *************** *** 591,595 **** Edge e2 = new Edge(v2, v3); Edge e3 = new Edge(v3, v1); ! List edges = new LinkedList(); edges.add(e1); edges.add(e2); --- 593,597 ---- Edge e2 = new Edge(v2, v3); Edge e3 = new Edge(v3, v1); ! List<Edge> edges = new LinkedList<Edge>(); edges.add(e1); edges.add(e2); *************** *** 618,621 **** --- 620,628 ---- } } + if (attributes.getDrawVertices()) { + gl.glPointSize(10.0f); + } else { + gl.glPointSize(1.0f); + } } } *************** *** 626,726 **** */ public void display(GLAutoDrawable gld) { ! gl = gld.getGL(); ! glu = new GLU(); ! ! boolean hitdetection = false; ! ! gl.glClearColor(bgColor[0], bgColor[1], bgColor[2], bgColor[3]); ! gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); ! ! if (picking > 0) { ! selectBuffer = BufferUtil.newIntBuffer(selectionLength); ! gl.glSelectBuffer(selectionLength, selectBuffer); ! gl.glRenderMode(GL.GL_SELECT); ! hitdetection = true; ! } ! ! initCamera(); ! gl.glPushMatrix(); ! picking = 0; ! ! enableClipplanes(); ! ! gl.glColor3fv(lineColor, 0); ! gl.glLineWidth(1.0f); ! ! drawAll(hitdetection); ! ! gl.glEnable(GL.GL_DEPTH_TEST); ! ! disableClipplanes(); ! ! //draw the clipping planes ! Collection<ClippingPlane> clips ! = Project.getInstance().getCurrentCamera().getClipplanes(); ! ! for (ClippingPlane current : clips) { ! Collection selection = Selection.primary(); ! if (current == target) { ! drawObject(current); ! } else { ! if (selection.contains(current)) { ! gl.glColor3fv(SELECTED_COLOR, 0); } else { ! gl.glColor3fv(CLIP_PLANE_COLOR, 0); } - drawClipplane(current); } ! } ! ! ! gl.glMatrixMode(GL.GL_PROJECTION); ! gl.glDisable(GL.GL_DEPTH_TEST); ! gl.glPushMatrix(); ! gl.glLoadIdentity(); ! if (hitdetection) { ! int[] viewport = new int[] {0, 0, (int)width, (int)height}; ! glu.gluPickMatrix(x, viewport[3] - y, 5, 5, viewport, 0); ! } ! glu.gluOrtho2D(0, width, 0, height); ! gl.glMatrixMode(GL.GL_MODELVIEW); ! gl.glPushMatrix(); ! gl.glLoadIdentity(); ! ! if (glv.getTool() instanceof SpaceTool) { ! labelSelection(hitdetection); ! } ! ! ! drawSpacePath(hitdetection); ! ! for (Widget widget : widgets) { ! widget.display(gl, glu, hitdetection); ! } ! ! gl.glMatrixMode(GL.GL_PROJECTION); ! gl.glPopMatrix(); ! gl.glMatrixMode(GL.GL_MODELVIEW); ! gl.glPopMatrix(); ! ! ! gl.glPopMatrix(); ! if (hitdetection) { ! gl.glFlush(); ! hits = gl.glRenderMode(GL.GL_RENDER); ! if (hits < 0) { ! // There were overflow in the selctionBuffer double the buffer and try again ! selectionLength *= 2; ! picking = 10; ! glv.repaint(true); } ! if (log.isDebugEnabled()) { ! log.debug("Hits: " + hits); } ! } else { ! gld.swapBuffers(); } } ! /** * disable all clipping planes --- 633,746 ---- */ public void display(GLAutoDrawable gld) { ! try { ! gl = gld.getGL(); ! glu = new GLU(); ! ! // remove old displayLists ! for (Integer i : deletedLists) { ! gl.glDeleteLists(i, i); ! } ! deletedLists.clear(); ! ! boolean hitdetection = false; ! ! gl.glClearColor(bgColor[0], bgColor[1], bgColor[2], bgColor[3]); ! gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); ! ! if (picking > 0) { ! selectBuffer = BufferUtil.newIntBuffer(selectionLength); ! gl.glSelectBuffer(selectionLength, selectBuffer); ! gl.glRenderMode(GL.GL_SELECT); ! hitdetection = true; ! } ! ! initCamera(); ! gl.glPushMatrix(); ! picking = 0; ! ! enableClipplanes(); ! ! gl.glColor3fv(lineColor, 0); ! gl.glLineWidth(1.0f); ! ! drawAll(hitdetection); ! ! gl.glEnable(GL.GL_DEPTH_TEST); ! ! disableClipplanes(); ! ! //draw the clipping planes ! Collection<ClippingPlane> clips ! = Project.getInstance().getCurrentCamera().getClipplanes(); ! ! for (ClippingPlane current : clips) { ! Collection selection = Selection.primary(); ! if (current == target) { ! drawObject(current); } else { ! if (selection.contains(current)) { ! gl.glColor3fv(SELECTED_COLOR, 0); ! } else { ! gl.glColor3fv(CLIP_PLANE_COLOR, 0); ! } ! drawClipplane(current); } } ! ! ! gl.glMatrixMode(GL.GL_PROJECTION); ! gl.glDisable(GL.GL_DEPTH_TEST); ! gl.glPushMatrix(); ! gl.glLoadIdentity(); ! if (hitdetection) { ! int[] viewport = new int[] {0, 0, (int)width, (int)height}; ! glu.gluPickMatrix(x, viewport[3] - y, 5, 5, viewport, 0); } ! glu.gluOrtho2D(0, width, 0, height); ! gl.glMatrixMode(GL.GL_MODELVIEW); ! gl.glPushMatrix(); ! gl.glLoadIdentity(); ! ! if (glv.getTool() instanceof SpaceTool) { ! labelSelection(hitdetection); } ! ! ! drawSpacePath(hitdetection); ! ! for (Widget widget : widgets) { ! widget.display(gl, glu, hitdetection); ! } ! ! gl.glMatrixMode(GL.GL_PROJECTION); ! gl.glPopMatrix(); ! gl.glMatrixMode(GL.GL_MODELVIEW); ! gl.glPopMatrix(); ! ! ! gl.glPopMatrix(); ! if (hitdetection) { ! gl.glFlush(); ! hits = gl.glRenderMode(GL.GL_RENDER); ! if (hits < 0) { ! // There were overflow in the selctionBuffer double the buffer and try again ! selectionLength *= 2; ! picking = 10; ! glv.repaint(true); ! } ! if (log.isDebugEnabled()) { ! log.debug("Hits: " + hits); ! } ! } else { ! gld.swapBuffers(); ! } ! } catch (Exception e) { ! log.error(e); ! //Maybe try to reset the gl setting ! Project.getInstance().resetCam(); ! Project.getInstance().changed(Project.getInstance().getCurrentCamera()); } } ! /** * disable all clipping planes *************** *** 862,867 **** * @return Supporting edges */ ! public Collection collectSupportingEdges(Space active) { ! Collection edges = new HashSet(); if (active != Project.getInstance().world()) { Space current = active; --- 882,887 ---- * @return Supporting edges */ ! public Collection<Edge> collectSupportingEdges(Space active) { ! Collection<Edge> edges = new HashSet<Edge>(); if (active != Project.getInstance().world()) { Space current = active; *************** *** 1108,1118 **** gl.glPolygonOffset(0.5f, 0.5f); gl.glEnable(GL.GL_CULL_FACE); ! gl.glCullFace(GL.GL_BACK); drawSurfaces(surfaces, FRONT); ! gl.glCullFace(GL.GL_FRONT); drawSurfaces(surfaces, BACK); ! gl.glDisable(GL.GL_CULL_FACE); gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); --- 1128,1138 ---- gl.glPolygonOffset(0.5f, 0.5f); gl.glEnable(GL.GL_CULL_FACE); ! gl.glCullFace(GL.GL_BACK); drawSurfaces(surfaces, FRONT); ! gl.glCullFace(GL.GL_FRONT); drawSurfaces(surfaces, BACK); ! gl.glDisable(GL.GL_CULL_FACE); gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); *************** *** 1137,1145 **** drawGeneralEdges(space.getEdges(), !active); } Collection elements = space.getElements(); Iterator iter = elements.iterator(); while (iter.hasNext()) { Space current = (Space) iter.next(); ! drawSpace(current, active, selected); } gl.glPopMatrix(); --- 1157,1168 ---- drawGeneralEdges(space.getEdges(), !active); } + Collection elements = space.getElements(); Iterator iter = elements.iterator(); while (iter.hasNext()) { Space current = (Space) iter.next(); ! if (!(current instanceof Net)) { ! drawSpace(current, active, selected); ! } } gl.glPopMatrix(); *************** *** 1517,1545 **** public void drawGeneralEdges(Collection<Edge> edges, boolean dodge) { Collection selection = Selection.primary(); - gl.glLineWidth(1.0f); for (Edge current : edges) { ! float[] color = lineColor; ! if (selection.contains(current)) { ! color = SELECTED_COLOR; ! gl.glLineWidth(1.5f); } else { float[] individualColor = (float[])colorMap.get(current); if (individualColor != null) { ! color = individualColor; } else { if (current.getStrippled()) { ! color = constructorColor; } else if (dodge) { ! color = GREY_LINE_COLOR; } } } ! gl.glColor3fv(color, 0); ! if (current.getStrippled()) { ! drawConstructor(current); ! } else { ! drawEdge(current); ! } gl.glColor3fv(lineColor, 0); } --- 1540,1567 ---- public void drawGeneralEdges(Collection<Edge> edges, boolean dodge) { Collection selection = Selection.primary(); for (Edge current : edges) { ! EdgeAttributes style = new EdgeAttributes(); if (selection.contains(current)) { ! style.setColor(SELECTED_COLOR); ! style.setLineWidth(1.5f); ! } else if (current.getOwner() instanceof Net) { ! style.setColor(constructorColor); ! style.setLineWidth(2.0f); ! style.setStipple(true); ! style.setDrawVertices(true); } else { float[] individualColor = (float[])colorMap.get(current); if (individualColor != null) { ! style.setColor(individualColor); } else { if (current.getStrippled()) { ! style.setColor(constructorColor); ! style.setStipple(true); } else if (dodge) { ! style.setColor(GREY_LINE_COLOR); } } } ! drawEdge(current, style); gl.glColor3fv(lineColor, 0); } *************** *** 1626,1640 **** Integer list = displayLists.get(s); if (list == null) { ! //list = gl.glGenLists(1); ! //displayLists.put(s, list); ! //gl.glNewList(list, GL.GL_COMPILE); //begining the polygon, we are not using userdata for now (hence the null) glu.gluTessBeginPolygon(tess, null); //light stuff ! if (drawMode == LIGHTING_MODE) { ! Vertex norm = s.normal(); ! if (norm != null) { ! gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); ! } } --- 1648,1660 ---- Integer list = displayLists.get(s); if (list == null) { ! list = gl.glGenLists(1); ! displayLists.put(s, list); ! gl.glNewList(list, GL.GL_COMPILE); //begining the polygon, we are not using userdata for now (hence the null) glu.gluTessBeginPolygon(tess, null); //light stuff ! Vertex norm = s.normal(); ! if (norm != null) { ! gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); } *************** *** 1648,1652 **** while (innerIt.hasNext()) { Surface surface = (Surface)innerIt.next(); ! if (hit) { if (surface.getOwner() == s.getOwner()) { drawContour(surface, tess); --- 1668,1676 ---- while (innerIt.hasNext()) { Surface surface = (Surface)innerIt.next(); ! if (surface.getOwner() == s.getOwner()) { ! drawContour(surface, tess); ! } ! /*if (hit) { ! // Meant to prevent selecting inner geometry in a space if (surface.getOwner() == s.getOwner()) { drawContour(surface, tess); *************** *** 1654,1664 **** } else { drawContour(surface, tess); ! } } } glu.gluTessEndPolygon(tess); ! //gl.glEndList(); } ! //gl.glCallList(list); } --- 1678,1688 ---- } else { drawContour(surface, tess); ! }*/ } } glu.gluTessEndPolygon(tess); ! gl.glEndList(); } ! gl.glCallList(list); } *************** *** 1941,1945 **** private void drawSelectionMode() { Space space = Project.getInstance().getActiveSpace(); ! Collection surfaces = new LinkedList(); surfaces.addAll(space.getSurfaces()); --- 1965,1969 ---- private void drawSelectionMode() { Space space = Project.getInstance().getActiveSpace(); ! Collection<Surface> surfaces = new LinkedList<Surface>(); surfaces.addAll(space.getSurfaces()); *************** *** 1958,1969 **** edges.addAll(Surface.edges(surfaces)); edges.addAll(tempEdges); ! Collection vertices = new LinkedList(); vertices.addAll(space.getVertices()); vertices.addAll(tempVertices); if (selectionMode != OBJECTS) { ! Collection envelopeEdges = collectSupportingEdges(space); edges.addAll(envelopeEdges); ! Collection envelopeVertices = Edge.vertices(envelopeEdges); vertices.addAll(envelopeVertices); } --- 1982,1993 ---- edges.addAll(Surface.edges(surfaces)); edges.addAll(tempEdges); ! Collection<Vertex> vertices = new LinkedList<Vertex>(); vertices.addAll(space.getVertices()); vertices.addAll(tempVertices); if (selectionMode != OBJECTS) { ! Collection<Edge> envelopeEdges = collectSupportingEdges(space); edges.addAll(envelopeEdges); ! Collection<Vertex> envelopeVertices = Edge.vertices(envelopeEdges); vertices.addAll(envelopeVertices); } *************** *** 2063,2067 **** Camera camera = Project.getInstance().getCurrentCamera(); ! Collection all = new LinkedList(); all.addAll(space.getConstructors()); all.addAll(tempConstructors); --- 2087,2091 ---- Camera camera = Project.getInstance().getCurrentCamera(); ! Collection<Constructor> all = new LinkedList<Constructor>(); all.addAll(space.getConstructors()); all.addAll(tempConstructors); *************** *** 2213,2219 **** } } ! ! ! /** * FIXME edge-drawing --- 2237,2241 ---- } } ! /** * FIXME edge-drawing *************** *** 2246,2250 **** --- 2268,2277 ---- apply(attributes); drawEdge(edge); + if (attributes.getDrawVertices()) { + drawVertexHit(edge.getFrom()); + drawVertexHit(edge.getTo()); + } } + private void drawEdges(Collection<Edge> edges, EdgeAttributes attributes) { apply(attributes); *************** *** 2265,2269 **** gl.glPointSize(1.0f); } ! /** * --- 2292,2296 ---- gl.glPointSize(1.0f); } ! /** * *************** *** 3339,3341 **** --- 3366,3412 ---- widgets.remove(widget); } + + /** + * The changed entity + * @param entity the changed entity + */ + public void update(Object entity) { + log.info("Change on " + entity + " class " + entity.getClass()); + if (entity instanceof Space) { + for (Surface s : ((Space)entity).getSurfaces()) { + Integer which = displayLists.remove(s); + if (which != null) { + deletedLists.add(which); + } + } + } else if (entity instanceof Surface) { + Integer which = displayLists.remove((Surface)entity); + if (which != null) { + deletedLists.add(which); + } + } else if (entity instanceof Geometric) { + Geometric g = (Geometric)entity; + Space sp = g.getOwner(); + for (Surface s : sp.getSurfaces()) { + Integer which = displayLists.remove(s); + if (which != null) { + deletedLists.add(which); + } + } + } else if (entity instanceof Project) { + deletedLists.addAll(displayLists.values()); + displayLists.clear(); + } else if (entity instanceof Selection) { + /*for (Geometric g : (Selection)entity) { + if (g instanceof Surface) { + Integer which = displayLists.remove((Surface)g); + if (which != null) { + deletedLists.add(which); + } + } + }*/ + } else { + log.warn("There were a update event on a undecided entity " + entity.getClass()); + } + } } |