<commit_before>/* -------------------------------- . ---------------------------------------- .
| Filename : SuperFormula.cpp       | DOCGL3.3 sample file                     |
| Author   : <NAME>         |                                          |
| Started  : 25/01/2011 10:09       |                                          |
` --------------------------------- . --------------------------------------- */

# define  _USE_MATH_DEFINES
# include "Tools.h"
# include <Docgl/Docgl.h>
# include <Docgl/DocglWindow.h>

struct SuperFormula3D
  {float a, b, m, n1, n2, n3;};
static const float step = 0.05f;
enum {superFormulaNumVertices = 7938}; // depends from step

#ifdef linux
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
#endif // linux

class Globals: public OpenGLWindowCallback
{
public:
  docgl::GLDirectContext context;
  docgl::GLBufferObject superFormulaVertexBuffer;
  docgl::GLVertexArrayObject superFormulaVertexArray;
  docgl::GLProgramObject flatColorTransformShader;
  GLint vColorLocation;
  GLint mvpMatrixLocation;
#ifdef DOCGL4_1
  GLint getColorFunctionLocation;
  GLuint getUniformColorIndex;
  GLuint getUniformColorInvIndex;
  bool invertColor;
#endif // !DOCGL4_1
  glm::mat4         projectionMatrix;
  Frame			  	    cameraFrame;
  Frame             objectFrame;
  int nStep;
  SuperFormula3D superFormula3d;
  bool invertCoordinate;
  bool cullFace;
  bool depthTest;
  bool wantExit;

  Globals()
    : superFormulaVertexBuffer(context)
    , superFormulaVertexArray(context)
    , flatColorTransformShader(context)
    , vColorLocation(-1)
    , mvpMatrixLocation(-1)
#ifdef DOCGL4_1
    , getColorFunctionLocation(-1)
    , getUniformColorIndex(GL_INVALID_INDEX)
    , getUniformColorInvIndex(GL_INVALID_INDEX)
    , invertColor(false)
#endif // !DOCGL4_1
    , nStep(0)
    , invertCoordinate(false)
    , cullFace(false)
    , depthTest(true)
    , wantExit(false)
    {
      static const SuperFormula3D formula = {1.f, 1.f, 4.f, 12.f, 15.f, 15.f};
      superFormula3d = formula;
    }

  virtual void draw()
  {
    context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    context.getCullFace().setValue(cullFace);
    context.getDepthTest().setValue(depthTest);

    bool succeed;
    glm::mat4 modelViewProjection = projectionMatrix * cameraFrame.getCameraMatrix() * objectFrame.getMatrix();
    succeed = flatColorTransformShader.setUniformMatrix<4, 4>(mvpMatrixLocation, 1, GL_FALSE, &modelViewProjection[0][0]).hasSucceed();
    glUniformMatrix4fv(mvpMatrixLocation, 1, GL_FALSE, &modelViewProjection[0][0]);

    GLenum primitive;
    switch (nStep)
    {
    case 0: primitive = GL_POINTS; break;
    case 1: primitive = GL_LINES; break;
    case 2: primitive = GL_LINE_STRIP; break;
    case 3: primitive = GL_LINE_LOOP; break;
    case 4: primitive = GL_TRIANGLES; break;
    case 7: primitive = GL_QUADS; break;
    case 5: primitive = GL_TRIANGLE_FAN; break;
    case 6: primitive = GL_TRIANGLE_STRIP; break;
    case 8: primitive = GL_QUAD_STRIP; break;
    case 9: primitive = GL_POLYGON; break;
    }

    const GLfloat vGreen[] = {0.0f, 1.0f, 0.0f, 1.0f};
    const GLfloat vBlack[] = {0.0f, 0.0f, 0.0f, 1.0f};
    if (nStep < 4)
    {
      succeed = flatColorTransformShader.setUniformValue(vColorLocation, 4, 1, vBlack).hasSucceed();
      jassert(succeed);

  #ifdef DOCGL4_1
      // last thing to do with flatColorTransformShader
      succeed = context.loadUniformSubroutines(GL_FRAGMENT_SHADER, 1, invertColor ? &getUniformColorInvIndex : &getUniformColorIndex).hasSucceed();
      jassert(succeed);
  #endif // !DOCGL4_1

      succeed = superFormulaVertexArray.draw(primitive, 0, superFormulaNumVertices).hasSucceed();
      jassert(succeed);
    }
    else
    {
      // Draw the batch solid green
      succeed = flatColorTransformShader.setUniformValue(vColorLocation, 4, 1, vGreen).hasSucceed();
      jassert(succeed);

  #ifdef DOCGL4_1
      // last thing to do with flatColorTransformShader
      succeed = context.loadUniformSubroutines(GL_FRAGMENT_SHADER, 1, invertColor ? &getUniformColorInvIndex : &getUniformColorIndex).hasSucceed();
      jassert(succeed);
  #endif // !DOCGL4_1

      succeed = superFormulaVertexArray.draw(primitive, 0, superFormulaNumVertices).hasSucceed();
      jassert(succeed);

      // Draw black outline
      context.getPolygonOffset().setValue(docgl::GLPolygonOffset(-1.0f, -1.0f));      // Shift depth values
      context.getLinePolygonOffset().setValue(true);

      // Draw black wireframe version of geometry
      succeed = flatColorTransformShader.setUniformValue(vColorLocation, 4, 1, vBlack).hasSucceed();
      jassert(succeed);

  #ifdef DOCGL4_1
      // last thing to do with flatColorTransformShader
      succeed = context.loadUniformSubroutines(GL_FRAGMENT_SHADER, 1, invertColor ? &getUniformColorInvIndex : &getUniformColorIndex).hasSucceed();
      jassert(succeed);
  #endif // !DOCGL4_1

      succeed = superFormulaVertexArray.draw(GL_LINE_STRIP, 0, superFormulaNumVertices).hasSucceed();
      jassert(succeed);

      // Put everything back the way we found it
      context.getLinePolygonOffset().setValue(false);
      context.getPolygonOffset().setValue(docgl::GLPolygonOffset(0.0f, 0.0f));
    }
  }



  void constructSuperMesh(const SuperFormula3D& s, bool invertCoordinate)
  {
    static GLfloat computeBuffer[superFormulaNumVertices][3];
    int veccount = 0;
    if (invertCoordinate)
    {
      for (float j = float(-M_PI / 2.f); j < M_PI / 2.f; j += step)
        for (float i = float(-M_PI); i < M_PI; i += step)
        {
           float raux1 = pow(std::abs(1.f / s.a * cos(s.m * i / 4.f)), s.n2) + pow(std::abs(1.f / s.b * sin(s.m * i / 4.f)), s.n3);
           float r1 = pow(std::abs(raux1), (-1.f / s.n1));
           float raux2 = pow(std::abs(1.f / s.a * cos(s.m * j / 4.f)), s.n2) + pow(std::abs(1.f / s.b * sin(s.m * j / 4.f)), s.n3);<commit_msg>fix for multicontext<commit_after>/* -------------------------------- . ---------------------------------------- .
| Filename : SuperFormula.cpp       | DOCGL3.3 sample file                     |
| Author   : <NAME>         |                                          |
| Started  : 25/01/2011 10:09       |                                          |
` --------------------------------- . --------------------------------------- */

# define  _USE_MATH_DEFINES
# include "Tools.h"
# include <Docgl/Docgl.h>
# include <Docgl/DocglWindow.h>

struct SuperFormula3D
  {float a, b, m, n1, n2, n3;};
static const float step = 0.05f;
enum {superFormulaNumVertices = 7938}; // depends from step

#ifdef linux
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
#endif // linux

class Globals: public OpenGLWindowCallback
{
public:
  docgl::GLDirectContext context;
  docgl::GLBufferObject superFormulaVertexBuffer;
  docgl::GLVertexArrayObject superFormulaVertexArray;
  docgl::GLProgramObject flatColorTransformShader;
  GLint vColorLocation;
  GLint mvpMatrixLocation;
#ifdef DOCGL4_1
  GLint getColorFunctionLocation;
  GLuint getUniformColorIndex;
  GLuint getUniformColorInvIndex;
  bool invertColor;
#endif // !DOCGL4_1
  glm::mat4         projectionMatrix;
  Frame			  	    cameraFrame;
  Frame             objectFrame;
  int nStep;
  SuperFormula3D superFormula3d;
  bool invertCoordinate;
  bool cullFace;
  bool depthTest;
  bool wantExit;

  Globals()
    : superFormulaVertexBuffer(context)
    , superFormulaVertexArray(context)
    , flatColorTransformShader(context)
    , vColorLocation(-1)
    , mvpMatrixLocation(-1)
#ifdef DOCGL4_1
    , getColorFunctionLocation(-1)
    , getUniformColorIndex(GL_INVALID_INDEX)
    , getUniformColorInvIndex(GL_INVALID_INDEX)
    , invertColor(false)
#endif // !DOCGL4_1
    , nStep(0)
    , invertCoordinate(false)
    , cullFace(false)
    , depthTest(true)
    , wantExit(false)
    {
      static const SuperFormula3D formula = {1.f, 1.f, 4.f, 12.f, 15.f, 15.f};
      superFormula3d = formula;
    }

  virtual void draw()
  {
    context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    context.getCullFace().setValue(cullFace);
    context.getDepthTest().setValue(depthTest);

    bool succeed;
    glm::mat4 modelViewProjection = projectionMatrix * cameraFrame.getCameraMatrix() * objectFrame.getMatrix();
    succeed = flatColorTransformShader.setUniformMatrix<4, 4>(mvpMatrixLocation, 1, GL_FALSE, &modelViewProjection[0][0]).hasSucceed();
    glUniformMatrix4fv(mvpMatrixLocation, 1, GL_FALSE, &modelViewProjection[0][0]);

    GLenum primitive;
    switch (nStep)
    {
    case 0: primitive = GL_POINTS; break;
    case 1: primitive = GL_LINES; break;
    case 2: primitive = GL_LINE_STRIP; break;
    case 3: primitive = GL_LINE_LOOP; break;
    case 4: primitive = GL_TRIANGLES; break;
    case 7: primitive = GL_QUADS; break;
    case 5: primitive = GL_TRIANGLE_FAN; break;
    case 6: primitive = GL_TRIANGLE_STRIP; break;
    case 8: primitive = GL_QUAD_STRIP; break;
    case 9: primitive = GL_POLYGON; break;
    }

    const GLfloat vGreen[] = {0.0f, 1.0f, 0.0f, 1.0f};
    const GLfloat vBlack[] = {0.0f, 0.0f, 0.0f, 1.0f};
    if (nStep < 4)
    {
      succeed = flatColorTransformShader.setUniformValue(vColorLocation, 4, 1, vBlack).hasSucceed();
      jassert(succeed);

  #ifdef DOCGL4_1
      // last thing to do with flatColorTransformShader
      succeed = context.loadUniformSubroutines(GL_FRAGMENT_SHADER, 1, invertColor ? &getUniformColorInvIndex : &getUniformColorIndex).hasSucceed();
      jassert(succeed);
  #endif // !DOCGL4_1

      succeed = superFormulaVertexArray.draw(primitive, 0, superFormulaNumVertices).hasSucceed();
      jassert(succeed);
    }
    else
    {
      // Draw the batch solid green
      succeed = flatColorTransformShader.setUniformValue(vColorLocation, 4, 1, vGreen).hasSucceed();
      jassert(succeed);

  #ifdef DOCGL4_1
      // last thing to do with flatColorTransformShader
      succeed = context.loadUniformSubroutines(GL_FRAGMENT_SHADER, 1, invertColor ? &getUniformColorInvIndex : &getUniformColorIndex).hasSucceed();
      jassert(succeed);
  #endif // !DOCGL4_1

      succeed = superFormulaVertexArray.draw(primitive, 0, superFormulaNumVertices).hasSucceed();
      jassert(succeed);

      // Draw black outline
      context.getPolygonOffset().setValue(docgl::GLPolygonOffset(-1.0f, -1.0f));      // Shift depth values
      context.getLinePolygonOffset().setValue(true);

      // Draw black wireframe version of geometry
      succeed = flatColorTransformShader.setUniformValue(vColorLocation, 4, 1, vBlack).hasSucceed();
      jassert(succeed);

  #ifdef DOCGL4_1
      // last thing to do with flatColorTransformShader
      succeed = context.loadUniformSubroutines(GL_FRAGMENT_SHADER, 1, invertColor ? &getUniformColorInvIndex : &getUniformColorIndex).hasSucceed();
      jassert(succeed);
  #endif // !DOCGL4_1

      succeed = superFormulaVertexArray.draw(GL_LINE_STRIP, 0, superFormulaNumVertices).hasSucceed();
      jassert(succeed);

      // Put everything back the way we found it
      context.getLinePolygonOffset().setValue(false);
      context.getPolygonOffset().setValue(docgl::GLPolygonOffset(0.0f, 0.0f));
    }
  }



  void constructSuperMesh(const SuperFormula3D& s, bool invertCoordinate)
  {
    GLfloat computeBuffer[superFormulaNumVertices][3];
    int veccount = 0;
    if (invertCoordinate)
    {
      for (float j = float(-M_PI / 2.f); j < M_PI / 2.f; j += step)
        for (float i = float(-M_PI); i < M_PI; i += step)
        {
           float raux1 = pow(std::abs(1.f / s.a * cos(s.m * i / 4.f)), s.n2) + pow(std::abs(1.f / s.b * sin(s.m * i / 4.f)), s.n3);
           float r1 = pow(std::abs(raux1), (-1.f / s.n1));
           float raux2 = pow(std::abs(1.f / s.a * cos(s.m * j / 4.f)), s.n2) + pow(std::abs(1.f / s.b * sin(s.m * j / 4.f)), s.n3);
{'fraction_non_alphanumeric': 0.14110326269761184, 'fraction_numerical': 0.02404978136562395, 'mean_word_length': 2.912171052631579, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1627119', 'n_tokens_mistral': 4198, 'n_tokens_neox': 4001, 'n_words': 822}