📄 joglrenderer.java
字号:
FloatBuffer color = curve.getColorBuffer();
if (color != null)
color.rewind();
float colorInterval = 0;
float colorModifier = 0;
if (null != color) {
matRecord.setCurrentColor(color.get(), color.get(), color.get(),
color.get());
colorInterval = 4f / color.limit();
colorModifier = colorInterval;
color.rewind();
}
Vector3f point;
float limit = (1 + (1.0f / curve.getSteps()));
for (float t = 0; t <= limit; t += 1.0f / curve.getSteps()) {
if (t >= colorInterval && color != null) {
colorInterval += colorModifier;
matRecord.setCurrentColor(color.get(), color.get(),
color.get(), color.get());
}
point = curve.getPoint(t, tempVa);
gl.glVertex3f(point.x, point.y, point.z);
}
if (Debug.stats) {
StatCollector.addStat(StatType.STAT_VERTEX_COUNT, limit);
}
gl.glEnd();
undoTransforms(curve);
}
/**
* <code>draw</code> renders a <code>Line</code> object including it's
* normals, colors, textures and vertices.
*
* @see Renderer#draw(Line)
* @param lines
* the lines to render.
*/
public void draw(Line lines) {
final GL gl = GLU.getCurrentGL();
if (!lines.predraw(this))
return;
if (Debug.stats) {
StatCollector.addStat(StatType.STAT_LINE_COUNT, 1);
StatCollector.addStat(StatType.STAT_VERTEX_COUNT, lines.getVertexCount());
StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
}
if (lines.getDisplayListID() != -1) {
renderDisplayList(lines);
return;
}
if (!generatingDisplayList)
applyStates(lines.states, lines);
if (Debug.stats) {
StatCollector.startStat(StatType.STAT_RENDER_TIMER);
}
boolean transformed = doTransforms(lines);
int mode = GL.GL_LINES;
switch (lines.getMode()) {
case Segments:
mode = GL.GL_LINES;
break;
case Connected:
mode = GL.GL_LINE_STRIP;
break;
case Loop:
mode = GL.GL_LINE_LOOP;
break;
}
LineRecord lineRecord = (LineRecord) display
.getCurrentContext().getLineRecord();
lineRecord.applyLineWidth(lines.getLineWidth());
lineRecord.applyLineStipple(lines.getStippleFactor(), lines
.getStipplePattern());
lineRecord.applyLineSmooth(lines.isAntialiased());
if (!lineRecord.isValid())
lineRecord.validate();
if (!predrawGeometry(lines)) {
// make sure only the necessary indices are sent through on old
// cards.
IntBuffer indices = lines.getIndexBuffer();
indices.rewind();
indices.limit(lines.getVertexCount());
gl.glDrawElements(mode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
indices.clear();
} else {
gl.glDrawElements(mode, lines.getIndexBuffer().limit(),
GL.GL_UNSIGNED_INT, 0);
}
postdrawGeometry(lines);
if (transformed) undoTransforms(lines);
if (Debug.stats) {
StatCollector.endStat(StatType.STAT_RENDER_TIMER);
}
lines.postdraw(this);
}
/**
* <code>draw</code> renders a <code>Point</code> object including it's
* normals, colors, textures and vertices.
*
* @see Renderer#draw(Point)
* @param points
* the points to render.
*/
public void draw(Point points) {
final GL gl = GLU.getCurrentGL();
if (!points.predraw(this))
return;
if (Debug.stats) {
StatCollector.addStat(StatType.STAT_POINT_COUNT, 1);
StatCollector.addStat(StatType.STAT_VERTEX_COUNT, points.getVertexCount());
StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
}
if (points.getDisplayListID() != -1) {
renderDisplayList(points);
return;
}
if (!generatingDisplayList)
applyStates(points.states, points);
if (Debug.stats) {
StatCollector.startStat(StatType.STAT_RENDER_TIMER);
}
boolean transformed = doTransforms(points);
gl.glPointSize(points.getPointSize());
if (points.isAntialiased()) {
gl.glEnable(GL.GL_POINT_SMOOTH);
gl.glHint(GL.GL_POINT_SMOOTH_HINT, GL.GL_NICEST);
}
if (!predrawGeometry(points)) {
// make sure only the necessary indices are sent through on old
// cards.
IntBuffer indices = points.getIndexBuffer();
indices.rewind();
indices.limit(points.getVertexCount());
gl.glDrawElements(GL.GL_POINTS, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
indices.clear();
} else {
gl.glDrawElements(GL.GL_POINTS,
points.getIndexBuffer().limit(), GL.GL_UNSIGNED_INT, 0);
}
if (points.isAntialiased()) {
gl.glDisable(GL.GL_POINT_SMOOTH);
}
postdrawGeometry(points);
if (transformed) undoTransforms(points);
if (Debug.stats) {
StatCollector.endStat(StatType.STAT_RENDER_TIMER);
}
points.postdraw(this);
}
/**
* <code>draw</code> renders a <code>QuadMesh</code> object including
* it's normals, colors, textures and vertices.
*
* @see Renderer#draw(QuadMesh)
* @param quads
* the mesh to render.
*/
public void draw(QuadMesh quads) {
final GL gl = GLU.getCurrentGL();
if (!quads.predraw(this))
return;
if (Debug.stats) {
StatCollector.addStat(StatType.STAT_QUAD_COUNT, quads.getQuadCount());
StatCollector.addStat(StatType.STAT_VERTEX_COUNT, quads.getVertexCount());
StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
}
if (quads.getDisplayListID() != -1) {
renderDisplayList(quads);
return;
}
if (!generatingDisplayList)
applyStates(quads.states, quads);
if (Debug.stats) {
StatCollector.startStat(StatType.STAT_RENDER_TIMER);
}
boolean transformed = doTransforms(quads);
int glMode = GL.GL_QUADS;
switch (quads.getMode()) {
case Quads:
glMode = GL.GL_QUADS;
break;
case Strip:
glMode = GL.GL_QUAD_STRIP;
break;
}
if (!predrawGeometry(quads)) {
// make sure only the necessary indices are sent through on old
// cards.
IntBuffer indices = quads.getIndexBuffer();
indices.rewind();
indices.limit(quads.getMaxIndex());
gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
indices.clear();
} else {
gl.glDrawElements(glMode, quads.getIndexBuffer().limit(),
GL.GL_UNSIGNED_INT, 0);
}
postdrawGeometry(quads);
if (transformed) undoTransforms(quads);
if (Debug.stats) {
StatCollector.endStat(StatType.STAT_RENDER_TIMER);
}
quads.postdraw(this);
}
/**
* <code>draw</code> renders a <code>TriMesh</code> object including
* it's normals, colors, textures and vertices.
*
* @see Renderer#draw(TriMesh)
* @param tris
* the mesh to render.
*/
public void draw(TriMesh tris) {
final GL gl = GLU.getCurrentGL();
if (!tris.predraw(this))
return;
if (Debug.stats) {
StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
}
if (tris.getDisplayListID() != -1) {
renderDisplayList(tris);
return;
}
if (!generatingDisplayList) {
applyStates(tris.states, tris);
}
if (Debug.stats) {
StatCollector.startStat(StatType.STAT_RENDER_TIMER);
}
boolean transformed = doTransforms(tris);
int glMode = GL.GL_TRIANGLES;
switch (tris.getMode()) {
case Triangles:
glMode = GL.GL_TRIANGLES;
break;
case Strip:
glMode = GL.GL_TRIANGLE_STRIP;
break;
case Fan:
glMode = GL.GL_TRIANGLE_FAN;
break;
}
if (!predrawGeometry(tris)) {
// make sure only the necessary indices are sent through on old
// cards.
IntBuffer indices = tris.getIndexBuffer();
if (indices == null) {
logger.severe("missing indices on geometry object: "
+ tris.toString());
} else {
indices.rewind();
indices.limit(tris.getMaxIndex());
gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
indices.clear();
}
} else {
gl.glDrawElements(glMode, tris.getIndexBuffer().limit(),
GL.GL_UNSIGNED_INT, 0);
}
postdrawGeometry(tris);
if (transformed) undoTransforms(tris);
if (Debug.stats) {
StatCollector.endStat(StatType.STAT_RENDER_TIMER);
}
tris.postdraw(this);
}
private synchronized void renderDisplayList(Geometry geom) {
final GL gl = GLU.getCurrentGL();
applyStates(geom.states, geom);
if (Debug.stats) {
StatCollector.startStat(StatType.STAT_RENDER_TIMER);
}
if ((geom.getLocks() & Spatial.LOCKED_TRANSFORMS) == 0) {
boolean transformed = doTransforms(geom);
gl.glCallList(geom.getDisplayListID());
if (transformed) undoTransforms(geom);
} else {
gl.glCallList(geom.getDisplayListID());
}
// invalidate line record as we do not know the line state anymore
((LineRecord) display.getCurrentContext()
.getLineRecord()).invalidate();
// invalidate "current arrays"
reset();
if (Debug.stats) {
StatCollector.endStat(StatType.STAT_RENDER_TIMER);
}
}
/**
* <code>prepVBO</code> binds the geometry data to a vbo buffer and sends
* it to the GPU if necessary. The vbo id is stored in the geometry's
* VBOInfo class. If a new vbo id is created, the VBO is also stored in a
* cache. Before creating a new VBO this cache will be checked to see if a
* VBO is already created for that Buffer.
*
* @param g
* the geometry to initialize VBO for.
*/
protected void prepVBO(Geometry g) {
final GL gl = GLU.getCurrentGL();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -