• Advertisement
Sign in to follow this  

OpenGL AMD 6310 GLSL/FBO texture copy issue

This topic is 1720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using OpenGL 2.0 and an FBO to copy some data from an RGBA texture to an RGB texture, and I ran into an issue where sometimes it "corrupts" the first few lowest order bits of some of the pixel components during the copy.

 

The texture copy is broken up into several steps, and I'm resizing the FBO.

 

At first I thought perhaps it was a problem related to the way that I was resizing the FBO, or with the way the the texture is being sampled, but the problem doesn't always occur, and when it does, it never occurs for every pixel copied nor does it ever occur for all of the components of each problematic pixel. In other words, it seems nearly random, except that it is indeed deterministic insomuch that the same error(s) occur if the same input float values are used during each run of the program.

 

Also, the problem never, ever occurs if I always use an FBO size of 1x1 (which is kind of misleading to know, because it made me think that it was a sampling issue, but, again, that is probably not the case since not every component of every problematic pixel is "corrupted"). Unfortunately, using an FBO size of 1x1 is absolutely useless in the real world where I'm going to be copying a texture containing anything more than a few pixels.

 

The problem happens on Windows 7 and Ubuntu, and the problem happens when I use MSVC++ or g++'s std rand() or Mersenne Twister to generate the input texture values (not that how I generate the values should matter, since copy operations are by definition independent of how the data to be copied was generated beforehand) .

 

I wrote a test program (see code below) where nothing changes between runs of the program other than the input texture values.

 

Does anyone have an AMD 6310 (or any other kind of hardware, really) that they can run this test program on? You'll have to run it a few times, as sometimes it produces an error, and sometimes it does not. I'm just curious if it ever produces the error on your hardware. I just can't spot the pattern, and my naive thinking is that this should either work all of the time, or never -- not so sporadically.

 

I'm also totally wiling to accept that it might, in the end, have something to do with the way that I'm using OpenGL to do the copy. This would be relieving actually, since it would mean that there's an easy and reliable solution. I hope this is the case.

 

I probably have some extraneous calls to glTexParameteri in there somewhere, but I was trying the "better safe than sorry" method while working on this test program.

 

In any case, the problem results in some of the pixel components having error that's on the order of like ~1e-8. Yes, that's a very small error, but it's totally unacceptable for what I'm doing.

 

#include <iostream>
using std::cout;
using std::endl;

#include <iomanip>
using std::ios_base;
using std::setprecision;
using std::fixed;

#include <vector>
using std::vector;

#include <string>
using std::string;

#include <utility>
using std::pair;

#include <cmath>
#include <cstdlib> // MSVC++ chokes if you don't include this before glut.h
#include <ctime>

#include <GL/glew.h>
#include <GL/glut.h>

// Automatically link in the GLUT and GLEW libraries if compiling on MSVC++
#ifdef _MSC_VER
    #pragma comment(lib, "glew32")
    #pragma comment(lib, "glut32")
#endif



float dist(float a, float b);
bool initialize_fragment_shader(const string &fragment_shader_code, GLint &shader, string &error);
void get_chunk_sizes(const size_t num_pixels, vector< pair<size_t, size_t> > &chunk_sizes, const bool force_1x1_chunks, const bool force_square_chunks = false);
string float_bits_string(const float f);

int main(int argc, char **argv)
{
    // This program uses an FBO and a fragment shader to copy RGBA pixels from an input array into an RGB output array.
    // It breaks up the entire pixel copy process into many smaller chunks of a varying number of pixels per chunk.
    // See line 165 to change the number of pixels in the array (right now it's hard-coded to be 7 pixels total).

    // If the chunk sizes are forced to be 1x1 pixels, then there are never any problems with the copy.
    // See line 186 to change whether the chunks are forced to be 1x1 pixels or not (right not they are not being forced as such).
    //
    // If the chunk sizes are not forced to be 1x1 pixels, then almost all of the time (but not quite always)
    // there is a small problem with at least one component of one of the pixels during the copy:
    //
    // The copy is off by a small, non-zero value of practically constant magnitude (on the order of ~1e-8).
    //
    // Since the values of the pixel components are the only thing that change between runs of the program,
    // the problem seems to be entirely dependent on the values of the pixel components themselves. This is totally
    // unexpected -- it should always work or always fail to the same degree, regardless of the pixel component values.
    // While looking at the bit patterns of the problematic pixel component values, it seems that it is always only the
    // first three to five lowest order bits that do not get copied successfully.
    //
    // Note that if the values of the pixel components do not change between runs, then the same errors occur,
    // and so the problem seems to be entirely deterministic. Right now the components are set via PRNG, and are done in a way
    // so that all of the bits of precision are used (see lines 173 - 176).
    // See line 86 to alter the PRNG seed.



// 1) Initialize pseudo-random number generator.
    srand(time(0)); // srand(0);



// 2) Initialize OpenGL and related objects.
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA);
    GLint glut_window_handle = glutCreateWindow("");

    if(! ( GLEW_OK == glewInit() &&
           GLEW_VERSION_2_0 &&
           GLEW_ARB_framebuffer_object &&
           GLEW_ARB_texture_rectangle ) )
    {
        return -1;
    }

    GLint shader_handle = 0;
    GLuint fbo_handle = 0;
    GLuint tex_fbo_handle = 0;
    GLuint tex_in_handle = 0;
    GLuint tex_out_handle = 0;
    const GLint tex_in_internal_format = GL_RGBA32F_ARB;
    const GLint tex_in_format = GL_RGBA;
    const GLint tex_out_internal_format = GL_RGB32F_ARB;
    const GLint tex_out_format = GL_RGB;
    const GLint var_type = GL_FLOAT;

    string code;
    code += "#version 110\n";
    code += "uniform sampler2D input_tex;\n";
    code += "void main(void)\n";
    code += "{\n";
    code += "    vec4 p = texture2D(input_tex, gl_TexCoord[0].st);\n";
    code += "    gl_FragData[0].rgb = vec3(p.xyz);\n";
    code += "}\n";

    string error;

    if(false == initialize_fragment_shader(code, shader_handle, error))
    {
        cout << error << endl;
        return -2;
    }

    glGenTextures(1, &tex_in_handle);
    glBindTexture(GL_TEXTURE_2D, tex_in_handle);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glGenTextures(1, &tex_out_handle);
    glBindTexture(GL_TEXTURE_2D, tex_out_handle);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glGenFramebuffersEXT(1, &fbo_handle);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_handle);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glGenTextures(1, &tex_fbo_handle);
    glBindTexture(GL_TEXTURE_2D, tex_fbo_handle);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glUseProgram(shader_handle);
    glUniform1i(glGetUniformLocation(shader_handle, "input_tex"), 0); // Use texture 0.



// 3) Set up input -- an array of RGBA float pixels with pseudorandom values.
    size_t num_pixels = 7; // = rand() % 50 + 1;
    size_t num_input_channels = 4;
    vector<float> input(num_pixels*num_input_channels, 0);

    for(size_t i = 0; i < num_pixels; i++)
    {
        size_t input_index = i*num_input_channels;
        
        input[input_index + 0] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
        input[input_index + 1] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
        input[input_index + 2] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
        input[input_index + 3] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
    }



// 4) Break up processing of input into chunks.
    vector< pair<size_t, size_t> > chunks;



#ifdef FORCE_1x1_CHUNKS
    get_chunk_sizes(num_pixels, chunks, true, true);
#else
    get_chunk_sizes(num_pixels, chunks, false, true);
