<commit_before>#include <SDL2/SDL.h>

#include "XSCommon/XSCommon.h"
#include "XSCommon/XSConsole.h"
#include "XSCommon/XSString.h"
#include "XSCommon/XSError.h"
#include "XSCommon/XSCvar.h"
#include "XSCommon/XSGlobals.h"
#include "XSCommon/XSTimer.h"
#include "XSRenderer/XSRenderer.h"
#include "XSRenderer/XSView.h"
#include "XSRenderer/XSRenderCommand.h"
#include "XSRenderer/XSBackend.h"
#include "XSRenderer/XSFramebuffer.h"
#include "XSRenderer/XSShaderProgram.h"
#include "XSRenderer/XSTexture.h"
#include "XSRenderer/XSFont.h"
#include "XSRenderer/XSImagePNG.h"
#include "XSRenderer/XSMaterial.h"
#include "XSRenderer/XSVertexAttributes.h"
#include "XSRenderer/XSMaterial.h"
#include "XSRenderer/XSBuffer.h"

#if defined(XS_OS_MAC)
//#include <OpenCL/cl_gl_ext.h>
#endif

#define USE_FBO
#define FBO_COMPOSITE

namespace XS {

	namespace Renderer {

		RendererState rdState = {};

		static SDL_Window *window = nullptr;
		static SDL_GLContext context;

		static Cvar *r_clear = nullptr;
		Cvar *r_debug = nullptr;
		Cvar *r_fastPath = nullptr;
		static Cvar *r_multisample = nullptr;
		static Cvar *r_skipRender = nullptr;
		static Cvar *r_swapInterval = nullptr;
		static Cvar *vid_height = nullptr;
		static Cvar *vid_noBorder = nullptr;
		static Cvar *vid_width = nullptr;

		std::vector<View *> views;
		static View *currentView = nullptr;

#ifdef FBO_COMPOSITE
		static ShaderProgram *compositeShader = nullptr;
#endif

		static const char *GLErrSeverityToString( GLenum severity ) {
			switch ( severity ) {
			case GL_DEBUG_SEVERITY_HIGH_ARB: {
				return "High";
			} break;

			case GL_DEBUG_SEVERITY_MEDIUM_ARB: {
				return "Medium";
			} break;

			case GL_DEBUG_SEVERITY_LOW_ARB: {
				return "Low";
			} break;

			default: {
				return "?";
			} break;
			}
		}

		static const char *GLErrSourceToString( GLenum source ) {
			switch ( source ) {
			case GL_DEBUG_SOURCE_API_ARB: {
				return "API";
			} break;

			case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: {
				return "WS";
			} break;

			case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: {
				return "GLSL";
			} break;

			case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: {
				return "3rd";
			} break;

			case GL_DEBUG_SOURCE_APPLICATION_ARB: {
				return "App";
			} break;

			case GL_DEBUG_SOURCE_OTHER_ARB: {
				return "Other";
			} break;

			default: {
				return "?";
			} break;
			}
		}

		static const char *GLErrTypeToString( GLenum type ) {
			switch ( type ) {
			case GL_DEBUG_TYPE_ERROR_ARB: {
				return "Error";
			} break;

			case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: {
				return "Deprecated";
			} break;

			case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: {
				return "UB";
			} break;

			case GL_DEBUG_TYPE_PORTABILITY_ARB: {
				return "Portability";
			} break;

			case GL_DEBUG_TYPE_PERFORMANCE_ARB: {
				return "Performance";
			} break;

			case GL_DEBUG_TYPE_OTHER_ARB: {
				return "Other";
			} break;

			default: {
				return "?";
			} break;
			}
		}

		static void OnGLError( GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
			const GLchar *message, GLvoid *userParam )
		{
			const int level = r_debug->GetInt32();
			if ( !level || (level == 1 && type == GL_DEBUG_TYPE_PERFORMANCE_ARB) ) {
				return;
			}

			console.Print( PrintLevel::Normal, "[%s] [%s] %s: %s\n",
				GLErrSeverityToString( severity ),
				GLErrSourceToString( source ),
				GLErrTypeToString( type ),
				message
			);
		}

