Example #1
0
Surface::Surface ( Uint16 _sizeX, Uint16 _sizeY, Uint16 _splitSections )
{
    if ( _splitSections > 64 ) _splitSections = 64;

    m_sizeXY = std::max ( nearestPowerOfTwo ( _sizeX ), nearestPowerOfTwo ( _sizeY ) );
    m_sqrtN = _splitSections;

    ARCDebugAssert ( isPowerOfTwo ( _splitSections ) );
    if ( !isPowerOfTwo ( _splitSections ) )
    {
        _splitSections = nearestPowerOfTwo ( _splitSections );
        m_nWays = _splitSections * _splitSections;
        m_sqrtN = _splitSections;
    }

    // We want to force it to use the nicest texture size possible without
    // compromising performance.
    Uint16 maxTexSize = std::min ( g_graphics->GetMaximumTextureSize() / 2, 1024 );

    m_pixelWH = m_sizeXY / m_sqrtN;
    while ( m_pixelWH > maxTexSize )
    {
        m_sqrtN *= 2;
        m_pixelWH = m_sizeXY / m_sqrtN;
    }
    m_nWays = m_sqrtN * m_sqrtN;

    m_sectionIDs.setSize ( m_nWays );
	m_srcRects = new SDL_Rect[m_nWays];
	m_destRects = new SDL_Rect[m_nWays];
}
void OpenglES2Device::generateMipMapFor2DTexture(int width, int height){
    // Opengl ES 2 requiere que para aplicar mipmap las texturas sean potencias de 2
    if(VideoConfiguration::getInstance()->isMipMapActive() && isPowerOfTwo(width) && isPowerOfTwo(height) ){
        glGenerateMipmap(GL_TEXTURE_2D);
        this->evaluateErrorsAndLog("generateMipMapFor2DTexture");
    }
}
unsigned char* imageIO::squareImage(unsigned char origImage[], int imageWidth, int imageHeight, int imageBytes) {
	int newImageWidth = 0;
	int newImageHeight = 0;

	if (std::max(imageWidth, imageHeight) == imageWidth) {
		if (!isPowerOfTwo(imageWidth)) {
			newImageWidth = pow(2, ceil(log(imageWidth) / log(2)));
			newImageHeight = newImageWidth;
		}
		else {
			newImageWidth = imageWidth;
			newImageHeight = imageWidth;
		}
	}
	else {
		if (!isPowerOfTwo(imageHeight)) {
			newImageHeight = pow(2, ceil(log(imageHeight) / log(2)));;
			newImageWidth = newImageHeight;
		}
		else {
			newImageHeight = imageHeight;
			newImageWidth = imageHeight;
		}
	}

	unsigned char* squareImage = new unsigned char[newImageWidth*newImageHeight*imageBytes];

	for (int y = 0; y < newImageHeight; y++) {
		for (int x = 0; x < newImageWidth; x++) {
			int oldIndex = ((y * imageWidth * imageBytes) + (x * imageBytes));
			int newIndex = ((y * newImageWidth * imageBytes) + (x * imageBytes));

			if (x < imageWidth && y < imageHeight) {
				squareImage[newIndex] = origImage[oldIndex];
				squareImage[newIndex + 1] = origImage[oldIndex + 1];
				squareImage[newIndex + 2] = origImage[oldIndex + 2];
				squareImage[newIndex + 3] = origImage[oldIndex + 3];
			}
			else {
				squareImage[newIndex] = 255;
				squareImage[newIndex + 1] = 255;
				squareImage[newIndex + 2] = 255;
				squareImage[newIndex + 3] = 255;
			}
		}
	}

	setImageWidth(newImageWidth);
	setImageHeight(newImageHeight);

	return squareImage;
}
Example #4
0
ModifiableTexture::ModifiableTexture(int width, int height) {
	if(!isPowerOfTwo(width) || !isPowerOfTwo(height))
		gdt_fatal(TAG, "ModifiableTexture sizes has to be a power of 2.");

	mWidth = width;
	mHeight = height;

	//mData = new pixel[width*height];		//(pixel *) calloc(width*height, sizeof(pixel));

	mData = (pixel *) calloc(width*height, sizeof(pixel));

	uploadAndCreateTexture();

	sTextures.push_back(this);
}
bool ProgramHeader::verify(){
    if (GET(p_type) == PT_LOAD){
        if (GET(p_filesz) > GET(p_memsz)){
            PRINT_ERROR("File size (%d) may not be greater than memory size (%d) for a loadable segment", GET(p_filesz), GET(p_memsz));
            return false;
        }
    }

    if (!isPowerOfTwo(GET(p_align)) && GET(p_align) != 0){
        PRINT_ERROR("Segment alignment must be 0 or a positive power of 2");
        return false;
    }

    if (GET(p_align) > 1){
        if (GET(p_vaddr) % GET(p_align) != GET(p_offset) % GET(p_align)){
            PRINT_ERROR("Segment(%d) virtual address(%016llx) and offset(%016llx) do not conform to alignment(%016llx)", index, GET(p_vaddr), GET(p_offset), GET(p_align));
            return false;
        }
    }

    if (GET(p_vaddr) % DEFAULT_PAGE_ALIGNMENT != GET(p_paddr) % DEFAULT_PAGE_ALIGNMENT){
        PRINT_ERROR("Physical and virtual address must be congruent mod pagesize for program header %d", index);
        return false;
    }

    return true;
}
PageAllocationAligned PageAllocationAligned::allocate(size_t size, size_t alignment, OSAllocator::Usage usage, bool writable)
{
    ASSERT(isPageAligned(size));
    ASSERT(isPageAligned(alignment));
    ASSERT(isPowerOfTwo(alignment));
    ASSERT(size >= alignment);
    size_t alignmentMask = alignment - 1;

#if OS(DARWIN)
    int flags = VM_FLAGS_ANYWHERE;
    if (usage != OSAllocator::UnknownUsage)
        flags |= usage;
    int protection = PROT_READ;
    if (writable)
        protection |= PROT_WRITE;

    vm_address_t address = 0;
    vm_map(current_task(), &address, size, alignmentMask, flags, MEMORY_OBJECT_NULL, 0, FALSE, protection, PROT_READ | PROT_WRITE, VM_INHERIT_DEFAULT);
    return PageAllocationAligned(reinterpret_cast<void*>(address), size);
#else
    size_t alignmentDelta = alignment - pageSize();

    // Resererve with suffcient additional VM to correctly align.
    size_t reservationSize = size + alignmentDelta;
    void* reservationBase = OSAllocator::reserveUncommitted(reservationSize, usage, writable, false);

    // Select an aligned region within the reservation and commit.
    void* alignedBase = reinterpret_cast<uintptr_t>(reservationBase) & alignmentMask
                        ? reinterpret_cast<void*>((reinterpret_cast<uintptr_t>(reservationBase) & ~alignmentMask) + alignment)
                        : reservationBase;
    OSAllocator::commit(alignedBase, size, writable, false);

    return PageAllocationAligned(alignedBase, size, reservationBase, reservationSize);
#endif
}
Example #7
0
void Texture::resize(const unsigned int _width, const unsigned int _height) {
    m_width = _width;
    m_height = _height;

    if (!(Hardware::supportsTextureNPOT) &&
        !(isPowerOfTwo(m_width) && isPowerOfTwo(m_height)) &&
        (m_generateMipmaps || isRepeatWrapping(m_options.wrapping))) {
        LOGW("OpenGL ES doesn't support texture repeat wrapping for NPOT textures nor mipmap textures");
        LOGW("Falling back to LINEAR Filtering");
        m_options.filtering = {GL_LINEAR, GL_LINEAR};
        m_generateMipmaps = false;
    }

    m_shouldResize = true;
    m_dirtyRanges.clear();
}
Example #8
0
bool FFT::init(UINT fftWindowSize,UINT hopSize,UINT numDimensions,UINT fftWindowFunction,bool computeMagnitude,bool computePhase,DataType inputType,DataType outputType){
    
    //Clear any previous setup
    clear();
    
    if( !isPowerOfTwo(fftWindowSize) ){
        errorLog << "init(UINT fftWindowSize,UINT hopSize,UINT numDimensions,UINT fftWindowFunction,bool computeMagnitude,bool computePhase) - fftWindowSize is not a power of two!" << std::endl;
        return false;
    }
    
    if( !validateFFTWindowFunction( fftWindowFunction ) ){
        errorLog << "init(UINT fftWindowSize,UINT hopSize,UINT numDimensions,UINT fftWindowFunction,bool computeMagnitude,bool computePhase) - Unkown Window Function!" << std::endl;
        return false;
    }
       
    this->dataBufferSize = fftWindowSize;
    this->fftWindowSize = fftWindowSize;
    this->hopSize = hopSize;
    this->fftWindowFunction = fftWindowFunction;
    this->computeMagnitude = computeMagnitude;
    this->computePhase = computePhase;
    this->inputType = inputType;
    this->outputType = outputType;
    hopCounter = 0;
    featureDataReady = false;
    numInputDimensions = numDimensions;
    
    //Set the output size, the fftWindowSize is divided by 2 because the FFT is symmetrical so only half the actual FFT is returned
    numOutputDimensions = 0;
    if( computePhase ) numOutputDimensions += fftWindowSize/2 * numInputDimensions;
    if( computeMagnitude ) numOutputDimensions += fftWindowSize/2 * numInputDimensions;
    
    //Resize the output feature vector
    featureVector.resize( numOutputDimensions, 0);

    dataBuffer.resize( dataBufferSize );
    tempBuffer.resize( dataBufferSize );

    for(UINT i=0; i<dataBufferSize; i++){
        dataBuffer[i].resize( numInputDimensions, 0 );
    }

    for(UINT i=0; i<dataBufferSize; i++){
        dataBuffer[i].resize( numInputDimensions, 0 );
    }

    //Setup the fft for each dimension
    fft.resize(numInputDimensions);
    for(unsigned int i=0; i<numInputDimensions; i++){
        if( !fft[i].init(fftWindowSize,fftWindowFunction,computeMagnitude,computePhase) ){
            errorLog << "init(UINT fftWindowSize,UINT hopSize,UINT numDimensions,UINT fftWindowFunction,bool computeMagnitude,bool computePhase) - Failed to initialize fft!" << std::endl;
            clear();
            return false;
        }
    }
    
    initialized = true;

    return true;
}
bool howPartition( int rLen, int maxNumThread, int* info )
{
	int maxNumElePerBlock = maxNumThread*2;
	int numBlock = (int)ceil((float)rLen/(maxNumElePerBlock));
	bool isMul = (rLen%maxNumElePerBlock == 0)?true:false;

	if( isMul )
	{
		info[0] = numBlock;
		info[1] = maxNumThread;
	}
	else
	{
		info[0] = numBlock - 1;

		int remainer = rLen - (numBlock - 1)*maxNumElePerBlock;
		if( isPowerOfTwo(remainer) )
		{
			info[1] = remainer/2;
		}
		else
		{
			info[1] = floorPow2( remainer );
		}
	}

	return isMul;
}
Example #10
0
 bool isPowerOfTwo(int n) {
     if(n==1) return true;
     if(n==0) return false;
     int res = n % 2;
     if(res==0) return isPowerOfTwo(n/2);
     else return false;
 }
