Esempio n. 1
0
        public static void UpdateTexture(int textureId, ColorMap image)
        {
            GL.BindTexture(TextureTarget.Texture2D, textureId);
            ShaderLibrary.PrintGlErrors("UpdateTexture bind");

            GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, image.Width, image.Height,
                             PixelFormat.Bgra, PixelType.UnsignedByte, image.RawPixels());
            ShaderLibrary.PrintGlErrors("UpdateTexture put data");

            int level = 1;

            foreach (var mipmap in makeMipmaps(image))
            {
                GL.TexSubImage2D(
                    TextureTarget.Texture2D, level, 0, 0, mipmap.Width, mipmap.Height,
                    PixelFormat.Bgra, PixelType.UnsignedByte, mipmap.RawPixels()
                    );
                ShaderLibrary.PrintGlErrors("CreateTexture put mipmap data level " + level);
                level++;
            }

            textureSizes[textureId] = new Vector2(image.Width, image.Height);
            GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);             //TODO(v0.9) make custom mipmap algorithm
            ShaderLibrary.PrintGlErrors("UpdateTexture generate mipmaps");
        }
        public VertexArray Generate(AGlProgram forProgram)
        {
            var vao = GL.GenVertexArray();

            GL.BindVertexArray(vao);

            var vbo = GL.GenBuffer();

            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(this.vertices.Count * sizeof(float)), this.vertices.ToArray(), BufferUsageHint.StaticDraw);
            forProgram.SetupAttributes();
            GL.BindVertexArray(0);
            ShaderLibrary.PrintGlErrors("Generate VAO");

            return(new VertexArray(vao, vbo, this.objectStarts, this.objectSizes));
        }
Esempio n. 3
0
        public static int CreateTexture(ColorMap image)
        {
            int textureId = GL.GenTexture();

            var maxLevel = (int)Math.Round(Math.Log(Math.Min(image.Width, image.Height), 2));

            ShaderLibrary.PrintGlErrors("CreateTexture generate ID");
            GL.BindTexture(TextureTarget.Texture2D, textureId);
            ShaderLibrary.PrintGlErrors("CreateTexture bind");
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.LinearMipmapLinear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, maxLevel);
            ShaderLibrary.PrintGlErrors("CreateTexture parameters");

            GL.TexImage2D(
                TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, image.Width, image.Height,
                0, PixelFormat.Bgra, PixelType.UnsignedByte, image.RawPixels()
                );
            ShaderLibrary.PrintGlErrors("CreateTexture put data");

            int level = 1;

            foreach (var mipmap in makeMipmaps(image))
            {
                GL.TexImage2D(
                    TextureTarget.Texture2D, level, PixelInternalFormat.Rgba, mipmap.Width, mipmap.Height,
                    0, PixelFormat.Bgra, PixelType.UnsignedByte, mipmap.RawPixels()
                    );
                ShaderLibrary.PrintGlErrors("CreateTexture put mipmap data level " + level);
                level++;
            }

            textureSizes[textureId] = new Vector2(image.Width, image.Height);

            return(textureId);
        }
Esempio n. 4
0
 public static void DeleteTexture(int textureId)
 {
     GL.DeleteTexture(textureId);
     ShaderLibrary.PrintGlErrors("DeleteTexture");
     textureSizes.Remove(textureId);
 }