Esempio n. 1
0
TextureID ResourceManagerImpl::new_texture_from_file(const unicode& path) {
    //Load the texture
    auto tex = texture(new_texture());
    window().loader_for(path.encode())->into(*tex);
    tex->upload(false, true, true, false);
    return tex->id();
}
Esempio n. 2
0
bool ResourceManagerImpl::init() {
    //FIXME: Should lock the default texture and material during construction!

    //Create the default blank texture
    default_texture_id_ = new_texture(false);

    auto tex = texture(default_texture_id_);

    tex->resize(1, 1);
    tex->set_bpp(32);

    tex->data()[0] = 255;
    tex->data()[1] = 255;
    tex->data()[2] = 255;
    tex->data()[3] = 255;
    tex->upload();

    //Maintain ref-count
    default_material_id_ = new_material_from_file(default_material_filename(), false);

    //Set the default material's first texture to the default (white) texture
    material(default_material_id_)->pass(0).set_texture_unit(0, default_texture_id_);

    return true;
}
Esempio n. 3
0
int                     build_black(t_conf *conf, SDL_Surface *screen)
{
  SDL_Surface           *img;

  if ((img = new_texture(BLACK)) == NULL)
    return (EXIT_FAILURE);
  if (put_img_on_screen(img, screen, conf) == EXIT_FAILURE)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}
Esempio n. 4
0
int			build_hero_l(t_conf *conf, SDL_Surface *screen)
{
  SDL_Surface		*img;

  if ((img = new_texture(PATHHEROL)) == NULL)
    return (EXIT_FAILURE);
  if (put_img_on_screen(img, screen, conf) == EXIT_FAILURE)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}
Esempio n. 5
0
	std::shared_ptr< sf::Texture > Engine::GetTexture( std::string Filename ) {
		if( m_textures.find( Filename ) == m_textures.end() ) {
			std::shared_ptr< sf::Texture > new_texture( new sf::Texture );
			if( !new_texture->LoadFromFile( Filename ) ) {
				return std::shared_ptr< sf::Texture >( nullptr );
			}
			m_textures[ Filename ] = new_texture;
		}
		return m_textures[ Filename ];
	}
