Example #1
0
    def test_manual(self):
        buffer_usage = BufferUsage.STORAGE_BUFFER
        buffer_layout = Layout.STD140
        buffer_order = Order.ROW_MAJOR

        structA = Struct([Vector.ivec2(), Scalar.double()],
                         buffer_layout,
                         member_names=["a", "b"],
                         type_name="structA")
        structB = Struct([Scalar.uint(), Scalar.double()],
                         buffer_layout,
                         type_name="structB")
        structC = Struct([structB, Vector.ivec2()],
                         buffer_layout,
                         type_name="structC")

        structs = [structA, structB, structC]

        variables = [
            Vector.vec3(),
            Vector.ivec4(),
            Array(structC, 2, buffer_layout),
            Vector.ivec4(),
            Scalar.uint(),
            Array(Scalar.double(), (5, 2), buffer_layout),
            Scalar.int(),
            Array(Vector.vec4(), (2, 3, 4), buffer_layout),
            Vector.dvec2(), structA
        ]

        container = Struct(variables, buffer_layout, type_name="block")
        print(container)

        glsl = self.build_glsl_program(container, structs, buffer_usage)
        # print(glsl)

        values, array_expected = self.build_values(container.definitions)
        array_expected = np.array(array_expected, dtype=np.float32)

        bytez_input = container.to_bytes(values)
        bytez_output = self.run_program(glsl,
                                        bytez_input,
                                        array_expected.nbytes,
                                        usage_input=buffer_usage)
        array = np.frombuffer(bytez_output, dtype=array_expected.dtype)

        print(array_expected)
        print(array)
        print("equal", ((array_expected - array) == 0).all())
Example #2
0
    def test_manually(self):
        buffer_usage = BufferUsage.STORAGE_BUFFER
        buffer_layout = Layout.STD140
        buffer_order = Order.ROW_MAJOR

        structA = Struct([Vector.ivec2(), Scalar.double()],
                         buffer_layout,
                         member_names=["a", "b"],
                         type_name="structA")
        structB = Struct([Scalar.uint(), Scalar.double()],
                         buffer_layout,
                         type_name="structB")
        structC = Struct([structB, Vector.ivec2()],
                         buffer_layout,
                         type_name="structC")

        structs = [structA, structB, structC]

        variables = [
            Vector.vec3(),
            Vector.ivec4(),
            Array(structC, 2, buffer_layout),
            Vector.ivec4(),
            Scalar.uint(),
            Array(Scalar.double(), (5, 2), buffer_layout),
            Scalar.int(),
            Array(Vector.vec4(), (2, 3, 4), buffer_layout),
            Vector.dvec2(), structA
        ]

        container = Struct(variables, buffer_layout, type_name="block")
        print(container)

        glsl = self.build_glsl_program(container, structs, buffer_usage)
        # print(glsl)

        values_expected, array = self.build_values(container.definitions)
        array = np.array(array, dtype=np.float32)

        bytez_in = array.tobytes()  # std430
        bytez_out = self.run_program(glsl, bytez_in, container.size())
        values = container.from_bytes(bytez_out)

        register = {}
        steps = {Scalar: 0, Vector: 0, Array: 0, Struct: 0}

        for struct in structs + [container]:
            self.build_register(register, struct, steps)

        values_ftd = self.format_values(container, values, register)
        values_expected_ftd = self.format_values(container, values_expected,
                                                 register)

        print("")
        self.print_formatted_values(values_ftd)
        print("")
        self.print_formatted_values(values_expected_ftd)
        print("")

        print("")

        print(values_ftd == values_expected_ftd)