<commit_before>﻿using System;
using OpenTK.Graphics.OpenGL;
using System.Diagnostics;
using ChamberLib.Content;

namespace ChamberLib.OpenTK
{
    public class ShaderStage : IShaderStage
    {
        public ShaderStage(ShaderContent content)
            : this(content.Source, content.Type, content.Name)
        {
        }
        public ShaderStage(string source, ShaderType shaderType, string name)
        {
            Source = source;
            ShaderType = shaderType;
            Name = name;
        }

        public string Name { get; protected set; }
        public int ShaderID { get; protected set; }
        public string Source { get; protected set; }
        public ShaderType ShaderType { get; protected set; }

        public void MakeReady()
        {
            if (ShaderID != 0) return;

            GLHelper.CheckError();
            ShaderID = GL.CreateShader(ShaderType.ToOpenTK());
            GLHelper.CheckError();
            GL.ShaderSource(ShaderID, Source);
            GLHelper.CheckError();
            GL.CompileShader(ShaderID);
            GLHelper.CheckError();

            int result;
            GL.GetShader(ShaderID, ShaderParameter.CompileStatus, out result);
            Debug.WriteLine("{1} compile status: {0}", result, ShaderType);
            GLHelper.CheckError();
            Debug.WriteLine("{0} info:", ShaderType);
            Debug.WriteLine(GL.GetShaderInfoLog(ShaderID));
            GLHelper.CheckError();
        }
    }
}
<commit_msg>Use a flag to indicate if the shader stage has been successfully compiled.<commit_after>﻿using System;
using OpenTK.Graphics.OpenGL;
using System.Diagnostics;
using ChamberLib.Content;
using _OpenTK = global::OpenTK;

namespace ChamberLib.OpenTK
{
    public class ShaderStage : IShaderStage
    {
        public ShaderStage(ShaderContent content)
            : this(content.Source, content.Type, content.Name)
        {
        }
        public ShaderStage(string source, ShaderType shaderType, string name)
        {
            Source = source;
            ShaderType = shaderType;
            Name = name;
        }

        public string Name { get; protected set; }
        public int ShaderID { get; protected set; }
        public string Source { get; protected set; }
        public ShaderType ShaderType { get; protected set; }

        public bool IsCompiled { get; protected set; }

        public void MakeReady()
        {
            GLHelper.CheckError();
            if (ShaderID == 0)
            {
                ShaderID = GL.CreateShader(ShaderType.ToOpenTK());
                GLHelper.CheckError();
                IsCompiled = false;
            }

            if (!IsCompiled)
            {
                GL.ShaderSource(ShaderID, Source);
                GLHelper.CheckError();
                GL.CompileShader(ShaderID);
                GLHelper.CheckError();

                int result;
                GL.GetShader(ShaderID, ShaderParameter.CompileStatus, out result);
                Debug.WriteLine("{1} compile status: {0}", result, ShaderType);
                GLHelper.CheckError();
                Debug.WriteLine("{0} info:", ShaderType);
                Debug.WriteLine(GL.GetShaderInfoLog(ShaderID));
                GLHelper.CheckError();

                IsCompiled = (result == 1);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09377791009228938, 'fraction_numerical': 0.0026793688597796963, 'mean_word_length': 1.8693424423569598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5373206', 'n_tokens_mistral': 896, 'n_tokens_neox': 848, 'n_words': 209}