コード例 #1
0
ファイル: Cubemap.cs プロジェクト: luxgile/Entygine
        protected override void CalculatePackedData()
        {
            packedData = new byte[6][];

            Ogl.BindTexture(TextureTarget.TextureCubeMap, handle);

            for (int i = 0; i < facesPixels.Length; i++)
            {
                Rgba32[] pixels = facesPixels[i];
                packedData[i] = new byte[pixels.Length * 4];
                for (int p = 0, packedIndex = 0; p < pixels.Length; p++)
                {
                    packedData[i][packedIndex++] = pixels[p].R;
                    packedData[i][packedIndex++] = pixels[p].G;
                    packedData[i][packedIndex++] = pixels[p].B;
                    packedData[i][packedIndex++] = pixels[p].A;
                }

                GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX + i, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, packedData[i]);
            }

            Ogl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, TextureMinFilter.Linear);
            Ogl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, TextureMagFilter.Linear);
            Ogl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, TextureWrapMode.ClampToEdge);
            Ogl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, TextureWrapMode.ClampToEdge);
            Ogl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, TextureWrapMode.ClampToEdge);
            //GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap);
        }
コード例 #2
0
ファイル: Mesh.cs プロジェクト: luxgile/Entygine
        private void BindMaterial(Material mat)
        {
            Ogl.BindVertexArray(vertexArrayHandle);

            Ogl.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
            Ogl.BufferData(BufferTarget.ArrayBuffer, packedData.Length * sizeof(float), packedData, BufferUsageHint.StaticDraw);

            Ogl.BindBuffer(BufferTarget.ElementArrayBuffer, trisBuffer);
            Ogl.BufferData(BufferTarget.ElementArrayBuffer, tris.Length * sizeof(uint), tris, BufferUsageHint.StaticDraw);

            VertexBufferLayout[] layouts = GetVertexLayout();
            int layoutSize   = GetVertexLayoutSize();
            int layoutOffset = 0;

            for (int l = 0; l < layouts.Length; l++)
            {
                VertexBufferLayout layout = layouts[l];
                int location = layout.Attribute.GetAttributeLocation(mat);

                if (location == -1)
                {
                    continue;
                }

                int stride = layoutSize * layout.Format.ByteSize();
                Ogl.EnableVertexAttribArray(location);
                Ogl.VertexAttribPointer(location, layout.Size, layout.Format.ToOpenGlAttribType(), false, stride, layoutOffset);

                layoutOffset += layout.Size * layout.Format.ByteSize();
            }

            Ogl.BindVertexArray(0);
        }
コード例 #3
0
ファイル: Framebuffer.cs プロジェクト: luxgile/Entygine
        public void ChangeSize(Vec2i size)
        {
            Size = size;

            if (colorBuffer != -1)
            {
                TextureTarget textureTarget = multisampledColor ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;
                Ogl.BindTexture(textureTarget, colorBuffer);
                if (multisampledColor)
                {
                    Ogl.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, 4, PixelInternalFormat.Rgb, Size.x, Size.y, true);
                }
                else
                {
                    Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, Size.x, Size.y, 0, PixelFormat.Rgb, PixelType.UnsignedByte, null);
                }
            }

            if (depthBuffer != -1)
            {
                TextureTarget textureTarget = multisampledDepth ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;
                Ogl.BindTexture(textureTarget, depthBuffer);
                if (multisampledDepth)
                {
                    Ogl.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, 4, PixelInternalFormat.DepthComponent, Size.x, Size.y, true);
                }
                else
                {
                    Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent, Size.x, Size.y, 0, PixelFormat.DepthComponent, PixelType.Float, null);
                }
            }
        }
コード例 #4
0
        public void CompileShader()
        {
            int vertexShader   = CompileShader(ShaderType.VertexShader, vertexProgram);
            int fragmentShader = CompileShader(ShaderType.FragmentShader, fragmentProgram);

            handle = Ogl.CreateProgram(Name);
            Ogl.AttachShader(handle, vertexShader);
            Ogl.AttachShader(handle, fragmentShader);
            Ogl.LinkProgram(handle);

            string infoLog = Ogl.GetProgramInfoLog(handle);

            if (!string.IsNullOrEmpty(infoLog))
            {
                Console.WriteLine(infoLog);
            }

            Ogl.DetachShader(handle, vertexShader);
            Ogl.DetachShader(handle, fragmentShader);
            Ogl.DeleteShader(vertexShader);
            Ogl.DeleteShader(fragmentShader);

            IsCompiled = true;
            ShadersLoaded++;
        }
