Java Code Examples for android.opengl.GLES20#glBindBuffer()

The following examples show how to use android.opengl.GLES20#glBindBuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlPreviewFilter.java    From GPUVideo-android with MIT License 6 votes vote down vote up
public void draw(final int texName, final float[] mvpMatrix, final float[] stMatrix, final float aspectRatio) {
    useProgram();

    GLES20.glUniformMatrix4fv(getHandle("uMVPMatrix"), 1, false, mvpMatrix, 0);
    GLES20.glUniformMatrix4fv(getHandle("uSTMatrix"), 1, false, stMatrix, 0);
    GLES20.glUniform1f(getHandle("uCRatio"), aspectRatio);

    GLES20.glBindBuffer(GL_ARRAY_BUFFER, getVertexBufferName());
    GLES20.glEnableVertexAttribArray(getHandle("aPosition"));
    GLES20.glVertexAttribPointer(getHandle("aPosition"), VERTICES_DATA_POS_SIZE, GL_FLOAT, false, VERTICES_DATA_STRIDE_BYTES, VERTICES_DATA_POS_OFFSET);
    GLES20.glEnableVertexAttribArray(getHandle("aTextureCoord"));
    GLES20.glVertexAttribPointer(getHandle("aTextureCoord"), VERTICES_DATA_UV_SIZE, GL_FLOAT, false, VERTICES_DATA_STRIDE_BYTES, VERTICES_DATA_UV_OFFSET);

    GLES20.glActiveTexture(GL_TEXTURE0);
    GLES20.glBindTexture(texTarget, texName);
    GLES20.glUniform1i(getHandle(DEFAULT_UNIFORM_SAMPLER), 0);

    GLES20.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    GLES20.glDisableVertexAttribArray(getHandle("aPosition"));
    GLES20.glDisableVertexAttribArray(getHandle("aTextureCoord"));
    GLES20.glBindBuffer(GL_ARRAY_BUFFER, 0);
    GLES20.glBindTexture(GL_TEXTURE_2D, 0);
}
 
Example 2
Source File: GLHelper.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * バッファーオブジェクトを生成&データをセットしてバッファー名を返す
 * @param target GL_ARRAY_BUFFERまたはGL_ELEMENT_ARRAY_BUFFER
 * @param data
 * @param usage GL_STATIC_DRAW, GL_STREAM_DRAW, GL_DYNAMIC_DRAW
 * @return
 */
public static int createBuffer(final int target, @NonNull final FloatBuffer data, final int usage) {
	final int[] ids = new int[1];
	GLES20.glGenBuffers(1, ids, 0);
	checkGlError("glGenBuffers");
	GLES20.glBindBuffer(target, ids[0]);
	checkGlError("glBindBuffer");
	GLES20.glBufferData(target, SIZEOF_FLOAT_BYTES * data.limit(), data, usage);
	checkGlError("glBufferData");
	GLES20.glBindBuffer(target, 0);
	return ids[0];
}
 
Example 3
Source File: FeatureShader.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
public void setTextureCoordinates(final int textureBufferHandle) {
	if (programHandle == -1) {
		initProgram();
	}

	if (textureCoordinateHandle >= 0) {
		GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, textureBufferHandle);
		GLES20.glEnableVertexAttribArray(textureCoordinateHandle);
		GLES20.glVertexAttribPointer(textureCoordinateHandle, 2,
				GLES20.GL_FLOAT, false, 0, 0);
	}
}
 
Example 4
Source File: DistortionRenderer.java    From Cardboard with Apache License 2.0 5 votes vote down vote up
private void renderDistortionMesh(DistortionMesh mesh) {
	GLES20.glBindBuffer(34962, mesh.mArrayBufferId);
	mesh.getClass();
	mesh.getClass();
	GLES20.glVertexAttribPointer(this.mProgramHolder.aPosition, 3, 5126,
			false, 20, 0 * 4);

	GLES20.glEnableVertexAttribArray(this.mProgramHolder.aPosition);

	mesh.getClass();
	mesh.getClass();
	GLES20.glVertexAttribPointer(this.mProgramHolder.aVignette, 1, 5126,
			false, 20, 2 * 4);

	GLES20.glEnableVertexAttribArray(this.mProgramHolder.aVignette);

	mesh.getClass();
	mesh.getClass();
	GLES20.glVertexAttribPointer(this.mProgramHolder.aTextureCoord, 2,
			5126, false, 20, 3 * 4);

	GLES20.glEnableVertexAttribArray(this.mProgramHolder.aTextureCoord);

	GLES20.glActiveTexture(33984);
	GLES20.glBindTexture(3553, this.mTextureId);
	GLES20.glUniform1i(this.mProgramHolder.uTextureSampler, 0);
	GLES20.glUniform1f(this.mProgramHolder.uTextureCoordScale,
			this.mResolutionScale);

	GLES20.glBindBuffer(34963, mesh.mElementBufferId);
	GLES20.glDrawElements(5, mesh.nIndices, 5125, 0);
}
 
Example 5
Source File: GLES20Canvas.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
private void setPosition(ShaderParameter[] params, int offset) {
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBoxCoordinates);
    checkError();
    GLES20.glVertexAttribPointer(params[INDEX_POSITION].handle, COORDS_PER_VERTEX,
            GLES20.GL_FLOAT, false, VERTEX_STRIDE, offset * VERTEX_STRIDE);
    checkError();
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    checkError();
}
 
Example 6
Source File: Points.java    From ShapesInOpenGLES2.0 with MIT License 5 votes vote down vote up
/**
 * create buffers for the Points shape object
 * @param pointPositions
 * @param pointColors
 */
public void createBuffers(float[] pointPositions, float[] pointColors) {
    // First, copy cube information into client-side floating point buffers.
    FloatBuffer pointPositionsBuffer;
    FloatBuffer pointColorsBuffer;

    try{
        vertexCount = pointPositions.length / POSITION_DATA_SIZE;

        pointPositionsBuffer = ByteBuffer.allocateDirect(pointPositions.length * BYTES_PER_FLOAT)
                .order(ByteOrder.nativeOrder()).asFloatBuffer();
        pointPositionsBuffer.put(pointPositions).position(0);

        pointColorsBuffer = ByteBuffer.allocateDirect(pointColors.length * BYTES_PER_FLOAT)
                .order(ByteOrder.nativeOrder()).asFloatBuffer();
        pointColorsBuffer.put(pointColors).position(0);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, glPointBuffer[0]);
        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, pointPositionsBuffer.capacity() * BYTES_PER_FLOAT, pointPositionsBuffer, GLES20.GL_STATIC_DRAW);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, glPointBuffer[1]);
        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, pointColorsBuffer.capacity() * BYTES_PER_FLOAT, pointColorsBuffer, GLES20.GL_STATIC_DRAW);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

        aPointPositionsBufferIdx = glPointBuffer[0];
        aPointColorsBufferIdx = glPointBuffer[1];

        pointPositionsBuffer.limit(0);
        pointPositionsBuffer = null;
        pointColorsBuffer.limit(0);
        pointColorsBuffer = null;
    }catch (Exception e){
        Log.d(Tag,"point buffer creation failed:", e);
    }
}
 
Example 7
Source File: CameraViewModel.java    From VIA-AI with MIT License 5 votes vote down vote up
private void checkDataUpdate()
{
    if(mNeedUpdate) {
        // VBO update vertex coordinate
        ByteBuffer bb = ByteBuffer.allocateDirect(mPosition.length * 4);
        bb.order(ByteOrder.nativeOrder());
        FloatBuffer vertexBuffer = bb.asFloatBuffer();
        vertexBuffer.put(mPosition);
        vertexBuffer.position(0);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mPositionVBO[0]);
        GLUtility.checkGlError("glBindBuffer");

        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mPosition.length * 4, vertexBuffer, GLES20.GL_STATIC_DRAW);
        GLUtility.checkGlError("glBufferData");


        // VBO update texture coordinate
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mTextureCoordinateVBO[0]);
        GLUtility.checkGlError("glBindBuffer");

        bb = ByteBuffer.allocateDirect(mTextureCoordinate.length * 4);
        bb.order(ByteOrder.nativeOrder());
        FloatBuffer textureCoordinateBuffer = bb.asFloatBuffer();
        textureCoordinateBuffer.put(mTextureCoordinate);
        textureCoordinateBuffer.position(0);

        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mTextureCoordinate.length * 4, textureCoordinateBuffer, GLES20.GL_STATIC_DRAW);
        GLUtility.checkGlError("glBufferData");

        mNeedUpdate = false;
    }
}
 
