package Ġgli mp se . android . gles Ċ Ċ import Ġandroid . graphics . Bitmap Factory Ċ import Ġandroid . opengl . GLES 2 0 Ċ import Ġandroid . opengl . GL Utils Ċ import Ġgli mp se . Color Ċ import Ġgli mp se . android . gles . deleg ates . Enable Disable Delegate Ċ import Ġgli mp se . gles .* Ċ import Ġgli mp se . gles . GLES Ċ import Ġgli mp se . gles . deleg ates . Enum Pair Set And Remember Delegate Ċ import Ġgli mp se . gles . deleg ates . Enum Set And Remember Delegate Ċ import Ġgli mp se . gles . deleg ates . Set And Remember Delegate Ċ import Ġgli mp se . shaders . Program Handle Ċ import Ġgli mp se . shaders . Shader Handle Ċ import Ġgli mp se . shaders . Shader Type Ċ import Ġgli mp se . textures . Texture Handle Ċ import Ġgli mp se . textures . Texture M agn ification Filter Ċ import Ġgli mp se . textures . Texture Min ification Filter Ċ import Ġgli mp se . textures . Texture Wr apping Ċ import Ġjava . io . InputStream Ċ import Ġjava . nio . Buffer Ċ import Ġjava . nio . Float Buffer Ċ import Ġjava . nio . Int Buffer Ċ Ċ /** Ċ Ġ* ĠAndroid Ġimplementation Ġof ĠGLES Ġfac ade . Ċ Ġ*/ Ċ object ĠGLES Ġ: ĠGLES Ġ{ ĊĊ ĉ override Ġvar Ġviewport : ĠView port Ġby ĠSet And Remember Delegate ( Viewport ( 1 , Ġ 1 )) Ġ{ Ċĉ ĉ GLES 2 0 . gl Viewport ( 0 , Ġ 0 , Ġit . width , Ġit . height ) Ċ ĉ } ĊĊ ĉ override Ġvar Ġclear Color : ĠColor Ġby ĠSet And Remember Delegate ( Color . Companion . BLACK ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Clear Color ( it . red , Ġit . green , Ġit . blue , Ġit . alpha ) Ċ ĉ } ĊĊ ĉ override Ġvar Ġclear Depth : ĠFloat Ġby ĠSet And Remember Delegate ( 1 f ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Clear Depth f ( it ) Ċ ĉ } ĊĊ ĉ override Ġvar Ġis Depth Test : ĠBoolean Ġby ĠEnable Disable Delegate ( GLES 2 0 . GL _ DEPTH _ TEST ) Ċ ĉ override Ġvar Ġdepth Test Function : ĠDepth Test Function Ġby ĠEnum Set And Remember Delegate ( Depth Test Function . LESS , Ġdepth Test Function Mapping ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Depth Func ( it ) Ċ ĉ } ĊĊ ĉ override Ġvar Ġis Blend : ĠBoolean Ġby ĠEnable Disable Delegate ( GLES 2 0 . GL _ BLEND ) Ċ ĉ override Ġvar Ġblend Function : ĠPair < Blend Factor , ĠBlend Factor > Ġby ĠEnum Pair Set And Remember Delegate ( Blend Factor . ZERO Ġto ĠBlend Factor . ONE , Ġblend Factor Mapping ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Blend Func ( it . first , Ġit . second ) Ċ ĉ } ĊĊ ĉ override Ġvar Ġis Cull Face : ĠBoolean Ġby ĠEnable Disable Delegate ( GLES 2 0 . GL _ C ULL _ FACE ) Ċ ĉ override Ġvar Ġc ull Face Mode : ĠC ull Face Mode Ġby ĠEnum Set And Remember Delegate ( Cull Face Mode . BACK , Ġc ull Face Mode Mapping ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Cull Face ( it ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġclear Depth Buffer () Ġ{ Ċĉ ĉ GLES 2 0 . gl Clear ( GLES 2 0 . GL _ DEPTH _ BUFFER _ BIT ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġclear Color Buffer () Ġ{ Ċĉ ĉ GLES 2 0 . gl Clear ( GLES 2 0 . GL _ COLOR _ BUFFER _ BIT ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġcreate Shader ( shader Type : ĠShader Type ) Ġ= Ċĉĉ ĉ Shader Handle ( GLES 2 0 . gl Create Shader ( shader Type Mapping [ shader Type ] !! )) ĊĊ ĉ override Ġfun Ġcompile Shader ( shader Handle : ĠShader Handle , Ġsource : ĠString ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Shader Source ( shader Handle . value , Ġsource ) Ċĉ ĉ GLES 2 0 . gl Compile Shader ( shader Handle . value ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġdelete Shader ( shader Handle : ĠShader Handle ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Delete Shader ( shader Handle . value ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġget Shader Compile Status ( shader Handle : ĠShader Handle ) Ġ= Ċĉĉ ĉ get Shader Property ( shader Handle , ĠGLES 2 0 . GL _ COMPILE _ STATUS ) Ġ== ĠGLES 2 0 . GL _ TRUE ĊĊ ĉ private Ġfun Ġget Shader Property ( shader Handle : ĠShader Handle , Ġproperty : ĠInt ): ĠInt Ġ{ Ċĉ ĉ val Ġresult Ġ= ĠInt Buffer . allocate ( 1 ) Ċĉ ĉ GLES 2 0 . glGet Shader iv ( shader Handle . value , Ġproperty , Ġresult ) Ċĉ ĉ return Ġresult [ 0 ] Ċ ĉ } ĊĊ ĉ override Ġfun Ġget Shader Log ( shader Handle : ĠShader Handle ): ĠString Ġ= Ċĉĉ ĉ GLES 2 0 . glGet Shader Info Log ( shader Handle . value ) ĊĊ ĉ override Ġfun Ġcreate Program () Ġ= Ċĉĉ ĉ Program Handle ( GLES 2 0 . gl Create Program ()) ĊĊ ĉ override Ġfun Ġattach Shader ( program Handle : ĠProgram Handle , Ġshader Handle : ĠShader Handle ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Attach Shader ( program Handle . value , Ġshader Handle . value ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġlink Program ( program Handle : ĠProgram Handle ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Link Program ( program Handle . value ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġuse Program ( program Handle : ĠProgram Handle ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Use Program ( program Handle . value ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġdelete Program ( program Handle : ĠProgram Handle ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Delete Program ( program Handle . value ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġget Program Link Status ( program Handle : ĠProgram Handle ) Ġ= Ċĉĉ ĉ get Program Property ( program Handle , ĠGLES 2 0 . GL _ LINK _ STATUS ) Ġ== ĠGLES 2 0 . GL _ TRUE ĊĊ ĉ private Ġfun Ġget Program Property ( program Handle : ĠProgram Handle , Ġproperty : ĠInt ): ĠInt Ġ{ Ċĉ ĉ val Ġresult Ġ= ĠInt Buffer . allocate ( 1 ) Ċĉ ĉ GLES 2 0 . glGet Program iv ( program Handle . value , Ġproperty , Ġresult ) Ċĉ ĉ return Ġresult [ 0 ] Ċ ĉ } ĊĊ ĉ override Ġfun Ġget Program Log ( program Handle : ĠProgram Handle ): ĠString Ġ= Ċĉĉ ĉ GLES 2 0 . glGet Program Info Log ( program Handle . value ) ĊĊ ĉ override Ġfun Ġget UniformLocation ( handle : ĠProgram Handle , Ġname : ĠString ) Ġ= Ċĉĉ ĉ UniformLocation ( GLES 2 0 . glGet UniformLocation ( handle . value , Ġname )) ĊĊ ĉ override Ġfun Ġget Attribute Location ( handle : ĠProgram Handle , Ġname : ĠString ) Ġ= Ċĉĉ ĉ Attribute Location ( GLES 2 0 . glGet Attrib Location ( handle . value , Ġname )) ĊĊ ĉ override Ġfun Ġuniform Float ( location : ĠUniform Location , Ġfloat : ĠFloat ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Uniform 1 f ( location . value , Ġfloat ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġuniform Float s ( location : ĠUniform Location , Ġfloats : ĠFloat Array ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Uniform 1 fv ( location . value , Ġfloats . size , Ġfloats , Ġ 0 ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġuniform Int ( location : ĠUniform Location , Ġint : ĠInt ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Uniform 1 i ( location . value , Ġint ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġuniform Ints ( location : ĠUniform Location , Ġints : ĠInt Array ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Uniform 1 iv ( location . value , Ġints . size , Ġints , Ġ 0 ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġuniform Matrix 1 6 f ( location : ĠUniform Location , Ġ_ 1 6 f : ĠArray < Float >) Ġ{ Ċĉ ĉ GLES 2 0 . gl Uniform Matrix 4 fv ( location . value , Ġ 1 , Ġfalse , Ġ_ 1 6 f . toFloat Array (), Ġ 0 ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġuniform 4 f ( location : ĠUniform Location , Ġ_ 4 f : ĠArray < Float >, Ġcount : ĠInt ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Uniform 4 fv ( location . value , Ġcount , Ġ_ 4 f . toFloat Array (), Ġ 0 ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġcreate Attribute Float Array ( location : ĠAttribute Location , Ġbuffer : ĠFloat Buffer , Ġvector Size : ĠInt ) Ġ= Ċĉĉ ĉ create Attribute Array ( location , Ġbuffer , Ġvector Size , ĠGLES 2 0 . GL _ FLOAT , Ġ 4 ) ĊĊ ĉ override Ġfun Ġcreate Attribute IntArray ( location : ĠAttribute Location , Ġbuffer : ĠInt Buffer , Ġvector Size : ĠInt ) Ġ= Ċĉĉ ĉ create Attribute Array ( location , Ġbuffer , Ġvector Size , ĠGLES 2 0 . GL _ INT , Ġ 4 ) ĊĊ ĉ private Ġfun Ġcreate Attribute Array ( location : ĠAttribute Location , Ġbuffer : ĠBuffer , Ġvector Size : ĠInt , Ġtype : ĠInt , Ġtype Size : ĠInt ): ĠBuffer Handle Ġ{ Ċĉ ĉ buffer . rewind () Ċĉ ĉ val Ġhandles Ġ= ĠInt Array ( 1 ) Ċĉ ĉ GLES 2 0 . gl Gen Buffers ( 1 , Ġhandles , Ġ 0 ) Ċĉ ĉ GLES 2 0 . glBind Buffer ( GLES 2 0 . GL _ ARRAY _ BUFFER , Ġhandles [ 0 ]) Ċĉ ĉ GLES 2 0 . gl BufferData ( GLES 2 0 . GL _ ARRAY _ BUFFER , Ġbuffer . limit () Ġ* Ġtype Size , Ġbuffer , ĠGLES 2 0 . GL _ STATIC _ DRAW ) Ċĉ ĉ GLES 2 0 . glVertex Attrib Pointer ( location . value , Ġvector Size , Ġtype , Ġfalse , Ġ 0 , Ġ 0 ) Ċĉ ĉ return ĠBuffer Handle ( handles [ 0 ]) Ċ ĉ } ĊĊ ĉ override Ġfun Ġdelete Attribute Array ( handle : ĠBuffer Handle ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Delete Buffers ( 1 , ĠarrayOf ( handle . value ). to IntArray (), Ġ 0 ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġenable Attribute Array ( location : ĠAttribute Location ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Enable VertexAttrib Array ( location . value ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġdisable Attribute Array ( location : ĠAttribute Location ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Disable VertexAttrib Array ( location . value ) Ċ ĉ } ĊĊ ĉ override Ġvar Ġtexture Min ification Filter : ĠTexture Min ification Filter Ċĉĉ ĉ by ĠEnum Set And Remember Delegate ( Texture Min ification Filter . NE ARE ST _ MIP MAP _ LINEAR , Ġtexture Min ification Filter Mapping ) Ġ{ Ċĉĉĉ ĉ GLES 2 0 . gl TexParameter i ( GLES 2 0 . GL _ TEXTURE _ 2 D , ĠGLES 2 0 . GL _ TEXTURE _ MIN _ FILTER , Ġit ) Ċĉĉ ĉ } Ċ ĉ override Ġvar Ġtexture M agn ification Filter : ĠTexture M agn ification Filter Ċĉĉ ĉ by ĠEnum Set And Remember Delegate ( Texture M agn ification Filter . LINEAR , Ġtexture M agn ification Filter Mapping ) Ġ{ Ċĉĉĉ ĉ GLES 2 0 . gl TexParameter i ( GLES 2 0 . GL _ TEXTURE _ 2 D , ĠGLES 2 0 . GL _ TEXTURE _ MIN _ FILTER , Ġit ) Ċĉĉ ĉ } Ċ ĉ override Ġvar Ġtexture Wr apping : ĠPair < Texture Wr apping , ĠTexture Wr apping > Ċĉĉ ĉ by ĠEnum Pair Set And Remember Delegate ( Texture Wr apping . REPEAT Ġto ĠTexture Wr apping . REPEAT , Ġtexture Wr apping Mapping ) Ġ{ Ċĉĉĉ ĉ GLES 2 0 . gl TexParameter i ( GLES 2 0 . GL _ TEXTURE _ 2 D , ĠGLES 2 0 . GL _ TEXTURE _ WRAP _ S , Ġit . first ) Ċĉĉĉ ĉ GLES 2 0 . gl TexParameter i ( GLES 2 0 . GL _ TEXTURE _ 2 D , ĠGLES 2 0 . GL _ TEXTURE _ WRAP _ T , Ġit . second ) Ċĉĉ ĉ } ĊĊ ĉ override Ġfun Ġgenerate Textures ( count : ĠInt ): ĠArray < Texture Handle > Ġ{ Ċĉ ĉ val Ġhandles Ġ= ĠInt Array ( count ) Ċĉ ĉ GLES 2 0 . gl Gen Textures ( count , Ġhandles , Ġ 0 ) Ċĉ ĉ return Ġhandles . map Ġ{ ĠTexture Handle ( it ) Ġ}. to Typed Array () Ċ ĉ } ĊĊ ĉ override Ġfun Ġdelete Textures ( count : ĠInt , Ġhandles : ĠArray < Texture Handle >) Ġ{ Ċĉ ĉ GLES 2 0 . gl Delete Textures ( count , Ġhandles . map Ġ{ Ġit . value Ġ}. to IntArray (), Ġ 0 ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġbind Texture 2 D ( handle : ĠTexture Handle ) Ġ{ Ċĉ ĉ GLES 2 0 . glBind Texture ( GLES 2 0 . GL _ TEXTURE _ 2 D , Ġhandle . value ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġtexture Image 2 D ( inputStream : ĠInputStream , ĠfileName : ĠString , Ġwith Mip map : ĠBoolean ) Ġ{ Ċĉ ĉ val Ġbitmap Ġ= ĠBitmap Factory . decode Stream ( inputStream ) Ċĉ ĉ GL Utils . tex Image 2 D ( GLES 2 0 . GL _ TEXTURE _ 2 D , Ġ 0 , ĠGLES 2 0 . GL _ RGBA , Ġbitmap , Ġ 0 ) Ċĉ ĉ if Ġ( with Mip map ) ĠGLES 2 0 . gl Generate Mip map ( GLES 2 0 . GL _ TEXTURE _ 2 D ) Ċĉ ĉ bitmap . recycle () Ċ ĉ } ĊĊ ĉ override Ġfun Ġactive Texture ( index : ĠInt ) Ġ{ Ċĉ ĉ require ( index Ġin Ġ 0 .. 3 1 ) Ġ{ Ġ" Texture Ġindex Ġout Ġof Ġbounds : Ġ$ index " Ġ} Ċĉ ĉ GLES 2 0 . gl Active Texture ( GLES 2 0 . GL _ TEXTURE 0 Ġ+ Ġindex ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġdraw Triangles ( vertices Count : ĠInt ) Ġ{ Ċĉ ĉ GLES 2 0 . gl Draw Arrays ( GLES 2 0 . GL _ TRI ANG LES , Ġ 0 , Ġvertices Count ) Ċ ĉ } Ċ } Ċ