Home | History | Annotate | Download | only in glowing
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
      5  * in compliance with the License. You may obtain a copy of the License at
      6  *
      7  * http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the License
     10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
     11  * or implied. See the License for the specific language governing permissions and limitations under
     12  * the License.
     13  */
     14 
     15 #include "BlurMeshNode.h"
     16 
     17 BlurMeshNode::BlurMeshNode(const Mesh* mesh, GLuint fboTexId, GLuint tmpTexId1, GLuint tmpTexId2,
     18         float width, float height) :
     19         MeshNode(mesh), mFboTexId(fboTexId), mTmpTexId1(tmpTexId1), mTmpTexId2(tmpTexId2),
     20         mWidth(width), mHeight(height) {
     21 }
     22 
     23 void BlurMeshNode::before(Program& program, Matrix& model, Matrix& view, Matrix& projection) {
     24     int textureUniformHandle = glGetUniformLocation(program.mProgramId, "u_Texture");
     25     int scaleUniformHandle = glGetUniformLocation(program.mProgramId, "u_Scale");
     26     int positionHandle = glGetAttribLocation(program.mProgramId, "a_Position");
     27     int texCoordHandle = glGetAttribLocation(program.mProgramId, "a_TexCoordinate");
     28 
     29     glEnableVertexAttribArray(positionHandle);
     30     glVertexAttribPointer(positionHandle, 3, GL_FLOAT, false, 0, mMesh->mVertices);
     31     glEnableVertexAttribArray(texCoordHandle);
     32     glVertexAttribPointer(texCoordHandle, 2, GL_FLOAT, false, 0, mMesh->mTexCoords);
     33 
     34     // Blur X
     35     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTmpTexId1, 0);
     36     glActiveTexture (GL_TEXTURE0);
     37     glBindTexture(GL_TEXTURE_2D, mFboTexId);
     38     glUniform1i(textureUniformHandle, 0);
     39 
     40     glUniform2f(scaleUniformHandle, 1.0f / mWidth, 0);
     41 
     42     glDrawArrays(GL_TRIANGLES, 0, mMesh->mNumVertices);
     43 
     44     // Blur Y
     45     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTmpTexId2, 0);
     46     glActiveTexture(GL_TEXTURE0);
     47     glBindTexture(GL_TEXTURE_2D, mTmpTexId1);
     48     glUniform1i(textureUniformHandle, 0);
     49 
     50     glUniform2f(scaleUniformHandle, 0, 1.0f / mHeight);
     51 
     52     glDrawArrays(GL_TRIANGLES, 0, mMesh->mNumVertices);
     53 }
     54 
     55 void BlurMeshNode::after(Program& program, Matrix& model, Matrix& view, Matrix& projection) {
     56 }
     57