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 8 123 ... LastLast
Results 1 to 10 of 80

Thread: Separate sampler state from texture state

  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
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: Separate sampler state from texture state

    "This has been suggested before and met furious resistance by both IHVs and users..."

    What? I have never seen any IHV make a comment about that, at all, and i have not seen any user complain about the idea. I myself have suggested it several times and no one ever complained.

    If there is any in/official statement from the ARB or an IHV about it, i would like to see.

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,386

    Re: Separate sampler state from texture state

    Quote Originally Posted by Alphonse Reinheart
    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.
    Have to agree. The original LP designs called for an (immutable) object along these lines, no? If you're going to change things - and we now have a deprecation mechanism in place to facilitate the emergence of new approaches - why not head in the general LP direction. Seems to me it's not too late to climb that peak (or the twin peaks of Kilimanjaro :-))...

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

    Re: Separate sampler state from texture state

    Quote Originally Posted by Jan
    "This has been suggested before and met furious resistance by both IHVs and users..."

    What? I have never seen any IHV make a comment about that, at all, and i have not seen any user complain about the idea. I myself have suggested it several times and no one ever complained.

    If there is any in/official statement from the ARB or an IHV about it, i would like to see.

    Jan.
    I don't recall the name but I distinctly remember a member of the ARB saying that this feature was discussed and turned down. I'll post a link if I find the relevant statements.

    Edit: either my search-fu or the search function of this forum sucks. No matter what keywords I specify, it returns about every single post from the "suggestions" and "items of importance" forums...
    [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
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: Separate sampler state from texture state

    Yeah, the search sucks, had the same problem several times. That is why i didn't even bother to search about this myself ;-)

    Jan.
    GLIM - Immediate Mode Emulation for GL3

Posting Permissions

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