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