<commit_before>﻿//--------------------------------------------------------------------------------
// Copyright (c) 2017-2019, sanko-shoko. All rights reserved.
//--------------------------------------------------------------------------------

#ifndef __SPGLEW_H__
#define __SPGLEW_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define GLEW_STATIC
#include "GL/glew.h"

#define SP_SHADER(...)  #__VA_ARGS__


namespace sp {

    class VertexBufferObject {

    private:
        GLuint m_id;

    private:
        VertexBufferObject(const VertexBufferObject &vbo) {}
        VertexBufferObject& operator =(const VertexBufferObject &vbo) {}

    public:

        VertexBufferObject() {
            glGenBuffers(1, &m_id);
        }

        ~VertexBufferObject() {
            glDeleteBuffers(1, &m_id);
        }

        void set(const int size, const void *vtx) {
            bind();
            glBufferData(GL_ARRAY_BUFFER, size, vtx, GL_STATIC_DRAW);
            unbind();
        }

        void bind() {
            glBindBuffer(GL_ARRAY_BUFFER, m_id);
        }
        void unbind() {
            glBindBuffer(GL_ARRAY_BUFFER, 0);
        }

        GLuint id() const {
            return m_id;
        }
    };

    class FrameBufferObject {

    private:
        // multi sampling
        GLuint m_msid;
        GLuint m_mstx[2];

        // normal
        GLuint m_id;
        GLuint m_tx[2];

    public:
        int samples;
        int dsize[2];
       
    private:
        void reset() {
            memset(this, 0, sizeof(FrameBufferObject));
        }

    public:
        FrameBufferObject() {
            reset();
        }

        FrameBufferObject(const int *dsize, const int samples = 1) {
            reset();
            resize(dsize, samples);
        }

        FrameBufferObject(const int dsize0, const int dsize1, const int samples = 1) {
            reset();
            resize(dsize0, dsize1, samples);
        }

        ~FrameBufferObject() {
            free();
        }

        void free() {
            {
                if (m_id) {
                    glDeleteFramebuffers(1, &m_id);
                }
                if (m_msid) {
                    glDeleteFramebuffers(1, &m_msid);
                }
            }
            for (int i = 0; i < 2; i++) {
                if (m_tx[i]) {
                    glDeleteTextures(1, &m_tx[i]);
                }
                if (m_mstx[i]) {
                    glDeleteTextures(1, &m_mstx[i]);
                }
            }
            reset();
        }

        void resize(const int dsize[2], const int samples = 1) {
            if (this->dsize[0] == dsize[0] && this->dsize[1] == dsize[1] && this->samples == samples) return;

            free();
            this->dsize[0] = dsize[0];
            this->dsize[1] = dsize[1];
            this->samples = samples;

            {
                glGenFramebuffers(1, &m_id);
                glGenTextures(2, m_tx);

                // color
                glBindTexture(GL_TEXTURE_2D, m_tx[0]);
                glPixelStorei(GL_PACK_ALIGNMENT, 1);
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dsize[0], dsize[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

                // depth
                glBindTexture(GL_TEXTURE_2D, m_tx[1]);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
                glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);

                glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, dsize[0], dsize[1], 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
            }
            if (samples > 1) {
                glGenFramebuffers(1, &m_msid);
                glGenTextures(2, m_mstx);

                // color
                glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_mstx[0]);

                glPixelStorei(GL_PACK_ALIGNMENT, 1);
                glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA, dsize[0], dsize[1], false);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