#endif



    size_t num_pixels_remaining = num_pixels;

    size_t num_output_channels = 3;
    vector<float> output(num_pixels*num_output_channels, 0);

    for(size_t i = 0; i < chunks.size(); i++)
    {
        cout << "Pixels remaining: " << num_pixels_remaining << ", processing chunk size: " << chunks[i].first << " x " << chunks[i].second << " = " << chunks[i].first*chunks[i].second << endl;

        const size_t tex_size_x = chunks[i].first;
        const size_t tex_size_y = chunks[i].second;
        const size_t index = num_pixels - num_pixels_remaining;
        const size_t input_index = index*num_input_channels;
        const size_t output_index = index*num_output_channels;

        // Set the FBO size to match the current chunk size.
        glBindTexture(GL_TEXTURE_2D, tex_fbo_handle);
        glTexImage2D(GL_TEXTURE_2D, 0, tex_out_internal_format, tex_size_x, tex_size_y, 0, tex_out_format, var_type, 0);
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex_fbo_handle, 0);

        // Write to GPU memory.
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, tex_in_handle);
        glTexImage2D(GL_TEXTURE_2D, 0, tex_in_internal_format, tex_size_x, tex_size_y, 0, tex_in_format, var_type, &input[input_index]);

        // Calculate by "drawing".
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, 1, 0, 1, 0, 1);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glViewport(0, 0, tex_size_x, tex_size_y);

        glBegin(GL_QUADS);
            glTexCoord2f(0, 1);    glVertex2f(0, 1);
            glTexCoord2f(0, 0);    glVertex2f(0, 0);
            glTexCoord2f(1, 0); glVertex2f(1, 0);
            glTexCoord2f(1, 1);    glVertex2f(1, 1);
        glEnd();

        // Read from GPU memory.
        glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
        glReadPixels(0, 0, tex_size_x, tex_size_y, tex_out_format, var_type, &output[output_index]);

        num_pixels_remaining -= tex_size_x*tex_size_y;
    }



// 5) Analyze largest distance between input and output -- it should be zero, but it is not zero
//    if the chunk sizes are not forced to be 1x1.
    float largest_dist = 0;
    cout << setprecision(18);

    cout << endl << "Comparing input and output: " << endl;

    for(size_t i = 0; i < num_pixels; i++)
    {
        size_t input_index = i*num_input_channels;
        size_t output_index = i*num_output_channels;

        float dist0 = dist(input[input_index + 0], output[output_index + 0]);
        float dist1 = dist(input[input_index + 1], output[output_index + 1]);
        float dist2 = dist(input[input_index + 2], output[output_index + 2]);

        if(dist0 > largest_dist)
            largest_dist = dist0;

        if(dist1 > largest_dist)
            largest_dist = dist1;

        if(dist2 > largest_dist)
            largest_dist = dist2;

        if(dist0 != 0)
        {
            cout << endl;
            cout << "**** Copy error at pixel " << i + 1  << " first component" << endl;
            cout << "\tInput:  " << input[input_index + 0] << '\n' << "\tOutput: " << output[output_index + 0] << endl;
            cout << "\tInput (as bits):  " << float_bits_string(input[input_index + 0]) << '\n' << "\tOutput (as bits): " << float_bits_string(output[output_index + 0]) << endl;
            cout << endl;
        }
        else
        {
            cout << "OK at pixel " << i + 1  << " first component" << endl;
//            cout << "\tInput:  " << input[input_index + 0] << '\n' << "\tOutput: " << output[output_index + 0] << endl;
        }

        if(dist1 != 0)
        {
            cout << endl;
            cout << "**** Copy error at pixel " << i + 1 << " second component" << endl;
            cout << "\tInput:  " << input[input_index + 1] << '\n' << "\tOutput: " << output[output_index + 1] << endl;
            cout << "\tInput (as bits):  " << float_bits_string(input[input_index + 1]) << '\n' << "\tOutput (as bits): " << float_bits_string(output[output_index + 1]) << endl;
            cout << endl;
        }
        else
        {
            cout << "OK at pixel " << i + 1 << " second component" << endl;
//            cout << "\tInput:  " << input[input_index + 1] << '\n' << "\tOutput: " << output[output_index + 1] << endl;
        }

        if(dist2 != 0)
        {
            cout << endl;
            cout << "**** Copy error at pixel " << i + 1 << " third component" << endl;
            cout << "\tInput:  " << input[input_index + 2] << '\n' << "\tOutput: " << output[output_index + 2] << endl;
            cout << "\tInput (as bits):  " << float_bits_string(input[input_index + 2]) << '\n' << "\tOutput (as bits): " << float_bits_string(output[output_index + 2]) << endl;
            cout << endl;
        }
        else
        {
            cout << "OK at pixel " << i + 1 << " third component" << endl;
//            cout << "\tInput:  " << input[input_index + 2] << '\n' << "\tOutput: " << output[output_index + 2] << endl;
        }

    }

    if(0 != largest_dist)
        cout << "\nLargest copy error: " << largest_dist << endl;
    else
        cout << "\nNo copy errors." << endl;



