Files
baji-vc/tests/avatar/GL.kt
T

71 lines
4.5 KiB
Kotlin

package android.opengl
import java.nio.Buffer
object GLFixture {
var swaps=0;var draws=0;var deleted=0;var terminated=0;var swapFails=false;var shaderFails=false
var bodySize=0f to 0f
var alpha=0f;var patchTexture=0;var activeUnit=0
val rendered=mutableListOf<Pair<Int,Float>>()
fun reset() { swaps=0;draws=0;deleted=0;terminated=0;swapFails=false;shaderFails=false;alpha=0f;patchTexture=0;activeUnit=0;rendered.clear();bodySize=0f to 0f }
}
class EGLDisplay
class EGLContext
class EGLSurface
class EGLConfig
object EGL14 {
val EGL_NO_DISPLAY=EGLDisplay();val EGL_NO_CONTEXT=EGLContext();val EGL_NO_SURFACE=EGLSurface()
const val EGL_DEFAULT_DISPLAY=0;const val EGL_RENDERABLE_TYPE=1;const val EGL_OPENGL_ES2_BIT=2
const val EGL_SURFACE_TYPE=3;const val EGL_WINDOW_BIT=4;const val EGL_RED_SIZE=5;const val EGL_GREEN_SIZE=6
const val EGL_BLUE_SIZE=7;const val EGL_ALPHA_SIZE=8;const val EGL_NONE=9;const val EGL_CONTEXT_CLIENT_VERSION=10
fun eglGetDisplay(id: Int)=EGLDisplay()
fun eglInitialize(d: EGLDisplay,v: IntArray,o: Int,v2: IntArray,o2: Int)=true
fun eglChooseConfig(d: EGLDisplay,attrs: IntArray,o: Int,configs: Array<EGLConfig?>,co: Int,size: Int,count: IntArray,no: Int): Boolean { configs[0]=EGLConfig();count[0]=1;return true }
fun eglCreateContext(d: EGLDisplay,c: EGLConfig?,share: EGLContext,attrs: IntArray,o: Int)=EGLContext()
fun eglCreateWindowSurface(d: EGLDisplay,c: EGLConfig?,native: Any,attrs: IntArray,o: Int)=EGLSurface()
fun eglMakeCurrent(d: EGLDisplay,draw: EGLSurface,read: EGLSurface,c: EGLContext)=true
fun eglSwapBuffers(d: EGLDisplay,s: EGLSurface): Boolean { GLFixture.swaps++;return !GLFixture.swapFails }
fun eglDestroySurface(d: EGLDisplay,s: EGLSurface)=true
fun eglDestroyContext(d: EGLDisplay,c: EGLContext)=true
fun eglTerminate(d: EGLDisplay): Boolean { GLFixture.terminated++;return true }
fun eglReleaseThread()=true
}
object GLES11Ext { const val GL_TEXTURE_EXTERNAL_OES=100 }
object GLES20 {
const val GL_TEXTURE_2D=101;const val GL_TEXTURE_MIN_FILTER=102;const val GL_TEXTURE_MAG_FILTER=103
const val GL_LINEAR=104;const val GL_TEXTURE_WRAP_S=105;const val GL_TEXTURE_WRAP_T=106;const val GL_CLAMP_TO_EDGE=107
const val GL_RGBA=108;const val GL_UNSIGNED_BYTE=109;const val GL_NO_ERROR=0;const val GL_VERTEX_SHADER=110
const val GL_FRAGMENT_SHADER=111;const val GL_COMPILE_STATUS=112;const val GL_TRUE=1;const val GL_LINK_STATUS=113
const val GL_COLOR_BUFFER_BIT=114;const val GL_FLOAT=115;const val GL_TEXTURE0=116;const val GL_TEXTURE1=117;const val GL_TRIANGLE_STRIP=118
fun glGetAttribLocation(p: Int,name: String)=if(name=="aPosition") 1 else 2
fun glGetUniformLocation(p: Int,name: String)=when(name) { "uOpacity"->3;"uRect"->4;else->5 }
fun glGenTextures(n: Int,ids: IntArray,o: Int) { repeat(n) { ids[o+it]=it+1 } }
fun glBindTexture(target: Int,id: Int) { if(target==GL_TEXTURE_2D && GLFixture.activeUnit==GL_TEXTURE1) GLFixture.patchTexture=id }
fun glTexParameteri(target: Int,name: Int,value: Int) {}
fun glTexImage2D(target: Int,level: Int,format: Int,w: Int,h: Int,border: Int,format2: Int,type: Int,data: Buffer) {}
fun glGetError()=GL_NO_ERROR
fun glCreateShader(type: Int)=1
fun glShaderSource(id: Int,source: String) {}
fun glCompileShader(id: Int) {}
fun glGetShaderiv(id: Int,p: Int,status: IntArray,o: Int) { status[o]=if(GLFixture.shaderFails) 0 else GL_TRUE }
fun glDeleteShader(id: Int) {}
fun glCreateProgram()=1
fun glAttachShader(program: Int,shader: Int) {}
fun glLinkProgram(program: Int) {}
fun glGetProgramiv(id: Int,p: Int,status: IntArray,o: Int) { status[o]=GL_TRUE }
fun glViewport(x: Int,y: Int,w: Int,h: Int) {}
fun glClearColor(r: Float,g: Float,b: Float,a: Float) {}
fun glClear(mask: Int) {}
fun glUseProgram(p: Int) {}
fun glVertexAttribPointer(location: Int,size: Int,type: Int,normalized: Boolean,stride: Int,data: Buffer) {}
fun glEnableVertexAttribArray(location: Int) {}
fun glUniformMatrix4fv(location: Int,count: Int,transpose: Boolean,value: FloatArray,o: Int) {}
fun glActiveTexture(id: Int) { GLFixture.activeUnit=id }
fun glUniform1i(location: Int,value: Int) {}
fun glUniform2f(location: Int,x: Float,y: Float) { GLFixture.bodySize=x to y }
fun glUniform4f(location: Int,a: Float,b: Float,c: Float,d: Float) {}
fun glUniform1f(location: Int,value: Float) { if(location==3) GLFixture.alpha=value }
fun glDrawArrays(mode: Int,first: Int,count: Int) { GLFixture.draws++;GLFixture.rendered+=GLFixture.patchTexture to GLFixture.alpha }
fun glDeleteTextures(n: Int,textures: IntArray,o: Int) { GLFixture.deleted+=n }
fun glDeleteProgram(p: Int) {}
}