Example #1
0
        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);
        }
Example #2
0
        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();
        }
Example #3
0
        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
 }
Example #5
0
        public void DrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int vertexCount, int[] indexData, int indexOffset, int primitiveCount) where T : IVertexType
        {
            // Unbind the VBOs
            GL11.BindBuffer(All11.ArrayBuffer, 0);
            GL11.BindBuffer(All11.ElementArrayBuffer, 0);

            var vd = VertexDeclaration.FromType(typeof(T));

            IntPtr arrayStart = GCHandle.Alloc(vertexData, GCHandleType.Pinned).AddrOfPinnedObject();

            if (vertexOffset > 0)
            {
                arrayStart = new IntPtr(arrayStart.ToInt32() + (vertexOffset * vd.VertexStride));
            }

            VertexDeclaration.PrepareForUse(vd, arrayStart);

            GL11.DrawArrays(PrimitiveTypeGL11(primitiveType), vertexOffset, getElementCountArray(primitiveType, primitiveCount));
        }
Example #6
0
        internal void GenerateBuffer <T>() where T : struct
        {
            var vd = VertexDeclaration.FromType(_type);

            _size = vd.VertexStride * ((T[])_buffer).Length;

                        #if MONOMAC
            BufferUsageHint bufferUsage = (_bufferUsage == BufferUsage.WriteOnly) ? BufferUsageHint.StaticDraw : BufferUsageHint.DynamicDraw;

            GL.GenBuffers(1, out _bufferStore);
            GL.BindBuffer(BufferTarget.ArrayBuffer, _bufferStore);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)_size, (T[])_buffer, bufferUsage);
                        #else
            var bufferUsage = (_bufferUsage == BufferUsage.WriteOnly) ? All11.StaticDraw : All11.DynamicDraw;

            GL11.GenBuffers(1, ref _bufferStore);
            GL11.BindBuffer(All11.ArrayBuffer, _bufferStore);
            GL11.BufferData(All11.ArrayBuffer, (IntPtr)_size, (T[])_buffer, bufferUsage);
                        #endif
        }
Example #7
0
        public void DrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount) where T : struct, IVertexType
        {
            // 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);
            }

            // Bind the VBO
            GL11.BindBuffer(ALL11.ArrayBuffer, VboIdArray);
            ////Clear previous data
            GL11.BufferData(ALL11.ArrayBuffer, (IntPtr)0, (IntPtr)null, ALL11.DynamicDraw);

            //Get VertexDeclaration
            var vd = VertexDeclaration.FromType(typeof(T));

            //Pin data
            var handle = 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)), vertexData, ALL11.DynamicDraw);

            //Setup VertexDeclaration
            VertexDeclaration.PrepareForUse(vd);

            //Draw
            GL11.DrawArrays(PrimitiveTypeGL11(primitiveType), vertexOffset, GetElementCountArray(primitiveType, primitiveCount));


            // Free resources
            GL11.BindBuffer(ALL11.ArrayBuffer, 0);
            GL11.BindBuffer(ALL11.ElementArrayBuffer, 0);
            handle.Free();
        }
Example #8
0
 private void SetIndexBuffer(IndexBuffer indexBuffer)
 {
     _indexBuffer = indexBuffer;
     GL11.BindBuffer(All11.ElementArrayBuffer, indexBuffer._bufferStore);
 }
Example #9
0
 public void SetVertexBuffer(VertexBuffer vertexBuffer)
 {
     _vertexBuffer = vertexBuffer;
     GL11.BindBuffer(All11.ArrayBuffer, vertexBuffer._bufferStore);
 }
