<commit_before>/*
 * Copyright (c), <NAME>.
 *
 * MIT License (MIT), http://opensource.org/licenses/MIT
 * Full license can be found in the LICENSE file
 */

#include "../include/gk.h"
#include "../include/gk-material.h"
#include <string.h>

#include "gk_uniform.h"

void
gkUniformMaterial(struct GkScene     * __restrict scene,
                  struct GkModelInst * __restrict modelInst) {
  GkMaterial    *material;
  GkFinalMatrix *fmat;
  GkProgInfo    *pinfo;
  char           buf[256];
  GLint          loc;
  GLuint         prog;

  material = modelInst->material;
  if (!material)
    material = modelInst->model->material;
  if (!material)
    return;

  pinfo = modelInst->model->pinfo;
  fmat  = modelInst->matrix->fmat;
  prog  = pinfo->prog;

  /* TODO: read uniform structure/names from options */
  strcpy(buf, "material.");

  if (material->technique->type == GK_MATERIAL_PHONG) {
    GkPhong *phong;
    phong  = (GkPhong *)material->technique;

    loc = gkGetUniformLoc(prog, buf, "ambient.color");
    glUniform4fv(loc, 1, phong->ambient.color.vec);

    loc = gkGetUniformLoc(prog, buf, "diffuse.color");
    glUniform4fv(loc, 1, phong->diffuse.color.vec);

    loc = gkGetUniformLoc(prog, buf, "specular.color");
    glUniform4fv(loc, 1, phong->specular.color.vec);

    loc = gkGetUniformLoc(prog, buf, "emission.color");
    glUniform4fv(loc, 1, phong->emission.color.vec);

    loc = gkGetUniformLoc(prog, buf, "reflective.color");
    glUniform4fv(loc, 1, phong->reflective.color.vec);

    loc = gkGetUniformLoc(prog, buf, "transparent.color");
    glUniform4fv(loc, 1, phong->transparent.color.vec);

    loc = gkGetUniformLoc(prog, buf, "shininess");
    glUniform1f(loc, phong->shininess);

    loc = gkGetUniformLoc(prog, buf, "reflectivity");
    glUniform1f(loc, phong->reflectivity);

    loc = gkGetUniformLoc(prog, buf, "transparency");
    glUniform1f(loc, phong->transparency);

    loc = gkGetUniformLoc(prog, buf, "indexOfRefraction");
    glUniform1f(loc, phong->indexOfRefraction);
  }
}<commit_msg>uniform effects as subroutines<commit_after>/*
 * Copyright (c), <NAME>.
 *
 * MIT License (MIT), http://opensource.org/licenses/MIT
 * Full license can be found in the LICENSE file
 */

#include "../include/gk.h"
#include "../include/gk-material.h"
#include <string.h>

#include "gk_uniform.h"

void
gkUniformMaterial(struct GkScene     * __restrict scene,
                  struct GkModelInst * __restrict modelInst) {
  GkMaterial    *material;
  GkTechnique   *technique;
  GkFinalMatrix *fmat;
  GkProgInfo    *pinfo;
  char           buf[256];
  GLint          loc;
  GLuint         locui;
  GLuint         prog;

  material = modelInst->material;
  if (!material)
    material = modelInst->model->material;
  if (!material)
    return;

  pinfo = modelInst->model->pinfo;
  fmat  = modelInst->matrix->fmat;
  prog  = pinfo->prog;

  /* TODO: read uniform structure/names from options */
  strcpy(buf, "material.");

  technique = material->technique;
  if (technique->type == GK_MATERIAL_PHONG) {
    GkPhong *phong;
    phong  = (GkPhong *)material->technique;

    loc = gkGetUniformLoc(prog, buf, "ambient.color");
    glUniform4fv(loc, 1, phong->ambient.color.vec);

    loc = gkGetUniformLoc(prog, buf, "diffuse.color");
    glUniform4fv(loc, 1, phong->diffuse.color.vec);

    loc = gkGetUniformLoc(prog, buf, "specular.color");
    glUniform4fv(loc, 1, phong->specular.color.vec);

    loc = gkGetUniformLoc(prog, buf, "emission.color");
    glUniform4fv(loc, 1, phong->emission.color.vec);

    loc = gkGetUniformLoc(prog, buf, "reflective.color");
    glUniform4fv(loc, 1, phong->reflective.color.vec);

    loc = gkGetUniformLoc(prog, buf, "transparent.color");
    glUniform4fv(loc, 1, phong->transparent.color.vec);

    loc = gkGetUniformLoc(prog, buf, "shininess");
    glUniform1f(loc, phong->shininess);

    loc = gkGetUniformLoc(prog, buf, "reflectivity");
    glUniform1f(loc, phong->reflectivity);

    loc = gkGetUniformLoc(prog, buf, "transparency");
    glUniform1f(loc, phong->transparency);

    loc = gkGetUniformLoc(prog, buf, "indexOfRefraction");
    glUniform1f(loc, phong->indexOfRefraction);
  }

  locui = glGetSubroutineIndex(prog,
                               GL_FRAGMENT_SHADER,
                               technique->subroutine);

  glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &locui);
}
{'fraction_non_alphanumeric': 0.14037890892490298, 'fraction_numerical': 0.008902077151335312, 'mean_word_length': 3.4173387096774195, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 50, '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': '2530475', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1518, 'n_words': 302}