Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change stage #19

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dk.scuffed.whiteboardapp.pipeline.stages

import android.content.Context
import android.opengl.GLES20
import android.util.Size
import dk.scuffed.whiteboardapp.R
import dk.scuffed.whiteboardapp.opengl.*
import dk.scuffed.whiteboardapp.pipeline.*


internal class ChangeStage(
context: Context,
private val inputFrameBufferInfo1: FramebufferInfo,
private val inputFrameBufferInfo2: FramebufferInfo,
pipeline: Pipeline): GLOutputStage(context, R.raw.vertex_shader, R.raw.change_shader, pipeline) {

init {
setup()
}

override fun setupFramebufferInfo() {
val resolution = Size(inputFrameBufferInfo1.textureSize.width, inputFrameBufferInfo1.textureSize.height)
allocateFramebuffer(GLES20.GL_RGBA, resolution)

}

override fun setupUniforms(program: Int) {
super.setupUniforms(program)

// Input framebuffer resolution
val framebufferResolutionHandle = glGetUniformLocation(program, "samplerResolution")
glUniform2f(framebufferResolutionHandle, inputFrameBufferInfo1.textureSize.width.toFloat(), inputFrameBufferInfo1.textureSize.height.toFloat())


// Input framebuffer
val framebufferTextureHandle1 = glGetUniformLocation(program, "sampler1")
glUniform1i(framebufferTextureHandle1, inputFrameBufferInfo1.textureUnitPair.textureUnitIndex)
glActiveTexture(inputFrameBufferInfo1.textureUnitPair.textureUnit)
glBindTexture(GLES20.GL_TEXTURE_2D, inputFrameBufferInfo1.textureHandle)

val framebufferTextureHandle2 = glGetUniformLocation(program, "sampler2")
glUniform1i(framebufferTextureHandle2, inputFrameBufferInfo2.textureUnitPair.textureUnitIndex)
glActiveTexture(inputFrameBufferInfo2.textureUnitPair.textureUnit)
glBindTexture(GLES20.GL_TEXTURE_2D, inputFrameBufferInfo2.textureHandle)
}
}
19 changes: 19 additions & 0 deletions app/src/main/res/raw/change_shader.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#extension GL_OES_EGL_image_external : require
precision mediump float;

uniform vec2 samplerResolution;
uniform vec2 maskResolution;

uniform sampler2D sampler1;
uniform sampler2D sampler2;
//uniform sampler2D mask;

void main() {
vec2 samplersUV = gl_FragCoord.xy / samplerResolution;
vec2 maskUV = gl_FragCoord.xy / maskResolution;

vec4 col1 = texture2D(sampler1, samplersUV);
vec4 col2 = texture2D(sampler2, samplersUV);

gl_FragColor = abs(col1 - col2);
}