//-----------------------------------------------------------------------
CompositionTechnique::TextureDefinition *CompositionTechnique::createTextureDefinition(const String &name)
{
    TextureDefinition *t = OGRE_NEW TextureDefinition();
    t->name = name;
    mTextureDefinitions.push_back(t);
    return t;
}
Exemplo n.º 2
0
TextureDefinition* TextureManager::CreateTexture(const char* texturefilename, int minfilter, int magfilter, int wraps, int wrapt)
{
    MyAssert( texturefilename );

    LOGInfo( LOGTag, "CreateTexture - %s\n", texturefilename );

    // find the texture if it already exists:
    TextureDefinition* pTextureDef = FindTexture( texturefilename );
    if( pTextureDef != 0 )
    {
        pTextureDef->AddRef();
        return pTextureDef;
    }

    // Create a new texture and add it to m_TexturesStillLoading
    pTextureDef = MyNew TextureDefinition();
    pTextureDef->m_ManagedByTextureManager = true;
    strcpy_s( pTextureDef->m_Filename, MAX_PATH, texturefilename );
    pTextureDef->m_MinFilter = minfilter;
    pTextureDef->m_MagFilter = magfilter;
    pTextureDef->m_WrapS = wraps;
    pTextureDef->m_WrapT = wrapt;

    m_TexturesStillLoading.AddTail( pTextureDef );

    // if the file load hasn't started... start the file load.
    MyAssert( pTextureDef->m_pFile == 0 );
#if 0 //MYFW_ANDROID
    //LOGInfo( LOGTag, "Loading Texture: pTextureDef->m_pFile %d\n", pTextureDef->m_pFile );
    if( pTextureDef->m_pFile == 0 )
    {
        pTextureDef->m_pFile = RequestTexture( pTextureDef->m_Filename, pTextureDef );
        //textureloaded = true;
    }
#else
    if( pTextureDef->m_pFile == 0 )
    {
        //LOGInfo( LOGTag, "Loading Texture: RequestFile\n" );
        pTextureDef->m_pFile = RequestFile( pTextureDef->m_Filename );
        //LOGInfo( LOGTag, "Loading Texture: ~RequestFile\n" );
    }
#endif

    return pTextureDef;
}
Exemplo n.º 3
0
bool FBODefinition::Create()
{
#if MYFW_WINDOWS
    if( glGenFramebuffers == 0 )
    {
        return false;
    }
#endif
#if MYFW_IOS || MYFW_ANDROID
    //return false;
#endif

#if !USE_D3D
    GLint maxsize;

    glGetIntegerv( GL_MAX_RENDERBUFFER_SIZE, &maxsize );
    LOGInfo( LOGTag, "CreateFBO - maxsize: %d\n", maxsize );

#if MYFW_ANDROID
    int range[2], precision;
    glGetShaderPrecisionFormat( GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, range, &precision );
    LOGInfo( LOGTag, "CreateFBO - High float precision: %d\n", precision );
    LOGInfo( LOGTag, "CreateFBO - High float range min: %d\n", range[0] );
    LOGInfo( LOGTag, "CreateFBO - High float range max: %d\n", range[1] );
    glGetShaderPrecisionFormat( GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, range, &precision );
    LOGInfo( LOGTag, "CreateFBO - Medium float precision: %d\n", precision );
    LOGInfo( LOGTag, "CreateFBO - Medium float range min: %d\n", range[0] );
    LOGInfo( LOGTag, "CreateFBO - Medium float range max: %d\n", range[1] );
    glGetShaderPrecisionFormat( GL_FRAGMENT_SHADER, GL_LOW_FLOAT, range, &precision );
    LOGInfo( LOGTag, "CreateFBO - Low float precision: %d\n", precision );
    LOGInfo( LOGTag, "CreateFBO - Low float range min: %d\n", range[0] );
    LOGInfo( LOGTag, "CreateFBO - Low float range max: %d\n", range[1] );
#endif

    if( m_TextureWidth > (unsigned int)maxsize || m_TextureHeight > (unsigned int)maxsize )
    {
        // requested size is too big.
        return false;
    }

    MyAssert( m_FrameBufferID == 0 );

    // get a framebuffer, render buffer and a texture from opengl.
    glGenFramebuffers( 1, &m_FrameBufferID );
    checkGlError( "glGenFramebuffers" );

    if( m_NeedColorTexture )
    {
        m_pColorTexture = MyNew TextureDefinition();
        glGenTextures( 1, &m_pColorTexture->m_TextureID );
        m_pColorTexture->m_MinFilter = m_MinFilter;
        m_pColorTexture->m_MagFilter = m_MagFilter;
        m_pColorTexture->m_WrapS = GL_CLAMP_TO_EDGE;
        m_pColorTexture->m_WrapT = GL_CLAMP_TO_EDGE;
        m_pColorTexture->m_Width = m_Width;
        m_pColorTexture->m_Height = m_Height;
    }
    checkGlError( "glGenTextures" );

    if( m_DepthBits != 0 )
    {
        m_pDepthTexture = MyNew TextureDefinition();

        MyAssert( m_DepthBits == 16 || m_DepthBits == 24 || m_DepthBits == 32 );

        if( m_DepthIsTexture )
        {
            glGenTextures( 1, &m_pDepthTexture->m_TextureID );
            checkGlError( "glGenTextures" );
        }
        else
        {
            glGenRenderbuffers( 1, &m_pDepthTexture->m_TextureID );
            checkGlError( "glGenRenderbuffers" );
        }

        m_pDepthTexture->m_Width = m_Width;
        m_pDepthTexture->m_Height = m_Height;
    }

    // create the texture
    if( m_pColorTexture && m_pColorTexture->m_TextureID != 0 )
    {
        glBindTexture( GL_TEXTURE_2D, m_pColorTexture->m_TextureID );
        //glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, m_TextureWidth, m_TextureHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL );
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, m_TextureWidth, m_TextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
        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_MAG_FILTER, m_MinFilter );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_MagFilter );
        glBindTexture( GL_TEXTURE_2D, 0 );
        checkGlError( "glBindTexture" );
    }

    // create a depth renderbuffer.
    if( m_pDepthTexture && m_pDepthTexture->m_TextureID != 0 )
    {
#if !MYFW_OPENGLES2
        GLint depthformat = GL_DEPTH_COMPONENT32;
        if( m_DepthBits == 24 )
            depthformat = GL_DEPTH_COMPONENT24;
        else if( m_DepthBits == 16 )
            depthformat = GL_DEPTH_COMPONENT16;
#else
        GLint depthformat = GL_DEPTH_COMPONENT16;
#endif

        if( m_DepthIsTexture )
        {
            glBindTexture( GL_TEXTURE_2D, m_pDepthTexture->m_TextureID );
            checkGlError( "glBindTexture" );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
            checkGlError( "glTexParameteri" );
            glTexImage2D( GL_TEXTURE_2D, 0, depthformat, m_TextureWidth, m_TextureHeight, 0,
                          GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0 );
                          //GL_DEPTH_COMPONENT, GL_FLOAT, 0 );
            checkGlError( "glTexImage2D" );
            glBindTexture( GL_TEXTURE_2D, 0 );
            checkGlError( "glBindTexture" );
        }
        else
        {
            glBindRenderbuffer( GL_RENDERBUFFER, m_pDepthTexture->m_TextureID );
            glRenderbufferStorage( GL_RENDERBUFFER, depthformat, m_TextureWidth, m_TextureHeight );
            checkGlError( "glRenderbufferStorageEXT" );
        }
    }

    // attach everything to the FBO
    {
        MyBindFramebuffer( GL_FRAMEBUFFER, m_FrameBufferID, 0, 0 );

        // attach color texture
        if( m_pColorTexture && m_pColorTexture->m_TextureID != 0 )
            glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pColorTexture->m_TextureID, 0 );

        // attach depth renderbuffer
        if( m_pDepthTexture && m_pDepthTexture->m_TextureID != 0 )
        {
            if( m_DepthIsTexture )
            {
                glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_pDepthTexture->m_TextureID, 0 );
            }
            else
            {
               glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_pDepthTexture->m_TextureID );
            }
        }

        MyBindFramebuffer( GL_FRAMEBUFFER, 0, 0, 0 );
        checkGlError( "glBindFramebufferEXT" );
    }

    // any problems?
    GLint status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
    checkGlError( "glCheckFramebufferStatus" );
    if( status != GL_FRAMEBUFFER_COMPLETE )
    {
        LOGInfo( LOGTag, "CreateFBO - error\n" );
        //MyAssert( false );
        Invalidate( true );
        return false;
    }

    LOGInfo( LOGTag, "CreateFBO - complete (%d, %d)\n", m_TextureWidth, m_TextureHeight );
#else
    return false;
#endif

    return true;
}