<commit_before>package dax

import (
	"fmt"

	"github.com/go-gl/gl/v3.3-core/gl"
)

type renderer struct {
	program uint32
}

func newRenderer() *renderer {
	r := new(renderer)

	program, err := newProgram(vertexShader, fragmentShader)
	if err != nil {
		panic(err)
	}
	r.program = program

	return r
}

func compileShader(source string, shaderType uint32) (uint32, error) {
	shader := gl.CreateShader(shaderType)

	csources, free := gl.Strs(source)
	gl.ShaderSource(shader, 1, csources, nil)
	free()
	gl.CompileShader(shader)

	var status int32
	gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logLength)

		//log := strings.Repeat('\x00', int(logLength+1))
		//gl.GetShaderInfoLog(shader, logLength, nil, gl.Str(log))

		log := "TODO"
		return 0, fmt.Errorf("failed to compile %v: %v", source, log)
	}

	return shader, nil
}

func newProgram(vertexShaderSource, fragmentShaderSource string) (uint32, error) {
	vertexShader, err := compileShader(vertexShaderSource, gl.VERTEX_SHADER)
	if err != nil {
		return 0, err
	}

	fragmentShader, err := compileShader(fragmentShaderSource, gl.FRAGMENT_SHADER)
	if err != nil {
		return 0, err
	}

	program := gl.CreateProgram()

	gl.AttachShader(program, vertexShader)
	gl.AttachShader(program, fragmentShader)
	gl.LinkProgram(program)

	var status int32
	gl.GetProgramiv(program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetProgramiv(program, gl.INFO_LOG_LENGTH, &logLength)

		//log := strings.Repeat("\x00", int(logLength+1))
		log := "TODO"
		gl.GetProgramInfoLog(program, logLength, nil, gl.Str(log))

		return 0, fmt.Errorf("failed to link program: %v", log)
	}

	gl.DeleteShader(vertexShader)
	gl.DeleteShader(fragmentShader)

	return program, nil
}

/*
var vertexShader = `
#version 330
uniform mat4 projection;
uniform mat4 camera;
uniform mat4 model;
in vec3 vert;
in vec2 vertTexCoord;
out vec2 fragTexCoord;
void main() {
    fragTexCoord = vertTexCoord;
    gl_Position = projection * camera * model * vec4(vert, 1);
}
`
*/

var vertexShader = `
#version 330 core

in vec3 position;

uniform mat4 mvp;

void main(){
	gl_Position = mvp * vec4(position, 1.0f);
}
` + "\x00"

/*
var fragmentShader = `
#version 330
uniform sampler2D tex;
in vec2 fragTexCoord;
out vec4 outputColor;
void main() {
    outputColor = texture(tex, fragTexCoord);
}
` + "0x00"
*/

var fragmentShader = `
#version 330
out vec4 outputColor;
void main() {
    outputColor = vec4(.8, .8, .8, 1);
}
` + "\x00"
<commit_msg>renderer: The shadres are actually constants<commit_after>package dax

import (
	"fmt"

	"github.com/go-gl/gl/v3.3-core/gl"
)

type renderer struct {
	program uint32
}

func newRenderer() *renderer {
	r := new(renderer)

	program, err := newProgram(vertexShader, fragmentShader)
	if err != nil {
		panic(err)
	}
	r.program = program

	return r
}

func compileShader(source string, shaderType uint32) (uint32, error) {
	shader := gl.CreateShader(shaderType)

	csources, free := gl.Strs(source)
	gl.ShaderSource(shader, 1, csources, nil)
	free()
	gl.CompileShader(shader)

	var status int32
	gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logLength)

		//log := strings.Repeat('\x00', int(logLength+1))
		//gl.GetShaderInfoLog(shader, logLength, nil, gl.Str(log))

		log := "TODO"
		return 0, fmt.Errorf("failed to compile %v: %v", source, log)
	}

	return shader, nil
}

func newProgram(vertexShaderSource, fragmentShaderSource string) (uint32, error) {
	vertexShader, err := compileShader(vertexShaderSource, gl.VERTEX_SHADER)
	if err != nil {
		return 0, err
	}

	fragmentShader, err := compileShader(fragmentShaderSource, gl.FRAGMENT_SHADER)
	if err != nil {
		return 0, err
	}

	program := gl.CreateProgram()

	gl.AttachShader(program, vertexShader)
	gl.AttachShader(program, fragmentShader)
	gl.LinkProgram(program)

	var status int32
	gl.GetProgramiv(program, gl.LINK_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetProgramiv(program, gl.INFO_LOG_LENGTH, &logLength)

		//log := strings.Repeat("\x00", int(logLength+1))
		log := "TODO"
		gl.GetProgramInfoLog(program, logLength, nil, gl.Str(log))

		return 0, fmt.Errorf("failed to link program: %v", log)
	}

	gl.DeleteShader(vertexShader)
	gl.DeleteShader(fragmentShader)

	return program, nil
}

/*
var vertexShader = `
#version 330
uniform mat4 projection;
uniform mat4 camera;
uniform mat4 model;
in vec3 vert;
in vec2 vertTexCoord;
out vec2 fragTexCoord;
void main() {
    fragTexCoord = vertTexCoord;
    gl_Position = projection * camera * model * vec4(vert, 1);
}
`
*/

const vertexShader = `
#version 330 core

in vec3 position;

uniform mat4 mvp;

void main(){
	gl_Position = mvp * vec4(position, 1.0f);
}
` + "\x00"

/*
var fragmentShader = `
#version 330
uniform sampler2D tex;
in vec2 fragTexCoord;
out vec4 outputColor;
void main() {
    outputColor = texture(tex, fragTexCoord);
}
` + "0x00"
*/

const fragmentShader = `
#version 330
out vec4 outputColor;
void main() {
    outputColor = vec4(.8, .8, .8, 1);
}
` + "\x00"

{'fraction_non_alphanumeric': 0.12998266897746968, 'fraction_numerical': 0.026959368380512227, 'mean_word_length': 4.433054393305439, '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': '5952702', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1873, 'n_words': 475}