コード例 #1
0
ファイル: loader.py プロジェクト: aimoonchen/RenderPipeline
 def __exit__(self, *args):
     duration = (time.clock() - self.start_time) * 1000.0
     if duration > 80.0 and timed_loading_operation.WARNING_COUNT < 5:
         RPObject.global_warn(
             "RPLoader", "Loading '" + self.resource + "' took", round(duration, 2), "ms")
         timed_loading_operation.WARNING_COUNT += 1
         if timed_loading_operation.WARNING_COUNT == 5:
             RPObject.global_warn(
                 "RPLoader", "Skipping further loading warnings (max warning count reached)")
コード例 #2
0
 def __exit__(self, *args):
     duration = (time.clock() - self.start_time) * 1000.0
     if duration > 80.0 and timed_loading_operation.WARNING_COUNT < 5:
         RPObject.global_warn("RPLoader",
                              "Loading '" + self.resource + "' took",
                              round(duration, 2), "ms")
         timed_loading_operation.WARNING_COUNT += 1
         if timed_loading_operation.WARNING_COUNT == 5:
             RPObject.global_warn(
                 "RPLoader",
                 "Skipping further loading warnings (max warning count reached)"
             )
コード例 #3
0
    def update(self):
        """ Updates the error display, fetching all new messages from the notify
        stream """

        if not self._notify_stream:
            self._init_notify()

        while self._notify_stream.is_text_available():
            line = self._notify_stream.get_line().strip()
            if "warning" in line:
                RPObject.global_warn("Panda3D", line)
                # self.add_warning(line)
            elif "error" in line:
                RPObject.global_error("Panda3D", line)
                self.add_error(line)
            else:
                RPObject.global_debug("Panda3D", line)
コード例 #4
0
    def update(self):
        """ Updates the error display, fetching all new messages from the notify
        stream """

        if not self._notify_stream:
            self._init_notify()

        while self._notify_stream.is_text_available():
            line = self._notify_stream.get_line().strip()
            if "warning" in line:
                RPObject.global_warn("Panda3D", line)
                # self.add_warning(line)
            elif "error" in line:
                RPObject.global_error("Panda3D", line)
                self.add_error(line)
            else:
                RPObject.global_debug("Panda3D", line)
コード例 #5
0
 def _init_globals(self):
     """ Inits all global bindings. This includes references to the global
     ShowBase instance, as well as the render resolution, the GUI font,
     and various global logging and output methods. """
     Globals.load(self._showbase)
     native_w, native_h = self._showbase.win.get_x_size(), self._showbase.win.get_y_size()
     Globals.native_resolution = LVecBase2i(native_w, native_h)
     self._last_window_dims = LVecBase2i(Globals.native_resolution)
     self._compute_render_resolution()
     RenderTarget.RT_OUTPUT_FUNC = lambda *args: RPObject.global_warn(
         "RenderTarget", *args[1:])
     RenderTarget.USE_R11G11B10 = self.settings["pipeline.use_r11_g11_b10"]
コード例 #6
0
    def _init_globals(self):
        """ Inits all global bindings """
        Globals.load(self._showbase)
        w, h = self._showbase.win.get_x_size(), self._showbase.win.get_y_size()

        scale_factor = self.settings["pipeline.resolution_scale"]
        w = int(float(w) * scale_factor)
        h = int(float(h) * scale_factor)

        # Make sure the resolution is a multiple of 4
        w = w - w % 4
        h = h - h % 4

        self.debug("Render resolution is", w, "x", h)
        Globals.resolution = LVecBase2i(w, h)

        # Connect the render target output function to the debug object
        RenderTarget.RT_OUTPUT_FUNC = lambda *args: RPObject.global_warn(
            "RenderTarget", *args[1:])

        RenderTarget.USE_R11G11B10 = self.settings["pipeline.use_r11_g11_b10"]
