├── .gitattributes ├── .gitignore ├── Example Projects ├── SFGraphicsGUI │ └── packages.config └── SFGraphicsGui │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── Lib │ ├── ColladaSharp.dll │ ├── FileFormatWavefront.XML │ ├── FileFormatWavefront.dll │ └── XMLSchemaDefinition.dll │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ ├── Resources │ └── UVPattern.png │ ├── SFGraphicsGui.csproj │ ├── Shaders │ ├── screenTexture.frag │ └── screenTexture.vert │ └── Source │ ├── ColladaToRenderMesh.cs │ ├── GraphicsResources.cs │ ├── ModelRendering.cs │ ├── RenderMesh.cs │ ├── RenderVertex.cs │ ├── ResourceTextFile.cs │ ├── ScreenDrawing │ ├── ScreenTriangle.cs │ └── ScreenVertex.cs │ ├── TextureGenerator.cs │ └── WavefrontToRenderMesh.cs ├── LICENSE.txt ├── Projects ├── SFGenericModel │ ├── GenericMesh.cs │ ├── GenericMeshBase.cs │ ├── GenericMeshNonInterleaved.cs │ ├── IndexedVertexData.cs │ ├── Materials │ │ ├── GenericMaterial.cs │ │ └── UniformBlock.cs │ ├── MeshEventArgs │ │ └── AttribSetEventArgs.cs │ ├── RenderState │ │ ├── AlphaBlendSettings.cs │ │ ├── AlphaTestSettings.cs │ │ ├── DepthTestSettings.cs │ │ ├── FaceCullingSettings.cs │ │ ├── GLRenderSettings.cs │ │ ├── PolygonModeSettings.cs │ │ └── RenderSettings.cs │ ├── SFGenericModel.csproj │ ├── Utils │ │ ├── IndexUtils.cs │ │ └── MeshBatchUtils.cs │ └── VertexAttributes │ │ ├── AttribPointerUtils.cs │ │ ├── VertexAttribute.cs │ │ ├── VertexAttributeUtils.cs │ │ ├── VertexFloatAttribute.cs │ │ └── VertexIntAttribute.cs ├── SFGraphics.Controls │ ├── GLViewport.cs │ └── SFGraphics.Controls.csproj ├── SFGraphics.ShaderGen │ ├── GlslParsing.cs │ ├── GlslShaderUtils │ │ ├── CaseStatement.cs │ │ ├── GlslUtils.cs │ │ ├── GlslVectorUtils.cs │ │ ├── ShaderAttribute.cs │ │ ├── ShaderUniform.cs │ │ └── SwitchUtils.cs │ ├── SFGraphics.ShaderGen.csproj │ ├── TextureRenderInfo.cs │ └── VertexAttributeShaderGenerator.cs ├── SFGraphics.Timing │ ├── SFGraphics.Timing.csproj │ └── ThreadTimer.cs ├── SFGraphics.Utils │ ├── BitmapUtils.cs │ ├── BoundingSphereGenerator.cs │ ├── BufferValidation.cs │ ├── ColorUtils.cs │ ├── SFGraphics.Utils.csproj │ ├── TriangleListUtils.cs │ ├── VectorUtils.cs │ └── VertexOptimization.cs ├── SFGraphics │ ├── Cameras │ │ └── Camera.cs │ ├── GLObjects │ │ ├── BufferObjects │ │ │ ├── BufferExceptionMessages.cs │ │ │ └── BufferObject.cs │ │ ├── Framebuffers │ │ │ ├── Framebuffer.cs │ │ │ ├── FramebufferReading.cs │ │ │ └── IFramebufferAttachment.cs │ │ ├── GLObject.cs │ │ ├── GLObjectManagement │ │ │ ├── GLObjectManager.cs │ │ │ └── ReferenceCounting.cs │ │ ├── Renderbuffers │ │ │ └── Renderbuffer.cs │ │ ├── Samplers │ │ │ └── SamplerObject.cs │ │ ├── Shaders │ │ │ ├── Shader.cs │ │ │ ├── ShaderEventArgs │ │ │ │ ├── LinkStatusEventArgs.cs │ │ │ │ ├── TextureSetEventArgs.cs │ │ │ │ └── UniformSetEventArgs.cs │ │ │ ├── ShaderLoaders.cs │ │ │ ├── ShaderObject.cs │ │ │ ├── ShaderSetters.cs │ │ │ └── Utils │ │ │ │ ├── ActiveAttribInfo.cs │ │ │ │ ├── ActiveUniformInfo.cs │ │ │ │ ├── ShaderLog.cs │ │ │ │ ├── ShaderTypeConversions.cs │ │ │ │ └── ShaderValidation.cs │ │ ├── Textures │ │ │ ├── DepthTexture.cs │ │ │ ├── Texture.cs │ │ │ ├── Texture2D.cs │ │ │ ├── Texture2DMultiSample.cs │ │ │ ├── Texture3D.cs │ │ │ ├── TextureCubeMap.cs │ │ │ ├── TextureFormats │ │ │ │ ├── CompressedBlockSize.cs │ │ │ │ ├── TextureFormatTools.cs │ │ │ │ └── TextureFormatUncompressed.cs │ │ │ └── Utils │ │ │ │ ├── MipmapLoading.cs │ │ │ │ └── TextureExceptionMessages.cs │ │ └── VertexArrays │ │ │ └── VertexArrayObject.cs │ ├── GlUtils │ │ └── OpenGLExtensions.cs │ └── SFGraphics.csproj ├── SFShaderLoader │ ├── SFShaderLoader.csproj │ └── ShaderLoader.cs └── SFShapes │ ├── Mesh3D.cs │ ├── SFShapes.csproj │ ├── ShapeExceptionMessages.cs │ ├── ShapeGenerator.cs │ └── Vertex3d.cs ├── README.md ├── SFGraphics.sln ├── Test Projects ├── RenderTestUtils │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── RenderTestUtils.csproj │ ├── Shaders │ │ ├── invalid.frag │ │ ├── invalid.vert │ │ ├── undefinedFunction.frag │ │ ├── valid.frag │ │ └── valid.vert │ └── TestTools │ │ ├── OpenTKWindowlessContext.cs │ │ ├── ResourceShaders.cs │ │ └── ShaderTestUtils.cs ├── SFGenericModel.Test │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SFGenericModel.Test.csproj │ ├── Tests │ │ ├── AttribPointerSize.cs │ │ ├── GenericMeshNonInterleavedTests │ │ │ ├── AddBuffer.cs │ │ │ ├── AddBufferFromExistingBuffer.cs │ │ │ ├── ConfigureAttribute.cs │ │ │ ├── ConfigureAttributeFromExistingBuffer.cs │ │ │ └── Constructors.cs │ │ ├── GenericMeshTests │ │ │ ├── Constructors.cs │ │ │ └── InvalidAttribSetEvent.cs │ │ ├── GroupByPrimitiveType.cs │ │ ├── IndexUtilsTests │ │ │ └── GenerateIndices.cs │ │ ├── RenderSettingsTests │ │ │ ├── AlphaBlendSettingsEquality.cs │ │ │ ├── AlphaTestEquality.cs │ │ │ ├── DepthTestSettingsEquality.cs │ │ │ ├── FaceCullSettingsEquality.cs │ │ │ ├── PolygonModeSettingsEquality.cs │ │ │ └── RenderSettingsEquality.cs │ │ ├── UniformBlockTests │ │ │ ├── BindBlock.cs │ │ │ ├── SetValue.cs │ │ │ └── SetValues.cs │ │ └── VertexAttributeInfoSize.cs │ └── packages.config ├── SFGraphics.Controls.Test │ ├── GLViewportTests │ │ └── Dispose.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SFGraphics.Controls.Test.csproj │ └── packages.config ├── SFGraphics.ShaderGen.Test │ ├── GlslParsingTests │ │ ├── GetAttributes.cs │ │ └── GetUniforms.cs │ ├── SFGraphics.ShaderGen.Test.csproj │ └── ShaderGeneratorTests │ │ └── CreateAttributeShader.cs ├── SFGraphics.Test │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── README.md │ ├── SFGraphics.Test.csproj │ ├── Tests │ │ ├── BufferObjectTests │ │ │ ├── BindBufferBase.cs │ │ │ ├── BindBufferRange.cs │ │ │ ├── BufferData.cs │ │ │ ├── BufferTest.cs │ │ │ ├── GetSubData.cs │ │ │ ├── MapBuffer.cs │ │ │ ├── SetCapacity.cs │ │ │ ├── SetSubData.cs │ │ │ └── SizeInBytes.cs │ │ ├── CameraTests │ │ │ ├── FovDegreesConversion.cs │ │ │ ├── FovRadiansConversion.cs │ │ │ ├── GetSetTranslation.cs │ │ │ ├── ProjectionMatrix.cs │ │ │ ├── RenderDimensions.cs │ │ │ ├── ResetTransforms.cs │ │ │ ├── RotationMatrix.cs │ │ │ └── TranslationMatrix.cs │ │ ├── FramebufferTests │ │ │ ├── Attachments.cs │ │ │ └── ConstructorExceptions.cs │ │ ├── GLExtensionTests │ │ │ └── ExtensionAvailabilityTests.cs │ │ ├── GLObjectTests │ │ │ └── GLObjectToString.cs │ │ ├── GraphicsContextTest.cs │ │ ├── ReferenceCountTests │ │ │ ├── AddReference.cs │ │ │ ├── GetObjectsWithNoReferencesTests.cs │ │ │ └── RemoveReference.cs │ │ ├── RenderbufferTests │ │ │ └── ConstructorExceptions.cs │ │ ├── SamplerTests │ │ │ └── SetProperties.cs │ │ ├── ShaderObjectTests │ │ │ ├── CreateShader.cs │ │ │ ├── GetInfoLog.cs │ │ │ └── GetShaderSource.cs │ │ ├── ShaderTests │ │ │ ├── GetAttribLocation.cs │ │ │ ├── GetProgramBinary.cs │ │ │ ├── GetShaderSources.cs │ │ │ ├── GetUniformBlockIndex.cs │ │ │ ├── GetUniformLocation.cs │ │ │ ├── ProgramCreationTests │ │ │ │ ├── JustFragShader.cs │ │ │ │ ├── JustVertShader.cs │ │ │ │ ├── LinkError.cs │ │ │ │ ├── NoShaders.cs │ │ │ │ ├── OnLinkStatusChanged.cs │ │ │ │ ├── ValidFragInvalidVert.cs │ │ │ │ └── ValidInvalidFragShader.cs │ │ │ ├── ProgramValidateStatus.cs │ │ │ ├── SetUniformTests │ │ │ │ ├── SetBoolToInt.cs │ │ │ │ ├── SetFloat.cs │ │ │ │ ├── SetFloatArray.cs │ │ │ │ ├── SetInt.cs │ │ │ │ ├── SetIntArray.cs │ │ │ │ ├── SetMatrix4x4.cs │ │ │ │ ├── SetMatrix4x4Array.cs │ │ │ │ ├── SetTexture.cs │ │ │ │ ├── SetUint.cs │ │ │ │ ├── SetUintArray.cs │ │ │ │ ├── SetVector2.cs │ │ │ │ ├── SetVector2Array.cs │ │ │ │ ├── SetVector3.cs │ │ │ │ ├── SetVector3Array.cs │ │ │ │ ├── SetVector4.cs │ │ │ │ └── SetVector4Array.cs │ │ │ ├── ShaderTest.cs │ │ │ ├── ShaderTestValidShader.cs │ │ │ ├── UniformBlockBinding.cs │ │ │ └── UseProgram.cs │ │ └── TextureTests │ │ │ ├── CompressedImageSize.cs │ │ │ ├── DepthTextureConstructor.cs │ │ │ ├── GetImageDataBgra.cs │ │ │ ├── GetImageDataRgba.cs │ │ │ ├── MipmapLoadingExceptions.cs │ │ │ ├── Texture2DMsConstructor.cs │ │ │ ├── Texture2DTests │ │ │ ├── LoadImageData.cs │ │ │ └── LoadImageDataBuffer.cs │ │ │ ├── Texture3DTests │ │ │ └── LoadImageData.cs │ │ │ └── TextureCubeMapTests │ │ │ └── LoadImageData.cs │ └── packages.config ├── SFGraphics.Utils.Test │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── README.md │ ├── SFGraphics.Utils.Test.csproj │ ├── Test │ │ ├── BitmapUtilsTests │ │ │ └── GetBitmap.cs │ │ ├── BoundingSphereTests │ │ │ ├── GenerateBoundingSphere.cs │ │ │ ├── GenerateBoundingSphereFromSpheres.cs │ │ │ └── SpherePointUtils.cs │ │ ├── BufferValidationTests │ │ │ └── IsValidAccess.cs │ │ ├── ColorUtilsTests │ │ │ ├── Clamp.cs │ │ │ ├── GetColorTests │ │ │ │ ├── FromFloats.cs │ │ │ │ ├── FromVector3.cs │ │ │ │ └── FromVector4.cs │ │ │ ├── GetVector3FromColor.cs │ │ │ ├── GetVector4FromColor.cs │ │ │ ├── HsvToRgbFloat.cs │ │ │ ├── InvertColor.cs │ │ │ └── RgbToHsvFloat.cs │ │ ├── TriangleListUtilsTests │ │ │ ├── CalculateSmoothNormals.cs │ │ │ └── CalculateTangentsBitangents.cs │ │ ├── VectorUtilsTests │ │ │ ├── CalculateNormals.cs │ │ │ ├── CalculateTangentBitangent.cs │ │ │ ├── CalculateTangentW.cs │ │ │ ├── GetDegrees.cs │ │ │ ├── GetRadians.cs │ │ │ └── Orthogonalize.cs │ │ └── VertexOptimizationTests │ │ │ └── OptimizeVertexData.cs │ └── packages.config ├── SFShaderLoader.Test │ ├── AddShaderFromBinary.cs │ ├── AddShaderFromNames.cs │ ├── AddShaderFromSource.cs │ ├── AddSource.cs │ ├── CreateProgramBinary.cs │ ├── GetShader.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SFShaderLoader.Test.csproj │ ├── Shaders │ │ ├── FunctionA.glsl │ │ ├── MultipleFunctions.frag │ │ ├── valid.frag │ │ └── valid.vert │ └── packages.config └── SFTiming.Test │ ├── Properties │ └── AssemblyInfo.cs │ ├── SFTiming.Test.csproj │ ├── ThreadTimerEvents.cs │ └── packages.config ├── appveyor.yml └── lib ├── OpenTK.GLControl.dll └── OpenTK.dll /Example Projects/SFGraphicsGUI/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace SFGraphicsGui 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Lib/ColladaSharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ScanMountGoat/SFGraphics/ec1c5f0741722cf6bea29fbe03c6f9226cc4d928/Example Projects/SFGraphicsGui/Lib/ColladaSharp.dll -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Lib/FileFormatWavefront.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ScanMountGoat/SFGraphics/ec1c5f0741722cf6bea29fbe03c6f9226cc4d928/Example Projects/SFGraphicsGui/Lib/FileFormatWavefront.dll -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Lib/XMLSchemaDefinition.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ScanMountGoat/SFGraphics/ec1c5f0741722cf6bea29fbe03c6f9226cc4d928/Example Projects/SFGraphicsGui/Lib/XMLSchemaDefinition.dll -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SFGraphicsGui.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.7.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Resources/UVPattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ScanMountGoat/SFGraphics/ec1c5f0741722cf6bea29fbe03c6f9226cc4d928/Example Projects/SFGraphicsGui/Resources/UVPattern.png -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/SFGraphicsGui.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netcoreapp3.1 4 | WinExe 5 | false 6 | true 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ..\..\lib\OpenTK.dll 19 | true 20 | 21 | 22 | ..\..\lib\OpenTK.GLControl.dll 23 | true 24 | 25 | 26 | .\lib\ColladaSharp.dll 27 | true 28 | 29 | 30 | .\lib\FileFOrmatWavefront.dll 31 | true 32 | 33 | 34 | 35 | 36 | 37 | PreserveNewest 38 | 39 | 40 | PreserveNewest 41 | 42 | 43 | PreserveNewest 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Shaders/screenTexture.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 texCoord; 4 | 5 | uniform sampler2D uvTexture; 6 | 7 | out vec4 fragColor; 8 | 9 | void main() 10 | { 11 | fragColor.rgb = texture(uvTexture, vec2(texCoord.x, 1 - texCoord.y)).rgb; 12 | fragColor.a = 1; 13 | } 14 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Shaders/screenTexture.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec3 position; 4 | 5 | out vec2 texCoord; 6 | 7 | // Convert the positions of a triangle to UV coordinates. 8 | // The triangle extends past the borders of the screen. 9 | // -1.0, -1.0, 0.0, 10 | // 3.0, -1.0, 0.0, 11 | // -1.0, 3.0, 0.0 12 | void main() 13 | { 14 | texCoord.xy = (position.xy + vec2(1.0)) * 0.5; 15 | gl_Position = vec4(position, 1); 16 | } 17 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Source/ColladaToRenderMesh.cs: -------------------------------------------------------------------------------- 1 | using ColladaSharp; 2 | using OpenTK; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace SFGraphicsGui.Source 9 | { 10 | internal static class ColladaToRenderMesh 11 | { 12 | public static async Task GetVerticesAsync(string filename) 13 | { 14 | var result = await Collada.ImportAsync(filename, new ColladaImportOptions(), 15 | new Progress(), CancellationToken.None); 16 | 17 | var vertices = new List(); 18 | foreach (var scene in result.Scenes) 19 | { 20 | foreach (var subMesh in scene.Model.Children) 21 | { 22 | for (int i = 0; i < subMesh.Primitives.Triangles.Count; i++) 23 | { 24 | var face = subMesh.Primitives.GetFace(i); 25 | vertices.Add(GetVertex(face.Vertex0)); 26 | vertices.Add(GetVertex(face.Vertex1)); 27 | vertices.Add(GetVertex(face.Vertex2)); 28 | } 29 | } 30 | } 31 | 32 | return vertices.ToArray(); 33 | } 34 | 35 | private static RenderVertex GetVertex(ColladaSharp.Models.Vertex vertex) 36 | { 37 | // TODO: Orientation? 38 | var position = new Vector4(vertex.Position.X, vertex.Position.Y, vertex.Position.Z, 1) * Matrix4.CreateRotationX(90); 39 | var normal = new Vector4(vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z, 1) * Matrix4.CreateRotationX(90); 40 | var texCoord = new Vector2(vertex.TexCoord.X, vertex.TexCoord.Y); 41 | return new RenderVertex(position.Xyz, normal.Xyz, texCoord); 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Source/ModelRendering.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | using SFGraphics.Cameras; 3 | 4 | namespace SFGraphicsGui.Source 5 | { 6 | internal static class ModelRendering 7 | { 8 | public static void DrawModel(RenderMesh modelToRender, int width, int height, GraphicsResources graphicsResources, int renderModeIndex) 9 | { 10 | if (!graphicsResources.objModelShader.LinkStatusIsOk) 11 | return; 12 | 13 | var camera = new Camera() 14 | { 15 | RenderWidth = width, 16 | RenderHeight = height, 17 | NearClipPlane = 0.01f, 18 | }; 19 | camera.FrameBoundingSphere(modelToRender.BoundingSphere); 20 | 21 | graphicsResources.objModelShader.UseProgram(); 22 | graphicsResources.objModelShader.SetMatrix4x4("mvpMatrix", camera.MvpMatrix); 23 | graphicsResources.objModelShader.SetInt("attributeIndex", renderModeIndex); 24 | 25 | GL.Clear(ClearBufferMask.DepthBufferBit); 26 | 27 | SFGenericModel.RenderState.GLRenderSettings.SetFaceCulling(new SFGenericModel.RenderState.FaceCullingSettings(true, CullFaceMode.Back)); 28 | SFGenericModel.RenderState.GLRenderSettings.SetDepthTesting(new SFGenericModel.RenderState.DepthTestSettings(true, true, DepthFunction.Lequal)); 29 | 30 | modelToRender.Draw(graphicsResources.objModelShader); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Source/RenderMesh.cs: -------------------------------------------------------------------------------- 1 | using SFGenericModel; 2 | using System.Collections.Generic; 3 | using OpenTK; 4 | 5 | namespace SFGraphicsGui 6 | { 7 | class RenderMesh : GenericMesh 8 | { 9 | public Vector4 BoundingSphere { get; } 10 | 11 | public RenderMesh(RenderVertex[] vertices) : base(vertices, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles) 12 | { 13 | var positions = new List(vertices.Length); 14 | foreach (var vertex in vertices) 15 | positions.Add(vertex.Position); 16 | 17 | BoundingSphere = SFGraphics.Utils.BoundingSphereGenerator.GenerateBoundingSphere(positions); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Source/RenderVertex.cs: -------------------------------------------------------------------------------- 1 | using OpenTK; 2 | using SFGenericModel.VertexAttributes; 3 | 4 | namespace SFGraphicsGui 5 | { 6 | struct RenderVertex 7 | { 8 | [VertexFloat("position", ValueCount.Three, OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float, false)] 9 | public Vector3 Position { get; } 10 | 11 | [VertexFloat("normal", ValueCount.Three, OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float, false)] 12 | public Vector3 Normal { get; } 13 | 14 | [VertexFloat("texcoord0", ValueCount.Two, OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float, false)] 15 | public Vector2 TexCoord0 { get; } 16 | 17 | public RenderVertex(Vector3 position, Vector3 normal, Vector2 texCoord0) 18 | { 19 | Position = position; 20 | Normal = normal; 21 | TexCoord0 = texCoord0; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Source/ResourceTextFile.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Reflection; 3 | 4 | namespace SFGraphicsGui 5 | { 6 | public static class ResourceTextFile 7 | { 8 | /// 9 | /// Reads all the text of the specified resource file into a string. 10 | /// 11 | /// The name of the resource, including the namespace and sub directories. 12 | /// Ex: "SFGraphicsGui.Shaders.screenShader.vert" 13 | /// 14 | public static string GetFileText(string resourceName) 15 | { 16 | Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); 17 | using (StreamReader reader = new StreamReader(stream)) 18 | { 19 | return reader.ReadToEnd(); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Source/ScreenDrawing/ScreenTriangle.cs: -------------------------------------------------------------------------------- 1 | using OpenTK; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Samplers; 4 | using SFGraphics.GLObjects.Shaders; 5 | using SFGraphics.GLObjects.Textures; 6 | 7 | namespace SFGraphicsGui 8 | { 9 | class ScreenTriangle : SFGenericModel.GenericMesh 10 | { 11 | // A triangle that extends past the screen. 12 | private static readonly ScreenVertex[] screenTrianglePositions = 13 | { 14 | new ScreenVertex(new Vector3(-1f, -1f, 0.0f)), 15 | new ScreenVertex(new Vector3( 3f, -1f, 0.0f)), 16 | new ScreenVertex(new Vector3(-1f, 3f, 0.0f)) 17 | }; 18 | 19 | public ScreenTriangle() : base(screenTrianglePositions, PrimitiveType.Triangles) 20 | { 21 | 22 | } 23 | 24 | public void DrawScreenTexture(Texture2D texture, Shader shader, SamplerObject sampler) 25 | { 26 | if (texture == null) 27 | return; 28 | 29 | // Always check program creation before using shaders to prevent crashes. 30 | if (!shader.LinkStatusIsOk) 31 | return; 32 | 33 | // Render using the shader. 34 | shader.UseProgram(); 35 | 36 | // The sampler's parameters are used instead of the texture's parameters. 37 | int textureUnit = 0; 38 | sampler.Bind(textureUnit); 39 | 40 | shader.SetInt("attributeIndex", 1); 41 | Matrix4 matrix4 = Matrix4.Identity; 42 | shader.SetMatrix4x4("mvpMatrix", ref matrix4); 43 | 44 | shader.SetTexture("uvTexture", texture, textureUnit); 45 | 46 | GL.Disable(EnableCap.DepthTest); 47 | 48 | Draw(shader); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Source/ScreenDrawing/ScreenVertex.cs: -------------------------------------------------------------------------------- 1 | using OpenTK; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGenericModel.VertexAttributes; 4 | 5 | namespace SFGraphicsGui 6 | { 7 | struct ScreenVertex 8 | { 9 | [VertexFloatAttribute("position", ValueCount.Three, VertexAttribPointerType.Float, false)] 10 | public Vector3 Position { get; } 11 | 12 | public ScreenVertex(Vector3 position) 13 | { 14 | Position = position; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Source/TextureGenerator.cs: -------------------------------------------------------------------------------- 1 | using OpenTK; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.BufferObjects; 4 | using SFGraphics.GLObjects.Textures; 5 | using SFGraphics.GLObjects.Textures.TextureFormats; 6 | 7 | namespace SFGraphicsGui 8 | { 9 | public static class TextureGenerator 10 | { 11 | public static Texture2D CreateStripes(bool usePbo, int width, int height) 12 | { 13 | Texture2D floatTexture = new Texture2D 14 | { 15 | MinFilter = TextureMinFilter.Nearest, 16 | MagFilter = TextureMagFilter.Nearest 17 | }; 18 | 19 | Vector3[] pixels = GetImagePixels(width, height); 20 | 21 | if (usePbo) 22 | LoadFloatTexImageDataPbo(floatTexture, pixels, width, height); 23 | else 24 | LoadFloatTexImageData(floatTexture, pixels, width, height); 25 | 26 | return floatTexture; 27 | } 28 | 29 | private static void LoadFloatTexImageData(Texture2D floatTexture, Vector3[] pixels, int width, int height) 30 | { 31 | floatTexture.LoadImageData(width, height, pixels, new TextureFormatUncompressed(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.Float)); 32 | } 33 | 34 | private static void LoadFloatTexImageDataPbo(Texture2D floatTexture, Vector3[] pixels, int width, int height) 35 | { 36 | BufferObject pixelBuffer = new BufferObject(BufferTarget.PixelUnpackBuffer); 37 | pixelBuffer.SetData(pixels, BufferUsageHint.StaticDraw); 38 | floatTexture.LoadImageData(width, height, pixelBuffer, new TextureFormatUncompressed(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.Float)); 39 | } 40 | 41 | private static Vector3[] GetImagePixels(int width, int height) 42 | { 43 | Vector3[] pixels = new Vector3[width * height]; 44 | for (int i = 0; i < pixels.Length; i++) 45 | { 46 | // Magenta and black stripes. 47 | pixels[i] = new Vector3(1, 0, 1) * (i % 2); 48 | } 49 | 50 | return pixels; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Example Projects/SFGraphicsGui/Source/WavefrontToRenderMesh.cs: -------------------------------------------------------------------------------- 1 | using OpenTK; 2 | 3 | namespace SFGraphicsGui.Source 4 | { 5 | internal static class WavefrontToRenderMesh 6 | { 7 | public static RenderMesh CreateRenderMesh(string fileName) 8 | { 9 | var vertices = GetVertices(FileFormatWavefront.FileFormatObj.Load(fileName, false)); 10 | return new RenderMesh(vertices); 11 | } 12 | 13 | private static RenderVertex[] GetVertices(FileFormatWavefront.FileLoadResult result) 14 | { 15 | // TODO: Groups? 16 | var vertices = new RenderVertex[result.Model.UngroupedFaces.Count * 3]; 17 | 18 | int i = 0; 19 | foreach (var face in result.Model.UngroupedFaces) 20 | { 21 | foreach (var index in face.Indices) 22 | { 23 | vertices[i] = GetVertex(result, index); 24 | i++; 25 | } 26 | } 27 | 28 | return vertices; 29 | } 30 | 31 | private static RenderVertex GetVertex(FileFormatWavefront.FileLoadResult result, FileFormatWavefront.Model.Index index) 32 | { 33 | var position = new Vector3(result.Model.Vertices[index.vertex].x, result.Model.Vertices[index.vertex].y, result.Model.Vertices[index.vertex].z); 34 | 35 | var normal = Vector3.Zero; 36 | if (index.normal != null) 37 | normal = new Vector3(result.Model.Normals[(int)index.normal].x, result.Model.Normals[(int)index.normal].y, result.Model.Normals[(int)index.normal].z); 38 | 39 | var texCoord = Vector2.Zero; 40 | if (index.uv != null) 41 | texCoord = new Vector2(result.Model.Uvs[(int)index.uv].u, result.Model.Uvs[(int)index.uv].v); 42 | 43 | return new RenderVertex(position, normal, texCoord); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 SMG 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Projects/SFGenericModel/MeshEventArgs/AttribSetEventArgs.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | using SFGenericModel.VertexAttributes; 3 | using System; 4 | 5 | namespace SFGenericModel.MeshEventArgs 6 | { 7 | /// 8 | /// Contains the data used to set a shader uniform variable. 9 | /// 10 | public class AttribSetEventArgs : EventArgs 11 | { 12 | /// 13 | /// The name of the attribute variable. 14 | /// 15 | public string Name { get; } 16 | 17 | /// 18 | /// The data type of the attribute variable 19 | /// 20 | public VertexAttribPointerType Type { get; } 21 | 22 | /// 23 | /// The number of components. Ex: 1 for or 24 | /// 4 for . 25 | /// 26 | public ValueCount ValueCount { get; } 27 | 28 | /// 29 | /// 30 | /// 31 | /// The name of the attribute 32 | /// The data type of the attribute 33 | /// The number of vector components or 1 for scalars 34 | public AttribSetEventArgs(string name, VertexAttribPointerType type, ValueCount valueCount) 35 | { 36 | Name = name; 37 | Type = type; 38 | ValueCount = valueCount; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Projects/SFGenericModel/SFGenericModel.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | bin\release\$(TargetFramework)\SFGenericModel.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ..\..\lib\OpenTK.dll 19 | true 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Projects/SFGenericModel/Utils/IndexUtils.cs: -------------------------------------------------------------------------------- 1 | namespace SFGenericModel.Utils 2 | { 3 | /// 4 | /// Contains methods for generating and manipulating vertex indices. 5 | /// 6 | public static class IndexUtils 7 | { 8 | /// 9 | /// Generates consecutive indices starting with 0 10 | /// up to but not including . 11 | /// 12 | /// The number of indices to generate 13 | /// Generated consecutive indices 14 | public static int[] GenerateIndices(int count) 15 | { 16 | var result = new int[count]; 17 | for (int i = 0; i < result.Length; i++) 18 | { 19 | result[i] = i; 20 | } 21 | return result; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Projects/SFGenericModel/VertexAttributes/VertexFloatAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace SFGenericModel.VertexAttributes 4 | { 5 | /// 6 | /// A floating point vertex attribute. Integer types are converted directly to floats. 7 | /// 8 | public sealed class VertexFloatAttribute : VertexAttribute 9 | { 10 | /// 11 | /// When true, integer values are converted to floats. Ex: float = int / INT_MAX 12 | /// 13 | public bool Normalized { get; } 14 | 15 | /// 16 | /// 17 | /// 18 | /// The name of the attribute in the shader 19 | /// The number of components for the value 20 | /// The data type of the value 21 | /// is not an implemented attribute type. 22 | public VertexFloatAttribute(string name, ValueCount valueCount, VertexAttribPointerType type, bool normalized) : base(name, valueCount, type) 23 | { 24 | Normalized = normalized; 25 | SizeInBytes = (int)valueCount * AttribPointerUtils.GetSizeInBytes(type); 26 | } 27 | 28 | /// 29 | /// Configures the vertex attribute for the currently bound array buffer. 30 | /// 31 | /// The index of the attribute variable in the shader 32 | /// The vertex size in bytes 33 | /// The offset in bytes of the attribute in the vertex 34 | public override void SetVertexAttribute(int index, int strideInBytes, int offsetInBytes) 35 | { 36 | GL.VertexAttribPointer(index, (int)ValueCount, Type, Normalized, strideInBytes, offsetInBytes); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Projects/SFGenericModel/VertexAttributes/VertexIntAttribute.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace SFGenericModel.VertexAttributes 4 | { 5 | /// 6 | /// A vertex attribute that preserves integer values. Only integer types are supported. 7 | /// 8 | public sealed class VertexIntAttribute : VertexAttribute 9 | { 10 | /// 11 | /// 12 | /// 13 | /// The name of the attribute in the shader 14 | /// The number of components for the value 15 | /// The data type of the value 16 | /// is not 17 | /// a supported attribute type. 18 | public VertexIntAttribute(string name, ValueCount valueCount, VertexAttribIntegerType type) : base(name, valueCount, (VertexAttribPointerType)type) 19 | { 20 | // The default attribute pointer type enum contains all the integer values. 21 | SizeInBytes = (int)valueCount * AttribPointerUtils.GetSizeInBytes(type); 22 | } 23 | 24 | /// 25 | /// Configures the vertex attribute for the currently bound array buffer. 26 | /// 27 | /// The index of the attribute variable in the shader 28 | /// The vertex size in bytes 29 | /// The offset in bytes of the attribute in the vertex 30 | public override void SetVertexAttribute(int index, int strideInBytes, int offsetInBytes) 31 | { 32 | GL.VertexAttribIPointer(index, (int)ValueCount, (VertexAttribIntegerType)Type, strideInBytes, new System.IntPtr(offsetInBytes)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Projects/SFGraphics.Controls/SFGraphics.Controls.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | bin\release\$(TargetFramework)\SFGraphics.Controls.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ..\..\lib\OpenTK.GLControl.dll 19 | true 20 | 21 | 22 | ..\..\lib\OpenTK.dll 23 | true 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Projects/SFGraphics.ShaderGen/GlslParsing.cs: -------------------------------------------------------------------------------- 1 | using SFGraphics.ShaderGen.GlslShaderUtils; 2 | using System.Collections.Generic; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace SFGraphics.ShaderGen 6 | { 7 | public static class GlslParsing 8 | { 9 | public static List GetUniforms(string shaderSource) 10 | { 11 | var uniforms = new List(); 12 | 13 | foreach (Match match in Regex.Matches(shaderSource, @"uniform .* .*;")) 14 | { 15 | var parts = match.Value.Split(' '); 16 | uniforms.Add(new ShaderUniform(parts[2].TrimEnd(';'), parts[1])); 17 | } 18 | return uniforms; 19 | } 20 | 21 | public static List GetAttributes(string shaderSource) 22 | { 23 | var uniforms = new List(); 24 | 25 | foreach (Match match in Regex.Matches(shaderSource, @"in .* .*;")) 26 | { 27 | var parts = match.Value.Split(' '); 28 | var name = parts[2].TrimEnd(';'); 29 | uniforms.Add(new ShaderAttribute(name, parts[1])); 30 | } 31 | return uniforms; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Projects/SFGraphics.ShaderGen/GlslShaderUtils/CaseStatement.cs: -------------------------------------------------------------------------------- 1 | namespace SFGraphics.ShaderGen.GlslShaderUtils 2 | { 3 | /// 4 | /// Stores information for the cases of a switch statement. 5 | /// 6 | internal class CaseStatement 7 | { 8 | /// 9 | /// The value for this case. 10 | /// 11 | public string SwitchValue { get; } 12 | 13 | /// 14 | /// The code to be executed. 15 | /// 16 | public string CaseBody { get; } 17 | 18 | public CaseStatement(string switchValue, string caseBody) 19 | { 20 | SwitchValue = switchValue; 21 | CaseBody = caseBody; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Projects/SFGraphics.ShaderGen/GlslShaderUtils/SwitchUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | 4 | namespace SFGraphics.ShaderGen.GlslShaderUtils 5 | { 6 | internal static class SwitchUtils 7 | { 8 | public static void AppendSwitchStatement(StringBuilder shaderSource, string switchVariable, List cases) 9 | { 10 | AppendBeginSwitch(shaderSource, switchVariable); 11 | foreach (var caseStatement in cases) 12 | { 13 | AppendSwitchCaseStatement(shaderSource, caseStatement); 14 | } 15 | AppendEndSwitch(shaderSource); 16 | } 17 | 18 | private static void AppendSwitchCaseStatement(StringBuilder shaderSource, CaseStatement caseStatement) 19 | { 20 | shaderSource.AppendLine($"\t\tcase {caseStatement.SwitchValue}:"); 21 | shaderSource.AppendLine($"\t\t\t{caseStatement.CaseBody}"); 22 | shaderSource.AppendLine("\t\t\tbreak;"); 23 | } 24 | 25 | private static void AppendBeginSwitch(StringBuilder shaderSource, string switchVariable) 26 | { 27 | shaderSource.AppendLine($"\tswitch ({switchVariable})"); 28 | shaderSource.AppendLine("\t{"); 29 | } 30 | 31 | private static void AppendEndSwitch(StringBuilder shaderSource) 32 | { 33 | shaderSource.AppendLine("\t}"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Projects/SFGraphics.ShaderGen/SFGraphics.ShaderGen.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | bin\release\$(TargetFramework)\SFGraphics.ShaderGen.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ..\..\lib\OpenTK.dll 19 | true 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Projects/SFGraphics.Timing/SFGraphics.Timing.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | bin\release\$(TargetFramework)\SFGraphics.Timing.xml 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Projects/SFGraphics.Utils/BitmapUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using System.Drawing.Imaging; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace SFGraphics.Utils 6 | { 7 | /// 8 | /// Contains methods for working with images. 9 | /// 10 | public static class BitmapUtils 11 | { 12 | /// 13 | /// Creates a from ABGR pixel data. 14 | /// 15 | /// The width in pixels of the image data 16 | /// The height in pixels of the image data 17 | /// ABGR image pixels 18 | /// A new image with the given image data 19 | public static Bitmap GetBitmap(int width, int height, byte[] imageData) 20 | { 21 | Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); 22 | 23 | BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bmp.PixelFormat); 24 | Marshal.Copy(imageData, 0, bmpData.Scan0, imageData.Length); 25 | 26 | bmp.UnlockBits(bmpData); 27 | return bmp; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Projects/SFGraphics.Utils/SFGraphics.Utils.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | bin\release\$(TargetFramework)\SFGraphics.Utils.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ..\..\lib\OpenTK.dll 19 | true 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/BufferObjects/BufferExceptionMessages.cs: -------------------------------------------------------------------------------- 1 | namespace SFGraphics.GLObjects.BufferObjects 2 | { 3 | internal static class BufferExceptionMessages 4 | { 5 | public static readonly string outOfRange = "The data read from or written to a buffer must not exceed the buffer's storage."; 6 | 7 | public static readonly string bufferNotDivisibleByRequestedType = "The buffer data is not divisible by the requested type's size."; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Framebuffers/IFramebufferAttachment.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace SFGraphics.GLObjects.Framebuffers 4 | { 5 | /// 6 | /// Contains methods for attaching to a 7 | /// 8 | public interface IFramebufferAttachment 9 | { 10 | /// 11 | /// Binds the object to for 12 | /// . 13 | /// 14 | /// The attachment point 15 | /// The target framebuffer for attachment 16 | void Attach(FramebufferAttachment attachment, Framebuffer target); 17 | 18 | /// 19 | /// The width of the attachment in pixels. 20 | /// 21 | int Width { get; } 22 | 23 | /// 24 | /// The height of the attachment in pixels. 25 | /// 26 | int Height { get; } 27 | } 28 | } -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Shaders/ShaderEventArgs/LinkStatusEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SFGraphics.GLObjects.Shaders.ShaderEventArgs 4 | { 5 | /// 6 | /// Contains information about a shader program linking. 7 | /// 8 | public class LinkStatusEventArgs : EventArgs 9 | { 10 | /// 11 | /// true if the shader program linked successfully. 12 | /// 13 | public bool LinkStatus { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Shaders/ShaderEventArgs/TextureSetEventArgs.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | using System; 3 | 4 | namespace SFGraphics.GLObjects.Shaders.ShaderEventArgs 5 | { 6 | /// 7 | /// Contains the data used to set a shader sampler uniform variable. 8 | /// 9 | public class TextureSetEventArgs : EventArgs 10 | { 11 | /// 12 | /// The name of the uniform variable. 13 | /// 14 | public string Name { get; set; } 15 | 16 | /// 17 | /// The data type of the texture uniform. 18 | /// 19 | public ActiveUniformType Type { get; set; } 20 | 21 | /// 22 | /// The texture used to initialize the uniform variable. 23 | /// 24 | public Textures.Texture Value { get; set; } 25 | 26 | /// 27 | /// The texture unit to which was bound. 28 | /// 29 | public int TextureUnit { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Shaders/ShaderEventArgs/UniformSetEventArgs.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | using System; 3 | 4 | namespace SFGraphics.GLObjects.Shaders.ShaderEventArgs 5 | { 6 | /// 7 | /// Contains the data used to set a shader uniform variable. 8 | /// 9 | public class UniformSetEventArgs : EventArgs 10 | { 11 | /// 12 | /// The name of the uniform variable. 13 | /// 14 | public string Name { get; set; } 15 | 16 | /// 17 | /// The data type of the uniform. 18 | /// 19 | public ActiveUniformType Type { get; set; } 20 | 21 | /// 22 | /// The value used to initialize the uniform variable. 23 | /// 24 | public object Value { get; set; } 25 | 26 | /// 27 | /// The number of components for . 28 | /// 29 | public int Size { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Shaders/Utils/ActiveAttribInfo.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace SFGraphics.GLObjects.Shaders.Utils 4 | { 5 | internal struct ActiveAttribInfo 6 | { 7 | public readonly int location; 8 | 9 | public readonly ActiveAttribType type; 10 | 11 | public readonly int size; 12 | 13 | public ActiveAttribInfo(int location, ActiveAttribType type, int size) 14 | { 15 | this.location = location; 16 | this.type = type; 17 | this.size = size; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Shaders/Utils/ActiveUniformInfo.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace SFGraphics.GLObjects.Shaders.Utils 4 | { 5 | internal struct ActiveUniformInfo 6 | { 7 | public readonly int location; 8 | 9 | public readonly ActiveUniformType type; 10 | 11 | public readonly int size; 12 | 13 | public ActiveUniformInfo(int location, ActiveUniformType type, int size = 1) 14 | { 15 | this.location = location; 16 | this.type = type; 17 | this.size = size; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Shaders/Utils/ShaderTypeConversions.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace SFGraphics.GLObjects.Shaders.Utils 6 | { 7 | internal static class ShaderTypeConversions 8 | { 9 | private static readonly Dictionary uniformTypeByTextureTarget = new Dictionary() 10 | { 11 | { TextureTarget.Texture2D, ActiveUniformType.Sampler2D }, 12 | { TextureTarget.TextureCubeMap, ActiveUniformType.SamplerCube }, 13 | { TextureTarget.Texture3D, ActiveUniformType.Sampler3D } 14 | }; 15 | 16 | public static ActiveUniformType GetUniformType(TextureTarget target) 17 | { 18 | if (!uniformTypeByTextureTarget.ContainsKey(target)) 19 | throw new NotImplementedException($"{target.ToString()} is not supported"); 20 | else 21 | return uniformTypeByTextureTarget[target]; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Shaders/Utils/ShaderValidation.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace SFGraphics.GLObjects.Shaders.Utils 4 | { 5 | internal static class ShaderValidation 6 | { 7 | /// 8 | /// Returns true if the program linked successfully. 9 | /// 10 | /// The program ID generated by OpenGL 11 | /// true if the program linked successfully 12 | public static bool GetProgramLinkStatus(int programId) 13 | { 14 | // 1: linked successfully, 0: linker errors 15 | GL.GetProgram(programId, GetProgramParameterName.LinkStatus, out int linkStatus); 16 | return linkStatus != 0; 17 | } 18 | 19 | /// 20 | /// Returns true if the program status is valid for rendering. 21 | /// 22 | /// The program ID generated by OpenGL 23 | /// true if the program status is valid for rendering 24 | public static bool GetProgramValidateStatus(int programId) 25 | { 26 | // 1: valid, 0: not valid 27 | GL.ValidateProgram(programId); 28 | GL.GetProgram(programId, GetProgramParameterName.ValidateStatus, out int validateStatus); 29 | return validateStatus != 0; 30 | } 31 | 32 | public static bool GetShaderObjectCompileStatus(int shaderId) 33 | { 34 | // 1: compiled successfully, 0: errors in compilation. 35 | GL.GetShader(shaderId, ShaderParameter.CompileStatus, out int compileStatus); 36 | return compileStatus != 0; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Textures/DepthTexture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Textures.TextureFormats; 4 | using SFGraphics.GLObjects.Textures.Utils; 5 | 6 | namespace SFGraphics.GLObjects.Textures 7 | { 8 | /// 9 | /// A simple texture for storing depth information. 10 | /// The texture can be attached to a object for shadow mapping and other effects. 11 | /// 12 | public class DepthTexture : Texture 13 | { 14 | /// 15 | /// Creates an empty depth texture of the specified dimensions and format. 16 | /// This texture does not use mipmaps. 17 | /// The border color is set to white, so attempts to sample outside the texture's border will return white. 18 | /// 19 | /// The width of the texture in pixels 20 | /// The height of the texture in pixels 21 | /// The internal format of the image data. This should be a valid depth format. 22 | /// The format is not a valid depth format. 23 | public DepthTexture(int width, int height, PixelInternalFormat pixelInternalFormat) : base(TextureTarget.Texture2D) 24 | { 25 | // Only certain formats are valid for a depth attachment. 26 | if (!TextureFormatTools.IsDepthFormat(pixelInternalFormat)) 27 | throw new ArgumentException(TextureExceptionMessages.invalidDepthTexFormat); 28 | 29 | Width = width; 30 | Height = height; 31 | 32 | // Set texture settings. 33 | Bind(); 34 | GL.TexImage2D(TextureTarget.Texture2D, 0, pixelInternalFormat, Width, Height, 0, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero); 35 | MagFilter = TextureMagFilter.Nearest; 36 | MinFilter = TextureMinFilter.Nearest; 37 | 38 | // Use white for values outside the depth map's border. 39 | TextureWrapS = TextureWrapMode.ClampToBorder; 40 | TextureWrapT = TextureWrapMode.ClampToBorder; 41 | GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, new float[] { 1, 1, 1, 1 }); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Textures/Texture2DMultiSample.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace SFGraphics.GLObjects.Textures 4 | { 5 | /// 6 | /// A TextureTarget.Texture2DMultisample texture that does not support mipmaps. 7 | /// 8 | public class Texture2DMultisample : Texture 9 | { 10 | /// 11 | /// The number of texture samples. 12 | /// 13 | int Samples { get; } 14 | 15 | /// 16 | /// Creates a multisampled 2D texture of the given dimensions and format 17 | /// 18 | /// The width of the texture in pixels 19 | /// The height of the texture in pixels 20 | /// The format used to store the image data 21 | /// The number of texture samples 22 | public Texture2DMultisample(int width, int height, PixelInternalFormat format, 23 | int samples) : base(TextureTarget.Texture2DMultisample) 24 | { 25 | Samples = samples; 26 | if (Samples <= 0) 27 | throw new System.ArgumentOutOfRangeException(nameof(samples), "Sample count must be greater than 0"); 28 | 29 | SetDimensionsAndFormat(width, height, format); 30 | } 31 | 32 | private void SetDimensionsAndFormat(int width, int height, PixelInternalFormat format) 33 | { 34 | Width = width; 35 | Height = height; 36 | 37 | Bind(); 38 | GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, Samples, format, 39 | width, height, true); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Textures/Texture3D.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace SFGraphics.GLObjects.Textures 4 | { 5 | /// 6 | /// A TextureTarget.Texture3D texture designed for 3D lookup tables. 7 | /// 8 | public class Texture3D : Texture 9 | { 10 | /// 11 | /// The depth of the base mip level in pixels. 12 | /// 13 | public int Depth { get; protected set; } 14 | 15 | /// 16 | /// Creates an empty 3D texture. 17 | /// The texture is incomplete until the dimensions and format are set. 18 | /// 19 | public Texture3D() : base(TextureTarget.Texture3D) 20 | { 21 | 22 | } 23 | 24 | /// 25 | /// Loads uncompressed texture data of the specified format for the first mip level. 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | public void LoadImageData(int width, int height, int depth, T[] imageData, TextureFormats.TextureFormatUncompressed format) where T : struct 34 | { 35 | Width = width; 36 | Height = height; 37 | Depth = depth; 38 | 39 | Bind(); 40 | GL.TexImage3D(TextureTarget, 0, format.pixelInternalFormat, width, height, depth, 0, format.pixelFormat, format.pixelType, imageData); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Textures/TextureFormats/CompressedBlockSize.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace SFGraphics.GLObjects.Textures.TextureFormats 4 | { 5 | internal static class CompressedBlockSize 6 | { 7 | /// 8 | /// A string is used instead of the enum because there are Ext versions of 9 | /// some enum values with identical associated integers. 10 | /// 11 | public static readonly Dictionary blockSizeByFormat = new Dictionary 12 | { 13 | { "CompressedR11Eac", 8}, 14 | { "CompressedRedRgtc1", 8}, 15 | { "CompressedRedRgtc1Ext", 8}, 16 | { "CompressedRg11Eac", 16}, 17 | { "CompressedRgRgtc2", 16}, 18 | { "CompressedRgb8Etc2", 8}, 19 | { "CompressedRgb8PunchthroughAlpha1Etc2", 8}, 20 | { "CompressedRgbBptcSignedFloat", 16}, 21 | { "CompressedRgbBptcUnsignedFloat", 16}, 22 | { "CompressedRgbS3tcDxt1Ext", 8}, 23 | { "CompressedRgba8Etc2Eac", 16}, 24 | { "CompressedRgbaBptcUnorm", 16}, 25 | { "CompressedRgbaS3tcDxt1Ext", 8}, 26 | { "CompressedRgbaS3tcDxt3Ext", 16}, 27 | { "CompressedRgbaS3tcDxt5Ext", 16}, 28 | { "CompressedSignedR11Eac", 8}, 29 | { "CompressedSignedRedRgtc1", 8}, 30 | { "CompressedSignedRedRgtc1Ext", 8}, 31 | { "CompressedSignedRg11Eac", 16}, 32 | { "CompressedSignedRgRgtc2", 16}, 33 | { "CompressedSrgb8Alpha8Etc2Eac", 16}, 34 | { "CompressedSrgb8Etc2", 8}, 35 | { "CompressedSrgb8PunchthroughAlpha1Etc2", 8}, 36 | { "CompressedSrgbAlphaBptcUnorm", 16}, 37 | { "CompressedSrgbAlphaS3tcDxt1Ext", 8}, 38 | { "CompressedSrgbAlphaS3tcDxt3Ext", 16}, 39 | { "CompressedSrgbAlphaS3tcDxt5Ext", 16}, 40 | { "CompressedSrgbS3tcDxt1Ext", 8} 41 | }; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Textures/TextureFormats/TextureFormatUncompressed.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Textures.Utils; 4 | 5 | namespace SFGraphics.GLObjects.Textures.TextureFormats 6 | { 7 | /// 8 | /// Stores uncompressed texture format information. 9 | /// 10 | public struct TextureFormatUncompressed 11 | { 12 | /// 13 | /// The format used by OpenGL to store the data 14 | /// 15 | public readonly PixelInternalFormat pixelInternalFormat; 16 | 17 | /// 18 | /// The format of the color components for the input data. 19 | /// 20 | public readonly PixelFormat pixelFormat; 21 | 22 | /// 23 | /// The data type of each color component for the input data 24 | /// 25 | public readonly PixelType pixelType; 26 | 27 | /// 28 | /// Initializes the format information for an uncompressed format. 29 | /// 30 | /// The format used by OpenGL to store the data 31 | /// The format of the color components for the input data 32 | /// The data type of each color component for the input data 33 | /// is a compressed format. 34 | public TextureFormatUncompressed(PixelInternalFormat pixelInternalFormat, PixelFormat pixelFormat, PixelType pixelType) 35 | { 36 | if (TextureFormatTools.IsCompressed(pixelInternalFormat)) 37 | throw new ArgumentException(TextureExceptionMessages.expectedUncompressed); 38 | 39 | this.pixelInternalFormat = pixelInternalFormat; 40 | this.pixelFormat = pixelFormat; 41 | this.pixelType = pixelType; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/Textures/Utils/TextureExceptionMessages.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace SFGraphics.GLObjects.Textures.Utils 3 | { 4 | /// 5 | /// Error messages thrown by constructors for classes inheriting from . 6 | /// 7 | internal static class TextureExceptionMessages 8 | { 9 | public static readonly string expectedCompressed = "The InternalFormat is not " + 10 | "a compressed image format."; 11 | 12 | public static readonly string expectedUncompressed = "The PixelInternalFormat is not " + 13 | "an uncompressed image format."; 14 | 15 | public static readonly string cubeFaceMipCountDifferent = "Mipmap count is not equal for all faces."; 16 | 17 | public static readonly string invalidDepthTexFormat = "The PixelInternalFormat is not a valid depth component format."; 18 | 19 | public static readonly string genericCompressedFormat = "Generic compressed formats are not supported."; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Projects/SFGraphics/GLObjects/VertexArrays/VertexArrayObject.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace SFGraphics.GLObjects.VertexArrays 4 | { 5 | /// 6 | /// Encapsulates an OpenGL vertex array object. 7 | /// Vertex array objects cannot be shared between contexts. 8 | /// 9 | public sealed class VertexArrayObject : GLObject 10 | { 11 | internal override GLObjectType ObjectType => GLObjectType.VertexArrayObject; 12 | 13 | /// 14 | /// Creates an empty vertex array object. 15 | /// The vertex array object must first be bound with . 16 | /// 17 | public VertexArrayObject() : base(GL.GenVertexArray()) 18 | { 19 | 20 | } 21 | 22 | /// 23 | /// Binds the vertex array 24 | /// 25 | public void Bind() 26 | { 27 | GL.BindVertexArray(Id); 28 | } 29 | 30 | /// 31 | /// Binds the default vertex array value of 0. 32 | /// 33 | public void Unbind() 34 | { 35 | GL.BindVertexArray(0); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Projects/SFGraphics/SFGraphics.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | bin\release\$(TargetFramework)\SFGraphics.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ..\..\lib\OpenTK.dll 19 | true 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Projects/SFShaderLoader/SFShaderLoader.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | bin\release\$(TargetFramework)\SFShaderLoader.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ..\..\lib\OpenTK.dll 19 | true 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Projects/SFShapes/Mesh3D.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | using SFGenericModel; 3 | using SFGenericModel.VertexAttributes; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace SFShapes 8 | { 9 | /// 10 | /// Draws simple geometry given a collection of vertex positions. 11 | /// 12 | public class Mesh3D : GenericMesh 13 | { 14 | /// 15 | /// 16 | /// 17 | /// The points for the shape 18 | /// Determines how the shape should be drawn 19 | public Mesh3D(Vertex3d[] vertices, PrimitiveType primitiveType) : base(vertices, primitiveType) 20 | { 21 | 22 | } 23 | 24 | /// 25 | /// 26 | /// 27 | /// The points of the shape 28 | public Mesh3D(Tuple vertices) : base(vertices.Item1, vertices.Item2) 29 | { 30 | 31 | } 32 | 33 | /// 34 | /// 35 | /// 36 | /// 37 | public static List GetRenderAttributes() 38 | { 39 | return new List() 40 | { 41 | new VertexFloatAttribute("position", ValueCount.Three, VertexAttribPointerType.Float, false) 42 | }; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Projects/SFShapes/SFShapes.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | bin\release\$(TargetFramework)\SFShapes.xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ..\..\lib\OpenTK.dll 19 | true 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Projects/SFShapes/ShapeExceptionMessages.cs: -------------------------------------------------------------------------------- 1 | namespace SFShapes 2 | { 3 | internal static class ShapeExceptionMessages 4 | { 5 | public static readonly string invalidSphereRadius = "Radius must be positive and non zero."; 6 | 7 | public static readonly string invalidSpherePrecision = "Precision must be greater than the required minimum."; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Projects/SFShapes/Vertex3d.cs: -------------------------------------------------------------------------------- 1 | using OpenTK; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGenericModel.VertexAttributes; 4 | 5 | namespace SFShapes 6 | { 7 | /// 8 | /// A simple struct for rendering a 3d vertex. 9 | /// 10 | public struct Vertex3d 11 | { 12 | /// 13 | /// The position of the vertex 14 | /// 15 | [VertexFloatAttribute("position", ValueCount.Three, VertexAttribPointerType.Float, false)] 16 | public Vector3 Position { get; } 17 | 18 | /// 19 | /// Creates a new vertex from the given coordinates 20 | /// 21 | /// The vertex coordinates 22 | public Vertex3d(Vector3 position) 23 | { 24 | Position = position; 25 | } 26 | 27 | /// 28 | /// Creates a new vertex from the given coordinates 29 | /// 30 | /// The x coordinate 31 | /// The y coordinate 32 | /// The z coordinate 33 | public Vertex3d(float x, float y, float z) 34 | { 35 | Position = new Vector3(x, y, z); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Test Projects/RenderTestUtils/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("RenderTestUtils")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("RenderTestUtils")] 12 | [assembly: AssemblyCopyright("Copyright © 2018")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("53cbdea3-f60c-4b16-b57f-21b6ce665040")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Test Projects/RenderTestUtils/Shaders/invalid.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | out vec4 fragColor; 4 | 5 | void main() 6 | { 7 | memes; 8 | fragColor = vec4(1); 9 | } 10 | -------------------------------------------------------------------------------- /Test Projects/RenderTestUtils/Shaders/invalid.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec3 position; 4 | out vec3 outPosition; 5 | 6 | void main() 7 | { 8 | memes; 9 | glPosition = vec4(1); 10 | } -------------------------------------------------------------------------------- /Test Projects/RenderTestUtils/Shaders/undefinedFunction.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | out vec4 fragColor; 4 | 5 | uniform vec3 vec3Uniform2; 6 | uniform vec3 vec3Uniform; 7 | 8 | vec3 notDefined(); 9 | 10 | void main() 11 | { 12 | fragColor.rgb = vec3Uniform2 * vec3Uniform * notDefined(); 13 | } -------------------------------------------------------------------------------- /Test Projects/RenderTestUtils/Shaders/valid.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform float float1; 4 | uniform float floatArray1[3]; 5 | 6 | uniform uint uint1; 7 | uniform uint uintArray1[3]; 8 | uniform int int1; 9 | uniform int boolInt1; 10 | uniform int intArray1[3]; 11 | 12 | uniform vec2 vector2a; 13 | uniform vec2[2] vector2Arr; 14 | 15 | uniform vec3 vector3a; 16 | uniform vec3[2] vector3Arr; 17 | 18 | uniform vec4 vector4a; 19 | uniform vec4[2] vector4Arr; 20 | 21 | uniform mat4 matrix4a; 22 | uniform mat4[2] matrix4Arr; 23 | 24 | uniform sampler2D tex2D; 25 | uniform samplerCube texCube; 26 | 27 | uniform UniformBlockA 28 | { 29 | float blockAFloat; 30 | vec4 blockAVec4; 31 | }; 32 | 33 | out vec4 fragColor; 34 | 35 | void main() 36 | { 37 | // Use all the uniforms, so they aren't optimized out by the compiler. 38 | fragColor = vec4(1) * float1 * int1; 39 | if (boolInt1 == 1) 40 | fragColor *= 0.5; 41 | fragColor.rg *= vector2a; 42 | fragColor.rgb *= vector3a; 43 | fragColor *= vector4a * matrix4a; 44 | fragColor *= texture(tex2D, vec2(1)); 45 | fragColor *= texture(texCube, vec3(1)); 46 | fragColor.rgb *= blockAFloat; 47 | 48 | 49 | // Use a for loop to access multiple elements. 50 | for (int i = 0; i < 2; i++) 51 | { 52 | fragColor *= floatArray1[i]; 53 | fragColor *= intArray1[i]; 54 | fragColor *= uintArray1[i]; 55 | 56 | fragColor *= matrix4Arr[i]; 57 | fragColor.rg *= vector2Arr[i]; 58 | fragColor *= vector4Arr[i]; 59 | fragColor.rgb *= vector3Arr[i]; 60 | } 61 | 62 | fragColor.rgb *= blockAVec4.rgb; 63 | 64 | fragColor.rgb *= uint1; 65 | } 66 | -------------------------------------------------------------------------------- /Test Projects/RenderTestUtils/Shaders/valid.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec3 position; 4 | in int intAttrib; 5 | 6 | out vec3 outPosition; 7 | 8 | void main() 9 | { 10 | gl_Position = vec4(position, 1) * intAttrib; 11 | } -------------------------------------------------------------------------------- /Test Projects/RenderTestUtils/TestTools/OpenTKWindowlessContext.cs: -------------------------------------------------------------------------------- 1 | using OpenTK; 2 | using OpenTK.Graphics; 3 | 4 | namespace RenderTestUtils 5 | { 6 | public static class OpenTKWindowlessContext 7 | { 8 | /// 9 | /// Creates and binds a dummy context, so OpenGL functions will work. 10 | /// If a context is already bound, no context is created. 11 | /// 12 | /// OpenGL major version 13 | /// OpenGL minor version 14 | public static void BindDummyContext(int major = 3, int minor = 3) 15 | { 16 | if (GraphicsContext.CurrentContext == null) 17 | { 18 | GameWindow window = new GameWindow(640, 480, GraphicsMode.Default, "", GameWindowFlags.Default, 19 | DisplayDevice.Default, major, minor, GraphicsContextFlags.Default); 20 | window.Visible = false; 21 | window.MakeCurrent(); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Test Projects/RenderTestUtils/TestTools/ResourceShaders.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Reflection; 3 | 4 | namespace RenderTestUtils 5 | { 6 | public static class ResourceShaders 7 | { 8 | public static string GetShaderSource(string shaderName) 9 | { 10 | string fullName = $"RenderTestUtils.Shaders.{shaderName}"; 11 | return GetResourceText(fullName); 12 | } 13 | 14 | private static string GetResourceText(string resourceName) 15 | { 16 | Assembly assembly = Assembly.GetExecutingAssembly(); 17 | 18 | string result = ""; 19 | Stream stream = assembly.GetManifestResourceStream(resourceName); 20 | using (StreamReader reader = new StreamReader(stream)) 21 | { 22 | result = reader.ReadToEnd(); 23 | } 24 | 25 | return result; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test Projects/RenderTestUtils/TestTools/ShaderTestUtils.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | using SFGraphics.GLObjects.Shaders; 3 | using System; 4 | 5 | namespace RenderTestUtils 6 | { 7 | public static class ShaderTestUtils 8 | { 9 | public static Shader CreateValidShader() 10 | { 11 | Shader shader = new Shader(); 12 | 13 | string fragSource = ResourceShaders.GetShaderSource("valid.frag"); 14 | string vertSource = ResourceShaders.GetShaderSource("valid.vert"); 15 | 16 | shader.LoadShaders( 17 | new ShaderObject(fragSource, ShaderType.FragmentShader), 18 | new ShaderObject(vertSource, ShaderType.VertexShader)); 19 | 20 | shader.UseProgram(); 21 | 22 | return shader; 23 | } 24 | 25 | public static string GetInvalidUniformErrorMessage(string name, ActiveUniformType type) 26 | { 27 | return $"[Warning] Attempted to set undeclared uniform variable {name} of type {type}"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyTitle("SFGenericModel.Test")] 5 | [assembly: AssemblyDescription("")] 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("SFGenericModel.Test")] 9 | [assembly: AssemblyCopyright("Copyright © 2018")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: Guid("7be87b94-ca49-4f44-905a-298ded4884f9")] 16 | 17 | // [assembly: AssemblyVersion("1.0.*")] 18 | [assembly: AssemblyVersion("1.0.0.0")] 19 | [assembly: AssemblyFileVersion("1.0.0.0")] 20 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/AttribPointerSize.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGenericModel.VertexAttributes; 4 | 5 | namespace SFGenericModel.Test.AttribPointerUtilsTest 6 | { 7 | [TestClass] 8 | public class AttribPointerSize 9 | { 10 | [TestMethod] 11 | public void Byte() 12 | { 13 | CheckAttribPointerSize(sizeof(byte), VertexAttribPointerType.Byte); 14 | } 15 | 16 | [TestMethod] 17 | public void UnsignedByte() 18 | { 19 | CheckAttribPointerSize(sizeof(byte), VertexAttribPointerType.UnsignedByte); 20 | } 21 | 22 | [TestMethod] 23 | public void Int() 24 | { 25 | CheckAttribPointerSize(sizeof(int), VertexAttribPointerType.Int); 26 | } 27 | 28 | [TestMethod] 29 | public void UnsignedInt() 30 | { 31 | CheckAttribPointerSize(sizeof(int), VertexAttribPointerType.UnsignedInt); 32 | } 33 | 34 | [TestMethod] 35 | public void Short() 36 | { 37 | CheckAttribPointerSize(sizeof(short), VertexAttribPointerType.Short); 38 | } 39 | 40 | [TestMethod] 41 | public void UnsignedShort() 42 | { 43 | CheckAttribPointerSize(sizeof(short), VertexAttribPointerType.UnsignedShort); 44 | } 45 | 46 | [TestMethod] 47 | public void Float() 48 | { 49 | CheckAttribPointerSize(sizeof(float), VertexAttribPointerType.Float); 50 | } 51 | 52 | [TestMethod] 53 | public void HalfFloat() 54 | { 55 | CheckAttribPointerSize(sizeof(float) / 2, VertexAttribPointerType.HalfFloat); 56 | } 57 | 58 | [TestMethod] 59 | public void Double() 60 | { 61 | CheckAttribPointerSize(sizeof(double), VertexAttribPointerType.Double); 62 | } 63 | 64 | private static void CheckAttribPointerSize(int expected, VertexAttribPointerType type) 65 | { 66 | Assert.AreEqual(expected, AttribPointerUtils.GetSizeInBytes(type)); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/GenericMeshNonInterleavedTests/AddBuffer.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using RenderTestUtils; 4 | 5 | namespace SFGenericModel.Test.GenericMeshNonInterleavedTests 6 | { 7 | [TestClass] 8 | public class AddBuffer 9 | { 10 | private static readonly int vertexCount = 8; 11 | 12 | private class MeshA : GenericMeshNonInterleaved 13 | { 14 | public MeshA() : base(new uint[16], PrimitiveType.Triangles, vertexCount) { } 15 | } 16 | 17 | [TestInitialize] 18 | public void Initialize() 19 | { 20 | OpenTKWindowlessContext.BindDummyContext(); 21 | } 22 | 23 | [TestMethod] 24 | public void AddBufferNoExistingBuffers() 25 | { 26 | var mesh = new MeshA(); 27 | mesh.AddBuffer("buffer1", new byte[8]); 28 | } 29 | 30 | [TestMethod] 31 | public void AddMultipleBuffers() 32 | { 33 | var mesh = new MeshA(); 34 | mesh.AddBuffer("buffer1", new byte[8]); 35 | mesh.AddBuffer("buffer2", new byte[8]); 36 | mesh.AddBuffer("buffer3", new byte[8]); 37 | } 38 | 39 | [TestMethod] 40 | public void AddDuplicateBuffer() 41 | { 42 | var mesh = new MeshA(); 43 | mesh.AddBuffer("buffer1", new byte[8]); 44 | var e = Assert.ThrowsException(() => mesh.AddBuffer("buffer1", new byte[8])); 45 | Assert.IsTrue(e.Message.Contains("A buffer with the given name already exists.")); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/GenericMeshNonInterleavedTests/AddBufferFromExistingBuffer.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using RenderTestUtils; 4 | using SFGraphics.GLObjects.BufferObjects; 5 | 6 | namespace SFGenericModel.Test.GenericMeshNonInterleavedTests 7 | { 8 | [TestClass] 9 | public class AddBufferFromExisting 10 | { 11 | private static readonly int vertexCount = 8; 12 | private static BufferObject meshBuffer; 13 | 14 | private class MeshA : GenericMeshNonInterleaved 15 | { 16 | public MeshA() : base(new uint[16], PrimitiveType.Triangles, vertexCount) { } 17 | } 18 | 19 | [TestInitialize] 20 | public void Initialize() 21 | { 22 | OpenTKWindowlessContext.BindDummyContext(); 23 | meshBuffer = new BufferObject(BufferTarget.ArrayBuffer); 24 | meshBuffer.SetData(new byte[8], BufferUsageHint.StaticDraw); 25 | } 26 | 27 | [TestMethod] 28 | public void AddBufferNoExistingBuffers() 29 | { 30 | var mesh = new MeshA(); 31 | mesh.AddBuffer("buffer1", meshBuffer); 32 | } 33 | 34 | [TestMethod] 35 | public void AddMultipleBuffers() 36 | { 37 | var mesh = new MeshA(); 38 | mesh.AddBuffer("buffer1", meshBuffer); 39 | mesh.AddBuffer("buffer2", meshBuffer); 40 | mesh.AddBuffer("buffer3", meshBuffer); 41 | } 42 | 43 | [TestMethod] 44 | public void AddDuplicateBuffer() 45 | { 46 | var mesh = new MeshA(); 47 | mesh.AddBuffer("buffer1", meshBuffer); 48 | var e = Assert.ThrowsException(() => mesh.AddBuffer("buffer1", meshBuffer)); 49 | Assert.IsTrue(e.Message.Contains("A buffer with the given name already exists.")); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/GenericMeshNonInterleavedTests/Constructors.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using RenderTestUtils; 4 | using SFGenericModel.VertexAttributes; 5 | using System; 6 | 7 | namespace SFGenericModel.Test.GenericMeshNonInterleavedTests 8 | { 9 | [TestClass] 10 | public class Constructors 11 | { 12 | private class MeshA : GenericMeshNonInterleaved 13 | { 14 | public MeshA(uint[] indices, int vertexCount) : base(indices, PrimitiveType.Triangles, vertexCount) { } 15 | } 16 | 17 | [TestInitialize] 18 | public void Initialize() 19 | { 20 | OpenTKWindowlessContext.BindDummyContext(); 21 | } 22 | 23 | [TestMethod] 24 | public void SetVertexCountVertexIndexCount() 25 | { 26 | var mesh = new MeshA(new uint[8], 7); 27 | Assert.AreEqual(8, mesh.VertexIndexCount); 28 | Assert.AreEqual(7, mesh.VertexCount); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/IndexUtilsTests/GenerateIndices.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System.Collections.Generic; 3 | 4 | namespace SFGenericModel.Utils.Test.IndexUtilsTests 5 | { 6 | [TestClass] 7 | public class GenerateIndices 8 | { 9 | [TestMethod] 10 | public void ZeroCount() 11 | { 12 | var indices = IndexUtils.GenerateIndices(0); 13 | Assert.AreEqual(0, indices.Length); 14 | } 15 | 16 | [TestMethod] 17 | public void NonZeroCount() 18 | { 19 | var indices = IndexUtils.GenerateIndices(3); 20 | CollectionAssert.AreEqual(new List() { 0, 1, 2 }, indices); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/RenderSettingsTests/AlphaBlendSettingsEquality.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGenericModel.RenderState; 3 | 4 | namespace SFGenericModel.Test.RenderSettingsTests 5 | { 6 | [TestClass] 7 | public class AlphaBlendSettingsEquality 8 | { 9 | [TestMethod] 10 | public void SameObject() 11 | { 12 | var settings = new AlphaBlendSettings(); 13 | var settings2 = settings; 14 | 15 | Assert.IsTrue(settings.Equals(settings2)); 16 | Assert.IsTrue(settings == settings2); 17 | Assert.IsFalse(settings != settings2); 18 | } 19 | 20 | [TestMethod] 21 | public void DifferentObjects() 22 | { 23 | var settings = new AlphaBlendSettings(); 24 | var settings2 = new AlphaBlendSettings(false, 25 | OpenTK.Graphics.OpenGL.BlendingFactor.Src1Alpha, 26 | OpenTK.Graphics.OpenGL.BlendingFactor.Src1Alpha, 27 | OpenTK.Graphics.OpenGL.BlendEquationMode.FuncReverseSubtract, 28 | OpenTK.Graphics.OpenGL.BlendEquationMode.FuncReverseSubtract); 29 | 30 | Assert.IsFalse(settings.Equals(settings2)); 31 | Assert.IsFalse(settings == settings2); 32 | Assert.IsTrue(settings != settings2); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/RenderSettingsTests/AlphaTestEquality.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGenericModel.RenderState; 3 | 4 | namespace SFGenericModel.Test.RenderSettingsTests 5 | { 6 | [TestClass] 7 | public class AlphaTestSettingsEquality 8 | { 9 | [TestMethod] 10 | public void SameObject() 11 | { 12 | var settings = new AlphaTestSettings(); 13 | var settings2 = settings; 14 | 15 | Assert.IsTrue(settings.Equals(settings2)); 16 | Assert.IsTrue(settings == settings2); 17 | Assert.IsFalse(settings != settings2); 18 | } 19 | 20 | [TestMethod] 21 | public void DifferentObjects() 22 | { 23 | var settings = new AlphaTestSettings(); 24 | var settings2 = new AlphaTestSettings(false, OpenTK.Graphics.OpenGL.AlphaFunction.Equal, 1); 25 | 26 | Assert.IsFalse(settings.Equals(settings2)); 27 | Assert.IsFalse(settings == settings2); 28 | Assert.IsTrue(settings != settings2); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/RenderSettingsTests/DepthTestSettingsEquality.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGenericModel.RenderState; 3 | 4 | namespace SFGenericModel.Test.RenderSettingsTests 5 | { 6 | [TestClass] 7 | public class DepthTestSettingsEquality 8 | { 9 | [TestMethod] 10 | public void SameObject() 11 | { 12 | var settings = new DepthTestSettings(); 13 | var settings2 = settings; 14 | 15 | Assert.IsTrue(settings.Equals(settings2)); 16 | Assert.IsTrue(settings == settings2); 17 | Assert.IsFalse(settings != settings2); 18 | } 19 | 20 | [TestMethod] 21 | public void DifferentObjects() 22 | { 23 | var settings = new DepthTestSettings(); 24 | var settings2 = new DepthTestSettings(false, false, OpenTK.Graphics.OpenGL.DepthFunction.Always); 25 | 26 | Assert.IsFalse(settings.Equals(settings2)); 27 | Assert.IsFalse(settings == settings2); 28 | Assert.IsTrue(settings != settings2); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/RenderSettingsTests/FaceCullSettingsEquality.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGenericModel.RenderState; 3 | 4 | namespace SFGenericModel.Test.RenderSettingsTests 5 | { 6 | [TestClass] 7 | public class FaceCullingSettingsEquality 8 | { 9 | [TestMethod] 10 | public void SameObject() 11 | { 12 | var settings = new FaceCullingSettings(); 13 | var settings2 = settings; 14 | 15 | Assert.IsTrue(settings.Equals(settings2)); 16 | Assert.IsTrue(settings == settings2); 17 | Assert.IsFalse(settings != settings2); 18 | } 19 | 20 | [TestMethod] 21 | public void DifferentObjects() 22 | { 23 | var settings = new FaceCullingSettings(); 24 | var settings2 = new FaceCullingSettings(false, OpenTK.Graphics.OpenGL.CullFaceMode.Front); 25 | 26 | Assert.IsFalse(settings.Equals(settings2)); 27 | Assert.IsFalse(settings == settings2); 28 | Assert.IsTrue(settings != settings2); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/RenderSettingsTests/PolygonModeSettingsEquality.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGenericModel.RenderState; 3 | 4 | namespace SFGenericModel.Test.RenderSettingsTests 5 | { 6 | [TestClass] 7 | public class PolygonModeSettingsEquality 8 | { 9 | [TestMethod] 10 | public void SameObject() 11 | { 12 | var settings = new PolygonModeSettings(); 13 | var settings2 = settings; 14 | 15 | Assert.IsTrue(settings.Equals(settings2)); 16 | Assert.IsTrue(settings == settings2); 17 | Assert.IsFalse(settings != settings2); 18 | } 19 | 20 | [TestMethod] 21 | public void DifferentObjects() 22 | { 23 | var settings = new PolygonModeSettings(); 24 | var settings2 = new PolygonModeSettings(OpenTK.Graphics.OpenGL.MaterialFace.Front, OpenTK.Graphics.OpenGL.PolygonMode.Point); 25 | 26 | Assert.IsFalse(settings.Equals(settings2)); 27 | Assert.IsFalse(settings == settings2); 28 | Assert.IsTrue(settings != settings2); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/UniformBlockTests/SetValue.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using SFGenericModel.Materials; 4 | using SFGraphics.GLObjects.Shaders; 5 | using System; 6 | 7 | namespace SFGenericModel.Test.UniformBlockTests 8 | { 9 | [TestClass] 10 | public class SetValue 11 | { 12 | private struct TestStruct 13 | { 14 | public readonly long val1; 15 | public readonly long val2; 16 | public readonly long val3; 17 | public readonly long val4; 18 | public readonly long val5; 19 | } 20 | 21 | private Shader shader; 22 | 23 | [TestInitialize] 24 | public void Initialize() 25 | { 26 | RenderTestUtils.OpenTKWindowlessContext.BindDummyContext(); 27 | if (shader == null) 28 | shader = RenderTestUtils.ShaderTestUtils.CreateValidShader(); 29 | 30 | } 31 | 32 | [TestMethod] 33 | public void ValidName() 34 | { 35 | var uniformBlock = new UniformBlock(shader, "UniformBlockA"); 36 | Assert.IsTrue(uniformBlock.SetValue("blockAFloat", 1.5f)); 37 | } 38 | 39 | [TestMethod] 40 | public void ValidNameLargerThanBlock() 41 | { 42 | var uniformBlock = new UniformBlock(shader, "UniformBlockA"); 43 | var e = Assert.ThrowsException(() => 44 | uniformBlock.SetValue("blockAFloat", new TestStruct())); 45 | } 46 | 47 | [TestMethod] 48 | public void ValidNameSmallerThanType() 49 | { 50 | var uniformBlock = new UniformBlock(shader, "UniformBlockA"); 51 | Assert.IsTrue(uniformBlock.SetValue("blockAFloat", (byte)128)); 52 | } 53 | 54 | [TestMethod] 55 | public void InvalidName() 56 | { 57 | var uniformBlock = new UniformBlock(shader, "UniformBlockA"); 58 | Assert.IsFalse(uniformBlock.SetValue("ಠ_ಠ", 1.5f)); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/UniformBlockTests/SetValues.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGenericModel.Materials; 3 | using SFGraphics.GLObjects.Shaders; 4 | using System; 5 | 6 | namespace SFGenericModel.Test.UniformBlockTests 7 | { 8 | [TestClass] 9 | public class SetValues 10 | { 11 | private Shader shader; 12 | 13 | [TestInitialize] 14 | public void Initialize() 15 | { 16 | RenderTestUtils.OpenTKWindowlessContext.BindDummyContext(); 17 | if (shader == null) 18 | shader = RenderTestUtils.ShaderTestUtils.CreateValidShader(); 19 | 20 | } 21 | 22 | [TestMethod] 23 | public void ValidName() 24 | { 25 | var uniformBlock = new UniformBlock(shader, "UniformBlockA"); 26 | Assert.IsTrue(uniformBlock.SetValues("blockAVec4", new float[4])); 27 | } 28 | 29 | [TestMethod] 30 | public void ValidNameLargerThanBlock() 31 | { 32 | var uniformBlock = new UniformBlock(shader, "UniformBlockA"); 33 | var e = Assert.ThrowsException(() => 34 | uniformBlock.SetValues("blockAVec4", new float[100])); 35 | } 36 | 37 | [TestMethod] 38 | public void InvalidName() 39 | { 40 | var uniformBlock = new UniformBlock(shader, "UniformBlockA"); 41 | Assert.IsFalse(uniformBlock.SetValues("ಠ_ಠ", new float[4])); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/Tests/VertexAttributeInfoSize.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGenericModel.VertexAttributes; 4 | 5 | namespace SFGenericModel.Test.VertexAttributeInfoTests 6 | { 7 | [TestClass] 8 | public class VertexAttributeInfoSize 9 | { 10 | [TestMethod] 11 | public void Byte() 12 | { 13 | CheckAttribPointerSizeTwoComponents(sizeof(byte) * 2, VertexAttribPointerType.Byte); 14 | } 15 | 16 | [TestMethod] 17 | public void UnsignedByte() 18 | { 19 | CheckAttribPointerSizeTwoComponents(sizeof(byte) * 2, VertexAttribPointerType.UnsignedByte); 20 | } 21 | 22 | [TestMethod] 23 | public void Int() 24 | { 25 | CheckAttribPointerSizeTwoComponents(sizeof(int) * 2, VertexAttribPointerType.Int); 26 | } 27 | 28 | [TestMethod] 29 | public void UnsignedInt() 30 | { 31 | CheckAttribPointerSizeTwoComponents(sizeof(int) * 2, VertexAttribPointerType.UnsignedInt); 32 | } 33 | 34 | [TestMethod] 35 | public void Short() 36 | { 37 | CheckAttribPointerSizeTwoComponents(sizeof(short) * 2, VertexAttribPointerType.Short); 38 | } 39 | 40 | [TestMethod] 41 | public void UnsignedShort() 42 | { 43 | CheckAttribPointerSizeTwoComponents(sizeof(short) * 2, VertexAttribPointerType.UnsignedShort); 44 | } 45 | 46 | [TestMethod] 47 | public void Float() 48 | { 49 | CheckAttribPointerSizeTwoComponents(sizeof(float) * 2, VertexAttribPointerType.Float); 50 | } 51 | 52 | [TestMethod] 53 | public void Double() 54 | { 55 | CheckAttribPointerSizeTwoComponents(sizeof(double) * 2, VertexAttribPointerType.Double); 56 | } 57 | 58 | private static void CheckAttribPointerSizeTwoComponents(int expected, VertexAttribPointerType type) 59 | { 60 | VertexFloatAttribute attribInfo = new VertexFloatAttribute("", ValueCount.Two, type, false); 61 | Assert.AreEqual(expected, attribInfo.SizeInBytes); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Test Projects/SFGenericModel.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Controls.Test/GLViewportTests/Dispose.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace SFGraphics.Controls.Test.GLViewportTests 5 | { 6 | [TestClass] 7 | public class Dispose 8 | { 9 | [TestMethod] 10 | public void DisposeRenderingNotStarted() 11 | { 12 | var viewport = new GLViewport(); 13 | viewport.Dispose(); 14 | } 15 | 16 | [TestMethod] 17 | public void DisposeRenderingStarted() 18 | { 19 | var viewport = new GLViewport(); 20 | viewport.RestartRendering(); 21 | viewport.Dispose(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Controls.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SFGraphics.Controls.Test")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("SFGraphics.Controls.Test")] 10 | [assembly: AssemblyCopyright("Copyright © 2020")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: Guid("c2177742-6b80-4410-b146-8054f28dc022")] 17 | 18 | // [assembly: AssemblyVersion("1.0.*")] 19 | [assembly: AssemblyVersion("1.0.0.0")] 20 | [assembly: AssemblyFileVersion("1.0.0.0")] 21 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Controls.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.ShaderGen.Test/SFGraphics.ShaderGen.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ..\..\lib\OpenTK.dll 21 | true 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyTitle("SFGraphicsRenderTests")] 5 | [assembly: AssemblyDescription("")] 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("SFGraphicsRenderTests")] 9 | [assembly: AssemblyCopyright("Copyright © 2018")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: Guid("91a71848-b6e5-450c-a629-3f41651296de")] 16 | 17 | // [assembly: AssemblyVersion("1.0.*")] 18 | [assembly: AssemblyVersion("1.0.0.0")] 19 | [assembly: AssemblyFileVersion("1.0.0.0")] 20 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/README.md: -------------------------------------------------------------------------------- 1 | # SFGraphics Render Tests 2 | Unit tests for classes and methods that require an OpenTK context to function. This is designed for 3 | basic testing of shader compilation, correctly changing state and bindings, etc. Usage examples for 4 | SFGraphics will be found in the SFGraphicsGUI. 5 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/BufferObjectTests/BindBufferBase.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace SFGraphics.Test.BufferObjectTests 5 | { 6 | [TestClass] 7 | public class BindBufferBase : BufferTest 8 | { 9 | [TestMethod] 10 | public void InvalidTarget() 11 | { 12 | // Shouldn't throw exception. 13 | buffer.BindBase(BufferRangeTarget.UniformBuffer, -1); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/BufferObjectTests/BindBufferRange.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace SFGraphics.Test.BufferObjectTests 5 | { 6 | [TestClass] 7 | public class BindBufferRange : BufferTest 8 | { 9 | [TestMethod] 10 | public void InvalidTarget() 11 | { 12 | // Shouldn't throw exception. 13 | buffer.BindRange(BufferRangeTarget.UniformBuffer, -1, 0, 0); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/BufferObjectTests/BufferData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK; 4 | 5 | namespace SFGraphics.Test.BufferObjectTests 6 | { 7 | [TestClass] 8 | public class BufferData : BufferTest 9 | { 10 | private struct Empty 11 | { 12 | } 13 | 14 | [TestMethod] 15 | public void GetFloats() 16 | { 17 | float[] readData = buffer.GetData(); 18 | CollectionAssert.AreEqual(originalData, readData); 19 | } 20 | 21 | [TestMethod] 22 | public void GetDataEmptyStruct() 23 | { 24 | // Empty structs use 1 byte. 25 | Empty[] readData = buffer.GetData(); 26 | Assert.AreEqual(sizeof(float) * originalData.Length, readData.Length); 27 | } 28 | 29 | [TestMethod] 30 | public void GetVector3FromFloats() 31 | { 32 | // The 3 floats should make a single Vector3 struct. 33 | Vector3[] expectedData = { new Vector3(1.5f, 2.5f, 3.5f) }; 34 | Vector3[] readData = buffer.GetData(); 35 | CollectionAssert.AreEqual(expectedData, readData); 36 | } 37 | 38 | [TestMethod] 39 | public void DataSizeNotDivisibleByType() 40 | { 41 | var e = Assert.ThrowsException(() => buffer.GetData()); 42 | Assert.AreEqual("T", e.ParamName); 43 | Assert.AreEqual($"The buffer data is not divisible by the requested type's size.{Environment.NewLine}Parameter name: T", e.Message); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/BufferObjectTests/BufferTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.BufferObjects; 4 | 5 | namespace SFGraphics.Test.BufferObjectTests 6 | { 7 | public abstract class BufferTest : GraphicsContextTest 8 | { 9 | protected BufferObject buffer; 10 | protected readonly float[] originalData = { 1.5f, 2.5f, 3.5f }; 11 | 12 | [TestInitialize] 13 | public override void Initialize() 14 | { 15 | base.Initialize(); 16 | buffer = new BufferObject(BufferTarget.ArrayBuffer); 17 | buffer.SetData(originalData, BufferUsageHint.StaticDraw); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/BufferObjectTests/MapBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using OpenTK.Graphics.OpenGL; 5 | 6 | namespace SFGraphics.Test.BufferObjectTests 7 | { 8 | [TestClass] 9 | public class MapBuffer : BufferTest 10 | { 11 | [TestMethod] 12 | public void ReadFromPtr() 13 | { 14 | // Copy the buffer's data to a new array using its pointer. 15 | IntPtr pointer = buffer.MapBuffer(BufferAccess.ReadOnly); 16 | float[] readData = new float[originalData.Length]; 17 | Marshal.Copy(pointer, readData, 0, originalData.Length); 18 | buffer.Unmap(); 19 | 20 | CollectionAssert.AreEqual(originalData, readData); 21 | } 22 | 23 | [TestMethod] 24 | public void WriteToPtr() 25 | { 26 | float[] dataToWrite = { -1f, -1f, -1f }; 27 | 28 | // Modify the buffer's data using its pointer. 29 | IntPtr pointer = buffer.MapBuffer(BufferAccess.ReadWrite); 30 | Marshal.Copy(dataToWrite, 0, pointer, dataToWrite.Length); 31 | buffer.Unmap(); 32 | 33 | CollectionAssert.AreEqual(dataToWrite, buffer.GetData()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/BufferObjectTests/SetCapacity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.BufferObjectTests 6 | { 7 | [TestClass] 8 | public class SetCapacity : BufferTest 9 | { 10 | [TestMethod] 11 | public void EmptyBuffer() 12 | { 13 | buffer.SetCapacity(0, BufferUsageHint.StaticDraw); 14 | Assert.AreEqual(0, buffer.SizeInBytes); 15 | } 16 | 17 | [TestMethod] 18 | public void ValidCapacity() 19 | { 20 | buffer.SetCapacity(0, BufferUsageHint.StaticDraw); 21 | buffer.SetCapacity(1024, BufferUsageHint.StaticDraw); 22 | 23 | // Shouldn't throw exception. 24 | buffer.SetSubData(new float[3], 50); 25 | Assert.AreEqual(1024, buffer.SizeInBytes); 26 | } 27 | 28 | [TestMethod] 29 | public void NegativeCapacity() 30 | { 31 | var e = Assert.ThrowsException(() => buffer.SetCapacity(-5, BufferUsageHint.StaticDraw)); 32 | Assert.AreEqual("sizeInBytes", e.ParamName); 33 | Assert.IsTrue(e.Message.Contains("The buffer size must be non negative.")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/BufferObjectTests/SizeInBytes.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.BufferObjects; 4 | 5 | namespace SFGraphics.Test.BufferObjectTests 6 | { 7 | [TestClass] 8 | public class SizeInBytes : GraphicsContextTest 9 | { 10 | [TestMethod] 11 | public void UninitializedBuffer() 12 | { 13 | var buffer = new BufferObject(BufferTarget.ArrayBuffer); 14 | Assert.AreEqual(0, buffer.SizeInBytes); 15 | } 16 | 17 | [TestMethod] 18 | public void SetEmptyData() 19 | { 20 | var buffer = new BufferObject(BufferTarget.ArrayBuffer); 21 | buffer.SetData(new float[] { }, BufferUsageHint.StaticDraw); 22 | Assert.AreEqual(0, buffer.SizeInBytes); 23 | } 24 | 25 | [TestMethod] 26 | public void SetNonEmptyData() 27 | { 28 | var buffer = new BufferObject(BufferTarget.ArrayBuffer); 29 | buffer.SetData(new float[] { 1, 2, 3 }, BufferUsageHint.StaticDraw); 30 | Assert.AreEqual(sizeof(float) * 3, buffer.SizeInBytes); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/CameraTests/FovDegreesConversion.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGraphics.Cameras; 3 | 4 | namespace SFGraphics.Test.CameraTests 5 | { 6 | [TestClass] 7 | public class FovDegreesConversion 8 | { 9 | [TestMethod] 10 | public void DegreesToRadiansMaxFov() 11 | { 12 | // Value is outside of range and should be ignored. 13 | Camera camera = new Camera(); 14 | float original = camera.FovRadians; 15 | camera.FovDegrees = 180; 16 | Assert.AreEqual(original, camera.FovRadians, 0.001); 17 | } 18 | 19 | [TestMethod] 20 | public void DegreesToRadiansMinFov() 21 | { 22 | // Value is outside of range and should be ignored. 23 | Camera camera = new Camera(); 24 | float original = camera.FovRadians; 25 | camera.FovDegrees = 0; 26 | Assert.AreEqual(original, camera.FovRadians, 0.001); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/CameraTests/FovRadiansConversion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using SFGraphics.Cameras; 4 | 5 | namespace SFGraphics.Test.CameraTests 6 | { 7 | [TestClass] 8 | public class FovRadiansConversion 9 | { 10 | [TestMethod] 11 | public void RadiansToDegreesMaxFov() 12 | { 13 | // Value is outside of range and should be ignored. 14 | var camera = new Camera(); 15 | float original = camera.FovDegrees; 16 | camera.FovRadians = (float)Math.PI; 17 | Assert.AreEqual(original, camera.FovDegrees, 0.001); 18 | } 19 | 20 | [TestMethod] 21 | public void RadiansToDegreesMinFov() 22 | { 23 | // Value is outside of range and should be ignored. 24 | var camera = new Camera(); 25 | float original = camera.FovDegrees; 26 | camera.FovRadians = 0; 27 | Assert.AreEqual(original, camera.FovDegrees, 0.001); 28 | } 29 | 30 | [TestMethod] 31 | public void RadiansToDegreesInsideRange() 32 | { 33 | var camera = new Camera { FovRadians = (float)Math.PI / 2.0f }; 34 | Assert.AreEqual(90, camera.FovDegrees, 0.001); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/CameraTests/GetSetTranslation.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGraphics.Cameras; 3 | 4 | namespace SFGraphics.Test.Tests.CameraTests 5 | { 6 | [TestClass] 7 | public class GetSetTranslation 8 | { 9 | [TestMethod] 10 | public void GetSetPropValues() 11 | { 12 | var camera = new Camera { Translation = new OpenTK.Vector3(1, 2, 3) }; 13 | Assert.AreEqual(1, camera.TranslationX); 14 | Assert.AreEqual(2, camera.TranslationY); 15 | Assert.AreEqual(3, camera.TranslationZ); 16 | camera.TranslationX = 3; 17 | camera.TranslationY = 2; 18 | camera.TranslationZ = 1; 19 | Assert.AreEqual(new OpenTK.Vector3(3, 2, 1), camera.Translation); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/CameraTests/ProjectionMatrix.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using SFGraphics.Cameras; 4 | 5 | namespace SFGraphics.Test.CameraTests 6 | { 7 | [TestClass] 8 | public class ProjectionMatrix 9 | { 10 | [TestMethod] 11 | public void ChangeWidthHeightFov() 12 | { 13 | Camera camera = new Camera { RenderWidth = 1, RenderHeight = 2, FovRadians = 0.5f }; 14 | var expected = Matrix4.CreatePerspectiveFieldOfView(0.5f, 0.5f, camera.NearClipPlane, camera.FarClipPlane); 15 | Assert.AreEqual(expected, camera.PerspectiveMatrix); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/CameraTests/RenderDimensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using SFGraphics.Cameras; 4 | 5 | namespace SFGraphics.Test.CameraTests 6 | { 7 | [TestClass] 8 | public class RenderDimensions 9 | { 10 | [TestMethod] 11 | public void SquareAspect() 12 | { 13 | Camera camera = new Camera { RenderHeight = 1, RenderWidth = 1 }; 14 | Assert.AreEqual(Matrix4.CreatePerspectiveFieldOfView(camera.FovRadians, 1, camera.NearClipPlane, camera.FarClipPlane), camera.PerspectiveMatrix); 15 | } 16 | 17 | [TestMethod] 18 | public void NonSquareAspect() 19 | { 20 | Camera camera = new Camera { RenderHeight = 1, RenderWidth = 2 }; 21 | Assert.AreEqual(Matrix4.CreatePerspectiveFieldOfView(camera.FovRadians, 2, camera.NearClipPlane, camera.FarClipPlane), camera.PerspectiveMatrix); 22 | } 23 | 24 | [TestMethod] 25 | public void InvalidValues() 26 | { 27 | Camera camera = new Camera { RenderHeight = -1, RenderWidth = 0 }; 28 | 29 | Assert.AreEqual(1, camera.RenderHeight); 30 | Assert.AreEqual(1, camera.RenderWidth); 31 | Assert.AreEqual(Matrix4.CreatePerspectiveFieldOfView(camera.FovRadians, 1, camera.NearClipPlane, camera.FarClipPlane), camera.PerspectiveMatrix); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/CameraTests/ResetTransforms.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using SFGraphics.Cameras; 4 | 5 | namespace SFGraphics.Test.CameraTests 6 | { 7 | [TestClass] 8 | public class ResetTransforms 9 | { 10 | [TestMethod] 11 | public void ResetAllTransforms() 12 | { 13 | Camera camera = new Camera { Translation = new Vector3(-1, -1, -1) }; 14 | camera.ResetTransforms(); 15 | Assert.AreEqual(Vector3.Zero, camera.Translation); 16 | Assert.AreEqual(Vector3.Zero, camera.PositionWorldSpace); 17 | Assert.AreEqual(0, camera.RotationXDegrees); 18 | Assert.AreEqual(0, camera.RotationYDegrees); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/CameraTests/RotationMatrix.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using SFGraphics.Cameras; 4 | using SFGraphics.Utils; 5 | 6 | namespace SFGraphics.Test.CameraTests 7 | { 8 | [TestClass] 9 | public class RotationMatrix 10 | { 11 | [TestMethod] 12 | public void RotationXDegrees() 13 | { 14 | Camera camera = new Camera {RotationXDegrees = 30}; 15 | Assert.AreEqual(Matrix4.CreateRotationX((float)VectorUtils.GetRadians(30)), camera.RotationMatrix); 16 | } 17 | 18 | [TestMethod] 19 | public void RotationXRadians() 20 | { 21 | Camera camera = new Camera {RotationXRadians = 0.5f}; 22 | Assert.AreEqual(Matrix4.CreateRotationX(0.5f), camera.RotationMatrix); 23 | } 24 | 25 | [TestMethod] 26 | public void RotationYDegrees() 27 | { 28 | Camera camera = new Camera {RotationYDegrees = 30}; 29 | Assert.AreEqual(Matrix4.CreateRotationY((float)VectorUtils.GetRadians(30)), camera.RotationMatrix); 30 | } 31 | [TestMethod] 32 | public void RotationYRadians() 33 | { 34 | Camera camera = new Camera {RotationYRadians = 0.5f}; 35 | Assert.AreEqual(Matrix4.CreateRotationY(0.5f), camera.RotationMatrix); 36 | } 37 | 38 | [TestMethod] 39 | public void RotationXYRadians() 40 | { 41 | Camera camera = new Camera {RotationYRadians = 0.75f, RotationXRadians = 0.5f}; 42 | 43 | Matrix4 expected = Matrix4.CreateRotationY(0.75f) * Matrix4.CreateRotationX(0.5f); 44 | Assert.AreEqual(expected, camera.RotationMatrix); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/CameraTests/TranslationMatrix.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using SFGraphics.Cameras; 4 | 5 | namespace SFGraphics.Test.CameraTests 6 | { 7 | [TestClass] 8 | public class TranslationMatrix 9 | { 10 | [TestMethod] 11 | public void CameraAtOrigin() 12 | { 13 | Camera camera = new Camera 14 | { 15 | Translation = new Vector3(0) 16 | }; 17 | Assert.AreEqual(Matrix4.Identity, camera.TranslationMatrix); 18 | } 19 | 20 | [TestMethod] 21 | public void NonZeroPosition() 22 | { 23 | Camera camera = new Camera 24 | { 25 | Translation = new Vector3(1, 2, 3) 26 | }; 27 | Assert.AreEqual(Matrix4.CreateTranslation(1, -2, 3), camera.TranslationMatrix); 28 | } 29 | 30 | [TestMethod] 31 | public void PanNoScalingRenderDimensionsZero() 32 | { 33 | Camera camera = new Camera 34 | { 35 | Translation = new Vector3(0), 36 | RenderHeight = 0, 37 | RenderWidth = 0 38 | }; 39 | camera.Pan(0, 0, false); 40 | 41 | // Check for divide by 0. 42 | Assert.AreEqual(Matrix4.Identity, camera.TranslationMatrix); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/FramebufferTests/ConstructorExceptions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Framebuffers; 4 | using System; 5 | 6 | namespace SFGraphics.Test.FramebufferTests 7 | { 8 | [TestClass] 9 | public class ConstructorExceptions : GraphicsContextTest 10 | { 11 | [TestMethod] 12 | public void NegativeColorAttachments() 13 | { 14 | var e = Assert.ThrowsException(() => 15 | new Framebuffer(FramebufferTarget.Framebuffer, 1, 1, PixelInternalFormat.Rgba, -1)); 16 | 17 | Assert.IsTrue(e.Message.Contains("Color attachment count must be non negative.")); 18 | Assert.AreEqual("colorAttachmentsCount", e.ParamName); 19 | } 20 | 21 | [TestMethod] 22 | public void UncompressedFormat() 23 | { 24 | // Shouldn't throw an exception. 25 | Framebuffer framebuffer = new Framebuffer(FramebufferTarget.Framebuffer, 8, 4, PixelInternalFormat.Rgb); 26 | Assert.AreEqual(8, framebuffer.Width); 27 | Assert.AreEqual(4, framebuffer.Height); 28 | } 29 | 30 | [TestMethod] 31 | public void CompressedFormat() 32 | { 33 | var e = Assert.ThrowsException(() => 34 | new Framebuffer(FramebufferTarget.Framebuffer, 1, 1, PixelInternalFormat.CompressedRgbaS3tcDxt1Ext)); 35 | 36 | Assert.AreEqual("The PixelInternalFormat is not an uncompressed image format.", e.Message); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/GLExtensionTests/ExtensionAvailabilityTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGraphics.GlUtils; 3 | 4 | namespace SFGraphics.Test.GLExtensionTests 5 | { 6 | [TestClass] 7 | public class ExtensionAvailabilityTests : GraphicsContextTest 8 | { 9 | [TestMethod] 10 | public void CorrectName() 11 | { 12 | Assert.IsTrue(OpenGLExtensions.IsAvailable("GL_ARB_sampler_objects")); 13 | } 14 | 15 | [TestMethod] 16 | public void CorrectNameLowerCase() 17 | { 18 | Assert.IsTrue(OpenGLExtensions.IsAvailable("gl_arb_sampler_objects")); 19 | } 20 | 21 | [TestMethod] 22 | public void InvalidName() 23 | { 24 | Assert.IsFalse(OpenGLExtensions.IsAvailable("GL_dank_memes")); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/GLObjectTests/GLObjectToString.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.BufferObjects; 4 | using SFGraphics.GLObjects.Framebuffers; 5 | using SFGraphics.GLObjects.RenderBuffers; 6 | using SFGraphics.GLObjects.Shaders; 7 | using SFGraphics.GLObjects.Textures; 8 | using SFGraphics.GLObjects.VertexArrays; 9 | 10 | namespace SFGraphics.Test.GLObjectTests 11 | { 12 | [TestClass] 13 | public class GLObjectToString : GraphicsContextTest 14 | { 15 | [TestMethod] 16 | public void Shader() 17 | { 18 | Shader glObject = new Shader(); 19 | Assert.AreEqual($"ShaderProgram ID: {glObject.Id}", glObject.ToString()); 20 | } 21 | 22 | [TestMethod] 23 | public void VertexArrayObject() 24 | { 25 | VertexArrayObject glObject = new VertexArrayObject(); 26 | Assert.AreEqual($"VertexArrayObject ID: {glObject.Id}", glObject.ToString()); 27 | } 28 | 29 | [TestMethod] 30 | public void BufferObject() 31 | { 32 | BufferObject glObject = new BufferObject(BufferTarget.ArrayBuffer); 33 | Assert.AreEqual($"BufferObject ID: {glObject.Id}", glObject.ToString()); 34 | } 35 | 36 | [TestMethod] 37 | public void Texture() 38 | { 39 | // We only need to test one subclass. 40 | Texture glObject = new Texture2D(); 41 | Assert.AreEqual($"Texture ID: {glObject.Id}", glObject.ToString()); 42 | } 43 | 44 | [TestMethod] 45 | public void RenderbufferObject() 46 | { 47 | Renderbuffer glObject = new Renderbuffer(1, 1, RenderbufferStorage.Rgba16); 48 | Assert.AreEqual($"RenderbufferObject ID: {glObject.Id}", glObject.ToString()); 49 | } 50 | 51 | [TestMethod] 52 | public void FramebufferObject() 53 | { 54 | Framebuffer glObject = new Framebuffer(FramebufferTarget.Framebuffer); 55 | Assert.AreEqual($"FramebufferObject ID: {glObject.Id}", glObject.ToString()); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/GraphicsContextTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using RenderTestUtils; 3 | 4 | namespace SFGraphics.Test 5 | { 6 | [TestClass] 7 | public abstract class GraphicsContextTest 8 | { 9 | [TestInitialize] 10 | public virtual void Initialize() 11 | { 12 | // Set up the context for all the tests. 13 | OpenTKWindowlessContext.BindDummyContext(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ReferenceCountTests/AddReference.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using SFGraphics.GLObjects.GLObjectManagement; 4 | 5 | namespace SFGraphics.Test.ReferenceCountTests 6 | { 7 | [TestClass] 8 | public class AddReference 9 | { 10 | [TestMethod] 11 | public void AddNewReference() 12 | { 13 | ConcurrentDictionary refCountByName = new ConcurrentDictionary(); 14 | ReferenceCounting.AddReference(refCountByName, "memes"); 15 | 16 | Assert.AreEqual(1, refCountByName["memes"]); 17 | } 18 | 19 | [TestMethod] 20 | public void IncrementExistingReference() 21 | { 22 | ConcurrentDictionary refCountByName = new ConcurrentDictionary(); 23 | ReferenceCounting.AddReference(refCountByName, "memes"); 24 | ReferenceCounting.AddReference(refCountByName, "memes"); 25 | 26 | Assert.AreEqual(2, refCountByName["memes"]); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ReferenceCountTests/GetObjectsWithNoReferencesTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using System.Collections.Generic; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using SFGraphics.GLObjects.GLObjectManagement; 5 | 6 | namespace SFGraphics.Test.ReferenceCountTests 7 | { 8 | [TestClass] 9 | public class GetObjectsWithNoReferencesTests 10 | { 11 | [TestMethod] 12 | public void OneObjectWithNoReferences() 13 | { 14 | ConcurrentDictionary refCountByName = new ConcurrentDictionary(); 15 | refCountByName.TryAdd("a", 1); 16 | refCountByName.TryAdd("b", 0); 17 | refCountByName.TryAdd("c", 1); 18 | 19 | HashSet namesWithNoReferences = ReferenceCounting.GetObjectsWithNoReferences(refCountByName); 20 | Assert.AreEqual(1, namesWithNoReferences.Count); 21 | Assert.IsTrue(namesWithNoReferences.Contains("b")); 22 | } 23 | 24 | [TestMethod] 25 | public void DuplicateObjecstWithNoReferences() 26 | { 27 | ConcurrentDictionary refCountByName = new ConcurrentDictionary(); 28 | refCountByName.TryAdd("a", 0); 29 | refCountByName.TryAdd("a", 0); 30 | refCountByName.TryAdd("a", 0); 31 | 32 | // Names are unique, so there is no need to delete an OpenGL object more than once. 33 | HashSet namesWithNoReferences = ReferenceCounting.GetObjectsWithNoReferences(refCountByName); 34 | Assert.AreEqual(1, namesWithNoReferences.Count); 35 | Assert.IsTrue(namesWithNoReferences.Contains("a")); 36 | } 37 | 38 | [TestMethod] 39 | public void EmptyDictionary() 40 | { 41 | ConcurrentDictionary refCountByName = new ConcurrentDictionary(); 42 | 43 | HashSet namesWithNoReferences = ReferenceCounting.GetObjectsWithNoReferences(refCountByName); 44 | Assert.AreEqual(0, namesWithNoReferences.Count); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ReferenceCountTests/RemoveReference.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using SFGraphics.GLObjects.GLObjectManagement; 4 | 5 | namespace SFGraphics.Test.ReferenceCountTests 6 | { 7 | [TestClass] 8 | public class RemoveReference 9 | { 10 | [TestMethod] 11 | public void TryDecrementInvalidReference() 12 | { 13 | // Doesn't throw exception. 14 | var refCountByName = new ConcurrentDictionary(); 15 | 16 | ReferenceCounting.RemoveReference(refCountByName, "memes"); 17 | 18 | Assert.IsFalse(refCountByName.ContainsKey("memes")); 19 | } 20 | 21 | [TestMethod] 22 | public void DecrementExistingReference() 23 | { 24 | var refCountByName = new ConcurrentDictionary(); 25 | 26 | ReferenceCounting.AddReference(refCountByName, "memes"); 27 | ReferenceCounting.RemoveReference(refCountByName, "memes"); 28 | 29 | Assert.AreEqual(0, refCountByName["memes"]); 30 | } 31 | 32 | [TestMethod] 33 | public void DecrementZeroReference() 34 | { 35 | var refCountByName = new ConcurrentDictionary(); 36 | 37 | ReferenceCounting.AddReference(refCountByName, "memes"); 38 | ReferenceCounting.RemoveReference(refCountByName, "memes"); 39 | ReferenceCounting.RemoveReference(refCountByName, "memes"); 40 | 41 | Assert.AreEqual(0, refCountByName["memes"]); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/RenderbufferTests/ConstructorExceptions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.RenderBuffers; 4 | using System; 5 | 6 | namespace SFGraphics.Test.RenderbufferTests 7 | { 8 | [TestClass] 9 | public class ConstructorExceptions : GraphicsContextTest 10 | { 11 | [TestMethod] 12 | public void NegativeWidth() 13 | { 14 | var e = Assert.ThrowsException(() => 15 | new Renderbuffer(-1, 8, RenderbufferStorage.Rgba8)); 16 | 17 | Assert.IsTrue(e.Message.Contains("Dimensions must be non negative.")); 18 | Assert.AreEqual("width", e.ParamName); 19 | } 20 | 21 | [TestMethod] 22 | public void NegativeHeight() 23 | { 24 | var e = Assert.ThrowsException(() => 25 | new Renderbuffer(8, -1, RenderbufferStorage.Rgba8)); 26 | 27 | Assert.IsTrue(e.Message.Contains("Dimensions must be non negative.")); 28 | Assert.AreEqual("height", e.ParamName); 29 | } 30 | 31 | [TestMethod] 32 | public void NegativeWidthMultisample() 33 | { 34 | var e = Assert.ThrowsException(() => 35 | new Renderbuffer(-1, 8, 4,RenderbufferStorage.Rgba8)); 36 | 37 | Assert.IsTrue(e.Message.Contains("Dimensions must be non negative.")); 38 | Assert.AreEqual("width", e.ParamName); 39 | } 40 | 41 | [TestMethod] 42 | public void NegativeHeightMultisample() 43 | { 44 | var e = Assert.ThrowsException(() => 45 | new Renderbuffer(8, -1, 4, RenderbufferStorage.Rgba8)); 46 | 47 | Assert.IsTrue(e.Message.Contains("Dimensions must be non negative.")); 48 | Assert.AreEqual("height", e.ParamName); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderObjectTests/CreateShader.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Shaders; 4 | 5 | namespace SFGraphics.Test.ShaderObjectTests 6 | { 7 | [TestClass] 8 | public class CreateShader : GraphicsContextTest 9 | { 10 | [TestMethod] 11 | public void FromEmptySource() 12 | { 13 | var shader = new ShaderObject("", ShaderType.FragmentShader); 14 | Assert.IsFalse(shader.WasCompiledSuccessfully); 15 | } 16 | 17 | [TestMethod] 18 | public void FromNullSource() 19 | { 20 | var shader = new ShaderObject("", ShaderType.FragmentShader); 21 | Assert.IsFalse(shader.WasCompiledSuccessfully); 22 | } 23 | 24 | [TestMethod] 25 | public void FromValidSource() 26 | { 27 | var source = RenderTestUtils.ResourceShaders.GetShaderSource("valid.frag"); 28 | var shader = new ShaderObject(source, ShaderType.FragmentShader); 29 | Assert.IsTrue(shader.WasCompiledSuccessfully); 30 | } 31 | 32 | [TestMethod] 33 | public void FromInvalidSource() 34 | { 35 | var source = RenderTestUtils.ResourceShaders.GetShaderSource("invalid.frag"); 36 | var shader = new ShaderObject(source, ShaderType.FragmentShader); 37 | Assert.IsFalse(shader.WasCompiledSuccessfully); 38 | } 39 | 40 | [TestMethod] 41 | public void SetShaderTypeFrag() 42 | { 43 | var source = RenderTestUtils.ResourceShaders.GetShaderSource("valid.frag"); 44 | var shader = new ShaderObject(source, ShaderType.FragmentShader); 45 | Assert.AreEqual(ShaderType.FragmentShader, shader.ShaderType); 46 | } 47 | 48 | [TestMethod] 49 | public void SetShaderTypeGeom() 50 | { 51 | var source = RenderTestUtils.ResourceShaders.GetShaderSource("valid.frag"); 52 | var shader = new ShaderObject(source, ShaderType.GeometryShader); 53 | Assert.AreEqual(ShaderType.GeometryShader, shader.ShaderType); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderObjectTests/GetInfoLog.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Shaders; 4 | 5 | namespace SFGraphics.Test.ShaderObjectTests 6 | { 7 | [TestClass] 8 | public class GetInfoLog : GraphicsContextTest 9 | { 10 | [TestMethod] 11 | public void FromEmptySource() 12 | { 13 | var shader = new ShaderObject("", ShaderType.FragmentShader); 14 | Assert.AreEqual("", shader.GetInfoLog()); 15 | } 16 | 17 | [TestMethod] 18 | public void FromNullSource() 19 | { 20 | var shader = new ShaderObject("", ShaderType.FragmentShader); 21 | Assert.AreEqual("", shader.GetInfoLog()); 22 | } 23 | 24 | [TestMethod] 25 | public void FromValidSource() 26 | { 27 | var source = RenderTestUtils.ResourceShaders.GetShaderSource("valid.frag"); 28 | var shader = new ShaderObject(source, ShaderType.FragmentShader); 29 | Assert.AreEqual("", shader.GetInfoLog()); 30 | } 31 | 32 | [TestMethod] 33 | public void FromInvalidSource() 34 | { 35 | // The logs are driver dependent, so just check that it produces some sort of error message. 36 | var source = RenderTestUtils.ResourceShaders.GetShaderSource("invalid.frag"); 37 | var shader = new ShaderObject(source, ShaderType.FragmentShader); 38 | Assert.IsTrue(shader.GetInfoLog().ToLower().Contains("error")); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderObjectTests/GetShaderSource.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Shaders; 4 | 5 | namespace SFGraphics.Test.ShaderObjectTests 6 | { 7 | [TestClass] 8 | public class GetShaderSource : GraphicsContextTest 9 | { 10 | [TestMethod] 11 | public void GetEmptySource() 12 | { 13 | var shader = new ShaderObject("", ShaderType.FragmentShader); 14 | Assert.AreEqual("", shader.GetShaderSource()); 15 | } 16 | 17 | [TestMethod] 18 | public void GetNullSource() 19 | { 20 | var shader = new ShaderObject(null, ShaderType.FragmentShader); 21 | Assert.AreEqual("", shader.GetShaderSource()); 22 | } 23 | 24 | [TestMethod] 25 | public void GetValidSource() 26 | { 27 | var source = RenderTestUtils.ResourceShaders.GetShaderSource("valid.frag"); 28 | var shader = new ShaderObject(source, ShaderType.FragmentShader); 29 | Assert.AreEqual(source, shader.GetShaderSource()); 30 | } 31 | 32 | [TestMethod] 33 | public void GetInvalidSource() 34 | { 35 | var source = RenderTestUtils.ResourceShaders.GetShaderSource("invalid.frag"); 36 | var shader = new ShaderObject(source, ShaderType.FragmentShader); 37 | Assert.AreEqual(source, shader.GetShaderSource()); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/GetAttribLocation.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Shaders; 4 | 5 | namespace SFGraphics.Test.ShaderTests 6 | { 7 | [TestClass] 8 | public class GetAttribLocation : ShaderTest 9 | { 10 | [TestMethod] 11 | public void ValidName() 12 | { 13 | Assert.AreEqual(GL.GetAttribLocation(shader.Id, "position"), shader.GetAttribLocation("position")); 14 | } 15 | 16 | [TestMethod] 17 | public void InvalidName() 18 | { 19 | Assert.AreEqual(-1, shader.GetAttribLocation("memes")); 20 | } 21 | 22 | [TestMethod] 23 | public void EmptyName() 24 | { 25 | Assert.AreEqual(-1, shader.GetAttribLocation("")); 26 | } 27 | 28 | [TestMethod] 29 | public void NullName() 30 | { 31 | Assert.AreEqual(-1, shader.GetAttribLocation(null)); 32 | } 33 | 34 | [TestMethod] 35 | public void ShaderNotLinked() 36 | { 37 | var shader = new Shader(); 38 | Assert.AreEqual(-1, shader.GetAttribLocation("memes")); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/GetProgramBinary.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using RenderTestUtils; 4 | using SFGraphics.GLObjects.Shaders; 5 | 6 | namespace SFGraphics.Test.ShaderTests 7 | { 8 | [TestClass] 9 | public class GetProgramBinary : GraphicsContextTest 10 | { 11 | [TestMethod] 12 | public void ValidProgram() 13 | { 14 | var shader = ShaderTestUtils.CreateValidShader(); 15 | Assert.IsTrue(shader.GetProgramBinary(out byte[] binary, out BinaryFormat binaryFormat)); 16 | } 17 | 18 | [TestMethod] 19 | public void InvalidProgram() 20 | { 21 | var shader = new Shader(); 22 | Assert.IsFalse(shader.GetProgramBinary(out byte[] binary, out BinaryFormat binaryFormat)); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/GetShaderSources.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Shaders; 4 | 5 | 6 | namespace SFGraphics.Test.ShaderTests 7 | { 8 | [TestClass] 9 | public class GetShaderSources : GraphicsContextTest 10 | { 11 | [TestMethod] 12 | public void NoShaders() 13 | { 14 | Shader shader = new Shader(); 15 | 16 | // The order may not be the same. 17 | CollectionAssert.AreEquivalent(new string[0], shader.GetShaderSources()); 18 | } 19 | 20 | [TestMethod] 21 | public void EmptyShaders() 22 | { 23 | Shader shader = new Shader(); 24 | shader.LoadShaders( 25 | new ShaderObject("", ShaderType.FragmentShader), 26 | new ShaderObject(null, ShaderType.FragmentShader)); 27 | 28 | // The order may not be the same. 29 | CollectionAssert.AreEquivalent(new string[] { "", "" }, shader.GetShaderSources()); 30 | } 31 | 32 | [TestMethod] 33 | public void InvalidShaders() 34 | { 35 | Shader shader = new Shader(); 36 | shader.LoadShaders( 37 | new ShaderObject("a", ShaderType.FragmentShader), 38 | new ShaderObject("b", ShaderType.FragmentShader), 39 | new ShaderObject("c", ShaderType.FragmentShader)); 40 | 41 | // The order may not be the same. 42 | CollectionAssert.AreEquivalent(new string[] { "a", "b", "c" }, shader.GetShaderSources()); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/GetUniformBlockIndex.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Shaders; 4 | 5 | namespace SFGraphics.Test.ShaderTests 6 | { 7 | [TestClass] 8 | public class GetUniformBlockIndex : ShaderTest 9 | { 10 | [TestMethod] 11 | public void ValidName() 12 | { 13 | Assert.AreEqual(GL.GetUniformBlockIndex(shader.Id, "UniformBlock"), shader.GetUniformBlockIndex("UniformBlock")); 14 | } 15 | 16 | [TestMethod] 17 | public void InvalidName() 18 | { 19 | Assert.AreEqual(-1, shader.GetUniformBlockIndex("memes")); 20 | } 21 | 22 | 23 | [TestMethod] 24 | public void EmptyName() 25 | { 26 | Assert.AreEqual(-1, shader.GetUniformBlockIndex("")); 27 | } 28 | 29 | [TestMethod] 30 | public void NullName() 31 | { 32 | Assert.AreEqual(-1, shader.GetUniformBlockIndex(null)); 33 | } 34 | 35 | [TestMethod] 36 | public void ShaderNotLinked() 37 | { 38 | var shader = new Shader(); 39 | Assert.AreEqual(-1, shader.GetUniformBlockIndex("memes")); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/GetUniformLocation.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Shaders; 4 | 5 | namespace SFGraphics.Test.ShaderTests 6 | { 7 | [TestClass] 8 | public class GetUniformLocation : ShaderTest 9 | { 10 | [TestMethod] 11 | public void ValidName() 12 | { 13 | Assert.AreEqual(GL.GetUniformLocation(shader.Id, "float1"), shader.GetUniformLocation("float1")); 14 | } 15 | 16 | [TestMethod] 17 | public void InvalidName() 18 | { 19 | Assert.AreEqual(-1, shader.GetUniformLocation("memes")); 20 | } 21 | 22 | [TestMethod] 23 | public void EmptyName() 24 | { 25 | Assert.AreEqual(-1, shader.GetUniformLocation("")); 26 | } 27 | 28 | [TestMethod] 29 | public void NullName() 30 | { 31 | Assert.AreEqual(-1, shader.GetUniformLocation(null)); 32 | } 33 | 34 | [TestMethod] 35 | public void ValidArrayName() 36 | { 37 | Assert.AreEqual(GL.GetUniformLocation(shader.Id, "floatArray1"), shader.GetUniformLocation("floatArray1")); 38 | } 39 | 40 | [TestMethod] 41 | public void ValidArrayNameBrackets() 42 | { 43 | Assert.AreEqual(GL.GetUniformLocation(shader.Id, "floatArray1[0]"), shader.GetUniformLocation("floatArray1[0]")); 44 | } 45 | 46 | [TestMethod] 47 | public void ShaderNotLinked() 48 | { 49 | var shader = new Shader(); 50 | Assert.AreEqual(-1, shader.GetUniformLocation("memes")); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/ProgramCreationTests/JustVertShader.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using RenderTestUtils; 4 | using SFGraphics.GLObjects.Shaders; 5 | 6 | 7 | namespace SFGraphics.Test.ShaderTests.ProgramCreationTests 8 | { 9 | [TestClass] 10 | public class JustVertShader : GraphicsContextTest 11 | { 12 | [TestMethod] 13 | public void ValidVertShader() 14 | { 15 | // Load the shader file from the embedded resources. 16 | Shader shader = new Shader(); 17 | string shaderSource = ResourceShaders.GetShaderSource("valid.vert"); 18 | shader.LoadShaders(new ShaderObject(shaderSource, ShaderType.VertexShader)); 19 | 20 | Assert.IsTrue(shader.LinkStatusIsOk); 21 | 22 | Assert.AreEqual(0, shader.ActiveUniformCount); 23 | Assert.AreEqual(0, shader.ActiveUniformBlockCount); 24 | Assert.AreEqual(2, shader.ActiveAttributeCount); 25 | } 26 | 27 | [TestMethod] 28 | public void InvalidVertShader() 29 | { 30 | // Load the shader file from the embedded resources. 31 | Shader shader = new Shader(); 32 | string shaderSource = ResourceShaders.GetShaderSource("invalid.vert"); 33 | shader.LoadShaders(new ShaderObject(shaderSource, ShaderType.VertexShader)); 34 | 35 | Assert.IsFalse(shader.LinkStatusIsOk); 36 | 37 | Assert.AreEqual(0, shader.ActiveUniformCount); 38 | Assert.AreEqual(0, shader.ActiveUniformBlockCount); 39 | Assert.AreEqual(0, shader.ActiveAttributeCount); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/ProgramCreationTests/LinkError.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using RenderTestUtils; 4 | using SFGraphics.GLObjects.Shaders; 5 | 6 | 7 | namespace SFGraphics.Test.ShaderTests.ProgramCreationTests 8 | { 9 | [TestClass] 10 | public class LinkError : GraphicsContextTest 11 | { 12 | [TestMethod] 13 | public void FunctionNotDefined() 14 | { 15 | Shader shader = new Shader(); 16 | 17 | // The shader declared but does not define a function. 18 | string fragSource = ResourceShaders.GetShaderSource("undefinedFunction.frag"); 19 | shader.LoadShaders(new ShaderObject(fragSource, ShaderType.FragmentShader)); 20 | Assert.IsFalse(shader.LinkStatusIsOk); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/ProgramCreationTests/NoShaders.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGraphics.GLObjects.Shaders; 3 | 4 | 5 | namespace SFGraphics.Test.ShaderTests.ProgramCreationTests 6 | { 7 | [TestClass] 8 | public class NoShaders : GraphicsContextTest 9 | { 10 | [TestMethod] 11 | public void NoAttachedShaders() 12 | { 13 | Shader shader = new Shader(); 14 | Assert.IsFalse(shader.LinkStatusIsOk); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/ProgramCreationTests/OnLinkStatusChanged.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK.Graphics.OpenGL; 4 | using RenderTestUtils; 5 | using SFGraphics.GLObjects.Shaders; 6 | using SFGraphics.GLObjects.Shaders.ShaderEventArgs; 7 | 8 | namespace SFGraphics.Test.ShaderTests.ProgramCreationTests 9 | { 10 | [TestClass] 11 | public class OnLinkStatusChanged : GraphicsContextTest 12 | { 13 | private Shader shader; 14 | private readonly List linkChangedEvents = new List(); 15 | 16 | [TestInitialize] 17 | public override void Initialize() 18 | { 19 | // Set up the context for all the tests. 20 | base.Initialize(); 21 | shader = new Shader(); 22 | shader.LinkStatusChanged += Shader_OnLinkStatusChanged; 23 | } 24 | 25 | private void Shader_OnLinkStatusChanged(object sender, LinkStatusEventArgs e) 26 | { 27 | linkChangedEvents.Add(e); 28 | } 29 | 30 | [TestMethod] 31 | public void ValidFragShader() 32 | { 33 | string shaderSource = ResourceShaders.GetShaderSource("valid.frag"); 34 | shader.LoadShaders(new ShaderObject(shaderSource, ShaderType.FragmentShader)); 35 | 36 | Assert.AreEqual(1, linkChangedEvents.Count); 37 | Assert.AreEqual(true, linkChangedEvents[0].LinkStatus); 38 | } 39 | 40 | [TestMethod] 41 | public void ValidInvalidFragShader() 42 | { 43 | string shaderSource = ResourceShaders.GetShaderSource("valid.frag"); 44 | shader.LoadShaders(new ShaderObject(shaderSource, ShaderType.FragmentShader)); 45 | 46 | string shaderSourceInvalid = ResourceShaders.GetShaderSource("invalid.frag"); 47 | shader.LoadShaders(new ShaderObject(shaderSourceInvalid, ShaderType.FragmentShader)); 48 | 49 | Assert.AreEqual(2, linkChangedEvents.Count); 50 | Assert.AreEqual(true, linkChangedEvents[0].LinkStatus); 51 | Assert.AreEqual(false, linkChangedEvents[1].LinkStatus); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/ProgramCreationTests/ValidFragInvalidVert.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using RenderTestUtils; 4 | using SFGraphics.GLObjects.Shaders; 5 | 6 | namespace SFGraphics.Test.ShaderTests.ProgramCreationTests 7 | { 8 | [TestClass] 9 | public class ValidFragInvalidVert : GraphicsContextTest 10 | { 11 | [TestMethod] 12 | public void ValidFragInvalidVertShader() 13 | { 14 | Shader shader = new Shader(); 15 | 16 | // Load the shader files from the embedded resources. 17 | string fragSource = ResourceShaders.GetShaderSource("valid.frag"); 18 | shader.LoadShaders(new ShaderObject(fragSource, ShaderType.FragmentShader)); 19 | // Force an update of compilation/link status. 20 | Assert.IsTrue(shader.LinkStatusIsOk); 21 | 22 | // Make sure the compilation/link status still updates. 23 | string vertSource = ResourceShaders.GetShaderSource("invalid.vert"); 24 | shader.LoadShaders(new ShaderObject(vertSource, ShaderType.VertexShader)); 25 | Assert.IsFalse(shader.LinkStatusIsOk); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/ProgramCreationTests/ValidInvalidFragShader.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using RenderTestUtils; 4 | using SFGraphics.GLObjects.Shaders; 5 | 6 | namespace SFGraphics.Test.ShaderTests.ProgramCreationTests 7 | { 8 | [TestClass] 9 | public class ValidInvalidFragShader : GraphicsContextTest 10 | { 11 | [TestMethod] 12 | public void ValidAndInvalidFragShader() 13 | { 14 | // Load the shader file from the embedded resources. 15 | Shader shader = new Shader(); 16 | string shaderSource = ResourceShaders.GetShaderSource("valid.frag"); 17 | shader.LoadShaders(new ShaderObject(shaderSource, ShaderType.FragmentShader)); 18 | 19 | string shaderSource2 = ResourceShaders.GetShaderSource("invalid.frag"); 20 | shader.LoadShaders(new ShaderObject(shaderSource2, ShaderType.FragmentShader)); 21 | 22 | Assert.IsFalse(shader.LinkStatusIsOk); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/ProgramValidateStatus.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGraphics.GLObjects.Textures; 3 | 4 | namespace SFGraphics.Test.ShaderTests 5 | { 6 | [TestClass] 7 | public class ProgramValidateStatus : ShaderTest 8 | { 9 | [TestMethod] 10 | public void ValidStatus() 11 | { 12 | shader.SetTexture("tex2D", new Texture2D(), 0); 13 | shader.SetTexture("texCube", new TextureCubeMap(), 1); 14 | 15 | Assert.IsTrue(shader.ValidateStatusIsOk); 16 | } 17 | 18 | [TestMethod] 19 | public void TwoTypesPerTextureUnit() 20 | { 21 | shader.SetTexture("tex2D", new Texture2D(), 0); 22 | shader.SetTexture("texCube", new TextureCubeMap(), 0); 23 | 24 | // There can only be a single texture type for each active texture. 25 | Assert.IsFalse(shader.ValidateStatusIsOk); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetBoolToInt.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace SFGraphics.Test.ShaderTests.SetterTests 5 | { 6 | [TestClass] 7 | public class SetBoolToInt : ShaderTest 8 | { 9 | [TestMethod] 10 | public void ValidNameValidType() 11 | { 12 | shader.SetBoolToInt("boolInt1", true); 13 | Assert.AreEqual(1, GetInt("boolInt1")); 14 | 15 | shader.SetBoolToInt("boolInt1", false); 16 | Assert.AreEqual(0, GetInt("boolInt1")); 17 | 18 | Assert.IsTrue(IsValidSet("boolInt1", ActiveUniformType.Int)); 19 | } 20 | 21 | [TestMethod] 22 | public void InvalidName() 23 | { 24 | shader.SetBoolToInt("memes", true); 25 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.Int)); 26 | } 27 | 28 | [TestMethod] 29 | public void InvalidType() 30 | { 31 | shader.SetBoolToInt("float1", true); 32 | Assert.IsFalse(IsValidSet("float1", ActiveUniformType.Int)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetFloat.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace SFGraphics.Test.ShaderTests.SetterTests 5 | { 6 | [TestClass] 7 | public class SetFloat : ShaderTest 8 | { 9 | [TestMethod] 10 | public void ValidNameValidType() 11 | { 12 | shader.SetFloat("float1", 1); 13 | Assert.AreEqual(1, GetFloat("float1")); 14 | Assert.IsTrue(IsValidSet("float1", ActiveUniformType.Float)); 15 | } 16 | 17 | [TestMethod] 18 | public void InvalidType() 19 | { 20 | shader.SetFloat("int1", 0); 21 | Assert.IsFalse(IsValidSet("int1", ActiveUniformType.Float)); 22 | } 23 | 24 | [TestMethod] 25 | public void InvalidName() 26 | { 27 | shader.SetFloat("memes", 0.5f); 28 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.Float)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetFloatArray.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace SFGraphics.Test.ShaderTests.SetterTests 5 | { 6 | [TestClass] 7 | public class SetFloatArray : ShaderTest 8 | { 9 | private readonly float[] floatValues = { 1.5f, 2.5f, 3.5f }; 10 | 11 | [TestMethod] 12 | public void ValidNameValidType() 13 | { 14 | shader.SetFloat("floatArray1", floatValues); 15 | Assert.IsTrue(IsValidSet("floatArray1", ActiveUniformType.Float)); 16 | 17 | float[] values = GetFloatArray("floatArray1", floatValues.Length); 18 | CollectionAssert.AreEqual(floatValues, values); 19 | } 20 | 21 | [TestMethod] 22 | public void InvalidSize() 23 | { 24 | shader.SetFloat("floatArray1", new float[8]); 25 | Assert.IsFalse(IsValidSet("floatArray1", ActiveUniformType.Float)); 26 | } 27 | 28 | [TestMethod] 29 | public void InvalidType() 30 | { 31 | shader.SetFloat("intArray1", floatValues); 32 | Assert.IsFalse(IsValidSet("intArray1", ActiveUniformType.Float)); 33 | } 34 | 35 | [TestMethod] 36 | public void InvalidName() 37 | { 38 | shader.SetFloat("memesArray", floatValues); 39 | Assert.IsFalse(IsValidSet("memesArray", ActiveUniformType.Float)); 40 | } 41 | 42 | private float[] GetFloatArray(string name, int length) 43 | { 44 | // Array locations are sequential. 45 | float[] values = new float[length]; 46 | for (int i = 0; i < length; i++) 47 | GL.GetUniform(shader.Id, shader.GetUniformLocation(name) + i, out values[i]); 48 | 49 | return values; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetInt.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace SFGraphics.Test.ShaderTests.SetterTests 5 | { 6 | [TestClass] 7 | public class SetInt : ShaderTest 8 | { 9 | [TestMethod] 10 | public void ValidNameValidType() 11 | { 12 | shader.SetInt("int1", -1); 13 | Assert.AreEqual(-1, GetInt("int1")); 14 | Assert.IsTrue(IsValidSet("int1", ActiveUniformType.Int)); 15 | } 16 | 17 | [TestMethod] 18 | public void InvalidName() 19 | { 20 | shader.SetInt("memes", 0); 21 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.Int)); 22 | } 23 | 24 | [TestMethod] 25 | public void InvalidType() 26 | { 27 | shader.SetInt("float1", 0); 28 | Assert.IsFalse(IsValidSet("float1", ActiveUniformType.Int)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetIntArray.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace SFGraphics.Test.ShaderTests.SetterTests 5 | { 6 | [TestClass] 7 | public class SetIntArray : ShaderTest 8 | { 9 | private readonly int[] intValues = { -1, 0, 1 }; 10 | 11 | [TestMethod] 12 | public void ValidNameValidType() 13 | { 14 | shader.SetInt("intArray1", intValues); 15 | Assert.IsTrue(IsValidSet("intArray1", ActiveUniformType.Int)); 16 | 17 | var values = GetIntArray("intArray1", intValues.Length); 18 | CollectionAssert.AreEqual(intValues, values); 19 | } 20 | 21 | [TestMethod] 22 | public void InvalidSize() 23 | { 24 | shader.SetInt("intArray1", new int[8]); 25 | Assert.IsFalse(IsValidSet("intArray1", ActiveUniformType.Int)); 26 | } 27 | 28 | [TestMethod] 29 | public void InvalidName() 30 | { 31 | shader.SetInt("memes", intValues); 32 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.Int)); 33 | } 34 | 35 | [TestMethod] 36 | public void InvalidType() 37 | { 38 | shader.SetInt("float1", intValues); 39 | Assert.IsFalse(IsValidSet("float1", ActiveUniformType.Int)); 40 | } 41 | 42 | private int[] GetIntArray(string name, int length) 43 | { 44 | // Array locations are sequential. 45 | int[] values = new int[length]; 46 | for (int i = 0; i < length; i++) 47 | GL.GetUniform(shader.Id, shader.GetUniformLocation(name) + i, out values[i]); 48 | 49 | return values; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetMatrix4x4.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.ShaderTests.SetterTests 6 | { 7 | [TestClass] 8 | public class SetMatrix4x4 : ShaderTest 9 | { 10 | private static readonly float[] identityMatrix = { 11 | 1, 0, 0, 0, 12 | 0, 1, 0, 0, 13 | 0, 0, 1, 0, 14 | 0, 0, 0, 1 15 | }; 16 | 17 | [TestMethod] 18 | public void ValidNameValidType() 19 | { 20 | Matrix4 matrix4 = Matrix4.Identity; 21 | shader.SetMatrix4x4("matrix4a", ref matrix4); 22 | Assert.IsTrue(IsValidSet("matrix4a", ActiveUniformType.FloatMat4)); 23 | 24 | float[] values = GetMatrixValues("matrix4a"); 25 | CollectionAssert.AreEqual(identityMatrix, values); 26 | } 27 | 28 | [TestMethod] 29 | public void ValidNameValidTypeNoRef() 30 | { 31 | shader.SetMatrix4x4("matrix4a", Matrix4.Identity); 32 | Assert.IsTrue(IsValidSet("matrix4a", ActiveUniformType.FloatMat4)); 33 | 34 | float[] values = GetMatrixValues("matrix4a"); 35 | CollectionAssert.AreEqual(identityMatrix, values); 36 | } 37 | 38 | [TestMethod] 39 | public void InvalidName() 40 | { 41 | Matrix4 matrix4 = Matrix4.Identity; 42 | shader.SetMatrix4x4("memes", ref matrix4); 43 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.FloatMat4)); 44 | } 45 | 46 | [TestMethod] 47 | public void InvalidType() 48 | { 49 | Matrix4 matrix4 = Matrix4.Identity; 50 | shader.SetMatrix4x4("float1", ref matrix4); 51 | Assert.IsFalse(IsValidSet("float1", ActiveUniformType.FloatMat4)); 52 | } 53 | 54 | private float[] GetMatrixValues(string name) 55 | { 56 | float[] values = new float[16]; 57 | GL.GetUniform(shader.Id, shader.GetUniformLocation(name), values); 58 | return values; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetUint.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace SFGraphics.Test.ShaderTests.SetterTests 5 | { 6 | [TestClass] 7 | public class SetUint : ShaderTest 8 | { 9 | [TestMethod] 10 | public void ValidNameValidType() 11 | { 12 | shader.SetUint("uint1", uint.MaxValue); 13 | Assert.AreEqual(uint.MaxValue, GetUint("uint1")); 14 | Assert.IsTrue(IsValidSet("uint1", ActiveUniformType.UnsignedInt)); 15 | } 16 | 17 | [TestMethod] 18 | public void InvalidName() 19 | { 20 | shader.SetUint("memes", 0); 21 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.UnsignedInt)); 22 | } 23 | 24 | [TestMethod] 25 | public void InvalidType() 26 | { 27 | shader.SetUint("float1", 0); 28 | Assert.IsFalse(IsValidSet("float1", ActiveUniformType.UnsignedInt)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetUintArray.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.ShaderTests.SetterTests 6 | { 7 | [TestClass] 8 | public class SetUintArray : ShaderTest 9 | { 10 | private readonly uint[] uintValues = { 1, 2, 3 }; 11 | 12 | [TestMethod] 13 | public void ValidNameValidType() 14 | { 15 | shader.SetUint("uintArray1", uintValues); 16 | Assert.IsTrue(IsValidSet("uintArray1", ActiveUniformType.UnsignedInt)); 17 | 18 | var values = GetUintArray("uintArray1", uintValues.Length); 19 | CollectionAssert.AreEqual(uintValues, values); 20 | } 21 | 22 | [TestMethod] 23 | public void InvalidName() 24 | { 25 | shader.SetUint("memes", uintValues); 26 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.UnsignedInt)); 27 | } 28 | 29 | [TestMethod] 30 | public void InvalidSize() 31 | { 32 | shader.SetUint("uintArray1", new uint[8]); 33 | Assert.IsFalse(IsValidSet("uintArray1", ActiveUniformType.UnsignedInt)); 34 | } 35 | 36 | [TestMethod] 37 | public void InvalidType() 38 | { 39 | shader.SetUint("floatArray1", uintValues); 40 | Assert.IsFalse(IsValidSet("floatArray1", ActiveUniformType.UnsignedInt)); 41 | } 42 | 43 | private uint[] GetUintArray(string name, int length) 44 | { 45 | // Array locations are sequential. 46 | uint[] values = new uint[length]; 47 | for (int i = 0; i < length; i++) 48 | { 49 | GL.GetUniform(shader.Id, shader.GetUniformLocation(name) + i, out int value); 50 | values[i] = BitConverter.ToUInt32(BitConverter.GetBytes(value), 0); 51 | } 52 | 53 | return values; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetVector2.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.ShaderTests.SetterTests 6 | { 7 | [TestClass] 8 | public class SetVector2 : ShaderTest 9 | { 10 | [TestMethod] 11 | public void ValidNameValidType() 12 | { 13 | shader.SetVector2("vector2a", new Vector2(0.1f, -0.2f)); 14 | Assert.AreEqual(new Vector2(0.1f, -0.2f), GetVector2("vector2a")); 15 | Assert.IsTrue(IsValidSet("vector2a", ActiveUniformType.FloatVec2)); 16 | } 17 | 18 | [TestMethod] 19 | public void InvalidName() 20 | { 21 | shader.SetVector2("memes", new Vector2(1)); 22 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.FloatVec2)); 23 | } 24 | 25 | [TestMethod] 26 | public void FloatsValidNameValidType() 27 | { 28 | shader.SetVector2("vector2a", 0.5f, -0.75f); 29 | Assert.AreEqual(new Vector2(0.5f, -0.75f), GetVector2("vector2a")); 30 | Assert.IsTrue(IsValidSet("vector2a", ActiveUniformType.FloatVec2)); 31 | } 32 | 33 | [TestMethod] 34 | public void FloatsInvalidName() 35 | { 36 | shader.SetVector2("memes2", 1, 1); 37 | Assert.IsFalse(IsValidSet("memes2", ActiveUniformType.FloatVec2)); 38 | } 39 | 40 | [TestMethod] 41 | public void InvalidType() 42 | { 43 | shader.SetVector2("float1", 1, 1); 44 | Assert.IsFalse(IsValidSet("float1", ActiveUniformType.FloatVec2)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetVector2Array.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.ShaderTests.SetterTests 6 | { 7 | [TestClass] 8 | public class SetVector2Array : ShaderTest 9 | { 10 | private readonly Vector2[] vector2Values = 11 | { 12 | new Vector2(1, 2), 13 | new Vector2(3, 4) 14 | }; 15 | 16 | [TestMethod] 17 | public void ValidName() 18 | { 19 | shader.SetVector2("vector2Arr", vector2Values); 20 | Assert.IsTrue(IsValidSet("vector2Arr", ActiveUniformType.FloatVec2)); 21 | 22 | var values = GetVector2Array("vector2Arr", 2); 23 | CollectionAssert.AreEqual(vector2Values, values); 24 | } 25 | 26 | [TestMethod] 27 | public void InvalidSize() 28 | { 29 | shader.SetVector2("vector2Arr", new Vector2[8]); 30 | Assert.IsFalse(IsValidSet("vector2Arr", ActiveUniformType.FloatVec2)); 31 | } 32 | 33 | [TestMethod] 34 | public void InvalidName() 35 | { 36 | shader.SetVector2("memes", new Vector2[8]); 37 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.FloatVec2)); 38 | } 39 | 40 | [TestMethod] 41 | public void InvalidType() 42 | { 43 | shader.SetVector2("vector4Arr", new Vector2[8]); 44 | Assert.IsFalse(IsValidSet("vector4Arr", ActiveUniformType.FloatVec2)); 45 | } 46 | 47 | private Vector2[] GetVector2Array(string name, int length) 48 | { 49 | // Array locations are sequential. 50 | Vector2[] values = new Vector2[length]; 51 | for (int i = 0; i < length; i++) 52 | { 53 | float[] xy = new float[2]; 54 | GL.GetUniform(shader.Id, shader.GetUniformLocation(name) + i, xy); 55 | values[i] = new Vector2(xy[0], xy[1]); 56 | } 57 | 58 | return values; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetVector3.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.ShaderTests.SetterTests 6 | { 7 | [TestClass] 8 | public class SetVector3 : ShaderTest 9 | { 10 | [TestMethod] 11 | public void ValidNameValidType() 12 | { 13 | shader.SetVector3("vector3a", new Vector3(-1, 0.5f, 1)); 14 | Assert.AreEqual(new Vector3(-1, 0.5f, 1), GetVector3("vector3a")); 15 | Assert.IsTrue(IsValidSet("vector3", ActiveUniformType.FloatVec3)); 16 | } 17 | 18 | [TestMethod] 19 | public void InvalidName() 20 | { 21 | shader.SetVector3("memes", new Vector3(1)); 22 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.FloatVec3)); 23 | } 24 | 25 | [TestMethod] 26 | public void InvalidType() 27 | { 28 | shader.SetVector3("float1", 1, 1, 1); 29 | Assert.IsFalse(IsValidSet("float1", ActiveUniformType.FloatVec3)); 30 | } 31 | 32 | [TestMethod] 33 | public void FloatsValidNameValidType() 34 | { 35 | shader.SetVector3("vector3a", 1, 2, -2.5f); 36 | Assert.AreEqual(new Vector3(1, 2, -2.5f), GetVector3("vector3a")); 37 | Assert.IsTrue(IsValidSet("vector3a", ActiveUniformType.FloatVec3)); 38 | } 39 | 40 | [TestMethod] 41 | public void FloatsInvalidName() 42 | { 43 | shader.SetVector3("memes2", 1, 1, 1); 44 | Assert.IsFalse(IsValidSet("memes2", ActiveUniformType.FloatVec3)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetVector3Array.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.ShaderTests.SetterTests 6 | { 7 | [TestClass] 8 | public class SetVector3Array : ShaderTest 9 | { 10 | private readonly Vector3[] vector3Values = { 11 | new Vector3(1, 2, 3), 12 | new Vector3(4, 5, 6) 13 | }; 14 | 15 | [TestMethod] 16 | public void ValidNameValidType() 17 | { 18 | shader.SetVector3("vector3Arr", vector3Values); 19 | Assert.IsTrue(IsValidSet("vector3Arr", ActiveUniformType.FloatVec3)); 20 | 21 | var values = GetVector3Array("vector3Arr", vector3Values.Length); 22 | CollectionAssert.AreEqual(vector3Values, values); 23 | } 24 | 25 | [TestMethod] 26 | public void InvalidSize() 27 | { 28 | shader.SetVector3("vector3Arr", new Vector3[8]); 29 | Assert.IsFalse(IsValidSet("vector3Arr", ActiveUniformType.FloatVec3)); 30 | } 31 | 32 | [TestMethod] 33 | public void InvalidName() 34 | { 35 | shader.SetVector3("memes", new Vector3[8]); 36 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.FloatVec3)); 37 | } 38 | 39 | [TestMethod] 40 | public void InvalidType() 41 | { 42 | shader.SetVector3("vector2Arr", new Vector3[8]); 43 | Assert.IsFalse(IsValidSet("vector2Arr", ActiveUniformType.FloatVec3)); 44 | } 45 | 46 | private Vector3[] GetVector3Array(string name, int length) 47 | { 48 | // Array locations are sequential. 49 | Vector3[] values = new Vector3[length]; 50 | for (int i = 0; i < length; i++) 51 | { 52 | float[] xyz = new float[3]; 53 | GL.GetUniform(shader.Id, shader.GetUniformLocation(name) + i, xyz); 54 | values[i] = new Vector3(xyz[0], xyz[1], xyz[2]); 55 | } 56 | 57 | return values; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetVector4.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.ShaderTests.SetterTests 6 | { 7 | [TestClass] 8 | public class SetVector4 : ShaderTest 9 | { 10 | [TestMethod] 11 | public void ValidNameValidType() 12 | { 13 | shader.SetVector4("vector4a", new Vector4(-0.5f, 0, 0.5f, 1)); 14 | Assert.AreEqual(new Vector4(-0.5f, 0, 0.5f, 1), GetVector4("vector4a")); 15 | Assert.IsTrue(IsValidSet("vector4a", ActiveUniformType.FloatVec4)); 16 | } 17 | 18 | [TestMethod] 19 | public void InvalidName() 20 | { 21 | shader.SetVector4("memes", new Vector4(1)); 22 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.FloatVec4)); 23 | } 24 | 25 | [TestMethod] 26 | public void FloatsValidNameValidType() 27 | { 28 | shader.SetVector4("vector4a", 1, 2, 3, -0.1f); 29 | Assert.AreEqual(new Vector4(1, 2, 3, -0.1f), GetVector4("vector4a")); 30 | Assert.IsTrue(IsValidSet("vector4a", ActiveUniformType.FloatVec4)); 31 | } 32 | 33 | [TestMethod] 34 | public void FloatsInvalidName() 35 | { 36 | shader.SetVector4("memes2", 1, 1, 1, 1); 37 | Assert.IsFalse(IsValidSet("memes2", ActiveUniformType.FloatVec4)); 38 | } 39 | 40 | [TestMethod] 41 | public void InvalidType() 42 | { 43 | shader.SetVector4("float1", 1, 1, 1, 1); 44 | Assert.IsFalse(IsValidSet("float1", ActiveUniformType.FloatVec4)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/SetUniformTests/SetVector4Array.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.ShaderTests.SetterTests 6 | { 7 | [TestClass] 8 | public class SetVector4Array : ShaderTest 9 | { 10 | private readonly Vector4[] vector4Values = { 11 | new Vector4(1, 2, 3, 4), 12 | new Vector4(5, 6, 7, 8) 13 | }; 14 | 15 | [TestMethod] 16 | public void ValidName() 17 | { 18 | shader.SetVector4("vector4Arr", vector4Values); 19 | Assert.IsTrue(IsValidSet("vector4Arr", ActiveUniformType.FloatVec4)); 20 | 21 | var values = GetVector4Array("vector4Arr", vector4Values.Length); 22 | CollectionAssert.AreEqual(vector4Values, values); 23 | } 24 | 25 | 26 | [TestMethod] 27 | public void InvalidSize() 28 | { 29 | shader.SetVector4("vector4Arr", new Vector4[8]); 30 | Assert.IsFalse(IsValidSet("vector4Arr", ActiveUniformType.FloatVec4)); 31 | } 32 | 33 | [TestMethod] 34 | public void InvalidName() 35 | { 36 | shader.SetVector4("memes", new Vector4[8]); 37 | Assert.IsFalse(IsValidSet("memes", ActiveUniformType.FloatVec4)); 38 | } 39 | 40 | [TestMethod] 41 | public void InvalidType() 42 | { 43 | shader.SetVector4("vector2Arr", new Vector4[8]); 44 | Assert.IsFalse(IsValidSet("vector2Arr", ActiveUniformType.FloatVec4)); 45 | } 46 | 47 | private Vector4[] GetVector4Array(string name, int length) 48 | { 49 | // Array locations are sequential. 50 | Vector4[] values = new Vector4[length]; 51 | for (int i = 0; i < length; i++) 52 | { 53 | float[] xyzw = new float[4]; 54 | GL.GetUniform(shader.Id, shader.GetUniformLocation(name) + i, xyzw); 55 | values[i] = new Vector4(xyzw[0], xyzw[1], xyzw[2], xyzw[3]); 56 | } 57 | 58 | return values; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/ShaderTestValidShader.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using RenderTestUtils; 4 | using SFGraphics.GLObjects.Shaders; 5 | using SFGraphics.GLObjects.Shaders.ShaderEventArgs; 6 | 7 | namespace SFGraphics.Test.ShaderTests 8 | { 9 | [TestClass] 10 | internal class ShaderTestValidShader 11 | { 12 | protected Shader shader; 13 | protected List eventArgs = new List(); 14 | 15 | [TestInitialize] 16 | public void Initialize() 17 | { 18 | if (shader == null) 19 | { 20 | shader = ShaderTestUtils.CreateValidShader(); 21 | shader.InvalidUniformSet += Shader_OnInvalidUniformSet; 22 | } 23 | 24 | eventArgs.Clear(); 25 | } 26 | 27 | private void Shader_OnInvalidUniformSet(object sender, UniformSetEventArgs e) 28 | { 29 | eventArgs.Add(e); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/UniformBlockBinding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace SFGraphics.Test.ShaderTests 6 | { 7 | [TestClass] 8 | public class UniformBlockBinding : ShaderTest 9 | { 10 | [TestMethod] 11 | public void ValidName() 12 | { 13 | shader.UniformBlockBinding("UniformBlockA", 3); 14 | GL.GetActiveUniformBlock(shader.Id, 15 | shader.GetUniformBlockIndex("UniformBlockA"), 16 | ActiveUniformBlockParameter.UniformBlockBinding, out int binding); 17 | Assert.AreEqual(3, binding); 18 | } 19 | 20 | [TestMethod] 21 | public void InvalidName() 22 | { 23 | // Shouldn't throw graphics exceptions. 24 | shader.UniformBlockBinding("memes", 3); 25 | } 26 | 27 | 28 | [TestMethod] 29 | public void InvalidBinding() 30 | { 31 | // Shouldn't throw graphics exceptions. 32 | var e = Assert.ThrowsException(() => 33 | shader.UniformBlockBinding("UniformBlock", -1)); 34 | 35 | Assert.IsTrue(e.Message.Contains("Binding points must be non negative.")); 36 | Assert.AreEqual("bindingPoint", e.ParamName); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/ShaderTests/UseProgram.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGraphics.GLObjects.Shaders; 3 | 4 | namespace SFGraphics.Test.ShaderTests 5 | { 6 | [TestClass] 7 | public class UseProgram : ShaderTest 8 | { 9 | [TestMethod] 10 | public void ValidProgram() 11 | { 12 | shader.UseProgram(); 13 | } 14 | 15 | [TestMethod] 16 | public void InvalidProgram() 17 | { 18 | // Shouldn't throw graphics exceptions. 19 | var shader = new Shader(); 20 | Assert.IsFalse(shader.LinkStatusIsOk); 21 | shader.UseProgram(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/TextureTests/DepthTextureConstructor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK.Graphics.OpenGL; 4 | using SFGraphics.GLObjects.Textures; 5 | 6 | 7 | namespace SFGraphics.Test.TextureTests 8 | { 9 | [TestClass] 10 | public class DepthTextureConstructor : GraphicsContextTest 11 | { 12 | [TestMethod] 13 | public void DepthFormat() 14 | { 15 | // Doesn't throw an exception. 16 | DepthTexture texture = new DepthTexture(1, 1, PixelInternalFormat.DepthComponent); 17 | } 18 | 19 | [TestMethod] 20 | public void NotDepthFormat() 21 | { 22 | var e = Assert.ThrowsException(() => 23 | new DepthTexture(1, 1, PixelInternalFormat.Rgba)); 24 | 25 | Assert.AreEqual("The PixelInternalFormat is not a valid depth component format.", e.Message); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/TextureTests/GetImageDataBgra.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK.Graphics.OpenGL; 4 | using SFGraphics.GLObjects.Textures; 5 | using SFGraphics.GLObjects.Textures.TextureFormats; 6 | 7 | 8 | namespace SFGraphics.Test.TextureTests 9 | { 10 | [TestClass] 11 | public class GetImageDataBgra : GraphicsContextTest 12 | { 13 | private readonly byte[] originalData = { 128, 0, 10, 255 }; 14 | 15 | [TestMethod] 16 | public void GetSinglePixel() 17 | { 18 | Texture2D texture = new Texture2D(); 19 | texture.LoadImageData(1, 1, originalData, 20 | new TextureFormatUncompressed(PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.UnsignedByte)); 21 | 22 | // The channels will be swapped by OpenGL. 23 | byte[] imageData = texture.GetImageDataBgra(0); 24 | CollectionAssert.AreEqual(new byte[] { 10, 0, 128, 255 }, imageData); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/TextureTests/GetImageDataRgba.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Textures; 4 | using SFGraphics.GLObjects.Textures.TextureFormats; 5 | 6 | 7 | namespace SFGraphics.Test.TextureTests 8 | { 9 | [TestClass] 10 | public class GetImageDataRgba : GraphicsContextTest 11 | { 12 | private readonly byte[] originalData = { 128, 255, 0, 10 }; 13 | 14 | [TestMethod] 15 | public void GetSingleRgbaPixel() 16 | { 17 | Texture2D texture = new Texture2D(); 18 | texture.LoadImageData(1, 1, originalData, 19 | new TextureFormatUncompressed(PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.UnsignedByte)); 20 | 21 | byte[] imageData = texture.GetImageDataRgba(0); 22 | CollectionAssert.AreEqual(originalData, imageData); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/TextureTests/MipmapLoadingExceptions.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK.Graphics.OpenGL; 4 | using SFGraphics.GLObjects.Textures.Utils; 5 | 6 | 7 | namespace SFGraphics.Test.TextureTests 8 | { 9 | [TestClass] 10 | public class MipmapLoadingExceptions : GraphicsContextTest 11 | { 12 | [TestMethod] 13 | public void LoadImageData2DBitmap() 14 | { 15 | // Doesn't throw exception. 16 | MipmapLoading.LoadBaseLevelGenerateMipmaps(TextureTarget.Texture2D, new Bitmap(128, 64)); 17 | } 18 | 19 | [TestMethod] 20 | public void LoadImageDataCubeBitmap() 21 | { 22 | // Doesn't throw exception. 23 | // Width and height must be equal for cube maps. 24 | MipmapLoading.LoadBaseLevelGenerateMipmaps(TextureTarget.TextureCubeMapPositiveX, new Bitmap(128, 128)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/TextureTests/Texture2DMsConstructor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK.Graphics.OpenGL; 4 | using SFGraphics.GLObjects.Textures; 5 | 6 | 7 | namespace SFGraphics.Test.TextureTests 8 | { 9 | [TestClass] 10 | public class Texture2DMsConstructor : GraphicsContextTest 11 | { 12 | [TestMethod] 13 | public void ValidSampleCount() 14 | { 15 | // Doesn't throw an exception. 16 | var texture = new Texture2DMultisample(64, 16, PixelInternalFormat.Rgb, 1); 17 | } 18 | 19 | [TestMethod] 20 | public void ZeroSamples() 21 | { 22 | var e = Assert.ThrowsException(() => 23 | new Texture2DMultisample(64, 16, PixelInternalFormat.Rgb, 0)); 24 | 25 | Assert.IsTrue(e.Message.Contains("Sample count must be greater than 0")); 26 | Assert.AreEqual("samples", e.ParamName); 27 | } 28 | 29 | [TestMethod] 30 | public void NegativeSamples() 31 | { 32 | var e = Assert.ThrowsException(() => 33 | new Texture2DMultisample(64, 16, PixelInternalFormat.Rgb, -1)); 34 | 35 | Assert.IsTrue(e.Message.Contains("Sample count must be greater than 0")); 36 | Assert.AreEqual("samples", e.ParamName); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/TextureTests/Texture2DTests/LoadImageDataBuffer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK.Graphics.OpenGL; 4 | using SFGraphics.GLObjects.BufferObjects; 5 | using SFGraphics.GLObjects.Textures; 6 | using SFGraphics.GLObjects.Textures.TextureFormats; 7 | 8 | 9 | namespace SFGraphics.Test.TextureTests 10 | { 11 | [TestClass] 12 | public class LoadImageDataBuffer : GraphicsContextTest 13 | { 14 | [TestMethod] 15 | public void UncompressedBaseLevel() 16 | { 17 | Texture2D texture = new Texture2D(); 18 | BufferObject pixelBuffer = new BufferObject(BufferTarget.PixelUnpackBuffer); 19 | pixelBuffer.SetData(new float[] { 1, 1, 1 }, BufferUsageHint.StaticDraw); 20 | texture.LoadImageData(1, 1, pixelBuffer, new TextureFormatUncompressed(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.Float)); 21 | } 22 | 23 | [TestMethod] 24 | public void UncompressedMipmaps() 25 | { 26 | Texture2D texture = new Texture2D(); 27 | BufferObject pixelBuffer = new BufferObject(BufferTarget.PixelUnpackBuffer); 28 | pixelBuffer.SetData(new float[] { 1, 1, 1 }, BufferUsageHint.StaticDraw); 29 | texture.LoadImageData(1, 1, new List { pixelBuffer }, 30 | new TextureFormatUncompressed(PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.Float)); 31 | } 32 | 33 | [TestMethod] 34 | public void CompressedMipmaps() 35 | { 36 | Texture2D texture = new Texture2D(); 37 | BufferObject pixelBuffer = new BufferObject(BufferTarget.PixelUnpackBuffer); 38 | pixelBuffer.SetData(new float[] { 1, 1, 1 }, BufferUsageHint.StaticDraw); 39 | texture.LoadImageData(1, 1, new List { pixelBuffer }, InternalFormat.CompressedRgbaS3tcDxt1Ext); 40 | } 41 | 42 | [TestMethod] 43 | public void CompressedBaseLevel() 44 | { 45 | Texture2D texture = new Texture2D(); 46 | BufferObject pixelBuffer = new BufferObject(BufferTarget.PixelUnpackBuffer); 47 | pixelBuffer.SetData(new float[] { 1, 1, 1 }, BufferUsageHint.StaticDraw); 48 | texture.LoadImageData(1, 1, pixelBuffer, InternalFormat.CompressedRgbaS3tcDxt1Ext); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/Tests/TextureTests/Texture3DTests/LoadImageData.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using SFGraphics.GLObjects.Textures; 4 | using SFGraphics.GLObjects.Textures.TextureFormats; 5 | 6 | 7 | namespace SFGraphics.Test.TextureTests.Texture3DTests 8 | { 9 | [TestClass] 10 | public class LoadImageData : GraphicsContextTest 11 | { 12 | // 2 x 4 x 8 RGBA byte. 13 | private readonly byte[] imageData = new byte[2 * 4 * 8 * 4]; 14 | 15 | [TestMethod] 16 | public void SetDimensions() 17 | { 18 | var texture = new Texture3D(); 19 | texture.LoadImageData(2, 4, 8, imageData, new TextureFormatUncompressed(PixelInternalFormat.Rgba, PixelFormat.Rgba, PixelType.Byte)); 20 | 21 | Assert.AreEqual(TextureWrapMode.ClampToEdge, texture.TextureWrapS); 22 | Assert.AreEqual(TextureWrapMode.ClampToEdge, texture.TextureWrapT); 23 | Assert.AreEqual(TextureWrapMode.ClampToEdge, texture.TextureWrapR); 24 | 25 | // Ensure the right wrap mode is used for no mipmaps. 26 | Assert.AreEqual(TextureMagFilter.Linear, texture.MagFilter); 27 | Assert.AreEqual(TextureMinFilter.Linear, texture.MinFilter); 28 | 29 | Assert.AreEqual(2, texture.Width); 30 | Assert.AreEqual(4, texture.Height); 31 | Assert.AreEqual(8, texture.Depth); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyTitle("SFGraphicsTest")] 5 | [assembly: AssemblyDescription("")] 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("SFGraphicsTest")] 9 | [assembly: AssemblyCopyright("Copyright © 2018")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: Guid("66831642-dbff-4fb8-91d0-cbf634f98cb3")] 16 | 17 | // [assembly: AssemblyVersion("1.0.*")] 18 | [assembly: AssemblyVersion("1.0.0.0")] 19 | [assembly: AssemblyFileVersion("1.0.0.0")] 20 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/README.md: -------------------------------------------------------------------------------- 1 | # SFGraphics Tests 2 | Unit tests for all classes and methods that don't depend on an OpenTK context. These tests are checked by each Appveyor build. 3 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/BitmapUtilsTests/GetBitmap.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace SFGraphics.Utils.Test.BitmapUtilsTests 5 | { 6 | [TestClass] 7 | public class GetBitmap 8 | { 9 | [TestMethod] 10 | public void CreateSinglePixel() 11 | { 12 | byte[] pixels = { 1, 2, 3, 4 }; 13 | using (var bmp = BitmapUtils.GetBitmap(1, 1, pixels)) 14 | { 15 | // Compare ABGR to ARGB. 16 | Assert.AreEqual(Color.FromArgb(4, 3, 2, 1), bmp.GetPixel(0, 0)); 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/BoundingSphereTests/GenerateBoundingSphere.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK; 4 | 5 | namespace SFGraphics.Utils.Test.BoundingSphereTests 6 | { 7 | [TestClass] 8 | public class GenerateBoundingSphere 9 | { 10 | [TestMethod] 11 | public void NoVertices() 12 | { 13 | var boundingSphere = BoundingSphereGenerator.GenerateBoundingSphere(new List()); 14 | Assert.AreEqual(new Vector4(0), boundingSphere); 15 | } 16 | 17 | [TestMethod] 18 | public void UnitCube() 19 | { 20 | var points = new List 21 | { 22 | new Vector3(0.5f, -0.5f, -0.5f), 23 | new Vector3(0.5f, -0.5f, 0.5f), 24 | new Vector3(-0.5f, -0.5f, 0.5f), 25 | new Vector3(-0.5f, -0.5f, -0.5f), 26 | new Vector3(0.5f, 0.5f, -0.5f), 27 | new Vector3(0.5f, 0.5f, 0.5f), 28 | new Vector3(-0.5f, 0.5f, 0.5f), 29 | new Vector3(-0.5f, 0.5f, -0.5f) 30 | }; 31 | 32 | var boundingSphere = BoundingSphereGenerator.GenerateBoundingSphere(points); 33 | Assert.IsTrue(SpherePointUtils.SphereContainsPoints(boundingSphere, points)); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/BoundingSphereTests/SpherePointUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using OpenTK; 3 | 4 | namespace SFGraphics.Utils.Test.BoundingSphereTests 5 | { 6 | internal static class SpherePointUtils 7 | { 8 | public static bool SphereContainsPoints(Vector4 sphere, List points) 9 | { 10 | foreach (var point in points) 11 | { 12 | if ((point - sphere.Xyz).LengthSquared > (sphere.W * sphere.W)) 13 | return false; 14 | } 15 | return true; 16 | } 17 | 18 | public static bool SphereContainsSpheres(Vector4 outer, List inner) 19 | { 20 | foreach (var sphere in inner) 21 | { 22 | // Check if distance between centers is less than sum of radii. 23 | if (Vector3.Distance(sphere.Xyz, outer.Xyz) > (outer.W + sphere.W)) 24 | return false; 25 | } 26 | return true; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/ColorUtilsTests/Clamp.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace SFGraphics.Utils.Test.ColorUtilsTests 4 | { 5 | [TestClass] 6 | public class ClampFloatTest 7 | { 8 | [TestMethod] 9 | public void WithinRange() 10 | { 11 | Assert.AreEqual(0.5f, ColorUtils.Clamp(0.5f, 0, 1)); 12 | } 13 | 14 | [TestMethod] 15 | public void BelowMin() 16 | { 17 | Assert.AreEqual(0.25f, ColorUtils.Clamp(0, 0.25f, 1)); 18 | } 19 | 20 | [TestMethod] 21 | public void AboveMax() 22 | { 23 | Assert.AreEqual(0.75f, ColorUtils.Clamp(1, 0, 0.75f)); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/ColorUtilsTests/GetColorTests/FromFloats.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace SFGraphics.Utils.Test.ColorUtilsTests.GetColorTests 5 | { 6 | [TestClass] 7 | public class FromFloats 8 | { 9 | [TestMethod] 10 | public void WithinRange() 11 | { 12 | Assert.AreEqual(Color.FromArgb(255, 127, 0, 255), ColorUtils.GetColor(0.5f, 0, 1)); 13 | } 14 | 15 | [TestMethod] 16 | public void BelowRange() 17 | { 18 | Assert.AreEqual(Color.FromArgb(0, 0, 0, 0), ColorUtils.GetColor(-1, -1, -1, -1)); 19 | } 20 | 21 | [TestMethod] 22 | public void AboveRange() 23 | { 24 | Assert.AreEqual(Color.FromArgb(255, 255, 255, 255), ColorUtils.GetColor(1.1f, 1.1f, 1.1f, 1.1f)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/ColorUtilsTests/GetColorTests/FromVector3.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK; 4 | 5 | namespace SFGraphics.Utils.Test.ColorUtilsTests.GetColorTests 6 | { 7 | [TestClass] 8 | public class FromVector3 9 | { 10 | [TestMethod] 11 | public void WithinRange() 12 | { 13 | Assert.AreEqual(Color.FromArgb(255, 127, 0, 255), ColorUtils.GetColor(new Vector3(0.5f, 0, 1))); 14 | } 15 | 16 | [TestMethod] 17 | public void BelowRange() 18 | { 19 | Assert.AreEqual(Color.FromArgb(255, 0, 0, 0), ColorUtils.GetColor(new Vector3(-1, -1, -1))); 20 | } 21 | 22 | [TestMethod] 23 | public void AboveRange() 24 | { 25 | Assert.AreEqual(Color.FromArgb(255, 255, 255, 255), ColorUtils.GetColor(new Vector3(1.1f, 1.1f, 1.1f))); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/ColorUtilsTests/GetColorTests/FromVector4.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK; 4 | 5 | namespace SFGraphics.Utils.Test.ColorUtilsTests.GetColorTests 6 | { 7 | [TestClass] 8 | public class FromVector4 9 | { 10 | [TestMethod] 11 | public void WithinRange() 12 | { 13 | Assert.AreEqual(Color.FromArgb(255, 127, 0, 255), ColorUtils.GetColor(new Vector4(0.5f, 0, 1, 1))); 14 | } 15 | 16 | [TestMethod] 17 | public void BelowRange() 18 | { 19 | Assert.AreEqual(Color.FromArgb(0, 0, 0, 0), ColorUtils.GetColor(new Vector4(-1, -1, -1, -1))); 20 | } 21 | 22 | [TestMethod] 23 | public void AboveRange() 24 | { 25 | Assert.AreEqual(Color.FromArgb(255, 255, 255, 255), ColorUtils.GetColor(new Vector4(1.1f, 1.1f, 1.1f, 1.1f))); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/ColorUtilsTests/GetVector3FromColor.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK; 4 | 5 | namespace SFGraphics.Utils.Test.ColorUtilsTests 6 | { 7 | [TestClass] 8 | public class Vector3FromColorTest 9 | { 10 | private readonly float delta = 0.001f; 11 | 12 | [TestMethod] 13 | public void Vector3FromBlack() 14 | { 15 | Color color = Color.FromArgb(128, 0, 0, 0); 16 | Vector3 actual = ColorUtils.GetVector3(color); 17 | 18 | Vector3 expected = new Vector3(0, 0, 0); 19 | Assert.AreEqual(expected.X, actual.X, delta); 20 | Assert.AreEqual(expected.Y, actual.Y, delta); 21 | Assert.AreEqual(expected.Z, actual.Z, delta); 22 | } 23 | 24 | [TestMethod] 25 | public void Vector3FromRgbChannels() 26 | { 27 | Color color = Color.FromArgb(128, 64, 32, 16); 28 | Vector3 actual = ColorUtils.GetVector3(color); 29 | 30 | Vector3 expected = new Vector3(0.251f, 0.126f, 0.063f); 31 | Assert.AreEqual(expected.X, actual.X, delta); 32 | Assert.AreEqual(expected.Y, actual.Y, delta); 33 | Assert.AreEqual(expected.Z, actual.Z, delta); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/ColorUtilsTests/GetVector4FromColor.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK; 4 | 5 | namespace SFGraphics.Utils.Test.ColorUtilsTests 6 | { 7 | [TestClass] 8 | public class Vector4FromColorTest 9 | { 10 | private readonly float delta = 0.001f; 11 | 12 | [TestMethod] 13 | public void Vector4FromBlack() 14 | { 15 | Color color = Color.FromArgb(128, 0, 0, 0); 16 | Vector4 actual = ColorUtils.GetVector4(color); 17 | 18 | Vector4 expected = new Vector4(0, 0, 0, 0.502f); 19 | Assert.AreEqual(expected.X, actual.X, delta); 20 | Assert.AreEqual(expected.Y, actual.Y, delta); 21 | Assert.AreEqual(expected.Z, actual.Z, delta); 22 | Assert.AreEqual(expected.W, actual.W, delta); 23 | } 24 | 25 | [TestMethod] 26 | public void Vector4FromAllChannels() 27 | { 28 | Color color = Color.FromArgb(128, 64, 32, 16); 29 | Vector4 actual = ColorUtils.GetVector4(color); 30 | 31 | Vector4 expected = new Vector4(0.251f, 0.126f, 0.063f, 0.502f); 32 | Assert.AreEqual(expected.X, actual.X, delta); 33 | Assert.AreEqual(expected.Y, actual.Y, delta); 34 | Assert.AreEqual(expected.Z, actual.Z, delta); 35 | Assert.AreEqual(expected.W, actual.W, delta); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/ColorUtilsTests/InvertColor.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace SFGraphics.Utils.Test.ColorUtilsTests 5 | { 6 | [TestClass] 7 | public class InvertColorTest 8 | { 9 | [TestMethod] 10 | public void InvertColor() 11 | { 12 | Color color = Color.FromArgb(255, 255, 255, 255); 13 | Color inverted = ColorUtils.InvertColor(color); 14 | 15 | Color expected = Color.FromArgb(255, 0, 0, 0); 16 | Assert.AreEqual(expected, inverted); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/TriangleListUtilsTests/CalculateSmoothNormals.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using OpenTK; 4 | 5 | namespace SFGraphics.Utils.Test.TriangleListUtilsTests 6 | { 7 | [TestClass] 8 | public class CalculateSmoothNormals 9 | { 10 | private static readonly float delta = 0.0001f; 11 | 12 | [TestMethod] 13 | public void NoVertices() 14 | { 15 | TriangleListUtils.CalculateSmoothNormals(new List(), new List(), out Vector3[] normals); 16 | 17 | Assert.AreEqual(0, normals.Length); 18 | } 19 | 20 | [TestMethod] 21 | public void ThreeVertices() 22 | { 23 | var values3d = new List { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) }; 24 | 25 | TriangleListUtils.CalculateSmoothNormals(values3d, new List { 0, 1, 2 }, out Vector3[] normals); 26 | 27 | // Ensure vectors are normalized. 28 | Assert.AreEqual(1.0f, normals[0].Length, delta); 29 | Assert.AreEqual(1.0f, normals[1].Length, delta); 30 | Assert.AreEqual(1.0f, normals[2].Length, delta); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/VectorUtilsTests/CalculateNormals.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | 4 | namespace SFGraphics.Utils.Test.VectorUtilsTests 5 | { 6 | [TestClass] 7 | public class CalculateNormals 8 | { 9 | [TestMethod] 10 | public void PositiveNormal() 11 | { 12 | // Vertices facing the camera should be in counter-clockwise order. 13 | Vector3 v1 = new Vector3(-5, 5, 1); 14 | Vector3 v2 = new Vector3(-5, 0, 1); 15 | Vector3 v3 = new Vector3(0, 0, 1); 16 | Vector3 normal = VectorUtils.CalculateNormal(v1, v2, v3).Normalized(); 17 | 18 | Assert.AreEqual(0, normal.X); 19 | Assert.AreEqual(0, normal.Y); 20 | Assert.AreEqual(1, normal.Z); 21 | } 22 | 23 | [TestMethod] 24 | public void NegativeNormal() 25 | { 26 | // Vertices facing the camera in clockwise order. 27 | Vector3 v1 = new Vector3(-5, 5, 1); 28 | Vector3 v2 = new Vector3(-5, 0, 1); 29 | Vector3 v3 = new Vector3(0, 0, 1); 30 | Vector3 normal = VectorUtils.CalculateNormal(v3, v2, v1).Normalized(); 31 | 32 | Assert.AreEqual(0, normal.X); 33 | Assert.AreEqual(0, normal.Y); 34 | Assert.AreEqual(-1, normal.Z); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/VectorUtilsTests/CalculateTangentW.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | 4 | namespace SFGraphicsTest.Test.VectorUtilsTests 5 | { 6 | [TestClass] 7 | public class CalculateTangentW 8 | { 9 | [TestMethod] 10 | public void ShouldFlip() 11 | { 12 | // cross(tangent,bitangent) is in the opposite direction of the normal. 13 | // This occurs on the side with mirrored UVs. 14 | var tangent = new Vector3(0, 1, 0); 15 | var bitangent = new Vector3(1, 0, 0); 16 | var normal = new Vector3(0, 0, 1); 17 | var w = SFGraphics.Utils.VectorUtils.CalculateTangentW(normal, tangent, bitangent); 18 | Assert.AreEqual(-1.0f, w); 19 | } 20 | 21 | [TestMethod] 22 | public void ShouldNotFlip() 23 | { 24 | // cross(tangent,bitangent) is in the same direction as the normal. 25 | // This occurs on the side without mirrored UVs. 26 | var tangent = new Vector3(1, 0, 0); 27 | var bitangent = new Vector3(0, 1, 0); 28 | var normal = new Vector3(0, 0, 1); 29 | var w = SFGraphics.Utils.VectorUtils.CalculateTangentW(normal, tangent, bitangent); 30 | Assert.AreEqual(1.0f, w); 31 | } 32 | 33 | [TestMethod] 34 | public void ShouldNotBeZero() 35 | { 36 | // cross(tangent,bitangent) is orthogonal to the normal. 37 | var tangent = new Vector3(1, 0, 0); 38 | var bitangent = new Vector3(0, 1, 0); 39 | var normal = new Vector3(1, 0, 0); 40 | var w = SFGraphics.Utils.VectorUtils.CalculateTangentW(normal, tangent, bitangent); 41 | Assert.AreEqual(1.0f, w); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/VectorUtilsTests/GetDegrees.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace SFGraphics.Utils.Test.VectorUtilsTests 4 | { 5 | [TestClass] 6 | public class GetDegrees 7 | { 8 | private readonly double delta = 0.00001; 9 | 10 | [TestMethod] 11 | public void ZeroRadiansToDegrees() 12 | { 13 | Assert.AreEqual(0, VectorUtils.GetDegrees(0), delta); 14 | } 15 | 16 | [TestMethod] 17 | public void SmallRadiansToDegrees() 18 | { 19 | Assert.AreEqual(35, VectorUtils.GetDegrees(0.6108652382), delta); 20 | } 21 | 22 | [TestMethod] 23 | public void LargeRadiansToDegrees() 24 | { 25 | Assert.AreEqual(720, VectorUtils.GetDegrees(12.566370614), delta); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/VectorUtilsTests/GetRadians.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace SFGraphics.Utils.Test.VectorUtilsTests 4 | { 5 | [TestClass] 6 | public class GetRadians 7 | { 8 | private readonly double delta = 0.00001; 9 | 10 | [TestMethod] 11 | public void ZeroDegreesToRadians() 12 | { 13 | Assert.AreEqual(0, VectorUtils.GetRadians(0), delta); 14 | } 15 | 16 | [TestMethod] 17 | public void SmallDegreesToRadians() 18 | { 19 | Assert.AreEqual(0.6108652382, VectorUtils.GetRadians(35), delta); 20 | } 21 | 22 | [TestMethod] 23 | public void LargeDegreesToRadians() 24 | { 25 | Assert.AreEqual(12.566370614, VectorUtils.GetRadians(720), delta); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/Test/VectorUtilsTests/Orthogonalize.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK; 3 | 4 | namespace SFGraphics.Utils.Test.VectorUtilsTests 5 | { 6 | [TestClass] 7 | public class Orthogonalize 8 | { 9 | private readonly double delta = 0.0001; 10 | 11 | [TestMethod] 12 | public void OrthogonalizeVector() 13 | { 14 | // Not orthogonal initally. 15 | Vector3 a = new Vector3(1, 0.5f, 0); 16 | Vector3 b = new Vector3(1, 0, 0); 17 | Assert.AreNotEqual(0, Vector3.Dot(a, b)); 18 | 19 | // a and b should now be orthogonal. 20 | // dot(a, b) == 0 if a and b are orthogonal. 21 | Vector3 aOrthoToB = VectorUtils.Orthogonalize(a, b); 22 | Assert.AreEqual(0, Vector3.Dot(aOrthoToB, b), delta); 23 | } 24 | 25 | [TestMethod] 26 | public void AlreadyOrthogonal() 27 | { 28 | // Already orthogonal. 29 | Vector3 a = new Vector3(0, 1, 0); 30 | Vector3 b = new Vector3(1, 0, 0); 31 | Assert.AreEqual(0, Vector3.Dot(a, b), delta); 32 | 33 | // a should remain the same 34 | Vector3 aOrthoToB = VectorUtils.Orthogonalize(a, b); 35 | Assert.AreEqual(a, aOrthoToB); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Test Projects/SFGraphics.Utils.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/AddShaderFromBinary.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGraphics.GLObjects.Shaders; 3 | using System.IO; 4 | using OpenTK.Graphics.OpenGL; 5 | 6 | namespace SFShaderLoader.Test 7 | { 8 | [TestClass] 9 | public class AddShaderFromBinary 10 | { 11 | private readonly ShaderLoader loader = new ShaderLoader(); 12 | 13 | [TestInitialize] 14 | public void Setup() 15 | { 16 | RenderTestUtils.OpenTKWindowlessContext.BindDummyContext(); 17 | } 18 | 19 | [TestMethod] 20 | public void AddValidBinary() 21 | { 22 | var shader = new Shader(); 23 | shader.LoadShaders(File.ReadAllText("Shaders/valid.vert"), File.ReadAllText("Shaders/valid.frag")); 24 | shader.GetProgramBinary(out byte[] binary, out BinaryFormat format); 25 | 26 | Assert.IsTrue(loader.AddShader("validShader", binary, format)); 27 | } 28 | 29 | [TestMethod] 30 | public void AddInvalidBinary() 31 | { 32 | var shader = new Shader(); 33 | shader.LoadShaders(File.ReadAllText("Shaders/valid.vert"), File.ReadAllText("Shaders/valid.frag")); 34 | shader.GetProgramBinary(out byte[] binary, out BinaryFormat format); 35 | 36 | // Use an empty binary to try and trigger an exception with GL.ProgramBinary. 37 | Assert.IsFalse(loader.AddShader("validShader", new byte[0], format)); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/AddShaderFromNames.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using System.IO; 4 | using System.Collections.Generic; 5 | 6 | namespace SFShaderLoader.Test 7 | { 8 | [TestClass] 9 | public class AddShaderFromNames 10 | { 11 | [TestInitialize] 12 | public void Setup() 13 | { 14 | RenderTestUtils.OpenTKWindowlessContext.BindDummyContext(); 15 | } 16 | 17 | [TestMethod] 18 | public void AddAllSources() 19 | { 20 | var loader = new ShaderLoader(); 21 | loader.AddSource("a", File.ReadAllText("Shaders/FunctionA.glsl"), ShaderType.FragmentShader); 22 | loader.AddSource("b", File.ReadAllText("Shaders/MultipleFunctions.frag"), ShaderType.FragmentShader); 23 | Assert.IsTrue(loader.AddShader("shader", "a", "b")); 24 | Assert.IsTrue(loader.GetShader("shader").LinkStatusIsOk); 25 | } 26 | 27 | [TestMethod] 28 | public void MissingSource() 29 | { 30 | var loader = new ShaderLoader(); 31 | loader.AddSource("b", File.ReadAllText("Shaders/MultipleFunctions.frag"), ShaderType.FragmentShader); 32 | Assert.IsFalse(loader.AddShader("shader", "b")); 33 | } 34 | 35 | [TestMethod] 36 | public void InvalidKey() 37 | { 38 | var loader = new ShaderLoader(); 39 | loader.AddSource("b", File.ReadAllText("Shaders/MultipleFunctions.frag"), ShaderType.FragmentShader); 40 | var e = Assert.ThrowsException(() => loader.AddShader("shader", "b", "(╯ຈل͜ຈ) ╯︵ ┻━┻")); 41 | Assert.AreEqual("Source not found for key (╯ຈل͜ຈ) ╯︵ ┻━┻", e.Message); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/AddSource.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using OpenTK.Graphics.OpenGL; 3 | using System.IO; 4 | 5 | namespace SFShaderLoader.Test 6 | { 7 | [TestClass] 8 | public class AddSource 9 | { 10 | [TestInitialize] 11 | public void Setup() 12 | { 13 | RenderTestUtils.OpenTKWindowlessContext.BindDummyContext(); 14 | } 15 | 16 | [TestMethod] 17 | public void AddValidSourceFrag() 18 | { 19 | var loader = new ShaderLoader(); 20 | Assert.IsTrue(loader.AddSource("frag1", File.ReadAllText("Shaders/valid.frag"), ShaderType.FragmentShader)); 21 | } 22 | 23 | [TestMethod] 24 | public void AddValidSourceVert() 25 | { 26 | var loader = new ShaderLoader(); 27 | Assert.IsTrue(loader.AddSource("vert1", File.ReadAllText("Shaders/valid.vert"), ShaderType.VertexShader)); 28 | } 29 | 30 | [TestMethod] 31 | public void AddValidSourceDuplicate() 32 | { 33 | var loader = new ShaderLoader(); 34 | Assert.IsTrue(loader.AddSource("frag1", File.ReadAllText("Shaders/valid.frag"), ShaderType.FragmentShader)); 35 | Assert.IsTrue(loader.AddSource("frag1", File.ReadAllText("Shaders/valid.frag"), ShaderType.FragmentShader)); 36 | } 37 | 38 | [TestMethod] 39 | public void AddInvalidSource() 40 | { 41 | var loader = new ShaderLoader(); 42 | Assert.IsFalse(loader.AddSource("frag1", @"¯\_( ͡° ͜ʖ ͡°)_/¯", ShaderType.FragmentShader)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/GetShader.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | 5 | namespace SFShaderLoader.Test 6 | { 7 | [TestClass] 8 | public class GetShader 9 | { 10 | private readonly ShaderLoader loader = new ShaderLoader(); 11 | 12 | [TestInitialize] 13 | public void Setup() 14 | { 15 | RenderTestUtils.OpenTKWindowlessContext.BindDummyContext(); 16 | 17 | loader.AddShader("validShader", 18 | new List() { File.ReadAllText("Shaders/valid.vert") }, 19 | new List() { File.ReadAllText("Shaders/valid.frag") }, 20 | new List()); 21 | } 22 | 23 | [TestMethod] 24 | public void GetInvalidName() 25 | { 26 | Assert.IsNull(loader.GetShader("invalidShader")); 27 | } 28 | 29 | [TestMethod] 30 | public void GetValidName() 31 | { 32 | Assert.IsNotNull(loader.GetShader("validShader")); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyTitle("SFShaderLoader.Test")] 5 | [assembly: AssemblyDescription("")] 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("SFShaderLoader.Test")] 9 | [assembly: AssemblyCopyright("Copyright © 2019")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: Guid("ce0ab008-0c14-4dc0-8f66-8c6f902e0315")] 16 | 17 | // [assembly: AssemblyVersion("1.0.*")] 18 | [assembly: AssemblyVersion("1.0.0.0")] 19 | [assembly: AssemblyFileVersion("1.0.0.0")] 20 | -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/Shaders/FunctionA.glsl: -------------------------------------------------------------------------------- 1 | float FunctionA() 2 | { 3 | return 1.5; 4 | } -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/Shaders/MultipleFunctions.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | out vec4 fragColor; 4 | 5 | float FunctionA(); 6 | 7 | void main() 8 | { 9 | fragColor = vec4(FunctionA()); 10 | } -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/Shaders/valid.frag: -------------------------------------------------------------------------------- 1 | #version 420 2 | 3 | out vec4 fragColor; 4 | 5 | void main() 6 | { 7 | fragColor = vec4(1); 8 | } 9 | -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/Shaders/valid.vert: -------------------------------------------------------------------------------- 1 | #version 420 2 | 3 | void main() 4 | { 5 | gl_Position = vec4(0); 6 | } 7 | -------------------------------------------------------------------------------- /Test Projects/SFShaderLoader.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Test Projects/SFTiming.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SFTiming.Test")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("SFTiming.Test")] 10 | [assembly: AssemblyCopyright("Copyright © 2020")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: Guid("f25c04bd-761a-4676-9bb2-c04e445cc362")] 17 | 18 | // [assembly: AssemblyVersion("1.0.*")] 19 | [assembly: AssemblyVersion("1.0.0.0")] 20 | [assembly: AssemblyFileVersion("1.0.0.0")] 21 | -------------------------------------------------------------------------------- /Test Projects/SFTiming.Test/ThreadTimerEvents.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using SFGraphics.Timing; 3 | 4 | namespace SFTiming.Test 5 | { 6 | [TestClass] 7 | public class ThreadTimerEvents 8 | { 9 | [TestMethod] 10 | public void CreateDispose() 11 | { 12 | var timer = new ThreadTimer(); 13 | timer.Dispose(); 14 | } 15 | 16 | [TestMethod] 17 | public void CreateDisposeAfterStarting() 18 | { 19 | var timer = new ThreadTimer(); 20 | timer.Start(); 21 | timer.Dispose(); 22 | } 23 | 24 | [TestMethod] 25 | public void StartStop() 26 | { 27 | using (var timer = new ThreadTimer()) 28 | { 29 | timer.Start(); 30 | timer.Stop(); 31 | } 32 | } 33 | 34 | [TestMethod] 35 | public void StartTwice() 36 | { 37 | using (var timer = new ThreadTimer()) 38 | { 39 | timer.Start(); 40 | timer.Start(); 41 | } 42 | } 43 | 44 | [TestMethod] 45 | public void StopTwice() 46 | { 47 | using (var timer = new ThreadTimer()) 48 | { 49 | timer.Stop(); 50 | timer.Stop(); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Test Projects/SFTiming.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /lib/OpenTK.GLControl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ScanMountGoat/SFGraphics/ec1c5f0741722cf6bea29fbe03c6f9226cc4d928/lib/OpenTK.GLControl.dll -------------------------------------------------------------------------------- /lib/OpenTK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ScanMountGoat/SFGraphics/ec1c5f0741722cf6bea29fbe03c6f9226cc4d928/lib/OpenTK.dll --------------------------------------------------------------------------------