-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nekocode
committed
Aug 12, 2016
1 parent
689503d
commit bb3261d
Showing
55 changed files
with
618 additions
and
645 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
app/src/main/java/cn/nekocode/camerafilter/RenderBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2016 nekocode | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cn.nekocode.camerafilter; | ||
|
||
import android.opengl.GLES20; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.nio.IntBuffer; | ||
|
||
import javax.microedition.khronos.opengles.GL10; | ||
|
||
/** | ||
* Created by nekocode on 16/8/12. | ||
*/ | ||
public class RenderBuffer { | ||
private int texId = 0; | ||
private int activeTexUnit = 0; | ||
private int renderBufferId = 0; | ||
private int frameBufferId = 0; | ||
|
||
private int width, height; | ||
|
||
public RenderBuffer(int width, int height, int activeTexUnit) { | ||
this.width = width; | ||
this.height = height; | ||
this.activeTexUnit = activeTexUnit; | ||
int[] genbuf = new int[1]; | ||
|
||
// Generate and bind 2d texture | ||
GLES20.glActiveTexture(activeTexUnit); | ||
texId = MyGLUtils.genTexture(); | ||
IntBuffer texBuffer = | ||
ByteBuffer.allocateDirect(width * height * 4).order(ByteOrder.nativeOrder()).asIntBuffer(); | ||
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, texBuffer); | ||
|
||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); | ||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); | ||
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); | ||
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); | ||
|
||
// Generate frame buffer | ||
GLES20.glGenFramebuffers(1, genbuf, 0); | ||
frameBufferId = genbuf[0]; | ||
// Bind frame buffer | ||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferId); | ||
|
||
// Generate render buffer | ||
GLES20.glGenRenderbuffers(1, genbuf, 0); | ||
renderBufferId = genbuf[0]; | ||
// Bind render buffer | ||
GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBufferId); | ||
GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height); | ||
|
||
unbind(); | ||
} | ||
|
||
public int getTexId() { | ||
return texId; | ||
} | ||
|
||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
public int getHeight() { | ||
return height; | ||
} | ||
|
||
public int getActiveTexUnit() { | ||
return activeTexUnit; | ||
} | ||
|
||
public void bind() { | ||
GLES20.glViewport(0, 0, width, height); | ||
|
||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBufferId); | ||
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, | ||
GLES20.GL_TEXTURE_2D, texId, 0); | ||
GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, | ||
GLES20.GL_RENDERBUFFER, renderBufferId); | ||
} | ||
|
||
public void unbind() { | ||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); | ||
} | ||
} |
Oops, something went wrong.