コード例 #1
0
    def __init__(self, target, data, usage):
        self.buffer = glGenBuffersARB(1)  # Returns a numpy.ndarray for > 1.
        self.target = target

        self.bind()
        self.size = len(data)

        # Push the data over to Graphics card RAM.
        glBufferDataARB(target, data, usage)

        self.unbind()
        return
コード例 #2
0
    def __init__(self, target, data, usage):
        self.buffer = glGenBuffersARB(1)  # Returns a numpy.ndarray for > 1.
        self.target = target

        self.bind()
        self.size = len(data)

        # Push the data over to Graphics card RAM.
        glBufferDataARB(target, data, usage)

        self.unbind()
        return
コード例 #3
0
ファイル: gl_buffers.py プロジェクト: elfion/nanoengineer
    def __init__(self, target, data, usage):
        self.buffer = glGenBuffersARB(1) # Returns a numpy.ndarray for > 1.
        self.target = target             # OpenGL array binding target.
        self.usage = usage               # OpenGL Buffer Object usage hint.

        self.bind()
        if type(data) == type(1):
            self.size = data
            # Allocate with glBufferDataARB but don't fill it in yet.
            glAllocBufferData(target, self.size, None, usage)
        else:
            self.size = len(data)
            # Allocate, and push the data over to Graphics card RAM too.
            glBufferDataARB(target, data, usage)

        self.unbind()

        # Support for lazily updating drawing caches, namely a
        # timestamp showing when this GLBufferObject was last flushed.
        self.flushed = drawing_constants.NO_EVENT_YET

        return
コード例 #4
0
ファイル: viewer.py プロジェクト: bsergean/oglshow
    def setup_vbo(self):
        glInitVertexBufferObjectARB()
        self.VBO_vertex = int(glGenBuffersARB(1))					# Get A Valid Name
        self.VBO_normal = int(glGenBuffersARB(1))					# Get A Valid Name

        # Load The Data
        sc = self.scene
        self.vbo_array_size = len(sc.faces) * 3
        vertices = Numeric.zeros ( (self.vbo_array_size, 3), 'f')

        if self.do_lighting:
            normals = Numeric.zeros ( (self.vbo_array_size, 3), 'f')
            if not sc.normals:
                print 'compute normals'
                from geom_ops import compute_normals
                sc.normals, sc.faces_normals = compute_normals(sc)

        i = 0
        for j in xrange(len(sc.faces)):
            t = sc.faces[j]
            p1 = sc.points[t[0]]
            p2 = sc.points[t[1]]
            p3 = sc.points[t[2]]

            vertices [i, 0] = p1[0]
            vertices [i, 1] = p1[1]
            vertices [i, 2] = p1[2]

            vertices [i+1, 0] = p2[0]
            vertices [i+1, 1] = p2[1]
            vertices [i+1, 2] = p2[2]

            vertices [i+2, 0] = p3[0]
            vertices [i+2, 1] = p3[1]
            vertices [i+2, 2] = p3[2]

            # print p1, p2, p3

            if self.do_lighting:
                n = sc.faces_normals[j]
                n1 = sc.normals[n[0]]
                n2 = sc.normals[n[1]]
                n3 = sc.normals[n[2]]

                normals [i, 0] = n1[0]
                normals [i, 1] = n1[1]
                normals [i, 2] = n1[2]

                normals [i+1, 0] = n2[0]
                normals [i+1, 1] = n2[1]
                normals [i+1, 2] = n2[2]

                normals [i+2, 0] = n3[0]
                normals [i+2, 1] = n3[1]
                normals [i+2, 2] = n3[2]

            i += 3

        glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.VBO_vertex )
        glBufferDataARB( GL_ARRAY_BUFFER_ARB, vertices, GL_STATIC_DRAW_ARB );

        if self.do_lighting:
            glBindBufferARB( GL_ARRAY_BUFFER_ARB, self.VBO_normal )
            glBufferDataARB( GL_ARRAY_BUFFER_ARB, normals, GL_STATIC_DRAW_ARB );

        if self.gpu_info:
            print glGetString (GL_VENDOR)
            print glGetString (GL_RENDERER)
            print glGetString (GL_VERSION)
            Extensions = glGetString (GL_EXTENSIONS)
            for ext in Extensions.split():
                print ext

        return self.VBO_vertex, self.VBO_normal
コード例 #5
0
    def setup_vbo(self):
        glInitVertexBufferObjectARB()
        self.VBO_vertex = int(glGenBuffersARB(1))  # Get A Valid Name
        self.VBO_normal = int(glGenBuffersARB(1))  # Get A Valid Name

        # Load The Data
        sc = self.scene
        self.vbo_array_size = len(sc.faces) * 3
        vertices = Numeric.zeros((self.vbo_array_size, 3), 'f')

        if self.do_lighting:
            normals = Numeric.zeros((self.vbo_array_size, 3), 'f')
            if not sc.normals:
                print 'compute normals'
                from geom_ops import compute_normals
                sc.normals, sc.faces_normals = compute_normals(sc)

        i = 0
        for j in xrange(len(sc.faces)):
            t = sc.faces[j]
            p1 = sc.points[t[0]]
            p2 = sc.points[t[1]]
            p3 = sc.points[t[2]]

            vertices[i, 0] = p1[0]
            vertices[i, 1] = p1[1]
            vertices[i, 2] = p1[2]

            vertices[i + 1, 0] = p2[0]
            vertices[i + 1, 1] = p2[1]
            vertices[i + 1, 2] = p2[2]

            vertices[i + 2, 0] = p3[0]
            vertices[i + 2, 1] = p3[1]
            vertices[i + 2, 2] = p3[2]

            # print p1, p2, p3

            if self.do_lighting:
                n = sc.faces_normals[j]
                n1 = sc.normals[n[0]]
                n2 = sc.normals[n[1]]
                n3 = sc.normals[n[2]]

                normals[i, 0] = n1[0]
                normals[i, 1] = n1[1]
                normals[i, 2] = n1[2]

                normals[i + 1, 0] = n2[0]
                normals[i + 1, 1] = n2[1]
                normals[i + 1, 2] = n2[2]

                normals[i + 2, 0] = n3[0]
                normals[i + 2, 1] = n3[1]
                normals[i + 2, 2] = n3[2]

            i += 3

        glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.VBO_vertex)
        glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertices, GL_STATIC_DRAW_ARB)

        if self.do_lighting:
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.VBO_normal)
            glBufferDataARB(GL_ARRAY_BUFFER_ARB, normals, GL_STATIC_DRAW_ARB)

        if self.gpu_info:
            print glGetString(GL_VENDOR)
            print glGetString(GL_RENDERER)
            print glGetString(GL_VERSION)
            Extensions = glGetString(GL_EXTENSIONS)
            for ext in Extensions.split():
                print ext

        return self.VBO_vertex, self.VBO_normal