コード例 #5
0
        public void SetSize(Vec2i size)
        {
            width  = size.x;
            height = size.y;

            Ogl.BindTexture(TextureTarget.Texture2D, handle);
            Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, packedData);
            Ogl.GenerateMipmap(GenerateMipmapTarget.Texture2D);
        }
コード例 #6
0
ファイル: Font.cs プロジェクト: luxgile/Entygine
        private void ClearCharacters()
        {
            foreach (KeyValuePair <char, FontCharacter> character in characters)
            {
                Ogl.DeleteTexture(character.Value.TextureID);
            }

            characters.Clear();
        }
コード例 #7
0
ファイル: Cubemap.cs プロジェクト: luxgile/Entygine
        public Cubemap(string[] paths)
        {
            if (paths.Length != 6)
            {
                throw new ArgumentException("Cubemap needs 6 path for every texture");
            }

            this.handle = Ogl.GenTexture("Cubemap");

            LoadFromPath(paths);
        }
コード例 #8
0
        public void UseTexture(TextureUnit unit)
        {
            if (HasChanged)
            {
                HasChanged = false;
                CalculatePackedData();
            }

            Ogl.ActiveTexture(unit);
            Ogl.BindTexture(TextureType, Handle);
        }
コード例 #9
0
ファイル: Mesh.cs プロジェクト: luxgile/Entygine
        public Mesh()
        {
            vertexArrayHandle = Ogl.GenVertexArray("Mesh");
            vertexBuffer      = Ogl.GenBuffer("Mesh - Vertex");
            trisBuffer        = Ogl.GenBuffer("Mesh - Tris");

            layouts = new[]
            {
                new VertexBufferLayout(VertexAttribute.Position, VertexAttributeFormat.Float32, 3),
                new VertexBufferLayout(VertexAttribute.Uv0, VertexAttributeFormat.Float32, 2),
                new VertexBufferLayout(VertexAttribute.Normal, VertexAttributeFormat.Float32, 3),
            };
        }
コード例 #10
0
ファイル: Font.cs プロジェクト: luxgile/Entygine
        private int LoadBitmapOnChar(int width, int height, IntPtr buffer)
        {
            int textureID = Ogl.GenTexture("Char");

            Ogl.BindTexture(TextureTarget.Texture2D, textureID);
            Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R8, width, height
                           , 0, PixelFormat.Red, PixelType.UnsignedByte, buffer);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, TextureWrapMode.ClampToEdge);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, TextureWrapMode.ClampToEdge);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureMinFilter.Linear);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureMagFilter.Linear);
            return(textureID);
        }
コード例 #11
0
        public Texture2D(string path, string name)
        {
            this.handle = Ogl.GenTexture(name);

            Ogl.BindTexture(TextureTarget.Texture2D, handle);
            Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, null);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureMinFilter.Linear);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureMagFilter.Linear);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, TextureWrapMode.Repeat);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, TextureWrapMode.Repeat);

            LoadFromPath(path);
        }
コード例 #12
0
ファイル: DepthTexture.cs プロジェクト: luxgile/Entygine
        public void SetSize(Vec2i resolution)
        {
            width  = resolution.x;
            height = resolution.y;

            Ogl.BindTexture(TextureTarget.Texture2D, handle);
            Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent, width, height, 0, PixelFormat.DepthComponent, PixelType.Float, null);

            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureMinFilter.Nearest);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureMagFilter.Nearest);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, TextureWrapMode.ClampToBorder);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, TextureWrapMode.ClampToBorder);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, new float[] { 1, 1, 1, 1 });
        }
コード例 #13
0
        protected override void CalculatePackedData()
        {
            packedData = new byte[pixels.Length * 4];
            for (int i = 0, packedIndex = 0; i < pixels.Length; i++)
            {
                packedData[packedIndex++] = pixels[i].R;
                packedData[packedIndex++] = pixels[i].G;
                packedData[packedIndex++] = pixels[i].B;
                packedData[packedIndex++] = pixels[i].A;
            }

            Ogl.BindTexture(TextureTarget.Texture2D, handle);
            Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, packedData);
            Ogl.GenerateMipmap(GenerateMipmapTarget.Texture2D);
        }
