public OpenGLCubemapTexture(
            IntPtr pixelsFront,
            IntPtr pixelsBack,
            IntPtr pixelsLeft,
            IntPtr pixelsRight,
            IntPtr pixelsTop,
            IntPtr pixelsBottom,
            int width,
            int height,
            PixelFormat format)
            : base(TextureTarget.TextureCubeMap, width, height)
        {
            _internalFormat = OpenGLFormats.MapPixelInternalFormat(format);
            _format         = OpenGLFormats.MapPixelFormat(format);
            _type           = OpenGLFormats.MapPixelType(format);

            Bind();
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge);

            SetFacePixels(0, pixelsRight);
            SetFacePixels(1, pixelsLeft);
            SetFacePixels(2, pixelsTop);
            SetFacePixels(3, pixelsBottom);
            SetFacePixels(4, pixelsBack);
            SetFacePixels(5, pixelsFront);
        }
        public void SetIndices(IntPtr indices, IndexFormat format, int count, int elementOffset)
        {
            int elementSizeInBytes = format == IndexFormat.UInt16 ? sizeof(ushort) : sizeof(uint);

            SetData(indices, count * elementSizeInBytes, elementOffset * elementSizeInBytes);
            ElementsType = OpenGLFormats.MapIndexFormat(format);
        }
        public override DeviceTexture2D CreateTexture(
            int mipLevels,
            int width,
            int height,
            PixelFormat format,
            DeviceTextureCreateOptions createOptions)
        {
            OpenTK.Graphics.OpenGL.PixelFormat pixelFormat = OpenGLFormats.MapPixelFormat(format);
            PixelInternalFormat pixelInternalFormat        = OpenGLFormats.MapPixelInternalFormat(format);

            if (createOptions == DeviceTextureCreateOptions.DepthStencil)
            {
                if (format != PixelFormat.R16_UInt)
                {
                    throw new NotImplementedException("R16_UInt is the only supported depth texture format.");
                }

                pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.DepthComponent;
                pixelInternalFormat = PixelInternalFormat.DepthComponent16;
            }

            return(new OpenGLTexture2D(
                       mipLevels,
                       width,
                       height,
                       format,
                       pixelInternalFormat,
                       pixelFormat,
                       OpenGLFormats.MapPixelType(format)));
        }
Example #4
0
        public void Apply()
        {
            if (CullMode == FaceCullingMode.None)
            {
                GL.Disable(EnableCap.CullFace);
            }
            else
            {
                GL.Enable(EnableCap.CullFace);
                GL.CullFace(OpenGLFormats.ConvertCullMode(CullMode));
            }

            GL.PolygonMode(MaterialFace.FrontAndBack, OpenGLFormats.ConvertFillMode(FillMode));

            if (IsScissorTestEnabled)
            {
            }
            else
            {
                GL.Disable(EnableCap.ScissorTest);
            }

            if (IsDepthClipEnabled)
            {
                GL.Disable(EnableCap.DepthClamp);
            }
            else
            {
                GL.Enable(EnableCap.DepthClamp);
            }
        }
Example #5
0
        public void SetIndices <T>(T[] indices, IndexFormat format, int stride, int elementOffset) where T : struct
        {
            int elementSizeInBytes = Unsafe.SizeOf <T>();

            SetData(indices, elementSizeInBytes * indices.Length, elementOffset * elementSizeInBytes);
            ElementsType = OpenGLFormats.MapIndexFormat(format);
        }
Example #6
0
            public unsafe InternalSamplerState(
                SamplerAddressMode addressU,
                SamplerAddressMode addressV,
                SamplerAddressMode addressW,
                SamplerFilter filter,
                int maxAnisotropy,
                RgbaFloat borderColor,
                DepthComparison comparison,
                int minLod,
                int maxLod,
                int lodBias,
                bool mip)
            {
                _samplerID = GL.GenSampler();

                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureWrapR, (int)OpenGLFormats.VeldridToGLTextureWrapMode(addressU));
                Utilities.CheckLastGLError();
                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureWrapS, (int)OpenGLFormats.VeldridToGLTextureWrapMode(addressV));
                Utilities.CheckLastGLError();
                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureWrapT, (int)OpenGLFormats.VeldridToGLTextureWrapMode(addressW));
                Utilities.CheckLastGLError();

                if (addressU == SamplerAddressMode.Border || addressV == SamplerAddressMode.Border || addressW == SamplerAddressMode.Border)
                {
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureBorderColor, (float *)&borderColor);
                    Utilities.CheckLastGLError();
                }

                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMinLod, (float)minLod);
                Utilities.CheckLastGLError();
                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMaxLod, (float)maxLod);
                Utilities.CheckLastGLError();
                GL.SamplerParameter(_samplerID, SamplerParameterName.TextureLodBias, (float)lodBias);
                Utilities.CheckLastGLError();

                if (filter == SamplerFilter.Anisotropic || filter == SamplerFilter.ComparisonAnisotropic)
                {
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMaxAnisotropyExt, (float)maxAnisotropy);
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMinFilter, mip ? (int)TextureMinFilter.LinearMipmapLinear : (int)TextureMinFilter.Linear);
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                    Utilities.CheckLastGLError();
                }
                else
                {
                    OpenGLFormats.VeldridToGLTextureMinMagFilter(filter, mip, out TextureMinFilter min, out TextureMagFilter mag);
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMinFilter, (int)min);
                    Utilities.CheckLastGLError();
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMagFilter, (int)mag);
                    Utilities.CheckLastGLError();
                }

                if (s_comparisonFilters.Contains(filter))
                {
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureCompareMode, (int)TextureCompareMode.CompareRefToTexture);
                    Utilities.CheckLastGLError();
                    GL.SamplerParameter(_samplerID, SamplerParameterName.TextureCompareFunc, (int)OpenGLFormats.ConvertDepthComparison(comparison));
                    Utilities.CheckLastGLError();
                }
            }
        public override void DrawIndexedPrimitives(int count, int startingIndex, int startingVertex)
        {
            PreDrawCommand();
            var elementsType = ((OpenGLIndexBuffer)IndexBuffer).ElementsType;
            int indexSize    = OpenGLFormats.GetIndexFormatSize(elementsType);

            GL.DrawElementsBaseVertex(_primitiveType, count, elementsType, new IntPtr(startingIndex * indexSize), startingVertex);
        }
        public override void DrawInstancedPrimitives(int indexCount, int instanceCount, int startingIndex)
        {
            PreDrawCommand();
            var elementsType = ((OpenGLIndexBuffer)IndexBuffer).ElementsType;
            int indexSize    = OpenGLFormats.GetIndexFormatSize(elementsType);

            GL.DrawElementsInstanced(_primitiveType, indexCount, elementsType, new IntPtr(startingIndex * indexSize), instanceCount);
        }