// 6) Cleanup OpenGL and related objects.
    glDeleteTextures(1, &tex_in_handle);
    glDeleteTextures(1, &tex_out_handle);
    glDeleteTextures(1, &tex_fbo_handle);
    glDeleteFramebuffersEXT(1, &fbo_handle);
    glUseProgram(0);
    glDeleteProgram(shader_handle);
    glutDestroyWindow(glut_window_handle);

    return 0;
}

float dist(float a, float b)
{
    return fabsf(b - a);
}

bool initialize_fragment_shader(const string &fragment_shader_code, GLint &shader, string &error)
{
    error = "";

    // Compile shader.
    const char *cch = 0;
    GLint status = GL_FALSE;
    GLint frag = glCreateShader(GL_FRAGMENT_SHADER);

    glShaderSource(frag, 1, &(cch = fragment_shader_code.c_str()), 0);
    glCompileShader(frag);
    glGetShaderiv(frag, GL_COMPILE_STATUS, &status);

    if(GL_FALSE == status)
    {
        error = "Fragment shader compile error.\n";
        vector<GLchar> buf(4096, '\0');
        glGetShaderInfoLog(frag, 4095, 0, &buf[0]);

        for(size_t i = 0; i < buf.size(); i++)
            if(0 != buf[i])
                error += buf[i];

        error += '\n';

        return false;
    }

    // Link to get final shader.
    shader = glCreateProgram();
    glAttachShader(shader, frag);
    glLinkProgram(shader);
    glGetProgramiv(shader, GL_LINK_STATUS, &status);

    if(GL_FALSE == status)
    {
        error = "Program link error.\n";
        vector<GLchar> buf(4096, '\0');
        glGetShaderInfoLog(shader, 4095, 0, &buf[0]);

        for(size_t i = 0; i < buf.size(); i++)
            if(0 != buf[i])
                error += buf[i];

        error += '\n';

        glDetachShader(shader, frag);
        glDeleteShader(frag);
        return false;
    }

    // Cleanup.
    glDetachShader(shader, frag);
    glDeleteShader(frag);

    return true;
}

void get_chunk_sizes(const size_t num_pixels, vector< pair<size_t, size_t> > &chunk_sizes, const bool force_1x1_chunks, const bool force_square_chunks)
{
    chunk_sizes.clear();

    size_t num_pixels_remaining = num_pixels;
    GLint max_tex_size = 0;

    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);

    size_t curr_tex_x = max_tex_size;
    size_t curr_tex_y = max_tex_size;

    if(true == force_1x1_chunks)
        curr_tex_x = curr_tex_y = 1;

    while(0 < num_pixels_remaining)
    {
        if(num_pixels_remaining < curr_tex_x*curr_tex_y)
        {
            if(true == force_square_chunks)
            {
                curr_tex_x /= 2;
                curr_tex_y /= 2;
            }
            else
            {
                if(curr_tex_x == curr_tex_y)
                    curr_tex_y /= 2;
                else
                    curr_tex_x /= 2;
            }
        }
        else
        {
            pair<size_t, size_t> p(curr_tex_x, curr_tex_y);
            chunk_sizes.push_back(p);
            num_pixels_remaining -= curr_tex_x*curr_tex_y;
        }
    }
}

string float_bits_string(const float f)
{
    long unsigned int bit_mask = 1;
    long unsigned int intval = *(long unsigned int*)&f;

    string bits;

    for(size_t i = 0; i < 32; i++, bit_mask <<= 1)
    {
        if(intval & bit_mask)
            bits += '1';
        else
            bits += '0';
    }

    bits = string(bits.rbegin(), bits.rend());

    return bits;
}
 
Edited by taby

Share this post


Link to post
Share on other sites
Advertisement