コード例 #14
0
ファイル: DepthTexture.cs プロジェクト: luxgile/Entygine
        public DepthTexture(int width, int height, string name)
        {
            handle = Ogl.GenTexture(name);

            Ogl.BindTexture(TextureTarget.Texture2D, handle);
            Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent, width, height, 0, PixelFormat.DepthComponent, PixelType.Float, null);

            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureMinFilter.Nearest);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureMagFilter.Nearest);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, TextureWrapMode.ClampToBorder);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, TextureWrapMode.ClampToBorder);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, new float[] { 1, 1, 1, 1 });

            this.width  = width;
            this.height = height;
        }
コード例 #15
0
        private int CompileShader(ShaderType type, string shaderSource)
        {
            int shader = Ogl.CreateShader(type, $" {type} - {Name}");

            Ogl.ShaderSource(shader, shaderSource);

            Ogl.CompileShader(shader);
            string infoLog = Ogl.GetShaderInfoLog(shader);

            if (!string.IsNullOrEmpty(infoLog))
            {
                Console.WriteLine(infoLog);
            }

            return(shader);
        }
コード例 #16
0
        public Texture2D(int width, int height, string name)
        {
            handle = Ogl.GenTexture(name);

            Ogl.BindTexture(TextureTarget.Texture2D, handle);
            Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, null);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureMinFilter.Linear);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureMagFilter.Linear);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, TextureWrapMode.Repeat);
            Ogl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, TextureWrapMode.Repeat);

            this.width  = width;
            this.height = height;

            pixels     = new Rgba32[width * height];
            packedData = new byte[pixels.Length * 4];
        }
コード例 #17
0
ファイル: Framebuffer.cs プロジェクト: luxgile/Entygine
        public void AddDepthBuffer(bool multisampling)
        {
            if (depthBuffer != -1)
            {
                DevConsole.Log(LogType.Error, "Framebuffer already has depth buffer");
                return;
            }

            multisampledDepth = multisampling;
            TextureTarget textureTarget = multisampling ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;

            depthBuffer = Ogl.GenTexture($"{name} - Depth");

            Ogl.BindTexture(textureTarget, depthBuffer);

            if (multisampling)
            {
                Ogl.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, 4, PixelInternalFormat.DepthComponent, Size.x, Size.y, true);
            }
            else
            {
                Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent, Size.x, Size.y, 0, PixelFormat.DepthComponent, PixelType.Float, null);
                Ogl.TexParameter(textureTarget, TextureParameterName.TextureMinFilter, TextureMinFilter.Nearest);
                Ogl.TexParameter(textureTarget, TextureParameterName.TextureMagFilter, TextureMagFilter.Nearest);
                Ogl.TexParameter(textureTarget, TextureParameterName.TextureWrapS, TextureWrapMode.ClampToBorder);
                Ogl.TexParameter(textureTarget, TextureParameterName.TextureWrapT, TextureWrapMode.ClampToBorder);
                Ogl.TexParameter(textureTarget, TextureParameterName.TextureBorderColor, new float[] { 1, 1, 1, 1 });
            }


            Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, handle);
            Ogl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, textureTarget, depthBuffer, 0);

            var error = Ogl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (error != FramebufferErrorCode.FramebufferComplete)
            {
                DevConsole.Log(LogType.Warning, error);
            }

            Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
コード例 #18
0
ファイル: Framebuffer.cs プロジェクト: luxgile/Entygine
        public void AddColorBuffer(bool multisampling)
        {
            if (colorBuffer != -1)
            {
                DevConsole.Log(LogType.Error, "Framebuffer already has color buffer");
                return;
            }

            multisampledColor = multisampling;
            TextureTarget textureTarget = multisampling ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;

            colorBuffer = Ogl.GenTexture($"{name} - Color");

            Ogl.BindTexture(textureTarget, colorBuffer);
            if (multisampling)
            {
                Ogl.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, 4, PixelInternalFormat.Rgb, Size.x, Size.y, true);
            }
            else
            {
                Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, Size.x, Size.y, 0, PixelFormat.Rgb, PixelType.UnsignedByte, null);

                Ogl.TexParameter(textureTarget, TextureParameterName.TextureMinFilter, TextureMinFilter.Linear);
                Ogl.TexParameter(textureTarget, TextureParameterName.TextureMagFilter, TextureMagFilter.Linear);
                Ogl.TexParameter(textureTarget, TextureParameterName.TextureWrapS, TextureWrapMode.Repeat);
                Ogl.TexParameter(textureTarget, TextureParameterName.TextureWrapT, TextureWrapMode.Repeat);
            }


            Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, handle);
            Ogl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, textureTarget, colorBuffer, 0);

            var error = Ogl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (error != FramebufferErrorCode.FramebufferComplete)
            {
                DevConsole.Log(LogType.Warning, error);
            }

            Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
