Exemplo n.º 1
0
            public override void onDrawFrame(GL10 gl)
            {
                mFrameLock.@lock();
                if (mCurrentFrame != null && !mVideoDisabled)
                {
                    GLES20.glUseProgram(mProgram);

                    if (mTextureWidth != mCurrentFrame.Width || mTextureHeight != mCurrentFrame.Height)
                    {
                        setupTextures(mCurrentFrame);
                    }
                    updateTextures(mCurrentFrame);

                    Matrix.setIdentityM(mScaleMatrix, 0);
                    float scaleX = 1.0f, scaleY = 1.0f;
                    float ratio  = (float)mCurrentFrame.Width / mCurrentFrame.Height;
                    float vratio = (float)mViewportWidth / mViewportHeight;

                    if (mVideoFitEnabled)
                    {
                        if (ratio > vratio)
                        {
                            scaleY = vratio / ratio;
                        }
                        else
                        {
                            scaleX = ratio / vratio;
                        }
                    }
                    else
                    {
                        if (ratio < vratio)
                        {
                            scaleY = vratio / ratio;
                        }
                        else
                        {
                            scaleX = ratio / vratio;
                        }
                    }

                    Matrix.scaleM(mScaleMatrix, 0, scaleX * (mCurrentFrame.MirroredX ? -1.0f : 1.0f), scaleY, 1);

                    int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
                    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mScaleMatrix, 0);

                    GLES20.glDrawElements(GLES20.GL_TRIANGLES, mVertexIndex.Length, GLES20.GL_UNSIGNED_SHORT, mDrawListBuffer);
                }
                else
                {
                    //black frame when video is disabled
                    gl.glClearColor(0, 0, 0, 1);
                    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
                }
                mFrameLock.unlock();
            }
Exemplo n.º 2
0
            public override void onSurfaceCreated(GL10 gl, EGLConfig config)
            {
                gl.glClearColor(0, 0, 0, 1);
                GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

                int vertexShader   = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
                int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

                mProgram = GLES20.glCreateProgram();                 // create empty OpenGL ES
                // Program
                GLES20.glAttachShader(mProgram, vertexShader);       // add the vertex
                // shader to program
                GLES20.glAttachShader(mProgram, fragmentShader);     // add the fragment
                // shader to
                // program
                GLES20.glLinkProgram(mProgram);

                int positionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
                int textureHandle  = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");

                GLES20.glVertexAttribPointer(positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, COORDS_PER_VERTEX * 4, mVertexBuffer);

                GLES20.glEnableVertexAttribArray(positionHandle);

                GLES20.glVertexAttribPointer(textureHandle, TEXTURECOORDS_PER_VERTEX, GLES20.GL_FLOAT, false, TEXTURECOORDS_PER_VERTEX * 4, mTextureBuffer);

                GLES20.glEnableVertexAttribArray(textureHandle);

                GLES20.glUseProgram(mProgram);
                int i = GLES20.glGetUniformLocation(mProgram, "Ytex");

                GLES20.glUniform1i(i, 0);                 // Bind Ytex to texture unit 0

                i = GLES20.glGetUniformLocation(mProgram, "Utex");
                GLES20.glUniform1i(i, 1);                 // Bind Utex to texture unit 1

                i = GLES20.glGetUniformLocation(mProgram, "Vtex");
                GLES20.glUniform1i(i, 2);                 // Bind Vtex to texture unit 2

                mTextureWidth  = 0;
                mTextureHeight = 0;
            }