Converted project to ^nullable enable.

This commit is contained in:
H. Utku Maden 2024-06-09 22:54:33 +03:00
parent 55e9d775cd
commit 1ccab1c85a
29 changed files with 241 additions and 247 deletions

@ -14,10 +14,10 @@ namespace Quik.OpenTK
private readonly List<OpenTKPort> _ports = new List<OpenTKPort>();
// These shall remain a sad nop for now.
public string Title { get; set; }
public QImage Icon { get; set; }
public string? Title { get; set; }
public QImage? Icon { get; set; } = null;
public event EventHandler EventRaised;
public event EventHandler? EventRaised;
public NativeWindowSettings DefaultSettings { get; set; } = NativeWindowSettings.Default;

@ -51,7 +51,7 @@ namespace Quik.OpenTK
public bool IsValid => !isDisposed;
public event EventHandler EventRaised;
public event EventHandler? EventRaised;
public OpenTKPort(NativeWindow window)
{

@ -2,8 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<LangVersion>7.3</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>

@ -28,7 +28,7 @@ namespace Quik.CommandMachine
private float _f4;
[FieldOffset(24)]
private object _object;
private object? _object = null;
public bool IsCommand => _type == FrameType.Command;
public bool IsInteger =>
@ -200,7 +200,7 @@ namespace Quik.CommandMachine
public T As<T>()
{
return (T)_object;
return (T)_object!;
}
public float GetF(int i)

@ -75,11 +75,11 @@ namespace Quik.Controls
cmd.PopStyle();
}
public event EventHandler StyleChanged;
public event EventHandler VisualsInvalidated;
public event EventHandler VisualsValidated;
public event EventHandler LayoutInvalidated;
public event EventHandler LayoutValidated;
public event EventHandler? StyleChanged;
public event EventHandler? VisualsInvalidated;
public event EventHandler? VisualsValidated;
public event EventHandler? LayoutInvalidated;
public event EventHandler? LayoutValidated;
protected virtual void OnStyleChanged(object sender, EventArgs ea)
{

@ -6,17 +6,16 @@ namespace Quik.Controls
{
public class Label : Control
{
public string Text { get; set; }
public QFont Font { get; set; }
public string Text { get; set; } = string.Empty;
public QFont? Font { get; set; }
public float TextSize { get; set; }
public bool AutoSize { get; set; } = true;
protected override void ValidateLayout()
{
if (AutoSize)
{
QVec2 size = Typesetter.MeasureHorizontal(Text, TextSize, Font);
QVec2 size = Typesetter.MeasureHorizontal(Text, TextSize, Font!);
Size = size;
}
}
@ -26,7 +25,7 @@ namespace Quik.Controls
float padding = Padding;
QVec2 origin = new QVec2(padding, padding);
cmd.TypesetHorizontalDirect(Text, origin, TextSize, Font);
cmd.TypesetHorizontalDirect(Text, origin, TextSize, Font!);
}
}
}

@ -11,8 +11,8 @@ namespace Quik.Controls
{
private QVec2 size;
public UIBase Parent { get; protected set; }
public string Id { get; set; }
public UIBase? Parent { get; protected set; }
public string? Id { get; set; }
public QRectangle Bounds
{
get => new QRectangle(Position + Size, Position);
@ -58,7 +58,7 @@ namespace Quik.Controls
public bool IsMaximumSizeSet => MaximumSize != new QVec2(-1, -1);
public bool IsMinimumSizeSet => MinimumSize != new QVec2(-1, -1);
public virtual void NotifyEvent(object sender, EventArgs args)
public virtual void NotifyEvent(object? sender, EventArgs args)
{
}
@ -80,7 +80,7 @@ namespace Quik.Controls
PaintEnd(cmd);
}
public event EventHandler<ResizedEventArgs> Resized;
public event EventHandler<ResizedEventArgs>? Resized;
public virtual void OnResized(object sender, ResizedEventArgs ea)
{

@ -39,7 +39,6 @@ namespace Quik.Media.Color
protected override void Dispose(bool disposing)
{
buffer = null;
if (handle.IsAllocated) handle.Free();
GC.SuppressFinalize(this);

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Quik.Media.Color;
namespace Quik.Media.Font
@ -20,7 +17,7 @@ namespace Quik.Media.Font
private readonly List<AtlasPage> atlases = new List<AtlasPage>();
private readonly Dictionary<int, FontAtlasGlyphInfo> glyphs = new Dictionary<int, FontAtlasGlyphInfo>();
private int index = 0;
private AtlasPage last = null;
private AtlasPage? last = null;
private bool isSdf = false;
private int expansion;
@ -31,7 +28,7 @@ namespace Quik.Media.Font
{
foreach (AtlasPage page in atlases)
{
(page.Image as QImageBuffer).SetSdf(value);
((QImageBuffer)page.Image).SetSdf(value);
}
isSdf = value;
}
@ -59,7 +56,7 @@ namespace Quik.Media.Font
AddPage();
}
last.PutGlyph(source, ref info);
last!.PutGlyph(source, ref info);
}
private void AddPage()
@ -73,7 +70,7 @@ namespace Quik.Media.Font
else
{
last = new AtlasPage(width, height, expansion);
(last.Image as QImageBuffer).SetSdf(IsSdf);
((QImageBuffer)last.Image).SetSdf(IsSdf);
atlases.Add(last);
}
}

@ -74,9 +74,9 @@ namespace Quik.Media.Font
return this == other;
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return (obj.GetType() == typeof(FontFace)) &&
return (obj?.GetType() == typeof(FontFace)) &&
this == (FontFace)obj;
}