コード例 #7
0
    def _init_globals(self):
        """ Inits all global bindings """
        Globals.load(self._showbase)
        w, h = self._showbase.win.get_x_size(), self._showbase.win.get_y_size()

        scale_factor = self.settings["pipeline.resolution_scale"]
        w = int(float(w) * scale_factor)
        h = int(float(h) * scale_factor)

        # Make sure the resolution is a multiple of 4
        w = w - w % 4
        h = h - h % 4

        self.debug("Render resolution is", w, "x", h)
        Globals.resolution = LVecBase2i(w, h)

        # Connect the render target output function to the debug object
        RenderTarget.RT_OUTPUT_FUNC = lambda *args: RPObject.global_warn(
            "RenderTarget", *args[1:])

        RenderTarget.USE_R11G11B10 = self.settings["pipeline.use_r11_g11_b10"]
コード例 #8
0
    def _generate_sampling_code(cls, texture, view_width, view_height): # pylint: disable=W0613
        """ Generates the GLSL code to sample a texture and also returns the
        GLSL sampler type """

        texture_type = texture.get_texture_type()
        comp_type = texture.get_component_type()

        # Useful snippets
        int_coord = "ivec2 int_coord = ivec2(texcoord * textureSize(p3d_Texture0, mipmap).xy);"
        slice_count = "int slice_count = textureSize(p3d_Texture0, 0).z;"

        float_types = [Image.T_float, Image.T_unsigned_byte]
        int_types = [Image.T_int, Image.T_unsigned_short, Image.T_unsigned_int_24_8]

        result = "result = vec3(1, 0, 1);", "sampler2D"

        if comp_type not in float_types + int_types:
            RPObject.global_warn("DisplayShaderBuilder", "Unkown texture component type:", comp_type)

        # 2D Textures
        if texture_type == Image.TT_2d_texture:

            if comp_type in float_types:
                result = "result = textureLod(p3d_Texture0, texcoord, mipmap).xyz;", "sampler2D"

            elif comp_type in int_types:
                result = int_coord + "result = texelFetch(p3d_Texture0, int_coord, mipmap).xyz / 10.0;", "isampler2D"

        # Buffer Textures
        elif texture_type == Image.TT_buffer_texture:

            range_check = lambda s: "if (int_index < textureSize(p3d_Texture0)) {" + s + "} else { result = vec3(1.0, 0.6, 0.2);};"

            if comp_type in float_types:
                result = range_check("result = texelFetch(p3d_Texture0, int_index).xyz;"), "samplerBuffer"

            elif comp_type in int_types:
                result = range_check("result = texelFetch(p3d_Texture0, int_index).xyz / 10.0;"), "isamplerBuffer"

        # 3D Textures
        elif texture_type == Image.TT_3d_texture:

            if comp_type in float_types:
                result = slice_count + "result = textureLod(p3d_Texture0, vec3(texcoord, (0.5 + slice) / slice_count), mipmap).xyz;", "sampler3D"

            elif comp_type in int_types:
                result = int_coord + "result = texelFetch(p3d_Texture0, ivec3(int_coord, slice), mipmap).xyz / 10.0;", "isampler3D"

        # 2D Texture Array
        elif texture_type == Image.TT_2d_texture_array:

            if comp_type in float_types:
                result = "result = textureLod(p3d_Texture0, vec3(texcoord, slice), mipmap).xyz;", "sampler2DArray"

            elif comp_type in int_types:
                result = int_coord + "result = texelFetch(p3d_Texture0, ivec3(int_coord, slice), mipmap).xyz / 10.0;", "isampler2DArray"

        # Cubemap
        elif texture_type == Image.TT_cube_map:

            code = "vec3 sample_dir = get_cubemap_coordinate(slice, texcoord*2-1);\n"
            code += "result = textureLod(p3d_Texture0, sample_dir, mipmap).xyz;"
            result = code, "samplerCube"

        # Cubemap array
        elif texture_type == Image.TT_cube_map_array:
            code = "vec3 sample_dir = get_cubemap_coordinate(slice % 6, texcoord*2-1);\n"
            code += "result = textureLod(p3d_Texture0, vec4(sample_dir, slice / 6), mipmap).xyz;"
            result = code, "samplerCubeArray"


        else:
            print("WARNING: Unhandled texture type", texture_type, "in display shader builder")

        return result