<commit_before>// OVRkill.cpp

#include <GL/glew.h>
#include "OVRkill.h"
#include "OVR_Shaders.h"
#include "GL/ShaderFunctions.h"


/// Once source is obtained from either file or hard-coded map, compile the
/// shader, release the string memory and return the ID.
GLuint makeShaderFromSource(const char* source, const unsigned long Type)
{
    if (source == NULL)
        return 0;
    GLint length = strlen(source);

    GLuint shaderId = glCreateShader(Type);
    glShaderSource(shaderId, 1, &source, &length);
    glCompileShader(shaderId);

    return shaderId;
}

/// Create a shader program from the OVR sources.
GLuint CreateOVRShaders()
{
    GLuint vertSrc = makeShaderFromSource(PostProcessVertexShaderSrc, GL_VERTEX_SHADER);
    GLuint fragSrc = makeShaderFromSource(PostProcessFragShaderSrc, GL_FRAGMENT_SHADER);

    printShaderInfoLog(vertSrc);
    printShaderInfoLog(fragSrc);

    GLuint program = glCreateProgram();

    glCompileShader(vertSrc);
    glCompileShader(fragSrc);

    glAttachShader(program, vertSrc);
    glAttachShader(program, fragSrc);

    // Will be deleted when program is.
    glDeleteShader(vertSrc);
    glDeleteShader(fragSrc);

    glLinkProgram(program);
    printProgramInfoLog(program);

    glUseProgram(0);
    return program;
}



OVRkill::OVRkill()
: m_pManager(NULL)
, m_pHMD(NULL)
, m_pSensor(NULL)
, m_SFusion()
, m_HMDInfo()
, m_SConfig()
, m_PostProcess(PostProcess_Distortion)
, m_fboWidth(0)
, m_fboHeight(0)
, m_progRiftDistortion(0)
, m_progPresFbo(0)
, m_windowWidth(0)
, m_windowHeight(0)
{
}

OVRkill::~OVRkill()
{
    DestroyOVR();
}

void OVRkill::DestroyOVR()
{
    /// Clear these before calling Destroy.
    m_pSensor.Clear();
    m_pManager.Clear();
    m_pHMD.Clear();
    // No OVR functions involving memory are allowed after this.
    OVR::System::Destroy();
}

/// We need an active GL context for this
void OVRkill::CreateShaders()
{
    m_progPresFbo = makeShaderByName("presentFbo");
    m_progRiftDistortion = CreateOVRShaders();
}

void OVRkill::CreateRenderBuffer()
{
    allocateFBO(m_renderBuffer, m_fboWidth, m_fboHeight);
}

void OVRkill::BindRenderBuffer()
{
    bindFBO(m_renderBuffer);
}

void OVRkill::UnBindRenderBuffer()
{
    unbindFBO();
}

void OVRkill::PresentFbo_NoDistortion()
{
    glUseProgram(m_progPresFbo);
    {
        OVR::Matrix4f ortho = OVR::Matrix4f::Ortho2D((float)m_fboWidth, (float)m_fboHeight);
        glUniformMatrix4fv(getUniLoc(m_progPresFbo, "prmtx"), 1, false, &ortho.Transposed().M[0][0]);

        const float verts[] = {
            0                ,  0,
            (float)m_fboWidth,  0,
            (float)m_fboWidth, (float)m_fboHeight,
            0                , (float)m_fboHeight,
        };
        const float texs[] = {
            0,1,
            1,1,
            1,0,
            0,0,
        };
        const unsigned int tris[] = {
            0,1,2, 0,3,2, // ccw
        };

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, verts);
        glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, texs);
        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(1);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, m_renderBuffer.tex);
        glUniform1i(getUniLoc(m_progPresFbo, "fboTex"), 0);

        glDrawElements(GL_TRIANGLES,
                       6,
                       GL_UNSIGNED_INT,
                       &tris[0]);
    }<commit_msg>Flipped one of the triangles in OVRkill FBO present, which were respectively out-of-order.<commit_after>// OVRkill.cpp

