Hi all,

I have some difficulties getting atomic counter to work. The first gl call
glGenBuffers throws a segfault. I am wondering if this is related to OpenSG
stuff or something else.

Thank you for your time!

Here is my code:

.h

#ifndef COUNTER_H_INCLUDED
#define COUNTER_H_INCLUDED

class AtomicCounter {
    private:
        GLuint buffer;

    public:
        AtomicCounter();

        void init();
        void reset();
        void fetch();
};

#endif // COUNTER_H_INCLUDED

.cpp

#include <GL/glew.h>
#include <GL/glext.h>
#define GL_ATOMIC_COUNTER_BUFFER          0x92C0
#include "counter.h"
#include <string.h>

AtomicCounter::AtomicCounter() {;}

void AtomicCounter::init() {
    // declare and generate a buffer object name
    glGenBuffers(1, &buffer); //  <
--------------------------------------------- segfault!!!
    // bind the buffer and define its initial storage capacity
    glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, buffer);
    glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(GLuint) * 3, NULL,
GL_DYNAMIC_DRAW);
    // unbind the buffer
    glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
}

void AtomicCounter::reset() {
    // declare a pointer to hold the values in the buffer
    GLuint *userCounters;
    glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, buffer);
    // map the buffer, userCounters will point to the buffers data
    userCounters = (GLuint*)glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0 ,
sizeof(GLuint) * 3,
                                             GL_MAP_WRITE_BIT |
GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT );
    // set the memory to zeros, resetting the values in the buffer
    memset(userCounters, 0, sizeof(GLuint) *3 );
    // unmap the buffer
    glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
}

void AtomicCounter::fetch() {
    GLuint userCounters[3];
    glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, buffer);
    glGetBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(GLuint) * 3,
userCounters);
    glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0);
    /*redPixels = userCounters[0];
    greenPixels = userCounters[1];
    redPixels = userCounters[2];*/
}
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to