Esempio n. 6
0
TextureID ResourceManagerImpl::new_texture_with_alias(const unicode& alias, bool garbage_collect) {
    TextureID t = new_texture(garbage_collect);
    try {
        TextureManager::manager_store_alias(alias, t);
    } catch(...) {
        delete_texture(t);
        throw;
    }
    return t;
}
Esempio n. 7
0
TextureID ResourceManagerImpl::new_texture_from_file(const unicode& path, TextureFlags flags, bool garbage_collect) {
    //Load the texture
    auto tex = texture(new_texture(garbage_collect));
    window->loader_for("texture", path.encode())->into(tex);

    if((flags & TEXTURE_OPTION_FLIP_VERTICALLY) == TEXTURE_OPTION_FLIP_VERTICALLY) {
        tex->flip_vertically();
    }

    tex->upload(
        false,
        (flags & TEXTURE_OPTION_DISABLE_MIPMAPS) != TEXTURE_OPTION_DISABLE_MIPMAPS,
        (flags & TEXTURE_OPTION_CLAMP_TO_EDGE) != TEXTURE_OPTION_CLAMP_TO_EDGE,
        (flags & TEXTURE_OPTION_NEAREST_FILTER) != TEXTURE_OPTION_NEAREST_FILTER
    );

    mark_texture_as_uncollected(tex->id());
    return tex->id();
}
Esempio n. 8
0
Texture *LoadFile(char *fname)
{
  Texture           *texture;

  FBM image;
  int colors;
  image.bm=NULL;
  image.cm=NULL;
  
  
  read_bitmap(&image,fname);
   
  printf("LoadFile %s : %d x %d x %d\n",
	 fname,
	 image.hdr.cols,image.hdr.rows,image.hdr.bits);
  printf("aspect=%g\n",image.hdr.aspect);
  colors=1<<image.hdr.bits;
  
  texture = new_texture( image.hdr.cols/8,image.hdr.rows);
  memcpy(texture->texels,image.bm,image.hdr.cols/8*image.hdr.rows);
  return texture;
}
Esempio n. 9
0
void quake3_bsp_map::convert_and_load_textures() {
    typedef vector<quake3_texture>::iterator quake3_texture_iterator;

    vector<string> extensions;
    extensions.push_back(".tga");
    extensions.push_back(".jpg");

    m_textures.resize(m_raw_texture_data.size());

    int i = 0;
    for (quake3_texture_iterator texture = m_raw_texture_data.begin();
            texture != m_raw_texture_data.end(); ++texture) {

        string filename_to_check = (*texture).file;
        //We search the listed extensions above to find an available file,
        //If the file is not available loading will fail (it will look for a file
        //without an extension). This is fine.
        for (vector<string>::const_iterator ext = extensions.begin();
                ext != extensions.end(); ++ext) {

            if (get_owning_resource_manager()->is_file_available(filename_to_check + (*ext))) {
                filename_to_check += (*ext);
                break;
            }
        }
        shared_ptr<boost::mutex> new_mutex(new boost::mutex());
        shared_ptr<resource_interface> new_texture(new devil_texture());

        //Load the textures asynchronously
        resource_id id = get_owning_resource_manager()->queue_file_for_loading(
                             filename_to_check, new_texture, new_mutex);

        m_textures[i++].set_resource_id(id);
        //TODO: copy other texture stuff across
    }
}
Esempio n. 10
0
Texture *
LoadGIF(FILE *fp, char *fname )
{
  Texture           *texture;
  int                filesize, numcols;
  register unsigned  char ch, ch1;
  register byte     *ptr, *ptr1;
  register int   i;

  BitOffset=0;
  XC=0;
  YC=0;
  Pass=0;
  
  /* find the size of the file */
  fseek(fp, 0L, 2);
  filesize = ftell(fp);
  fseek(fp, 0L, 0);

  if (!(ptr = RawGIF = (byte *) malloc(filesize)))
    fatal_error("not enough memory to read gif file");

  if (!(Raster = (byte *) malloc(filesize))) {
    free( ptr );
    fatal_error("not enough memory to read gif file");
  }

  if (fread(ptr, filesize, 1, fp) != 1)
    fatal_error("GIF data read failed");
  
  if (strncmp(ptr, id, 6))
    fatal_error("not a GIF file");

  ptr += 6;

/* Get variables from the GIF screen descriptor */

  ch           = NEXTBYTE;
  RWidth       = ch + 0x100 * NEXTBYTE; /* screen dimensions... not used. */
  ch           = NEXTBYTE;
  RHeight      = ch + 0x100 * NEXTBYTE;

  if (Verbose)
    fprintf(stderr, "screen dims: %dx%d.\n", RWidth, RHeight);

  ch           = NEXTBYTE;
  HasColormap  = ((ch & COLORMAPMASK) ? True : False);

  BitsPerPixel = (ch & 7) + 1;
  numcols      = ColorMapSize = 1 << BitsPerPixel;
  BitMask      = ColorMapSize - 1;

  printf("ColorMapSize = %d\n",ColorMapSize);
  
  Background   = NEXTBYTE;		/* background color... not used. */
  
  if (NEXTBYTE)		/* supposed to be NULL */
    fatal_error("corrupt GIF file (bad screen descriptor)");

/* Read in global colormap. */

  if (HasColormap) {
    if (Verbose)
      fprintf(stderr, "%s is %dx%d, %d bits per pixel, (%d colors).\n",
	      fname, RWidth,RHeight,BitsPerPixel, ColorMapSize);

    for (i = 0; i < ColorMapSize; i++) {
      Red[i]   = NEXTBYTE;
      Green[i] = NEXTBYTE;
      Blue[i]  = NEXTBYTE;
      used[i]  = 0;
    }

    numused = 0;
  } /* else no colormap in GIF file */

/* Check for image seperator */

  if (NEXTBYTE != IMAGESEP)
    fatal_error("corrupt GIF file (no image separator)");

/* Now read in values from the image descriptor */

  ch        = NEXTBYTE;
  LeftOfs   = ch + 0x100 * NEXTBYTE;
  ch        = NEXTBYTE;
  TopOfs    = ch + 0x100 * NEXTBYTE;
  ch        = NEXTBYTE;
  Width     = ch + 0x100 * NEXTBYTE;
  ch        = NEXTBYTE;
  Height    = ch + 0x100 * NEXTBYTE;
  Interlace = ((NEXTBYTE & INTERLACEMASK) ? True : False);

  if (Verbose)
    fprintf(stderr, "Reading a %d by %d %sinterlaced image...",
	    Width, Height, (Interlace) ? "" : "non-");

  texture = new_texture( Width, Height );

/* Note that I ignore the possible existence of a local color map.
 * I'm told there aren't many files around that use them, and the spec
 * says it's defined for future use.  This could lead to an error
 * reading some files. 
 */

/* Start reading the raster data. First we get the intial code size
 * and compute decompressor constant values, based on this code size.
 */

    CodeSize  = NEXTBYTE;
    ClearCode = (1 << CodeSize);
    EOFCode   = ClearCode + 1;
    FreeCode  = FirstFree = ClearCode + 2;

/* The GIF spec has it that the code size is the code size used to
 * compute the above values is the code size given in the file, but the
 * code size used in compression/decompression is the code size given in
 * the file plus one. (thus the ++).
 */

    CodeSize++;
    InitCodeSize = CodeSize;
    MaxCode      = (1 << CodeSize);
    ReadMask     = MaxCode - 1;

/* Read the raster data.  Here we just transpose it from the GIF array
 * to the Raster array, turning it from a series of blocks into one long
 * data stream, which makes life much easier for ReadCode().
 */

    ptr1 = Raster;
    do {
	ch = ch1 = NEXTBYTE;
	while (ch--) *ptr1++ = NEXTBYTE;
	if ((ptr - Raster) > filesize)
	    fatal_error("corrupt GIF file (unblock)");
    } while(ch1);

    free(RawGIF);		/* We're done with the raw data now... */

    if (Verbose) {
	fprintf(stderr, "done.\n");
	fprintf(stderr, "Decompressing...");
    }

    Image               = texture->texels;
    BytesPerScanline    = Width;


/* Decompress the file, continuing until you see the GIF EOF code.
 * One obvious enhancement is to add checking for corrupt files here.
 */

    Code = ReadCode();
    while (Code != EOFCode) {

/* Clear code sets everything back to its initial value, then reads the
 * immediately subsequent code as uncompressed data.
 */

	if (Code == ClearCode) {
	    CodeSize = InitCodeSize;
	    MaxCode  = (1 << CodeSize);
	    ReadMask = MaxCode - 1;
	    FreeCode = FirstFree;
	    CurCode  = OldCode = Code = ReadCode();
	    FinChar  = CurCode & BitMask;
	    AddToPixel(FinChar);
	}
	else {

/* If not a clear code, then must be data: save same as CurCode and InCode */

	    CurCode = InCode = Code;

/* If greater or equal to FreeCode, not in the hash table yet;
 * repeat the last character decoded
 */

	    if (CurCode >= FreeCode) {
		CurCode = OldCode;
		OutCode[OutCount++] = FinChar;
	    }

/* Unless this code is raw data, pursue the chain pointed to by CurCode
 * through the hash table to its end; each code in the chain puts its
 * associated output code on the output queue.
 */

	    while (CurCode > BitMask) {
		if (OutCount > 1024) {
		    fprintf(stderr,"\nCorrupt GIF file (OutCount)!\n");
                    exit(1);  /* calling 'exit(-1)' dumps core, so I don't */
                    }
		OutCode[OutCount++] = Suffix[CurCode];
		CurCode = Prefix[CurCode];
	    }

/* The last code in the chain is treated as raw data. */

	    FinChar             = CurCode & BitMask;
	    OutCode[OutCount++] = FinChar;

/* Now we put the data out to the Output routine.
 * It's been stacked LIFO, so deal with it that way...
 */

	    for (i = OutCount - 1; i >= 0; i--)
		AddToPixel(OutCode[i]);
	    OutCount = 0;

/* Build the hash table on-the-fly. No table is stored in the file. */

	    Prefix[FreeCode] = OldCode;
	    Suffix[FreeCode] = FinChar;
	    OldCode          = InCode;

/* Point to the next slot in the table.  If we exceed the current
 * MaxCode value, increment the code size unless it's already 12.  If it
 * is, do nothing: the next code decompressed better be CLEAR
 */

	    FreeCode++;
	    if (FreeCode >= MaxCode) {
		if (CodeSize < 12) {
		    CodeSize++;
		    MaxCode *= 2;
		    ReadMask = (1 << CodeSize) - 1;
		}
	    }
	}
	Code = ReadCode();
    }

    free(Raster);

    if (Verbose)
	fprintf(stderr, "done.\n");
    else
        fprintf(stderr,"(of which %d are used)\n",numused);

  remap(texture);
  
  return texture;
}