Skip to content

Instantly share code, notes, and snippets.

@appspell
Created March 4, 2021 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appspell/c92a8a4a7a402bdf39c36939bbf12ed0 to your computer and use it in GitHub Desktop.
Save appspell/c92a8a4a7a402bdf39c36939bbf12ed0 to your computer and use it in GitHub Desktop.
private const val OPENGL_VERSION = 3
class ShaderView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) :
GLTextureView(context, attrs, defStyleAttr) {
init {
// define OpenGL version
setEGLContextClientVersion(OPENGL_VERSION)
// load shader's source code from RAW files
val vsh = context.resources.getRawTextFile(R.raw.vertex_shader)
val fsh = context.resources.getRawTextFile(R.raw.fragment_shader)
// set renderer
setRenderer(QuadRender(vertexShaderSource = vsh, fragmentShaderSource = fsh))
// set render mode RENDERMODE_WHEN_DIRTY or RENDERMODE_CONTINUOUSLY
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY) // or GLSurfaceView.RENDERMODE_CONTINUOUSLY if we need to update it each frame
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment