Jump to content
  • entries
    941
  • comments
    5,894
  • views
    867,563

Asset Loader Class


Josh

1,880 views

 Share

There's a discussion on the forum that sort of veered into talking about Khronos' GLTF file format specification:

Some of this gave me some ideas for changes in the art pipeline in Turbo Game Engine. I was not feeling very concentrated today so I decided to do some easy work and implement a loader class:

class Loader : public SharedObject
{
public:
	std::vector<wstring> extensions;
	virtual bool Reload(shared_ptr<Stream> stream, shared_ptr<SharedObject> o, const int flags = 0)=0;
};

Then I created a TEX texture loader class:

class TEXTextureLoader : public Loader
{
public:
	virtual bool Reload(shared_ptr<Stream> stream, shared_ptr<SharedObject> o, const int flags = 0)=0;
};

When the engine is initialized it creates a TEXTexLoader object and saves it in a list of texture loaders:

GameEngine::Initialize()
{
	textureloaders.push_back(make_shared<TEXTextureLoader>());
}

And the class constructor itself creates an array of file extensions the loader supports:

TEXTextureLoader::TEXTextureLoader()
{
	extensions = { "tex" };
}

When a texture is loaded, the engine looks for a texture loader that matches the extension or the loaded file path.

At this point, all we have done is restructured the engine to do the same thing it did before, with more code. But now we can add new loaders for other file formats. And that is exactly what I did. You can now load textures directly from PNG files:

class PNGTextureLoader : public Loader
{
public:
	virtual bool Reload(shared_ptr<Stream> stream, shared_ptr<SharedObject> o, const int flags = 0)=0;
};

I've done the same thing for model file loading as well, although I have not yet added support for any other file types.

If we can add a C++ loader, we should be able to add one with Lua too. I haven't worked out the details yet, but it could work something like this:

function LoadModelObj( stream, model )
	while stream:EOF() == false do
		--------------
	end
end
  
AddModelLoader(LoadModelObj)

So with that, you could download a Lua script that would add support for loading a new file format.

I think in the new engine we will support all common image formats, including Photoshop PSD, as well as DDS, KTX, and our existing TEX files. Textures loaded from image formats will be less optimal because mipmaps will be generated on loading. Settings like clamping and filter modes will be stored in the associated .meta files, which means these files will start getting published along with your game asset files. This is a change from the Leadwerks 4 way of doing things.

  • Like 1
  • Upvote 2
 Share

3 Comments


Recommended Comments

I love the extra flexibility.

Quote

mipmaps will be generated on loading

I'm hoping that will be optional as sometimes you intentionally uncheck these in Leadwerks to make images look better (unless Turbo handles this a different way).

Link to comment
25 minutes ago, gamecreator said:

I love the extra flexibility.

I'm hoping that will be optional as sometimes you intentionally uncheck these in Leadwerks to make images look better (unless Turbo handles this a different way).

I think this will be another option stored in the .meta file. LE4 already does this, but it is currently only used for saving settings when images are reimported. By default loaded images will have mipmaps generated, since this is what you want 98% if the time.

  • Upvote 1
Link to comment

I added a FreeImage texture loader and now the following image formats can be loaded directly as textures:

  • bmp
  • jpg
  • gif
  • tga
  • pcx
  • hdr
  • psd
  • pcx
  • png
  • tif
  • ico

FreeImage supports DDS files but I don't want to route those through an image. Instead I want a more detailed DDS loader that loads exactly what the file contains, like mipmaps, cube textures, etc.

  • Like 1
  • Upvote 1
Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...