public void applyParameters(ShaderProgram program) {
    LocalPlayer localPlayer = CoreRegistry.get(LocalPlayer.class);

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    glBindTexture(GL11.GL_TEXTURE_2D, terrainTex.getId());

    if (localPlayer != null) program.setInt("carryingTorch", localPlayer.isCarryingTorch() ? 1 : 0);
  }
 @Override
 public void unbind(final ShaderProgram shader, final int[] locations) {
   final GL20 gl = App.getGL20();
   final int numAttributes = attributes.size();
   if (locations == null) {
     for (int i = 0; i < numAttributes; i++) {
       shader.disableVertexAttribute(attributes.get(i).alias);
     }
   } else {
     for (int i = 0; i < numAttributes; i++) {
       final int location = locations[i];
       if (location >= 0) shader.disableVertexAttribute(location);
     }
   }
   gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
   isBound = false;
 }
示例#3
0
  public void draw(ShaderProgram program, BoundingFrustum frustum) {
    program.reset();

    final Matrix matrix = getModelMatrix();
    final LWJGLModel3D model = (LWJGLModel3D) getModel();
    for (final Group g : model.getGroups()) {
      for (final IBufferObject ib : g.getBuffers()) {
        BufferObject b = (BufferObject) ib;
        final BoundingSphere sph = TEMP_SPHERE_DRAW.set(b);
        sph.add(matrix.getTranslation());
        if (frustum.contains(sph) != ContainmentType.Disjoint) {
          b.bind(program);
          program.setModelMatrix(matrix);
          b.draw(program);
        }
      }
    }
  }
示例#4
0
 @Override
 protected void bindAttributes() {
   super.bindAttribute(0, "position");
 }
示例#5
0
 public void loadViewMatrix(Camera camera) {
   Matrix4f matrix = Maths.createViewMatrix(camera);
   super.loadMatrix(location_viewMatrix, matrix);
 }
示例#6
0
 public void loadProjectionMatrix(Matrix4f matrix) {
   super.loadMatrix(location_projectionMatrix, matrix);
 }
  @Override
  public void applyParameters(ShaderProgram program) {
    super.applyParameters(program);

    DefaultRenderingProcess.FBO sceneOpaque =
        DefaultRenderingProcess.getInstance().getFBO("sceneOpaque");

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneOpaque.bindTexture();
    program.setInt("texSceneOpaque", texId++);

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneOpaque.bindDepthTexture();
    program.setInt("texSceneOpaqueDepth", texId++);

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneOpaque.bindNormalsTexture();
    program.setInt("texSceneOpaqueNormals", texId++);

    DefaultRenderingProcess.FBO sceneTransparent =
        DefaultRenderingProcess.getInstance().getFBO("sceneTransparent");

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneTransparent.bindTexture();
    program.setInt("texSceneTransparent", texId++);

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneTransparent.bindDepthTexture();
    program.setInt("texSceneTransparentDepth", texId++);

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneTransparent.bindNormalsTexture();
    program.setInt("texSceneTransparentNormals", texId++);

    if (CoreRegistry.get(Config.class).getRendering().isSsao()) {
      DefaultRenderingProcess.FBO ssao =
          DefaultRenderingProcess.getInstance().getFBO("ssaoBlurred1");
      GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
      ssao.bindTexture();
      program.setInt("texSsao", texId++);
    }

    if (CoreRegistry.get(Config.class).getRendering().isOutline()) {
      DefaultRenderingProcess.FBO sobel = DefaultRenderingProcess.getInstance().getFBO("sobel");
      GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
      sobel.bindTexture();
      program.setInt("texEdges", texId++);

      program.setFloat("outlineDepthThreshold", (Float) outlineDepthThreshold.getValue());
      program.setFloat("outlineThickness", (Float) outlineThickness.getValue());
    }

    program.setFloat("shoreStart", (Float) shoreStart.getValue());
    program.setFloat("shoreEnd", (Float) shoreEnd.getValue());
  }
 @Override
 protected void bindAttributes() {
   super.bindAttribute(0, "position");
   super.bindAttribute(1, "texCoords");
 }
  @Override
  public void bind(ShaderProgram shader, int[] locations) {

    if (bufferHandle == 0) throw new GLViewRuntimeException("No buffer allocated!");

    final GL20 gl = App.getGL20();

    gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle);
    if (isDirty) {
      byteBuffer.limit(buffer.limit() * 4);
      gl.glBufferData(GL20.GL_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage);
      isDirty = false;
    }

    final int numAttributes = attributes.size();
    if (locations == null) {
      for (int i = 0; i < numAttributes; i++) {
        final VertexAttribute attribute = attributes.get(i);
        final int location = shader.getAttributeLocation(attribute.alias);
        if (location < 0) continue;
        shader.enableVertexAttribute(location);

        if (attribute.usage == Usage.ColorPacked)
          shader.setVertexAttribute(
              location,
              attribute.numComponents,
              GL20.GL_UNSIGNED_BYTE,
              true,
              attributes.vertexSize,
              attribute.offset);
        else
          shader.setVertexAttribute(
              location,
              attribute.numComponents,
              GL20.GL_FLOAT,
              false,
              attributes.vertexSize,
              attribute.offset);
      }
    } else {
      for (int i = 0; i < numAttributes; i++) {
        final VertexAttribute attribute = attributes.get(i);
        final int location = locations[i];
        if (location < 0) continue;
        shader.enableVertexAttribute(location);

        if (attribute.usage == Usage.ColorPacked)
          shader.setVertexAttribute(
              location,
              attribute.numComponents,
              GL20.GL_UNSIGNED_BYTE,
              true,
              attributes.vertexSize,
              attribute.offset);
        else
          shader.setVertexAttribute(
              location,
              attribute.numComponents,
              GL20.GL_FLOAT,
              false,
              attributes.vertexSize,
              attribute.offset);
      }
    }
    isBound = true;
  }