Jump to content

  • Log In with Google      Sign In   
  • Create Account


Mipmaps in image


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Alundra   Members   -  Reputation: 809

Like
0Likes
Like

Posted 24 June 2014 - 11:02 AM

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



Sponsor:

#2 phil_t   Crossbones+   -  Reputation: 3229

Like
0Likes
Like

Posted 24 June 2014 - 11:08 AM

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.



#3 Alundra   Members   -  Reputation: 809

Like
0Likes
Like

Posted 24 June 2014 - 11:55 AM

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.


Edited by Alundra, 24 June 2014 - 11:55 AM.


#4 Samith   Members   -  Reputation: 2114

Like
0Likes
Like

Posted 24 June 2014 - 01:35 PM

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.



#5 Alundra   Members   -  Reputation: 809

Like
0Likes
Like

Posted 24 June 2014 - 02:54 PM

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



#6 L. Spiro   Crossbones+   -  Reputation: 12878

Like
1Likes
Like

Posted 24 June 2014 - 03:44 PM

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#7 Alundra   Members   -  Reputation: 809

Like
0Likes
Like

Posted 24 June 2014 - 06:23 PM

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.



#8 L. Spiro   Crossbones+   -  Reputation: 12878

Like
0Likes
Like

Posted 24 June 2014 - 07:26 PM

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

Edited by L. Spiro, 24 June 2014 - 07:27 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 Alundra   Members   -  Reputation: 809

Like
0Likes
Like

Posted 24 June 2014 - 08:24 PM

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 ?


Edited by Alundra, 24 June 2014 - 09:09 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS