Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 80

Thread: Separate sampler state from texture state

Hybrid View

  1. #1
    Member Regular Contributor
    Join Date
    Oct 2006
    Posts
    352

    Separate sampler state from texture state

    An oft requested feature since OpenGL 2.1. Right now, OpenGL treats sampler state as part of the texture object. This is *not* how the hardware works and makes specific algorithms inefficient (those that require different sampling states for the same texture).

    Potential API:
    Code :
    // Preferred
    glSamplerParameter(GL_SAMPLER0, GL_SAMPLER_MAG_FILTER, ...);
    glSamplerTexture(GL_SAMPLER0, tex_id);
    glGetSamplerParameter(GL_SAMPLER0, ...);
     
    // following current bind-to-edit semantics (worse):
    glBindSampler(GL_SAMPLER0);
    glSamplerParameter(...);
    glSamplerTexture(tex_id);
    glGetSamplerParamater(GL_SAMPLER_MAG_FILTER, ...);
    glBindSampler(0);

    Alternatively, replace Sampler by TexUnit and SAMPLERi by the existing TEXTURE_UNITi tokens:
    Code :
    // Following current OpenGL naming conventions:
    glTexUnitParameter(GL_TEXTURE_UNIT0, GL_TEXTURE_MAG_FILTER, ...);
    glTexUnitTexture(GL_TEXTURE_UNIT0, tex_id);
    glGetTexUnitParameter(GL_TEXTURE_UNIT0, ...);

    glActiveTexture and glTexParameter tokens that set sampler state will be deprecated.

    Backwards compatibility can be maintained:
    1. using a new version profile
    2. specifying that glTexParameter will be ignored when the relevant texture is bound to a sampler with glSamplerTexture. Old applications (using glActiveTexture) will continue to use glTexParameter and ignore glSamplerParameter.

    Questions:
    1. "Sampler" or "TexUnit"? My personal preference is the latter, as it follows existing OpenGL naming conventions.

    2. Use bind-to-edit semantics? ActiveTexture is not bind-to-edit, so it would be best to define the new API to *not* use bind-to-edit.

    3. "TexUnitTexture" function - the name is ugly. We could reuse the ActiveTexture entry point but this is going to be nasty both for driver developers and users (backwards compatibility).

    Other thoughts, questions, ideas? Any chance we will see something like this in OpenGL 3.3?
    [The Open Toolkit library: C# OpenGL 4.4, OpenGL ES 3.1, OpenAL 1.1 for Mono/.Net]

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264

    Re: Separate sampler state from texture state

    This sounds reasonable.
    glSamplerParameter(GL_SAMPLER0, GL_SAMPLER_MAG_FILTER, ...);

    1. The name should be very different. This is a good thing.
    2. no more bind to edit in the next API revision
    3. or TextureImageUnit but Sampler sounds simpler.
    4. What is the risk of this becoming obsolete? Will samplers become programmable one day? Will we have to do this instead one day?
    loc=glGetUniformLocation(program, "MagFilter");
    glUseProgram(X);
    glUniform(loc, GL_LINEAR);
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Junior Member Regular Contributor
    Join Date
    Aug 2006
    Posts
    218

    Re: Separate sampler state from texture state

    You should just need these 2 functions (plus some matching Get functions):

    glUniformSamplerParameter{i,f,...}(GLint location, GLenum parameter, {GLint,GLfloat,...} value);

    glUniformSamplerTexture(GLint location, GLint texture);

    (where location is the result from glGetUniformLocation)

    They've got ugly names, but they get the job done.

    Regards
    elFarto

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Separate sampler state from texture state

    Why not put these in the shader? Or at least optionally have these parameters be defined in the shader (external setting of params before link would override them)?

  5. #5
    Member Regular Contributor
    Join Date
    Oct 2006
    Posts
    352

    Re: Separate sampler state from texture state

    This has been suggested before and met furious resistance by both IHVs and users... so no, defining sampler state in the shader is probably not an option.
    [The Open Toolkit library: C# OpenGL 4.4, OpenGL ES 3.1, OpenAL 1.1 for Mono/.Net]

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Separate sampler state from texture state

    If you are going to separate sampler state from textures, then there should be sampler objects that encapsulate that state. That way, you only need one function to set the sampler state on a uniform.

  7. #7
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    934

    Re: Separate sampler state from texture state

    Quote Originally Posted by Stephen A
    Potential API:
    Code :
    // Preferred
    glSamplerParameter(GL_SAMPLER0, GL_SAMPLER_MAG_FILTER, ...);
    glSamplerTexture(GL_SAMPLER0, tex_id);
    glGetSamplerParameter(GL_SAMPLER0, ...);
     
    // following current bind-to-edit semantics (worse):
    glBindSampler(GL_SAMPLER0);
    glSamplerParameter(...);
    glSamplerTexture(tex_id);
    glGetSamplerParamater(GL_SAMPLER_MAG_FILTER, ...);
    glBindSampler(0);

    Alternatively, replace Sampler by TexUnit and SAMPLERi by the existing TEXTURE_UNITi tokens:
    Code :
    // Following current OpenGL naming conventions:
    glTexUnitParameter(GL_TEXTURE_UNIT0, GL_TEXTURE_MAG_FILTER, ...);
    glTexUnitTexture(GL_TEXTURE_UNIT0, tex_id);
    glGetTexUnitParameter(GL_TEXTURE_UNIT0, ...);
    I'm sorry to say that but I think that you just propose some syntax sugar ...

    The purpose of separated image and sampler is more flexibility and probably removing the MAX_TEXTURE < 32 limitation. It would allows to use several samplers per image or several images per sampler.

    I'm personally imagine a "sampler object", binds like uniforms replacing glUniformi ... No more TexUnit concept.

  8. #8
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,270

    Re: Separate sampler state from texture state

    Wait, doesn't the slew of texture-lookup GLSL functions already provide in-shader selectable filtering? texture() vs textureLod() vs texelFetch() . Or if you mean to provide a user-modifiable anisotropic-filtering value for a large range of textures, can't you just keep a vector of those textures and set the param accordingly.

  9. #9
    Member Regular Contributor
    Join Date
    Oct 2006
    Posts
    352

    Re: Separate sampler state from texture state

    Quote Originally Posted by Groovounet
    I'm sorry to say that but I think that you just propose some syntax sugar ...

    The purpose of separated image and sampler is more flexibility and probably removing the MAX_TEXTURE < 32 limitation. It would allows to use several samplers per image or several images per sampler.

    I'm personally imagine a "sampler object", binds like uniforms replacing glUniformi ... No more TexUnit concept.
    I agree 100%. The code in the OP was just meant as a starting point for the discussion.

    Quote Originally Posted by Ilian Dinev
    Wait, doesn't the slew of texture-lookup GLSL functions already provide in-shader selectable filtering? texture() vs textureLod() vs texelFetch() . Or if you mean to provide a user-modifiable anisotropic-filtering value for a large range of textures, can't you just keep a vector of those textures and set the param accordingly.
    Yes you can, but this workaround wastes texture memory and is far from ideal. Why copy texture data just to change sampling modes?
    [The Open Toolkit library: C# OpenGL 4.4, OpenGL ES 3.1, OpenAL 1.1 for Mono/.Net]

  10. #10
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Separate sampler state from texture state

    As an alternative, if sampler objects are just too different for OpenGL, you could have the ability to build a texture object from another texture object. They would share certain information (the texture data itself, internal format, etc), but they would have their own instance data (sampler state).

    Wait, doesn't the slew of texture-lookup GLSL functions already provide in-shader selectable filtering? texture() vs textureLod() vs texelFetch()
    These do not change the filtering alone. These are different functions with different behaviors. For example, texelFetch expects the texture coordinates to be integer pixel values, not normalized floating-point.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •