<commit_before>/*
 *  ARC++
 *
 *  Copyright (c) 2007-2008 <NAME>.
 *
 *  Licensed under the New BSD License.
 *
 */

#include "universal_include.h"

#include "Graphics/opengl.h"
#include "Graphics/texture_opengl.h"

OpenGLTexture::OpenGLTexture ()
 : Texture(),
   m_textureID(INVALID_SURFACE_ID)
{
}

OpenGLTexture::OpenGLTexture ( SDL_Surface *_surface )
 : Texture(_surface),
   m_textureID(INVALID_SURFACE_ID)
{
}

OpenGLTexture::~OpenGLTexture()
{
}

void OpenGLTexture::Dispose()
{
    if ( m_textureID != INVALID_SURFACE_ID &&
         m_textureID != SCREEN_SURFACE_ID )
    {
	    g_openGL->ActivateTextureRect();
        Bind();
        glTexImage2D ( g_openGL->GetTextureTarget(), 0, g_openGL->GetInternalFormat32(), 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
        ASSERT_OPENGL_ERRORS;

        g_openGL->FreeTexture ( m_textureID );
        m_textureID = INVALID_SURFACE_ID;
    }

	Texture::Dispose();
}

bool OpenGLTexture::Create ( Uint16 _width, Uint16 _height, bool _isColorKeyed )
{
    ARCReleaseAssert ( m_textureID != SCREEN_SURFACE_ID );
    ARCReleaseAssert ( _width > 0 ); ARCReleaseAssert ( _height > 0 );
    
    Uint32 oldWidth = _width, oldHeight = _height;
    if ( !g_openGL->GetSetting ( OPENGL_TEX_ALLOW_NPOT, false ) ) {
        if ( !isPowerOfTwo ( _width ) )
            _width = nearestPowerOfTwo ( _width );
        if ( !isPowerOfTwo ( _height ) )
            _height = nearestPowerOfTwo ( _height );
        ARCReleaseAssert ( isPowerOfTwo ( _width * _height ) );
    }

    Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif

    m_sdlSurface = SDL_CreateRGBSurface ( SDL_SWSURFACE, _width, _height, 32, rmask, gmask, bmask, amask );
    ARCReleaseAssert ( m_sdlSurface != NULL );

    SDL_SetAlpha ( m_sdlSurface, 0, SDL_ALPHA_OPAQUE );
        
    m_textureID = g_openGL->GetFreeTexture();
    ARCReleaseAssert ( m_textureID != 0 );
    ASSERT_OPENGL_ERRORS;

    Bind();

    glTexParameteri ( g_openGL->GetTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_LINEAR ); // set up for linear scaling
    ASSERT_OPENGL_ERRORS;
    glTexParameteri ( g_openGL->GetTextureTarget(), GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    ASSERT_OPENGL_ERRORS;

    g_openGL->VertexArrayStateTexture();

    m_originalWidth = oldWidth;
    m_originalHeight = oldHeight;

    Damage ();
<commit_msg>opengl textures: disable bilinear filtering<commit_after>/*
 *  ARC++
 *
 *  Copyright (c) 2007-2008 <NAME>.
 *
 *  Licensed under the New BSD License.
 *
 */

#include "universal_include.h"

#include "Graphics/opengl.h"
#include "Graphics/texture_opengl.h"

OpenGLTexture::OpenGLTexture ()
 : Texture(),
   m_textureID(INVALID_SURFACE_ID)
{
}

OpenGLTexture::OpenGLTexture ( SDL_Surface *_surface )
 : Texture(_surface),
   m_textureID(INVALID_SURFACE_ID)
{
}

OpenGLTexture::~OpenGLTexture()
{
}

void OpenGLTexture::Dispose()
{
    if ( m_textureID != INVALID_SURFACE_ID &&
         m_textureID != SCREEN_SURFACE_ID )
    {
	    g_openGL->ActivateTextureRect();
        Bind();
        glTexImage2D ( g_openGL->GetTextureTarget(), 0, g_openGL->GetInternalFormat32(), 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
        ASSERT_OPENGL_ERRORS;

        g_openGL->FreeTexture ( m_textureID );
        m_textureID = INVALID_SURFACE_ID;
    }

	Texture::Dispose();
}

bool OpenGLTexture::Create ( Uint16 _width, Uint16 _height, bool _isColorKeyed )
{
    ARCReleaseAssert ( m_textureID != SCREEN_SURFACE_ID );
    ARCReleaseAssert ( _width > 0 ); ARCReleaseAssert ( _height > 0 );
    
    Uint32 oldWidth = _width, oldHeight = _height;
    if ( !g_openGL->GetSetting ( OPENGL_TEX_ALLOW_NPOT, false ) ) {
        if ( !isPowerOfTwo ( _width ) )
            _width = nearestPowerOfTwo ( _width );
        if ( !isPowerOfTwo ( _height ) )
            _height = nearestPowerOfTwo ( _height );
        ARCReleaseAssert ( isPowerOfTwo ( _width * _height ) );
    }

    Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif

    m_sdlSurface = SDL_CreateRGBSurface ( SDL_SWSURFACE, _width, _height, 32, rmask, gmask, bmask, amask );
    ARCReleaseAssert ( m_sdlSurface != NULL );

    SDL_SetAlpha ( m_sdlSurface, 0, SDL_ALPHA_OPAQUE );
        
    m_textureID = g_openGL->GetFreeTexture();
    ARCReleaseAssert ( m_textureID != 0 );
    ASSERT_OPENGL_ERRORS;

    Bind();

#if 0
    glTexParameteri ( g_openGL->GetTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_LINEAR ); // set up for linear scaling
    ASSERT_OPENGL_ERRORS;
    glTexParameteri ( g_openGL->GetTextureTarget(), GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    ASSERT_OPENGL_ERRORS;
#else
    glTexParameteri ( g_openGL->GetTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    ASSERT_OPENGL_ERRORS;
    glTexParameteri ( g_openGL->GetTextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    ASSERT_OPENGL_ERRORS;
#endif

    g_openGL->VertexArrayStateTexture();

    m_originalWidth = oldWidth;
    m_originalHeight = oldHeight;

    Damage ();

{'fraction_non_alphanumeric': 0.10781570602499534, 'fraction_numerical': 0.0318970341354225, 'mean_word_length': 3.5711849957374255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '910141', 'n_tokens_mistral': 2121, 'n_tokens_neox': 1923, 'n_words': 348}