added sources for Slick

Former-commit-id: 1647fa32ef6894bd7db44f741f07c2f4dcdf9054
Former-commit-id: 0e5810dcfbe1fd59b13e7cabe9f1e93c5542da2d
This commit is contained in:
Song Minjae
2016-12-30 23:29:12 +09:00
parent d1f01a203d
commit d3080ffb78
329 changed files with 58400 additions and 7 deletions

View File

@@ -0,0 +1,72 @@
package org.newdawn.slick.opengl.renderer;
/**
* The default version of the renderer relies of GL calls to do everything.
* Unfortunately this is driver dependent and often implemented inconsistantly
*
* @author kevin
*/
public class DefaultLineStripRenderer implements LineStripRenderer {
/** The access to OpenGL */
private SGL GL = Renderer.get();
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#end()
*/
public void end() {
GL.glEnd();
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#setAntiAlias(boolean)
*/
public void setAntiAlias(boolean antialias) {
if (antialias) {
GL.glEnable(SGL.GL_LINE_SMOOTH);
} else {
GL.glDisable(SGL.GL_LINE_SMOOTH);
}
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#setWidth(float)
*/
public void setWidth(float width) {
GL.glLineWidth(width);
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#start()
*/
public void start() {
GL.glBegin(SGL.GL_LINE_STRIP);
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#vertex(float, float)
*/
public void vertex(float x, float y) {
GL.glVertex2f(x,y);
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#color(float, float, float, float)
*/
public void color(float r, float g, float b, float a) {
GL.glColor4f(r, g, b, a);
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#setLineCaps(boolean)
*/
public void setLineCaps(boolean caps) {
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#applyGLLineFixes()
*/
public boolean applyGLLineFixes() {
return true;
}
}

View File

@@ -0,0 +1,426 @@
package org.newdawn.slick.opengl.renderer;
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.opengl.EXTSecondaryColor;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
/**
* The default OpenGL renderer, uses immediate mode for everything
*
* @author kevin
*/
public class ImmediateModeOGLRenderer implements SGL {
/** The width of the display */
private int width;
/** The height of the display */
private int height;
/** The current colour */
private float[] current = new float[] {1,1,1,1};
/** The global colour scale */
protected float alphaScale = 1;
/**
* @see org.newdawn.slick.opengl.renderer.SGL#initDisplay(int, int)
*/
public void initDisplay(int width, int height) {
this.width = width;
this.height = height;
String extensions = GL11.glGetString(GL11.GL_EXTENSIONS);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glClearDepth(1);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glViewport(0,0,width,height);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#enterOrtho(int, int)
*/
public void enterOrtho(int xsize, int ysize) {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, width, height, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glTranslatef((width-xsize)/2,
(height-ysize)/2,0);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glBegin(int)
*/
public void glBegin(int geomType) {
GL11.glBegin(geomType);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glBindTexture(int, int)
*/
public void glBindTexture(int target, int id) {
GL11.glBindTexture(target, id);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glBlendFunc(int, int)
*/
public void glBlendFunc(int src, int dest) {
GL11.glBlendFunc(src, dest);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glCallList(int)
*/
public void glCallList(int id) {
GL11.glCallList(id);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glClear(int)
*/
public void glClear(int value) {
GL11.glClear(value);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glClearColor(float, float, float, float)
*/
public void glClearColor(float red, float green, float blue, float alpha) {
GL11.glClearColor(red, green, blue, alpha);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glClipPlane(int, java.nio.DoubleBuffer)
*/
public void glClipPlane(int plane, DoubleBuffer buffer) {
GL11.glClipPlane(plane, buffer);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glColor4f(float, float, float, float)
*/
public void glColor4f(float r, float g, float b, float a) {
a *= alphaScale;
current[0] = r;
current[1] = g;
current[2] = b;
current[3] = a;
GL11.glColor4f(r, g, b, a);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glColorMask(boolean, boolean, boolean, boolean)
*/
public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha) {
GL11.glColorMask(red, green, blue, alpha);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glCopyTexImage2D(int, int, int, int, int, int, int, int)
*/
public void glCopyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) {
GL11.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glDeleteTextures(java.nio.IntBuffer)
*/
public void glDeleteTextures(IntBuffer buffer) {
GL11.glDeleteTextures(buffer);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glDisable(int)
*/
public void glDisable(int item) {
GL11.glDisable(item);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glEnable(int)
*/
public void glEnable(int item) {
GL11.glEnable(item);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glEnd()
*/
public void glEnd() {
GL11.glEnd();
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glEndList()
*/
public void glEndList() {
GL11.glEndList();
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glGenLists(int)
*/
public int glGenLists(int count) {
return GL11.glGenLists(count);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glGetFloat(int, java.nio.FloatBuffer)
*/
public void glGetFloat(int id, FloatBuffer ret) {
GL11.glGetFloat(id, ret);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glGetInteger(int, java.nio.IntBuffer)
*/
public void glGetInteger(int id, IntBuffer ret) {
GL11.glGetInteger(id, ret);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glGetTexImage(int, int, int, int, java.nio.ByteBuffer)
*/
public void glGetTexImage(int target, int level, int format, int type, ByteBuffer pixels) {
GL11.glGetTexImage(target, level, format, type, pixels);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glLineWidth(float)
*/
public void glLineWidth(float width) {
GL11.glLineWidth(width);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glLoadIdentity()
*/
public void glLoadIdentity() {
GL11.glLoadIdentity();
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glNewList(int, int)
*/
public void glNewList(int id, int option) {
GL11.glNewList(id, option);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glPointSize(float)
*/
public void glPointSize(float size) {
GL11.glPointSize(size);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glPopMatrix()
*/
public void glPopMatrix() {
GL11.glPopMatrix();
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glPushMatrix()
*/
public void glPushMatrix() {
GL11.glPushMatrix();
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glReadPixels(int, int, int, int, int, int, java.nio.ByteBuffer)
*/
public void glReadPixels(int x, int y, int width, int height, int format, int type, ByteBuffer pixels) {
GL11.glReadPixels(x, y, width, height, format, type, pixels);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glRotatef(float, float, float, float)
*/
public void glRotatef(float angle, float x, float y, float z) {
GL11.glRotatef(angle, x, y, z);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glScalef(float, float, float)
*/
public void glScalef(float x, float y, float z) {
GL11.glScalef(x, y, z);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glScissor(int, int, int, int)
*/
public void glScissor(int x, int y, int width, int height) {
GL11.glScissor(x, y, width, height);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glTexCoord2f(float, float)
*/
public void glTexCoord2f(float u, float v) {
GL11.glTexCoord2f(u, v);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glTexEnvi(int, int, int)
*/
public void glTexEnvi(int target, int mode, int value) {
GL11.glTexEnvi(target, mode, value);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glTranslatef(float, float, float)
*/
public void glTranslatef(float x, float y, float z) {
GL11.glTranslatef(x, y, z);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glVertex2f(float, float)
*/
public void glVertex2f(float x, float y) {
GL11.glVertex2f(x, y);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glVertex3f(float, float, float)
*/
public void glVertex3f(float x, float y, float z) {
GL11.glVertex3f(x, y, z);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#flush()
*/
public void flush() {
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glTexParameteri(int, int, int)
*/
public void glTexParameteri(int target, int param, int value) {
GL11.glTexParameteri(target, param, value);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#getCurrentColor()
*/
public float[] getCurrentColor() {
return current;
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glDeleteLists(int, int)
*/
public void glDeleteLists(int list, int count) {
GL11.glDeleteLists(list, count);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glClearDepth(float)
*/
public void glClearDepth(float value) {
GL11.glClearDepth(value);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glDepthFunc(int)
*/
public void glDepthFunc(int func) {
GL11.glDepthFunc(func);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glDepthMask(boolean)
*/
public void glDepthMask(boolean mask) {
GL11.glDepthMask(mask);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#setGlobalAlphaScale(float)
*/
public void setGlobalAlphaScale(float alphaScale) {
this.alphaScale = alphaScale;
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glLoadMatrix(java.nio.FloatBuffer)
*/
public void glLoadMatrix(FloatBuffer buffer) {
GL11.glLoadMatrix(buffer);
}
/*
* (non-Javadoc)
* @see org.newdawn.slick.opengl.renderer.SGL#glGenTextures(java.nio.IntBuffer)
*/
public void glGenTextures(IntBuffer ids) {
GL11.glGenTextures(ids);
}
/*
* (non-Javadoc)
* @see org.newdawn.slick.opengl.renderer.SGL#glGetError()
*/
public void glGetError() {
GL11.glGetError();
}
/*
* (non-Javadoc)
* @see org.newdawn.slick.opengl.renderer.SGL#glTexImage2D(int, int, int, int, int, int, int, int, java.nio.ByteBuffer)
*/
public void glTexImage2D(int target, int i, int dstPixelFormat,
int width, int height, int j, int srcPixelFormat,
int glUnsignedByte, ByteBuffer textureBuffer) {
GL11.glTexImage2D(target, i, dstPixelFormat, width, height, j, srcPixelFormat,glUnsignedByte,textureBuffer);
}
public void glTexSubImage2D(int glTexture2d, int i, int pageX, int pageY,
int width, int height, int glBgra, int glUnsignedByte,
ByteBuffer scratchByteBuffer) {
GL11.glTexSubImage2D(glTexture2d, i, pageX, pageY, width, height, glBgra, glUnsignedByte, scratchByteBuffer);
}
/*
* (non-Javadoc)
* @see org.newdawn.slick.opengl.renderer.SGL#canTextureMirrorClamp()
*/
public boolean canTextureMirrorClamp() {
return GLContext.getCapabilities().GL_EXT_texture_mirror_clamp;
}
/*
* (non-Javadoc)
* @see org.newdawn.slick.opengl.renderer.SGL#canSecondaryColor()
*/
public boolean canSecondaryColor() {
return GLContext.getCapabilities().GL_EXT_secondary_color;
}
/*
* (non-Javadoc)
* @see org.newdawn.slick.opengl.renderer.SGL#glSecondaryColor3ubEXT(byte, byte, byte)
*/
public void glSecondaryColor3ubEXT(byte b, byte c, byte d) {
EXTSecondaryColor.glSecondaryColor3ubEXT(b,c,d);
}
}

View File

@@ -0,0 +1,66 @@
package org.newdawn.slick.opengl.renderer;
/**
* The description of a class able to render line strips through
* OpenGL
*
* @author kevin
*/
public interface LineStripRenderer {
/**
* Check if we should apply default line fixes
*
* @return True if we should apply GL fixes
*/
public abstract boolean applyGLLineFixes();
/**
* Start the line strips
*/
public abstract void start();
/**
* End the line strips
*/
public abstract void end();
/**
* Add a vertex
*
* @param x The x coordinate of the vertex
* @param y The y coordinate of the vertex
*/
public abstract void vertex(float x, float y);
/**
* Apply a colour to the next vertex
*
* @param r The red component of the colour
* @param g The green component of the colour
* @param b The blue component of the colour
* @param a The alpha component of the colour
*/
public abstract void color(float r, float g, float b, float a);
/**
* Set the width of the lines to be drawn
*
* @param width The width of the lines to be drawn
*/
public abstract void setWidth(float width);
/**
* Indicate whether antialiasing should be applied
*
* @param antialias True if antialiasing should be applied
*/
public abstract void setAntiAlias(boolean antialias);
/**
* Indicate if we should render end caps
*
* @param caps True if we should render end caps
*/
public void setLineCaps(boolean caps);
}

View File

@@ -0,0 +1,293 @@
package org.newdawn.slick.opengl.renderer;
/**
* A line strip renderer that uses quads to generate lines
*
* @author kevin
*/
public class QuadBasedLineStripRenderer implements LineStripRenderer {
/** The renderer used to interact with GL */
private SGL GL = Renderer.get();
/** Maximum number of points allowed in a single strip */
public static int MAX_POINTS = 10000;
/** True if antialiasing is currently enabled */
private boolean antialias;
/** The width of the lines to draw */
private float width = 1;
/** The points to draw */
private float[] points;
/** The colours to draw */
private float[] colours;
/** The number of points to draw */
private int pts;
/** The number of colour points recorded */
private int cpt;
/** The default renderer used when width = 1 */
private DefaultLineStripRenderer def = new DefaultLineStripRenderer();
/** Indicates need to render half colour */
private boolean renderHalf;
/** True if we shoudl render end caps */
private boolean lineCaps = false;
/**
* Create a new strip renderer
*/
public QuadBasedLineStripRenderer() {
points = new float[MAX_POINTS * 2];
colours = new float[MAX_POINTS * 4];
}
/**
* Indicate if we should render end caps
*
* @param caps True if we should render end caps
*/
public void setLineCaps(boolean caps) {
this.lineCaps = caps;
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#start()
*/
public void start() {
if (width == 1) {
def.start();
return;
}
pts = 0;
cpt = 0;
GL.flush();
float[] col = GL.getCurrentColor();
color(col[0],col[1],col[2],col[3]);
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#end()
*/
public void end() {
if (width == 1) {
def.end();
return;
}
renderLines(points, pts);
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#vertex(float, float)
*/
public void vertex(float x, float y) {
if (width == 1) {
def.vertex(x,y);
return;
}
points[(pts*2)] = x;
points[(pts*2)+1] = y;
pts++;
int index = pts-1;
color(colours[(index*4)], colours[(index*4)+1], colours[(index*4)+2], colours[(index*4)+3]);
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#setWidth(float)
*/
public void setWidth(float width) {
this.width = width;
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#setAntiAlias(boolean)
*/
public void setAntiAlias(boolean antialias) {
def.setAntiAlias(antialias);
this.antialias = antialias;
}
/**
* Render the lines applying antialiasing if required
*
* @param points The points to be rendered as lines
* @param count The number of points to render
*/
public void renderLines(float[] points, int count) {
if (antialias) {
GL.glEnable(SGL.GL_POLYGON_SMOOTH);
renderLinesImpl(points,count,width+1f);
}
GL.glDisable(SGL.GL_POLYGON_SMOOTH);
renderLinesImpl(points,count,width);
if (antialias) {
GL.glEnable(SGL.GL_POLYGON_SMOOTH);
}
}
/**
* Render the lines given
*
* @param points The points building up the lines
* @param count The number of points to render
* @param w The width to render at
*/
public void renderLinesImpl(float[] points, int count, float w) {
float width = w / 2;
float lastx1 = 0;
float lasty1 = 0;
float lastx2 = 0;
float lasty2 = 0;
GL.glBegin(SGL.GL_QUADS);
for (int i=0;i<count+1;i++) {
int current = i;
int next = i+1;
int prev = i-1;
if (prev < 0) {
prev += count;
}
if (next >= count) {
next -= count;
}
if (current >= count) {
current -= count;
}
float x1 = points[(current*2)];
float y1 = points[(current*2)+1];
float x2 = points[(next*2)];
float y2 = points[(next*2)+1];
// draw the next segment
float dx = x2 - x1;
float dy = y2 - y1;
if ((dx == 0) && (dy == 0)) {
continue;
}
float d2 = (dx*dx)+(dy*dy);
float d = (float) Math.sqrt(d2);
dx *= width;
dy *= width;
dx /= d;
dy /= d;
float tx = dy;
float ty = -dx;
if (i != 0) {
bindColor(prev);
GL.glVertex3f(lastx1,lasty1,0);
GL.glVertex3f(lastx2,lasty2,0);
bindColor(current);
GL.glVertex3f(x1+tx,y1+ty,0);
GL.glVertex3f(x1-tx,y1-ty,0);
}
lastx1 = x2-tx;
lasty1 = y2-ty;
lastx2 = x2+tx;
lasty2 = y2+ty;
if (i < count-1) {
bindColor(current);
GL.glVertex3f(x1+tx,y1+ty,0);
GL.glVertex3f(x1-tx,y1-ty,0);
bindColor(next);
GL.glVertex3f(x2-tx,y2-ty,0);
GL.glVertex3f(x2+tx,y2+ty,0);
}
}
GL.glEnd();
float step = width <= 12.5f ? 5 : 180 / (float)Math.ceil(width / 2.5);
// start cap
if (lineCaps) {
float dx = points[2] - points[0];
float dy = points[3] - points[1];
float fang = (float) Math.toDegrees(Math.atan2(dy,dx)) + 90;
if ((dx != 0) || (dy != 0)) {
GL.glBegin(SGL.GL_TRIANGLE_FAN);
bindColor(0);
GL.glVertex2f(points[0], points[1]);
for (int i=0;i<180+step;i+=step) {
float ang = (float) Math.toRadians(fang+i);
GL.glVertex2f(points[0]+((float) (Math.cos(ang) * width)),
points[1]+((float) (Math.sin(ang) * width)));
}
GL.glEnd();
}
}
// end cap
if (lineCaps) {
float dx = points[(count*2)-2] - points[(count*2)-4];
float dy = points[(count*2)-1] - points[(count*2)-3];
float fang = (float) Math.toDegrees(Math.atan2(dy,dx)) - 90;
if ((dx != 0) || (dy != 0)) {
GL.glBegin(SGL.GL_TRIANGLE_FAN);
bindColor(count-1);
GL.glVertex2f(points[(count*2)-2], points[(count*2)-1]);
for (int i=0;i<180+step;i+=step) {
float ang = (float) Math.toRadians(fang+i);
GL.glVertex2f(points[(count*2)-2]+((float) (Math.cos(ang) * width)),
points[(count*2)-1]+((float) (Math.sin(ang) * width)));
}
GL.glEnd();
}
}
}
/**
* Bind the colour at a given index in the array
*
* @param index The index of the colour to bind
*/
private void bindColor(int index) {
if (index < cpt) {
if (renderHalf) {
GL.glColor4f(colours[(index*4)]*0.5f, colours[(index*4)+1]*0.5f,
colours[(index*4)+2]*0.5f, colours[(index*4)+3]*0.5f);
} else {
GL.glColor4f(colours[(index*4)], colours[(index*4)+1],
colours[(index*4)+2], colours[(index*4)+3]);
}
}
}
/**
* @see org.newdawn.slick.opengl.renderer.LineStripRenderer#color(float, float, float, float)
*/
public void color(float r, float g, float b, float a) {
if (width == 1) {
def.color(r,g,b,a);
return;
}
colours[(pts*4)] = r;
colours[(pts*4)+1] = g;
colours[(pts*4)+2] = b;
colours[(pts*4)+3] = a;
cpt++;
}
public boolean applyGLLineFixes() {
if (width == 1) {
return def.applyGLLineFixes();
}
return def.applyGLLineFixes();
}
}

View File

@@ -0,0 +1,99 @@
package org.newdawn.slick.opengl.renderer;
/**
* The static holder for the current GL implementation. Note that this
* renderer can only be set before the game has been started.
*
* @author kevin
*/
public class Renderer {
/** The indicator for immediate mode renderering (the default) */
public static final int IMMEDIATE_RENDERER = 1;
/** The indicator for vertex array based rendering */
public static final int VERTEX_ARRAY_RENDERER = 2;
/** The indicator for direct GL line renderer (the default) */
public static final int DEFAULT_LINE_STRIP_RENDERER = 3;
/** The indicator for consistant quad based lines */
public static final int QUAD_BASED_LINE_STRIP_RENDERER = 4;
/** The renderer in use */
private static SGL renderer = new ImmediateModeOGLRenderer();
/** The line strip renderer to use */
private static LineStripRenderer lineStripRenderer = new DefaultLineStripRenderer();
/**
* Set the renderer to one of the known types
*
* @param type The type of renderer to use
*/
public static void setRenderer(int type) {
switch (type) {
case IMMEDIATE_RENDERER:
setRenderer(new ImmediateModeOGLRenderer());
return;
case VERTEX_ARRAY_RENDERER:
setRenderer(new VAOGLRenderer());
return;
}
throw new RuntimeException("Unknown renderer type: "+type);
}
/**
* Set the line strip renderer to one of the known types
*
* @param type The type of renderer to use
*/
public static void setLineStripRenderer(int type) {
switch (type) {
case DEFAULT_LINE_STRIP_RENDERER:
setLineStripRenderer(new DefaultLineStripRenderer());
return;
case QUAD_BASED_LINE_STRIP_RENDERER:
setLineStripRenderer(new QuadBasedLineStripRenderer());
return;
}
throw new RuntimeException("Unknown line strip renderer type: "+type);
}
/**
* Set the line strip renderer to be used globally
*
* @param renderer The line strip renderer to be used
*/
public static void setLineStripRenderer(LineStripRenderer renderer) {
lineStripRenderer = renderer;
}
/**
* Set the renderer to be used
*
* @param r The renderer to be used
*/
public static void setRenderer(SGL r) {
renderer = r;
}
/**
* Get the renderer to be used when accessing GL
*
* @return The renderer to be used when accessing GL
*/
public static SGL get() {
return renderer;
}
/**
* Get the line strip renderer to use
*
* @return The line strip renderer to use
*/
public static LineStripRenderer getLineStripRenderer() {
return lineStripRenderer;
}
}

View File

@@ -0,0 +1,535 @@
package org.newdawn.slick.opengl.renderer;
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.opengl.EXTSecondaryColor;
import org.lwjgl.opengl.EXTTextureMirrorClamp;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
/**
* The description of the OpenGL functions used Slick. Any other rendering method will
* need to emulate these.
*
* @author kevin
*/
public interface SGL {
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_TEXTURE_2D = GL11.GL_TEXTURE_2D;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_RGBA = GL11.GL_RGBA;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_RGB = GL11.GL_RGB;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_UNSIGNED_BYTE = GL11.GL_UNSIGNED_BYTE;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_LINEAR = GL11.GL_LINEAR;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_NEAREST = GL11.GL_NEAREST;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_TEXTURE_MIN_FILTER = GL11.GL_TEXTURE_MIN_FILTER;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_TEXTURE_MAG_FILTER = GL11.GL_TEXTURE_MAG_FILTER;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_POINT_SMOOTH = GL11.GL_POINT_SMOOTH;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_POLYGON_SMOOTH = GL11.GL_POLYGON_SMOOTH;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_LINE_SMOOTH = GL11.GL_LINE_SMOOTH;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_SCISSOR_TEST = GL11.GL_SCISSOR_TEST;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_MODULATE = GL11.GL_MODULATE;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_TEXTURE_ENV = GL11.GL_TEXTURE_ENV;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_TEXTURE_ENV_MODE = GL11.GL_TEXTURE_ENV_MODE;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_QUADS = GL11.GL_QUADS;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_POINTS = GL11.GL_POINTS;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_LINES = GL11.GL_LINES;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_LINE_STRIP = GL11.GL_LINE_STRIP;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_TRIANGLES = GL11.GL_TRIANGLES;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_TRIANGLE_FAN = GL11.GL_TRIANGLE_FAN;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_SRC_ALPHA = GL11.GL_SRC_ALPHA;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_ONE = GL11.GL_ONE;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_ONE_MINUS_DST_ALPHA = GL11.GL_ONE_MINUS_DST_ALPHA;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_DST_ALPHA = GL11.GL_DST_ALPHA;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_ONE_MINUS_SRC_ALPHA = GL11.GL_ONE_MINUS_SRC_ALPHA;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_COMPILE = GL11.GL_COMPILE;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_MAX_TEXTURE_SIZE = GL11.GL_MAX_TEXTURE_SIZE;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_COLOR_BUFFER_BIT = GL11.GL_COLOR_BUFFER_BIT;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_DEPTH_BUFFER_BIT = GL11.GL_DEPTH_BUFFER_BIT;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_BLEND = GL11.GL_BLEND;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_COLOR_CLEAR_VALUE = GL11.GL_COLOR_CLEAR_VALUE;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_LINE_WIDTH = GL11.GL_LINE_WIDTH;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_CLIP_PLANE0 = GL11.GL_CLIP_PLANE0;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_CLIP_PLANE1 = GL11.GL_CLIP_PLANE1;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_CLIP_PLANE2 = GL11.GL_CLIP_PLANE2;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_CLIP_PLANE3 = GL11.GL_CLIP_PLANE3;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_COMPILE_AND_EXECUTE = GL11.GL_COMPILE_AND_EXECUTE;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_RGBA8 = GL11.GL_RGBA;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_RGBA16 = GL11.GL_RGBA16;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_BGRA = GL12.GL_BGRA;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_MIRROR_CLAMP_TO_EDGE_EXT = EXTTextureMirrorClamp.GL_MIRROR_CLAMP_TO_EDGE_EXT;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_TEXTURE_WRAP_S = GL11.GL_TEXTURE_WRAP_S;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_TEXTURE_WRAP_T = GL11.GL_TEXTURE_WRAP_T;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_CLAMP = GL11.GL_CLAMP;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_COLOR_SUM_EXT = EXTSecondaryColor.GL_COLOR_SUM_EXT;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_ALWAYS = GL11.GL_ALWAYS;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_DEPTH_TEST = GL11.GL_DEPTH_TEST;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_NOTEQUAL = GL11.GL_NOTEQUAL;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_EQUAL = GL11.GL_EQUAL;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_SRC_COLOR = GL11.GL_SRC_COLOR;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_ONE_MINUS_SRC_COLOR = GL11.GL_ONE_MINUS_SRC_COLOR;
/** OpenGL Enum - @url http://www.opengl.org/documentation */
public static final int GL_MODELVIEW_MATRIX = GL11.GL_MODELVIEW_MATRIX;
/**
* Flush the current state of the renderer down to GL
*/
public void flush();
/**
* Initialise the display
*
* @param width The width of the display
* @param height The height of the display
*/
public void initDisplay(int width, int height);
/**
* Enter orthographic mode
*
* @param xsize The size of the ortho display
* @param ysize The size of the ortho display
*/
public void enterOrtho(int xsize, int ysize);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param red
* @param green
* @param blue
* @param alpha
*/
public void glClearColor(float red, float green, float blue, float alpha);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param plane
* @param buffer
*/
public void glClipPlane(int plane, DoubleBuffer buffer);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param x
* @param y
* @param width
* @param height
*/
public void glScissor(int x, int y, int width, int height);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param width
*/
public void glLineWidth(float width);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param value
*/
public void glClear(int value);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param red
* @param green
* @param blue
* @param alpha
*/
public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*/
public void glLoadIdentity();
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param id
* @param ret
*/
public void glGetInteger(int id, IntBuffer ret);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param id
* @param ret
*/
public void glGetFloat(int id, FloatBuffer ret);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param item
*/
public void glEnable(int item);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param item
*/
public void glDisable(int item);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param target
* @param id
*/
public void glBindTexture(int target, int id);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param target
* @param level
* @param format
* @param type
* @param pixels
*/
public void glGetTexImage(int target, int level, int format, int type, ByteBuffer pixels);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param buffer
*/
public void glDeleteTextures(IntBuffer buffer);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param r
* @param g
* @param b
* @param a
*/
public void glColor4f(float r, float g, float b, float a);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param u
* @param v
*/
public void glTexCoord2f(float u, float v);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param x
* @param y
* @param z
*/
public void glVertex3f(float x, float y, float z);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param x
* @param y
*/
public void glVertex2f(float x, float y);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param angle
* @param x
* @param y
* @param z
*/
public void glRotatef(float angle, float x, float y, float z);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param x
* @param y
* @param z
*/
public void glTranslatef(float x, float y, float z);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param geomType
*/
public void glBegin(int geomType);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*/
public void glEnd();
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param target
* @param mode
* @param value
*/
public void glTexEnvi(int target, int mode, int value);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param size
*/
public void glPointSize(float size);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param x
* @param y
* @param z
*/
public void glScalef(float x, float y, float z);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*/
public void glPushMatrix();
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*/
public void glPopMatrix();
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param src
* @param dest
*/
public void glBlendFunc(int src, int dest);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param count
* @return The index of the lists
*/
public int glGenLists(int count);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param id
* @param option
*/
public void glNewList(int id, int option);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*/
public void glEndList();
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param id
*/
public void glCallList(int id);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param target
* @param level
* @param internalFormat
* @param x
* @param y
* @param width
* @param height
* @param border
*/
public void glCopyTexImage2D(int target, int level, int internalFormat,
int x, int y, int width, int height, int border);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param x
* @param y
* @param width
* @param height
* @param format
* @param type
* @param pixels
*/
public void glReadPixels(int x, int y, int width, int height, int format, int type,
ByteBuffer pixels);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param target
* @param param
* @param value
*/
public void glTexParameteri(int target, int param, int value);
/**
* Get the current colour being rendered
*
* @return The current colour being rendered
*/
public float[] getCurrentColor();
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param list
* @param count
*/
public void glDeleteLists(int list, int count);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param mask
*/
public void glDepthMask(boolean mask);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param value
*/
public void glClearDepth(float value);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param func
*/
public void glDepthFunc(int func);
/**
* Set the scaling we'll apply to any colour binds in this renderer
*
* @param alphaScale The scale to apply to any colour binds
*/
public void setGlobalAlphaScale(float alphaScale);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param buffer
*/
public void glLoadMatrix(FloatBuffer buffer);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*
* @param ids
*/
public void glGenTextures(IntBuffer ids);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*/
public void glGetError();
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*/
public void glTexImage2D(int target, int i, int dstPixelFormat,
int get2Fold, int get2Fold2, int j, int srcPixelFormat,
int glUnsignedByte, ByteBuffer textureBuffer);
/**
* OpenGL Method - @url http://www.opengl.org/documentation/
*/
public void glTexSubImage2D(int glTexture2d, int i, int pageX, int pageY,
int width, int height, int glBgra, int glUnsignedByte,
ByteBuffer scratchByteBuffer);
/**
* Check if the mirror clamp extension is available
*
* @return True if the mirro clamp extension is available
*/
public boolean canTextureMirrorClamp();
public boolean canSecondaryColor();
public void glSecondaryColor3ubEXT(byte b, byte c, byte d);
}

View File

@@ -0,0 +1,417 @@
package org.newdawn.slick.opengl.renderer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
/**
* A renderer that caches all operations into an array, creates an opengl vertex array when
* required and spits the data down to the card in batch mode
*
* @author kevin
*/
public class VAOGLRenderer extends ImmediateModeOGLRenderer {
/** The tolerance to rendering immediate */
private static final int TOLERANCE = 20;
/** Indicates there is no current geometry buffer */
public static final int NONE = -1;
/** The maximum number of vertices draw in one batch */
public static final int MAX_VERTS = 5000;
/** The type of the geometry array currently being built - i.e. GL_QUADS */
private int currentType = NONE;
/** The last colour applied */
private float[] color = new float[] {1f,1f,1f,1f};
/** The last texture applied */
private float[] tex = new float[] {0f,0f};
/** The index of the next vertex to be created */
private int vertIndex;
/** The vertex data cached */
private float[] verts = new float[MAX_VERTS*3];
/** The vertex colour data cached */
private float[] cols = new float[MAX_VERTS*4];
/** The vertex texture coordiante data cached */
private float[] texs = new float[MAX_VERTS*3];
/** The buffer used to pass the vertex data to the card */
private FloatBuffer vertices = BufferUtils.createFloatBuffer(MAX_VERTS * 3);
/** The buffer used to pass the vertex color data to the card */
private FloatBuffer colors = BufferUtils.createFloatBuffer(MAX_VERTS * 4);
/** The buffer used to pass the vertex texture coordinate data to the card */
private FloatBuffer textures = BufferUtils.createFloatBuffer(MAX_VERTS * 2);
/** The stack for entering list creation mode - when we're creating a list we can't use our VAs */
private int listMode = 0;
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#initDisplay(int, int)
*/
public void initDisplay(int width, int height) {
super.initDisplay(width, height);
startBuffer();
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
}
/**
* Start a new buffer for a vertex array
*/
private void startBuffer() {
vertIndex = 0;
}
/**
* Flush the currently cached data down to the card
*/
private void flushBuffer() {
if (vertIndex == 0) {
return;
}
if (currentType == NONE) {
return;
}
if (vertIndex < TOLERANCE) {
GL11.glBegin(currentType);
for (int i=0;i<vertIndex;i++) {
GL11.glColor4f(cols[(i*4)+0], cols[(i*4)+1], cols[(i*4)+2], cols[(i*4)+3]);
GL11.glTexCoord2f(texs[(i*2)+0], texs[(i*2)+1]);
GL11.glVertex3f(verts[(i*3)+0], verts[(i*3)+1], verts[(i*3)+2]);
}
GL11.glEnd();
currentType = NONE;
return;
}
vertices.clear();
colors.clear();
textures.clear();
vertices.put(verts,0,vertIndex*3);
colors.put(cols,0,vertIndex*4);
textures.put(texs,0,vertIndex*2);
vertices.flip();
colors.flip();
textures.flip();
GL11.glVertexPointer(3,0,vertices);
GL11.glColorPointer(4,0,colors);
GL11.glTexCoordPointer(2,0,textures);
GL11.glDrawArrays(currentType, 0, vertIndex);
currentType = NONE;
}
/**
* Apply the current buffer and restart it
*/
private void applyBuffer() {
if (listMode > 0) {
return;
}
if (vertIndex != 0) {
flushBuffer();
startBuffer();
}
super.glColor4f(color[0], color[1], color[2], color[3]);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#flush()
*/
public void flush() {
super.flush();
applyBuffer();
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glBegin(int)
*/
public void glBegin(int geomType) {
if (listMode > 0) {
super.glBegin(geomType);
return;
}
if (currentType != geomType) {
applyBuffer();
currentType = geomType;
}
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glColor4f(float, float, float, float)
*/
public void glColor4f(float r, float g, float b, float a) {
a *= alphaScale;
color[0] = r;
color[1] = g;
color[2] = b;
color[3] = a;
if (listMode > 0) {
super.glColor4f(r,g,b,a);
return;
}
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glEnd()
*/
public void glEnd() {
if (listMode > 0) {
super.glEnd();
return;
}
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glTexCoord2f(float, float)
*/
public void glTexCoord2f(float u, float v) {
if (listMode > 0) {
super.glTexCoord2f(u,v);
return;
}
tex[0] = u;
tex[1] = v;
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glVertex2f(float, float)
*/
public void glVertex2f(float x, float y) {
if (listMode > 0) {
super.glVertex2f(x,y);
return;
}
glVertex3f(x,y,0);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glVertex3f(float, float, float)
*/
public void glVertex3f(float x, float y, float z) {
if (listMode > 0) {
super.glVertex3f(x,y,z);
return;
}
verts[(vertIndex*3)+0] = x;
verts[(vertIndex*3)+1] = y;
verts[(vertIndex*3)+2] = z;
cols[(vertIndex*4)+0] = color[0];
cols[(vertIndex*4)+1] = color[1];
cols[(vertIndex*4)+2] = color[2];
cols[(vertIndex*4)+3] = color[3];
texs[(vertIndex*2)+0] = tex[0];
texs[(vertIndex*2)+1] = tex[1];
vertIndex++;
if (vertIndex > MAX_VERTS - 50) {
if (isSplittable(vertIndex, currentType)) {
int type = currentType;
applyBuffer();
currentType = type;
}
}
}
/**
* Check if the geometry being created can be split at the current index
*
* @param count The current index
* @param type The type of geometry being built
* @return True if the geometry can be split at the current index
*/
private boolean isSplittable(int count, int type) {
switch (type) {
case GL11.GL_QUADS:
return count % 4 == 0;
case GL11.GL_TRIANGLES:
return count % 3 == 0;
case GL11.GL_LINE:
return count % 2 == 0;
}
return false;
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glBindTexture(int, int)
*/
public void glBindTexture(int target, int id) {
applyBuffer();
super.glBindTexture(target, id);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glBlendFunc(int, int)
*/
public void glBlendFunc(int src, int dest) {
applyBuffer();
super.glBlendFunc(src, dest);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glCallList(int)
*/
public void glCallList(int id) {
applyBuffer();
super.glCallList(id);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glClear(int)
*/
public void glClear(int value) {
applyBuffer();
super.glClear(value);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glClipPlane(int, java.nio.DoubleBuffer)
*/
public void glClipPlane(int plane, DoubleBuffer buffer) {
applyBuffer();
super.glClipPlane(plane, buffer);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glColorMask(boolean, boolean, boolean, boolean)
*/
public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha) {
applyBuffer();
super.glColorMask(red, green, blue, alpha);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glDisable(int)
*/
public void glDisable(int item) {
applyBuffer();
super.glDisable(item);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glEnable(int)
*/
public void glEnable(int item) {
applyBuffer();
super.glEnable(item);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glLineWidth(float)
*/
public void glLineWidth(float width) {
applyBuffer();
super.glLineWidth(width);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glPointSize(float)
*/
public void glPointSize(float size) {
applyBuffer();
super.glPointSize(size);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glPopMatrix()
*/
public void glPopMatrix() {
applyBuffer();
super.glPopMatrix();
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glPushMatrix()
*/
public void glPushMatrix() {
applyBuffer();
super.glPushMatrix();
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glRotatef(float, float, float, float)
*/
public void glRotatef(float angle, float x, float y, float z) {
applyBuffer();
super.glRotatef(angle, x, y, z);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glScalef(float, float, float)
*/
public void glScalef(float x, float y, float z) {
applyBuffer();
super.glScalef(x, y, z);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glScissor(int, int, int, int)
*/
public void glScissor(int x, int y, int width, int height) {
applyBuffer();
super.glScissor(x, y, width, height);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glTexEnvi(int, int, int)
*/
public void glTexEnvi(int target, int mode, int value) {
applyBuffer();
super.glTexEnvi(target, mode, value);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glTranslatef(float, float, float)
*/
public void glTranslatef(float x, float y, float z) {
applyBuffer();
super.glTranslatef(x, y, z);
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glEndList()
*/
public void glEndList() {
listMode--;
super.glEndList();
}
/**
* @see org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer#glNewList(int, int)
*/
public void glNewList(int id, int option) {
listMode++;
super.glNewList(id, option);
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#getCurrentColor()
*/
public float[] getCurrentColor() {
return color;
}
/**
* @see org.newdawn.slick.opengl.renderer.SGL#glLoadMatrix(java.nio.FloatBuffer)
*/
public void glLoadMatrix(FloatBuffer buffer) {
flushBuffer();
super.glLoadMatrix(buffer);
}
}