<commit_before>#include "graphics/gl.h"
#include <string>
#include <iostream>
#include <cstddef>

const std::string defaultVertexShader = "vec4 position(mat4 transform_proj, vec4 vertpos) {\n"
                                        "  return transform_proj * vertpos;\n"
                                        "}\n";
const std::string defaultFragShader = "vec4 effect(mediump vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) {\n"
                                      "  return Texel(tex, texcoord) * vcolor;\n"
                                      "}\n";

namespace Demoloop {
  GL::GL() {
    initMatrices();
  }

  GL::~GL() {}

  bool GL::initContext() {
    glEnable(GL_MULTISAMPLE); // TODO: is this doing anything?
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    Shader::defaultShader = new Shader({defaultVertexShader, defaultFragShader});
    Shader::defaultShader->attach();

    glGenBuffers(1, &mVBO);
    glGenBuffers(1, &mIBO);

    createDefaultTexture();

    glBindTexture(GL_TEXTURE_2D, mDefaultTexture);
    glVertexAttrib4f(Shader::defaultShader->getAttribLocation("ConstantColor"), 1, 1, 1, 1);
    glVertexAttrib4f(Shader::defaultShader->getAttribLocation("VertexColor"), 1, 1, 1, 1);

    return true;
  }

  void GL::initMatrices() {
    matrices.transform.clear();
    matrices.projection.clear();

    matrices.transform.push_back(Matrix4());
    matrices.projection.push_back(Matrix4());
  }

  void GL::setViewport(const GL::Viewport &v) {
    glViewport(v.x, v.y, v.w, v.h);
    GLfloat dimensions[4] = {(GLfloat)v.w, (GLfloat)v.h, 0, 0};
    Shader::defaultShader->sendFloat("demoloop_ScreenSize", 4, dimensions, 1);
    matrices.projection.back() = Matrix4::ortho(0, v.w, v.h, 0, 0.1, 100);
    matrices.transform.back() = Matrix4::lookAt({0, 0, 100}, {0, 0, 0}, {0, 1, 0});
  }

  void GL::pushTransform()
  {
    matrices.transform.push_back(matrices.transform.back());
  }

  void GL::popTransform()
  {
    matrices.transform.pop_back();
  }

  Matrix4 &GL::getTransform()
  {
    return matrices.transform.back();
  }

  void GL::pushProjection()
  {
    matrices.projection.push_back(matrices.projection.back());
  }

  void GL::popProjection()
  {
    matrices.projection.pop_back();
  }

  Matrix4 &GL::getProjection()
  {
    return matrices.projection.back();
  }

  void GL::prepareDraw() {
    Shader::defaultShader->checkSetBuiltinUniforms();
    Matrix4 View = matrices.transform.back();
    Matrix4 Projection = matrices.projection.back();
    Matrix4 mvp = Projection * View; // * Model
    Shader::defaultShader->sendMatrix("TransformProjectionMatrix", 4, mvp.getElements(), 1);
  }

  void GL::lines(const Vertex *coords, size_t count) {
    prepareDraw();

    glBindBuffer(GL_ARRAY_BUFFER, mVBO);
    glBufferData(GL_ARRAY_BUFFER, count * sizeof(Vertex), &coords[0].x, GL_DYNAMIC_DRAW);<commit_msg>remove excess uniform passing<commit_after>#include "graphics/gl.h"
#include <string>
#include <iostream>
#include <cstddef>

const std::string defaultVertexShader = "vec4 position(mat4 transform_proj, vec4 vertpos) {\n"
                                        "  return transform_proj * vertpos;\n"
                                        "}\n";
const std::string defaultFragShader = "vec4 effect(mediump vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) {\n"
                                      "  return Texel(tex, texcoord) * vcolor;\n"
                                      "}\n";

namespace Demoloop {
  GL::GL() {
    initMatrices();
  }

  GL::~GL() {}

  bool GL::initContext() {
    glEnable(GL_MULTISAMPLE); // TODO: is this doing anything?
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    Shader::defaultShader = new Shader({defaultVertexShader, defaultFragShader});
    Shader::defaultShader->attach();

    glGenBuffers(1, &mVBO);
    glGenBuffers(1, &mIBO);

    createDefaultTexture();

    glBindTexture(GL_TEXTURE_2D, mDefaultTexture);
    glVertexAttrib4f(Shader::defaultShader->getAttribLocation("ConstantColor"), 1, 1, 1, 1);
    glVertexAttrib4f(Shader::defaultShader->getAttribLocation("VertexColor"), 1, 1, 1, 1);

    return true;
  }

  void GL::initMatrices() {
    matrices.transform.clear();
    matrices.projection.clear();

    matrices.transform.push_back(Matrix4());
    matrices.projection.push_back(Matrix4());
  }

  void GL::setViewport(const GL::Viewport &v) {
    glViewport(v.x, v.y, v.w, v.h);
    GLfloat dimensions[4] = {(GLfloat)v.w, (GLfloat)v.h, 0, 0};
    Shader::defaultShader->sendFloat("demoloop_ScreenSize", 4, dimensions, 1);
    matrices.projection.back() = Matrix4::ortho(0, v.w, v.h, 0, 0.1, 100);
    matrices.transform.back() = Matrix4::lookAt({0, 0, 100}, {0, 0, 0}, {0, 1, 0});
  }

  void GL::pushTransform()
  {
    matrices.transform.push_back(matrices.transform.back());
  }

  void GL::popTransform()
  {
    matrices.transform.pop_back();
  }

  Matrix4 &GL::getTransform()
  {
    return matrices.transform.back();
  }

  void GL::pushProjection()
  {
    matrices.projection.push_back(matrices.projection.back());
  }

  void GL::popProjection()
  {
    matrices.projection.pop_back();
  }

  Matrix4 &GL::getProjection()
  {
    return matrices.projection.back();
  }

  void GL::prepareDraw() {
    Shader::defaultShader->checkSetBuiltinUniforms();
  }

  void GL::lines(const Vertex *coords, size_t count) {
    prepareDraw();

    glBindBuffer(GL_ARRAY_BUFFER, mVBO);
    glBufferData(GL_ARRAY_BUFFER, count * sizeof(Vertex), &coords[0].x, GL_DYNAMIC_DRAW);
{'fraction_non_alphanumeric': 0.1478674656327106, 'fraction_numerical': 0.018505463517800493, 'mean_word_length': 3.3687451886066206, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '231797', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1897, 'n_words': 337}