#include <GL/glew.h>
#include "OVRkill.h"
#include "OVR_Shaders.h"
#include "GL/ShaderFunctions.h"


/// Once source is obtained from either file or hard-coded map, compile the
/// shader, release the string memory and return the ID.
GLuint makeShaderFromSource(const char* source, const unsigned long Type)
{
    if (source == NULL)
        return 0;
    GLint length = strlen(source);

    GLuint shaderId = glCreateShader(Type);
    glShaderSource(shaderId, 1, &source, &length);
    glCompileShader(shaderId);

    return shaderId;
}

/// Create a shader program from the OVR sources.
GLuint CreateOVRShaders()
{
    GLuint vertSrc = makeShaderFromSource(PostProcessVertexShaderSrc, GL_VERTEX_SHADER);
    GLuint fragSrc = makeShaderFromSource(PostProcessFragShaderSrc, GL_FRAGMENT_SHADER);

    printShaderInfoLog(vertSrc);
    printShaderInfoLog(fragSrc);

    GLuint program = glCreateProgram();

    glCompileShader(vertSrc);
    glCompileShader(fragSrc);

    glAttachShader(program, vertSrc);
    glAttachShader(program, fragSrc);

    // Will be deleted when program is.
    glDeleteShader(vertSrc);
    glDeleteShader(fragSrc);

    glLinkProgram(program);
    printProgramInfoLog(program);

    glUseProgram(0);
    return program;
}



OVRkill::OVRkill()
: m_pManager(NULL)
, m_pHMD(NULL)
, m_pSensor(NULL)
, m_SFusion()
, m_HMDInfo()
, m_SConfig()
, m_PostProcess(PostProcess_Distortion)
, m_fboWidth(0)
, m_fboHeight(0)
, m_progRiftDistortion(0)
, m_progPresFbo(0)
, m_windowWidth(0)
, m_windowHeight(0)
{
}

OVRkill::~OVRkill()
{
    DestroyOVR();
}

void OVRkill::DestroyOVR()
{
    /// Clear these before calling Destroy.
    m_pSensor.Clear();
    m_pManager.Clear();
    m_pHMD.Clear();
    // No OVR functions involving memory are allowed after this.
    OVR::System::Destroy();
}

/// We need an active GL context for this
void OVRkill::CreateShaders()
{
    m_progPresFbo = makeShaderByName("presentFbo");
    m_progRiftDistortion = CreateOVRShaders();
}

void OVRkill::CreateRenderBuffer()
{
    allocateFBO(m_renderBuffer, m_fboWidth, m_fboHeight);
}

void OVRkill::BindRenderBuffer()
{
    bindFBO(m_renderBuffer);
}

void OVRkill::UnBindRenderBuffer()
{
    unbindFBO();
}

void OVRkill::PresentFbo_NoDistortion()
{
    glUseProgram(m_progPresFbo);
    {
        OVR::Matrix4f ortho = OVR::Matrix4f::Ortho2D((float)m_fboWidth, (float)m_fboHeight);
        glUniformMatrix4fv(getUniLoc(m_progPresFbo, "prmtx"), 1, false, &ortho.Transposed().M[0][0]);

        const float verts[] = {
            0                ,  0,
            (float)m_fboWidth,  0,
            (float)m_fboWidth, (float)m_fboHeight,
            0                , (float)m_fboHeight,
        };
        const float texs[] = {
            0,1,
            1,1,
            1,0,
            0,0,
        };
        const unsigned int tris[] = {
            0,2,1, 0,3,2, // ccw
        };

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, verts);
        glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, texs);
        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(1);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, m_renderBuffer.tex);
        glUniform1i(getUniLoc(m_progPresFbo, "fboTex"), 0);

        glDrawElements(GL_TRIANGLES,
                       6,
                       GL_UNSIGNED_INT,
                       &tris[0]);
    }
{'fraction_non_alphanumeric': 0.11649382014490695, 'fraction_numerical': 0.01392243216365961, 'mean_word_length': 3.0835266821345706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1968019', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2433, 'n_words': 458}