Example #1
0
 @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);
   }
 }
Example #2
0
 @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");
   }
 }
Example #3
0
 @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));
   }
 }
Example #4
0
 @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();
 }
Example #5
0
  @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));
    }
  }
Example #6
0
 @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);
   }
 }
Example #7
0
 @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);
   }
 }
Example #8
0
 @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);
   }
 }
Example #9
0
 @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...
 }
Example #10
0
 @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);
   }
 }
Example #11
0
 @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);
   }
 }
Example #12
0
 @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);
   }
 }
Example #13
0
 @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);
   }
 }
  public GwtRenderingContext(Panel root, GwtAppConfiguration config)
      throws ParallaxRuntimeException {
    this.root = root;
    root.clear();

    Canvas canvasWidget = Canvas.createIfSupported();
    if (canvasWidget == null) throw new ParallaxRuntimeException("Canvas not supported");

    int width = root.getOffsetWidth();
    int height = root.getOffsetHeight();

    if (width == 0 || height == 0)
      new ParallaxRuntimeException("Width or Height of the Panel is 0");

    lastWidth = width;
    lastHeight = height;

    canvas = canvasWidget.getCanvasElement();
    root.add(canvasWidget);
    canvas.setWidth(width);
    canvas.setHeight(height);
    this.config = config;

    WebGLContextAttributes attributes = WebGLContextAttributes.create();
    attributes.setAntialias(config.antialiasing);
    attributes.setStencil(config.stencil);
    attributes.setAlpha(config.alpha);
    attributes.setPremultipliedAlpha(config.premultipliedAlpha);
    attributes.setPreserveDrawingBuffer(config.preserveDrawingBuffer);

    context = WebGLRenderingContext.getContext(canvas, attributes);
    context.viewport(0, 0, width, height);

    gl = new GwtGL20(context);

    renderer = new GLRenderer(gl, width, height);

    input = new GwtInput(canvas);

    addEventListeners();

    Window.addResizeHandler(this);
  }
Example #15
0
  public GwtGraphics(Panel root, GwtApplicationConfiguration config) {
    Canvas canvasWidget = Canvas.createIfSupported();
    if (canvasWidget == null) throw new GdxRuntimeException("Canvas not supported");
    canvas = canvasWidget.getCanvasElement();
    root.add(canvasWidget);
    canvas.setWidth(config.width);
    canvas.setHeight(config.height);
    this.config = config;

    WebGLContextAttributes attributes = WebGLContextAttributes.create();
    attributes.setAntialias(config.antialiasing);
    attributes.setStencil(config.stencil);
    attributes.setAlpha(false);
    attributes.setPremultipliedAlpha(false);
    attributes.setPreserveDrawingBuffer(config.preserveDrawingBuffer);

    context = WebGLRenderingContext.getContext(canvas, attributes);
    context.viewport(0, 0, config.width, config.height);
    this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GwtGL20(context);
  }
Example #16
0
 @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());
 }
Example #17
0
 @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());
 }
  HtmlSurfaceLayerGL(HtmlGraphicsGL gfx, int width, int height) {
    super(gfx);

    this.width = width;
    this.height = height;
    gfx.flush();

    WebGLRenderingContext gl = gfx.gl;
    tex = gfx.createTexture(false, false);
    gl.texImage2D(TEXTURE_2D, 0, RGBA, width, height, 0, RGBA, UNSIGNED_BYTE, null);

    fbuf = gl.createFramebuffer();
    gl.bindFramebuffer(FRAMEBUFFER, fbuf);
    gl.framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D, tex, 0);

    gl.bindTexture(TEXTURE_2D, null);
    gfx.bindFramebuffer();

    surface = new HtmlSurfaceGL(gfx, fbuf, width, height);
  }
Example #19
0
 @Override
 public void glUniform3i(int location, int x, int y, int z) {
   WebGLUniformLocation loc = getUniformLocation(location);
   gl.uniform3i(loc, x, y, z);
 }
Example #20
0
 @Override
 public void glUniform3f(int location, float x, float y, float z) {
   WebGLUniformLocation loc = getUniformLocation(location);
   gl.uniform3f(loc, x, y, z);
 }
Example #21
0
 @Override
 public void glUniform3fv(int location, int count, FloatBuffer v) {
   WebGLUniformLocation loc = getUniformLocation(location);
   gl.uniform3fv(loc, copy(v));
 }
Example #22
0
 @Override
 public void glTexParameteriv(int target, int pname, IntBuffer params) {
   gl.texParameterf(target, pname, params.get());
 }
Example #23
0
 @Override
 public void glUniform1i(int location, int x) {
   WebGLUniformLocation loc = getUniformLocation(location);
   gl.uniform1i(loc, x);
 }
Example #24
0
 @Override
 public void glStencilOpSeparate(int face, int fail, int zfail, int zpass) {
   gl.stencilOpSeparate(face, fail, zfail, zpass);
 }
Example #25
0
 @Override
 public void glTexParameteri(int target, int pname, int param) {
   gl.texParameterf(target, pname, param);
 }
Example #26
0
 @Override
 public void glStencilMaskSeparate(int face, int mask) {
   gl.stencilMaskSeparate(face, mask);
 }
Example #27
0
 @Override
 public void glStencilFuncSeparate(int face, int func, int ref, int mask) {
   gl.stencilFuncSeparate(face, func, ref, mask);
 }
Example #28
0
 @Override
 public void glShaderSource(int shader, String source) {
   gl.shaderSource(shaders.get(shader), source);
 }
Example #29
0
 @Override
 public void glSampleCoverage(float value, boolean invert) {
   gl.sampleCoverage(value, invert);
 }
Example #30
0
 @Override
 public void glRenderbufferStorage(int target, int internalformat, int width, int height) {
   gl.renderbufferStorage(target, internalformat, width, height);
 }