<commit_before>/*
===========================================================================
Copyright (C) 2006 <NAME>
Copyright (C) 2006-2008 <NAME> <<EMAIL>>

This file is part of Daemon source code.

Daemon source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

Daemon source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Daemon source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
// tr_fbo.c
#include "tr_local.h"

/*
=============
R_CheckFBO
=============
*/
qboolean R_CheckFBO( const FBO_t *fbo )
{
#if defined( USE_D3D10 )
	// TODO
	return qfalse;
#else
	int code;
	int id;

	glGetIntegerv( GL_FRAMEBUFFER_BINDING_EXT, &id );
	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo->frameBuffer );

	code = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );

	if ( code == GL_FRAMEBUFFER_COMPLETE_EXT )
	{
		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, id );
		return qtrue;
	}

	// an error occurred
	switch ( code )
	{
		case GL_FRAMEBUFFER_COMPLETE_EXT:
			break;

		case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Unsupported framebuffer format\n", fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete attachment\n", fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, missing attachment\n", fbo->name );
			break;

			//case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
			//  ri.Printf(PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, duplicate attachment\n", fbo->name);
			//  break;

		case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, attached images must have same dimensions\n",
			           fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, attached images must have same format\n",
			           fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, missing draw buffer\n", fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, missing read buffer\n", fbo->name );
			break;

		default:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) unknown error 0x%X\n", fbo->name, code );
			//ri.Error(ERR_FATAL, "R_CheckFBO: (%s) unknown error 0x%X", fbo->name, code);
			//assert(0);
			break;
	}

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, id );

	return qfalse;
#endif
}

/*
============
R_CreateFBO
============
*/
FBO_t          *R_CreateFBO( const char *name, int width, int height )
{
#if defined( USE_D3D10 )
	// TODO
	return NULL;
#else
	FBO_t *fbo;

	if ( strlen( name ) >= MAX_QPATH )
	{
		ri.Error( ERR_DROP, "R_CreateFBO: \"%s\" is too long", name );
	}

	if ( width <= 0 || width > glConfig2.maxRenderbufferSize )
	{
		ri.Error( ERR_DROP, "R_CreateFBO: bad width %i", width );
	}

	if ( height <= 0 || height > glConfig2.maxRenderbufferSize )
	{
		ri.Error( ERR_DROP, "R_CreateFBO: bad height %i", height );
	}

	if ( tr.numFBOs == MAX_FBOS )
	{
		ri.Error( ERR_DROP, "R_CreateFBO: MAX_FBOS hit" );
	}

	fbo = tr.fbos[ tr.numFBOs ] = ri.Hunk_Alloc( sizeof( *fbo ), h_low );
	Q_strncpyz( fbo->name, name, sizeof( fbo->name ) );
	fbo->index = tr.numFBOs++;
	fbo->width = width;
	fbo->height = height;

	glGenFramebuffersEXT( 1, &fbo->frameBuffer );

	return fbo;
#endif
}