		void Init( void ) {
			rdState.valid = true;

			RegisterCvars();

			CreateDisplay();

			glewExperimental = GL_TRUE;
			GLenum error = glewInit();
			if ( error != GLEW_OK ) {
				throw( XSError( String::Format( "Failed to initialise GLEW: %s\n",
					glewGetErrorString( error ) ).c_str() ) );
			}

			// ARB_debug_output causes a crash due to a driver bug on Nvidia GTX 680 driver versions [350.12, 353.82]<commit_msg>Disable unused renderer debug functions<commit_after>#include <SDL2/SDL.h>

#include "XSCommon/XSCommon.h"
#include "XSCommon/XSConsole.h"
#include "XSCommon/XSString.h"
#include "XSCommon/XSError.h"
#include "XSCommon/XSCvar.h"
#include "XSCommon/XSGlobals.h"
#include "XSCommon/XSTimer.h"
#include "XSRenderer/XSRenderer.h"
#include "XSRenderer/XSView.h"
#include "XSRenderer/XSRenderCommand.h"
#include "XSRenderer/XSBackend.h"
#include "XSRenderer/XSFramebuffer.h"
#include "XSRenderer/XSShaderProgram.h"
#include "XSRenderer/XSTexture.h"
#include "XSRenderer/XSFont.h"
#include "XSRenderer/XSImagePNG.h"
#include "XSRenderer/XSMaterial.h"
#include "XSRenderer/XSVertexAttributes.h"
#include "XSRenderer/XSMaterial.h"
#include "XSRenderer/XSBuffer.h"

#if defined(XS_OS_MAC)
//#include <OpenCL/cl_gl_ext.h>
#endif

#define USE_FBO
#define FBO_COMPOSITE

namespace XS {

	namespace Renderer {

		RendererState rdState = {};

		static SDL_Window *window = nullptr;
		static SDL_GLContext context;

		static Cvar *r_clear = nullptr;
		Cvar *r_debug = nullptr;
		Cvar *r_fastPath = nullptr;
		static Cvar *r_multisample = nullptr;
		static Cvar *r_skipRender = nullptr;
		static Cvar *r_swapInterval = nullptr;
		static Cvar *vid_height = nullptr;
		static Cvar *vid_noBorder = nullptr;
		static Cvar *vid_width = nullptr;

		std::vector<View *> views;
		static View *currentView = nullptr;

#ifdef FBO_COMPOSITE
		static ShaderProgram *compositeShader = nullptr;
#endif

#if 0 // see comment regarding GLEW_ARB_debug_output below
		static const char *GLErrSeverityToString( GLenum severity ) {
			switch ( severity ) {
			case GL_DEBUG_SEVERITY_HIGH_ARB: {
				return "High";
			} break;

			case GL_DEBUG_SEVERITY_MEDIUM_ARB: {
				return "Medium";
			} break;

			case GL_DEBUG_SEVERITY_LOW_ARB: {
				return "Low";
			} break;

			default: {
				return "?";
			} break;
			}
		}

		static const char *GLErrSourceToString( GLenum source ) {
			switch ( source ) {
			case GL_DEBUG_SOURCE_API_ARB: {
				return "API";
			} break;

			case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: {
				return "WS";
			} break;

			case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: {
				return "GLSL";
			} break;

			case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: {
				return "3rd";
			} break;

			case GL_DEBUG_SOURCE_APPLICATION_ARB: {
				return "App";
			} break;

			case GL_DEBUG_SOURCE_OTHER_ARB: {
				return "Other";
			} break;

			default: {
				return "?";
			} break;
			}
		}

		static const char *GLErrTypeToString( GLenum type ) {
			switch ( type ) {
			case GL_DEBUG_TYPE_ERROR_ARB: {
				return "Error";
			} break;

			case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: {
				return "Deprecated";
			} break;

			case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: {
				return "UB";
			} break;

			case GL_DEBUG_TYPE_PORTABILITY_ARB: {
				return "Portability";
			} break;

			case GL_DEBUG_TYPE_PERFORMANCE_ARB: {
				return "Performance";
			} break;

			case GL_DEBUG_TYPE_OTHER_ARB: {
				return "Other";
			} break;

			default: {
				return "?";
			} break;
			}
		}

		static void OnGLError( GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
			const GLchar *message, GLvoid *userParam )
		{
			const int level = r_debug->GetInt32();
			if ( !level || (level == 1 && type == GL_DEBUG_TYPE_PERFORMANCE_ARB) ) {
				return;
			}

			console.Print( PrintLevel::Normal, "[%s] [%s] %s: %s\n",
				GLErrSeverityToString( severity ),
				GLErrSourceToString( source ),
				GLErrTypeToString( type ),
				message
			);
		}
#endif

		void Init( void ) {
			rdState.valid = true;

			RegisterCvars();

			CreateDisplay();

			glewExperimental = GL_TRUE;
			GLenum error = glewInit();
			if ( error != GLEW_OK ) {
				throw( XSError( String::Format( "Failed to initialise GLEW: %s\n",
					glewGetErrorString( error ) ).c_str() ) );
			}

			// ARB_debug_output causes a crash due to a driver bug on Nvidia GTX 680 driver versions [350.12, 353.82]
{'fraction_non_alphanumeric': 0.11408016443987667, 'fraction_numerical': 0.0047533401849948614, 'mean_word_length': 3.695416164053076, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '98273', 'n_tokens_mistral': 3421, 'n_tokens_neox': 2853, 'n_words': 619}