示例#1
0
void TextureManager::requestBundle(Node* forNode) {
  if (forNode->hasBundleName()) {
    for (int i = 0; i < 6; i++) {
      std::vector<int> arrayOfCoordinates;
      // We ensure the texture is properly stretched, so we take the default cube size
      // TODO: This setting should be obtained from the Config class
      int coords[] = {0, 0, kDefTexSize, 0, kDefTexSize, kDefTexSize, 0, kDefTexSize};
      unsigned arraySize = sizeof(coords) / sizeof(int);
      
      arrayOfCoordinates.assign(coords, coords + arraySize);
      Spot* spot = new Spot(arrayOfCoordinates, i, kSpotClass);
      Texture* texture = new Texture;
      
      spot->setTexture(texture);
      spot->texture()->setIndexInBundle(i);
      
      // In this case, the filename is generated from the name
      // of the texture
      spot->texture()->setName(forNode->bundleName().c_str());
      
      registerTexture(spot->texture());
      
      forNode->addSpot(spot);
    }
  }
  
  // Possibly raise an error if this fails
}
示例#2
0
 void TextureManager::init()
 {
     m_DefaultTexture = registerTexture("DEFAULT_TEXTURE");
     rendering::Image img;
     img.loadFromFile("default.png");
     m_DefaultTexture->load(img);
 }
示例#3
0
void 
Surface::setTextureMap(const GFXBitmap* in_pTexture)
{
   // Because we are queueing all polys, we need to map this call into a
   //  registerTexture call with the handle cache...
   //
   AssertFatal(pTextureCache != NULL, "Error, surface not locked...");
   AssertFatal(pHandleCache != NULL, "Error, surface not locked...");

   GFXTextureHandle texHandle;
   texHandle.key[0] = DWORD(in_pTexture);
   texHandle.key[1] = 0;

   if (_pHandleCache->setTextureHandle(texHandle) == true) {
      // already registered, and now it's set...
      //
      return;
   }
  
   // Otherwise, we need to register the texture, which will also leave it
   //  set as the curreny texture...
   //
   registerTexture(texHandle,
                   in_pTexture->getWidth(), in_pTexture->getHeight(),
                   0, 0,
                   0, NULL,
                   in_pTexture, 1);
}
示例#4
0
//----------------------------------------------------------
ofTexture::ofTexture(const ofTexture & mom){
	anchor = mom.anchor;
	bAnchorIsPct = mom.bAnchorIsPct;
	texData = mom.texData;
	bWantsMipmap = mom.bWantsMipmap;
	retain(texData.textureID);
#ifdef TARGET_ANDROID
	registerTexture(this);
#endif
}
int TinyRendererVisualShapeConverter::loadTextureFile(const char* filename)
{
    int width,height,n;
    unsigned char* image=0;
    image = stbi_load(filename, &width, &height, &n, 3);
    if (image && (width>=0) && (height>=0))
    {
        return registerTexture(image, width, height);
    }
    return -1;
}
示例#6
0
ofTexture::ofTexture(ofTexture && mom){
    anchor = mom.anchor;
    bAnchorIsPct = mom.bAnchorIsPct;
    texData = mom.texData;
    bWantsMipmap = mom.bWantsMipmap;
    mom.texData.bAllocated = 0;
    mom.texData.textureID = 0;
#ifdef TARGET_ANDROID
    registerTexture(this);
#endif
}
示例#7
0
 void TextureManager::loadTextureFromFileAsync(const std::string &name, const std::string &filename, core::TaskStatus *status)
 {
     m_Device->getTaskScheduler()->getThreadPool().enqueue([=](){
         // In thread
         Image *image = new Image();
         image->loadFromFile(filename);
         if(image->isValid()) {
             m_Device->getTaskScheduler()->scheduleTask(NORMAL_PRIORITY, [=](){
                 // In main thread
                 Texture *texture = registerTexture(name);
                 texture->load(*image);
                 delete image;
             }, status);
         }
     });
 }
