Example usage for android.opengl GLES20 glUniform1f

List of usage examples for android.opengl GLES20 glUniform1f

Introduction

In this page you can find the example usage for android.opengl GLES20 glUniform1f.

Prototype

public static native void glUniform1f(int location, float x);

Source Link

Usage

From source file:com.ryandymock.consumptionvisualization.shader.ParticleMaterial.java

@Override
public void beginRender() {
    super.beginRender();

    // Specific uniforms to this material
    GLES20.glUniform1f(getUniformLocation("uPointSize"),
            Math.max(1.0f, mParticleSizeScale * ParticleRenderer.FB_SIZE
                    * (Renderer.PARTICLE_RADIUS / Renderer.getInstance().sRenderWorldHeight)));
}

From source file:com.google.fpl.liquidfunpaint.shader.ParticleMaterial.java

@Override
public void beginRender() {
    super.beginRender();

    float pSize = mParticleSizeScale * ParticleRenderer.FB_SIZE * (ParticleSystems.PARTICLE_RADIUS
            / Math.min(WorldLock.getInstance().sRenderWorldWidth, WorldLock.getInstance().sRenderWorldHeight));

    // Specific uniforms to this material
    GLES20.glUniform1f(getUniformLocation("uPointSize"), Math.max(1.0f, pSize));
}

From source file:com.google.fpl.liquidfunpaint.renderer.ScreenRenderer.java

/**
 * Draw function for the geometry that this class owns.
 */// w  w  w. ja  v a2  s . c o  m
public void draw(float[] transformFromTexture) {
    RenderHelper.SCREEN_QUAD_VERTEX_BUFFER.rewind();

    mMaterial.beginRender();

    // Set attribute arrays
    mMaterial.setVertexAttributeBuffer("aPosition", RenderHelper.SCREEN_QUAD_VERTEX_BUFFER, 0);
    mMaterial.setVertexAttributeBuffer("aTexCoord", RenderHelper.SCREEN_QUAD_VERTEX_BUFFER, 3);

    // Set per draw uniforms
    GLES20.glUniformMatrix4fv(mMaterial.getUniformLocation("uMvpTransform"), 1, false, transformFromTexture, 0);
    GLES20.glUniform1f(mMaterial.getUniformLocation("uAlphaThreshold"), mAlphaThreshold);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 4);

    mMaterial.endRender();
}

From source file:com.ryandymock.consumptionvisualization.shader.WaterParticleMaterial.java

@Override
public void beginRender() {
    super.beginRender();

    // Specific uniforms to this material
    GLES20.glUniform1f(getUniformLocation("uPointSize"),
            Math.max(1.0f, mParticleSizeScale * ParticleRenderer.FB_SIZE
                    * (Renderer.PARTICLE_RADIUS / Renderer.getInstance().sRenderWorldHeight)));
    GLES20.glUniform3fv(getUniformLocation("uWeightParams"), 1, mWeightParams, 0);
}

From source file:com.google.fpl.liquidfunpaint.shader.WaterParticleMaterial.java

@Override
public void beginRender() {
    super.beginRender();

    float pSize = mParticleSizeScale * ParticleRenderer.FB_SIZE * (ParticleSystems.PARTICLE_RADIUS
            / Math.min(WorldLock.getInstance().sRenderWorldWidth, WorldLock.getInstance().sRenderWorldHeight));

    // Specific uniforms to this material
    GLES20.glUniform1f(getUniformLocation("uPointSize"), Math.max(1.0f, pSize));
    GLES20.glUniform3fv(getUniformLocation("uWeightParams"), 1, mWeightParams, 0);
}

From source file:com.kentdisplays.synccardboarddemo.Page.java

/**
 * Encapsulates the OpenGL ES instructions for drawing this page.
 *
 * @param perspective//from  ww  w.j a  v a  2 s .c  om
 * @param view
 */
public void draw(float[] perspective, float[] view) {
    mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
    mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
    mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");
    mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP");
    mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor");
    mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model");
    mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix");

    // This is not the floor!
    GLES20.glUniform1f(mIsFloorParam, 0f);

    // Set the Model in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModel, 0);

    // Build the ModelView and ModelViewProjection matrices
    // for calculating cube position and light.
    float[] modelView = new float[16];
    float[] modelViewProjection = new float[16];
    Matrix.multiplyMM(modelView, 0, view, 0, mModel, 0);
    Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);

    // Set the ModelView in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, modelView, 0);

    // Set the position of the cube
    GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mPageVertices);

    // Set the ModelViewProjection matrix in the shader.
    GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, modelViewProjection, 0);

    // Set the normal positions of the cube, again for shading
    GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mPageNormals);

    GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mPageColors);

    // Animate over all the paths every 30 seconds.
    long time = SystemClock.uptimeMillis() % 30000L;
    int numberOfPathsToDraw = Math.round(mNumberOfPaths / 30000.0f * time);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, numberOfPathsToDraw * 6);
}

From source file:com.kentdisplays.synccardboarddemo.MainActivity.java

/**
 * Draw the floor. This feeds in data for the floor into the shader. Note that this doesn't
 * feed in data about position of the light, so if we rewrite our code to draw the floor first,
 * the lighting might look strange./*from   w  w w . ja v a 2 s  .  co m*/
 */