Example #10
0
        public static bool arglSetupTextureGeometry(ARGL_CONTEXT_SETTINGS contextSettings)
        {
            float  ty_prev, tx, ty;
            float  y_prev, x, y;
            double x1, x2, y1, y2;
            float  xx1, xx2, yy1, yy2;
            int    i, j;
            int    vertexCount, t2count, v2count;
            float  imageSizeX, imageSizeY;
            float  zoom;

            // Delete previous geometry, unless this is our first time here.
            if (contextSettings.textureGeometryHasBeenSetup)
            {
                GL1.DeleteBuffers(1, ref contextSettings.t2bo);
                GL1.DeleteBuffers(1, ref contextSettings.v2bo);
                contextSettings.textureGeometryHasBeenSetup = false;
            }

            // Set up the geometry for the surface which we will texture upon.
            imageSizeX = (float)contextSettings.arParam.xsize;
            imageSizeY = (float)contextSettings.arParam.ysize;
            zoom       = contextSettings.zoom;
            if (contextSettings.disableDistortionCompensation)
            {
                vertexCount = 4;
            }
            else
            {
                vertexCount = 840;  // 20 rows of 2 x 21 vertices.
            }
            contextSettings.t2 = new float[2 * vertexCount];
            contextSettings.v2 = new float[2 * vertexCount];
            t2count            = v2count = 0;
            if (contextSettings.disableDistortionCompensation)
            {
                contextSettings.t2[t2count++] = 0.0f; // Top-left.
                contextSettings.t2[t2count++] = 0.0f;
                contextSettings.v2[v2count++] = 0.0f;
                contextSettings.v2[v2count++] = imageSizeY * zoom;
                contextSettings.t2[t2count++] = 0.0f; // Bottom-left.
                contextSettings.t2[t2count++] = imageSizeY / (float)contextSettings.textureSizeY;
                contextSettings.v2[v2count++] = 0.0f;
                contextSettings.v2[v2count++] = 0.0f;
                contextSettings.t2[t2count++] = imageSizeX / (float)contextSettings.textureSizeX; // Top-right.
                contextSettings.t2[t2count++] = 0.0f;
                contextSettings.v2[v2count++] = imageSizeX * zoom;
                contextSettings.v2[v2count++] = imageSizeY * zoom;
                contextSettings.t2[t2count++] = imageSizeX / (float)contextSettings.textureSizeX; // Bottom-right.
                contextSettings.t2[t2count++] = imageSizeY / (float)contextSettings.textureSizeY;
                contextSettings.v2[v2count++] = imageSizeX * zoom;
                contextSettings.v2[v2count++] = 0.0f;
            }
            else
            {
                y  = 0.0f;
                ty = 0.0f;
                for (j = 1; j <= 20; j++)      // Do 20 rows of triangle strips.
                {
                    y_prev  = y;
                    ty_prev = ty;
                    y       = imageSizeY * (float)j / 20.0f;
                    ty      = y / (float)contextSettings.textureSizeY;


                    for (i = 0; i <= 20; i++)   // 21 columns of triangle strip vertices, 2 vertices per column.
                    {
                        x  = imageSizeX * (float)i / 20.0f;
                        tx = x / (float)contextSettings.textureSizeX;

                        arParamObserv2Ideal(contextSettings.arParam.dist_factor, (double)x, (double)y_prev, out x1, out y1, contextSettings.arParam.dist_function_version);
                        arParamObserv2Ideal(contextSettings.arParam.dist_factor, (double)x, (double)y, out x2, out y2, contextSettings.arParam.dist_function_version);

                        xx1 = (float)x1 * zoom;
                        yy1 = (imageSizeY - (float)y1) * zoom;
                        xx2 = (float)x2 * zoom;
                        yy2 = (imageSizeY - (float)y2) * zoom;

                        contextSettings.t2[t2count++] = tx; // Top.
                        contextSettings.t2[t2count++] = ty_prev;
                        contextSettings.v2[v2count++] = xx1;
                        contextSettings.v2[v2count++] = yy1;
                        contextSettings.t2[t2count++] = tx; // Bottom.
                        contextSettings.t2[t2count++] = ty;
                        contextSettings.v2[v2count++] = xx2;
                        contextSettings.v2[v2count++] = yy2;
                    } // columns.
                }     // rows.
            }

            // Now setup VBOs.
            GL1.GenBuffers(1, out contextSettings.t2bo);
            GL1.GenBuffers(1, out contextSettings.v2bo);
            GL1.BindBuffer(All1.ArrayBuffer, contextSettings.t2bo);
            GL1.BufferData(All1.ArrayBuffer, new IntPtr((sizeof(float) * 2 * vertexCount)), contextSettings.t2, All1.StaticDraw);
            GL1.BindBuffer(All1.ArrayBuffer, contextSettings.v2bo);
            GL1.BufferData(All1.ArrayBuffer, new IntPtr((sizeof(float) * 2 * vertexCount)), contextSettings.v2, All1.StaticDraw);
            GL1.BindBuffer(All1.ArrayBuffer, 0);

            contextSettings.textureGeometryHasBeenSetup = true;
            return(true);
        }
Example #11
0
        static void arglDispImageStateful(ARGL_CONTEXT_SETTINGS contextSettings)
        {
            int texEnvModeSave;
            int i;

            if (contextSettings == null)
            {
                return;
            }
            if (contextSettings.textureObjectsHaveBeenSetup)
            {
                return;
            }
            if (contextSettings.textureGeometryHasBeenSetup)
            {
                return;
            }
            if (contextSettings.textureDataReady)
            {
                return;
            }

            GL1.ActiveTexture(All1.Texture0);

            GL1.MatrixMode(All1.Texture);
            GL1.LoadIdentity();
            GL1.MatrixMode(All1.Modelview);

            GL1.BindTexture(All1.Texture2D, contextSettings.texture);
            GL1.GetTexEnv(All1.TextureEnv, All1.TextureEnvMode, out texEnvModeSave); // Save GL texture environment mode.
            if (texEnvModeSave != (int)All1.Replace)
            {
                GL1.TexEnv(All1.TextureEnv, All1.TextureEnvMode, (int)All1.Replace);
            }
            GL1.Enable(All1.Texture2D);

            GL1.ClientActiveTexture(All1.Texture0);
            GL1.BindBuffer(All1.ArrayBuffer, contextSettings.t2bo);
            GL1.TexCoordPointer(2, All1.Float, 0, IntPtr.Zero);
            GL1.EnableClientState(All1.TextureCoordArray);

            GL1.BindBuffer(All1.ArrayBuffer, contextSettings.v2bo);
            GL1.VertexPointer(2, All1.Float, 0, IntPtr.Zero);
            GL1.EnableClientState(All1.VertexArray);
            GL1.DisableClientState(All1.NormalArray);

            if (contextSettings.disableDistortionCompensation)
            {
                GL1.DrawArrays(All1.TriangleStrip, 0, 4);
            }
            else
            {
                for (i = 0; i < 20; i++)
                {
                    GL1.DrawArrays(All1.TriangleStrip, i * 42, 42);
                }
            }

            GL1.BindBuffer(All1.ArrayBuffer, 0);
            GL1.DisableClientState(All1.VertexArray);
            GL1.DisableClientState(All1.TextureCoordArray);

            GL1.Disable(All1.Texture2D);
            if (texEnvModeSave != (int)All1.Replace)
            {
                GL1.TexEnv(All1.TextureEnv, All1.TextureEnvMode, texEnvModeSave);                                      // Restore GL texture environment mode.
            }
        }