Example #1
0
RBClock::RBClock(const timesource* a_timesource)
{
	_time_source = NULL;
	_current_time = 0;
	_frame_time = 0;
	_frame_time = 0;
	_source_last_value = 0;
	_source_start_value = 0;
	reset_time_source(a_timesource);
	set_filtering(1);
	_frame_time = get_predicted_frame_time();

}
Example #2
0
void Texture::init(const void* data_ptr)
{
	// ------------------------------------------------
	// Check params

#if GLLIB_GLES
	if (is_half(_format))
	{
		// Just in case:
		// FIXME: needed?
		_params.wrap = std::make_pair(WrapMode::Clamp, WrapMode::Clamp);
		//_params.filter = TexFilter::Nearest;
		//_params.filter = TexFilter::Linear;
	}
#endif

	// ------------------------------------------------

	//std::cout << "Uploading Texture..." << std::endl;

	CHECK_FOR_GL_ERROR;

	bind();

	set_filtering(_params.filter);
	set_wrap_mode(_params.wrap.first, _params.wrap.second);

	// ------------------------------------------------

	if (data_ptr) {
		set_data(data_ptr);
	}

	CHECK_FOR_GL_ERROR;

	set_debug_name(_debug_name);

	CHECK_FOR_GL_ERROR;
}
Example #3
0
bool
opengl_texture::create() {

    if( data_state != resource_state::good ) {
        // don't bother until we have useful texture data
        return false;
    }

    // TODO: consider creating and storing low-res version of the texture if it's ever unloaded from the gfx card,
    // as a placeholder until it can be loaded again
    if( id == -1 ) {

        ::glGenTextures( 1, &id );
        ::glBindTexture( GL_TEXTURE_2D, id );

        // analyze specified texture traits
        bool wraps{ true };
        bool wrapt{ true };
        for( auto const &trait : traits ) {

            switch( trait ) {

                case 's': { wraps = false; break; }
                case 't': { wrapt = false; break; }
            }
        }

        ::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, ( wraps == true ? GL_REPEAT : GL_CLAMP_TO_EDGE ) );
        ::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, ( wrapt == true ? GL_REPEAT : GL_CLAMP_TO_EDGE ) );

        set_filtering();

        if( data_mapcount == 1 ) {
            // fill missing mipmaps if needed
            ::glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
        }
        // upload texture data
        int dataoffset = 0,
            datasize = 0,
            datawidth = data_width,
            dataheight = data_height;
        for( int maplevel = 0; maplevel < data_mapcount; ++maplevel ) {

            if( ( data_format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT )
                || ( data_format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT )
                || ( data_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ) ) {
                // compressed dds formats
                int const datablocksize =
                    ( data_format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ?
                    8 :
                    16 );

                datasize = ( ( std::max( datawidth, 4 ) + 3 ) / 4 ) * ( ( std::max( dataheight, 4 ) + 3 ) / 4 ) * datablocksize;

                ::glCompressedTexImage2D(
                    GL_TEXTURE_2D, maplevel, data_format,
                    datawidth, dataheight, 0,
                    datasize, (GLubyte *)&data[ dataoffset ] );

                dataoffset += datasize;
                datawidth = std::max( datawidth / 2, 1 );
                dataheight = std::max( dataheight / 2, 1 );
            }
            else {
                // uncompressed texture data. have the gfx card do the compression as it sees fit
                ::glTexImage2D(
                    GL_TEXTURE_2D, 0,
					Global.compress_tex ? GL_COMPRESSED_RGBA : GL_RGBA,
                    data_width, data_height, 0,
                    data_format, GL_UNSIGNED_BYTE, (GLubyte *)&data[ 0 ] );
            }
        }

        if( ( true == Global.ResourceMove )
         || ( false == Global.ResourceSweep ) ) {
            // if garbage collection is disabled we don't expect having to upload the texture more than once
            data = std::vector<char>();
            data_state = resource_state::none;
        }

        if( type == "make:" ) {
            // for generated textures send a request to have the actual content of the texture generated
            make_request();
        }

        is_ready = true;
    }

    return true;
}