public void ResetViewport() { EnsureNotDisposed(); SDL_gpu.GPU_UnsetViewport(TargetHandle); CurrentViewport = null; }
public void SetCamera(Camera camera) { EnsureNotDisposed(); SDL_gpu.GPU_SetCamera(TargetHandle, ref camera.GpuCamera); CurrentCamera = camera; }
public void SetUniform(string name, Texture value, int textureUnit) { EnsureNotDisposed(); if (value.Disposed) { throw new ArgumentException("Texture provided was already diposed."); } if (textureUnit == 0) { _log.Error("Cannot set texture unit 0: reserved for use by the rendering system blitting functions."); return; } var loc = SDL_gpu.GPU_GetUniformLocation(ProgramHandle, name); if (loc == -1) { _log.Warning($"Texture sampler '{name}' does not exist."); return; } SDL_gpu.GPU_SetShaderImage(value.ImageHandle, loc, textureUnit); }
public void ResetCamera() { EnsureNotDisposed(); SDL_gpu.GPU_SetCamera(TargetHandle, IntPtr.Zero); CurrentCamera = null; }
public VertexShader(string filePath) { FilePath = filePath; SourceCode = File.ReadAllText(FilePath); VertexShaderObjectHandle = SDL_gpu.GPU_CompileShader(SDL_gpu.GPU_ShaderEnum.GPU_VERTEX_SHADER, SourceCode); if (VertexShaderObjectHandle == 0) { throw new ShaderException("Compilation failed.", SDL_gpu.GPU_GetShaderMessage()); } CompileAndSetDefaultPixelShader(); if (PixelShaderObjectHandle == 0) { throw new ShaderException( "Default Chroma pixel shader compilation failed. " + "Report an issue - be sure to include GLSL errors or I'll f**k you up just like I did with this framework.", SDL_gpu.GPU_GetShaderMessage()); } ProgramHandle = SDL_gpu.GPU_LinkShaders(PixelShaderObjectHandle, VertexShaderObjectHandle); if (ProgramHandle == 0) { throw new ShaderException("Linkage failed.", SDL_gpu.GPU_GetShaderMessage()); } CreateShaderBlock(); }
private void LinkShaders() { ProgramHandle = SDL_gpu.GPU_LinkShaders(PixelShaderObjectHandle, VertexShaderObjectHandle); if (ProgramHandle == 0) { throw new ShaderException("Compound shader linkage failed.", SDL_gpu.GPU_GetShaderMessage()); } }
private void TryCompileVertexShader() { VertexShaderSourceCode = File.ReadAllText(VertexShaderFilePath); VertexShaderObjectHandle = SDL_gpu.GPU_CompileShader(SDL_gpu.GPU_ShaderEnum.GPU_VERTEX_SHADER, VertexShaderSourceCode); if (VertexShaderObjectHandle == 0) { throw new ShaderException("Vertex shader compilation failed.", SDL_gpu.GPU_GetShaderMessage()); } }
private void TryCompilePixelShader() { PixelShaderSourceCode = File.ReadAllText(PixelShaderFilePath); PixelShaderObjectHandle = SDL_gpu.GPU_CompileShader(SDL_gpu.GPU_ShaderEnum.GPU_PIXEL_SHADER, PixelShaderSourceCode); if (PixelShaderObjectHandle == 0) { throw new ShaderException("Pixel shader compilation failed.", SDL_gpu.GPU_GetShaderMessage()); } }
protected virtual void CompileAndSetDefaultPixelShader() { EnsureNotDisposed(); var shaderSourceStream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("Chroma.Resources.shader.default.frag"); using var sr = new StreamReader(shaderSourceStream !); PixelShaderObjectHandle = SDL_gpu.GPU_CompileShader(SDL_gpu.GPU_ShaderEnum.GPU_PIXEL_SHADER, sr.ReadToEnd()); }
protected void CompileAndSetDefaultVertexShader() { EnsureNotDisposed(); var shaderSourceStream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("Chroma.Resources.shader.default.vert"); using var sr = new StreamReader(shaderSourceStream); VertexShaderObjectHandle = SDL_gpu.GPU_CompileShader(SDL_gpu.GPU_ShaderEnum.GPU_VERTEX_SHADER, sr.ReadToEnd()); }
protected void CleanupAfterLinking() { SDL_gpu.GPU_DetachShader(ProgramHandle, VertexShaderObjectHandle); SDL_gpu.GPU_DetachShader(ProgramHandle, PixelShaderObjectHandle); SDL_gpu.GPU_FreeShader(VertexShaderObjectHandle); SDL_gpu.GPU_FreeShader(PixelShaderObjectHandle); VertexShaderObjectHandle = 0; PixelShaderObjectHandle = 0; }
public void Quit() { Audio.Dispose(); Content.Dispose(); SDL_mixer.Mix_Quit(); SDL_gpu.GPU_Quit(); SDL2.SDL_Quit(); Environment.Exit(0); }
public virtual void Activate() { EnsureNotDisposed(); if (ProgramHandle == 0) { _log.Warning($"Refusing to activate invalid shader."); return; } SDL_gpu.GPU_ActivateShaderProgram(ProgramHandle, ref Block); }
protected void CreateShaderBlock() { EnsureNotDisposed(); Block = SDL_gpu.GPU_LoadShaderBlock( ProgramHandle, "gpu_VertexPosition", "gpu_TexCoord", "gpu_VertexColor", "gpu_ModelViewProjection" ); }
private static void InitializeSdlSystems() { Console.WriteLine("---"); Console.WriteLine("Initializing SDL2 core..."); SDL2.SDL_Init(BootConfig.SdlModules.SdlInitFlags); if (BootConfig.EnableSdlGpuDebugging) { Console.WriteLine("Enabling SDL_gpu debugging..."); SDL_gpu.GPU_SetDebugLevel(SDL_gpu.GPU_DebugLevelEnum.GPU_DEBUG_LEVEL_MAX); } }
public void SetViewport(Rectangle viewportRectangle) { EnsureNotDisposed(); CurrentViewport = viewportRectangle; SDL_gpu.GPU_SetViewport(TargetHandle, new SDL_gpu.GPU_Rect { x = viewportRectangle.X, y = viewportRectangle.Y, w = viewportRectangle.Width, h = viewportRectangle.Height }); }
public void SetUniform(string name, int value) { EnsureNotDisposed(); var loc = SDL_gpu.GPU_GetUniformLocation(ProgramHandle, name); if (loc == -1) { _log.Warning($"Int uniform '{name}' does not exist."); return; } SDL_gpu.GPU_SetUniformi(loc, value); }
public void SetUniform(string name, Color value) { EnsureNotDisposed(); var loc = SDL_gpu.GPU_GetUniformLocation(ProgramHandle, name); if (loc == -1) { Log.Warning($"Vec4 uniform '{name}' does not exist."); return; } SDL_gpu.GPU_SetUniformfv(loc, 4, 1, value.AsOrderedArray()); }
public void SetUniform(string name, Vector3 value) { EnsureNotDisposed(); var loc = SDL_gpu.GPU_GetUniformLocation(ProgramHandle, name); if (loc == -1) { _log.Warning($"Vec3 uniform '{name}' does not exist."); return; } SDL_gpu.GPU_SetUniformfv(loc, 3, 1, new[] { value.X, value.Y, value.Z }); }
public void SetAttribute(string name, Color value) { EnsureNotDisposed(); var loc = SDL_gpu.GPU_GetAttributeLocation(ProgramHandle, name); if (loc == -1) { _log.Warning($"Vec4 attribute '{name}' does not exist."); return; } SDL_gpu.GPU_SetAttributefv(loc, 4, value.AsNormalizedFloatArray()); }
public void SetAttribute(string name, Vector4 value) { EnsureNotDisposed(); var loc = SDL_gpu.GPU_GetAttributeLocation(ProgramHandle, name); if (loc == -1) { _log.Warning($"Vec4 attribute '{name}' does not exist."); return; } SDL_gpu.GPU_SetAttributefv(loc, 4, new[] { value.X, value.Y, value.Z, value.W }); }
public void SetAttribute(string name, uint value) { EnsureNotDisposed(); var loc = SDL_gpu.GPU_GetAttributeLocation(ProgramHandle, name); if (loc == -1) { _log.Warning($"Uint attribute '{name}' does not exist."); return; } SDL_gpu.GPU_SetAttributeui(loc, value); }
protected virtual void TryLinkShaders() { ProgramHandle = SDL_gpu.GPU_CreateShaderProgram(); SDL_gpu.GPU_AttachShader(ProgramHandle, VertexShaderObjectHandle); SDL_gpu.GPU_AttachShader(ProgramHandle, PixelShaderObjectHandle); SDL_gpu.GPU_LinkShaderProgram(ProgramHandle); var obj = SDL_gpu.GPU_PopErrorCode(); if (obj.error == SDL_gpu.GPU_ErrorEnum.GPU_ERROR_BACKEND_ERROR) { throw new ShaderException( "Failed to link vertex and pixel shader.\nMake sure your 'in' parameters have correct f*****g types.", string.Empty ); } }
protected override void FreeNativeResources() { EnsureNotDisposed(); if (PixelShaderObjectHandle != 0) { SDL_gpu.GPU_FreeShader(PixelShaderObjectHandle); } if (VertexShaderObjectHandle != 0) { SDL_gpu.GPU_FreeShader(VertexShaderObjectHandle); } if (ProgramHandle != 0) { SDL_gpu.GPU_FreeShaderProgram(ProgramHandle); } }
public void SetUniform(string name, Texture value, int textureUnit) { EnsureNotDisposed(); if (value.Disposed) { throw new ArgumentException("Texture provided was already diposed."); } var loc = SDL_gpu.GPU_GetUniformLocation(ProgramHandle, name); if (loc == -1) { Log.Warning($"Float uniform '{name}' does not exist."); return; } SDL_gpu.GPU_SetShaderImage(value.ImageHandle, loc, textureUnit); }
public RenderTarget(int width, int height) : base(width, height) { if (ImageHandle == IntPtr.Zero) { var msg = $"Failed to create texture handle: {SDL2.SDL_GetError()}"; Log.Error(msg); throw new Exception(msg); } TargetHandle = SDL_gpu.GPU_LoadTarget(ImageHandle); if (TargetHandle == IntPtr.Zero) { var msg = $"Failed to create render target handle: {SDL2.SDL_GetError()}"; Log.Error(msg); throw new Exception(msg); } }
public void SetUniform(string name, Matrix4x4 value) { EnsureNotDisposed(); var loc = SDL_gpu.GPU_GetUniformLocation(ProgramHandle, name); if (loc == -1) { _log.Warning($"Mat4 uniform '{name}' does not exist."); return; } SDL_gpu.GPU_SetUniformMatrixfv(loc, 1, 4, 4, false, new[] { value.M11, value.M12, value.M13, value.M14, value.M21, value.M22, value.M23, value.M24, value.M31, value.M32, value.M33, value.M34, value.M41, value.M42, value.M43, value.M44 }); }
public static void Deactivate() => SDL_gpu.GPU_ActivateShaderProgram(0, IntPtr.Zero);
protected override void FreeNativeResources() { SDL_gpu.GPU_FreeTarget(TargetHandle); base.FreeNativeResources(); }
public RenderTarget(int width, int height) : base(width, height) { TargetHandle = SDL_gpu.GPU_LoadTarget(ImageHandle); }