public void Apply() { if (CullMode == FaceCullingMode.None) { GL.Disable(EnableCap.CullFace); Utilities.CheckLastGLES3Error(); } else { GL.Enable(EnableCap.CullFace); Utilities.CheckLastGLES3Error(); GL.CullFace(OpenGLESFormats.ConvertCullMode(CullMode)); Utilities.CheckLastGLES3Error(); } var mode = OpenGLESFormats.ConvertFillMode(FillMode); if (mode != PolygonMode.Fill) { throw new NotSupportedException(); } if (IsScissorTestEnabled) { } else { GL.Disable(EnableCap.ScissorTest); Utilities.CheckLastGLES3Error(); } // IsDepthClipEnabled is not really supported on OpenGL ES. }
public OpenGLESCubemapTexture( IntPtr pixelsFront, IntPtr pixelsBack, IntPtr pixelsLeft, IntPtr pixelsRight, IntPtr pixelsTop, IntPtr pixelsBottom, int width, int height, PixelFormat format) : base(TextureTarget.TextureCubeMap, width, height) { _texComponentCount = OpenGLESFormats.MapTextureComponentCount(format, false); _format = OpenGLESFormats.MapPixelFormat(format); _type = OpenGLESFormats.MapPixelType(format); Bind(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); Utilities.CheckLastGLES3Error(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMagFilter.Linear); Utilities.CheckLastGLES3Error(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); Utilities.CheckLastGLES3Error(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); Utilities.CheckLastGLES3Error(); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge); Utilities.CheckLastGLES3Error(); SetFacePixels(0, pixelsRight); SetFacePixels(1, pixelsLeft); SetFacePixels(2, pixelsTop); SetFacePixels(3, pixelsBottom); SetFacePixels(4, pixelsBack); SetFacePixels(5, pixelsFront); }
public OpenGLESTexture2D( int mipLevels, int width, int height, PixelFormat veldridFormat, OpenTK.Graphics.ES30.PixelFormat pixelFormat, PixelType pixelType) : base(TextureTarget.Texture2D, width, height) { MipLevels = mipLevels; _veldridFormat = veldridFormat; _pixelFormat = pixelFormat; _pixelType = pixelType; _texComponentCount = OpenGLESFormats.MapTextureComponentCount(veldridFormat, pixelFormat == OpenTK.Graphics.ES30.PixelFormat.DepthComponent); Bind(); for (int currentLevel = 0; currentLevel < mipLevels; currentLevel++) { // Set size, load empty data into texture GL.TexImage2D( TextureTarget2d.Texture2D, currentLevel, _texComponentCount, width, height, 0, // border _pixelFormat, _pixelType, IntPtr.Zero); Utilities.CheckLastGLES3Error(); width = Math.Max(1, width / 2); height = Math.Max(1, height / 2); } }
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 = OpenGLESFormats.MapIndexFormat(format); }
public override void DrawIndexedPrimitives(int count, int startingIndex, int startingVertex) { SetBaseVertexOffset(startingVertex); PreDrawCommand(); var elementsType = ((OpenGLESIndexBuffer)IndexBuffer).ElementsType; int indexSize = OpenGLESFormats.GetIndexFormatSize(elementsType); GL.DrawElements(_primitiveType, count, elementsType, new IntPtr(startingIndex * indexSize)); }
public override void DrawInstancedPrimitives(int indexCount, int instanceCount, int startingIndex) { SetBaseVertexOffset(0); PreDrawCommand(); var elementsType = ((OpenGLESIndexBuffer)IndexBuffer).ElementsType; int indexSize = OpenGLESFormats.GetIndexFormatSize(elementsType); GL.DrawElementsInstanced(_primitiveType, indexCount, elementsType, new IntPtr(startingIndex * indexSize), instanceCount); Utilities.CheckLastGLES3Error(); }
public void Apply() { if (IsDepthEnabled) { GL.Enable(EnableCap.DepthTest); Utilities.CheckLastGLES3Error(); GL.DepthFunc(OpenGLESFormats.ConvertDepthComparison(DepthComparison)); Utilities.CheckLastGLES3Error(); GL.DepthMask(true); Utilities.CheckLastGLES3Error(); } else { GL.Disable(EnableCap.DepthTest); Utilities.CheckLastGLES3Error(); } }
public unsafe void Apply() { if (!IsBlendEnabled) { GL.Disable(EnableCap.Blend); Utilities.CheckLastGLES3Error(); } else { GL.Enable(EnableCap.Blend); Utilities.CheckLastGLES3Error(); GL.BlendFuncSeparate( OpenGLESFormats.ConvertBlendSrc(SourceColorBlend), OpenGLESFormats.ConvertBlendDest(DestinationColorBlend), OpenGLESFormats.ConvertBlendSrc(SourceAlphaBlend), OpenGLESFormats.ConvertBlendDest(DestinationAlphaBlend)); GL.BlendEquationSeparate( OpenGLESFormats.ConvertBlendEquation(ColorBlendFunction), OpenGLESFormats.ConvertBlendEquation(AlphaBlendFunction)); GL.BlendColor(BlendFactor.R, BlendFactor.G, BlendFactor.B, BlendFactor.A); } }
public override DeviceTexture2D CreateTexture( int mipLevels, int width, int height, PixelFormat format, DeviceTextureCreateOptions createOptions) { int pixelSizeInBytes = FormatHelpers.GetPixelSizeInBytes(format); OpenTK.Graphics.ES30.PixelFormat pixelFormat = OpenGLESFormats.MapPixelFormat(format); if (createOptions == DeviceTextureCreateOptions.DepthStencil) { if (format != PixelFormat.R16_UInt && format != PixelFormat.R32_Float) { throw new NotImplementedException("The only supported depth texture formats are R16_UInt and R32_Float."); } pixelFormat = OpenTK.Graphics.ES30.PixelFormat.DepthComponent; } return(new OpenGLESTexture2D(mipLevels, width, height, format, pixelFormat, OpenGLESFormats.MapPixelType(format))); }
public OpenGLESTexture2D(int width, int height, PixelFormat format, IntPtr pixelData) : this(1, width, height, format, OpenGLESFormats.MapPixelFormat(format), OpenGLESFormats.MapPixelType(format)) { SetTextureData(1, 0, 0, width, height, pixelData, FormatHelpers.GetPixelSizeInBytes(format) * width * height); }
public override Shader CreateShader(ShaderStages type, CompiledShaderCode compiledShaderCode) { OpenGLESCompiledShaderCode glShaderSource = (OpenGLESCompiledShaderCode)compiledShaderCode; return(new OpenGLESShader(glShaderSource.ShaderCode, OpenGLESFormats.VeldridToGLShaderType(type))); }
public override IndexBuffer CreateIndexBuffer(int sizeInBytes, bool isDynamic, IndexFormat format) { return(new OpenGLESIndexBuffer(isDynamic, OpenGLESFormats.MapIndexFormat(format))); }
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)OpenGLESFormats.VeldridToGLTextureWrapMode(addressU)); Utilities.CheckLastGLError(); GL.SamplerParameter(_samplerID, SamplerParameterName.TextureWrapS, (int)OpenGLESFormats.VeldridToGLTextureWrapMode(addressV)); Utilities.CheckLastGLError(); GL.SamplerParameter(_samplerID, SamplerParameterName.TextureWrapT, (int)OpenGLESFormats.VeldridToGLTextureWrapMode(addressW)); Utilities.CheckLastGLError(); if (addressU == SamplerAddressMode.Border || addressV == SamplerAddressMode.Border || addressW == SamplerAddressMode.Border) { #pragma warning disable CS0618 // TextureBorderColor is not exposed on SamplerParameterName GL.SamplerParameter(_samplerID, All.TextureBorderColor, (float *)&borderColor); #pragma warning restore CS0618 Utilities.CheckLastGLError(); } GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMinLod, (float)minLod); Utilities.CheckLastGLError(); GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMaxLod, (float)maxLod); Utilities.CheckLastGLError(); if (filter == SamplerFilter.Anisotropic || filter == SamplerFilter.ComparisonAnisotropic) { #pragma warning disable CS0618 // TextureMaxAnisotropyExt is not exposed on SamplerParameterName GL.SamplerParameter(_samplerID, All.TextureMaxAnisotropyExt, (float)maxAnisotropy); #pragma warning restore CS0618 // Type or member is obsolete Utilities.CheckLastGLError(); GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMinFilter, mip ? (int)TextureMinFilter.LinearMipmapLinear : (int)TextureMinFilter.Linear); Utilities.CheckLastGLError(); GL.SamplerParameter(_samplerID, SamplerParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); Utilities.CheckLastGLError(); } else { OpenGLESFormats.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)All.CompareRefToTexture); Utilities.CheckLastGLError(); GL.SamplerParameter(_samplerID, SamplerParameterName.TextureCompareFunc, (int)OpenGLESFormats.ConvertDepthComparison(comparison)); Utilities.CheckLastGLError(); } }
protected override void PlatformSetPrimitiveTopology(PrimitiveTopology primitiveTopology) { _primitiveType = OpenGLESFormats.ConvertPrimitiveTopology(primitiveTopology); }