Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for runtime mipmap generation. #2

Open
mtwilliams opened this issue May 22, 2014 · 5 comments
Open

Add support for runtime mipmap generation. #2

mtwilliams opened this issue May 22, 2014 · 5 comments
Assignees

Comments

@mtwilliams
Copy link
Member

Runtime mipmap generation should be exposed for texture objects.

The cleanest approach would be to provide a stateless method that explicitly generates mipmaps from the top-most level, i.e., agl_texture_generate_mipmaps(). However, this violates the zero-copy design philosophy of AGL, and is impossible for immutable texture objects. Thus, agl_texture_data_1d/2d/3d() should accept flags, of which AUTO_GENERATE_MIPMAPS should implement the desired behavior.

agl_texture_data_2d(texture, x, y, w, h, format, data, AGL_TEXTURE_AUTO_GENERATE_MIPMAPS);
((agl::Texture2D *)texture)->data(x, y, w, h, format, data, agl::Texture::AutoGenerateMipmaps);

Alternatively, a boolean texture parameter can be exposed that results in similar behavior:

agl_texture_set_parameter_boolean(texture, AGL_TEXTURE_PARAMETER_AUTO_GENERATE_MIPMAPS, 1);
agl_texture_data_2d(texture, x, y, w, h, format, data);
texture->set_parameter(agl::Texture::Parameters::AutoGenerateMipmaps, true);
((agl::Texture2D *)texture)->data(x, y, w, h, format, data);
@mtwilliams mtwilliams self-assigned this May 22, 2014
@mtwilliams
Copy link
Member Author

For Direct3D9, if IDirect3DBaseTexture9::GetAutoGenFilterType returns D3DTEXF_NONE then calls to IDirect3DBaseTexture9::GetLevelCount will return incorrect values, thus affecting AGL_TEXTURE_PARAMETER_LEVEL_OF_DETAIL, see #3

To generate sub-levels texture objects need to:

  1. Not be in the system memory pool, D3DPOOL_SYSTEMMEM; and
  2. have D3DUSAGE_AUTOGENMIPMAP specified.

Then calls to IDirect3DBaseTexture9::GenerateMipSubLevels can be used to hint when sublevels should be generated, i.e. in agl_texture_data_1d/2d/3d.

@mtwilliams
Copy link
Member Author

For Direct3D11, calls to ID3D11DeviceContext::GenerateMips for non-render-target views have no effect, thus auto-generation must implemented by AGL.

@mtwilliams
Copy link
Member Author

For OpenGL 2.1+, and OpenGL 3.3+, calls to glGenerateMipmapEXT should be preceded with glEnable calls, as a work around ATI/AMD driver bugs. [1]

Additionally, as a fallback, set the texture parameter GL_GENERATE_MIPMAP to GL_TRUE then specify texture data and then rebind the texture. This however results in the implicit generation of mipmaps, i.e., it hints to the driver to generate sublevels. Furthermore, it is a Pandora's box of issues especially with regards to framebuffers and unbatched textures updates. [2]

@mtwilliams
Copy link
Member Author

For OpenGL ES 2.0 and OpenGL ES 3.0, just use glGenerateMipmap.

@mtwilliams
Copy link
Member Author

Finally, for other backends (presumably including mantle), auto-generation must be implemented by AGL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant