Exemple #1
0
bool RAM::init()
{
    if ((size != getNextPowerOf2(size)) ||
        (!size))
    {
		logMessage("invalid value for size");
        
		return false;
    }
    
    if (controlBus)
        controlBus->postMessage(this, CONTROLBUS_GET_POWERSTATE, &powerState);
    
    if (!powerOnPattern.size())
        powerOnPattern.resize(1);
    else
        powerOnPattern.resize((size_t) getNextPowerOf2((int) powerOnPattern.size()));
    
    size_t oldSize = data.size();
    data.resize((size_t) size);
    if (oldSize == 0)
        initMemory();
    datap = &data.front();
    mask = size - 1;
    
    return true;
}
Exemple #2
0
Int32 getQuadtreeLeafNodeCount(Int32 iSamplesX, 
                               Int32 iSamplesY, 
                               Int32 iTileSize)
{
    const Int32 iLeafNodeCountX = 
        getNextPowerOf2(getCeil(Real32(iSamplesX) / Real32(iTileSize)));

    const Int32 iLeafNodeCountY = 
        getNextPowerOf2(getCeil(Real32(iSamplesY) / Real32(iTileSize)));
    
    // todo: output a warning, if leafNodeCountX and leafNodeCountY are to 
    // much apart.. this wastes a lot of memory right now..

    return osgMax(iLeafNodeCountX, iLeafNodeCountY);
}
Exemple #3
0
bool ROM::init()
{
    if (!data.size())
    {
        logMessage("missing ROM");
        
        return false;
    }
    
    OEAddress size = getNextPowerOf2((int) data.size());
    data.resize((size_t) size);
    datap = &data.front();
    mask = size - 1;
    
    return true;
}
bool GeometryClipmaps::initialize( int requestedLevelSize, 
                                   HeightDataSource* heightSource, 
                                   TextureDataSource* textureSource )
{
    if( requestedLevelSize < 3 )
    {
        // todo: report an error...
        return false;
    }
    if( !heightSource )
    {
        return false;
    }
    
    // fix the levelsize to be 2**x - 1:
    const int levelSampleCount = int(getNextPowerOf2( requestedLevelSize ) - 1);
    const int worldSampleCount = int(heightSource->getSampleCount().maxValue());
    
    // Calculate needed level count 
    int levelCount = 1;
    int levelSize = levelSampleCount;
    
    while( levelSize < worldSampleCount )
    {
        levelCount++;
        levelSize = ( 1 << ( levelCount - 1 ) ) * ( levelSampleCount - 1 ) + 1;
    }
    
    // debug: use only 2 levels:
    const int maxLevelCount = 20;
    levelCount = std::min( maxLevelCount, levelCount );
    
    // todo: make this a parameter:
    const int TextureSize = 256;
    
    levels_.resize( levelCount );
    
    // initialize clipmap-level:        
    for( int i = 0; i < levelCount; ++i )
    {
        // Level 0 is the coarsest one: so reverse the index:
        const int levelIndex = levelCount - i - 1;
        
        GeometryClipmapLevel& level = levels_[ i ];
        
        level.index             = i;
        level.isSampleDataDirty = true;
        level.sampleSpacing     = 1 << levelIndex;
        
        level.heightmap.initialize( levelSampleCount );
        
        level.textureData = Image::create();
        
        level.textureData->set( Image::OSG_RGBA_PF, TextureSize, TextureSize );
    }           
    
    // one full levelupdate is allowed..
    sampleUpdateBudget_ = ( levelSampleCount * levelSampleCount );      
    
    // initialize the render data:
    if( !cpuRenderer_.initialize( this ) )
    {
        levels_.clear();
        return false;
    }
    
    heightSource_   = heightSource;
    textureSource_  = textureSource;

    return true;
}
Exemple #5
0
Texture::Texture(Image* image){
	eraseProtection = false;
	xRatio = 1.0f;
	yRatio = 1.0f;
	nonPowerOfTwo = false;
	glGenTextures(1, &textureId);
	glBindTexture(GL_TEXTURE_2D, textureId);
	
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//);GL_NEAREST
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//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);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	GLint internalFormat = GL_RGB;
	format = GL_RGB;
	logInf("image w:%i h:%i format:%i",image->width,image->height,image->bytes_per_pixel);

	xSquare = getNextPowerOf2(image->width);
	ySquare = getNextPowerOf2(image->height);

	widthOriginal = image->width;
	heightOriginal = image->height;

	if(image->bytes_per_pixel == Image::RGBA){
		internalFormat = GL_RGBA;
		format = GL_RGBA;
	}

	if(xSquare != image->width || ySquare != image->height){
		nonPowerOfTwo = true;
		logWar("the current image isn't a power of two w:%i h:%i the image will be of w:%i h:%i and cropped", image->width, image->height, xSquare, ySquare);
		xRatio = (float)image->width / xSquare;
		yRatio = (float)image->height / ySquare;
		glTexImage2D(GL_TEXTURE_2D, 		// target
				0,  						// level, 0 = base, no minimap,
				internalFormat,			 	// internalformat
				xSquare,  					// width
				ySquare, 					// height
				0,  						// border, always 0 in OpenGL ES
				format,						// format
				GL_UNSIGNED_BYTE, 			// type
				0);
		glTexSubImage2D(GL_TEXTURE_2D, 		// target
				0,  						// level, 0 = base, no minimap,
				0,							//xoffset
				0,							//yoffset
				image->width,  				// width
				image->height, 				// height
				format,						// format
				GL_UNSIGNED_BYTE, 			// type
				image->pixel_data);
		return;
	}


	glTexImage2D(GL_TEXTURE_2D, 		// target
			0,  						// level, 0 = base, no minimap,
			internalFormat,			 	// internalformat
			image->width,  				// width
			image->height, 				// height
			0,  						// border, always 0 in OpenGL ES
			format,						// format
			GL_UNSIGNED_BYTE, 			// type
			image->pixel_data);
}