Example 8
Source File: Points.java    From ShapesInOpenGLES2.0 with MIT License 5 votes vote down vote up
/**
 * draws the Points shape object
 * @param aMVPMatrix
 */
public void render(float[] aMVPMatrix) {

    // Set our per-vertex lighting program.
    GLES20.glUseProgram(aPointProgramHandle);

    aMVPMatrixHandle = GLES20.glGetUniformLocation(aPointProgramHandle, "u_MVPMatrix");
    aPositionHandle = GLES20.glGetAttribLocation(aPointProgramHandle, "a_Position");
    aColorHandle = GLES20.glGetAttribLocation(aPointProgramHandle, "a_Color");

    // Pass in the combined matrix.
    GLES20.glUniformMatrix4fv(aMVPMatrixHandle, 1, false, aMVPMatrix, 0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, aPointPositionsBufferIdx);
    GLES20.glEnableVertexAttribArray(aPositionHandle);
    GLES20.glVertexAttribPointer(aPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, 0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, aPointColorsBufferIdx);
    GLES20.glEnableVertexAttribArray(aColorHandle);
    GLES20.glVertexAttribPointer(aColorHandle, COLOR_DATA_SIZE, GLES20.GL_FLOAT, false, 0, 0);

    // Clear the currently bound buffer (so future OpenGL calls do not use this buffer).
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    // Draw the point.
    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, vertexCount);
}
 
Example 9
Source File: HeightMap.java    From ShapesInOpenGLES2.0 with MIT License 5 votes vote down vote up
public static void createBuffers() {
    final FloatBuffer heightMapVertexDataBuffer = ByteBuffer
            .allocateDirect(aHeightMapVertexData.length * BYTES_PER_FLOAT).order(ByteOrder.nativeOrder())
            .asFloatBuffer();
    heightMapVertexDataBuffer.put(aHeightMapVertexData).position(0);

    final ShortBuffer heightMapIndexDataBuffer = ByteBuffer
            .allocateDirect(aHeightMapIndexData.length * BYTES_PER_SHORT).order(ByteOrder.nativeOrder())
            .asShortBuffer();
    heightMapIndexDataBuffer.put(aHeightMapIndexData).position(0);

    if (vbo[0] > 0 && ibo[0] > 0) {
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo[0]);
        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, heightMapVertexDataBuffer.capacity() * BYTES_PER_FLOAT,
                heightMapVertexDataBuffer, GLES20.GL_STATIC_DRAW);

        GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo[0]);
        GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, heightMapIndexDataBuffer.capacity()
                * BYTES_PER_SHORT, heightMapIndexDataBuffer, GLES20.GL_STATIC_DRAW);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
        GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

    } else {
        GlUtil.checkGlError("glGenBuffers");
    }
}
 
Example 10
Source File: BaseRenderer.java    From VidEffects with Apache License 2.0 5 votes vote down vote up
protected void init() {
    GLES20.glGenBuffers(2, bufferHandles, 0);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferHandles[0]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, Utils.VERTICES.length * FLOAT_SIZE_BYTES, Utils.getVertexBuffer(), GLES20.GL_DYNAMIC_DRAW);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, bufferHandles[1]);
    GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, Utils.INDICES.length * FLOAT_SIZE_BYTES, Utils.getIndicesBuffer(), GLES20.GL_DYNAMIC_DRAW);
    GLES20.glGenTextures(2, textureHandles, 0);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureHandles[0]);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
}
 
Example 11
Source File: DebugMeshShaderRenderer.java    From justaline-android with Apache License 2.0 4 votes vote down vote up
/**
 * Allocates and initializes OpenGL resources needed by the Line renderer.  Must be
 * called on the OpenGL thread, typically in
 * {@link GLSurfaceView.Renderer#onSurfaceCreated(GL10, EGLConfig)}.
 *
 * @param context Needed to access shader source.
 */
public void createOnGlThread(Context context) {
    ShaderUtil.checkGLError(TAG, "before create");

    int buffers[] = new int[1];
    GLES20.glGenBuffers(1, buffers, 0);
    mVbo = buffers[0];
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);
    mVboSize = 0;
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mVboSize, null, GLES20.GL_DYNAMIC_DRAW);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);


    ShaderUtil.checkGLError(TAG, "buffer alloc");


    /*
     *
     * The LineShaderRenderer uses an ES2 pipeline.  It uses the line_vert.glsl and
     * line_frag.glsl shader to render a volumetric line.  It uses several techniques detailed in
     * the following resources:
     *
     *      Drawing Lines is Hard by Matt DesLauriers
     *          https://mattdesl.svbtle.com/drawing-lines-is-hard
     *
     *      InkSpace an Android Experiment by Zach Lieberman
     *          https://experiments.withgoogle.com/android/ink-space
     *          https://github.com/ofZach/inkSpace
     *
     *      THREEJS.MeshLine by Jaume Sanchez
     *          https://github.com/spite/THREE.MeshLine/blob/master/src/THREE.MeshLine.js
     *
     *
     * The Renderer batches all of the geometry into a single VBO.  This allows us to have a single
     * draw call to render the geometry.  We also optimize the application to only re-upload the
     * geometry data when a new stroke or new points are added to the drawing. The renderer uses
     * a technique detailed in the following link to create degenerate faces between the strokes
     * to disconnect them from one another.
     *      https://developer.apple.com/library/content/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html
     *
     */

    int vertexShader = ShaderUtil.loadGLShader(TAG, context,
            GLES20.GL_VERTEX_SHADER, R.raw.line_vert);
    int fragmentShader = ShaderUtil.loadGLShader(TAG, context,
            GLES20.GL_FRAGMENT_SHADER, R.raw.line_frag);


    mProgramName = GLES20.glCreateProgram();
    GLES20.glAttachShader(mProgramName, vertexShader);
    GLES20.glAttachShader(mProgramName, fragmentShader);
    GLES20.glLinkProgram(mProgramName);
    GLES20.glUseProgram(mProgramName);

    ShaderUtil.checkGLError(TAG, "program");

    mPositionAttribute = GLES20.glGetAttribLocation(mProgramName, "position");
    mPreviousAttribute = GLES20.glGetAttribLocation(mProgramName, "previous");
    mNextAttribute = GLES20.glGetAttribLocation(mProgramName, "next");
    mSideAttribute = GLES20.glGetAttribLocation(mProgramName, "side");
    mWidthAttribte = GLES20.glGetAttribLocation(mProgramName, "width");
    mCountersAttribute = GLES20.glGetAttribLocation(mProgramName, "counters");
    mProjectionUniform = GLES20.glGetUniformLocation(mProgramName, "projectionMatrix");
    mModelViewUniform = GLES20.glGetUniformLocation(mProgramName, "modelViewMatrix");
    mResolutionUniform = GLES20.glGetUniformLocation(mProgramName, "resolution");
    mColorUniform = GLES20.glGetUniformLocation(mProgramName, "color");
    mOpacityUniform = GLES20.glGetUniformLocation(mProgramName, "opacity");
    mNearUniform = GLES20.glGetUniformLocation(mProgramName, "near");
    mFarUniform = GLES20.glGetUniformLocation(mProgramName, "far");
    mSizeAttenuationUniform = GLES20.glGetUniformLocation(mProgramName, "sizeAttenuation");
    mVisibility = GLES20.glGetUniformLocation(mProgramName, "visibility");
    mAlphaTest = GLES20.glGetUniformLocation(mProgramName, "alphaTest");
    mDrawModeUniform = GLES20.glGetUniformLocation(mProgramName, "drawMode");
    mNearCutoffUniform = GLES20.glGetUniformLocation(mProgramName, "nearCutOff");
    mFarCutoffUniform = GLES20.glGetUniformLocation(mProgramName, "farCutOff");
    mLineDepthScaleUniform = GLES20.glGetUniformLocation(mProgramName, "lineDepthScale");

    ShaderUtil.checkGLError(TAG, "program  params");

    Matrix.setIdentityM(mModelMatrix, 0);

    mColor = new Vector3f(1f, 1f, 1f);


}
 