@ -25,7 +25,7 @@ namespace Quik.Media
public void Get(int codepoint, float size, out FontGlyph glyph)
{
SizedFontCollection collection;
SizedFontCollection? collection;
if (!_atlasses.TryGetValue(size, out collection))
{
@ -102,11 +102,11 @@ namespace Quik.Media
public readonly struct FontGlyph
{
public readonly int CodePoint;
public readonly QImage Image;
public readonly QImage? Image;
public readonly QGlyphMetrics Metrics;
public readonly QRectangle UVs;
public FontGlyph(int codepoint, QImage image, in QGlyphMetrics metrics, in QRectangle uvs)
public FontGlyph(int codepoint, QImage? image, in QGlyphMetrics metrics, in QRectangle uvs)
{
CodePoint = codepoint;
Image = image;

@ -7,10 +7,10 @@ namespace Quik.OpenGL
{
private delegate void BufferDataProc(GLEnum target, int size, void* data, GLEnum usageHint);
private static GenObjectsProc _genBuffers;
private static GenObjectsProc _deleteBuffers;
private static BindSlottedProc _bindBuffer;
private static BufferDataProc _bufferData;
private static GenObjectsProc? _genBuffers;
private static GenObjectsProc? _deleteBuffers;
private static BindSlottedProc? _bindBuffer;
private static BufferDataProc? _bufferData;
private static void LoadBuffer()
{
@ -24,7 +24,7 @@ namespace Quik.OpenGL
public static void GenBuffers(int count, out int buffers)
{
fixed (int *ptr = &buffers)
_genBuffers(count, ptr);
_genBuffers!(count, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -41,7 +41,7 @@ namespace Quik.OpenGL
public static void DeleteBuffers(int count, ref int buffers)
{
fixed (int *ptr = &buffers)
_deleteBuffers(count, ptr);
_deleteBuffers!(count, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -53,19 +53,19 @@ namespace Quik.OpenGL
[MethodImpl(AggressiveInlining)]
public static void BindBuffer(GLEnum target, int buffer)
{
_bindBuffer(target, buffer);
_bindBuffer!(target, buffer);
}
[MethodImpl(AggressiveInlining)]
public static void BufferData(GLEnum target, int size, IntPtr data, GLEnum usageHint) =>
_bufferData(target, size, (void*)data, usageHint);
_bufferData!(target, size, (void*)data, usageHint);
[MethodImpl(AggressiveInlining)]
public static void BufferData<T>(GLEnum target, int size, ref T data, GLEnum usageHint)
where T : unmanaged
{
fixed (T* ptr = &data)
_bufferData(target, size, ptr, usageHint);
_bufferData!(target, size, ptr, usageHint);
}
[MethodImpl(AggressiveInlining)]

@ -16,16 +16,16 @@ namespace Quik.OpenGL
private delegate void DeleteProgramProc(int program);
private delegate int GetShaderLocationProc(int program, byte *name);
private static CreateProgramProc _createProgram;
private static UseProgramProc _useProgram;
private static AttachShaderProc _attachShader;
private static DetachShaderProc _detachShader;
private static LinkProgramProc _linkProgram;
private static GetProgramProc _getProgram;
private static GetProgramInfoLogProc _getProgramInfoLog;
private static DeleteProgramProc _deleteProgram;
private static GetShaderLocationProc _getUniformLocation;
private static GetShaderLocationProc _getAttribLocation;
private static CreateProgramProc? _createProgram;
private static UseProgramProc? _useProgram;
private static AttachShaderProc? _attachShader;
private static DetachShaderProc? _detachShader;
private static LinkProgramProc? _linkProgram;
private static GetProgramProc? _getProgram;
private static GetProgramInfoLogProc? _getProgramInfoLog;
private static DeleteProgramProc? _deleteProgram;
private static GetShaderLocationProc? _getUniformLocation;
private static GetShaderLocationProc? _getAttribLocation;
private static void LoadProgram()
{
@ -42,26 +42,26 @@ namespace Quik.OpenGL
}
[MethodImpl(AggressiveInlining)]
public static int CreateProgram() => _createProgram();
public static int CreateProgram() => _createProgram!();
[MethodImpl(AggressiveInlining)]
public static void UseProgram(int program) => _useProgram(program);
public static void UseProgram(int program) => _useProgram!(program);
[MethodImpl(AggressiveInlining)]
public static void AttachShader(int program, int shader) => _attachShader(program, shader);
public static void AttachShader(int program, int shader) => _attachShader!(program, shader);
[MethodImpl(AggressiveInlining)]
public static void DetachShader(int program, int shader) => _detachShader(program, shader);
public static void DetachShader(int program, int shader) => _detachShader!(program, shader);
[MethodImpl(AggressiveInlining)]
public static void LinkProgram(int program) => _linkProgram(program);
public static void LinkProgram(int program) => _linkProgram!(program);
[MethodImpl(AggressiveInlining)]
public static void GetProgram(int program, GLEnum pname, out int value)
{
value = default;
fixed (int* ptr = &value)
_getProgram(program, pname, ptr);
_getProgram!(program, pname, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -71,26 +71,26 @@ namespace Quik.OpenGL
byte[] infoLog = new byte[length];
fixed (byte *ptr = infoLog)
_getProgramInfoLog(program, length, &length, ptr);
_getProgramInfoLog!(program, length, &length, ptr);
return Encoding.UTF8.GetString(infoLog);
}
[MethodImpl(AggressiveInlining)]
public static void DeleteProgram(int program) => _deleteProgram(program);
public static void DeleteProgram(int program) => _deleteProgram!(program);
[MethodImpl(AggressiveInlining)]
public static int GetUniformLocation(int program, string name)
{
fixed(byte* ptr = Encoding.UTF8.GetBytes(name))
return _getUniformLocation(program, ptr);
return _getUniformLocation!(program, ptr);
}
[MethodImpl(AggressiveInlining)]
public static int GetAttribLocation(int program, string name)
{
fixed(byte* ptr = Encoding.UTF8.GetBytes(name))
return _getAttribLocation(program, ptr);
return _getAttribLocation!(program, ptr);
}
}
}

@ -15,12 +15,12 @@ namespace Quik.OpenGL
private delegate void GetShaderInfoLogProc(int shader, int maxLength, int* length, byte* infoLog);
private delegate void DeleteShaderProc(int id);
private static CreateShaderProc _createShader;
private static ShaderSourceProc _shaderSource;
private static CompileShaderProc _compileShader;
private static GetShaderProc _getShader;
private static GetShaderInfoLogProc _getShaderInfoLog;
private static DeleteShaderProc _deleteShader;
private static CreateShaderProc? _createShader;
private static ShaderSourceProc? _shaderSource;
private static CompileShaderProc? _compileShader;
private static GetShaderProc? _getShader;
private static GetShaderInfoLogProc? _getShaderInfoLog;
private static DeleteShaderProc? _deleteShader;
private static void LoadShader()
{
@ -33,7 +33,7 @@ namespace Quik.OpenGL
}
[MethodImpl(AggressiveInlining)]
public static int CreateShader(GLEnum type) => _createShader(type);
public static int CreateShader(GLEnum type) => _createShader!(type);
[MethodImpl(AggressiveInlining)]
public static void ShaderSource(int shader, string source)
@ -43,7 +43,7 @@ namespace Quik.OpenGL
fixed (byte* ptr = &sourceUTF8[0])
{
_shaderSource(shader, 1, &ptr, &length);
_shaderSource!(shader, 1, &ptr, &length);
}
}
@ -69,7 +69,7 @@ namespace Quik.OpenGL
fixed (byte** ptr = &pointers[0])
fixed (int * len = &lengths[0])
{
_shaderSource(shader, count, ptr, len);
_shaderSource!(shader, count, ptr, len);
}
}
finally
@ -82,14 +82,14 @@ namespace Quik.OpenGL
}
[MethodImpl(AggressiveInlining)]
public static void CompileShader(int shader) => _compileShader(shader);
public static void CompileShader(int shader) => _compileShader!(shader);
[MethodImpl(AggressiveInlining)]
public static void GetShader(int shader, GLEnum pname, out int value)
{
value = default;
fixed (int *ptr = &value)
_getShader(shader, pname, ptr);
_getShader!(shader, pname, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -99,12 +99,12 @@ namespace Quik.OpenGL
byte[] infoLog = new byte[length];
fixed (byte *ptr = infoLog)
_getShaderInfoLog(shader, length, &length, ptr);
_getShaderInfoLog!(shader, length, &length, ptr);
return Encoding.UTF8.GetString(infoLog);
}
[MethodImpl(AggressiveInlining)]
public static void DeleteShader(int shader) => _deleteShader(shader);
public static void DeleteShader(int shader) => _deleteShader!(shader);
}
}

@ -18,21 +18,21 @@ namespace Quik.OpenGL
private delegate void TexParameterfvProc(GLEnum target, GLEnum pname, float* value);
private delegate void GenerateMipmapProc(GLEnum target);
private static GenObjectsProc _genTextures;
private static GenObjectsProc _deleteTextures;
private static BindSlottedProc _bindTexture;
private static ActiveTextureProc _activeTexture;
private static PixelStoreiProc _pixelStorei;
private static PixelStorefProc _pixelStoref;
private static TexImage2DProc _texImage2D;
private static TexImage3DProc _texImage3D;
private static TexSubImage2DProc _texSubImage2D;
private static TexSubImage3DProc _texSubImage3D;
private static TexParameteriProc _texParameteri;
private static TexParameterfProc _texParameterf;
private static TexParameterivProc _texParameteriv;
private static TexParameterfvProc _texParameterfv;
private static GenerateMipmapProc _generateMipmap;
private static GenObjectsProc? _genTextures;
private static GenObjectsProc? _deleteTextures;
private static BindSlottedProc? _bindTexture;
private static ActiveTextureProc? _activeTexture;
private static PixelStoreiProc? _pixelStorei;
private static PixelStorefProc? _pixelStoref;
private static TexImage2DProc? _texImage2D;
private static TexImage3DProc? _texImage3D;
private static TexSubImage2DProc? _texSubImage2D;
private static TexSubImage3DProc? _texSubImage3D;
private static TexParameteriProc? _texParameteri;
private static TexParameterfProc? _texParameterf;
private static TexParameterivProc? _texParameteriv;
private static TexParameterfvProc? _texParameterfv;
private static GenerateMipmapProc? _generateMipmap;
private static void LoadTexture()
{
@ -57,7 +57,7 @@ namespace Quik.OpenGL
public static void GenTextures(int count, out int textures)
{
fixed (int *ptr = &textures)
_genTextures(count, ptr);
_genTextures!(count, ptr);
}
[MethodImpl(AggressiveInlining)]
public static int GenTexture()
@ -72,7 +72,7 @@ namespace Quik.OpenGL
public static void DeleteTextures(int count, in int textures)
{
fixed (int* ptr = &textures)
_deleteTextures(count, ptr);
_deleteTextures!(count, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -82,26 +82,26 @@ namespace Quik.OpenGL
public static void DeleteTextures(int[] textures) => DeleteTextures(textures.Length, in textures[0]);
[MethodImpl(AggressiveInlining)]
public static void BindTexture(GLEnum target, int texture) => _bindTexture(target, texture);
public static void BindTexture(GLEnum target, int texture) => _bindTexture!(target, texture);
[MethodImpl(AggressiveInlining)]
public static void ActiveTexture(GLEnum unit) => _activeTexture(unit);
public static void ActiveTexture(GLEnum unit) => _activeTexture!(unit);
[MethodImpl(AggressiveInlining)]
public static void PixelStore(GLEnum pname, int value) => _pixelStorei(pname, value);
public static void PixelStore(GLEnum pname, int value) => _pixelStorei!(pname, value);
[MethodImpl(AggressiveInlining)]
public static void PixelStore(GLEnum pname, float value) => _pixelStoref(pname, value);
public static void PixelStore(GLEnum pname, float value) => _pixelStoref!(pname, value);
[MethodImpl(AggressiveInlining)]
public static void TexImage2D(GLEnum target, int level, GLEnum internalFormat, int width, int height, int border, GLEnum format, GLEnum pixelType, IntPtr data) =>
_texImage2D(target, level, internalFormat, width, height, border, format, pixelType, (void*)data);
_texImage2D!(target, level, internalFormat, width, height, border, format, pixelType, (void*)data);
[MethodImpl(AggressiveInlining)]
public static void TexImage2D<T>(GLEnum target, int level, GLEnum internalFormat, int width, int height, int border, GLEnum format, GLEnum pixelType, in T data) where T : unmanaged
{
fixed(T *ptr = &data)
_texImage2D(target, level, internalFormat, width, height, border, format, pixelType, ptr);
_texImage2D!(target, level, internalFormat, width, height, border, format, pixelType, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -110,14 +110,14 @@ namespace Quik.OpenGL
[MethodImpl(AggressiveInlining)]
public static void TexImage3D(GLEnum target, int level, GLEnum internalFormat, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, void* data) =>
_texImage3D(target, level, internalFormat, width, height, depth, border, format, pixelType, data);
_texImage3D!(target, level, internalFormat, width, height, depth, border, format, pixelType, data);
[MethodImpl(AggressiveInlining)]
public static void TexImage3D<T>(GLEnum target, int level, GLEnum internalFormat, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, in T data)
where T : unmanaged
{
fixed (T* ptr = &data)
_texImage3D(target, level, internalFormat, width, height, depth, border, format, pixelType, ptr);
_texImage3D!(target, level, internalFormat, width, height, depth, border, format, pixelType, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -127,13 +127,13 @@ namespace Quik.OpenGL
[MethodImpl(AggressiveInlining)]
public static void TexSubImage2D(GLEnum target, int level, int x, int y, int width, int height, GLEnum format, GLEnum pixelType, IntPtr data) =>
_texSubImage2D(target, level, x, y, width, height,format, pixelType, (void*)data);
_texSubImage2D!(target, level, x, y, width, height,format, pixelType, (void*)data);
[MethodImpl(AggressiveInlining)]
public static void TexSubImage2d<T>(GLEnum target, int level, int x, int y, int width, int height, GLEnum format, GLEnum pixelType, in T data) where T : unmanaged
{
fixed(T *ptr = &data)
_texSubImage2D(target, level, x, y, width, height, format, pixelType, ptr);
_texSubImage2D!(target, level, x, y, width, height, format, pixelType, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -142,14 +142,14 @@ namespace Quik.OpenGL
[MethodImpl(AggressiveInlining)]
public static void TexSubImage3D(GLEnum target, int level, int x, int y, int z, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, void* data) =>
_texSubImage3D(target, level, x, y, z, width, height, depth, border, format, pixelType, data);
_texSubImage3D!(target, level, x, y, z, width, height, depth, border, format, pixelType, data);
[MethodImpl(AggressiveInlining)]
public static void TexSubImage3D<T>(GLEnum target, int level, int x, int y, int z, int width, int height, int depth, int border, GLEnum format, GLEnum pixelType, in T data)
where T : unmanaged
{
fixed (T* ptr = &data)
_texSubImage3D(target, level, x, y, z, width, height, depth, border, format, pixelType, ptr);
_texSubImage3D!(target, level, x, y, z, width, height, depth, border, format, pixelType, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -158,16 +158,16 @@ namespace Quik.OpenGL
TexSubImage3D(target, level, x, y, z, width, height, depth, border, format, pixelType, in data[0]);
[MethodImpl(AggressiveInlining)]
public static void TexParameter(GLEnum target, GLEnum pname, int value) => _texParameteri(target, pname, value);
public static void TexParameter(GLEnum target, GLEnum pname, int value) => _texParameteri!(target, pname, value);
[MethodImpl(AggressiveInlining)]
public static void TexParameter(GLEnum target, GLEnum pname, GLEnum value) => _texParameteri(target, pname, (int)value);
public static void TexParameter(GLEnum target, GLEnum pname, GLEnum value) => _texParameteri!(target, pname, (int)value);
[MethodImpl(AggressiveInlining)]
public static void TexParameter(GLEnum target, GLEnum pname, float value) => _texParameterf(target, pname, value);
public static void TexParameter(GLEnum target, GLEnum pname, float value) => _texParameterf!(target, pname, value);
[MethodImpl(AggressiveInlining)]
public static void TexParameter(GLEnum target, GLEnum pname, ref int values)
{
fixed (int *ptr = &values)
_texParameteriv(target, pname, ptr);
_texParameteriv!(target, pname, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void TexParameter(GLEnum target, GLEnum pname, int[] values) => TexParameter(target, pname, ref values[0]);
@ -176,12 +176,12 @@ namespace Quik.OpenGL
public static void TexParameter(GLEnum target, GLEnum pname, ref float values)
{
fixed (float *ptr = &values)
_texParameterfv(target, pname, ptr);
_texParameterfv!(target, pname, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void TexParameter(GLEnum target, GLEnum pname, float[] values) => TexParameter(target, pname, ref values[0]);
[MethodImpl(AggressiveInlining)]
public static void GenerateMipmap(GLEnum target) => _generateMipmap(target);
public static void GenerateMipmap(GLEnum target) => _generateMipmap!(target);
}
}

@ -16,25 +16,25 @@ namespace Quik.OpenGL
private delegate void UniformNivProc(int location, int count, int* value);
private delegate void UniformMatrixNxNfvProc(int location, int count, bool transpose, float *value);
private static Uniform1fProc _uniform1f;
private static Uniform2fProc _uniform2f;
private static Uniform3fProc _uniform3f;
private static Uniform4fProc _uniform4f;
private static Uniform1iProc _uniform1i;
private static Uniform2iProc _uniform2i;
private static Uniform3iProc _uniform3i;
private static Uniform4iProc _uniform4i;
private static UniformNfvProc _uniform1fv;
private static UniformNfvProc _uniform2fv;
private static UniformNfvProc _uniform3fv;
private static UniformNfvProc _uniform4fv;
private static UniformNivProc _uniform1iv;
private static UniformNivProc _uniform2iv;
private static UniformNivProc _uniform3iv;
private static UniformNivProc _uniform4iv;
private static UniformMatrixNxNfvProc _uniformMatrix2fv;
private static UniformMatrixNxNfvProc _uniformMatrix3fv;
private static UniformMatrixNxNfvProc _uniformMatrix4fv;
private static Uniform1fProc? _uniform1f;
private static Uniform2fProc? _uniform2f;
private static Uniform3fProc? _uniform3f;
private static Uniform4fProc? _uniform4f;
private static Uniform1iProc? _uniform1i;
private static Uniform2iProc? _uniform2i;
private static Uniform3iProc? _uniform3i;
private static Uniform4iProc? _uniform4i;
private static UniformNfvProc? _uniform1fv;
private static UniformNfvProc? _uniform2fv;
private static UniformNfvProc? _uniform3fv;
private static UniformNfvProc? _uniform4fv;
private static UniformNivProc? _uniform1iv;
private static UniformNivProc? _uniform2iv;
private static UniformNivProc? _uniform3iv;
private static UniformNivProc? _uniform4iv;
private static UniformMatrixNxNfvProc? _uniformMatrix2fv;
private static UniformMatrixNxNfvProc? _uniformMatrix3fv;
private static UniformMatrixNxNfvProc? _uniformMatrix4fv;
public static void LoadUniform()
{
@ -62,161 +62,161 @@ namespace Quik.OpenGL
[MethodImpl(AggressiveInlining)]
public static void Uniform1(int location, float x)
{
_uniform1f(location, x);
_uniform1f!(location, x);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform2(int location, float x, float y)
{
_uniform2f(location, x, y);
_uniform2f!(location, x, y);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform3(int location, float x, float y, float z)
{
_uniform3f(location, x, y, z);
_uniform3f!(location, x, y, z);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform4(int location, float x, float y, float z, float w)
{
_uniform4f(location, x, y, z, w);
_uniform4f!(location, x, y, z, w);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform1(int location, int x)
{
_uniform1i(location, x);
_uniform1i!(location, x);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform2(int location, int x, int y)
{
_uniform2i(location, x, y);
_uniform2i!(location, x, y);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform3(int location, int x, int y, int z)
{
_uniform3i(location, x, y, z);
_uniform3i!(location, x, y, z);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform4(int location, int x, int y, int z, int w)
{
_uniform4i(location, x, y, z, w);
_uniform4i!(location, x, y, z, w);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform1(int location, int count, ref float first)
{
fixed(float *ptr = &first)
_uniform1fv(location, count, ptr);
_uniform1fv!(location, count, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform2(int location, int count, ref float first)
{
fixed(float *ptr = &first)
_uniform2fv(location, count, ptr);
_uniform2fv!(location, count, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform3(int location, int count, ref float first)
{
fixed(float *ptr = &first)
_uniform3fv(location, count, ptr);
_uniform3fv!(location, count, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform4(int location, int count, ref float first)
{
fixed(float *ptr = &first)
_uniform4fv(location, count, ptr);
_uniform4fv!(location, count, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform1(int location, int count, ref int first)
{
fixed(int *ptr = &first)
_uniform1iv(location, count, ptr);
_uniform1iv!(location, count, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform2(int location, int count, ref int first)
{
fixed(int *ptr = &first)
_uniform2iv(location, count, ptr);
_uniform2iv!(location, count, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform3(int location, int count, ref int first)
{
fixed(int *ptr = &first)
_uniform3iv(location, count, ptr);
_uniform3iv!(location, count, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void Uniform4(int location, int count, ref int first)
{
fixed(int *ptr = &first)
_uniform4iv(location, count, ptr);
_uniform4iv!(location, count, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void UniformMatrix2(int location, bool transpose, ref float m11)
{
fixed (float* ptr = &m11)
_uniformMatrix2fv(location, 1, transpose, ptr);
_uniformMatrix2fv!(location, 1, transpose, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void UniformMatrix3(int location, bool transpose, ref float m11)
{
fixed (float* ptr = &m11)
_uniformMatrix3fv(location, 1, transpose, ptr);
_uniformMatrix3fv!(location, 1, transpose, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void UniformMatrix4(int location, bool transpose, ref float m11)
{
fixed (float* ptr = &m11)
_uniformMatrix4fv(location, 1, transpose, ptr);
_uniformMatrix4fv!(location, 1, transpose, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void UniformMatrix2(int location, int count, bool transpose, ref float m11)
{
fixed (float* ptr = &m11)
_uniformMatrix2fv(location, count, transpose, ptr);
_uniformMatrix2fv!(location, count, transpose, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void UniformMatrix3(int location, int count, bool transpose, ref float m11)
{
fixed (float* ptr = &m11)
_uniformMatrix3fv(location, count, transpose, ptr);
_uniformMatrix3fv!(location, count, transpose, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void UniformMatrix4(int location, int count, bool transpose, ref float m11)
{
fixed (float* ptr = &m11)
_uniformMatrix4fv(location, count, transpose, ptr);
_uniformMatrix4fv!(location, count, transpose, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void UniformMatrix4(int location, bool transpose, in QMat4 m4)
{
fixed (float* ptr = &m4.M11)
_uniformMatrix4fv(location, 1, transpose, ptr);
_uniformMatrix4fv!(location, 1, transpose, ptr);
}
[MethodImpl(AggressiveInlining)]
public static void UniformMatrix4(int location, int count, bool transpose, ref QMat4 m4)
{
fixed (float* ptr = &m4.M11)
_uniformMatrix4fv(location, count, transpose, ptr);
_uniformMatrix4fv!(location, count, transpose, ptr);
}
}
}

@ -9,13 +9,13 @@ namespace Quik.OpenGL
private delegate void VertexAttribPointerProc(int location, int size, GLEnum type, bool normalized, int stride, IntPtr offset);
private delegate void VertexAttribIPointerProc(int location, int size, GLEnum type, int stride, IntPtr offset);
private static GenObjectsProc _genVertexArrays;
private static GenObjectsProc _deleteVertexArrays;
private static BindObjectProc _bindVertexArray;
private static EnableVertexAttribArrayProc _enableVertexAttribArray;
private static EnableVertexAttribArrayProc _disableVertexAttribArray;
private static VertexAttribPointerProc _vertexAttribPointer;
private static VertexAttribIPointerProc _vertexAttribIPointer;
private static GenObjectsProc? _genVertexArrays;
private static GenObjectsProc? _deleteVertexArrays;
private static BindObjectProc? _bindVertexArray;
private static EnableVertexAttribArrayProc? _enableVertexAttribArray;
private static EnableVertexAttribArrayProc? _disableVertexAttribArray;
private static VertexAttribPointerProc? _vertexAttribPointer;
private static VertexAttribIPointerProc? _vertexAttribIPointer;
private static void LoadVertexArrays()
{
@ -32,7 +32,7 @@ namespace Quik.OpenGL
public static void GenVertexArrays(int count, out int vertexArrays)
{
fixed (int *ptr = &vertexArrays)
_genVertexArrays(count, ptr);
_genVertexArrays!(count, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -49,7 +49,7 @@ namespace Quik.OpenGL
public static void DeleteVertexArrays(int count, ref int vertexArrays)
{
fixed (int *ptr = &vertexArrays)
_deleteVertexArrays(count, ptr);
_deleteVertexArrays!(count, ptr);
}
[MethodImpl(AggressiveInlining)]
@ -59,20 +59,20 @@ namespace Quik.OpenGL
public static void DeleteVertexArray(int vertexArray) => DeleteVertexArrays(1, ref vertexArray);
[MethodImpl(AggressiveInlining)]
public static void BindVertexArray(int vertexArray) => _bindVertexArray(vertexArray);
public static void BindVertexArray(int vertexArray) => _bindVertexArray!(vertexArray);
[MethodImpl(AggressiveInlining)]
public static void EnableVertexAttribArray(int location) => _enableVertexAttribArray(location);
public static void EnableVertexAttribArray(int location) => _enableVertexAttribArray!(location);
[MethodImpl(AggressiveInlining)]
public static void DisableVertexAttribArray(int location) => _disableVertexAttribArray(location);
public static void DisableVertexAttribArray(int location) => _disableVertexAttribArray!(location);
[MethodImpl(AggressiveInlining)]
public static void VertexAttribPointer(int location, int size, GLEnum type, bool normalized, int stride, int offset) =>
_vertexAttribPointer(location, size, type, normalized, stride, (IntPtr)offset);
_vertexAttribPointer!(location, size, type, normalized, stride, (IntPtr)offset);
[MethodImpl(AggressiveInlining)]
public static void VertexAttribIPointer(int location, int size, GLEnum type, int stride, int offset) =>
_vertexAttribIPointer(location, size, type, stride, (IntPtr)offset);
_vertexAttribIPointer!(location, size, type, stride, (IntPtr)offset);
}
}

@ -23,25 +23,25 @@ namespace Quik.OpenGL
private const short AggressiveInlining = (short)MethodImplOptions.AggressiveInlining;
private static GetProcAddressProc _getProcAddress;
private static GLEnum1Proc _enable;
private static GLEnum1Proc _disable;
private static GLEnum2Proc _blendFunc;
private static GLEnum1Proc _depthFunc;
private static GLEnum1Proc _clear;
private static GLI4Proc _viewport;
private static GLI4Proc _scissor;
private static GLF4Proc _clearColor;
private static DrawElementsProc _drawElements;
private static DrawArraysProc _drawArrays;
private static GetIntegervProc _getIntegerv;
private static GetFloatvProc _getFloatv;
private static GetStringProc _getString;
private static GetProcAddressProc? _getProcAddress;
private static GLEnum1Proc? _enable;
private static GLEnum1Proc? _disable;
private static GLEnum2Proc? _blendFunc;
private static GLEnum1Proc? _depthFunc;
private static GLEnum1Proc? _clear;
private static GLI4Proc? _viewport;
private static GLI4Proc? _scissor;
private static GLF4Proc? _clearColor;
private static DrawElementsProc? _drawElements;
private static DrawArraysProc? _drawArrays;
private static GetIntegervProc? _getIntegerv;
private static GetFloatvProc? _getFloatv;
private static GetStringProc? _getString;
private static T GetProcAddress<T>(string procName)
where T : Delegate
{
IntPtr funcptr = _getProcAddress(procName);
IntPtr funcptr = _getProcAddress!(procName);
return Marshal.GetDelegateForFunctionPointer<T>(funcptr);
}
@ -72,27 +72,27 @@ namespace Quik.OpenGL
}
[MethodImpl(AggressiveInlining)]
public static void Enable(GLEnum cap) => _enable(cap);
public static void Enable(GLEnum cap) => _enable!(cap);
[MethodImpl(AggressiveInlining)]
public static void Disable(GLEnum cap) => _disable(cap);
public static void Disable(GLEnum cap) => _disable!(cap);
[MethodImpl(AggressiveInlining)]
public static void BlendFunc(GLEnum src, GLEnum dst) => _blendFunc(src, dst);
public static void BlendFunc(GLEnum src, GLEnum dst) => _blendFunc!(src, dst);
[MethodImpl(AggressiveInlining)]
public static void DepthFunc(GLEnum func) => _depthFunc(func);
public static void DepthFunc(GLEnum func) => _depthFunc!(func);
[MethodImpl(AggressiveInlining)]
public static void Clear(GLEnum buffer_bits) => _clear(buffer_bits);
public static void Clear(GLEnum buffer_bits) => _clear!(buffer_bits);
[MethodImpl(AggressiveInlining)]
public static void Viewport(int x, int y, int w, int h) => _viewport(x, y, w, h);
public static void Viewport(int x, int y, int w, int h) => _viewport!(x, y, w, h);
[MethodImpl(AggressiveInlining)]
public static void Scissor(int x, int y, int w, int h) => _scissor(x, y, w, h);
public static void Scissor(int x, int y, int w, int h) => _scissor!(x, y, w, h);
[MethodImpl(AggressiveInlining)]
public static void ClearColor(float r, float g, float b, float a) => _clearColor(r, g, b, a);
public static void ClearColor(float r, float g, float b, float a) => _clearColor!(r, g, b, a);
[MethodImpl(AggressiveInlining)]
public static void DrawElements(GLEnum primitive, int count, GLEnum type, int offset) => _drawElements(primitive, count, type, (void*)offset);
public static void DrawElements(GLEnum primitive, int count, GLEnum type, int offset) => _drawElements!(primitive, count, type, (void*)offset);
[MethodImpl(AggressiveInlining)]
public static void DrawArrays(GLEnum primitive, int offset, int count) => _drawArrays(primitive, offset, count);
public static void DrawArrays(GLEnum primitive, int offset, int count) => _drawArrays!(primitive, offset, count);
[MethodImpl(AggressiveInlining)]
public static void Get(GLEnum pname, out int value)
@ -100,7 +100,7 @@ namespace Quik.OpenGL
value = default;
fixed(int* ptr = &value)
{
_getIntegerv(pname, ptr);
_getIntegerv!(pname, ptr);
}
}
@ -110,7 +110,7 @@ namespace Quik.OpenGL
value = default;
fixed (float* ptr = &value)
{
_getFloatv(pname, ptr);
_getFloatv!(pname, ptr);
}
}
@ -118,7 +118,7 @@ namespace Quik.OpenGL
public static string GetString(GLEnum pname)
{
int length;
byte* str = _getString(pname);
byte* str = _getString!(pname);
for (length = 0; str[length] == 0 || length < 256; length++);

@ -31,7 +31,7 @@ namespace Quik.OpenGL
private readonly TextureManager textures = new TextureManager();
public bool IsInit { get; private set; } = false;
public event Action<GL21Driver> OnGCDispose;
public event Action<GL21Driver>? OnGCDispose;
public GL21Driver()
{
@ -91,7 +91,7 @@ namespace Quik.OpenGL
{
AssertInit();
if (!data.TryGetValue(queue, out DrawData draw))
if (!data.TryGetValue(queue, out DrawData? draw))
{
draw = new DrawData(this, queue);
data.Add(queue, draw);
@ -163,7 +163,7 @@ namespace Quik.OpenGL
{
AssertInit();
if (!data.TryGetValue(queue, out DrawData draw))
if (!data.TryGetValue(queue, out DrawData? draw))
return;
draw.Dispose();
data.Remove(queue);
@ -171,7 +171,7 @@ namespace Quik.OpenGL
private static int CreateShader(GLEnum type, string name)
{
StreamReader source = new StreamReader(typeof(GL21Driver).Assembly.GetManifestResourceStream(name));
StreamReader source = new StreamReader(typeof(GL21Driver).Assembly.GetManifestResourceStream(name) ?? throw new Exception("Resource not found."));
string text = source.ReadToEnd();
source.Dispose();

@ -19,17 +19,17 @@ namespace Quik.PAL
/// <summary>
/// The title of the application.
/// </summary>
string Title { get; set; }
string? Title { get; set; }
/// <summary>
/// The default icon for the application.
/// </summary>
QImage Icon { get; set; }
QImage? Icon { get; set; }
/// <summary>
/// The event raised when an event is received.
/// </summary>
event EventHandler EventRaised;
event EventHandler? EventRaised;
/// <summary>
/// Raise the events that have been enqueued.

@ -34,7 +34,7 @@ namespace Quik.PAL
set => platform.PortSetPosition(handle, value);
}
public UIBase UIElement { get; set; }
public UIBase? UIElement { get; set; }
public bool IsValid => platform.PortIsValid(handle);
@ -70,13 +70,12 @@ namespace Quik.PAL
platform.PortFocus(handle);
}
public void Paint(CommandList list = null)
public void Paint(CommandList? list = null)
{
if (UIElement == null)
return;
if(list == null)
list = new CommandList();
list ??= new CommandList();
list.Clear();
UIElement.Bounds = new QRectangle(Size, new QVec2(0,0));

@ -2,8 +2,8 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>

@ -22,7 +22,7 @@ namespace Quik
/// <summary>
/// Title of the application.
/// </summary>
public string Title
public string? Title
{
get => Platform.Title;
set => Platform.Title = value;
@ -31,13 +31,13 @@ namespace Quik
/// <summary>
/// Application icon.
/// </summary>
public QImage Icon
public QImage? Icon
{
get => Platform.Icon;
set => Platform.Icon = value;
}
public QuikPort MainPort { get; private set; } = null;
public QuikPort? MainPort { get; private set; } = null;
public FontProvider FontProvider { get; }
@ -53,9 +53,9 @@ namespace Quik
Current = this;
}
public IDisposable GetMedia(object key, MediaHint hint)
public IDisposable? GetMedia(object key, MediaHint hint)
{
IDisposable disposable = null;
IDisposable? disposable = null;
foreach (MediaLoader loader in MediaLoaders)
{
@ -68,9 +68,9 @@ namespace Quik
return disposable;
}
public IDisposable GetMedia<T>(T key, MediaHint hint)
public IDisposable? GetMedia<T>(T key, MediaHint hint)
{
IDisposable disposable = null;
IDisposable? disposable = null;
foreach (MediaLoader loader in MediaLoaders)
{
@ -109,7 +109,7 @@ namespace Quik
public bool RunSync()
{
if (!MainPort.IsValid)
if (!MainPort!.IsValid)
return false;
Platform.ProcessEvents(false);
@ -123,7 +123,7 @@ namespace Quik
return true;
}
public static QuikApplication Current { get; private set; }
public static QuikApplication Current { get; private set; } = null!;
public static void SetCurrentApplication(QuikApplication application)
{

@ -66,7 +66,7 @@ namespace Quik
public static bool operator !=(QVec2 a, QVec2 b) => a.X != b.X || a.Y != b.Y;
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj is QVec2)
{

@ -53,7 +53,7 @@ namespace Quik
public abstract class StyleBase
{
public abstract object this[string key] { get; set; }
public abstract object? this[string key] { get; set; }
public QColor? Color
{
@ -109,9 +109,9 @@ namespace Quik
set => this["list-marker-position"] = value;
}
public QImage ListMarkerImage
public QImage? ListMarkerImage
{
get => (QImage)this["list-marker-image"];
get => (QImage?)this["list-marker-image"];
set => this["list-marker-image"] = value;
}
@ -127,9 +127,9 @@ namespace Quik
set => this["stroke-color"] = value;
}
public FontFace Font
public FontFace? Font
{
get => (FontFace)this["font"];
get => (FontFace?)this["font"];
set => this["font"] = value;
}
@ -144,9 +144,9 @@ namespace Quik
{
private readonly Dictionary<string, object> _keys = new Dictionary<string, object>();
public override object this[string styleKey]
public override object? this[string styleKey]
{
get => _keys.TryGetValue(styleKey, out object value) ? value : null;
get => _keys.TryGetValue(styleKey, out object? value) ? value : null;
set
{
if (value == null)
@ -163,11 +163,11 @@ namespace Quik
public Style BaseStyle { get; }
public override object this[string key]
public override object? this[string key]
{
get
{
object value = null;
object? value = null;
for (int i = _styles.Count; i != 0 && value == null; i--)
{

@ -16,18 +16,19 @@ namespace Quik.Typography
private Dictionary<FontFace, QFont> Fonts { get; } = new Dictionary<FontFace, QFont>();
private HashSet<QFont> UsedFonts { get; } = new HashSet<QFont>();
public readonly FontRasterizerOptions RasterizerOptions;
public IFontDataBase Database { get; set; }
public IFontFactory FontFactory { get; set; }
public IFontDataBase? Database { get; set; }
public IFontFactory? FontFactory { get; set; }
private readonly QuikApplication App;
public QFont this[FontFace info]
{
get
{
if (!Fonts.TryGetValue(info, out QFont font))
if (!Fonts.TryGetValue(info, out QFont? font))
{
using Stream str = Database?.Open(info);
if (FontFactory.TryOpen(str, out font))
using Stream str = Database?.Open(info) ?? throw new Exception("Font could not be found.");
if (FontFactory?.TryOpen(str, out font) ?? false)
{
Fonts.Add(info, font);
}
@ -46,7 +47,7 @@ namespace Quik.Typography
{
get
{
return this[Database.GetSystemFontFace(family)];
return this[Database?.GetSystemFontFace(family) ?? throw new Exception("No font database.")];
}
}
@ -55,21 +56,21 @@ namespace Quik.Typography
RasterizerOptions = options;
App = app;
Type fdb = Type.GetType("Quik.Media.Defaults.FontDataBaseProvider, Quik.Media.Defaults");
Type? fdb = Type.GetType("Quik.Media.Defaults.FontDataBaseProvider, Quik.Media.Defaults");
if (fdb != null)
{
PropertyInfo instanceProperty = fdb.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty);
PropertyInfo? instanceProperty = fdb.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty);
if (instanceProperty != null)
{
Database = (IFontDataBase)instanceProperty.GetValue(null);
Database = (IFontDataBase)instanceProperty.GetValue(null)!;
}
}
Type ffact = Type.GetType("Quik.Media.Defaults.FreeTypeFontFactory, Quik.Media.Defaults");
Type? ffact = Type.GetType("Quik.Media.Defaults.FreeTypeFontFactory, Quik.Media.Defaults");
if (ffact != null)
{
ConstructorInfo ctor = ffact.GetConstructor(Array.Empty<Type>());
FontFactory = (IFontFactory)ctor.Invoke(null);
ConstructorInfo? ctor = ffact.GetConstructor(Array.Empty<Type>());
FontFactory = (IFontFactory?)ctor?.Invoke(null);
}
}
public FontProvider(QuikApplication app)

@ -135,7 +135,7 @@ namespace Quik.Typography
font.Get(codepoint, size, out FontGlyph glyph);
ref readonly QGlyphMetrics metrics = ref glyph.Metrics;
QImage image = glyph.Image;
QImage? image = glyph.Image;
if (image == null)
{

@ -14,7 +14,7 @@ namespace Quik.VertexGenerator
private int _start;
private int _baseOffset;
private QRectangle _bounds;
private QImage _texture;
private QImage? _texture;
public int ZDepth { get; private set; }
public QuikVertex[] VertexArray => _vertices.InternalArray;
@ -33,7 +33,7 @@ namespace Quik.VertexGenerator
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void StartDrawCall(in QRectangle bounds, QImage texture, int baseOffset)
public void StartDrawCall(in QRectangle bounds, QImage? texture, int baseOffset)
{
_start = ElementCount;
_texture = texture;
@ -100,9 +100,9 @@ namespace Quik.VertexGenerator
public int Start { get; }
public int Count { get; }
public QRectangle Bounds { get; }
public QImage Texture { get; }
public QImage? Texture { get; }
public DrawCall(int start, int count, in QRectangle bounds, QImage texture)
public DrawCall(int start, int count, in QRectangle bounds, QImage? texture)
{
Start = start;
Count = count;

@ -20,7 +20,7 @@ namespace QuikDemo
public class EmptyView : View
{
private QFont font;
private QFont? font;
private readonly Label Label = new Label() { Text = "Hello world!", Position = new QVec2(300, 300) };
protected override void PaintBegin(CommandList cmd)