/*
================
R_CreateFBOColorBuffer

Framebuffer must be bound
================
*/
void R_CreateFBOColorBuffer( FBO_t *fbo, int format, int index )
{
#if defined( USE_D3D10 )
	// TODO
#else
	qboolean absent;

	if ( index < 0 || index >= glConfig2.maxColorAttachments )
	{
		ri.Printf( PRINT_WARNING, "R_CreateFBOColorBuffer: invalid attachment index %i\n", index );
		return;
	}

#if 0

	if ( format != GL_RGB &&
	     format != GL_RGBA &&
	     format != GL_RGB16F && format != GL_RGBA16F_ && format != GL_RGB32F_ARB && format != GL_RGBA32F_ARB )
	{
		ri.Printf( PRINT_WARNING, "R_CreateFBOColorBuffer: format %i is not color-renderable\n", format );
		//return;
	}

#endif

	fbo->colorFormat = format;

	absent = fbo->colorBuffers[ index ] == 0;<commit_msg>Remove extra underscore in comment<commit_after>/*
===========================================================================
Copyright (C) 2006 <NAME>
Copyright (C) 2006-2008 <NAME> <<EMAIL>>

This file is part of Daemon source code.

Daemon source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

Daemon source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Daemon source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
// tr_fbo.c
#include "tr_local.h"

/*
=============
R_CheckFBO
=============
*/
qboolean R_CheckFBO( const FBO_t *fbo )
{
#if defined( USE_D3D10 )
	// TODO
	return qfalse;
#else
	int code;
	int id;

	glGetIntegerv( GL_FRAMEBUFFER_BINDING_EXT, &id );
	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo->frameBuffer );

	code = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );

	if ( code == GL_FRAMEBUFFER_COMPLETE_EXT )
	{
		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, id );
		return qtrue;
	}

	// an error occurred
	switch ( code )
	{
		case GL_FRAMEBUFFER_COMPLETE_EXT:
			break;

		case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Unsupported framebuffer format\n", fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete attachment\n", fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, missing attachment\n", fbo->name );
			break;

			//case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
			//  ri.Printf(PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, duplicate attachment\n", fbo->name);
			//  break;

		case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, attached images must have same dimensions\n",
			           fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, attached images must have same format\n",
			           fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, missing draw buffer\n", fbo->name );
			break;

		case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) Framebuffer incomplete, missing read buffer\n", fbo->name );
			break;

		default:
			ri.Printf( PRINT_WARNING, "R_CheckFBO: (%s) unknown error 0x%X\n", fbo->name, code );
			//ri.Error(ERR_FATAL, "R_CheckFBO: (%s) unknown error 0x%X", fbo->name, code);
			//assert(0);
			break;
	}

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, id );

	return qfalse;
#endif
}

/*
============
R_CreateFBO
============
*/
FBO_t          *R_CreateFBO( const char *name, int width, int height )
{
#if defined( USE_D3D10 )
	// TODO
	return NULL;
#else
	FBO_t *fbo;

	if ( strlen( name ) >= MAX_QPATH )
	{
		ri.Error( ERR_DROP, "R_CreateFBO: \"%s\" is too long", name );
	}

	if ( width <= 0 || width > glConfig2.maxRenderbufferSize )
	{
		ri.Error( ERR_DROP, "R_CreateFBO: bad width %i", width );
	}

	if ( height <= 0 || height > glConfig2.maxRenderbufferSize )
	{
		ri.Error( ERR_DROP, "R_CreateFBO: bad height %i", height );
	}

	if ( tr.numFBOs == MAX_FBOS )
	{
		ri.Error( ERR_DROP, "R_CreateFBO: MAX_FBOS hit" );
	}

	fbo = tr.fbos[ tr.numFBOs ] = ri.Hunk_Alloc( sizeof( *fbo ), h_low );
	Q_strncpyz( fbo->name, name, sizeof( fbo->name ) );
	fbo->index = tr.numFBOs++;
	fbo->width = width;
	fbo->height = height;

	glGenFramebuffersEXT( 1, &fbo->frameBuffer );

	return fbo;
#endif
}

/*
================
R_CreateFBOColorBuffer

Framebuffer must be bound
================
*/
void R_CreateFBOColorBuffer( FBO_t *fbo, int format, int index )
{
#if defined( USE_D3D10 )
	// TODO
#else
	qboolean absent;

	if ( index < 0 || index >= glConfig2.maxColorAttachments )
	{
		ri.Printf( PRINT_WARNING, "R_CreateFBOColorBuffer: invalid attachment index %i\n", index );
		return;
	}

#if 0

	if ( format != GL_RGB &&
	     format != GL_RGBA &&
	     format != GL_RGB16F && format != GL_RGBA16F && format != GL_RGB32F_ARB && format != GL_RGBA32F_ARB )
	{
		ri.Printf( PRINT_WARNING, "R_CreateFBOColorBuffer: format %i is not color-renderable\n", format );
		//return;
	}

#endif

	fbo->colorFormat = format;

	absent = fbo->colorBuffers[ index ] == 0;
{'fraction_non_alphanumeric': 0.15576260887178447, 'fraction_numerical': 0.01073526433056512, 'mean_word_length': 4.334954078876283, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 57, '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': '1660929', 'n_tokens_mistral': 3715, 'n_tokens_neox': 3449, 'n_words': 925}