/** * \brief Draw the video (in OpenGL). * @param mvpMatrix the model-view-projection matrix. */ private void DrawVideo(float[] mvpMatrix) { GLES20.GlUseProgram(mVideo_Program_GL_ID); int vertexHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexPosition"); int textureCoordHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexTexCoord"); int mvpMatrixHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "modelViewProjectionMatrix"); int texSampler2DHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "texSamplerOES"); GLES20.GlVertexAttribPointer(vertexHandle, 3, GLES20.GlFloat, false, 0, mVertices_Buffer); GLES20.GlVertexAttribPointer(textureCoordHandle, 2, GLES20.GlFloat, false, 0, mVideoTexCoords_Buffer); GLES20.GlEnableVertexAttribArray(vertexHandle); GLES20.GlEnableVertexAttribArray(textureCoordHandle); GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES11Ext.GlTextureExternalOes, mVideoTexture_GL_ID); GLES20.GlUniform1i(texSampler2DHandle, 0); GLES20.GlUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0); // Render GLES20.GlDrawElements(GLES20.GlTriangles, mIndices_Number, GLES20.GlUnsignedShort, mIndex_Buffer); GLES20.GlDisableVertexAttribArray(vertexHandle); GLES20.GlDisableVertexAttribArray(textureCoordHandle); GLES20.GlUseProgram(0); }
/** * \brief Draw the video keyframe (in OpenGL). * @param mvpMatrix the model-view-projection matrix. */ private void DrawKeyFrame(float[] mvpMatrix) { GLES20.GlEnable(GLES20.GlBlend); GLES20.GlBlendFunc(GLES20.GlSrcAlpha, GLES20.GlOneMinusSrcAlpha); GLES20.GlUseProgram(mKeyframe_Program_GL_ID); int vertexHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexPosition"); int textureCoordHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexTexCoord"); int mvpMatrixHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "modelViewProjectionMatrix"); int texSampler2DHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "texSampler2D"); GLES20.GlVertexAttribPointer(vertexHandle, 3, GLES20.GlFloat, false, 0, mVertices_Buffer); GLES20.GlVertexAttribPointer(textureCoordHandle, 2, GLES20.GlFloat, false, 0, mTexCoords_Buffer); GLES20.GlEnableVertexAttribArray(vertexHandle); GLES20.GlEnableVertexAttribArray(textureCoordHandle); GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES20.GlTexture2d, mKeyframeTexture_GL_ID); GLES20.GlUniform1i(texSampler2DHandle, 0); GLES20.GlUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0); GLES20.GlDrawElements(GLES20.GlTriangles, mIndices_Number, GLES20.GlUnsignedShort, mIndex_Buffer); GLES20.GlDisableVertexAttribArray(vertexHandle); GLES20.GlDisableVertexAttribArray(textureCoordHandle); GLES20.GlUseProgram(0); GLES20.GlDisable(GLES20.GlBlend); }
public virtual void DrawQuad(FloatBuffer vertices) { vertices.Position(0); AXy.VertexPointer(2, 4, vertices); vertices.Position(2); AUv.VertexPointer(2, 4, vertices); GLES20.GlDrawElements(GLES20.GlTriangles, Quad.SIZE, GLES20.GlUnsignedShort, Quad.GetIndices(1)); }
public virtual void DrawElements(FloatBuffer vertices, ShortBuffer indices, int size) { vertices.Position(0); AXy.VertexPointer(2, 4, vertices); vertices.Position(2); AUv.VertexPointer(2, 4, vertices); GLES20.GlDrawElements(GLES20.GlTriangles, size, GLES20.GlUnsignedShort, indices); }
/// <summary> /// Draw face geometrical features. This method is called on each frame. /// </summary> private void DrawFaceGeometry() { ShaderUtil.CheckGlError(TAG, "Before draw."); Log.Debug(TAG, "Draw face geometry: mPointsNum: " + mPointsNum + " mTrianglesNum: " + mTrianglesNum); GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES20.GlTexture2d, mTextureName); GLES20.GlUniform1i(mTextureUniform, 0); ShaderUtil.CheckGlError(TAG, "Init texture."); GLES20.GlEnable(GLES20.GlDepthTest); GLES20.GlEnable(GL_CULL_FACE_CONSTANT); // Draw point. GLES20.GlUseProgram(mProgram); ShaderUtil.CheckGlError(TAG, "Draw point."); GLES20.GlEnableVertexAttribArray(mPositionAttribute); GLES20.GlEnableVertexAttribArray(mTextureCoordAttribute); GLES20.GlEnableVertexAttribArray(mColorUniform); GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVerticeId); GLES20.GlVertexAttribPointer(mPositionAttribute, POSITION_COMPONENTS_NUMBER, GLES20.GlFloat, false, BYTES_PER_POINT, 0); GLES20.GlVertexAttribPointer(mTextureCoordAttribute, TEXCOORD_COMPONENTS_NUMBER, GLES20.GlFloat, false, BYTES_PER_COORD, 0); GLES20.GlUniform4f(mColorUniform, 1.0f, 0.0f, 0.0f, 1.0f); GLES20.GlUniformMatrix4fv(mModelViewProjectionUniform, 1, false, mModelViewProjections, 0); GLES20.GlUniform1f(mPointSizeUniform, 5.0f); // Set the size of Point to 5. GLES20.GlDrawArrays(GLES20.GlPoints, 0, mPointsNum); GLES20.GlDisableVertexAttribArray(mColorUniform); GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0); ShaderUtil.CheckGlError(TAG, "Draw point."); // Draw triangles. GLES20.GlEnableVertexAttribArray(mColorUniform); // Clear the color and use the texture color to draw triangles. GLES20.GlUniform4f(mColorUniform, 0.0f, 0.0f, 0.0f, 0.0f); GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, mTriangleId); // The number of input triangle points GLES20.GlDrawElements(GLES20.GlTriangles, mTrianglesNum * 3, GLES20.GlUnsignedInt, 0); GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, 0); GLES20.GlDisableVertexAttribArray(mColorUniform); ShaderUtil.CheckGlError(TAG, "Draw triangles."); GLES20.GlDisableVertexAttribArray(mTextureCoordAttribute); GLES20.GlDisableVertexAttribArray(mPositionAttribute); GLES20.GlBindTexture(GLES20.GlTexture2d, 0); GLES20.GlDisable(GLES20.GlDepthTest); GLES20.GlDisable(GL_CULL_FACE_CONSTANT); ShaderUtil.CheckGlError(TAG, "Draw after."); }
/** * \brief Draw this mesh (in OpenGL). * @param modelViewProjection this mesh model-view-projection matrix. */ public void DrawMesh(float[] modelViewProjection) { //set up gl state GLES20.GlEnable(GLES20.GlDepthTest); //GLES20.GlDisable(GLES20.GlCullFaceMode); GLES20.GlCullFace(GLES20.GlBack); GLES20.GlFrontFace(GLES20.GlCw); //set shader program to use GLES20.GlUseProgram(mProgram_GL_ID); RenderUtils.CheckGLError("DrawMesh:glUseProgram"); //find attrib and unifroms in shader program int vertexHandle = GLES20.GlGetAttribLocation(mProgram_GL_ID, "vertexPosition"); //int normalHandle = GLES20.GlGetAttribLocation(Program_GL_ID, "vertexNormal"); int textureCoordHandle = GLES20.GlGetAttribLocation(mProgram_GL_ID, "vertexTexCoord"); int mvpMatrixHandle = GLES20.GlGetUniformLocation(mProgram_GL_ID, "modelViewProjectionMatrix"); int texSampler2DHandle = GLES20.GlGetUniformLocation(mProgram_GL_ID, "texSampler2D"); RenderUtils.CheckGLError("DrawMesh:get attribs and uniforms"); //upload mesh data to OpenGL attribs GLES20.GlVertexAttribPointer(vertexHandle, 3, GLES20.GlFloat, false, 0, mVertices_Buffer); //GLES20.GlVertexAttribPointer(normalHandle, 3, GLES20.GlFloat, false, 0, Normals_Buffer); GLES20.GlVertexAttribPointer(textureCoordHandle, 2, GLES20.GlFloat, false, 0, mTexCoords_Buffer); RenderUtils.CheckGLError("DrawMesh:put attrib pointers"); //enable gl attribs to use GLES20.GlEnableVertexAttribArray(vertexHandle); //GLES20.GlEnableVertexAttribArray(normalHandle); GLES20.GlEnableVertexAttribArray(textureCoordHandle); RenderUtils.CheckGLError("DrawMesh:enable attrib arrays"); // activate texture 0, bind it, and pass to shader GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES20.GlTexture2d, mTexture_GL_ID); GLES20.GlUniform1i(texSampler2DHandle, 0); RenderUtils.CheckGLError("DrawMesh:activate texturing"); // pass the model view matrix to the shader GLES20.GlUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjection, 0); RenderUtils.CheckGLError("DrawMesh:upload matrix"); // finally draw the teapot GLES20.GlDrawElements(GLES20.GlTriangles, mIndices_Number, GLES20.GlUnsignedShort, mIndex_Buffer); RenderUtils.CheckGLError("DrawMesh:draw elements"); // disable the enabled arrays GLES20.GlDisableVertexAttribArray(vertexHandle); //GLES20.GlDisableVertexAttribArray(normalHandle); GLES20.GlDisableVertexAttribArray(textureCoordHandle); RenderUtils.CheckGLError("DrawMesh:disable attrib arrays"); }
private void DrawLabel(float[] cameraViews, float[] cameraProjection) { ShaderUtil.CheckGlError(TAG, "Draw label start."); Matrix.MultiplyMM(modelViewMatrix, 0, cameraViews, 0, modelMatrix, 0); Matrix.MultiplyMM(modelViewProjectionMatrix, 0, cameraProjection, 0, modelViewMatrix, 0); float halfWidth = LABEL_WIDTH / 2.0f; float halfHeight = LABEL_HEIGHT / 2.0f; float[] vertices = { -halfWidth, -halfHeight, 1, -halfWidth, halfHeight, 1, halfWidth, halfHeight, 1, halfWidth, -halfHeight, 1, }; // The size of each floating point is 4 bits. FloatBuffer vetBuffer = ByteBuffer.AllocateDirect(4 * vertices.Length) .Order(ByteOrder.NativeOrder()).AsFloatBuffer(); vetBuffer.Rewind(); for (int i = 0; i < vertices.Length; ++i) { vetBuffer.Put(vertices[i]); } vetBuffer.Rewind(); // The size of each floating point is 4 bits. GLES20.GlVertexAttribPointer(glPositionParameter, COORDS_PER_VERTEX, GLES20.GlFloat, false, 4 * COORDS_PER_VERTEX, vetBuffer); // Set the sequence of OpenGL drawing points to generate two triangles that form a plane. short[] indices = { 0, 1, 2, 0, 2, 3 }; // Size of the allocated buffer. ShortBuffer idxBuffer = ByteBuffer.AllocateDirect(2 * indices.Length) .Order(ByteOrder.NativeOrder()).AsShortBuffer(); idxBuffer.Rewind(); for (int i = 0; i < indices.Length; ++i) { idxBuffer.Put(indices[i]); } idxBuffer.Rewind(); GLES20.GlUniformMatrix4fv(glModelViewProjectionMatrix, 1, false, modelViewProjectionMatrix, 0); GLES20.GlDrawElements(GLES20.GlTriangleStrip, idxBuffer.Limit(), GLES20.GlUnsignedShort, idxBuffer); ShaderUtil.CheckGlError(TAG, "Draw label end."); }
/// <summary> /// Draw a virtual object at a specific location on a specified plane. /// This method is called when WorldRenderManager's OnDrawFrame. /// </summary> /// <param name="cameraView">The viewMatrix is a 4 * 4 matrix.</param> /// <param name="cameraProjection">The ProjectionMatrix is a 4 * 4 matrix.</param> /// <param name="lightIntensity">The lighting intensity.</param> /// <param name="obj">The virtual object.</param> public void OnDrawFrame(float[] cameraView, float[] cameraProjection, float lightIntensity, VirtualObject obj) { ShaderUtil.CheckGlError(TAG, "onDrawFrame start."); mModelMatrixs = obj.GetModelAnchorMatrix(); Matrix.MultiplyMM(mModelViewMatrixs, 0, cameraView, 0, mModelMatrixs, 0); Matrix.MultiplyMM(mModelViewProjectionMatrixs, 0, cameraProjection, 0, mModelViewMatrixs, 0); GLES20.GlUseProgram(mGlProgram); Matrix.MultiplyMV(mViewLightDirections, 0, mModelViewMatrixs, 0, LIGHT_DIRECTIONS, 0); MatrixUtil.NormalizeVec3(mViewLightDirections); // Light direction. GLES20.GlUniform4f(mLightingParametersUniform, mViewLightDirections[0], mViewLightDirections[1], mViewLightDirections[2], lightIntensity); float[] objColors = obj.GetColor(); GLES20.GlUniform4fv(mColorUniform, 1, objColors, 0); GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES20.GlTexture2d, mTextures[0]); GLES20.GlUniform1i(mTextureUniform, 0); GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVertexBufferId); // The coordinate dimension of the read virtual object is 3. GLES20.GlVertexAttribPointer( mPositionAttribute, 3, GLES20.GlFloat, false, 0, 0); // The dimension of the normal vector is 3. GLES20.GlVertexAttribPointer( mNormalAttribute, 3, GLES20.GlFloat, false, 0, mNormalsBaseAddress); // The dimension of the texture coordinate is 2. GLES20.GlVertexAttribPointer( mTexCoordAttribute, 2, GLES20.GlFloat, false, 0, mTexCoordsBaseAddress); GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0); GLES20.GlUniformMatrix4fv( mModelViewUniform, 1, false, mModelViewMatrixs, 0); GLES20.GlUniformMatrix4fv( mModelViewProjectionUniform, 1, false, mModelViewProjectionMatrixs, 0); GLES20.GlEnableVertexAttribArray(mPositionAttribute); GLES20.GlEnableVertexAttribArray(mNormalAttribute); GLES20.GlEnableVertexAttribArray(mTexCoordAttribute); GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, mIndexBufferId); GLES20.GlDrawElements(GLES20.GlTriangles, mIndexCount, GLES20.GlUnsignedShort, 0); GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, 0); GLES20.GlDisableVertexAttribArray(mPositionAttribute); GLES20.GlDisableVertexAttribArray(mNormalAttribute); GLES20.GlDisableVertexAttribArray(mTexCoordAttribute); GLES20.GlBindTexture(GLES20.GlTexture2d, 0); ShaderUtil.CheckGlError(TAG, "onDrawFrame end."); }
public virtual void DrawQuadSet(FloatBuffer vertices, int size) { if (size == 0) { return; } vertices.Position(0); AXy.VertexPointer(2, 4, vertices); vertices.Position(2); AUv.VertexPointer(2, 4, vertices); GLES20.GlDrawElements(GLES20.GlTriangles, Quad.SIZE * size, GLES20.GlUnsignedShort, Quad.GetIndices(size)); }
private void Render(float[] matrix) { // clear Screen and Depth Buffer, we have set the clear color as black. GLES20.GlClear(GLES20.GlColorBufferBit | GLES20.GlDepthBufferBit); // get handle to vertex shader's vPosition member int positionHandle = GLES20.GlGetAttribLocation(ShaderHelper.SpImage, "vPosition"); // Enable generic vertex attribute array GLES20.GlEnableVertexAttribArray(positionHandle); // Prepare the triangle coordinate data GLES20.GlVertexAttribPointer(positionHandle, 3, GLES20.GlFloat, false, 0, vertexBuffer); // Get handle to texture coordinates location int textureCoordinatesLocation = GLES20.GlGetAttribLocation(ShaderHelper.SpImage, "a_texCoord"); // Enable generic vertex attribute array GLES20.GlEnableVertexAttribArray(textureCoordinatesLocation); // Prepare the texturecoordinates GLES20.GlVertexAttribPointer(textureCoordinatesLocation, 2, GLES20.GlFloat, false, 0, uvBuffer); // Get handle to shape's transformation matrix int matrixhandle = GLES20.GlGetUniformLocation(ShaderHelper.SpImage, "uMVPMatrix"); // Apply the projection and view transformation GLES20.GlUniformMatrix4fv(matrixhandle, 1, false, matrix, 0); // Get handle to textures locations int samplerLocation = GLES20.GlGetUniformLocation(ShaderHelper.SpImage, "s_texture"); // Set the sampler texture unit to 0, where we have saved the texture. GLES20.GlUniform1i(samplerLocation, 0); // Draw the triangle GLES20.GlDrawElements(GLES20.GlTriangles, indices.Length, GLES20.GlUnsignedShort, drawListBuffer); // Disable vertex array GLES20.GlDisableVertexAttribArray(positionHandle); GLES20.GlDisableVertexAttribArray(textureCoordinatesLocation); }
/// <summary> /// Draw the plane /// </summary> private void Draw(float[] cameraView, float[] cameraPerspective) { // Build the ModelView and ModelViewProjection matrices // for calculating cube position and light. Matrix.MultiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0); Matrix.MultiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0); // Set the position of the plane mVertexBuffer.Rewind(); GLES20.GlVertexAttribPointer( mPlaneXZPositionAlphaAttribute, COORDS_PER_VERTEX, GLES20.GlFloat, false, BYTES_PER_FLOAT * COORDS_PER_VERTEX, mVertexBuffer); // Set the Model and ModelViewProjection matrices in the shader. GLES20.GlUniformMatrix4fv(mPlaneModelUniform, 1, false, mModelMatrix, 0); GLES20.GlUniformMatrix4fv( mPlaneModelViewProjectionUniform, 1, false, mModelViewProjectionMatrix, 0); mIndexBuffer.Rewind(); GLES20.GlDrawElements(GLES20.GlTriangleStrip, mIndexBuffer.Limit(), GLES20.GlUnsignedShort, mIndexBuffer); }
private void renderDistortionMesh(DistortionMesh mesh) { GLES20.GlBindBuffer(34962, mesh.mArrayBufferId); /*mesh.getClass(); mesh.getClass();*/ GLES20.GlVertexAttribPointer(mProgramHolder.aPosition, 3, 5126, false, 20, 0 * 4); GLES20.GlEnableVertexAttribArray(mProgramHolder.aPosition); /*mesh.getClass(); mesh.getClass();*/ GLES20.GlVertexAttribPointer(mProgramHolder.aVignette, 1, 5126, false, 20, 2 * 4); GLES20.GlEnableVertexAttribArray(mProgramHolder.aVignette); /*mesh.getClass(); mesh.getClass();*/ GLES20.GlVertexAttribPointer(mProgramHolder.aTextureCoord, 2, 5126, false, 20, 3 * 4); GLES20.GlEnableVertexAttribArray(mProgramHolder.aTextureCoord); GLES20.GlActiveTexture(33984); GLES20.GlBindTexture(3553, mTextureId); GLES20.GlUniform1i(mProgramHolder.uTextureSampler, 0); GLES20.GlUniform1f(mProgramHolder.uTextureCoordScale, mResolutionScale); GLES20.GlBindBuffer(34963, mesh.mElementBufferId); GLES20.GlDrawElements(5, mesh.nIndices, 5125, 0); }
public void Draw(float[] mvpMatrix) { // Add program to OpenGL environment GLES20.GlUseProgram(mProgram); // get handle to vertex shader's vPosition member mPositionHandle = GLES20.GlGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices GLES20.GlEnableVertexAttribArray(mPositionHandle); // Prepare the triangle coordinate data GLES20.GlVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GlFloat, false, vertexStride, vertexBuffer); // get handle to fragment shader's vColor member mColorHandle = GLES20.GlGetUniformLocation(mProgram, "vColor"); // Set color for drawing the triangle GLES20.GlUniform4fv(mColorHandle, 1, color, 0); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES20.GlGetUniformLocation(mProgram, "uMVPMatrix"); MyGLRenderer.CheckGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES20.GlUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); MyGLRenderer.CheckGlError("glUniformMatrix4fv"); // Draw the square GLES20.GlDrawElements(GLES20.GlTriangles, drawOrder.Length, GLES20.GlUnsignedShort, drawListBuffer); // Disable vertex array GLES20.GlDisableVertexAttribArray(mPositionHandle); }
/** * Draws the model. * * @param cameraView A 4x4 view matrix, in column-major order. * @param cameraPerspective A 4x4 projection matrix, in column-major order. * @param lightIntensity Illumination intensity. Combined with diffuse and specular material * properties. * @see #setBlendMode(BlendMode) * @see #updateModelMatrix(float[], float) * @see #setMaterialProperties(float, float, float, float) * @see android.opengl.Matrix */ public void Draw(float[] cameraView, float[] cameraPerspective, float lightIntensity) { ShaderUtil.CheckGLError(TAG, "Before draw"); // Build the ModelView and ModelViewProjection matrices // for calculating object position and light. Android.Opengl.Matrix.MultiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0); Android.Opengl.Matrix.MultiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0); GLES20.GlUseProgram(mProgram); // Set the lighting environment properties. Android.Opengl.Matrix.MultiplyMV(mViewLightDirection, 0, mModelViewMatrix, 0, LIGHT_DIRECTION, 0); normalizeVec3(mViewLightDirection); GLES20.GlUniform4f(mLightingParametersUniform, mViewLightDirection[0], mViewLightDirection[1], mViewLightDirection[2], lightIntensity); // Set the object material properties. GLES20.GlUniform4f(mMaterialParametersUniform, mAmbient, mDiffuse, mSpecular, mSpecularPower); // Attach the object texture. GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES20.GlTexture2d, mTextures[0]); GLES20.GlUniform1i(mTextureUniform, 0); // Set the vertex attributes. GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVertexBufferId); GLES20.GlVertexAttribPointer( mPositionAttribute, COORDS_PER_VERTEX, GLES20.GlFloat, false, 0, mVerticesBaseAddress); GLES20.GlVertexAttribPointer( mNormalAttribute, 3, GLES20.GlFloat, false, 0, mNormalsBaseAddress); GLES20.GlVertexAttribPointer( mTexCoordAttribute, 2, GLES20.GlFloat, false, 0, mTexCoordsBaseAddress); GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0); // Set the ModelViewProjection matrix in the shader. GLES20.GlUniformMatrix4fv( mModelViewUniform, 1, false, mModelViewMatrix, 0); GLES20.GlUniformMatrix4fv( mModelViewProjectionUniform, 1, false, mModelViewProjectionMatrix, 0); // Enable vertex arrays GLES20.GlEnableVertexAttribArray(mPositionAttribute); GLES20.GlEnableVertexAttribArray(mNormalAttribute); GLES20.GlEnableVertexAttribArray(mTexCoordAttribute); if (mBlendMode != BlendMode.Null) { GLES20.GlDepthMask(false); GLES20.GlEnable(GLES20.GlBlend); switch (mBlendMode) { case BlendMode.Shadow: // Multiplicative blending function for Shadow. GLES20.GlBlendFunc(GLES20.GlZero, GLES20.GlOneMinusSrcAlpha); break; case BlendMode.Grid: // Grid, additive blending function. GLES20.GlBlendFunc(GLES20.GlSrcAlpha, GLES20.GlOneMinusSrcAlpha); break; } } GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, mIndexBufferId); GLES20.GlDrawElements(GLES20.GlTriangles, mIndexCount, GLES20.GlUnsignedShort, 0); GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, 0); if (mBlendMode != BlendMode.Null) { GLES20.GlDisable(GLES20.GlBlend); GLES20.GlDepthMask(true); } // Disable vertex arrays GLES20.GlDisableVertexAttribArray(mPositionAttribute); GLES20.GlDisableVertexAttribArray(mNormalAttribute); GLES20.GlDisableVertexAttribArray(mTexCoordAttribute); GLES20.GlBindTexture(GLES20.GlTexture2d, 0); ShaderUtil.CheckGLError(TAG, "After draw"); }
private void drawOneMaterial(GLSL glsl, ShellSurface surface, RenderList mat) { // set motion if (surface.Animation) { if (mat.bone_inv_map == null) { for (int j = 0; j < surface.RenderBones.Count; j++) { var b = surface.RenderBones[j]; if (b != null) { Array.Copy(b.matrix, 0, mBoneMatrix, j * 16, 16); } } } else { for (int j = 0; j < mat.bone_inv_map.Length; j++) { int inv = mat.bone_inv_map[j]; if (inv >= 0) { var b = surface.RenderBones[inv]; Array.Copy(b.matrix, 0, mBoneMatrix, j * 16, 16); } } } GLES20.GlUniformMatrix4fv(glsl.muMBone, mat.bone_num, false, mBoneMatrix, 0); GLES20.GlEnableVertexAttribArray(glsl.maBlendHandle); GLES20.GlVertexAttribPointer(glsl.maBlendHandle, 3, GLES20.GlUnsignedByte, false, 0, mat.weight); } // initialize color for (int i = 0; i < mDifAmb.Count(); i++) { mDifAmb[i] = 1.0f; } // diffusion and ambient float wi = 0.6f; // light color = (0.6, 0.6, 0.6) for (int i = 0; i < 3; i++) { mDifAmb[i] *= mat.material.diffuse_color[i] * wi + mat.material.emmisive_color[i]; } mDifAmb[3] *= mat.material.diffuse_color[3]; Vector.min(mDifAmb, 1.0f); GLES20.GlUniform4fv(glsl.muDif, 1, mDifAmb, 0); // speculation if (glsl.muPow >= 0) { GLES20.GlUniform4f(glsl.muSpec, mat.material.specular_color[0], mat.material.specular_color[1], mat.material.specular_color[2], 0); GLES20.GlUniform1f(glsl.muPow, mat.material.power); } // toon GLES20.GlUniform1i(glsl.msToonSampler, 0); GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlBindTexture(GLES20.GlTexture2d, TextureFile.FetchTexInfo(surface.toon_name[mat.material.toon_index]).tex); // texture GLES20.GlUniform1i(glsl.msTextureSampler, 1); GLES20.GlActiveTexture(GLES20.GlTexture1); if (mat.material.texture != null) { TexInfo tb = TextureFile.FetchTexInfo(mat.material.texture); if (tb != null) { GLES20.GlBindTexture(GLES20.GlTexture2d, tb.tex); } else // avoid crash { GLES20.GlBindTexture(GLES20.GlTexture2d, TextureFile.FetchTexInfo(surface.toon_name[0]).tex); // white texture using toon0.bmp for (int i = 0; i < 3; i++) // for emulate premultiplied alpha { mDifAmb[i] *= mat.material.diffuse_color[3]; } } } else { GLES20.GlBindTexture(GLES20.GlTexture2d, TextureFile.FetchTexInfo(surface.toon_name[0]).tex); // white texture using toon0.bmp for (int i = 0; i < 3; i++) // for emulate premultiplied alpha { mDifAmb[i] *= mat.material.diffuse_color[3]; } } // sphere(sph) GLES20.GlUniform1i(glsl.msSphSampler, 2); GLES20.GlActiveTexture(GLES20.GlTexture2); if (mat.material.sph != null) { TexInfo tb = TextureFile.FetchTexInfo(mat.material.sph); if (tb != null) { GLES20.GlBindTexture(GLES20.GlTexture2d, tb.tex); } else // avoid crash { GLES20.GlBindTexture(GLES20.GlTexture2d, TextureFile.FetchTexInfo(surface.toon_name [0]).tex); // white texture using toon0.bmp } } else { GLES20.GlBindTexture(GLES20.GlTexture2d, TextureFile.FetchTexInfo(surface.toon_name[0]).tex); // white texture using toon0.bmp } // sphere(spa) GLES20.GlUniform1i(glsl.msSpaSampler, 3); GLES20.GlActiveTexture(GLES20.GlTexture3); if (mat.material.spa != null) { TexInfo tb = TextureFile.FetchTexInfo(mat.material.spa); if (tb != null) { GLES20.GlBindTexture(GLES20.GlTexture2d, tb.tex); } } // draw surface.IndexBuffer.Position(mat.face_vert_offset); GLES20.GlDrawElements(GLES20.GlTriangles, mat.face_vert_count, GLES20.GlUnsignedShort, surface.IndexBuffer); checkGlError("glDrawElements"); }
/** * \brief Draw the video icon (in OpenGL). * @param mvpMatrix the model-view-projection matrix. * @param status the video state. */ private void DrawIcon(float[] mvpMatrix, PikkartVideoPlayer.VideoSate.VIDEO_STATE status) { GLES20.GlEnable(GLES20.GlBlend); GLES20.GlBlendFunc(GLES20.GlSrcAlpha, GLES20.GlOneMinusSrcAlpha); GLES20.GlUseProgram(mKeyframe_Program_GL_ID); int vertexHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexPosition"); int textureCoordHandle = GLES20.GlGetAttribLocation(mKeyframe_Program_GL_ID, "vertexTexCoord"); int mvpMatrixHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "modelViewProjectionMatrix"); int texSampler2DHandle = GLES20.GlGetUniformLocation(mKeyframe_Program_GL_ID, "texSampler2D"); GLES20.GlVertexAttribPointer(vertexHandle, 3, GLES20.GlFloat, false, 0, mVertices_Buffer); GLES20.GlVertexAttribPointer(textureCoordHandle, 2, GLES20.GlFloat, false, 0, mTexCoords_Buffer); GLES20.GlEnableVertexAttribArray(vertexHandle); GLES20.GlEnableVertexAttribArray(textureCoordHandle); GLES20.GlActiveTexture(GLES20.GlTexture0); switch ((int)status) { case 0: //end GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 1: //pasued GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 2: //stopped GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 3: //playing GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 4: //ready GLES20.GlBindTexture(GLES20.GlTexture2d, mIconPlayTexture_GL_ID); break; case 5: //not ready GLES20.GlBindTexture(GLES20.GlTexture2d, mIconBusyTexture_GL_ID); break; case 6: //buffering GLES20.GlBindTexture(GLES20.GlTexture2d, mIconBusyTexture_GL_ID); break; case 7: //error GLES20.GlBindTexture(GLES20.GlTexture2d, mIconErrorTexture_GL_ID); break; default: GLES20.GlBindTexture(GLES20.GlTexture2d, mIconBusyTexture_GL_ID); break; } GLES20.GlUniform1i(texSampler2DHandle, 0); GLES20.GlUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0); GLES20.GlDrawElements(GLES20.GlTriangles, mIndices_Number, GLES20.GlUnsignedShort, mIndex_Buffer); GLES20.GlDisableVertexAttribArray(vertexHandle); GLES20.GlDisableVertexAttribArray(textureCoordHandle); GLES20.GlUseProgram(0); GLES20.GlDisable(GLES20.GlBlend); }