int
main(int argc, char* argv[])
{
    output = fopen("final", "wb");

    argc--;
    path = malloc(MAX_PATH * sizeof(char));
    isMaster = 1;

    //only works with number of files that are a power of two!
    if(!isPowerOfTwo(argc))
    {
        printf("# of args(%i) not power of 2\n", argc);
        return 0;
    }

    filenames = malloc(sizeof(char*) * argc);
    //stores files into global array
    for(int i = 0; i < argc; i++)
    {
        filenames[i] = argv[i + 1];
    }

    //number of levels in the tree, discluding the master node
    max_levels = (int)(log(argc) / log(2));
    spawnChildren(max_levels);

    free(filenames);
    fclose(output);
    sleep(1);
    return 0;
}
Example #12
0
LargeObject FreeList::take(Owner owner, size_t alignment, size_t size, size_t unalignedSize)
{
    BASSERT(isPowerOfTwo(alignment));
    size_t alignmentMask = alignment - 1;

    LargeObject candidate;
    size_t candidateIndex;
    size_t begin = m_vector.size() > freeListSearchDepth ? m_vector.size() - freeListSearchDepth : 0;
    for (size_t i = begin; i < m_vector.size(); ++i) {
        LargeObject largeObject(LargeObject::DoNotValidate, m_vector[i].begin());
        if (!largeObject.isValidAndFree(owner, m_vector[i].size())) {
            m_vector.pop(i--);
            continue;
        }

        if (largeObject.size() < size)
            continue;

        if (test(largeObject.begin(), alignmentMask) && largeObject.size() < unalignedSize)
            continue;

        if (!!candidate && candidate.begin() < largeObject.begin())
            continue;

        candidate = largeObject;
        candidateIndex = i;
    }
    
    if (!!candidate)
        m_vector.pop(candidateIndex);
    return candidate;
}
Example #13
0
int main(void) {
int count,i,ans;
long long int a, q,z;
char dummy;
	    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
scanf("%d",&count);
for(i=1;i<=count;i++)
{
scanf("%lld%c%lld",&a,&dummy,&q);
z=gcd(a,q);
a=a/z;
q=q/z;
if(isPowerOfTwo(q))
{
// power= log10(q)/log10(2);
// printf("%d\n",power);
// if(((float)a/q)>1/2.0)
// {
// printf("Case #%d: %d\n",i,power);
// }
// else
// printf("Case #%d: %d\n",i,power+1);
ans=rec(a,q);
printf("Case #%d: %d\n",i,ans);

}
else
printf("Case #%d: impossible\n",i);	}
return 0;
}
Example #14
0
void* Heap::allocateLarge(std::lock_guard<StaticMutex>& lock, size_t alignment, size_t size, size_t unalignedSize)
{
    BASSERT(size <= largeMax);
    BASSERT(size >= largeMin);
    BASSERT(size == roundUpToMultipleOf<largeAlignment>(size));
    BASSERT(unalignedSize <= largeMax);
    BASSERT(unalignedSize >= largeMin);
    BASSERT(unalignedSize == roundUpToMultipleOf<largeAlignment>(unalignedSize));
    BASSERT(alignment <= largeChunkSize / 2);
    BASSERT(alignment >= largeAlignment);
    BASSERT(isPowerOfTwo(alignment));

    LargeObject largeObject = m_largeObjects.take(alignment, size, unalignedSize);
    if (!largeObject) {
        m_isAllocatingPages = true;
        largeObject = m_vmHeap.allocateLargeObject(alignment, size, unalignedSize);
    }

    size_t alignmentMask = alignment - 1;
    if (test(largeObject.begin(), alignmentMask)) {
        size_t prefixSize = roundUpToMultipleOf(alignment, largeObject.begin() + largeMin) - largeObject.begin();
        std::pair<LargeObject, LargeObject> pair = largeObject.split(prefixSize);
        m_largeObjects.insert(pair.first);
        largeObject = pair.second;
    }

    return allocateLarge(lock, largeObject, size);
}
Example #15
0
size_t pageSize()
{
    if (!s_pageSize)
        s_pageSize = systemPageSize();
    ASSERT(isPowerOfTwo(s_pageSize));
    return s_pageSize;
}
Example #16
0
void MFNHashTypePlain::createArbitraryBitmap(uint8_t startWord,
        std::vector<std::vector<uint8_t> > &hashList, std::vector<uint8_t> &bitmap,
        uint32_t bitmapSizeBytes) {

    uint32_t bitmapIndex;
    uint8_t  bitmapByte;
    uint64_t passwordIndex;
    uint32_t bitmapMask;

    if (!isPowerOfTwo(bitmapSizeBytes)) {
        printf("Error!  Bitmap size not a power of 2!\n");
        exit(1);
    }

    // Set the bitmap mask - size - 1 for and masking.
    bitmapMask = (bitmapSizeBytes - 1);

    // Step 1: Set the vector to whatever is specified.
    bitmap.resize(bitmapSizeBytes);
    // Step 2: Clear the vector
    memset(&bitmap[0], 0, bitmapSizeBytes);


    for (passwordIndex = 0; passwordIndex < hashList.size(); passwordIndex++) {
        if (this->HashIsBigEndian) {
            // Big endian hash - read in as a big endian value
            bitmapIndex =
                    ((uint32_t)hashList.at(passwordIndex).at((startWord * 4) + 0) << 24) +
                    ((uint32_t)hashList.at(passwordIndex).at((startWord * 4) + 1) << 16) +
                    ((uint32_t)hashList.at(passwordIndex).at((startWord * 4) + 2) <<  8) +
                    ((uint32_t)hashList.at(passwordIndex).at((startWord * 4) + 3) <<  0);
        } else {
            // Little endian hash - take bytes 0 & 1 in the word as the low value (swapped).
            bitmapIndex =
                    ((uint32_t)hashList.at(passwordIndex).at((startWord * 4) + 0) <<  0) +
                    ((uint32_t)hashList.at(passwordIndex).at((startWord * 4) + 1) <<  8) +
                    ((uint32_t)hashList.at(passwordIndex).at((startWord * 4) + 2) << 16) +
                    ((uint32_t)hashList.at(passwordIndex).at((startWord * 4) + 3) << 24);
        }
        //printf("bitmapIndex: %08x\n", bitmapIndex);

        // Set the byte by shifting left by the lower 3 bits in the index
        bitmapByte = 0x01 << (bitmapIndex & 0x0007);
        // Determine the byte offset by shifting right 3 bits.
        bitmapIndex = bitmapIndex >> 3;
        // Mask off the lower 27 bits
        bitmapIndex &= bitmapMask;

        //printf("bitmapByte: %02x\n", bitmapByte);
        //printf("bitmapIndex: %08x\n", bitmapIndex);

        if (bitmapIndex >= bitmapSizeBytes) {
            printf("FATAL ERROR: Bitmap index beyond bound of bitmap!\n");
            exit(1);
        }

        // Add the bit into the bitmap
        bitmap[bitmapIndex] |= bitmapByte;
    }
}
int main(void){
	int test = 38; //whatever you like
	bool result = isPowerOfTwo(test);
	printf("%d\n",result);

	return 0;
}
Example #18
0
bool canUseMipmaps(const QSize &size)
{
    static bool initialized = false;
    static bool supportsNonPowerOfTwoMipmaps = true;
    if (!initialized) {
        printf("VENDOR string: %s\n", glGetString(GL_VENDOR));
        printf("RENDERER string: %s\n", glGetString(GL_RENDERER));

        supportsNonPowerOfTwoMipmaps = !QByteArray(reinterpret_cast<const char *>(glGetString(GL_RENDERER))).contains("Tegra 3");
        initialized = true;

        printf("Supports non-power-of-two mipmaps: %d\n", int(supportsNonPowerOfTwoMipmaps));
    }

    return supportsNonPowerOfTwoMipmaps || (isPowerOfTwo(size.width()) && isPowerOfTwo(size.height()));
}
Example #19
0
//-----------------------------------------------------------------------------
UserSuppliedHeapBuffer* UserSuppliedHeapBuffer_Alloc( int bufSize, int alignment )
//-----------------------------------------------------------------------------
{
    UserSuppliedHeapBuffer* p = ( UserSuppliedHeapBuffer* )calloc( 1, sizeof( UserSuppliedHeapBuffer ) );
    p->bufSize_ = bufSize;
    p->alignment_ = alignment;
    if( bufSize > 0 )
    {
        assert( isPowerOfTwo( alignment ) );
        p->pBuf_ = ( char* )calloc( 1, bufSize + alignment );
#if defined(_MSC_VER) && (_MSC_VER < 1400) // is older then Microsoft VS 2005 compiler?
        p->pBufAligned_ = ( char* )( ( ( ( UINT_PTR )( p->pBuf_ ) + alignment - 1 ) & ( UINT_MAX - ( alignment - 1 ) ) ) );
#elif defined(_WIN32) && defined(__BORLANDC__) // is Borland C++ Builder?
        p->pBufAligned_ = ( char* )( ( ( ( UINT_PTR )( p->pBuf_ ) + alignment - 1 ) & ( UINT_MAX - ( alignment - 1 ) ) ) );
#else
        p->pBufAligned_ = ( char* )( ( ( ( UINT_PTR )( p->pBuf_ ) + alignment - 1 ) & ( SIZE_MAX - ( alignment - 1 ) ) ) );
#endif // #if defined(_MSC_VER) && (_MSC_VER < 1300) // is 'old' Microsoft VC6 compiler?
    }
    else
    {
        p->pBuf_ = 0;
        p->pBufAligned_ = 0;
    }
    p->pNext_ = 0;
    p->pPrev_ = 0;
    return p;
}
Example #20
0
void global_sum(double* result, int rank, int size, double my_value){
	// error checking code
	if(!isPowerOfTwo(size)){
		printf("The number of processors must be power of 2!\n");
		MPI_Finalize();
		exit(1);
	}

	double recvbuf;

	MPI_Status status;

	*result=my_value; // add my_value to result

	while(0!=(size=size/2)){
		if(rank%(size*2)<size){
			MPI_Sendrecv(result, 1, MPI_DOUBLE, rank+size, size, &recvbuf, 1, MPI_DOUBLE, rank+size, size, MPI_COMM_WORLD, &status);
		} else {
			MPI_Sendrecv(result, 1, MPI_DOUBLE, rank-size, size, &recvbuf, 1, MPI_DOUBLE, rank-size, size, MPI_COMM_WORLD, &status);
		}

		*result+=recvbuf;
	}
	return;
}
Example #21
0
UnlockQueue::UnlockQueue(unsigned int size)
    : m_size(size)
{
    if (!isPowerOfTwo(size))
    {
        m_size = roundupPowerOfTwo(size);
    }
}
Example #22
0
static void		initTexture(const char* filename)
{
  FILE* imageFile;
  int lat, lon;
  unsigned char buffer[4];
  unsigned char* image;
  int dx, dy;

  /* initialize texture coordinates */
  for (lat = 0; lat <= LAT_GRID; lat++) {
    const float y = (float)lat / (float)LAT_GRID;
    for (lon = 0; lon <= LON_GRID; lon++) {
      uv[lat][lon][0] = (float)lon / (float)LON_GRID;
      uv[lat][lon][1] = y;
    }
  }

  /* open image file */
  imageFile = fopen(filename, "rb");
  if (!imageFile) {
    fprintf(stderr, "cannot open image file %s for reading\n", filename);
    exit(1);
  }

  /* read image size */
  fread(buffer, 1, 4, imageFile);
  dx = (int)((buffer[0] << 8) | buffer[1]);
  dy = (int)((buffer[2] << 8) | buffer[3]);
  if (!isPowerOfTwo(dx) || !isPowerOfTwo(dy)) {
    fprintf(stderr, "image %s has an illegal size: %dx%d\n", filename, dx, dy);
    exit(1);
  }

  /* read image */
  image = (unsigned char*)malloc(3 * dx * dy * sizeof(unsigned char));
  fread(image, 3 * dx, dy, imageFile);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_2D, 0, 3, dx, dy, 0,
		GL_RGB, GL_UNSIGNED_BYTE, image);

  /* tidy up */
  free(image);
  fclose(imageFile);
}
Example #23
0
int Mymain()
{
    vector<int> nums = {0, 1, 65536, 93728, 32, 999, -3893};
    cout << std::boolalpha;
    for (int i : nums){
        cout << i << ": \t" << isPowerOfTwo(i) << endl;
    }
}
Example #24
0
int
MathUtilities::nearestPowerOfTwo(int x)
{
    if (isPowerOfTwo(x)) return x;
    int n0 = previousPowerOfTwo(x), n1 = nextPowerOfTwo(x);
    if (x - n0 < n1 - x) return n0;
    else return n1;
}
Example #25
0
int main(int argc, char **argv)
{
	int n;
	while (scanf("%d", &n) != EOF) {
		printf("%d\n", isPowerOfTwo(n));
	}
	return 0;
}
Example #26
0
int
MathUtilities::nextPowerOfTwo(int x)
{
    if (isPowerOfTwo(x)) return x;
    if (x < 1) return 1;
    int n = 1;
    while (x) { x >>= 1; n <<= 1; }
    return n;
}
Example #27
0
int main()
{
	int N;
	scanf("%d",N);
	if(isPowerOfTwo(N))
		printf("Yes\n",N);
	else
		printf("No\n");
}
int main() {
	int num;
	int a;
	while (1) {
		scanf("%d", &num);
		a = isPowerOfTwo(num);
		printf("%d\n", a);
	}
}
Example #29
0
void ContentLayerChromium::updateTextureRect(void* pixels, const IntSize& bitmapSize,
    const IntSize& requiredTextureSize, const IntRect& updateRect, unsigned textureId, MipmapUse requestMipmap)
{
    if (!pixels)
        return;

    GraphicsContext3D* context = layerRendererContext();
    context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId);

    bool generateMipmap = (requestMipmap == useMipmap)
                          && (layerRenderer()->contentLayerSharedValues()->npotSupported()
                              || (isPowerOfTwo(updateRect.width()) && isPowerOfTwo(updateRect.height())));

    // If the texture id or size changed since last time then we need to tell GL
    // to re-allocate a texture.
    if (m_contentsTexture != textureId || requiredTextureSize != m_allocatedTextureSize) {
        ASSERT(bitmapSize == requiredTextureSize);
        GLC(context, context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, requiredTextureSize.width(), requiredTextureSize.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels));
        if (generateMipmap) {
            GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER,
                GraphicsContext3D::LINEAR_MIPMAP_LINEAR));
            GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER,
                GraphicsContext3D::LINEAR));
        } else {
            GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER,
                 GraphicsContext3D::LINEAR));
            GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER,
                GraphicsContext3D::LINEAR));
        }

        m_contentsTexture = textureId;
        m_allocatedTextureSize = requiredTextureSize;
    } else {
        ASSERT(updateRect.width() <= m_allocatedTextureSize.width() && updateRect.height() <= m_allocatedTextureSize.height());
        ASSERT(updateRect.width() == bitmapSize.width() && updateRect.height() == bitmapSize.height());
        GLC(context, context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels));
    }

    if (generateMipmap)
        GLC(context, context->generateMipmap(GraphicsContext3D::TEXTURE_2D));

    m_dirtyRect.setSize(FloatSize());
    m_contentsDirty = false;
}
Example #30
0
bool checkCompatibility( const Vector3ui& volumeDim,
                         const Vector3ui& blockSize )
{
    if( volumeDim.x() % blockSize.x() )
        return false;
    if( volumeDim.y() % blockSize.y() )
        return false;
    if( volumeDim.z() % blockSize.z() )
        return false;

    if( !isPowerOfTwo( volumeDim.x() / blockSize.x() ) )
        return false;
    if( !isPowerOfTwo( volumeDim.y() / blockSize.y() ) )
        return false;
    if( !isPowerOfTwo( volumeDim.z() / blockSize.z() ) )
        return false;

    return true;
}