Exemplo n.º 1
0
    def __init__(self, name, program, geometry):
        self.name = name
        self.program = program
        self.geometry = geometry
        # size of batched draw calls
        self.batch = BATCH_SIZE

        self.vertex_attr = glGetAttribLocation(self.program.id, b"vertex")
        self.edge_attr = glGetAttribLocation(self.program.id, b"edge")
        self.index_attr = glGetAttribLocation(self.program.id, b"index")

        # load/bind/configure vertex buffer
        self.vertex_buffer = VertexBuffer(GLfloat, GL_STATIC_DRAW)
        batched_edges = list(geometry.edges) * self.batch
        self.vertex_buffer.load(memory.create_vertex_buffer(batched_edges))
        self.vertex_buffer.partition(
            [(self.vertex_attr, 4), (self.edge_attr, 3)]
        )

        uniform_indicies = []
        for i in range(self.batch):
            uniform_indicies.extend([i] * geometry.num_vertex)

        indices_buffer = memory.create_vertex_buffer(uniform_indicies)
        self.indices_buffer = VertexBuffer(GLfloat, GL_STATIC_DRAW)
        self.indices_buffer.load(indices_buffer)
        self.indices_buffer.set(self.index_attr, 1)
Exemplo n.º 2
0
    def __init__(self, name, program, geometry):
        self.name = name
        self.program = program
        self.geometry = geometry
        # size of batched draw calls
        self.batch = BATCH_SIZE

        self.vertex_attr = glGetAttribLocation(self.program.id, b"vertex")
        self.edge_attr = glGetAttribLocation(self.program.id, b"edge")
        self.index_attr = glGetAttribLocation(self.program.id, b"index")

        # load/bind/configure vertex buffer
        self.vertex_buffer = VertexBuffer(GLfloat, GL_STATIC_DRAW)
        batched_edges = list(geometry.edges) * self.batch
        self.vertex_buffer.load(memory.create_vertex_buffer(batched_edges))
        self.vertex_buffer.partition([(self.vertex_attr, 4),
                                      (self.edge_attr, 3)])

        uniform_indicies = []
        for i in range(self.batch):
            uniform_indicies.extend([i] * geometry.num_vertex)

        indices_buffer = memory.create_vertex_buffer(uniform_indicies)
        self.indices_buffer = VertexBuffer(GLfloat, GL_STATIC_DRAW)
        self.indices_buffer.load(indices_buffer)
        self.indices_buffer.set(self.index_attr, 1)
Exemplo n.º 3
0
    def __init__(self, scale, vertices, indices, exclude):
        self.scale = scale

        self.vertices = create_vertex_buffer(vertices)
        self.indices = create_index_buffer(indices)
        self.num_vertex = len(indices)

        self.edges = self.calculate_edges(exclude)
Exemplo n.º 4
0
    def __init__(self, scale, vertices, indices, exclude):
        self.scale = scale

        self.vertices = create_vertex_buffer(vertices)
        self.indices = create_index_buffer(indices)
        self.num_vertex = len(indices)

        self.edges = self.calculate_edges(exclude)
Exemplo n.º 5
0
    def calculate_edges(self, excludes):
        """Builds a vertex list adding barycentric coordinates to each vertex.

        Used to draw turtle borders efficiently, specialised to draw only the
        some edges. See below for references.

        http://stackoverflow.com/questions/18035719/drawing-a-border-on-a-2d-polygon-with-a-fragment-shader  # NOQA
        http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/  # NOQA
        http://strattonbrazil.blogspot.co.uk/2011/09/single-pass-wireframe-rendering_11.html  # NOQA
        """
        edges = []
        MEW = 100.0
        if excludes is None:
            excludes = [0] * len(self.indices) * 2
        for i in range(0, len(self.indices), 3):  # each triangle
            i0 = self.indices[i+0] * 4
            i1 = self.indices[i+1] * 4
            i2 = self.indices[i+2] * 4
            e0 = excludes[i+0]
            e1 = excludes[i+1]
            e2 = excludes[i+2]
            p0 = self.vertices[i0:i0+4]
            p1 = self.vertices[i1:i1+4]
            p2 = self.vertices[i2:i2+4]
            v0 = self.vec2minus(p2, p1)
            v1 = self.vec2minus(p2, p0)
            v2 = self.vec2minus(p1, p0)
            area = fabs(v1[0]*v2[1] - v1[1] * v2[0])
            c0 = (area/self.magnitude(v0), e1 * MEW, e2 * MEW)
            c1 = (e0 * MEW, area/self.magnitude(v1), e2 * MEW)
            c2 = (e0 * MEW, e1 * MEW, area/self.magnitude(v2))
            edges.extend(p0)
            edges.extend(c0)
            edges.extend(p1)
            edges.extend(c1)
            edges.extend(p2)
            edges.extend(c2)
        return create_vertex_buffer(edges)
Exemplo n.º 6
0
    def calculate_edges(self, excludes):
        """Builds a vertex list adding barycentric coordinates to each vertex.

        Used to draw turtle borders efficiently, specialised to draw only the
        some edges. See below for references.

        http://stackoverflow.com/questions/18035719/drawing-a-border-on-a-2d-polygon-with-a-fragment-shader  # NOQA
        http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/  # NOQA
        http://strattonbrazil.blogspot.co.uk/2011/09/single-pass-wireframe-rendering_11.html  # NOQA
        """
        edges = []
        MEW = 100.0
        if excludes is None:
            excludes = [0] * len(self.indices) * 2
        for i in range(0, len(self.indices), 3):  # each triangle
            i0 = self.indices[i + 0] * 4
            i1 = self.indices[i + 1] * 4
            i2 = self.indices[i + 2] * 4
            e0 = excludes[i + 0]
            e1 = excludes[i + 1]
            e2 = excludes[i + 2]
            p0 = self.vertices[i0:i0 + 4]
            p1 = self.vertices[i1:i1 + 4]
            p2 = self.vertices[i2:i2 + 4]
            v0 = self.vec2minus(p2, p1)
            v1 = self.vec2minus(p2, p0)
            v2 = self.vec2minus(p1, p0)
            area = fabs(v1[0] * v2[1] - v1[1] * v2[0])
            c0 = (area / self.magnitude(v0), e1 * MEW, e2 * MEW)
            c1 = (e0 * MEW, area / self.magnitude(v1), e2 * MEW)
            c2 = (e0 * MEW, e1 * MEW, area / self.magnitude(v2))
            edges.extend(p0)
            edges.extend(c0)
            edges.extend(p1)
            edges.extend(c1)
            edges.extend(p2)
            edges.extend(c2)
        return create_vertex_buffer(edges)