public void drawFloor(float[] perspective) {
    // This is the floor!
    GLES20.glUniform1f(mIsFloorParam, 1f);

    // Set ModelView, MVP, position, normals, and color
    GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelFloor, 0);
    GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0);
    GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0);
    GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mFloorVertices);
    GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mFloorNormals);
    GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mFloorColors);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);

    checkGLError("drawing floor");
}

From source file:com.tumblr.cardboard.Tumblr3DActivity.java

/**
 * Draw the rect. We've set all of our transformation matrices. Now we simply pass them into
 * the shader.//  www .  jav a 2s . c  o  m
 */
public void drawRect(int texIndex) {
    if (mRectTextureIds[texIndex] < INVALID_TEXTURE) {
        // can't draw this rectangle
        return;
    }

    // This is not the floor!
    GLES20.glUniform1f(mIsFloorParam, 0f);

    // Set the active texture unit
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texIndex);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mRectTextureIds[texIndex]);

    // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0.
    GLES20.glUniform1i(mRectTextureUniformParam, texIndex);

    // Set the Model in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelRect[texIndex], 0);

    // Set the ModelView in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0);

    // Set the position of the rect
    GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mRectVertices);

    // Set the ModelViewProjection matrix in the shader.
    GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0);

    // Set the normal positions of the rect, again for shading
    GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mRectNormals);

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(mRectTextureCoordinateParam, 2, GLES20.GL_FLOAT, false, 0, mRectTexCoords);

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(mRectTextureCoordinateParam);

    if (texIndex == mSelectedTexIndex || isLookingAtObject(texIndex)) {
        GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mRectFoundColors);
    } else {
        GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mRectColors);
    }
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, WorldLayoutData.RECT_COORDS.length / 3); // 3 b/c triangles
    checkGLError("Drawing rect");
}

From source file:com.tumblr.cardboard.Tumblr3DActivity.java

/**
 * Draw the floor. This feeds in data for the floor into the shader. Note that this doesn't
 * feed in data about position of the light, so if we rewrite our code to draw the floor first,
 * the lighting might look strange./*www .j  av  a 2s  .co m*/
 */
@SuppressWarnings("UnusedParameters")
public void drawFloor(float[] perspective) {
    // This is the floor!
    GLES20.glUniform1f(mIsFloorParam, 1f);

    // Set ModelView, MVP, position, normals, and color
    GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelFloor, 0);
    GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0);
    GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0);
    GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mFloorVertices);
    GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mFloorNormals);
    GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mFloorColors);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);

    checkGLError("drawing floor");
}

From source file:com.aimfire.gallery.cardboard.PhotoActivity.java

/**
 * Draws a frame for an eye.//from   www.  ja v a  2  s  . c om
 *
 * @param eye The eye to render. Includes all required transformations.
 */
@Override
public void onDrawEye(Eye eye) {
    if (mAssetInd == -1) {
        // we are still showing instruction, return without doing anything
        return;
    }

    if (!mAssetChangedLeft && !mAssetChangedRight) {
        // nothing changed, do nothing and return
        return;
    }

    if (eye.getType() == Eye.Type.LEFT)
        mAssetChangedLeft = false;
    else if (eye.getType() == Eye.Type.RIGHT)
        mAssetChangedRight = false;

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    checkGLError("mColorParam");

    GLES20.glUseProgram(mPicProgram);

    GLES20.glUniform1f(mDimRatioParam, mDimRatio);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    if (eye.getType() == Eye.Type.LEFT) {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureCurr[0]);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureCurr[1]);
    }

    // set the zoom level
    GLES20.glUniform1f(mZoomParam, sZoom[mImgZoomInd]);

    /*
     * if user prefers negative parallax, shift window on left frame leftward and right frame
     * rightward. if user prefers positive parallax, do the opposite
     */
    if (eye.getType() == Eye.Type.LEFT) {
        GLES20.glUniform1f(mParallaxParam, mImgParallaxAdj / 2.0f);
    } else {
        GLES20.glUniform1f(mParallaxParam, -mImgParallaxAdj / 2.0f);
    }

    // Set the position of the picture
    //float zoomCoords[] = new float[picCoords.length];
    //for(int i=0; i<picCoords.length; i++)
    //zoomCoords[i] = picCoords[i] * zoom[zoomInd];

    //ByteBuffer bblVertices = ByteBuffer.allocateDirect(zoomCoords.length * 4);
    ByteBuffer bblVertices = ByteBuffer.allocateDirect(picCoords.length * 4);
    bblVertices.order(ByteOrder.nativeOrder());
    mPicVertices = bblVertices.asFloatBuffer();
    //mPicVertices.put(zoomCoords);
    mPicVertices.put(picCoords);
    mPicVertices.position(0);

    GLES20.glVertexAttribPointer(mPicPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride,
            mPicVertices);

    GLES20.glDrawElements(GLES20.GL_TRIANGLES, /* mode */
            6, /* count */
            GLES20.GL_UNSIGNED_SHORT, /* type */
            mPicElements /* element array buffer offset */
    );
}