53
54
private static HashMap<Integer, Vector2dDouble> allTextures = new HashMap<Integer, Vector2dDouble>();
55
private final static int[] formatMap = { GL.GL_LUMINANCE4, GL.GL_LUMINANCE4, GL.GL_LUMINANCE4, GL.GL_LUMINANCE4, GL.GL_LUMINANCE8, GL.GL_LUMINANCE8, GL.GL_LUMINANCE8, GL.GL_LUMINANCE8, GL.GL_LUMINANCE12, GL.GL_LUMINANCE12, GL.GL_LUMINANCE12, GL.GL_LUMINANCE12, GL.GL_LUMINANCE16, GL.GL_LUMINANCE16, GL.GL_LUMINANCE16, GL.GL_LUMINANCE16 };
56
private final static int[] formatMap = { GL2.GL_LUMINANCE4, GL2.GL_LUMINANCE4, GL2.GL_LUMINANCE4, GL2.GL_LUMINANCE4, GL2.GL_LUMINANCE8, GL2.GL_LUMINANCE8, GL2.GL_LUMINANCE8, GL2.GL_LUMINANCE8, GL2.GL_LUMINANCE12, GL2.GL_LUMINANCE12, GL2.GL_LUMINANCE12, GL2.GL_LUMINANCE12, GL2.GL_LUMINANCE16, GL2.GL_LUMINANCE16, GL2.GL_LUMINANCE16, GL2.GL_LUMINANCE16 };
58
59
* Sets whether non power of two textures should be used.
307
308
* area of the frame buffer to copy
308
309
* @return texture the frame buffer was copied to
310
public int copyFrameBufferToTexture(GL gl, int texture, Rectangle rect) {
312
gl.glActiveTexture(GL.GL_TEXTURE0);
314
textureImplementation.genTexture2D(gl, texture, GL.GL_RGBA, rect.width, rect.height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
311
public int copyFrameBufferToTexture(GL2 gl, int texture, Rectangle rect) {
313
gl.glActiveTexture(GL2.GL_TEXTURE0);
315
textureImplementation.genTexture2D(gl, texture, GL2.GL_RGBA, rect.width, rect.height, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, null);
315
316
textureImplementation.copyFrameBufferToTexture(gl, texture, rect);
546
gl.glPixelStorei(GL.GL_UNPACK_SKIP_PIXELS, 0);
547
gl.glPixelStorei(GL.GL_UNPACK_SKIP_ROWS, 0);
548
gl.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, 0);
549
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, mapDataBufferTypeToGLAlign(rawBuffer.getDataType()));
550
gl.glPixelStorei(GL2.GL_UNPACK_SKIP_PIXELS, 0);
551
gl.glPixelStorei(GL2.GL_UNPACK_SKIP_ROWS, 0);
552
gl.glPixelStorei(GL2.GL_UNPACK_ROW_LENGTH, 0);
553
gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, mapDataBufferTypeToGLAlign(rawBuffer.getDataType()));
551
555
if (source.getHeight() == 1) {
552
556
textureImplementation.genTexture1D(gl, target, mapTypeToInternalGLFormat(source.getType()), source.getWidth(), mapTypeToInputGLFormat(source.getType()), mapDataBufferTypeToGLType(rawBuffer.getDataType()), buffer);
795
public void genTexture1D(GL gl, int texID, int internalFormat, int width, int inputFormat, int inputType, Buffer buffer) {
797
gl.glBindTexture(GL.GL_TEXTURE_1D, texID);
799
gl.glTexImage1D(GL.GL_TEXTURE_1D, 0, internalFormat, width, 0, inputFormat, inputType, buffer);
801
gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
802
gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
803
gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
809
public void genTexture2D(GL gl, int texID, int internalFormat, int width, int height, int inputFormat, int inputType, Buffer buffer) {
811
gl.glBindTexture(GL.GL_TEXTURE_2D, texID);
813
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, internalFormat, width, height, 0, inputFormat, inputType, buffer);
815
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
816
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
817
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
818
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
824
public void bindTexture(GL gl, int texture) {
825
gl.glBindTexture(GL.GL_TEXTURE_2D, texture);
831
public void bindTexture(GL gl, int target, int texture) {
799
public void genTexture1D(GL2 gl, int texID, int internalFormat, int width, int inputFormat, int inputType, Buffer buffer) {
801
gl.glBindTexture(GL2.GL_TEXTURE_1D, texID);
803
gl.glTexImage1D(GL2.GL_TEXTURE_1D, 0, internalFormat, width, 0, inputFormat, inputType, buffer);
805
gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
806
gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
807
gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP);
813
public void genTexture2D(GL2 gl, int texID, int internalFormat, int width, int height, int inputFormat, int inputType, Buffer buffer) {
815
gl.glBindTexture(GL2.GL_TEXTURE_2D, texID);
817
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, internalFormat, width, height, 0, inputFormat, inputType, buffer);
819
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
820
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
821
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP);
822
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP);
828
public void bindTexture(GL2 gl, int texture) {
829
gl.glBindTexture(GL2.GL_TEXTURE_2D, texture);
835
public void bindTexture(GL2 gl, int target, int texture) {
832
836
gl.glBindTexture(target, texture);
838
public void copyFrameBufferToTexture(GL gl, int texture, Rectangle rect) {
839
gl.glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, rect.x, rect.y, rect.width, rect.height, 0);
842
public void copyFrameBufferToTexture(GL2 gl, int texture, Rectangle rect) {
843
gl.glCopyTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA, rect.x, rect.y, rect.width, rect.height, 0);
855
public void genTexture1D(GL gl, int texID, int internalFormat, int width, int inputFormat, int inputType, Buffer buffer) {
860
public void genTexture1D(GL2 gl, int texID, int internalFormat, int width, int inputFormat, int inputType, Buffer buffer) {
857
gl.glBindTexture(GL.GL_TEXTURE_1D, texID);
862
gl.glBindTexture(GL2.GL_TEXTURE_1D, texID);
859
864
int width2 = nextPowerOfTwo(width);
861
gl.glTexImage1D(GL.GL_TEXTURE_1D, 0, internalFormat, width2, 0, inputFormat, inputType, null);
866
gl.glTexImage1D(GL2.GL_TEXTURE_1D, 0, internalFormat, width2, 0, inputFormat, inputType, null);
863
868
if (buffer != null) {
864
gl.glTexSubImage1D(GL.GL_TEXTURE_1D, 0, 0, width, inputFormat, inputType, buffer);
869
gl.glTexSubImage1D(GL2.GL_TEXTURE_1D, 0, 0, width, inputFormat, inputType, buffer);
867
gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
868
gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
869
gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
872
gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
873
gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
874
gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP);
871
876
float scaleX = (float) width / width2;
880
public void genTexture2D(GL gl, int texID, int internalFormat, int width, int height, int inputFormat, int inputType, Buffer buffer) {
885
public void genTexture2D(GL2 gl, int texID, int internalFormat, int width, int height, int inputFormat, int inputType, Buffer buffer) {
882
gl.glBindTexture(GL.GL_TEXTURE_2D, texID);
887
gl.glBindTexture(GL2.GL_TEXTURE_2D, texID);
884
889
int width2 = nextPowerOfTwo(width);
885
890
int height2 = nextPowerOfTwo(height);
887
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, internalFormat, width2, height2, 0, inputFormat, inputType, null);
892
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, internalFormat, width2, height2, 0, inputFormat, inputType, null);
889
894
if (buffer != null) {
890
gl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, width, height, inputFormat, inputType, buffer);
895
gl.glTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, width, height, inputFormat, inputType, buffer);
893
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
894
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
895
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
896
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
898
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
899
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
900
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP);
901
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP);
898
903
float scaleX = (float) width / width2;
899
904
float scaleY = (float) height / height2;