@@ -203,25 +203,33 @@ void RenderTriangle ()
203
203
// Enable a handle to the triangle vertices
204
204
GL . EnableVertexAttribArray ( mPositionHandle ) ;
205
205
206
- // Prepare the triangle coordinate data
207
- GL . VertexAttribPointer ( 0 , 3 , All . Float , false , 0 , vertices ) ;
206
+ // pin the data, so that GC doesn't move them, while used
207
+ // by native code
208
+ unsafe {
209
+ fixed ( float * pvertices = vertices ) {
210
+ // Prepare the triangle coordinate data
211
+ GL . VertexAttribPointer ( 0 , 3 , All . Float , false , 0 , new IntPtr ( pvertices ) ) ;
208
212
209
- // get handle to fragment shader's vColor member
210
- mColorHandle = GL . GetUniformLocation ( mProgramHandle , new StringBuilder ( "vColor" ) ) ;
213
+ // get handle to fragment shader's vColor member
214
+ mColorHandle = GL . GetUniformLocation ( mProgramHandle , new StringBuilder ( "vColor" ) ) ;
211
215
212
- // Set color for drawing the triangle
213
- GL . Uniform4 ( mColorHandle , 1 , color ) ;
216
+ // Set color for drawing the triangle
217
+ GL . Uniform4 ( mColorHandle , 1 , color ) ;
214
218
215
- // get handle to shape's transformation matrix
216
- mMVPMatrixHandle = GL . GetUniformLocation ( mProgramHandle , new StringBuilder ( "uMVPMatrix" ) ) ;
219
+ // get handle to shape's transformation matrix
220
+ mMVPMatrixHandle = GL . GetUniformLocation ( mProgramHandle , new StringBuilder ( "uMVPMatrix" ) ) ;
217
221
218
- // Apply the projection and view transformation
219
- GL . UniformMatrix4 ( mMVPMatrixHandle , false , ref mModelViewProjectionMatrix ) ;
222
+ // Apply the projection and view transformation
223
+ GL . UniformMatrix4 ( mMVPMatrixHandle , false , ref mModelViewProjectionMatrix ) ;
220
224
221
- GL . DrawArrays ( All . Triangles , 0 , 3 ) ;
225
+ GL . DrawArrays ( All . Triangles , 0 , 3 ) ;
226
+
227
+ GL . Finish ( ) ;
228
+ }
229
+ }
222
230
223
231
// Disable vertex array
224
- GL . DisableVertexAttribArray ( mPositionHandle ) ;
232
+ GL . DisableVertexAttribArray ( mPositionHandle ) ;
225
233
226
234
SwapBuffers ( ) ;
227
235
}
0 commit comments