예제 #1
0
파일: myshaders.py 프로젝트: tom66/glscope
    def reload(self):
        """
            Reload or build for the first time the attribute cache.
            This can be quite expensive so it is only done on shader linking.
            If the shader was linked outside the api, you have to call this manually.
        """
        prog = self.prog()
        if prog is None:
            raise RuntimeError('Shader was freed')

        maxlength = getattr(prog, 'max_attribute_length')
        name_buf = (c_char * maxlength)()
        name_buf_ptr = cast(name_buf, POINTER(c_char))
        type_buf = GLenum(0)
        name_buf_length = GLint(0)
        buf_size = GLint(0)

        self.cache = {}
        for i in range(getattr(prog, 'attributes_count')):
            glGetActiveAttrib(prog.pid, i, maxlength, byref(name_buf_length),
                              byref(buf_size), byref(type_buf), name_buf_ptr)
            type = type_buf.value
            name_len = name_buf_length.value
            name = bytes(name_buf)[0:name_len].decode('UTF-8')
            size = buf_size.value

            loc = GLint(glGetAttribLocation(
                prog.pid,
                name))  #Kept in a c_int to quickly send the value when setting

            self.cache_item_build(loc, size, name, type)
예제 #2
0
    def prepDraw(self):
        glNewList(self.dl, GL_COMPILE)

        c = self.corners
        for h in c:
            glPushMatrix()
            glTranslatef(h.x, h.y, h.z)
            q = gluNewQuadric()
            gluSphere(q, GLdouble(0.45), GLint(10), GLint(10))
            glPopMatrix()

        glBegin(GL_QUADS)

        glVertex3fv(adaptVec(c[0]))
        glVertex3fv(adaptVec(c[2]))
        glVertex3fv(adaptVec(c[6]))
        glVertex3fv(adaptVec(c[4]))

        glVertex3fv(adaptVec(c[1]))
        glVertex3fv(adaptVec(c[3]))
        glVertex3fv(adaptVec(c[7]))
        glVertex3fv(adaptVec(c[5]))

        glVertex3fv(adaptVec(c[0]))
        glVertex3fv(adaptVec(c[1]))
        glVertex3fv(adaptVec(c[3]))
        glVertex3fv(adaptVec(c[2]))

        glVertex3fv(adaptVec(c[2]))
        glVertex3fv(adaptVec(c[3]))
        glVertex3fv(adaptVec(c[7]))
        glVertex3fv(adaptVec(c[6]))

        glVertex3fv(adaptVec(c[7]))
        glVertex3fv(adaptVec(c[6]))
        glVertex3fv(adaptVec(c[4]))
        glVertex3fv(adaptVec(c[5]))

        glVertex3fv(adaptVec(c[0]))
        glVertex3fv(adaptVec(c[1]))
        glVertex3fv(adaptVec(c[5]))
        glVertex3fv(adaptVec(c[4]))

        glEnd()
        glEndList()
예제 #3
0
파일: myshaders.py 프로젝트: tom66/glscope
def current_program():
    """
        Return the currently bound shader program or None if there is None.
        The returned shader do not own the underlying buffer.
    """
    cprog = GLint(0)
    glGetIntegerv(GL_CURRENT_PROGRAM, byref(cprog))
    if cprog.value == 0:
        return None
    else:
        return ShaderProgram(cprog)
예제 #4
0
파일: myshaders.py 프로젝트: tom66/glscope
    def reload(self):
        """
            Reload or build for the first time the uniforms cache.
            This can be quite expensive so it is only done on shader linking.
            If the shader was linked outside the api, you have to call this manually.
        """
        prog = self.prog()

        if prog is None:
            raise RuntimeError('Shader was freed')

        maxlength = getattr(prog, 'max_uniform_length')
        name_buf = (c_char * maxlength)()
        name_buf_ptr = cast(name_buf, POINTER(c_char))
        type_buf = GLenum(0)
        name_buf_length = GLint(0)
        buf_size = GLint(0)

        self.cache = {}
        for i in range(getattr(prog, 'uniforms_count')):
            name, size, type = glGetActiveUniform(prog.pid, i)
            name = name.decode('UTF-8')
            loc = glGetUniformLocation(prog.pid, name)
            self.cache_item_build(loc, size, name, type)
예제 #5
0
파일: myshaders.py 프로젝트: tom66/glscope
class GLGetObject(object):
    """
        Descriptor that wraps glGet* function
    """
    __slots__ = ['pname']
    buffer = GLint(0)

    def __init__(self, pname):
        self.pname = pname

    def __set__(self):
        raise AttributeError('Attribute is not writable')

    def __delete__(self):
        raise AttributeError('Attribute cannot be deleted')
예제 #6
0
def main():
    with egl_context(output=None) as context:
        display,context,surface = context
        print("Vendor: %s"%(EGL.eglQueryString(display, EGL.EGL_VENDOR)))
        print("Version: %s"%(EGL.eglQueryString(display, EGL.EGL_VERSION)))
        print("Extensions: %s"%(EGL.eglQueryString(display, EGL.EGL_EXTENSIONS),))
        print("Client Extensions: %s"%(EGL.eglQueryString(display, EGL.EGL_CLIENT_APIS),))
        if device_enumeration.eglQueryDevicesEXT:
            devices = (device_query.EGLDeviceEXT * 5)()
            count = GLint()
            device_enumeration.eglQueryDevicesEXT(
                5,
                devices,
                count,
            )
            for device in devices[:int(count)]:
                print(device)
        else:
            print('No device_query extension available')
예제 #7
0
    def __init__(self, mesh):
        self.outline_color = (1, 1, 1)
        vertices = mesh.vertex_list.getVertices()
        minV = Vector3()
        maxV = Vector3()
        vertices.sort(lambda x, y: cmp(y.x, x.x))
        minV.x = vertices[0].x
        maxV.x = vertices[-1].x
        vertices.sort(lambda x, y: cmp(y.y, x.y))
        minV.y = vertices[0].y
        maxV.y = vertices[-1].y
        vertices.sort(lambda x, y: cmp(y.z, x.z))
        minV.z = vertices[0].z
        maxV.z = vertices[-1].z

        self.points = []
        for i in range(8):
            self.points.append(Vector3())
        for i in range(2):
            for j in range(2):
                self.points[int('%d%d%d' % (0, i, j), 2)].x = minV.x
                self.points[int('%d%d%d' % (1, i, j), 2)].x = maxV.x
                self.points[int('%d%d%d' % (i, 0, j), 2)].y = minV.y
                self.points[int('%d%d%d' % (i, 1, j), 2)].y = maxV.y
                self.points[int('%d%d%d' % (i, j, 0), 2)].z = minV.z
                self.points[int('%d%d%d' % (i, j, 1), 2)].z = maxV.z

        self.center = Vector3()
        for p in self.points:
            self.center += p
        self.center /= float(8)
        self.dl = glGenLists(1)
        glNewList(self.dl, GL_COMPILE)
        glLineWidth(5)
        c = self.outline_color
        glColor4f(c[0], c[1], c[2], 0.2)
        glBegin(GL_LINE_STRIP)
        for v in self.points:
            glVertex(v())
        glEnd()
        c = self.points
        glBegin(GL_LINES)

        glVertex(c[0]())
        glVertex(c[2]())
        glVertex(c[6]())
        glVertex(c[4]())

        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[2]())

        glVertex(c[2]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[6]())

        glVertex(c[7]())
        glVertex(c[6]())
        glVertex(c[4]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[5]())
        glVertex(c[4]())

        glEnd()
        glPushMatrix()
        glTranslatef(self.center.x, self.center.y, self.center.z)
        q = gluNewQuadric()
        gluSphere(q, GLdouble(0.25), GLint(10), GLint(10))
        glPopMatrix()
        glEndList()