// Set up the texture objects. static bool arglSetupTextureObjects(ARGL_CONTEXT_SETTINGS contextSettings) { int textureWrapMode; // Delete previous textures, unless this is our first time here. if (contextSettings.textureObjectsHaveBeenSetup) { GL1.ActiveTexture(All1.Texture0); GL1.BindTexture(All1.Texture2D, 0); GL1.DeleteTextures(1, ref contextSettings.texture); contextSettings.textureObjectsHaveBeenSetup = false; } GL1.GenTextures(1, out contextSettings.texture); GL1.ActiveTexture(All1.Texture0); GL1.BindTexture(All1.Texture2D, contextSettings.texture); GL1.TexParameterx(All1.Texture2D, All1.TextureMinFilter, (int)All1.Linear); GL1.TexParameterx(All1.Texture2D, All1.TextureMagFilter, (int)All1.Linear); // Decide whether we can use GL_CLAMP_TO_EDGE. //if (arglGLCapabilityCheck(0x0120, (unsigned char *)"GL_SGIS_texture_edge_clamp")) { textureWrapMode = (int)All1.ClampToEdge; //} else { // textureWrapMode = (int)All1.Repeat; //} GL1.TexParameterx(All1.Texture2D, All1.TextureWrapS, textureWrapMode); GL1.TexParameterx(All1.Texture2D, All1.TextureWrapT, textureWrapMode); contextSettings.textureObjectsHaveBeenSetup = true; return(true); }
void LoadTextureFromPvrtc() { //texturetool -e PVRTC -o glass.pvrtc glass.png using (NSData ns = NSData.FromFile("glass.pvrtc")) { GL.BindTexture(All.Texture2D, texture[0]); GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int)All.Nearest); GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int)All.Nearest); GL.CompressedTexImage2D(All.Texture2D, 0, All.CompressedRgbPvrtc4Bppv1Img, 128, 128, 0, (int)ns.Length, ns.Bytes); GL.BindTexture(All.Texture2D, texture[1]); GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int)All.Linear); GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int)All.Linear); GL.CompressedTexImage2D(All.Texture2D, 0, All.CompressedRgbPvrtc4Bppv1Img, 128, 128, 0, (int)ns.Length, ns.Bytes); GL.BindTexture(All.Texture2D, texture[2]); GL1.TexParameter(All1.Texture2D, All1.GenerateMipmap, 1); GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int)All.Linear); GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int)All.LinearMipmapNearest); GL.CompressedTexImage2D(All.Texture2D, 0, All.CompressedRgbPvrtc4Bppv1Img, 128, 128, 0, (int)ns.Length, ns.Bytes); } }
public override void setFullscreen(bool state, bool resizable) { var display = TK.DisplayDevice.Default; display.ChangeResolution(display.Width, display.Height, display.BitsPerPixel, display.RefreshRate); if (state) { _window.WindowState = TK.WindowState.Fullscreen; _window.WindowBorder = TK.WindowBorder.Hidden; } else { _window.WindowState = TK.WindowState.Normal; if (resizable) { _window.WindowBorder = TK.WindowBorder.Resizable; } else { _window.WindowBorder = TK.WindowBorder.Fixed; } } GL11.Viewport(0, 0, _window.Width, _window.Height); }
static bool arglPixelBufferDataUpload(ARGL_CONTEXT_SETTINGS contextSettings, byte[] bufDataPtr) { if (contextSettings == null) { return(false); } if (contextSettings.textureObjectsHaveBeenSetup || contextSettings.textureGeometryHasBeenSetup || contextSettings.pixSize == 0) { return(false); } GL1.ActiveTexture(All1.Texture0); GL1.BindTexture(All1.Texture2D, contextSettings.texture); GL1.PixelStore(All1.UnpackAlignment, (((contextSettings.bufSizeX * contextSettings.pixSize) & 0x3) == 0 ? 4 : 1)); if (contextSettings.bufSizeIsTextureSize) { GL1.TexImage2D(All1.Texture2D, 0, (OpenTK.Graphics.ES11.All)contextSettings.pixIntFormat, contextSettings.textureSizeX, contextSettings.textureSizeY, 0, (All1)contextSettings.pixFormat, (All1)contextSettings.pixType, bufDataPtr); } else { // Request OpenGL allocate memory internally for a power-of-two texture of the appropriate size. // Then send the NPOT-data as a subimage. GL1.TexImage2D(All1.Texture2D, 0, (OpenTK.Graphics.ES11.All)contextSettings.pixIntFormat, contextSettings.textureSizeX, contextSettings.textureSizeY, 0, (All1)contextSettings.pixFormat, (All1)contextSettings.pixType, IntPtr.Zero); GL1.TexSubImage2D(All1.Texture2D, 0, 0, 0, contextSettings.bufSizeX, contextSettings.bufSizeY, (All1)contextSettings.pixFormat, (All1)contextSettings.pixType, bufDataPtr); } contextSettings.textureDataReady = true; return(true); }
public void initOpenGLParams() { GL11.Enable(TK.Graphics.ES11.EnableCap.CullFace); GL11.Enable(TK.Graphics.ES11.EnableCap.DepthTest); GL11.Enable(TK.Graphics.ES11.EnableCap.Normalize); GL11.DepthFunc(TK.Graphics.ES11.DepthFunction.Lequal); }
internal override void Apply() { GLStateManager.Projection(Projection); GLStateManager.World(World); GLStateManager.View(View); base.Apply(); // set camera Matrix _matrix = Matrix.Identity; GL11.MatrixMode(All11.Projection); GL11.LoadIdentity(); GL11.Ortho(0, 320, 480, 0, -1, 1); GL11.MatrixMode(All11.Modelview); GL11.LoadMatrix(ref _matrix.M11); GL11.Viewport(0, 0, 320, 480); // Initialize OpenGL states (ideally move this to initialize somewhere else) GL11.Disable(All11.DepthTest); GL11.TexEnv(All11.TextureEnv, All11.TextureEnvMode, (int)All11.BlendSrc); GL11.Enable(All11.Texture2D); GL11.EnableClientState(All11.VertexArray); GL11.EnableClientState(All11.ColorArray); GL11.EnableClientState(All11.TextureCoordArray); GL11.Disable(All11.CullFace); }
void LoadTextureFromPng() { using (UIImage img = UIImage.FromFile("NeHe.png")) { int width = img.CGImage.Width; int height = img.CGImage.Height; using (MonoTouch.CoreGraphics.CGColorSpace colorSpaceRef = MonoTouch.CoreGraphics.CGColorSpace.CreateDeviceRGB()) { IntPtr imageData = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(height * width * 4); try { using (MonoTouch.CoreGraphics.CGBitmapContext context = new MonoTouch.CoreGraphics.CGBitmapContext( imageData, width, height, 8, 4 * width, colorSpaceRef, MonoTouch.CoreGraphics.CGBitmapFlags.ByteOrder32Big | MonoTouch.CoreGraphics.CGBitmapFlags.PremultipliedLast)) { colorSpaceRef.Dispose(); context.ClearRect(new System.Drawing.RectangleF(0.0f, 0.0f, (float)width, (float)height)); context.TranslateCTM(0, 0); context.DrawImage(new System.Drawing.RectangleF(0.0f, 0.0f, (float)width, (float)height), img.CGImage); GL1.TexImage2D(All1.Texture2D, 0, (int)All1.Rgba, width, height, 0, All1.Rgba, All1.UnsignedByte, imageData); } } finally { System.Runtime.InteropServices.Marshal.FreeCoTaskMem(imageData); } } } }
public byte[] Render(IEnumerable <FeatureCollection> featureCollections) { lock (_syncRoot) { // There needs to be a gamewindow even though we don't write to screen. It is created but not used explicitly in our code. using (var gameWindow = new GameWindow(_pixelWidth, _pixelHeight)) { if (!GL.GetString(StringName.Extensions).Contains("GL_EXT_framebuffer_object")) { throw new NotSupportedException( "GL_EXT_framebuffer_object extension is required. Please update your drivers."); } FrameBufferObjectHelper.StartFrameBufferObject(_pixelWidth, _pixelHeight); OpenTK.Graphics.ES20.GL.ClearColor(Color4.White); OpenTK.Graphics.ES20.GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Set2DViewport(_pixelWidth, _pixelHeight); GL.PushMatrix(); GL.Scale(_pixelWidth / _extentWidth, _pixelHeight / _extentHeight, 1); GL.Translate(-_extentMinX, -_extentMinY, 0); PolygonRenderer(featureCollections); var byteArray = GraphicsContextToBitmapConverter.ToBitmap(_pixelWidth, _pixelHeight); GL.PopMatrix(); FrameBufferObjectHelper.StopFrameBufferObject(); return(byteArray); } } }
public static void PrepareForUse(VertexDeclaration vd) { GLStateManager.VertexArray(true); bool normal = false; bool texcoord = false; foreach (var ve in vd.GetVertexElements()) { switch (ve.VertexElementUsage) { case VertexElementUsage.Position: GL11.VertexPointer( ve.VertexElementFormat.OpenGLNumberOfElements(), ve.VertexElementFormat.OpenGLValueType(), vd.VertexStride, //ve.Offset (IntPtr)ve.Offset ); break; case VertexElementUsage.Color: GL11.ColorPointer( ve.VertexElementFormat.OpenGLNumberOfElements(), ve.VertexElementFormat.OpenGLValueType(), vd.VertexStride, //ve.Offset (IntPtr)ve.Offset ); break; case VertexElementUsage.Normal: GL11.NormalPointer( ve.VertexElementFormat.OpenGLValueType(), vd.VertexStride, //ve.Offset (IntPtr)ve.Offset ); normal = true; break; case VertexElementUsage.TextureCoordinate: GL11.TexCoordPointer( ve.VertexElementFormat.OpenGLNumberOfElements(), ve.VertexElementFormat.OpenGLValueType(), vd.VertexStride, //ve.Offset (IntPtr)ve.Offset ); texcoord = true; break; default: throw new NotImplementedException(); } } GLStateManager.TextureCoordArray(texcoord); GLStateManager.NormalArray(normal); }
private static void Set2DViewport(int width, int height) { GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); OpenTK.Graphics.OpenGL.GL.Ortho(0, width, height, 0, 0, 1); // This has no effect: OpenTK.Graphics.ES11.GL.Ortho(0, width, height, 0, 0, 1); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); LoadGLTextures(); GL.Enable(All.Texture2D); GL1.ShadeModel(All1.Smooth); // Enables Smooth Shading GL.ClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background // Create a depth renderbuffer uint depthRenderBuffer = 0; GL.GenRenderbuffers(1, ref depthRenderBuffer); GL.BindRenderbuffer(All.Renderbuffer, depthRenderBuffer); // Allocate storage for the new renderbuffer GL.RenderbufferStorage(All.Renderbuffer, All.DepthComponent16, Size.Width, Size.Height); // Attach the renderbuffer to the framebuffer's depth attachment point GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment, All.Renderbuffer, depthRenderBuffer); GL1.ClearDepth(1.0f); // Depth Buffer Setup GL1.Enable(All1.DepthTest); // Enables Depth Testing GL1.DepthFunc(All1.Lequal); // The Type Of Depth Test To Do GL1.Hint(All1.PerspectiveCorrectionHint, All1.Nicest); // Really Nice Perspective Calculations GL1.Light(All1.Light0, All1.Ambient, LightAmbient); // Setup The Ambient Light GL1.Light(All1.Light0, All1.Diffuse, LightDiffuse); // Setup The Diffuse Light GL1.Light(All1.Light0, All1.Position, LightPosition); // Position The Light GL1.Enable(All1.Light0); }
public void Clear(ClearOptions options, Vector4 color, float depth, int stencil) { GL11.ClearColor(color.X, color.Y, color.Z, 1.0f); GL11.ClearDepth(depth); GL11.ClearStencil(stencil); GL11.Clear((uint)(All11.ColorBufferBit | All11.DepthBufferBit | All11.StencilBufferBit)); }
public void Clear(Color color) { Vector4 vector = color.ToEAGLColor(); GL11.ClearColor(vector.X, vector.Y, vector.Z, 1.0f); GL11.Clear((uint)All11.ColorBufferBit); }
public void DrawPrimitives(PrimitiveType primitiveType, int vertexStart, int primitiveCount) { var vd = VertexDeclaration.FromType(_vertexBuffer._type); VertexDeclaration.PrepareForUse(vd, IntPtr.Zero); GL11.DrawArrays(PrimitiveTypeGL11(primitiveType), vertexStart, getElementCountArray(primitiveType, primitiveCount)); }
internal void GenerateBuffer <T>() where T : struct { All11 bufferUsage = (_bufferUsage == BufferUsage.WriteOnly) ? All11.StaticDraw : All11.DynamicDraw; GL11.GenBuffers(1, out _bufferStore); GL11.BindBuffer(All11.ElementArrayBuffer, _bufferStore); GL11.BufferData <T>(All11.ElementArrayBuffer, (IntPtr)_size, (T[])_buffer, bufferUsage); }
void FlushVertexArray11(int start, int end) { // draw stuff if (start != end) { GL11.DrawElements(All11.Triangles, (end - start) / 2 * 3, All11.UnsignedShort, (IntPtr)((uint)_indexHandle.AddrOfPinnedObject() + (uint)(start / 2 * 3 * sizeof(short)))); } }
public static void GlCheckError(object caller) { var e = (int)OpenGL.GetError(); if (e != 0) { throw new Exception(string.Format("OpenGL error {0} from {1}", e, caller.ToString())); } }
private void handleButtons() { if (lightButton.TouchInside && !lp) // L Key Being Pressed Not Held? { lp = true; // lp Becomes TRUE light = !light; // Toggle Light TRUE/FALSE if (!light) // If Not Light { GL1.Disable(All1.Lighting); // Disable Lighting } else // Otherwise { GL1.Enable(All1.Lighting); // Enable Lighting } } if (!lightButton.TouchInside) // Has L Key Been Released? { lp = false; // If So, lp Becomes FALSE } if (filterButton.TouchInside && !fp) // Is F Key Being Pressed? { fp = true; // fp Becomes TRUE filter += 1; // filter Value Increases By One if (filter > 2) // Is Value Greater Than 2? { filter = 0; // If So, Set filter To 0 } } if (!filterButton.TouchInside) // Has F Key Been Released? { fp = false; // If So, fp Becomes FALSE } if (minusButton.TouchInside) // Is Page Up Being Pressed? { z -= 0.02f; // If So, Move Into The Screen } if (plusButton.TouchInside) // Is Page Down Being Pressed? { z += 0.02f; // If So, Move Towards The Viewer } if (upButton.TouchInside) // Is Up Arrow Being Pressed? { xspeed -= 0.01f; // If So, Decrease xspeed } if (downButton.TouchInside) // Is Down Arrow Being Pressed? { xspeed += 0.01f; // If So, Increase xspeed } if (rightButton.TouchInside) // Is Right Arrow Being Pressed? { yspeed += 0.01f; // If So, Increase yspeed } if (leftButton.TouchInside) // Is Left Arrow Being Pressed? { yspeed -= 0.01f; // If So, Decrease yspeed } }
public override void Dispose() { #if MONOMAC GL.GenBuffers(0, out _bufferStore); #else GL11.GenBuffers(0, ref _bufferStore); #endif base.Dispose(); }
public void DrawInRect(Rectangle rect) { float[] coordinates = { 0, _maxT, _maxS, _maxT, 0, 0, _maxS, 0 }; float[] vertices = { rect.Left, rect.Top, 0.0f, rect.Right, rect.Top, 0.0f, rect.Left, rect.Bottom, 0.0f, rect.Right, rect.Bottom, 0.0f }; GL11.BindTexture(ALL11.Texture2D, _name); GL11.VertexPointer(3, ALL11.Float, 0, vertices); GL11.TexCoordPointer(2, ALL11.Float, 0, coordinates); GL11.DrawArrays(ALL11.TriangleStrip, 0, 4); }
/// <summary> /// Actions after render /// - finish rotatation /// - pop position /// </summary> public virtual void AfterRender() { if (!Rotation.IsZero) { var c = Center; GL.Translate((float)+c.X, (float)+c.Y, (float)+c.Z); } GL.PopMatrix(); }
public void Present() { if (openGLESVersion == GLContextVersion.Gles2_0) { GL20.Flush(); } else { GL11.Flush(); } }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); MakeCurrent(); SetupView(); GL1.Clear((int)(All.ColorBufferBit | All.DepthBufferBit)); // Clear The Screen And The Depth Buffer GL1.LoadIdentity(); // Reset The Current Modelview Matrix GL1.Translate(-1.5f, 0.0f, -6.0f); // Move Left 1.5 Units And Into The Screen 6.0 GL1.Rotate(rtri, 0.0f, 1.0f, 0.0f); // Rotate The Triangle On The Y axis float [] triangleVertices = { 0.0f, 1.0f, 0.0f, // Top -1.0f, -1.0f, 0.0f, // Bottom Left 1.0f, -1.0f, 0.0f }; // Bottom Right float [] triangleColors = { 1.0f, 0.0f, 0.0f, 1.0f, // Set The Color To Red 0.0f, 1.0f, 0.0f, 1.0f, // Set The Color To Green 0.0f, 0.0f, 1.0f, 1.0f }; // Set The Color To Blue GL1.VertexPointer(3, All1.Float, 0, triangleVertices); GL1.EnableClientState(All1.VertexArray); GL1.ColorPointer(4, All1.Float, 0, triangleColors); GL1.EnableClientState(All1.ColorArray); GL.DrawArrays(All.Triangles, 0, 3); GL1.LoadIdentity(); // Reset The Current Modelview Matrix GL1.Translate(1.5f, 0.0f, -6.0f); // Move Right 1.5 Units And Into The Screen 6.0 GL1.Rotate(rquad, 1.0f, 0.0f, 0.0f); // Rotate The Quad On The X axis float [] squareVerticies = { -1.0f, 1.0f, 0.0f, // Top Left -1.0f, -1.0f, 0.0f, // Bottom Left 1.0f, 1.0f, 0.0f, // Top Right 1.0f, -1.0f, 0.0f }; // Bottom Right GL1.DisableClientState(All1.ColorArray); GL1.Color4(0.5f, 0.5f, 1.0f, 1.0f); // Set The Color To Blue One Time Only GL1.VertexPointer(3, All1.Float, 0, squareVerticies); GL1.EnableClientState(All1.VertexArray); GL.DrawArrays(All.TriangleStrip, 0, 4); SwapBuffers(); rtri += 2f; // Increase The Rotation Variable For The Triangle rquad -= 1.5f; // Decrease The Rotation Variable For The Quad }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); MakeCurrent(); // Replace the implementation of this method to do your own custom drawing. GL.ClearColor(0.5f, 0.5f, 0.5f, 1.0f); GL.Clear(ClearBufferMask.ColorBufferBit); if (ContextRenderingApi == EAGLRenderingAPI.OpenGLES2) { // Use shader program. GL.UseProgram(program); // Update uniform value. GL.Uniform1(uniforms [UNIFORM_TRANSLATE], transY); transY += 0.075f; // Update attribute values. GL.VertexAttribPointer(ATTRIB_VERTEX, 2, VertexAttribPointerType.Float, false, 0, squareVertices); GL.EnableVertexAttribArray(ATTRIB_VERTEX); GL.VertexAttribPointer(ATTRIB_COLOR, 4, VertexAttribPointerType.UnsignedByte, true, 0, squareColors); GL.EnableVertexAttribArray(ATTRIB_COLOR); // Validate program before drawing. This is a good check, but only really necessary in a debug build. #if DEBUG if (!ValidateProgram(program)) { Console.WriteLine("Failed to validate program {0:x}", program); return; } #endif } else { GL1.MatrixMode(All1.Projection); GL1.LoadIdentity(); GL1.MatrixMode(All1.Modelview); GL1.LoadIdentity(); GL1.Translate(0.0f, (float)Math.Sin(transY) / 2.0f, 0.0f); transY += 0.075f; GL1.VertexPointer(2, All1.Float, 0, squareVertices); GL1.EnableClientState(All1.VertexArray); GL1.ColorPointer(4, All1.UnsignedByte, 0, squareColors); GL1.EnableClientState(All1.ColorArray); } GL.DrawArrays(BeginMode.TriangleStrip, 0, 4); SwapBuffers(); }
public void DrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int vertexCount, short[] indexData, int indexOffset, int primitiveCount) where T : struct, IVertexType { if (indexOffset != 0) { throw new NotImplementedException(); } // Unbind the VBOs GL11.BindBuffer(ALL11.ArrayBuffer, 0); GL11.BindBuffer(ALL11.ElementArrayBuffer, 0); //Create VBO if not created already if (VboIdArray == 0) { GL11.GenBuffers(1, out VboIdArray); } if (VboIdElement == 0) { GL11.GenBuffers(1, out VboIdElement); } // Bind the VBO GL11.BindBuffer(ALL11.ArrayBuffer, VboIdArray); GL11.BindBuffer(ALL11.ElementArrayBuffer, VboIdElement); ////Clear previous data GL11.BufferData(ALL11.ArrayBuffer, (IntPtr)0, (IntPtr)null, ALL11.DynamicDraw); GL11.BufferData(ALL11.ElementArrayBuffer, (IntPtr)0, (IntPtr)null, ALL11.DynamicDraw); //Get VertexDeclaration var vd = VertexDeclaration.FromType(typeof(T)); //Pin data var handle = GCHandle.Alloc(vertexData, GCHandleType.Pinned); var handle2 = GCHandle.Alloc(vertexData, GCHandleType.Pinned); //Buffer data to VBO; This should use stream when we move to ES2.0 GL11.BufferData(ALL11.ArrayBuffer, (IntPtr)(vd.VertexStride * GetElementCountArray(primitiveType, primitiveCount)), new IntPtr(handle.AddrOfPinnedObject().ToInt64() + (vertexOffset * vd.VertexStride)), ALL11.DynamicDraw); GL11.BufferData(ALL11.ElementArrayBuffer, (IntPtr)(sizeof(short) * GetElementCountArray(primitiveType, primitiveCount)), indexData, ALL11.DynamicDraw); //Setup VertexDeclaration VertexDeclaration.PrepareForUse(vd); //Draw // note: GL supports only unsigned types, xna's method signature indicates signed. just ignore the sign bit. GL11.DrawElements(PrimitiveTypeGL11(primitiveType), GetElementCountArray(primitiveType, primitiveCount), ALL11.UnsignedShort, (IntPtr)(indexOffset * sizeof(short))); // Free resources GL11.BindBuffer(ALL11.ArrayBuffer, 0); GL11.BindBuffer(ALL11.ElementArrayBuffer, 0); handle.Free(); handle2.Free(); }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); MakeCurrent(); SetupView(); GL1.Clear((int)(All.ColorBufferBit | All.DepthBufferBit)); // Clear The Screen And The Depth Buffer GL1.LoadIdentity(); // Reset The Current Modelview Matrix SwapBuffers(); }
private void RenderPolygon(LineString lineString) { float lineWidth = 0; float[] points = ToOpenTK(lineString); GL.LineWidth(lineWidth); GL.Color4(0, 0, 0, 255); GL.EnableClientState(All.VertexArray); GL.VertexPointer(2, All.Float, 0, points); GL.DrawArrays(All.LineLoop, 0, points.Length / 2); GL.DisableClientState(All.VertexArray); }
public void DrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int vertexCount, uint[] indexData, int indexOffset, int primitiveCount) where T : struct, IVertexType { //////////////////////////// //This has not been tested// //////////////////////////// // Unbind the VBOs GL11.BindBuffer(ALL11.ArrayBuffer, 0); GL11.BindBuffer(ALL11.ElementArrayBuffer, 0); //Create VBO if not created already if (VboIdArray == 0) { GL11.GenBuffers(1, out VboIdArray); } if (VboIdElement == 0) { GL11.GenBuffers(1, out VboIdElement); } // Bind the VBO GL11.BindBuffer(ALL11.ArrayBuffer, VboIdArray); GL11.BindBuffer(ALL11.ElementArrayBuffer, VboIdElement); ////Clear previous data GL11.BufferData(ALL11.ArrayBuffer, (IntPtr)0, (IntPtr)null, ALL11.DynamicDraw); GL11.BufferData(ALL11.ElementArrayBuffer, (IntPtr)0, (IntPtr)null, ALL11.DynamicDraw); //Get VertexDeclaration var vd = VertexDeclaration.FromType(typeof(T)); //Pin data var handle = GCHandle.Alloc(vertexData, GCHandleType.Pinned); var handle2 = GCHandle.Alloc(vertexData, GCHandleType.Pinned); //Buffer data to VBO; This should use stream when we move to ES2.0 GL11.BufferData(ALL11.ArrayBuffer, (IntPtr)(vd.VertexStride * GetElementCountArray(primitiveType, primitiveCount)), new IntPtr(handle.AddrOfPinnedObject().ToInt64() + (vertexOffset * vd.VertexStride)), ALL11.DynamicDraw); GL11.BufferData(ALL11.ElementArrayBuffer, (IntPtr)(sizeof(uint) * GetElementCountArray(primitiveType, primitiveCount)), indexData, ALL11.DynamicDraw); //Setup VertexDeclaration VertexDeclaration.PrepareForUse(vd); //Draw GL11.DrawElements(PrimitiveTypeGL11(primitiveType), GetElementCountArray(primitiveType, primitiveCount), ALL11.UnsignedInt248Oes, (IntPtr)(indexOffset * sizeof(uint))); // Free resources GL11.BindBuffer(ALL11.ArrayBuffer, 0); GL11.BindBuffer(ALL11.ElementArrayBuffer, 0); handle.Free(); handle2.Free(); }
internal void GenerateBuffer <T>() where T : struct { #if MONOMAC BufferUsageHint bufferUsage = (_bufferUsage == BufferUsage.WriteOnly) ? BufferUsageHint.StaticDraw : BufferUsageHint.DynamicDraw; GL.GenBuffers(1, out _bufferStore); GL.BindBuffer(BufferTarget.ElementArrayBuffer, _bufferStore); GL.BufferData <T> (BufferTarget.ElementArrayBuffer, (IntPtr)_size, (T[])_buffer, bufferUsage); #else var bufferUsage = (_bufferUsage == BufferUsage.WriteOnly) ? All11.StaticDraw : All11.DynamicDraw; GL11.GenBuffers(1, ref _bufferStore); GL11.BindBuffer(All11.ElementArrayBuffer, _bufferStore); GL11.BufferData <T>(All11.ElementArrayBuffer, (IntPtr)_size, (T[])_buffer, bufferUsage); #endif }
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numbVertices, int startIndex, int primitiveCount) { if (minVertexIndex > 0 || baseVertex > 0) { throw new NotImplementedException("baseVertex > 0 and minVertexIndex > 0 are not supported"); } var vd = VertexDeclaration.FromType(_vertexBuffer._type); // Hmm, can the pointer here be changed with baseVertex? VertexDeclaration.PrepareForUse(vd, IntPtr.Zero); GL11.DrawElements(PrimitiveTypeGL11(primitiveType), _indexBuffer._count, All11.UnsignedShort, new IntPtr(startIndex)); }