-
-
Save appspell/c92a8a4a7a402bdf39c36939bbf12ed0 to your computer and use it in GitHub Desktop.
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
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