Example 12
Source File: EglUtil.java    From SimpleVideoEdit with Apache License 2.0 4 votes vote down vote up
public static void updateBufferData(final int bufferName, final FloatBuffer data) {
    GLES20.glBindBuffer(GL_ARRAY_BUFFER, bufferName);
    GLES20.glBufferData(GL_ARRAY_BUFFER, data.capacity() * FLOAT_SIZE_BYTES, data, GL_STATIC_DRAW);
    GLES20.glBindBuffer(GL_ARRAY_BUFFER, 0);
}
 
Example 13
Source File: GPUProcessor.java    From HoloKilo with GNU General Public License v3.0 4 votes vote down vote up
public void drawStereo()
{
    // Draw to screen in SBS for cardboard and so on.
    GLES20.glClearColor(0, 0, 0, 0);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glUseProgram(programFinal);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    if (Config.SHOW_DEBUG) {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, uploadTexture.textureId.get(0));
    } else if (Config.SHOW_CAMERA) {
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, cameraTexture);
    } else if (Config.SHOW_RGBA_RESULT && doneFramebufferPool.size() > 0) {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, doneFramebufferPool.get(0).textureId.get(0));
    } else if (previousFb != null) {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, previousFb.textureId.get(0));
    }
    GLES20.glUniform1f(exposureHandle, exposureValue.get());
    GLES20.glUniform1i(finalHandle, 0);
    GLES20.glUniform2f(pointHandle, (float) BlobFinder.getHitPoint()[0] / (float) subWidth, (float) BlobFinder.getHitPoint()[1] / (float) subHeight);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, textureVertexPointer[0]);
    GLES20.glEnableVertexAttribArray(textureCoordHandle[4]);
    GLES20.glVertexAttribPointer(textureCoordHandle[4], COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, 0);

    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, drawListPointer[0]);

    float w = (float)screenWidth / 2f * hfov;
    float h = (float)screenHeight * vfov;
    float x1 = ((float)screenWidth / 2f - w) / 2f;
    float x2 = x1 + (float)screenWidth / 2f;
    float y = ((float)screenHeight - h) / 2f;
    for (int i = 0; i < 2; i++) {
        GLES20.glViewport(i == 0 ? (int)x1 : (int)x2, (int)y, (int)w, (int)h);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexPointer[0]);
        GLES20.glEnableVertexAttribArray(positionHandle[4]);
        GLES20.glVertexAttribPointer(positionHandle[4], COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, 0);

        GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length,
                GLES20.GL_UNSIGNED_SHORT, 0);
    }
    GLES20.glViewport(0, 0, screenWidth, screenHeight);
    GLES20.glUseProgram(0);

    if (Config.DRAW_CUBES) {
        CubeRenderer.setStates(true);
        try {
            semMatrix.acquire();

            GLES20.glViewport(0, 0, screenWidth / 2, screenHeight);
            cubeRenderer.drawLeft();

            GLES20.glViewport(screenWidth / 2, 0, screenWidth / 2, screenHeight);
            cubeRenderer.drawRight();

            semMatrix.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        CubeRenderer.setStates(false);
    }

    // Draw seperation line
    GLES20.glViewport(0, 0, screenWidth, screenHeight);
    GLES20.glScissor(screenWidth / 2, 0, 1, screenHeight);
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glClearColor(1f, 1f, 1f, 0.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 14
Source File: GLES20Canvas.java    From android-openGL-canvas with Apache License 2.0 4 votes vote down vote up
@Override
public void drawMesh(BasicTexture texture, int x, int y, int xyBuffer, int uvBuffer,
                     int indexBuffer, int indexCount, int mode) {
    prepareTexture(texture, mMeshProgram, mMeshParameters);

    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
    checkError();

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, xyBuffer);
    checkError();
    int positionHandle = mMeshParameters[INDEX_POSITION].handle;
    GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
            VERTEX_STRIDE, 0);
    checkError();

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, uvBuffer);
    checkError();
    int texCoordHandle = mMeshParameters[INDEX_TEXTURE_COORD].handle;
    GLES20.glVertexAttribPointer(texCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT,
            false, VERTEX_STRIDE, 0);
    checkError();
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    checkError();

    GLES20.glEnableVertexAttribArray(positionHandle);
    checkError();
    GLES20.glEnableVertexAttribArray(texCoordHandle);
    checkError();

    setMatrix(mMeshParameters, x, y, 1, 1, null);
    GLES20.glDrawElements(mode, indexCount, GLES20.GL_UNSIGNED_BYTE, 0);
    checkError();

    GLES20.glDisableVertexAttribArray(positionHandle);
    checkError();
    GLES20.glDisableVertexAttribArray(texCoordHandle);
    checkError();
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
    checkError();
    mCountDrawMesh++;
}
 
Example 15
Source File: GLES20Canvas.java    From PhotoMovie with Apache License 2.0 4 votes vote down vote up
@Override
public void drawMesh(BasicTexture texture, int x, int y, int xyBuffer, int uvBuffer,
                     int indexBuffer, int indexCount) {
    prepareTexture(texture, mMeshProgram, mMeshParameters);

    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
    checkError();

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, xyBuffer);
    checkError();
    int positionHandle = mMeshParameters[INDEX_POSITION].handle;
    GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false,
            VERTEX_STRIDE, 0);
    checkError();

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, uvBuffer);
    checkError();
    int texCoordHandle = mMeshParameters[INDEX_TEXTURE_COORD].handle;
    GLES20.glVertexAttribPointer(texCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT,
            false, VERTEX_STRIDE, 0);
    checkError();
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    checkError();

    GLES20.glEnableVertexAttribArray(positionHandle);
    checkError();
    GLES20.glEnableVertexAttribArray(texCoordHandle);
    checkError();

    setMatrix(mMeshParameters, x, y, 1, 1);
    GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, indexCount, GLES20.GL_UNSIGNED_BYTE, 0);
    checkError();

    GLES20.glDisableVertexAttribArray(positionHandle);
    checkError();
    GLES20.glDisableVertexAttribArray(texCoordHandle);
    checkError();
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
    checkError();
    mCountDrawMesh++;
}
 
Example 16
Source File: GLModel.java    From Tanks with MIT License 4 votes vote down vote up
@Override
public void draw(RendererContext context, Data data)
{
  ShaderModel shader = (ShaderModel) Shader.getCurrent();
  Light.Data light = context.getLight();

  // build PVM matrix
  Matrix.multiplyMM(modelProjectionViewMatrix, 0, context.getProjectionViewMatrix(), 0, modelMatrix, 0);

  // bind texture to 0 slot
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle());

  // send uniform data to shader
  GLES20.glUniform1i(shader.uniformTextureHandle, 0);
  GLES20.glUniformMatrix4fv(shader.uniformMatrixProjectionHandle, 1, false, modelProjectionViewMatrix, 0);
  GLES20.glUniformMatrix3fv(shader.uniformNormalMatrix, 1, false, modelNormalMatrix, 0);
  GLES20.glUniformMatrix4fv(shader.uniformMatrixHandle, 1, false, modelMatrix, 0);
  GLES20.glUniform3fv(shader.uniformLightVectorHandle, 1, light.Position.getRaw(), 0);
  GLES20.glUniform4f(shader.uniformColorCoefficients, data.redCoeff, data.greenCoeff, data.blueCoeff, 1.0f);

  // bind data buffer
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle());

  // set offsets to arrays for buffer
  GLES20.glVertexAttribPointer(shader.attributePositionHandle, 3, GLES20.GL_FLOAT, false, 32, 0);
  GLES20.glVertexAttribPointer(shader.attributeNormalHandle, 3, GLES20.GL_FLOAT, false, 32, 12);
  GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 32, 24);

  // enable attribute arrays
  GLES20.glEnableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeNormalHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle);

  // validating if debug
  shader.validate();
  geometryData.validate();
  textureData.validate();

  // draw
  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount());

  // disable attribute arrays
  GLES20.glDisableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeNormalHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle);
}
 
Example 17
Source File: MyOSDReceiverRenderer.java    From myMediaCodecPlayer-for-FPV with MIT License 4 votes vote down vote up
public MyOSDReceiverRenderer(Context context, int[] textures,float[] leftEyeViewM,float[] rightEyeViewM,float[] projectionM,float videoFormat,float modelDistance,float videoDistance){
    SharedPreferences settings= PreferenceManager.getDefaultSharedPreferences(context);
    enable_model=settings.getBoolean("enable_model", true);
    enable_home_arrow=settings.getBoolean("enable_home_arrow", true);
    enable_fps=settings.getBoolean("enable_fps", true);
    enable_battery_life=settings.getBoolean("enable_battery_life", true);
    enable_lattitude_longitude=settings.getBoolean("enable_lattitude_longitude", true);
    enable_X1=settings.getBoolean("enable_x1", true);
    enable_X2=settings.getBoolean("enable_x2", true);
    enable_height=settings.getBoolean("enable_height", true);
    enable_voltage=settings.getBoolean("enable_voltage", true);
    enable_ampere=settings.getBoolean("enable_ampere", true);
    enable_home_distance=settings.getBoolean("enable_home_distance", true);
    enable_X3=settings.getBoolean("enable_x3", true);
    enable_speed=settings.getBoolean("enable_speed", true);
    enable_X4=settings.getBoolean("enable_x4", true);
    vertexBuffer = OpenGLHelper.getFloatBuffer(MyOSDReceiverRendererHelper.getTriangleCoords());
    GLES20.glGenBuffers(2, buffers, 0);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertexBuffer.capacity() * mBytesPerFloat,
            vertexBuffer, GLES20.GL_STATIC_DRAW);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    int   vertexShader=OpenGLHelper.loadShader(GLES20.GL_VERTEX_SHADER,MyOSDReceiverRendererHelper.getVertexShader2());
    int fragmentShader=OpenGLHelper.loadShader(GLES20.GL_FRAGMENT_SHADER, MyOSDReceiverRendererHelper.getFragmentShader2());
    mProgram=GLES20.glCreateProgram();
    GLES20.glAttachShader(mProgram, vertexShader);
    GLES20.glAttachShader(mProgram, fragmentShader);
    GLES20.glLinkProgram(mProgram);
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "a_Position");
    mColorHandle = GLES20.glGetAttribLocation(mProgram, "a_Color");
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "u_MVPMatrix");
    mProjM=projectionM;
    Matrix.setIdentityM(mWorldDistanceTranslationM,0);
    Matrix.translateM(mWorldDistanceTranslationM,0,0.0f,0.0f,-modelDistance);
    mOverdrawLayer=new OverdrawLayer(textures,videoFormat,videoDistance);
    receiveFromUDPThread=new Thread(){
        @Override
        public void run() {
            receiveFromUDP();}
    };
    circularRefreshThread=new Thread(){
        @Override
        public void run() {
            refreshCircular();}
    };
}
 
Example 18
Source File: DistortionRenderer.java    From Cardboard with Apache License 2.0 4 votes vote down vote up
public void afterDrawFrame() {
	GLES20.glBindFramebuffer(36160, this.mOriginalFramebufferId.array()[0]);
	GLES20.glViewport(0, 0, this.mHmd.getScreen().getWidth(), this.mHmd
			.getScreen().getHeight());

	GLES20.glGetIntegerv(2978, this.mViewport);
	GLES20.glGetIntegerv(2884, this.mCullFaceEnabled);
	GLES20.glGetIntegerv(3089, this.mScissorTestEnabled);
	GLES20.glDisable(3089);
	GLES20.glDisable(2884);

	GLES20.glClearColor(0.0F, 0.0F, 0.0F, 1.0F);
	GLES20.glClear(16640);

	GLES20.glUseProgram(this.mProgramHolder.program);

	GLES20.glEnable(3089);
	GLES20.glScissor(0, 0, this.mHmd.getScreen().getWidth() / 2, this.mHmd
			.getScreen().getHeight());

	renderDistortionMesh(this.mLeftEyeDistortionMesh);

	GLES20.glScissor(this.mHmd.getScreen().getWidth() / 2, 0, this.mHmd
			.getScreen().getWidth() / 2, this.mHmd.getScreen().getHeight());

	renderDistortionMesh(this.mRightEyeDistortionMesh);

	GLES20.glDisableVertexAttribArray(this.mProgramHolder.aPosition);
	GLES20.glDisableVertexAttribArray(this.mProgramHolder.aVignette);
	GLES20.glDisableVertexAttribArray(this.mProgramHolder.aTextureCoord);
	GLES20.glUseProgram(0);
	GLES20.glBindBuffer(34962, 0);
	GLES20.glBindBuffer(34963, 0);
	GLES20.glDisable(3089);
	if (this.mCullFaceEnabled.array()[0] == 1) {
		GLES20.glEnable(2884);
	}
	if (this.mScissorTestEnabled.array()[0] == 1) {
		GLES20.glEnable(3089);
	}
	GLES20.glViewport(this.mViewport.array()[0], this.mViewport.array()[1],
			this.mViewport.array()[2], this.mViewport.array()[3]);
}
 
Example 19
Source File: GLES20WallpaperRenderer.java    From alynx-live-wallpaper with Apache License 2.0 4 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
    // No depth test for 2D video.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthMask(false);
    GLES20.glDisable(GLES20.GL_CULL_FACE);
    GLES20.glDisable(GLES20.GL_BLEND);

    GLES20.glGenTextures(textures.length, textures, 0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
    GLES20.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES20.GL_TEXTURE_MIN_FILTER,
        GLES20.GL_LINEAR
    );
    GLES20.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES20.GL_TEXTURE_MAG_FILTER,
        GLES20.GL_LINEAR
    );
    GLES20.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES20.GL_TEXTURE_WRAP_S,
        GLES20.GL_CLAMP_TO_EDGE
    );
    GLES20.glTexParameteri(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
        GLES20.GL_TEXTURE_WRAP_T,
        GLES20.GL_CLAMP_TO_EDGE
    );

    program = Utils.linkProgramGLES20(
        Utils.compileShaderResourceGLES20(
            context, GLES20.GL_VERTEX_SHADER, R.raw.vertex_20
        ),
        Utils.compileShaderResourceGLES20(
            context, GLES20.GL_FRAGMENT_SHADER, R.raw.fragment_20
        )
    );
    mvpLocation = GLES20.glGetUniformLocation(program, "mvp");
    // Locations are NOT set in shader sources.
    positionLocation = GLES20.glGetAttribLocation(program, "in_position");
    texCoordLocation = GLES20.glGetAttribLocation(program, "in_tex_coord");

    GLES20.glGenBuffers(buffers.length, buffers, 0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
    GLES20.glBufferData(
        GLES20.GL_ARRAY_BUFFER, vertices.capacity() * BYTES_PER_FLOAT,
        vertices, GLES20.GL_STATIC_DRAW
    );
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[1]);
    GLES20.glBufferData(
        GLES20.GL_ARRAY_BUFFER, texCoords.capacity() * BYTES_PER_FLOAT,
        texCoords, GLES20.GL_STATIC_DRAW
    );
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, buffers[2]);
    GLES20.glBufferData(
        GLES20.GL_ELEMENT_ARRAY_BUFFER, indices.capacity() * BYTES_PER_INT,
        indices, GLES20.GL_STATIC_DRAW
    );
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
 
Example 20
Source File: GLLabel.java    From Tanks with MIT License 4 votes vote down vote up
@Override
public void draw(RendererContext context)
{
  Data data = dataProvider.get();
  Vector3 color = data.colorCoefficients;
  ShaderLabel shader = (ShaderLabel)Shader.getCurrent();

  // get dynamic resources
  Geometry geometryData = GameContext.resources.getGeometry(new LabelGeometrySource(data.value, data.mode, data.charWidth, data.charHeight));

  // build result matrix
  Matrix.multiplyMM(modelViewMatrix, 0, context.getOrthoMatrix(), 0, data.modelMatrix, 0);

  // bind texture to 0 slot
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle());

  // send data to shader
  GLES20.glUniform1i(shader.uniformTextureHandle, 0);
  GLES20.glUniformMatrix4fv(shader.uniformModelViewMatrixHandle, 1, false, modelViewMatrix, 0);
  GLES20.glUniform4f(shader.uniformColorCoefficients, color.getX(), color.getY(), color.getZ(), 1);

  // set buffer or reset if dynamic
  GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle());

  switch (geometryData.getMode())
  {
  case Static:
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, 0);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, 8);
    break;

  case Dynamic:
    FloatBuffer buffer = geometryData.getData();
    buffer.position(0);
    GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    buffer.position(2);
    GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, buffer);
    break;
  }

  // enable arrays
  GLES20.glEnableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle);

  // validating if debug
  shader.validate();
  geometryData.validate();
  textureData.validate();

  // draw
  GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount());

  // disable arrays
  GLES20.glDisableVertexAttribArray(shader.attributePositionHandle);
  GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle);

  // release dynamic resources
  GameContext.resources.release(geometryData);
}