public void testSetJsArray() { if (!TypedArrays.isSupported()) { // TODO: some way of showing test as skipped in this case? return; } ArrayBuffer buf = TypedArrays.createArrayBuffer(24); Uint32Array array = TypedArrays.createUint32Array(buf); setFromJsArray(array, 0); validateArrayContents(array, 0); buf = TypedArrays.createArrayBuffer(24); array = TypedArrays.createUint32Array(buf); setFromJsArray(array, 1); validateArrayContents(array, 1); }
public void testCreateJsArray() { if (!TypedArrays.isSupported()) { // TODO: some way of showing test as skipped in this case? return; } JsArrayNumber src = getJsoArray(); Uint32Array array = JsUtils.createUint32Array(src); validateArrayContents(array, 0); }
private void ensureCapacity(IntBuffer buffer) { if (buffer.remaining() > intBuffer.length()) { intBuffer = TypedArrays.createInt32Array(buffer.remaining()); } }
private void ensureCapacity(ShortBuffer buffer) { if (buffer.remaining() > shortBuffer.length()) { shortBuffer = TypedArrays.createInt16Array(buffer.remaining()); } }
private void ensureCapacity(FloatBuffer buffer) { if (buffer.remaining() > floatBuffer.length()) { floatBuffer = TypedArrays.createFloat32Array(buffer.remaining()); } }
public class GwtGL20 implements GL20 { final Map<Integer, WebGLProgram> programs = new HashMap<Integer, WebGLProgram>(); int nextProgramId = 1; final Map<Integer, WebGLShader> shaders = new HashMap<Integer, WebGLShader>(); int nextShaderId = 1; final Map<Integer, WebGLBuffer> buffers = new HashMap<Integer, WebGLBuffer>(); int nextBufferId = 1; final Map<Integer, WebGLFramebuffer> frameBuffers = new HashMap<Integer, WebGLFramebuffer>(); int nextFrameBufferId = 1; final Map<Integer, WebGLRenderbuffer> renderBuffers = new HashMap<Integer, WebGLRenderbuffer>(); int nextRenderBufferId = 1; final Map<Integer, WebGLTexture> textures = new HashMap<Integer, WebGLTexture>(); int nextTextureId = 1; final Map<Integer, Map<Integer, WebGLUniformLocation>> uniforms = new HashMap<Integer, Map<Integer, WebGLUniformLocation>>(); int nextUniformId = 1; int currProgram = 0; Float32Array floatBuffer = TypedArrays.createFloat32Array(2000 * 20); Int32Array intBuffer = TypedArrays.createInt32Array(2000 * 6); Int16Array shortBuffer = TypedArrays.createInt16Array(2000 * 6); float[] floatArray = new float[16000]; final WebGLRenderingContext gl; protected GwtGL20(WebGLRenderingContext gl) { ; this.gl = gl; this.gl.pixelStorei(WebGLRenderingContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0); } private void ensureCapacity(FloatBuffer buffer) { if (buffer.remaining() > floatBuffer.length()) { floatBuffer = TypedArrays.createFloat32Array(buffer.remaining()); } } private void ensureCapacity(ShortBuffer buffer) { if (buffer.remaining() > shortBuffer.length()) { shortBuffer = TypedArrays.createInt16Array(buffer.remaining()); } } private void ensureCapacity(IntBuffer buffer) { if (buffer.remaining() > intBuffer.length()) { intBuffer = TypedArrays.createInt32Array(buffer.remaining()); } } public Float32Array copy(FloatBuffer buffer) { if (GWT.isProdMode()) { return ((Float32Array) ((HasArrayBufferView) buffer).getTypedArray()) .subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { floatBuffer.set(j, buffer.get(i)); } return floatBuffer.subarray(0, buffer.remaining()); } } public Int16Array copy(ShortBuffer buffer) { if (GWT.isProdMode()) { return ((Int16Array) ((HasArrayBufferView) buffer).getTypedArray()) .subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { shortBuffer.set(j, buffer.get(i)); } return shortBuffer.subarray(0, buffer.remaining()); } } public Int32Array copy(IntBuffer buffer) { if (GWT.isProdMode()) { return ((Int32Array) ((HasArrayBufferView) buffer).getTypedArray()) .subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { intBuffer.set(j, buffer.get(i)); } return intBuffer.subarray(0, buffer.remaining()); } } private int allocateUniformLocationId(int program, WebGLUniformLocation location) { Map<Integer, WebGLUniformLocation> progUniforms = uniforms.get(program); if (progUniforms == null) { progUniforms = new HashMap<Integer, WebGLUniformLocation>(); uniforms.put(program, progUniforms); } // FIXME check if uniform already stored. int id = nextUniformId++; progUniforms.put(id, location); return id; } private WebGLUniformLocation getUniformLocation(int location) { return uniforms.get(currProgram).get(location); } private int allocateShaderId(WebGLShader shader) { int id = nextShaderId++; shaders.put(id, shader); return id; } private void deallocateShaderId(int id) { shaders.remove(id); } private int allocateProgramId(WebGLProgram program) { int id = nextProgramId++; programs.put(id, program); return id; } private void deallocateProgramId(int id) { uniforms.remove(id); programs.remove(id); } private int allocateBufferId(WebGLBuffer buffer) { int id = nextBufferId++; buffers.put(id, buffer); return id; } private void deallocateBufferId(int id) { buffers.remove(id); } private int allocateFrameBufferId(WebGLFramebuffer frameBuffer) { int id = nextBufferId++; frameBuffers.put(id, frameBuffer); return id; } private void deallocateFrameBufferId(int id) { frameBuffers.remove(id); } private int allocateRenderBufferId(WebGLRenderbuffer renderBuffer) { int id = nextRenderBufferId++; renderBuffers.put(id, renderBuffer); return id; } private void deallocateRenderBufferId(int id) { renderBuffers.remove(id); } private int allocateTextureId(WebGLTexture texture) { int id = nextTextureId++; textures.put(id, texture); return id; } private void deallocateTextureId(int id) { textures.remove(id); } @Override public void glActiveTexture(int texture) { gl.activeTexture(texture); } @Override public void glBindTexture(int target, int texture) { gl.bindTexture(target, textures.get(texture)); } @Override public void glBlendFunc(int sfactor, int dfactor) { gl.blendFunc(sfactor, dfactor); } @Override public void glClear(int mask) { gl.clear(mask); } @Override public void glClearColor(float red, float green, float blue, float alpha) { gl.clearColor(red, green, blue, alpha); } @Override public void glClearDepthf(float depth) { gl.clearDepth(depth); } @Override public void glClearStencil(int s) { gl.clearStencil(s); } @Override public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha) { gl.colorMask(red, green, blue, alpha); } @Override public void glCompressedTexImage2D( int target, int level, int internalformat, int width, int height, int border, int imageSize, Buffer data) { throw new GdxRuntimeException("compressed textures not supported by GWT WebGL backend"); } @Override public void glCompressedTexSubImage2D( int target, int level, int xoffset, int yoffset, int width, int height, int format, int imageSize, Buffer data) { throw new GdxRuntimeException("compressed textures not supported by GWT WebGL backend"); } @Override public void glCopyTexImage2D( int target, int level, int internalformat, int x, int y, int width, int height, int border) { gl.copyTexImage2D(target, level, internalformat, x, y, width, height, border); } @Override public void glCopyTexSubImage2D( int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) { gl.copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); } @Override public void glCullFace(int mode) { gl.cullFace(mode); } @Override public void glDeleteTextures(int n, IntBuffer textures) { for (int i = 0; i < n; i++) { int id = textures.get(); WebGLTexture texture = this.textures.get(id); deallocateTextureId(id); gl.deleteTexture(texture); } } @Override public void glDepthFunc(int func) { gl.depthFunc(func); } @Override public void glDepthMask(boolean flag) { gl.depthMask(flag); } @Override public void glDepthRangef(float zNear, float zFar) { gl.depthRange(zNear, zFar); } @Override public void glDisable(int cap) { gl.disable(cap); } @Override public void glDrawArrays(int mode, int first, int count) { gl.drawArrays(mode, first, count); } @Override public void glDrawElements(int mode, int count, int type, Buffer indices) { gl.drawElements( mode, count, type, indices.position()); // FIXME this is assuming WebGL supports client side buffers... } @Override public void glEnable(int cap) { gl.enable(cap); } @Override public void glFinish() { gl.finish(); } @Override public void glFlush() { gl.flush(); } @Override public void glFrontFace(int mode) { gl.frontFace(mode); } @Override public void glGenTextures(int n, IntBuffer textures) { WebGLTexture texture = gl.createTexture(); int id = allocateTextureId(texture); textures.put(id); } @Override public int glGetError() { return gl.getError(); } @Override public void glGetIntegerv(int pname, IntBuffer params) { // FIXME this is a hack, a nasty nasty hack if (pname == GL10.GL_MAX_TEXTURE_UNITS || pname == GL20.GL_MAX_TEXTURE_IMAGE_UNITS) { params.put(16); return; } throw new GdxRuntimeException("glGetInteger not supported by GWT WebGL backend"); } @Override public String glGetString(int name) { // FIXME throw new GdxRuntimeException("not implemented"); } @Override public void glHint(int target, int mode) { gl.hint(target, mode); } @Override public void glLineWidth(float width) { gl.lineWidth(width); } @Override public void glPixelStorei(int pname, int param) { gl.pixelStorei(pname, param); } @Override public void glPolygonOffset(float factor, float units) { gl.polygonOffset(factor, units); } @Override public void glReadPixels( int x, int y, int width, int height, int format, int type, Buffer pixels) { // verify request if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) { throw new GdxRuntimeException( "Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...)."); } if (!(pixels instanceof ByteBuffer)) { throw new GdxRuntimeException( "Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...)."); } // create new ArrayBufferView (4 bytes per pixel) int size = 4 * width * height; Uint8Array buffer = Uint8ArrayNative.create(size); // read bytes to ArrayBufferView gl.readPixels(x, y, width, height, format, type, buffer); // copy ArrayBufferView to our pixels array ByteBuffer pixelsByte = (ByteBuffer) pixels; for (int i = 0; i < size; i++) { pixelsByte.put((byte) (buffer.get(i) & 0x000000ff)); } } @Override public void glScissor(int x, int y, int width, int height) { gl.scissor(x, y, width, height); } @Override public void glStencilFunc(int func, int ref, int mask) { gl.stencilFunc(func, ref, mask); } @Override public void glStencilMask(int mask) { gl.stencilMask(mask); } @Override public void glStencilOp(int fail, int zfail, int zpass) { gl.stencilOp(fail, zfail, zpass); } @Override public void glTexImage2D( int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels) { Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer) pixels).get(0)); gl.texImage2D(target, level, internalformat, format, type, pixmap.getCanvasElement()); } @Override public void glTexParameterf(int target, int pname, float param) { gl.texParameterf(target, pname, param); } @Override public void glTexSubImage2D( int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, Buffer pixels) { Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer) pixels).get(0)); gl.texSubImage2D(target, level, xoffset, yoffset, width, height, pixmap.getCanvasElement()); } @Override public void glViewport(int x, int y, int width, int height) { gl.viewport(x, y, width, height); } @Override public void glAttachShader(int program, int shader) { WebGLProgram glProgram = programs.get(program); WebGLShader glShader = shaders.get(shader); gl.attachShader(glProgram, glShader); } @Override public void glBindAttribLocation(int program, int index, String name) { WebGLProgram glProgram = programs.get(program); gl.bindAttribLocation(glProgram, index, name); } @Override public void glBindBuffer(int target, int buffer) { gl.bindBuffer(target, buffers.get(buffer)); } @Override public void glBindFramebuffer(int target, int framebuffer) { gl.bindFramebuffer(target, frameBuffers.get(framebuffer)); } @Override public void glBindRenderbuffer(int target, int renderbuffer) { gl.bindRenderbuffer(target, renderBuffers.get(renderbuffer)); } @Override public void glBlendColor(float red, float green, float blue, float alpha) { gl.blendColor(red, green, blue, alpha); } @Override public void glBlendEquation(int mode) { gl.blendEquation(mode); } @Override public void glBlendEquationSeparate(int modeRGB, int modeAlpha) { gl.blendEquationSeparate(modeRGB, modeAlpha); } @Override public void glBlendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) { gl.blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); } @Override public void glBufferData(int target, int size, Buffer data, int usage) { if (data instanceof FloatBuffer) { gl.bufferData(target, copy((FloatBuffer) data), usage); } else if (data instanceof ShortBuffer) { gl.bufferData(target, copy((ShortBuffer) data), usage); } else { throw new GdxRuntimeException("Can only cope with FloatBuffer and ShortBuffer at the moment"); } } @Override public void glBufferSubData(int target, int offset, int size, Buffer data) { if (data instanceof FloatBuffer) { gl.bufferSubData(target, offset, copy((FloatBuffer) data)); } else if (data instanceof ShortBuffer) { gl.bufferSubData(target, offset, copy((ShortBuffer) data)); } else { throw new GdxRuntimeException("Can only cope with FloatBuffer and ShortBuffer at the moment"); } } @Override public int glCheckFramebufferStatus(int target) { return gl.checkFramebufferStatus(target); } @Override public void glCompileShader(int shader) { WebGLShader glShader = shaders.get(shader); gl.compileShader(glShader); } @Override public int glCreateProgram() { WebGLProgram program = gl.createProgram(); return allocateProgramId(program); } @Override public int glCreateShader(int type) { WebGLShader shader = gl.createShader(type); return allocateShaderId(shader); } @Override public void glDeleteBuffers(int n, IntBuffer buffers) { for (int i = 0; i < n; i++) { int id = buffers.get(); WebGLBuffer buffer = this.buffers.get(id); deallocateBufferId(id); gl.deleteBuffer(buffer); } } @Override public void glDeleteFramebuffers(int n, IntBuffer framebuffers) { for (int i = 0; i < n; i++) { int id = framebuffers.get(); WebGLFramebuffer fb = this.frameBuffers.get(id); deallocateFrameBufferId(id); gl.deleteFramebuffer(fb); } } @Override public void glDeleteProgram(int program) { WebGLProgram prog = programs.get(program); deallocateProgramId(program); gl.deleteProgram(prog); } @Override public void glDeleteRenderbuffers(int n, IntBuffer renderbuffers) { for (int i = 0; i < n; i++) { int id = renderbuffers.get(); WebGLRenderbuffer rb = this.renderBuffers.get(id); deallocateRenderBufferId(id); gl.deleteRenderbuffer(rb); } } @Override public void glDeleteShader(int shader) { WebGLShader sh = shaders.get(shader); deallocateShaderId(shader); gl.deleteShader(sh); } @Override public void glDetachShader(int program, int shader) { gl.detachShader(programs.get(program), shaders.get(shader)); } @Override public void glDisableVertexAttribArray(int index) { gl.disableVertexAttribArray(index); } @Override public void glDrawElements(int mode, int count, int type, int indices) { gl.drawElements(mode, count, type, indices); } @Override public void glEnableVertexAttribArray(int index) { gl.enableVertexAttribArray(index); } @Override public void glFramebufferRenderbuffer( int target, int attachment, int renderbuffertarget, int renderbuffer) { gl.framebufferRenderbuffer( target, attachment, renderbuffertarget, renderBuffers.get(renderbuffer)); } @Override public void glFramebufferTexture2D( int target, int attachment, int textarget, int texture, int level) { gl.framebufferTexture2D(target, attachment, textarget, textures.get(texture), level); } @Override public void glGenBuffers(int n, IntBuffer buffers) { for (int i = 0; i < n; i++) { WebGLBuffer buffer = gl.createBuffer(); int id = allocateBufferId(buffer); buffers.put(id); } } @Override public void glGenerateMipmap(int target) { gl.generateMipmap(target); } @Override public void glGenFramebuffers(int n, IntBuffer framebuffers) { for (int i = 0; i < n; i++) { WebGLFramebuffer fb = gl.createFramebuffer(); int id = allocateFrameBufferId(fb); framebuffers.put(id); } } @Override public void glGenRenderbuffers(int n, IntBuffer renderbuffers) { for (int i = 0; i < n; i++) { WebGLRenderbuffer rb = gl.createRenderbuffer(); int id = allocateRenderBufferId(rb); renderbuffers.put(id); } } @Override public String glGetActiveAttrib(int program, int index, IntBuffer size, Buffer type) { WebGLActiveInfo activeAttrib = gl.getActiveAttrib(programs.get(program), index); size.put(activeAttrib.getSize()); ((IntBuffer) type).put(activeAttrib.getType()); return activeAttrib.getName(); } @Override public String glGetActiveUniform(int program, int index, IntBuffer size, Buffer type) { WebGLActiveInfo activeUniform = gl.getActiveUniform(programs.get(program), index); size.put(activeUniform.getSize()); ((IntBuffer) type).put(activeUniform.getType()); return activeUniform.getName(); } @Override public void glGetAttachedShaders(int program, int maxcount, Buffer count, IntBuffer shaders) { // FIXME throw new GdxRuntimeException("not implemented"); } @Override public int glGetAttribLocation(int program, String name) { WebGLProgram prog = programs.get(program); return gl.getAttribLocation(prog, name); } @Override public void glGetBooleanv(int pname, Buffer params) { throw new GdxRuntimeException("glGetBoolean not supported by GWT WebGL backend"); } @Override public void glGetBufferParameteriv(int target, int pname, IntBuffer params) { // FIXME throw new GdxRuntimeException("not implemented"); } @Override public void glGetFloatv(int pname, FloatBuffer params) { throw new GdxRuntimeException("glGetFloat not supported by GWT WebGL backend"); } @Override public void glGetFramebufferAttachmentParameteriv( int target, int attachment, int pname, IntBuffer params) { // FIXME throw new GdxRuntimeException("not implemented"); } @Override public void glGetProgramiv(int program, int pname, IntBuffer params) { if (pname == GL20.GL_DELETE_STATUS || pname == GL20.GL_LINK_STATUS || pname == GL20.GL_VALIDATE_STATUS) { boolean result = gl.getProgramParameterb(programs.get(program), pname); params.put(result ? GL20.GL_TRUE : GL20.GL_FALSE); } else { params.put(gl.getProgramParameteri(programs.get(program), pname)); } } @Override public String glGetProgramInfoLog(int program) { return gl.getProgramInfoLog(programs.get(program)); } @Override public void glGetRenderbufferParameteriv(int target, int pname, IntBuffer params) { // FIXME throw new GdxRuntimeException("not implemented"); } @Override public void glGetShaderiv(int shader, int pname, IntBuffer params) { if (pname == GL20.GL_COMPILE_STATUS || pname == GL20.GL_DELETE_STATUS) { boolean result = gl.getShaderParameterb(shaders.get(shader), pname); params.put(result ? GL20.GL_TRUE : GL20.GL_FALSE); } else { int result = gl.getShaderParameteri(shaders.get(shader), pname); params.put(result); } } @Override public String glGetShaderInfoLog(int shader) { return gl.getShaderInfoLog(shaders.get(shader)); } @Override public void glGetShaderPrecisionFormat( int shadertype, int precisiontype, IntBuffer range, IntBuffer precision) { throw new GdxRuntimeException("glGetShaderPrecisionFormat not supported by GWT WebGL backend"); } @Override public void glGetShaderSource(int shader, int bufsize, Buffer length, String source) { throw new GdxRuntimeException("glGetShaderSource not supported by GWT WebGL backend"); } @Override public void glGetTexParameterfv(int target, int pname, FloatBuffer params) { throw new GdxRuntimeException("glGetTexParameter not supported by GWT WebGL backend"); } @Override public void glGetTexParameteriv(int target, int pname, IntBuffer params) { throw new GdxRuntimeException("glGetTexParameter not supported by GWT WebGL backend"); } @Override public void glGetUniformfv(int program, int location, FloatBuffer params) { // FIXME throw new GdxRuntimeException("not implemented"); } @Override public void glGetUniformiv(int program, int location, IntBuffer params) { // FIXME throw new GdxRuntimeException("not implemented"); } @Override public int glGetUniformLocation(int program, String name) { WebGLUniformLocation location = gl.getUniformLocation(programs.get(program), name); return allocateUniformLocationId(program, location); } @Override public void glGetVertexAttribfv(int index, int pname, FloatBuffer params) { // FIXME throw new GdxRuntimeException("not implemented"); } @Override public void glGetVertexAttribiv(int index, int pname, IntBuffer params) { // FIXME throw new GdxRuntimeException("not implemented"); } @Override public void glGetVertexAttribPointerv(int index, int pname, Buffer pointer) { throw new GdxRuntimeException("glGetVertexAttribPointer not supported by GWT WebGL backend"); } @Override public boolean glIsBuffer(int buffer) { return gl.isBuffer(buffers.get(buffer)); } @Override public boolean glIsEnabled(int cap) { return gl.isEnabled(cap); } @Override public boolean glIsFramebuffer(int framebuffer) { return gl.isFramebuffer(frameBuffers.get(framebuffer)); } @Override public boolean glIsProgram(int program) { return gl.isProgram(programs.get(program)); } @Override public boolean glIsRenderbuffer(int renderbuffer) { return gl.isRenderbuffer(renderBuffers.get(renderbuffer)); } @Override public boolean glIsShader(int shader) { return gl.isShader(shaders.get(shader)); } @Override public boolean glIsTexture(int texture) { return gl.isTexture(textures.get(texture)); } @Override public void glLinkProgram(int program) { gl.linkProgram(programs.get(program)); } @Override public void glReleaseShaderCompiler() { throw new GdxRuntimeException("not implemented"); } @Override public void glRenderbufferStorage(int target, int internalformat, int width, int height) { gl.renderbufferStorage(target, internalformat, width, height); } @Override public void glSampleCoverage(float value, boolean invert) { gl.sampleCoverage(value, invert); } @Override public void glShaderBinary( int n, IntBuffer shaders, int binaryformat, Buffer binary, int length) { throw new GdxRuntimeException("glShaderBinary not supported by GWT WebGL backend"); } @Override public void glShaderSource(int shader, String source) { gl.shaderSource(shaders.get(shader), source); } @Override public void glStencilFuncSeparate(int face, int func, int ref, int mask) { gl.stencilFuncSeparate(face, func, ref, mask); } @Override public void glStencilMaskSeparate(int face, int mask) { gl.stencilMaskSeparate(face, mask); } @Override public void glStencilOpSeparate(int face, int fail, int zfail, int zpass) { gl.stencilOpSeparate(face, fail, zfail, zpass); } @Override public void glTexParameterfv(int target, int pname, FloatBuffer params) { gl.texParameterf(target, pname, params.get()); } @Override public void glTexParameteri(int target, int pname, int param) { gl.texParameterf(target, pname, param); } @Override public void glTexParameteriv(int target, int pname, IntBuffer params) { gl.texParameterf(target, pname, params.get()); } @Override public void glUniform1f(int location, float x) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform1f(loc, x); } @Override public void glUniform1fv(int location, int count, FloatBuffer v) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform1fv(loc, copy(v)); } @Override public void glUniform1i(int location, int x) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform1i(loc, x); } @Override public void glUniform1iv(int location, int count, IntBuffer v) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform1iv(loc, copy(v)); } @Override public void glUniform2f(int location, float x, float y) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform2f(loc, x, y); } @Override public void glUniform2fv(int location, int count, FloatBuffer v) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform2fv(loc, copy(v)); } @Override public void glUniform2i(int location, int x, int y) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform2i(loc, x, y); } @Override public void glUniform2iv(int location, int count, IntBuffer v) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform2iv(loc, copy(v)); } @Override public void glUniform3f(int location, float x, float y, float z) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform3f(loc, x, y, z); } @Override public void glUniform3fv(int location, int count, FloatBuffer v) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform3fv(loc, copy(v)); } @Override public void glUniform3i(int location, int x, int y, int z) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform3i(loc, x, y, z); } @Override public void glUniform3iv(int location, int count, IntBuffer v) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform3iv(loc, copy(v)); } @Override public void glUniform4f(int location, float x, float y, float z, float w) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform4f(loc, x, y, z, w); } @Override public void glUniform4fv(int location, int count, FloatBuffer v) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform4fv(loc, copy(v)); } @Override public void glUniform4i(int location, int x, int y, int z, int w) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform4i(loc, x, y, z, w); } @Override public void glUniform4iv(int location, int count, IntBuffer v) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniform4iv(loc, copy(v)); } @Override public void glUniformMatrix2fv(int location, int count, boolean transpose, FloatBuffer value) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniformMatrix2fv(loc, transpose, copy(value)); } @Override public void glUniformMatrix3fv(int location, int count, boolean transpose, FloatBuffer value) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniformMatrix3fv(loc, transpose, copy(value)); } @Override public void glUniformMatrix4fv(int location, int count, boolean transpose, FloatBuffer value) { WebGLUniformLocation loc = getUniformLocation(location); gl.uniformMatrix4fv(loc, transpose, copy(value)); } @Override public void glUseProgram(int program) { currProgram = program; gl.useProgram(programs.get(program)); } @Override public void glValidateProgram(int program) { gl.validateProgram(programs.get(program)); } @Override public void glVertexAttrib1f(int indx, float x) { gl.vertexAttrib1f(indx, x); } @Override public void glVertexAttrib1fv(int indx, FloatBuffer values) { gl.vertexAttrib1fv(indx, copy(values)); } @Override public void glVertexAttrib2f(int indx, float x, float y) { gl.vertexAttrib2f(indx, x, y); } @Override public void glVertexAttrib2fv(int indx, FloatBuffer values) { gl.vertexAttrib2fv(indx, copy(values)); } @Override public void glVertexAttrib3f(int indx, float x, float y, float z) { gl.vertexAttrib3f(indx, x, y, z); } @Override public void glVertexAttrib3fv(int indx, FloatBuffer values) { gl.vertexAttrib3fv(indx, copy(values)); } @Override public void glVertexAttrib4f(int indx, float x, float y, float z, float w) { gl.vertexAttrib4f(indx, x, y, z, w); } @Override public void glVertexAttrib4fv(int indx, FloatBuffer values) { gl.vertexAttrib4fv(indx, copy(values)); } @Override public void glVertexAttribPointer( int indx, int size, int type, boolean normalized, int stride, Buffer ptr) { throw new GdxRuntimeException( "not implemented, vertex arrays aren't support in WebGL it seems"); } @Override public void glVertexAttribPointer( int indx, int size, int type, boolean normalized, int stride, int ptr) { gl.vertexAttribPointer(indx, size, type, normalized, stride, ptr); } }
/** This class represents structured wavelette data. */ final class IWBlock { // ~ Static fields/initializers --------------------------------------------- /** Ask Lean Bottou. */ static final short[] zigzagloc = { 0, 16, 512, 528, 8, 24, 520, 536, 256, 272, 768, 784, 264, 280, 776, 792, 4, 20, 516, 532, 12, 28, 524, 540, 260, 276, 772, 788, 268, 284, 780, 796, 128, 144, 640, 656, 136, 152, 648, 664, 384, 400, 896, 912, 392, 408, 904, 920, 132, 148, 644, 660, 140, 156, 652, 668, 388, 404, 900, 916, 396, 412, 908, 924, 2, 18, 514, 530, 10, 26, 522, 538, 258, 274, 770, 786, 266, 282, 778, 794, 6, 22, 518, 534, 14, 30, 526, 542, 262, 278, 774, 790, 270, 286, 782, 798, 130, 146, 642, 658, 138, 154, 650, 666, 386, 402, 898, 914, 394, 410, 906, 922, 134, 150, 646, 662, 142, 158, 654, 670, 390, 406, 902, 918, 398, 414, 910, 926, 64, 80, 576, 592, 72, 88, 584, 600, 320, 336, 832, 848, 328, 344, 840, 856, 68, 84, 580, 596, 76, 92, 588, 604, 324, 340, 836, 852, 332, 348, 844, 860, 192, 208, 704, 720, 200, 216, 712, 728, 448, 464, 960, 976, 456, 472, 968, 984, 196, 212, 708, 724, 204, 220, 716, 732, 452, 468, 964, 980, 460, 476, 972, 988, 66, 82, 578, 594, 74, 90, 586, 602, 322, 338, 834, 850, 330, 346, 842, 858, 70, 86, 582, 598, 78, 94, 590, 606, 326, 342, 838, 854, 334, 350, 846, 862, 194, 210, 706, 722, 202, 218, 714, 730, 450, 466, 962, 978, 458, 474, 970, 986, 198, 214, 710, 726, 206, 222, 718, 734, 454, 470, 966, 982, 462, 478, 974, 990, 1, 17, 513, 529, 9, 25, 521, 537, 257, 273, 769, 785, 265, 281, 777, 793, 5, 21, 517, 533, 13, 29, 525, 541, 261, 277, 773, 789, 269, 285, 781, 797, 129, 145, 641, 657, 137, 153, 649, 665, 385, 401, 897, 913, 393, 409, 905, 921, 133, 149, 645, 661, 141, 157, 653, 669, 389, 405, 901, 917, 397, 413, 909, 925, 3, 19, 515, 531, 11, 27, 523, 539, 259, 275, 771, 787, 267, 283, 779, 795, 7, 23, 519, 535, 15, 31, 527, 543, 263, 279, 775, 791, 271, 287, 783, 799, 131, 147, 643, 659, 139, 155, 651, 667, 387, 403, 899, 915, 395, 411, 907, 923, 135, 151, 647, 663, 143, 159, 655, 671, 391, 407, 903, 919, 399, 415, 911, 927, 65, 81, 577, 593, 73, 89, 585, 601, 321, 337, 833, 849, 329, 345, 841, 857, 69, 85, 581, 597, 77, 93, 589, 605, 325, 341, 837, 853, 333, 349, 845, 861, 193, 209, 705, 721, 201, 217, 713, 729, 449, 465, 961, 977, 457, 473, 969, 985, 197, 213, 709, 725, 205, 221, 717, 733, 453, 469, 965, 981, 461, 477, 973, 989, 67, 83, 579, 595, 75, 91, 587, 603, 323, 339, 835, 851, 331, 347, 843, 859, 71, 87, 583, 599, 79, 95, 591, 607, 327, 343, 839, 855, 335, 351, 847, 863, 195, 211, 707, 723, 203, 219, 715, 731, 451, 467, 963, 979, 459, 475, 971, 987, 199, 215, 711, 727, 207, 223, 719, 735, 455, 471, 967, 983, 463, 479, 975, 991, 32, 48, 544, 560, 40, 56, 552, 568, 288, 304, 800, 816, 296, 312, 808, 824, 36, 52, 548, 564, 44, 60, 556, 572, 292, 308, 804, 820, 300, 316, 812, 828, 160, 176, 672, 688, 168, 184, 680, 696, 416, 432, 928, 944, 424, 440, 936, 952, 164, 180, 676, 692, 172, 188, 684, 700, 420, 436, 932, 948, 428, 444, 940, 956, 34, 50, 546, 562, 42, 58, 554, 570, 290, 306, 802, 818, 298, 314, 810, 826, 38, 54, 550, 566, 46, 62, 558, 574, 294, 310, 806, 822, 302, 318, 814, 830, 162, 178, 674, 690, 170, 186, 682, 698, 418, 434, 930, 946, 426, 442, 938, 954, 166, 182, 678, 694, 174, 190, 686, 702, 422, 438, 934, 950, 430, 446, 942, 958, 96, 112, 608, 624, 104, 120, 616, 632, 352, 368, 864, 880, 360, 376, 872, 888, 100, 116, 612, 628, 108, 124, 620, 636, 356, 372, 868, 884, 364, 380, 876, 892, 224, 240, 736, 752, 232, 248, 744, 760, 480, 496, 992, 1008, 488, 504, 1000, 1016, 228, 244, 740, 756, 236, 252, 748, 764, 484, 500, 996, 1012, 492, 508, 1004, 1020, 98, 114, 610, 626, 106, 122, 618, 634, 354, 370, 866, 882, 362, 378, 874, 890, 102, 118, 614, 630, 110, 126, 622, 638, 358, 374, 870, 886, 366, 382, 878, 894, 226, 242, 738, 754, 234, 250, 746, 762, 482, 498, 994, 1010, 490, 506, 1002, 1018, 230, 246, 742, 758, 238, 254, 750, 766, 486, 502, 998, 1014, 494, 510, 1006, 1022, 33, 49, 545, 561, 41, 57, 553, 569, 289, 305, 801, 817, 297, 313, 809, 825, 37, 53, 549, 565, 45, 61, 557, 573, 293, 309, 805, 821, 301, 317, 813, 829, 161, 177, 673, 689, 169, 185, 681, 697, 417, 433, 929, 945, 425, 441, 937, 953, 165, 181, 677, 693, 173, 189, 685, 701, 421, 437, 933, 949, 429, 445, 941, 957, 35, 51, 547, 563, 43, 59, 555, 571, 291, 307, 803, 819, 299, 315, 811, 827, 39, 55, 551, 567, 47, 63, 559, 575, 295, 311, 807, 823, 303, 319, 815, 831, 163, 179, 675, 691, 171, 187, 683, 699, 419, 435, 931, 947, 427, 443, 939, 955, 167, 183, 679, 695, 175, 191, 687, 703, 423, 439, 935, 951, 431, 447, 943, 959, 97, 113, 609, 625, 105, 121, 617, 633, 353, 369, 865, 881, 361, 377, 873, 889, 101, 117, 613, 629, 109, 125, 621, 637, 357, 373, 869, 885, 365, 381, 877, 893, 225, 241, 737, 753, 233, 249, 745, 761, 481, 497, 993, 1009, 489, 505, 1001, 1017, 229, 245, 741, 757, 237, 253, 749, 765, 485, 501, 997, 1013, 493, 509, 1005, 1021, 99, 115, 611, 627, 107, 123, 619, 635, 355, 371, 867, 883, 363, 379, 875, 891, 103, 119, 615, 631, 111, 127, 623, 639, 359, 375, 871, 887, 367, 383, 879, 895, 227, 243, 739, 755, 235, 251, 747, 763, 483, 499, 995, 1011, 491, 507, 1003, 1019, 231, 247, 743, 759, 239, 255, 751, 767, 487, 503, 999, 1015, 495, 511, 1007, 1023 }; private static final Int16Array zeros = TypedArrays.createInt16Array(1024); class Block { private int offset; public int get(int pos) { return pdata.get(pos + offset); } public void set(int pos, int value) { pdata.set(pos + offset, value); } } // ~ Instance fields -------------------------------------------------------- /** the data structure for this block */ private Int16Array pdata = TypedArrays.createInt16Array(1024); /** value at index i: 1 if block i has been initialized, 0 otherwise */ private Int8Array blockInitialized = TypedArrays.createInt8Array(64); private Block block = new Block(); // ~ Methods ---------------------------------------------------------------- /** * Query a data block. * * @param n the data block to query. * @return the requested block */ Block getBlock(final int n) { if (blockInitialized.get(n) == 0) return null; block.offset = n * 16; return block; } /** * Query a data block. * * @param n the block to query. * @return the requested block */ Block getInitializedBlock(final int n) { blockInitialized.set(n, 1); block.offset = n * 16; return block; } /** * Write a liftblock * * @param coeff an array * @param bmin start position * @param bmax end position */ void write_liftblock(Int16Array coeff, int bmin, int bmax) { int n = bmin << 4; coeff.set(zeros); for (int n1 = bmin; n1 < bmax; n1++) { Block d = getBlock(n1); if (d == null) { n += 16; } else { for (int n2 = 0; n2 < 16; ) { coeff.set(zigzagloc[n], d.get(n2)); n2++; n++; } } } } }