Problem doesn't occur on Intel GPU. Much obliged for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Advertisement
  • Similar Content

    • By Balma Alparisi
      i got error 1282 in my code.
      sf::ContextSettings settings; settings.majorVersion = 4; settings.minorVersion = 5; settings.attributeFlags = settings.Core; sf::Window window; window.create(sf::VideoMode(1600, 900), "Texture Unit Rectangle", sf::Style::Close, settings); window.setActive(true); window.setVerticalSyncEnabled(true); glewInit(); GLuint shaderProgram = createShaderProgram("FX/Rectangle.vss", "FX/Rectangle.fss"); float vertex[] = { -0.5f,0.5f,0.0f, 0.0f,0.0f, -0.5f,-0.5f,0.0f, 0.0f,1.0f, 0.5f,0.5f,0.0f, 1.0f,0.0f, 0.5,-0.5f,0.0f, 1.0f,1.0f, }; GLuint indices[] = { 0,1,2, 1,2,3, }; GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); GLuint vbo; glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW); GLuint ebo; glGenBuffers(1, &ebo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(float) * 5, (void*)0); glEnableVertexAttribArray(0); glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(float) * 5, (void*)(sizeof(float) * 3)); glEnableVertexAttribArray(1); GLuint texture[2]; glGenTextures(2, texture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); sf::Image* imageOne = new sf::Image; bool isImageOneLoaded = imageOne->loadFromFile("Texture/container.jpg"); if (isImageOneLoaded) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageOne->getSize().x, imageOne->getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageOne->getPixelsPtr()); glGenerateMipmap(GL_TEXTURE_2D); } delete imageOne; glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); sf::Image* imageTwo = new sf::Image; bool isImageTwoLoaded = imageTwo->loadFromFile("Texture/awesomeface.png"); if (isImageTwoLoaded) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageTwo->getSize().x, imageTwo->getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageTwo->getPixelsPtr()); glGenerateMipmap(GL_TEXTURE_2D); } delete imageTwo; glUniform1i(glGetUniformLocation(shaderProgram, "inTextureOne"), 0); glUniform1i(glGetUniformLocation(shaderProgram, "inTextureTwo"), 1); GLenum error = glGetError(); std::cout << error << std::endl; sf::Event event; bool isRunning = true; while (isRunning) { while (window.pollEvent(event)) { if (event.type == event.Closed) { isRunning = false; } } glClear(GL_COLOR_BUFFER_BIT); if (isImageOneLoaded && isImageTwoLoaded) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture[1]); glUseProgram(shaderProgram); } glBindVertexArray(vao); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr); glBindVertexArray(0); window.display(); } glDeleteVertexArrays(1, &vao); glDeleteBuffers(1, &vbo); glDeleteBuffers(1, &ebo); glDeleteProgram(shaderProgram); glDeleteTextures(2,texture); return 0; } and this is the vertex shader
      #version 450 core layout(location=0) in vec3 inPos; layout(location=1) in vec2 inTexCoord; out vec2 TexCoord; void main() { gl_Position=vec4(inPos,1.0); TexCoord=inTexCoord; } and the fragment shader
      #version 450 core in vec2 TexCoord; uniform sampler2D inTextureOne; uniform sampler2D inTextureTwo; out vec4 FragmentColor; void main() { FragmentColor=mix(texture(inTextureOne,TexCoord),texture(inTextureTwo,TexCoord),0.2); } I was expecting awesomeface.png on top of container.jpg

    • By khawk
      We've just released all of the source code for the NeHe OpenGL lessons on our Github page at https://github.com/gamedev-net/nehe-opengl. code - 43 total platforms, configurations, and languages are included.
      Now operated by GameDev.net, NeHe is located at http://nehe.gamedev.net where it has been a valuable resource for developers wanting to learn OpenGL and graphics programming.

      View full story
    • By TheChubu
      The Khronos™ Group, an open consortium of leading hardware and software companies, announces from the SIGGRAPH 2017 Conference the immediate public availability of the OpenGL® 4.6 specification. OpenGL 4.6 integrates the functionality of numerous ARB and EXT extensions created by Khronos members AMD, Intel, and NVIDIA into core, including the capability to ingest SPIR-V™ shaders.
      SPIR-V is a Khronos-defined standard intermediate language for parallel compute and graphics, which enables content creators to simplify their shader authoring and management pipelines while providing significant source shading language flexibility. OpenGL 4.6 adds support for ingesting SPIR-V shaders to the core specification, guaranteeing that SPIR-V shaders will be widely supported by OpenGL implementations.
      OpenGL 4.6 adds the functionality of these ARB extensions to OpenGL’s core specification:
      GL_ARB_gl_spirv and GL_ARB_spirv_extensions to standardize SPIR-V support for OpenGL GL_ARB_indirect_parameters and GL_ARB_shader_draw_parameters for reducing the CPU overhead associated with rendering batches of geometry GL_ARB_pipeline_statistics_query and GL_ARB_transform_feedback_overflow_querystandardize OpenGL support for features available in Direct3D GL_ARB_texture_filter_anisotropic (based on GL_EXT_texture_filter_anisotropic) brings previously IP encumbered functionality into OpenGL to improve the visual quality of textured scenes GL_ARB_polygon_offset_clamp (based on GL_EXT_polygon_offset_clamp) suppresses a common visual artifact known as a “light leak” associated with rendering shadows GL_ARB_shader_atomic_counter_ops and GL_ARB_shader_group_vote add shader intrinsics supported by all desktop vendors to improve functionality and performance GL_KHR_no_error reduces driver overhead by allowing the application to indicate that it expects error-free operation so errors need not be generated In addition to the above features being added to OpenGL 4.6, the following are being released as extensions:
      GL_KHR_parallel_shader_compile allows applications to launch multiple shader compile threads to improve shader compile throughput WGL_ARB_create_context_no_error and GXL_ARB_create_context_no_error allow no error contexts to be created with WGL or GLX that support the GL_KHR_no_error extension “I’m proud to announce OpenGL 4.6 as the most feature-rich version of OpenGL yet. We've brought together the most popular, widely-supported extensions into a new core specification to give OpenGL developers and end users an improved baseline feature set. This includes resolving previous intellectual property roadblocks to bringing anisotropic texture filtering and polygon offset clamping into the core specification to enable widespread implementation and usage,” said Piers Daniell, chair of the OpenGL Working Group at Khronos. “The OpenGL working group will continue to respond to market needs and work with GPU vendors to ensure OpenGL remains a viable and evolving graphics API for all its customers and users across many vital industries.“
      The OpenGL 4.6 specification can be found at https://khronos.org/registry/OpenGL/index_gl.php. The GLSL to SPIR-V compiler glslang has been updated with GLSL 4.60 support, and can be found at https://github.com/KhronosGroup/glslang.
      Sophisticated graphics applications will also benefit from a set of newly released extensions for both OpenGL and OpenGL ES to enable interoperability with Vulkan and Direct3D. These extensions are named:
      GL_EXT_memory_object GL_EXT_memory_object_fd GL_EXT_memory_object_win32 GL_EXT_semaphore GL_EXT_semaphore_fd GL_EXT_semaphore_win32 GL_EXT_win32_keyed_mutex They can be found at: https://khronos.org/registry/OpenGL/index_gl.php
      Industry Support for OpenGL 4.6
      “With OpenGL 4.6 our customers have an improved set of core features available on our full range of OpenGL 4.x capable GPUs. These features provide improved rendering quality, performance and functionality. As the graphics industry’s most popular API, we fully support OpenGL and will continue to work closely with the Khronos Group on the development of new OpenGL specifications and extensions for our customers. NVIDIA has released beta OpenGL 4.6 drivers today at https://developer.nvidia.com/opengl-driver so developers can use these new features right away,” said Bob Pette, vice president, Professional Graphics at NVIDIA.
      "OpenGL 4.6 will be the first OpenGL release where conformant open source implementations based on the Mesa project will be deliverable in a reasonable timeframe after release. The open sourcing of the OpenGL conformance test suite and ongoing work between Khronos and X.org will also allow for non-vendor led open source implementations to achieve conformance in the near future," said David Airlie, senior principal engineer at Red Hat, and developer on Mesa/X.org projects.

      View full story
    • By _OskaR
      Hi,
      I have an OpenGL application but without possibility to wite own shaders.
      I need to perform small VS modification - is possible to do it in an alternative way? Do we have apps or driver modifictions which will catch the shader sent to GPU and override it?
    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
  • Advertisement