Mipmaps in image

Started by
7 comments, last by Alundra 9 years, 10 months ago

Hi all,

Do you think it's bad to store mipmaps in "Image class" with a GenerateMipmaps function or it only should be in "Texture class" ?

Thanks

Advertisement

They're used by the GPU, so they need to be part of the texture that is sent to the GPU.

What is "Image class"? What is "Texture class"? You've given us no context.

Image class is a class who stores pixel data, you can set or get a pixel if it's a RGBA image format, mirror, flip, change format, load from file, save to file.

Texture class is a class linked with the Renderer class who is renderer dependent, he stores the GPU texture data used for shader.

Image class supports RGBA and BC format.

Your Image class sounds like something that is (hopefully) only heavily used offline in your tools. It would make sense for your Image class to have a function to generate mipmaps, which can then be saved into the texture file that your game loads and creates a runtime texture from. The runtime Texture class will create a texture that contains the mipmaps that it read off disk, but is unlikely to have any interface for directly modifying those mips.

It's the design goal, doesn't looks bad since you said it.

The most effective set-up I have found so far is:
  • CImage loads and manipulates any image file (I use some custom loaders for my custom formats and DXT, and FreeImage for the rest). It can resample (rescale) them, flip them vertically, apply matrix operations (sobel filters for example), convert between formats, swizzle channels, allow direct texel modifications, etc. It can also create and store chains of mipmaps (since it can natively rescale images anyway), and also perform DXT compression (I use my own modification of Squish (SURPRISE—my own DXT routine has a flaw that needs to be handled, and it basically needs to be rewritten from scratch)). It also has the ability to save to a custom file format which includes the mipmaps and also to later load that file.
  • CTexture2d::CreateTexture() takes an array of CImage’s or file names. It takes an array in order to optionally support texture arrays (1 array slice per CImage you pass), and if you pass only 1 CImage it is a non-array regular 2D texture. If you pass file names it creates temporary internal CImage objects, uses them to load the file(s) you pass, and calls its const CImage * overload. The format of the texture, number of array slices, number of mipmaps levels, and dimensions are all implicit in this way.
  • Although CImage is part of the engine and can be used at run-time for any of the above operations, it is stupid to do so. Tools link to the engine. My LSDxt converter and LSFbx converter link to the necessary parts of the engine and use CImage for offline conversions. The run-time should only be using CImage to load custom .LSI (L. Spiro Image) files. Nonetheless it is there for use at run-time just for those very rare special cases.
In the distant past when I was (more) naïve, since textures were so strongly associated with the images in my game I tried to make them do everything (I associated image files with GPU textures). This was partially influenced by DirectX’s D3DXCreateTextureFromFile() function, which has definitely made more than just myself think it is correct to let textures have direct access to image files and loading therein.
My second attempt made better use of the single-responsibility principle, and I had a CImage as a member of CTexture2d. But this was still naïve, as a texture should be absolutely nothing more than bridging the gap between an image and the GPU. It should’t actually have an image. It should only take 1 or more as a parameter for bridging that gap.
Finally, the correct solution appears to be the above one.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I had the same before, CImage class inside ITexture class but it's bad, only source path is needed.

Do you store the texture sampler inside the texture class ?

One texture file format could store sampler info.

Do you store the texture sampler inside the texture class ?

A sampler is a separate object from a texture for a reason. Only in OpenGL would you think of them as being related (and even OpenGL makes them separate in recent versions).

No. Samplers are created elsewhere depending on how the textures are used.
If the texture comes from a model, the model will make a sampler at load-time based on the purpose of the texture (bilinear filtering for diffuse maps, specular maps, normal maps, etc.), existence of mipmaps (trilinear filtering), material wrap modes, and system-wide quality settings (level of anisotropy).

There is no reason an image file should have any notion of a sampler; a single image could be drawn for 2 different purposes and be sampled entirely differently (trilinear/wrap for models vs. nearest-neighbor/clamp for the texture-viewer (either for debug purposes or for tools)).


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

But in editor you like to set wrap mode and filtering and then set it on the material.

Why it should not be stored here if you like to set it in texture editor ?

Look at this image from unreal engine 4 : https://docs.unrealengine.com/latest/images/Engine/Content/Types/Textures/Properties/Interface/Texture_UI.jpg.

It's a good example, you can see on the right params, unity does the same, maybe crytek ?

In API doc of unreal engine, FTexture is :

api_variable_public.png

SamplerStateRHI

The sampler state to use for the texture.

api_variable_public.png

TextureRHI

The texture's RHI resource.

Is it bad to allow to open a current compressed DDS ?

This topic is closed to new replies.

Advertisement