Example #9
0
        public OpenGLShader(Stream dataStream, OpenTK.Graphics.OpenGL.ShaderType type)
        {
            Type = OpenGLFormats.GLToVeldridShaderType(type);
            string source;

            using (var sr = new StreamReader(dataStream))
            {
                source = sr.ReadToEnd();
            }

            LoadShader(source, type);
        }
Example #10
0
 public void Apply()
 {
     if (IsDepthEnabled)
     {
         GL.Enable(EnableCap.DepthTest);
         GL.DepthFunc(OpenGLFormats.ConvertDepthComparison(DepthComparison));
         GL.DepthMask(true);
     }
     else
     {
         GL.Disable(EnableCap.DepthTest);
     }
 }
Example #11
0
 public unsafe void Apply()
 {
     if (!IsBlendEnabled)
     {
         GL.Disable(EnableCap.Blend);
     }
     else
     {
         GL.Enable(EnableCap.Blend);
         GL.BlendFuncSeparate(
             OpenGLFormats.ConvertBlendSrc(SourceColorBlend), OpenGLFormats.ConvertBlendDest(DestinationColorBlend),
             OpenGLFormats.ConvertBlendSrc(SourceAlphaBlend), OpenGLFormats.ConvertBlendDest(DestinationAlphaBlend));
         GL.BlendEquationSeparate(
             OpenGLFormats.ConvertBlendEquation(ColorBlendFunction),
             OpenGLFormats.ConvertBlendEquation(AlphaBlendFunction));
     }
 }
Example #12
0
        public static OpenGLTexture2D Create <T>(T[] pixelData, int width, int height, int pixelSizeInBytes, PixelFormat format) where T : struct
        {
            var internalFormat = OpenGLFormats.MapPixelInternalFormat(format);
            var pixelFormat    = OpenGLFormats.MapPixelFormat(format);
            var pixelType      = OpenGLFormats.MapPixelType(format);

            OpenGLTexture2D texture = new OpenGLTexture2D(
                width,
                height,
                format,
                internalFormat,
                pixelFormat,
                pixelType);

            texture.Bind();
            GL.TexImage2D(TextureTarget.Texture2D, 0, internalFormat, width, height, 0, pixelFormat, pixelType, pixelData);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            return(texture);
        }
Example #13
0
 public void SetIndices(IntPtr indices, IndexFormat format, int elementSizeInBytes, int count, int elementOffset)
 {
     SetData(indices, count * elementSizeInBytes, elementOffset * elementSizeInBytes);
     ElementsType = OpenGLFormats.MapIndexFormat(format);
 }
Example #14
0
 public OpenGLTexture2D(int width, int height, PixelFormat format, IntPtr pixelData)
     : this(width, height, format, OpenGLFormats.MapPixelInternalFormat(format), OpenGLFormats.MapPixelFormat(format), OpenGLFormats.MapPixelType(format), pixelData)
 {
 }
 public OpenGLTexture2D(int width, int height, PixelFormat format, IntPtr pixelData)
     : this(1, width, height, format, OpenGLFormats.MapPixelInternalFormat(format), OpenGLFormats.MapPixelFormat(format), OpenGLFormats.MapPixelType(format))
 {
     SetTextureData(1, 0, 0, width, height, pixelData, FormatHelpers.GetPixelSizeInBytes(format) * width * height);
 }
        public override Shader CreateShader(ShaderStages type, CompiledShaderCode compiledShaderCode)
        {
            OpenGLCompiledShaderCode glShaderSource = (OpenGLCompiledShaderCode)compiledShaderCode;

            return(new OpenGLShader(glShaderSource.ShaderCode, OpenGLFormats.VeldridToGLShaderType(type)));
        }
 public override IndexBuffer CreateIndexBuffer(int sizeInBytes, bool isDynamic, IndexFormat format)
 {
     return(new OpenGLIndexBuffer(isDynamic, OpenGLFormats.MapIndexFormat(format)));
 }
Example #18
0
 public override Shader CreateShader(ShaderType type, string shaderCode, string name)
 {
     return(new OpenGLShader(shaderCode, OpenGLFormats.VeldridToGLShaderType(type)));
 }
 protected override void PlatformSetPrimitiveTopology(PrimitiveTopology primitiveTopology)
 {
     _primitiveType = OpenGLFormats.ConvertPrimitiveTopology(primitiveTopology);
 }