Example #1
0
  protected boolean prepare(int fbufWidth, int fbufHeight) {
    if (ctx.useShader(this) && glIsProgram(program)) {
      glUseProgram(program);
      ctx.checkGLError("Shader.prepare useProgram");

      glUniform2f(uScreenSizeLoc, fbufWidth, fbufHeight);
      // ctx.checkGLError("Shader.prepare uScreenSizeLoc set to " + fbufWidth + " " + fbufHeight);

      glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
      ctx.checkGLError("Shader.prepare BindBuffer");

      glEnableVertexAttribArray(aMatrix);
      glEnableVertexAttribArray(aTranslation);
      glEnableVertexAttribArray(aPosition);
      if (aTexture != -1) glEnableVertexAttribArray(aTexture);
      ctx.checkGLError("Shader.prepare AttribArrays enabled");

      glVertexAttribPointer(aMatrix, 4, GL_FLOAT, false, VERTEX_STRIDE, 0);
      glVertexAttribPointer(aTranslation, 2, GL_FLOAT, false, VERTEX_STRIDE, 16);
      glVertexAttribPointer(aPosition, 2, GL_FLOAT, false, VERTEX_STRIDE, 24);
      if (aTexture != -1) glVertexAttribPointer(aTexture, 2, GL_FLOAT, false, VERTEX_STRIDE, 32);
      ctx.checkGLError("Shader.prepare AttribPointer");
      return true;
    }
    return false;
  }
Example #2
0
  private void initGLObjects() {
    if (clTexture != NULL) {
      checkCLError(clReleaseMemObject(clTexture));
      glDeleteTextures(glTexture);
    }

    glTexture = glGenTextures();

    // Init textures
    glBindTexture(GL_TEXTURE_2D, glTexture);
    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_RGBA8UI,
        ww,
        wh,
        0,
        GL_RGBA_INTEGER,
        GL_UNSIGNED_BYTE,
        (ByteBuffer) null);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    clTexture =
        clCreateFromGLTexture2D(
            clContext, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, glTexture, errcode_ret);
    checkCLError(errcode_ret);
    glBindTexture(GL_TEXTURE_2D, 0);

    glViewport(0, 0, fbw, fbh);

    glUniform2f(sizeUniform, ww, wh);

    FloatBuffer projectionMatrix = BufferUtils.createFloatBuffer(4 * 4);
    glOrtho(0.0f, ww, 0.0f, wh, 0.0f, 1.0f, projectionMatrix);
    glUniformMatrix4fv(projectionUniform, false, projectionMatrix);

    shouldInitBuffers = false;
  }