@ -42,7 +42,6 @@ import static org.lwjgl.opengl.GL11.*;
public class LwjglGL1Renderer implements GL1Renderer {
public class LwjglGL1Renderer implements GL1Renderer {
private static final Logger logger = Logger . getLogger ( LwjglRenderer . class . getName ( ) ) ;
private static final Logger logger = Logger . getLogger ( LwjglRenderer . class . getName ( ) ) ;
private final ByteBuffer nameBuf = BufferUtils . createByteBuffer ( 250 ) ;
private final ByteBuffer nameBuf = BufferUtils . createByteBuffer ( 250 ) ;
private final StringBuilder stringBuf = new StringBuilder ( 250 ) ;
private final StringBuilder stringBuf = new StringBuilder ( 250 ) ;
private final IntBuffer ib1 = BufferUtils . createIntBuffer ( 1 ) ;
private final IntBuffer ib1 = BufferUtils . createIntBuffer ( 1 ) ;
@ -51,20 +50,16 @@ public class LwjglGL1Renderer implements GL1Renderer {
private final RenderContext context = new RenderContext ( ) ;
private final RenderContext context = new RenderContext ( ) ;
private final GLObjectManager objManager = new GLObjectManager ( ) ;
private final GLObjectManager objManager = new GLObjectManager ( ) ;
private final EnumSet < Caps > caps = EnumSet . noneOf ( Caps . class ) ;
private final EnumSet < Caps > caps = EnumSet . noneOf ( Caps . class ) ;
private int maxTexSize ;
private int maxTexSize ;
private int maxCubeTexSize ;
private int maxCubeTexSize ;
private int maxVertCount ;
private int maxVertCount ;
private int maxTriCount ;
private int maxTriCount ;
private final Statistics statistics = new Statistics ( ) ;
private final Statistics statistics = new Statistics ( ) ;
private int vpX , vpY , vpW , vpH ;
private int vpX , vpY , vpW , vpH ;
private int clipX , clipY , clipW , clipH ;
private int clipX , clipY , clipW , clipH ;
// private Matrix4f worldMatrix = new Matrix4f();
// private Matrix4f worldMatrix = new Matrix4f();
private Matrix4f viewMatrix = new Matrix4f ( ) ;
private Matrix4f viewMatrix = new Matrix4f ( ) ;
// private Matrix4f projMatrix = new Matrix4f();
// private Matrix4f projMatrix = new Matrix4f();
private boolean colorSet = false ;
private boolean colorSet = false ;
private boolean materialSet = false ;
private boolean materialSet = false ;
@ -93,16 +88,16 @@ public class LwjglGL1Renderer implements GL1Renderer {
glShadeModel ( GL_SMOOTH ) ;
glShadeModel ( GL_SMOOTH ) ;
glHint ( GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST ) ;
glHint ( GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST ) ;
if ( GLContext . getCapabilities ( ) . GL_ARB_texture_non_power_of_two ) {
if ( GLContext . getCapabilities ( ) . GL_ARB_texture_non_power_of_two ) {
caps . add ( Caps . NonPowerOfTwoTextures ) ;
caps . add ( Caps . NonPowerOfTwoTextures ) ;
} else {
} else {
logger . log ( Level . WARNING , "Your graphics card does not "
logger . log ( Level . WARNING , "Your graphics card does not "
+ "support non-power-of-2 textures. "
+ "support non-power-of-2 textures. "
+ "Some features might not work." ) ;
+ "Some features might not work." ) ;
}
}
}
}
public void invalidateState ( ) {
public void invalidateState ( ) {
context . reset ( ) ;
context . reset ( ) ;
}
}
@ -143,8 +138,8 @@ public class LwjglGL1Renderer implements GL1Renderer {
glClearColor ( color . r , color . g , color . b , color . a ) ;
glClearColor ( color . r , color . g , color . b , color . a ) ;
}
}
private void setMaterialColor ( int type , ColorRGBA color ) {
private void setMaterialColor ( int type , ColorRGBA color ) {
if ( ! materialSet ) {
if ( ! materialSet ) {
materialSet = true ;
materialSet = true ;
glEnable ( GL_COLOR_MATERIAL ) ;
glEnable ( GL_COLOR_MATERIAL ) ;
}
}
@ -155,8 +150,8 @@ public class LwjglGL1Renderer implements GL1Renderer {
glMaterial ( GL_FRONT_AND_BACK , type , fb16 ) ;
glMaterial ( GL_FRONT_AND_BACK , type , fb16 ) ;
}
}
public void setFixedFuncBinding ( FixedFuncBinding ffBinding , Object val ) {
public void setFixedFuncBinding ( FixedFuncBinding ffBinding , Object val ) {
switch ( ffBinding ) {
switch ( ffBinding ) {
case Color :
case Color :
ColorRGBA color = ( ColorRGBA ) val ;
ColorRGBA color = ( ColorRGBA ) val ;
glColor4f ( color . r , color . g , color . b , color . a ) ;
glColor4f ( color . r , color . g , color . b , color . a ) ;
@ -177,12 +172,12 @@ public class LwjglGL1Renderer implements GL1Renderer {
}
}
}
}
public void clearSetFixedFuncBindings ( ) {
public void clearSetFixedFuncBindings ( ) {
if ( colorSet ) {
if ( colorSet ) {
glColor4f ( 1 , 1 , 1 , 1 ) ;
glColor4f ( 1 , 1 , 1 , 1 ) ;
colorSet = false ;
colorSet = false ;
}
}
if ( materialSet ) {
if ( materialSet ) {
glDisable ( GL_COLOR_MATERIAL ) ;
glDisable ( GL_COLOR_MATERIAL ) ;
materialSet = false ; // TODO: not efficient
materialSet = false ; // TODO: not efficient
}
}
@ -231,7 +226,7 @@ public class LwjglGL1Renderer implements GL1Renderer {
context . colorWriteEnabled = false ;
context . colorWriteEnabled = false ;
}
}
if ( state . isPointSprite ( ) ) {
if ( state . isPointSprite ( ) ) {
logger . log ( Level . WARNING , "Point Sprite unsupported!" ) ;
logger . log ( Level . WARNING , "Point Sprite unsupported!" ) ;
}
}
@ -325,8 +320,9 @@ public class LwjglGL1Renderer implements GL1Renderer {
context . blendMode = state . getBlendMode ( ) ;
context . blendMode = state . getBlendMode ( ) ;
}
}
if ( state . isStencilTest ( ) )
if ( state . isStencilTest ( ) ) {
throw new UnsupportedOperationException ( "OpenGL 1.1 doesn't support two sided stencil operations." ) ;
throw new UnsupportedOperationException ( "OpenGL 1.1 doesn't support two sided stencil operations." ) ;
}
}
}
@ -519,11 +515,11 @@ public class LwjglGL1Renderer implements GL1Renderer {
}
}
// Check sizes if graphics card doesn't support NPOT
// Check sizes if graphics card doesn't support NPOT
if ( ! GLContext . getCapabilities ( ) . GL_ARB_texture_non_power_of_two ) {
if ( ! GLContext . getCapabilities ( ) . GL_ARB_texture_non_power_of_two ) {
if ( img . getWidth ( ) ! = 0 & & img . getHeight ( ) ! = 0 ) {
if ( img . getWidth ( ) ! = 0 & & img . getHeight ( ) ! = 0 ) {
if ( ! FastMath . isPowerOfTwo ( img . getWidth ( ) )
if ( ! FastMath . isPowerOfTwo ( img . getWidth ( ) )
| | ! FastMath . isPowerOfTwo ( img . getHeight ( ) )
| | ! FastMath . isPowerOfTwo ( img . getHeight ( ) )
| | img . getWidth ( ) ! = img . getHeight ( ) ) {
| | img . getWidth ( ) ! = img . getHeight ( ) ) {
// Resize texture to Power-of-2 size
// Resize texture to Power-of-2 size
MipMapGenerator . resizeToPowerOf2 ( img ) ;
MipMapGenerator . resizeToPowerOf2 ( img ) ;
@ -537,9 +533,9 @@ public class LwjglGL1Renderer implements GL1Renderer {
// generate from base level if required
// generate from base level if required
// Check if hardware mips are supported
// Check if hardware mips are supported
if ( GLContext . getCapabilities ( ) . OpenGL14 ) {
if ( GLContext . getCapabilities ( ) . OpenGL14 ) {
glTexParameteri ( target , GL14 . GL_GENERATE_MIPMAP , GL_TRUE ) ;
glTexParameteri ( target , GL14 . GL_GENERATE_MIPMAP , GL_TRUE ) ;
} else {
} else {
MipMapGenerator . generateMipMaps ( img ) ;
MipMapGenerator . generateMipMaps ( img ) ;
}
}
} else {
} else {
@ -547,33 +543,33 @@ public class LwjglGL1Renderer implements GL1Renderer {
/ *
/ *
if ( target = = GL_TEXTURE_CUBE_MAP ) {
if ( target = = GL_TEXTURE_CUBE_MAP ) {
List < ByteBuffer > data = img . getData ( ) ;
List < ByteBuffer > data = img . getData ( ) ;
if ( data . size ( ) ! = 6 ) {
if ( data . size ( ) ! = 6 ) {
logger . log ( Level . WARNING , "Invalid texture: {0}\n"
logger . log ( Level . WARNING , "Invalid texture: {0}\n"
+ "Cubemap textures must contain 6 data units." , img ) ;
+ "Cubemap textures must contain 6 data units." , img ) ;
return ;
return ;
}
}
for ( int i = 0 ; i < 6 ; i + + ) {
for ( int i = 0 ; i < 6 ; i + + ) {
TextureUtil . uploadTexture ( img , GL_TEXTURE_CUBE_MAP_POSITIVE_X + i , i , 0 , tdc ) ;
TextureUtil . uploadTexture ( img , GL_TEXTURE_CUBE_MAP_POSITIVE_X + i , i , 0 , tdc ) ;
}
}
} else if ( target = = EXTTextureArray . GL_TEXTURE_2D_ARRAY_EXT ) {
} else if ( target = = EXTTextureArray . GL_TEXTURE_2D_ARRAY_EXT ) {
List < ByteBuffer > data = img . getData ( ) ;
List < ByteBuffer > data = img . getData ( ) ;
// -1 index specifies prepare data for 2D Array
// -1 index specifies prepare data for 2D Array
TextureUtil . uploadTexture ( img , target , - 1 , 0 , tdc ) ;
TextureUtil . uploadTexture ( img , target , - 1 , 0 , tdc ) ;
for ( int i = 0 ; i < data . size ( ) ; i + + ) {
for ( int i = 0 ; i < data . size ( ) ; i + + ) {
// upload each slice of 2D array in turn
// upload each slice of 2D array in turn
// this time with the appropriate index
// this time with the appropriate index
TextureUtil . uploadTexture ( img , target , i , 0 , tdc ) ;
TextureUtil . uploadTexture ( img , target , i , 0 , tdc ) ;
}
}
} else { * /
} else { * /
TextureUtil . uploadTexture ( img , target , 0 , 0 , false ) ;
TextureUtil . uploadTexture ( img , target , 0 , 0 , false ) ;
//}
//}
img . clearUpdateNeeded ( ) ;
img . clearUpdateNeeded ( ) ;
}
}
public void setTexture ( int unit , Texture tex ) {
public void setTexture ( int unit , Texture tex ) {
if ( unit ! = 0 | | tex . getType ( ) ! = Texture . Type . TwoDimensional ) {
if ( unit ! = 0 | | tex . getType ( ) ! = Texture . Type . TwoDimensional ) {
//throw new UnsupportedOperationException();
//throw new UnsupportedOperationException();
return ;
return ;
}
}
@ -617,7 +613,7 @@ public class LwjglGL1Renderer implements GL1Renderer {
private void checkTexturingUsed ( ) {
private void checkTexturingUsed ( ) {
Image [ ] textures = context . boundTextures ;
Image [ ] textures = context . boundTextures ;
if ( textures [ 0 ] ! = null ) {
if ( textures [ 0 ] ! = null ) {
glDisable ( GL_TEXTURE_2D ) ;
glDisable ( GL_TEXTURE_2D ) ;
textures [ 0 ] = null ;
textures [ 0 ] = null ;
}
}
@ -691,8 +687,9 @@ public class LwjglGL1Renderer implements GL1Renderer {
}
}
public void drawTriangleArray ( Mesh . Mode mode , int count , int vertCount ) {
public void drawTriangleArray ( Mesh . Mode mode , int count , int vertCount ) {
if ( count > 1 )
if ( count > 1 ) {
throw new UnsupportedOperationException ( ) ;
throw new UnsupportedOperationException ( ) ;
}
glDrawArrays ( convertElementMode ( mode ) , 0 , vertCount ) ;
glDrawArrays ( convertElementMode ( mode ) , 0 , vertCount ) ;
}
}
@ -725,31 +722,34 @@ public class LwjglGL1Renderer implements GL1Renderer {
switch ( vb . getBufferType ( ) ) {
switch ( vb . getBufferType ( ) ) {
case Position :
case Position :
if ( ! ( data instanceof FloatBuffer ) )
if ( ! ( data instanceof FloatBuffer ) ) {
throw new UnsupportedOperationException ( ) ;
throw new UnsupportedOperationException ( ) ;
}
glVertexPointer ( comps , vb . getStride ( ) , ( FloatBuffer ) data ) ;
glVertexPointer ( comps , vb . getStride ( ) , ( FloatBuffer ) data ) ;
break ;
break ;
case Normal :
case Normal :
if ( ! ( data instanceof FloatBuffer ) )
if ( ! ( data instanceof FloatBuffer ) ) {
throw new UnsupportedOperationException ( ) ;
throw new UnsupportedOperationException ( ) ;
}
glNormalPointer ( vb . getStride ( ) , ( FloatBuffer ) data ) ;
glNormalPointer ( vb . getStride ( ) , ( FloatBuffer ) data ) ;
break ;
break ;
case Color :
case Color :
if ( data instanceof FloatBuffer ) {
if ( data instanceof FloatBuffer ) {
glColorPointer ( comps , vb . getStride ( ) , ( FloatBuffer ) data ) ;
glColorPointer ( comps , vb . getStride ( ) , ( FloatBuffer ) data ) ;
} else if ( data instanceof ByteBuffer ) {
} else if ( data instanceof ByteBuffer ) {
glColorPointer ( comps , true , vb . getStride ( ) , ( ByteBuffer ) data ) ;
glColorPointer ( comps , true , vb . getStride ( ) , ( ByteBuffer ) data ) ;
} else {
} else {
throw new UnsupportedOperationException ( ) ;
throw new UnsupportedOperationException ( ) ;
}
}
break ;
break ;
case TexCoord :
case TexCoord :
if ( ! ( data instanceof FloatBuffer ) )
if ( ! ( data instanceof FloatBuffer ) ) {
throw new UnsupportedOperationException ( ) ;
throw new UnsupportedOperationException ( ) ;
}
glTexCoordPointer ( comps , vb . getStride ( ) , ( FloatBuffer ) data ) ;
glTexCoordPointer ( comps , vb . getStride ( ) , ( FloatBuffer ) data ) ;
break ;
break ;
default :
default :
// Ignore, this is an unsupported attribute for OpenGL1.
// Ignore, this is an unsupported attribute for OpenGL1.
@ -761,16 +761,16 @@ public class LwjglGL1Renderer implements GL1Renderer {
setVertexAttrib ( vb , null ) ;
setVertexAttrib ( vb , null ) ;
}
}
private void drawElements ( int mode , int format , Buffer data ) {
private void drawElements ( int mode , int format , Buffer data ) {
switch ( format ) {
switch ( format ) {
case GL_UNSIGNED_BYTE :
case GL_UNSIGNED_BYTE :
glDrawElements ( mode , ( ByteBuffer ) data ) ;
glDrawElements ( mode , ( ByteBuffer ) data ) ;
break ;
break ;
case GL_UNSIGNED_SHORT :
case GL_UNSIGNED_SHORT :
glDrawElements ( mode , ( ShortBuffer ) data ) ;
glDrawElements ( mode , ( ShortBuffer ) data ) ;
break ;
break ;
case GL_UNSIGNED_INT :
case GL_UNSIGNED_INT :
glDrawElements ( mode , ( IntBuffer ) data ) ;
glDrawElements ( mode , ( IntBuffer ) data ) ;
break ;
break ;
default :
default :
throw new UnsupportedOperationException ( ) ;
throw new UnsupportedOperationException ( ) ;
@ -788,38 +788,36 @@ public class LwjglGL1Renderer implements GL1Renderer {
/ *
/ *
int [ ] modeStart = mesh . getModeStart ( ) ;
int [ ] modeStart = mesh . getModeStart ( ) ;
int [ ] elementLengths = mesh . getElementLengths ( ) ;
int [ ] elementLengths = mesh . getElementLengths ( ) ;
int elMode = convertElementMode ( Mode . Triangles ) ;
int elMode = convertElementMode ( Mode . Triangles ) ;
int fmt = convertVertexFormat ( indexBuf . getFormat ( ) ) ;
int fmt = convertVertexFormat ( indexBuf . getFormat ( ) ) ;
// int elSize = indexBuf.getFormat().getComponentSize();
// int elSize = indexBuf.getFormat().getComponentSize();
// int listStart = modeStart[0];
// int listStart = modeStart[0];
int stripStart = modeStart [ 1 ] ;
int stripStart = modeStart [ 1 ] ;
int fanStart = modeStart [ 2 ] ;
int fanStart = modeStart [ 2 ] ;
int curOffset = 0 ;
int curOffset = 0 ;
for ( int i = 0 ; i < elementLengths . length ; i + + ) {
for ( int i = 0 ; i < elementLengths . length ; i + + ) {
if ( i = = stripStart ) {
if ( i = = stripStart ) {
elMode = convertElementMode ( Mode . TriangleStrip ) ;
elMode = convertElementMode ( Mode . TriangleStrip ) ;
} else if ( i = = fanStart ) {
} else if ( i = = fanStart ) {
elMode = convertElementMode ( Mode . TriangleStrip ) ;
elMode = convertElementMode ( Mode . TriangleStrip ) ;
}
}
int elementLength = elementLengths [ i ] ;
int elementLength = elementLengths [ i ] ;
indexData . position ( curOffset ) ;
indexData . position ( curOffset ) ;
drawElements ( elMode ,
drawElements ( elMode ,
fmt ,
fmt ,
indexData ) ;
indexData ) ;
curOffset + = elementLength ;
curOffset + = elementLength ;
} * /
} * /
} else {
} else {
drawElements ( convertElementMode ( mode ) ,
drawElements ( convertElementMode ( mode ) ,
convertVertexFormat ( indexBuf . getFormat ( ) ) ,
convertVertexFormat ( indexBuf . getFormat ( ) ) ,
indexData ) ;
indexData ) ;
}
}
}
}
public void clearVertexAttribs ( ) {
public void clearVertexAttribs ( ) {
for ( int i = 0 ; i < 16 ; i + + ) {
for ( int i = 0 ; i < 16 ; i + + ) {
VertexBuffer vb = context . boundAttribs [ i ] ;
VertexBuffer vb = context . boundAttribs [ i ] ;
@ -874,8 +872,9 @@ public class LwjglGL1Renderer implements GL1Renderer {
}
}
public void renderMesh ( Mesh mesh , int lod , int count ) {
public void renderMesh ( Mesh mesh , int lod , int count ) {
if ( mesh . getVertexCount ( ) = = 0 )
if ( mesh . getVertexCount ( ) = = 0 ) {
return ;
return ;
}
if ( context . pointSize ! = mesh . getPointSize ( ) ) {
if ( context . pointSize ! = mesh . getPointSize ( ) ) {
glPointSize ( mesh . getPointSize ( ) ) ;
glPointSize ( mesh . getPointSize ( ) ) ;
@ -887,8 +886,9 @@ public class LwjglGL1Renderer implements GL1Renderer {
}
}
boolean dynamic = false ;
boolean dynamic = false ;
if ( mesh . getBuffer ( Type . InterleavedData ) ! = null )
if ( mesh . getBuffer ( Type . InterleavedData ) ! = null ) {
throw new UnsupportedOperationException ( ) ;
throw new UnsupportedOperationException ( ) ;
}
if ( mesh . getNumLodLevels ( ) = = 0 ) {
if ( mesh . getNumLodLevels ( ) = = 0 ) {
IntMap < VertexBuffer > bufs = mesh . getBuffers ( ) ;
IntMap < VertexBuffer > bufs = mesh . getBuffers ( ) ;
@ -905,10 +905,10 @@ public class LwjglGL1Renderer implements GL1Renderer {
statistics . onMeshDrawn ( mesh , lod ) ;
statistics . onMeshDrawn ( mesh , lod ) ;
// if (!dynamic) {
// if (!dynamic) {
// dealing with a static object, generate display list
// dealing with a static object, generate display list
// renderMeshDisplayList(mesh);
// renderMeshDisplayList(mesh);
// } else {
// } else {
renderMeshDefault ( mesh , lod , count ) ;
renderMeshDefault ( mesh , lod , count ) ;
// }
// }
@ -929,6 +929,9 @@ public class LwjglGL1Renderer implements GL1Renderer {
public void copyFrameBuffer ( FrameBuffer src , FrameBuffer dst ) {
public void copyFrameBuffer ( FrameBuffer src , FrameBuffer dst ) {
}
}
public void copyFrameBuffer ( FrameBuffer src , FrameBuffer dst , boolean copyDepth ) {
}
public void setFrameBuffer ( FrameBuffer fb ) {
public void setFrameBuffer ( FrameBuffer fb ) {
}
}
@ -943,5 +946,4 @@ public class LwjglGL1Renderer implements GL1Renderer {
public void deleteBuffer ( VertexBuffer vb ) {
public void deleteBuffer ( VertexBuffer vb ) {
}
}
}
}