Esempio n. 1
0
 protected ShaderBase(string source_name, int group_size_x, int group_size_y, int group_size_z)
 {
     if (max_group_invocations == -1)
     {
         max_group_invocations = MyGL.CheckError(() => GL.GetInteger((GetPName)All.MaxComputeWorkGroupInvocations));
         Print("max_group_invocations:", max_group_invocations);
         (int, int, int)res;
         GL.GetInteger((GetIndexedPName)All.MaxComputeWorkGroupSize, 0, out res.Item1);
         GL.GetInteger((GetIndexedPName)All.MaxComputeWorkGroupSize, 1, out res.Item2);
         GL.GetInteger((GetIndexedPName)All.MaxComputeWorkGroupSize, 2, out res.Item3);
         (max_group_size_x, max_group_size_y, max_group_size_z) = res;
         Print("max_group_size:", max_group_size_x, max_group_size_y, max_group_size_z);
         GL.GetInteger((GetIndexedPName)All.MaxComputeWorkGroupCount, 0, out res.Item1);
         GL.GetInteger((GetIndexedPName)All.MaxComputeWorkGroupCount, 1, out res.Item2);
         GL.GetInteger((GetIndexedPName)All.MaxComputeWorkGroupCount, 2, out res.Item3);
         (max_group_count_x, max_group_count_y, max_group_count_z) = res;
         Print("max_group_count:", max_group_count_x, max_group_count_y, max_group_count_z);
     }
     Assert(group_size_x <= max_group_size_x && group_size_y <= max_group_size_y && group_size_z <= max_group_size_z);
     Assert(group_size_x * group_size_y * group_size_z <= max_group_invocations);
     (this.group_size_x, this.group_size_y, this.group_size_z) = (group_size_x, group_size_y, group_size_z);
     if (!program_pool.TryGetValue((source_name, group_size_x, group_size_y, group_size_z), out program))
     {
         string source = IO.ReadResource(source_name);
         // inject code
         var lines = source.Split('\n').ToList();
         lines[0] = "#version 450";
         lines.Insert(1, $"layout(local_size_x = {group_size_x}, local_size_y = {group_size_y}, local_size_z = {group_size_z}) in;");
         source  = string.Join("\n", lines);
         program = new MyGL.Program(
             new MyGL.Shader(ShaderType.ComputeShader, source));
         program_pool.Add((source_name, group_size_x, group_size_y, group_size_z), program);
     }
 }
Esempio n. 2
0
 public GameWindow()
 // set window resolution, title, and default behaviour
     : base(1280, 720, GraphicsMode.Default, "OpenTK Intro",
            GameWindowFlags.Default, DisplayDevice.Default,
            // ask for an OpenGL 3.0 forward compatible context
            3, 0, GraphicsContextFlags.ForwardCompatible)
 {
     Console.WriteLine("gl version: " + GL.GetString(StringName.Version));
     texture_program = new MyGL.Program(
         new MyGL.Shader(ShaderType.VertexShader, IO.ReadResource("SIFT.shaders.example_vertex_shader.glsl")),
         new MyGL.Shader(ShaderType.FragmentShader, IO.ReadResource("SIFT.shaders.example_fragment_shader.glsl")));
     InitFBO();
     CreateVertexArrayObject();
     Canvas = new GPUImage(this.Width, this.Height);
 }