示例#8
0
void ofTexture::allocate(const ofTextureData & textureData, int glFormat, int pixelType){
#ifndef TARGET_OPENGLES
	if(texData.textureTarget == GL_TEXTURE_2D || texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB){
#else
	if(texData.textureTarget == GL_TEXTURE_2D){
#endif
		if( textureData.width <= 0.0 || textureData.height <= 0.0 ){
			ofLogError("ofTexture") << "allocate(): ofTextureData has 0 width and/or height: " << textureData.width << "x" << textureData.height;
			return;
		}
	}

	texData = textureData;
	//our graphics card might not support arb so we have to see if it is supported.
#ifndef TARGET_OPENGLES
	if( texData.textureTarget==GL_TEXTURE_RECTANGLE_ARB && ofGLSupportsNPOTTextures() ){
		texData.tex_w = texData.width;
		texData.tex_h = texData.height;
		texData.tex_t = texData.width;
		texData.tex_u = texData.height;
	}else if(texData.textureTarget == GL_TEXTURE_2D)
#endif
	{
		if(ofGLSupportsNPOTTextures()){
			texData.tex_w = texData.width;
			texData.tex_h = texData.height;
		}else{
			//otherwise we need to calculate the next power of 2 for the requested dimensions
			//ie (320x240) becomes (512x256)
			texData.tex_w = ofNextPow2(texData.width);
			texData.tex_h = ofNextPow2(texData.height);
		}

		texData.tex_t = texData.width / texData.tex_w;
		texData.tex_u = texData.height / texData.tex_h;
	}

	// attempt to free the previous bound texture, if we can:
	clear();

	glGenTextures(1, (GLuint *)&texData.textureID);   // could be more then one, but for now, just one
	retain(texData.textureID);

#ifndef TARGET_OPENGLES
	if(texData.textureTarget == GL_TEXTURE_2D || texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB){
#else
	if(texData.textureTarget == GL_TEXTURE_2D){
#endif
		glBindTexture(texData.textureTarget,texData.textureID);
		glTexImage2D(texData.textureTarget, 0, texData.glInternalFormat, (GLint)texData.tex_w, (GLint)texData.tex_h, 0, glFormat, pixelType, 0);  // init to black...

		glTexParameterf(texData.textureTarget, GL_TEXTURE_MAG_FILTER, texData.magFilter);
		glTexParameterf(texData.textureTarget, GL_TEXTURE_MIN_FILTER, texData.minFilter);
		glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_S, texData.wrapModeHorizontal);
		glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_T, texData.wrapModeVertical);

		#ifndef TARGET_PROGRAMMABLE_GL
			if (!ofIsGLProgrammableRenderer()){
				glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			}
		#endif
		glBindTexture(texData.textureTarget,0);
	}

	texData.bAllocated = true;

#ifdef TARGET_ANDROID
	registerTexture(this);
#endif
}


void ofTexture::setRGToRGBASwizzles(bool rToRGBSwizzles){
#ifndef TARGET_OPENGLES
	glBindTexture(texData.textureTarget,texData.textureID);
	if(rToRGBSwizzles){
		if(texData.glInternalFormat==GL_R8 ||
				texData.glInternalFormat==GL_R16 ||
				texData.glInternalFormat==GL_R32F){
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_R, GL_RED);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_G, GL_RED);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_B, GL_RED);

		}else if(texData.glInternalFormat==GL_RG8 ||
				texData.glInternalFormat==GL_RG16 ||
				texData.glInternalFormat==GL_RG32F){
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_R, GL_RED);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_G, GL_RED);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_B, GL_RED);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_A, GL_GREEN);
		}
	}else{
		if(texData.glInternalFormat==GL_R8 ||
				texData.glInternalFormat==GL_R16 ||
				texData.glInternalFormat==GL_R32F){
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_R, GL_RED);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_B, GL_BLUE);

		}else if(texData.glInternalFormat==GL_RG8 ||
				texData.glInternalFormat==GL_RG16 ||
				texData.glInternalFormat==GL_RG32F){
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_R, GL_RED);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
			 glTexParameteri(texData.textureTarget, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
		}
	}
	glBindTexture(texData.textureTarget,0);
#endif
}

void ofTexture::setSwizzle(GLenum srcSwizzle, GLenum dstChannel){
#ifndef TARGET_OPENGLES
	glBindTexture(texData.textureTarget,texData.textureID);
	glTexParameteri(texData.textureTarget, srcSwizzle, dstChannel);
	glBindTexture(texData.textureTarget,0);
#endif
}