@@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.map.internal
3
3
import android.opengl.GLES20
4
4
import android.opengl.Matrix
5
5
import android.util.Log
6
+ import androidx.compose.ui.graphics.Color
6
7
import java.nio.Buffer
7
8
import java.nio.ByteBuffer
8
9
import java.nio.FloatBuffer
@@ -17,20 +18,20 @@ fun initShaderProgram(vsSource: String, fsSource: String): Int {
17
18
val program = GLES20 .glCreateProgram()
18
19
check(program != 0 ) { " Could not create program" }
19
20
20
- // add the vertex shader to program
21
+ // Add the vertex shader to program
21
22
GLES20 .glAttachShader(program, vertexShader)
22
23
23
- // add the fragment shader to program
24
+ // Add the fragment shader to program
24
25
GLES20 .glAttachShader(program, fragmentShader)
25
26
26
- // creates OpenGL ES program executables
27
+ // Creates OpenGL ES program executables
27
28
GLES20 .glLinkProgram(program)
28
29
29
30
val linked = IntArray (1 )
30
31
GLES20 .glGetProgramiv(program, GLES20 .GL_LINK_STATUS , linked, 0 )
31
32
if (linked[0 ] == GLES20 .GL_FALSE ) {
32
33
val infoLog = GLES20 .glGetProgramInfoLog(program)
33
- Log .e(" mullvad " , " Could not link program: $infoLog " )
34
+ Log .e(" GLHelper " , " Could not link program: $infoLog " )
34
35
GLES20 .glDeleteProgram(program)
35
36
error(" Could not link program with vsSource: $vsSource and fsSource: $fsSource " )
36
37
}
@@ -39,21 +40,21 @@ fun initShaderProgram(vsSource: String, fsSource: String): Int {
39
40
}
40
41
41
42
private fun loadShader (type : Int , shaderCode : String ): Int {
42
- // create a vertex shader type (GLES20.GL_VERTEX_SHADER)
43
+ // Create a vertex shader type (GLES20.GL_VERTEX_SHADER)
43
44
// or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
44
45
val shader = GLES20 .glCreateShader(type)
45
46
46
47
require(shader != 0 ) { " Unable to create shader" }
47
48
48
- // add the source code to the shader and compile it
49
+ // Add the source code to the shader and compile it
49
50
GLES20 .glShaderSource(shader, shaderCode)
50
51
GLES20 .glCompileShader(shader)
51
52
52
53
val compiled = IntArray (1 )
53
54
GLES20 .glGetShaderiv(shader, GLES20 .GL_COMPILE_STATUS , compiled, 0 )
54
55
if (compiled[0 ] == GLES20 .GL_FALSE ) {
55
56
val infoLog = GLES20 .glGetShaderInfoLog(shader)
56
- Log .e(" mullvad " , " Could not compile shader $type :$infoLog " )
57
+ Log .e(" GLHelper " , " Could not compile shader $type :$infoLog " )
57
58
GLES20 .glDeleteShader(shader)
58
59
59
60
error(" Could not compile shader with shaderCode: $shaderCode " )
@@ -95,3 +96,11 @@ fun initIndexBuffer(dataBuffer: Buffer): IndexBufferWithLength {
95
96
}
96
97
97
98
fun newIdentityMatrix (): FloatArray = FloatArray (MATRIX_SIZE ).apply { Matrix .setIdentityM(this , 0 ) }
99
+
100
+ fun Color.toFloatArray (): FloatArray {
101
+ return floatArrayOf(red, green, blue, alpha)
102
+ }
103
+
104
+ fun Color.toFloatArrayWithoutAlpha (): FloatArray {
105
+ return floatArrayOf(red, green, blue)
106
+ }
0 commit comments