Package java.nio

Examples of java.nio.FloatBuffer


    this.buffer = BufferUtils.createFloatBuffer(startSize);
  }

  private void checkSize(final int count) {
    while ( buffer.remaining() < count ) {
      final FloatBuffer newBuffer = BufferUtils.createFloatBuffer(buffer.capacity() << 1);
      buffer.flip();
      newBuffer.put(buffer);
      buffer = newBuffer;
    }
  }
View Full Code Here


            // When drawing with vertex arrays we can bind the vertex buffer once. When using vertex buffer objects
            // we need to check to make sure that the vbo is available each time through the loop because loading
            // textures may force vbos out of the cache (see loop below).
            if (!this.shouldUseVBOs(dc))
            {
                FloatBuffer vb = this.coordBuffer;
                gl.glVertexPointer(ColladaAbstractGeometry.COORDS_PER_VERTEX, GL.GL_FLOAT, 0, vb.rewind());
            }

            for (Geometry geometry : this.geometries)
            {
                Material nextMaterial = geometry.material != null ? geometry.material : defaultMaterial;

                // Apply new material if necessary
                if (!dc.isPickingMode() && !nextMaterial.equals(activeMaterial))
                {
                    this.applyMaterial(dc, nextMaterial);
                    activeMaterial = nextMaterial;
                }

                if (!dc.isPickingMode()
                    && this.mustApplyTexture(geometry)
                    && this.getTexture(geometry).bind(dc)) // bind initiates retrieval
                {
                    this.getTexture(geometry).applyInternalTransform(dc);

                    if (!texturesEnabled)
                    {
                        gl.glEnable(GL.GL_TEXTURE_2D);
                        gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
                        texturesEnabled = true;
                    }

                    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
                    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);

                    gl.glTexCoordPointer(ColladaAbstractGeometry.TEX_COORDS_PER_VERTEX, GL.GL_FLOAT, 0,
                        this.textureCoordsBuffer.rewind());
                }
                else if (texturesEnabled)
                {
                    gl.glDisable(GL.GL_TEXTURE_2D);
                    gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
                    texturesEnabled = false;
                }

                // If this geometry is double sided, then backface culling must be disabled. Otherwise backface culling
                // must be enabled, because some SketchUp models will not render correctly without it.
                if (geometry.doubleSided && cullingEnabled)
                {
                    gl.glDisable(GL.GL_CULL_FACE);
                    cullingEnabled = false;
                }
                else if (!geometry.doubleSided && !cullingEnabled)
                {
                    gl.glEnable(GL.GL_CULL_FACE);
                    cullingEnabled = true;
                }

                // Look up VBO IDs each time through the loop because binding a texture may bump a VBO out of the cache.
                // If VBOs are not used, the vertex array is bound once, before the loop.
                int[] vboIds = null;
                if (this.shouldUseVBOs(dc))
                {
                    vboIds = this.getVboIds(dc);
                    if (vboIds == null)
                    {
                        FloatBuffer vb = this.coordBuffer;
                        gl.glVertexPointer(ColladaAbstractGeometry.COORDS_PER_VERTEX, GL.GL_FLOAT, 0, vb.rewind());
                    }
                }

                if (vboIds != null)
                    this.doDrawInteriorVBO(dc, geometry, vboIds);
View Full Code Here

                size);
        }

        try
        {
            FloatBuffer vb = this.coordBuffer;
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboIds[0]);
            gl.glBufferData(GL.GL_ARRAY_BUFFER, vb.limit() * Buffers.SIZEOF_FLOAT, vb.rewind(), GL.GL_STATIC_DRAW);
        }
        finally
        {
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
        }
View Full Code Here

   *
   * @return The background color of this graphics context
   */
  public Color getBackground() {
    predraw();
    FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
    GL.glGetFloat(SGL.GL_COLOR_CLEAR_VALUE, buffer);
    postdraw();

    return new Color(buffer);
  }
