<commit_before>/*
 * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * OpenGL/GLUT common code for perf programs.
 * <NAME>
 * 15 Sep 2009
 */


#include <stdio.h>
#include "glmain.h"
#include <GL/glut.h>


static int Win;
static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;


/** Return time in seconds */
double
PerfGetTime(void)
{
   return glutGet(GLUT_ELAPSED_TIME) * 0.001;
}


void
PerfSwapBuffers(void)
{
   glutSwapBuffers();
}


/** make simple checkerboard texture object */
GLuint
PerfCheckerTexture(GLsizei width, GLsizei height)
{
   const GLenum filter = GL_NEAREST;
   GLubyte *img = (GLubyte *) malloc(width * height * 4);
   GLint i, j, k;
   GLuint obj;

   k = 0;
   for (i = 0; i < height; i++) {
      for (j = 0; j < width; j++) {
         GLubyte color;
         if (((i / 8) ^ (j / 8)) & 1) {
            color = 0xff;
         }
         else {
            color = 0x0;
         }
         img[k++] = color;
         img[k++] = color;
         img[k++] = color;
         img[k++] = color;
      }
   }

   glGenTextures(1, &obj);
   glBindTexture(GL_TEXTURE_2D, obj);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
                GL_RGBA, GL_UNSIGNED_BYTE, img);
   free(img);

   return obj;
}


static GLuint
CompileShader(GLenum type, const char *shader)
{
   GLuint sh;
   GLint stat;

   sh = glCreateShader(type);
   glShaderSource(sh, 1, (const GLchar **) &shader, NULL);

   glCompileShader(sh);
      
   glGetShaderiv(sh, GL_COMPILE_STATUS, &stat);
   if (!stat) {
      GLchar log[1000];
      GLsizei len;
      glGetShaderInfoLog(sh, 1000, &len, log);
      fprintf(stderr, "Error: problem compiling shader: %s\n", log);
      exit(1);
   }

   return sh;
}


/** Make shader program from given vert/frag shader text */
GLuint
PerfShaderProgram(const char *vertShader, const char *fragShader)
{
   GLuint prog;
   GLint stat;

   {
      const char *version = (const char *) glGetString(GL_VERSION);
      if (version[0] != '2' || version[1] != '.') {
         fprintf(stderr, "Error: GL version 2.x required\n");
         exit(1);
      }
   }

   prog = glCreateProgram();

   if (vertShader) {
      GLuint vs = CompileShader(GL_VERTEX_SHADER, vertShader);
      glAttachShader(prog, vs);
   }
   if (fragShader) {
      GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragShader);<commit_msg>progs/perf: accept GL3.x also<commit_after>/*
 * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * OpenGL/GLUT common code for perf programs.
 * <NAME>
 * 15 Sep 2009
 */


#include <stdio.h>
#include "glmain.h"
#include <GL/glut.h>


static int Win;
static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;


/** Return time in seconds */
double
PerfGetTime(void)
{
   return glutGet(GLUT_ELAPSED_TIME) * 0.001;
}


void
PerfSwapBuffers(void)
{
   glutSwapBuffers();
}


/** make simple checkerboard texture object */
GLuint
PerfCheckerTexture(GLsizei width, GLsizei height)
{
   const GLenum filter = GL_NEAREST;
   GLubyte *img = (GLubyte *) malloc(width * height * 4);
   GLint i, j, k;
   GLuint obj;

   k = 0;
   for (i = 0; i < height; i++) {
      for (j = 0; j < width; j++) {
         GLubyte color;
         if (((i / 8) ^ (j / 8)) & 1) {
            color = 0xff;
         }
         else {
            color = 0x0;
         }
         img[k++] = color;
         img[k++] = color;
         img[k++] = color;
         img[k++] = color;
      }
   }

   glGenTextures(1, &obj);
   glBindTexture(GL_TEXTURE_2D, obj);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
                GL_RGBA, GL_UNSIGNED_BYTE, img);
   free(img);

   return obj;
}


static GLuint
CompileShader(GLenum type, const char *shader)
{
   GLuint sh;
   GLint stat;

   sh = glCreateShader(type);
   glShaderSource(sh, 1, (const GLchar **) &shader, NULL);

   glCompileShader(sh);
      
   glGetShaderiv(sh, GL_COMPILE_STATUS, &stat);
   if (!stat) {
      GLchar log[1000];
      GLsizei len;
      glGetShaderInfoLog(sh, 1000, &len, log);
      fprintf(stderr, "Error: problem compiling shader: %s\n", log);
      exit(1);
   }

   return sh;
}


/** Make shader program from given vert/frag shader text */
GLuint
PerfShaderProgram(const char *vertShader, const char *fragShader)
{
   GLuint prog;
   GLint stat;

   {
      const char *version = (const char *) glGetString(GL_VERSION);
      if ((version[0] != '2' && 
           version[0] != '3') || version[1] != '.') {
         fprintf(stderr, "Error: GL version 2.x or better required\n");
         exit(1);
      }
   }

   prog = glCreateProgram();

   if (vertShader) {
      GLuint vs = CompileShader(GL_VERTEX_SHADER, vertShader);
      glAttachShader(prog, vs);
   }
   if (fragShader) {
      GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragShader);
{'fraction_non_alphanumeric': 0.11002102312543798, 'fraction_numerical': 0.014435879467414156, 'mean_word_length': 3.013498312710911, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '7277717', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2291, 'n_words': 774}