ShaderHelper.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using OpenTK.Graphics.OpenGL;
  2. using Ryujinx.Common.Logging;
  3. namespace Ryujinx.Graphics.OpenGL.Effects
  4. {
  5. internal static class ShaderHelper
  6. {
  7. public static int CompileProgram(string shaderCode, ShaderType shaderType)
  8. {
  9. return CompileProgram([shaderCode], shaderType);
  10. }
  11. public static int CompileProgram(string[] shaders, ShaderType shaderType)
  12. {
  13. int shader = GL.CreateShader(shaderType);
  14. GL.ShaderSource(shader, shaders.Length, shaders, (int[])null);
  15. GL.CompileShader(shader);
  16. GL.GetShader(shader, ShaderParameter.CompileStatus, out int isCompiled);
  17. if (isCompiled == 0)
  18. {
  19. string log = GL.GetShaderInfoLog(shader);
  20. Logger.Error?.Print(LogClass.Gpu, $"Failed to compile effect shader:\n\n{log}\n");
  21. GL.DeleteShader(shader);
  22. return 0;
  23. }
  24. int program = GL.CreateProgram();
  25. GL.AttachShader(program, shader);
  26. GL.LinkProgram(program);
  27. GL.DetachShader(program, shader);
  28. GL.DeleteShader(shader);
  29. return program;
  30. }
  31. }
  32. }