View Full Code Here

    }

    public void updateBalls(final int count) {
      // Depth data

      final FloatBuffer depths = BufferUtils.createFloatBuffer(count * 2);
      final float depthStep = 1.9f / count;
      float depth = Float.parseFloat("0x1.fffffep-1");
      // Front-to-back
      for ( int i = 0; i < count; i++ ) {
        depths.put(depth);
        depth -= depthStep;
      }
      // Back-to-front
      for ( int i = 0; i < count; i++ )
        depths.put(depths.get(count - 1 - i));
      depths.flip();

      if ( depthVBO != 0 )
        glDeleteBuffers(depthVBO);

      depthVBO = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, depthVBO);
      glBufferData(GL_ARRAY_BUFFER, depths, GL_STATIC_DRAW);

      glEnableVertexAttribArray(depthLoc);
      glVertexAttribPointer(depthLoc, 1, GL_FLOAT, false, 0, 0);

      // Animation data

      final FloatBuffer transform = BufferUtils.createFloatBuffer(count * 2 * 4);
      // Front-to-back
      final Random random = new Random();
      for ( int i = 0; i < count; i++ ) {
        transform.put((int)(random.nextFloat() * (SCREEN_WIDTH - ballSize) + ballSize * 0.5f));
        transform.put((int)(random.nextFloat() * (SCREEN_HEIGHT - ballSize) + ballSize * 0.5f));
        transform.put(random.nextFloat() * 0.4f - 0.2f);
        transform.put(random.nextFloat() * 0.4f - 0.2f);
      }
      // Back-to-front
      for ( int i = 0; i < count; i++ ) {
        final int offset = (count - 1 - i) * 4;
        transform.put(transform.get(offset + 0));
        transform.put(transform.get(offset + 1));
        transform.put(transform.get(offset + 2));
        transform.put(transform.get(offset + 3));
      }
      transform.flip();

      if ( tfVBO[0] != 0 ) {
        for ( int i = 0; i < tfVBO.length; i++ )
          glDeleteBuffers(tfVBO[i]);
      }
View Full Code Here

    }

    public void updateBalls(final int count) {
      if ( tfVBO[0] != 0 ) {
        // Fetch current animation state
        final FloatBuffer state = BufferUtils.createFloatBuffer(transform.length);
        glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, state);
        state.get(transform);
      }

      super.updateBalls(count);

      if ( tfVBO[0] != 0 ) {
        for ( int i = 0; i < tfVBO.length; i++ )
          glDeleteBuffers(tfVBO[i]);
      }

      final FloatBuffer state = BufferUtils.createFloatBuffer(count * 4);
      state.put(transform);
      state.flip();

      for ( int i = 0; i < tfVBO.length; i++ ) {
        tfVBO[i] = glGenBuffers();
        glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, tfVBO[i]);
        glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, state, GL_STATIC_DRAW);
View Full Code Here

    }

    public void updateBalls(final int count) {
      kernelGlobalWorkSize.put(0, ballCount);

      final FloatBuffer transform = BufferUtils.createFloatBuffer(count * 4);

      final Random random = new Random();
      for ( int i = 0; i < count; i++ ) {
        transform.put((int)(random.nextFloat() * (SCREEN_WIDTH - ballSize)) + ballSize * 0.5f);
        transform.put((int)(random.nextFloat() * (SCREEN_HEIGHT - ballSize)) + ballSize * 0.5f);
        transform.put(random.nextFloat() * 0.4f - 0.2f);
        transform.put(random.nextFloat() * 0.4f - 0.2f);
      }
      transform.flip();

      if ( animVBO != 0 ) {
        clReleaseMemObject(clTransform);
        glDeleteBuffers(animVBO);
      }
View Full Code Here

    indices_buffer_id = int_buffer.get(1);

    glBindBuffer(GL_ARRAY_BUFFER, buffer_id);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer_id);

    final FloatBuffer vertices = BufferUtils.createFloatBuffer(2 * 4);
    vertices
      .put(-50).put(-50)
      .put(50).put(-50)
      .put(-50).put(50)
      .put(50).put(50);
    vertices.rewind();

    final IntBuffer indices = BufferUtils.createIntBuffer(4);
    indices.put(0).put(1).put(2).put(3);
    indices.rewind();

View Full Code Here

        throw new IllegalArgumentException("Invalid contrast value");
      int rampSize = display_impl.getGammaRampLength();
      if ( rampSize == 0 ) {
        throw new LWJGLException("Display configuration not supported");
      }
      FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize);
      for ( int i = 0; i < rampSize; i++ ) {
        float intensity = (float)i / (rampSize - 1);
        // apply gamma
        float rampEntry = (float)java.lang.Math.pow(intensity, gamma);
        // apply brightness
        rampEntry += brightness;
        // apply contrast
        rampEntry = (rampEntry - 0.5f) * contrast + 0.5f;
        // Clamp entry to [0, 1]
        if ( rampEntry > 1.0f )
          rampEntry = 1.0f;
        else if ( rampEntry < 0.0f )
          rampEntry = 0.0f;
        gammaRamp.put(i, rampEntry);
      }
      display_impl.setGammaRamp(gammaRamp);
      LWJGLUtil.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
    }
  }
View Full Code Here

        _supportsAniso = caps.GL_EXT_texture_filter_anisotropic;

        if (_supportsAniso) {
            // Due to LWJGL buffer check, you can't use smaller sized
            // buffers (min_size = 16 for glGetFloat()).
            final FloatBuffer max_a = BufferUtils.createFloatBuffer(16);
            max_a.rewind();

            // Grab the maximum anisotropic filter.
            GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max_a);

            // set max.
            _maxAnisotropic = max_a.get(0);
        }

        // See if we support textures that are not power of 2 in size.
        _supportsNonPowerTwo = caps.GL_ARB_texture_non_power_of_two;
View Full Code Here

TOP

Related Classes of java.nio.FloatBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.