<commit_before>// This is adapted from https://github.com/go-gl-legacy/glh/blob/master/shader.go

package loops

import (
	"log"
	"strings"

	gl "github.com/go-gl/gl/v4.1-core/gl"
)

type ShaderSource struct {
	Type   uint32
	Source string
}

type Program struct {
	Program uint32
}

func NewProgram(shaders ...ShaderSource) Program {
	program := gl.CreateProgram()

	shaderIds := make([]uint32, 0)

	for _, source := range shaders {
		shader := gl.CreateShader(source.Type)
		csource := gl.Str(source.Source + "\x00")
		gl.ShaderSource(shader, 1, &csource, nil)
		gl.CompileShader(shader)

		var status int32
		gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status)
		if status == gl.FALSE {
			var errorMessageLength int32
			gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &errorMessageLength)
			errorMessage := strings.Repeat("\x00", int(errorMessageLength+1))
			gl.GetShaderInfoLog(shader, errorMessageLength, nil, gl.Str(errorMessage))

			log.Fatal("Failed to compile shader", errorMessage)
		}

		gl.AttachShader(program, shader)
		shaderIds = append(shaderIds, shader)
	}

	gl.LinkProgram(program)

	var status int32
	gl.GetProgramiv(program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		log.Fatal("Failed to link program")
	}

	for _, shader := range shaderIds {
		gl.DeleteShader(shader)
	}

	return Program{program}
}

func (self *Program) GetUniformLocation(name string) int32 {
	return gl.GetUniformLocation(self.Program, gl.Str(name+"\x00"))
}

func (self *Program) GetAttribLocation(name string) int32 {
	return gl.GetAttribLocation(self.Program, gl.Str(name+"\x00"))
}

func (self *Program) Use() {<commit_msg>make get shader log generic<commit_after>// This is adapted from https://github.com/go-gl-legacy/glh/blob/master/shader.go

package loops

import (
	"log"
	"strings"

	gl "github.com/go-gl/gl/v4.1-core/gl"
)

type ShaderSource struct {
	Type   uint32
	Source string
}

type Program struct {
	Program uint32
}

type glGetParam func(uint32, uint32, *int32)
type glGetInfoLog func(uint32, int32, *int32, *uint8)

func checkErrorLog(msg string, object uint32, statusEnum uint32, getParam glGetParam, getLog glGetInfoLog) {
	var status int32
	getParam(object, statusEnum, &status)
	if status == gl.FALSE {
		var errorMessageLength int32
		getParam(object, gl.INFO_LOG_LENGTH, &errorMessageLength)
		errorMessage := strings.Repeat("\x00", int(errorMessageLength+1))
		getLog(object, errorMessageLength, nil, gl.Str(errorMessage))
		log.Fatal(msg, errorMessage)
	}
}

func NewProgram(shaders ...ShaderSource) Program {
	program := gl.CreateProgram()

	shaderIds := make([]uint32, 0)

	for _, source := range shaders {
		shader := gl.CreateShader(source.Type)
		csource := gl.Str(source.Source + "\x00")
		gl.ShaderSource(shader, 1, &csource, nil)
		gl.CompileShader(shader)

		checkErrorLog("Failed to compile shader:",
			shader, gl.COMPILE_STATUS, gl.GetShaderiv, gl.GetShaderInfoLog)

		gl.AttachShader(program, shader)
		shaderIds = append(shaderIds, shader)
	}

	gl.LinkProgram(program)

	var status int32
	gl.GetProgramiv(program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		log.Fatal("Failed to link program")
	}

	for _, shader := range shaderIds {
		gl.DeleteShader(shader)
	}

	return Program{program}
}

func (self *Program) GetUniformLocation(name string) int32 {
	return gl.GetUniformLocation(self.Program, gl.Str(name+"\x00"))
}

func (self *Program) GetAttribLocation(name string) int32 {
	return gl.GetAttribLocation(self.Program, gl.Str(name+"\x00"))
}

func (self *Program) Use() {
{'fraction_non_alphanumeric': 0.12928834703714204, 'fraction_numerical': 0.021264530762687837, 'mean_word_length': 4.745928338762215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5747619', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1229, 'n_words': 277}