コード例 #19
0
ファイル: Font.cs プロジェクト: luxgile/Entygine
        private void UpdateTextures()
        {
            ClearCharacters();

            Ogl.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
            //For now we load the first 128 ASCII chars
            for (uint i = 0; i < 255; i++)
            {
                font.LoadChar(i, LoadFlags.Render, LoadTarget.Normal);

                int width    = font.Glyph.Bitmap.Width;
                int height   = font.Glyph.Bitmap.Rows;
                int bearingX = font.Glyph.BitmapLeft;
                int bearingY = font.Glyph.BitmapTop;

                int textureID = LoadBitmapOnChar(width, height, font.Glyph.Bitmap.Buffer);

                FontCharacter character = new FontCharacter(textureID, new Vec2i(width, height), new Vec2i(bearingX, bearingY)
                                                            , font.Glyph.Advance.X.Value);

                characters.Add((char)i, character);
            }
        }
コード例 #20
0
ファイル: GraphicsAPI.cs プロジェクト: luxgile/Entygine
 public static void DrawTriangles(int trisCount)
 {
     Ogl.DrawElements(PrimitiveType.Triangles, trisCount, DrawElementsType.UnsignedInt, 0);
 }
コード例 #21
0
ファイル: GraphicsAPI.cs プロジェクト: luxgile/Entygine
        public static void FreeMeshMaterial(Mesh mesh, Material mat)
        {
            mat.FreeMaterial();

            Ogl.BindVertexArray(0);
        }
コード例 #22
0
ファイル: DirectionalLight.cs プロジェクト: luxgile/Entygine
 public override void BindShadowMap()
 {
     Ogl.Viewport(0, 0, TEXTURE_RES, TEXTURE_RES);
     Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, finalFBO.Handle);
 }
コード例 #23
0
ファイル: Framebuffer.cs プロジェクト: luxgile/Entygine
 public void Bind()
 {
     Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, handle);
     Ogl.DrawBuffer(DrawBufferMode.ColorAttachment0);
 }
コード例 #24
0
ファイル: Framebuffer.cs プロジェクト: luxgile/Entygine
 public void Unbind()
 {
     Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
 }
コード例 #25
0
ファイル: Framebuffer.cs プロジェクト: luxgile/Entygine
 public static void Blit(Framebuffer read, Framebuffer write, ClearBufferMask mask)
 {
     Ogl.BindFramebuffer(FramebufferTarget.ReadFramebuffer, read.handle);
     Ogl.BindFramebuffer(FramebufferTarget.DrawFramebuffer, write.handle);
     Ogl.BlitFramebuffer(0, 0, read.Size.x, read.Size.y, 0, 0, write.Size.x, write.Size.y, mask, BlitFramebufferFilter.Nearest);
 }
コード例 #26
0
ファイル: DirectionalLight.cs プロジェクト: luxgile/Entygine
 public override void UnbindShadowMap()
 {
     //Framebuffer.Blit(multisampledFBO, finalFBO, ClearBufferMask.DepthBufferBit);
     Ogl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
 }
コード例 #27
0
 public void SetRawData(IntPtr data)
 {
     Ogl.BindTexture(TextureTarget.Texture2D, handle);
     Ogl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, data);
     Ogl.GenerateMipmap(GenerateMipmapTarget.Texture2D);
 }
コード例 #28
0
ファイル: GraphicsAPI.cs プロジェクト: luxgile/Entygine
 public static void UseMeshMaterial(Mesh mesh, Material mat)
 {
     mat.UseMaterial();
     mesh.UpdateMeshData(mat);
     Ogl.BindVertexArray(mesh.GetVertexArrayHandle());
 }
コード例 #29
0
 public void FreeTexture()
 {
     Ogl.BindTexture(TextureType, 0);
 }
コード例 #30
0
ファイル: Framebuffer.cs プロジェクト: luxgile/Entygine
 public Framebuffer(Vec2i size, string name)
 {
     this.name = name;
     handle    = Ogl.GenFramebuffer(name);
     Size      = size;
 }