                // depth
                glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_mstx[1]);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
                glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);

                glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_DEPTH_COMPONENT, dsize[0], dsize[1], false);
            }
            glBindTexture(GL_TEXTURE_2D, 0);
        }

        void resize(const int dsize0, const int dsize1, const int samples = 1) {
            int dsize[2] = { dsize0, dsize1 };
            resize(dsize, samples);
        }

        void bind() {
            if (dsize[0] == 0 || dsize[1] == 0)return;
            glPushAttrib(GL_VIEWPORT_BIT);
            ::glViewport(0, 0, dsize[0], dsize[1]);
<commit_msg>refactoring<commit_after>﻿//--------------------------------------------------------------------------------
// Copyright (c) 2017-2019, sanko-shoko. All rights reserved.
//--------------------------------------------------------------------------------

#ifndef __SPGLEW_H__
#define __SPGLEW_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define GLEW_STATIC
#include "GL/glew.h"

#define SP_SHADER(...)  #__VA_ARGS__


namespace sp {

    class VertexBufferObject {

    private:
        GLuint m_id;

    private:
        VertexBufferObject(const VertexBufferObject &vbo) {}
        VertexBufferObject& operator =(const VertexBufferObject &vbo) {}

    public:

        VertexBufferObject() {
            glGenBuffers(1, &m_id);
        }

        ~VertexBufferObject() {
            glDeleteBuffers(1, &m_id);
        }

        void set(const int size, const void *vtx) {
            bind();
            glBufferData(GL_ARRAY_BUFFER, size, vtx, GL_STATIC_DRAW);
            unbind();
        }

        void bind() {
            glBindBuffer(GL_ARRAY_BUFFER, m_id);
        }
        void unbind() {
            glBindBuffer(GL_ARRAY_BUFFER, 0);
        }

        GLuint id() const {
            return m_id;
        }
    };

    class FrameBufferObject {

    private:
        // multi sampling
        GLuint m_msid;
        GLuint m_mstx[2];

        // normal
        GLuint m_id;
        GLuint m_tx[2];

    public:
        int samples;
        int dsize[2];
       
    private:
        void reset() {
            memset(this, 0, sizeof(FrameBufferObject));
        }

    public:
        FrameBufferObject() {
            reset();
        }

        FrameBufferObject(const int *dsize, const int samples = 1) {
            reset();
            resize(dsize, samples);
        }

        FrameBufferObject(const int dsize0, const int dsize1, const int samples = 1) {
            reset();
            resize(dsize0, dsize1, samples);
        }

        ~FrameBufferObject() {
            free();
        }

        void free() {
            {
                if (m_id) {
                    glDeleteFramebuffers(1, &m_id);
                }
                if (m_msid) {
                    glDeleteFramebuffers(1, &m_msid);
                }
            }
            for (int i = 0; i < 2; i++) {
                if (m_tx[i]) {
                    glDeleteTextures(1, &m_tx[i]);
                }
                if (m_mstx[i]) {
                    glDeleteTextures(1, &m_mstx[i]);
                }
            }
            reset();
        }

        void resize(const int dsize[2], const int samples = 1) {
            if (this->dsize[0] == dsize[0] && this->dsize[1] == dsize[1] && this->samples == samples) return;

            free();
            this->dsize[0] = dsize[0];
            this->dsize[1] = dsize[1];
            this->samples = samples;

            {
                glGenFramebuffers(1, &m_id);
                glGenTextures(2, m_tx);

                // color
                glBindTexture(GL_TEXTURE_2D, m_tx[0]);
                glPixelStorei(GL_PACK_ALIGNMENT, 1);
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dsize[0], dsize[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

                // depth
                glBindTexture(GL_TEXTURE_2D, m_tx[1]);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
                glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);

                glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, dsize[0], dsize[1], 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
            }
            if (samples > 1) {
                glGenFramebuffers(1, &m_msid);
                glGenTextures(2, m_mstx);

                // color
                glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_mstx[0]);

                glPixelStorei(GL_PACK_ALIGNMENT, 1);
                glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA, dsize[0], dsize[1], false);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

                // depth
                glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_mstx[1]);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
                glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);

                glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_DEPTH_COMPONENT, dsize[0], dsize[1], false);
            }
            glBindTexture(GL_TEXTURE_2D, 0);
        }

        void resize(const int dsize0, const int dsize1, const int samples = 1) {
            int dsize[2] = { dsize0, dsize1 };
            resize(dsize, samples);
        }

        void bind() {
            if (dsize[0] == 0 || dsize[1] == 0)return;
            glPushAttrib(GL_ALL_ATTRIB_BITS);
            ::glViewport(0, 0, dsize[0], dsize[1]);

{'fraction_non_alphanumeric': 0.1197199716825297, 'fraction_numerical': 0.0179343978604578, 'mean_word_length': 1.7778020537469958, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '7409748', 'n_tokens_mistral': 4484, 'n_tokens_neox': 4084, 'n_words': 662}