<commit_before>/**
 * Measure fill rates for basic shading/texturing modes.
 *
 * <NAME>
 * 1 April 2008
 */


#define GL_GLEXT_PROTOTYPES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include "readtex.h"

#define TEXTURE_1_FILE "../images/tile.rgb"
#define TEXTURE_2_FILE "../images/reflect.rgb"

static int Win;
static int Width = 1010, Height = 1010;
static GLuint Textures[2];


/**
 * Draw quad 10 pixels shorter, narrower than window size.
 */
static void
DrawQuad(void)
{
   glBegin(GL_POLYGON);

   glColor3f(1.0, 0.5, 0.5);
   glMultiTexCoord2f(GL_TEXTURE0, 0, 0);
   glMultiTexCoord2f(GL_TEXTURE1, 0, 0);
   glVertex2f(5, 5);

   glColor3f(0.5, 1.0, 0.5);
   glMultiTexCoord2f(GL_TEXTURE0, 1, 0);
   glMultiTexCoord2f(GL_TEXTURE1, 1, 0);
   glVertex2f(Width - 5, 5);

   glColor3f(0.5, 0.5, 1.0);
   glMultiTexCoord2f(GL_TEXTURE0, 1, 1);
   glMultiTexCoord2f(GL_TEXTURE1, 1, 1);
   glVertex2f(Width - 5, Height - 5);

   glColor3f(1.0, 0.5, 1.0);
   glMultiTexCoord2f(GL_TEXTURE0, 0, 1);
   glMultiTexCoord2f(GL_TEXTURE1, 0, 1);
   glVertex2f(5, Height - 5);

   glEnd();
}


/**
 * Compute rate for drawing large quad with given shading/texture state.
 */
static void
RunTest(GLenum shading, GLuint numTextures, GLenum texFilter)
{
   const GLdouble minPeriod = 2.0;
   GLdouble t0, t1;
   GLdouble texels, rate;
   GLint i, iters;

   glActiveTexture(GL_TEXTURE0);
   if (numTextures > 0) {
      glBindTexture(GL_TEXTURE_2D, Textures[0]);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texFilter);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texFilter);
      glEnable(GL_TEXTURE_2D);
   }
   else {
      glDisable(GL_TEXTURE_2D);
   }

   glActiveTexture(GL_TEXTURE1);
   if (numTextures > 1) {
      glBindTexture(GL_TEXTURE_2D, Textures[1]);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texFilter);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texFilter);
      glEnable(GL_TEXTURE_2D);
   }
   else {
      glDisable(GL_TEXTURE_2D);
   }

   glShadeModel(shading);


   glFinish();

   iters = 1;
   do {
      iters *= 4;
      t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
      for (i = 0; i < iters; i++) {
         DrawQuad();
      }
      glFinish();
      t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
   } while (t1 - t0 < minPeriod);

   glutSwapBuffers();

   texels = iters * (Width - 10) * (Height - 10);
   rate = texels / (t1 - t0);
   rate /= 1000000.0;  /* megatexels/second */

   printf("%s ", shading == GL_FLAT ? "GL_FLAT" : "GL_SMOOTH");
   printf("Textures=%u ", numTextures);
   printf("Filter=%s: ", texFilter == GL_LINEAR ? "GL_LINEAR" : "GL_NEAREST");
   printf("%g MPixels/sec\n", rate);
}


static void
Draw(void)
{
   glClear(GL_COLOR_BUFFER_BIT);

   RunTest(GL_FLAT, 0, GL_NEAREST);
   RunTest(GL_SMOOTH, 0, GL_NEAREST);<commit_msg>mesa: added a cast to avoid int overflow, plus rename texels->pixels<commit_after>/**
 * Measure fill rates for basic shading/texturing modes.
 *
 * <NAME>
 * 1 April 2008
 */


#define GL_GLEXT_PROTOTYPES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include "readtex.h"

#define TEXTURE_1_FILE "../images/tile.rgb"
#define TEXTURE_2_FILE "../images/reflect.rgb"

static int Win;
static int Width = 1010, Height = 1010;
static GLuint Textures[2];


/**
 * Draw quad 10 pixels shorter, narrower than window size.
 */
static void
DrawQuad(void)
{
   glBegin(GL_POLYGON);

   glColor3f(1.0, 0.5, 0.5);
   glMultiTexCoord2f(GL_TEXTURE0, 0, 0);
   glMultiTexCoord2f(GL_TEXTURE1, 0, 0);
   glVertex2f(5, 5);

   glColor3f(0.5, 1.0, 0.5);
   glMultiTexCoord2f(GL_TEXTURE0, 1, 0);
   glMultiTexCoord2f(GL_TEXTURE1, 1, 0);
   glVertex2f(Width - 5, 5);

   glColor3f(0.5, 0.5, 1.0);
   glMultiTexCoord2f(GL_TEXTURE0, 1, 1);
   glMultiTexCoord2f(GL_TEXTURE1, 1, 1);
   glVertex2f(Width - 5, Height - 5);

   glColor3f(1.0, 0.5, 1.0);
   glMultiTexCoord2f(GL_TEXTURE0, 0, 1);
   glMultiTexCoord2f(GL_TEXTURE1, 0, 1);
   glVertex2f(5, Height - 5);

   glEnd();
}


/**
 * Compute rate for drawing large quad with given shading/texture state.
 */
static void
RunTest(GLenum shading, GLuint numTextures, GLenum texFilter)
{
   const GLdouble minPeriod = 2.0;
   GLdouble t0, t1;
   GLdouble pixels, rate;
   GLint i, iters;

   glActiveTexture(GL_TEXTURE0);
   if (numTextures > 0) {
      glBindTexture(GL_TEXTURE_2D, Textures[0]);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texFilter);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texFilter);
      glEnable(GL_TEXTURE_2D);
   }
   else {
      glDisable(GL_TEXTURE_2D);
   }

   glActiveTexture(GL_TEXTURE1);
   if (numTextures > 1) {
      glBindTexture(GL_TEXTURE_2D, Textures[1]);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texFilter);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texFilter);
      glEnable(GL_TEXTURE_2D);
   }
   else {
      glDisable(GL_TEXTURE_2D);
   }

   glShadeModel(shading);


   glFinish();

   iters = 1;
   do {
      iters *= 4;
      t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
      for (i = 0; i < iters; i++) {
         DrawQuad();
      }
      glFinish();
      t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001;
   } while (t1 - t0 < minPeriod);

   glutSwapBuffers();

   pixels = (double) iters * (Width - 10) * (Height - 10);
   rate = pixels / (t1 - t0);
   rate /= 1000000.0;  /* megapixels/second */

   printf("%s ", shading == GL_FLAT ? "GL_FLAT" : "GL_SMOOTH");
   printf("Textures=%u ", numTextures);
   printf("Filter=%s: ", texFilter == GL_LINEAR ? "GL_LINEAR" : "GL_NEAREST");
   printf("%g MPixels/sec\n", rate);
}


static void
Draw(void)
{
   glClear(GL_COLOR_BUFFER_BIT);

   RunTest(GL_FLAT, 0, GL_NEAREST);
   RunTest(GL_SMOOTH, 0, GL_NEAREST);
{'fraction_non_alphanumeric': 0.13846685082872928, 'fraction_numerical': 0.048687845303867404, 'mean_word_length': 3.501165501165501, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, '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': '2605660', 'n_tokens_mistral': 2554, 'n_tokens_neox': 2296, 'n_words': 468}