Browse Source

loader: Added loading of 2D texture array

Signed-off-by: deflected <[email protected]>
deflected 9 years ago
parent
commit
234e7eefee
2 changed files with 61 additions and 4 deletions
  1. 57 0
      direct/src/showbase/Loader.py
  2. 4 4
      panda/src/putil/loaderOptions.I

+ 57 - 0
direct/src/showbase/Loader.py

@@ -687,6 +687,63 @@ class Loader(DirectObject):
 
         return texture
 
+    def load2DTextureArray(self, texturePattern, readMipmaps = False, okMissing = False,
+                      minfilter = None, magfilter = None, anisotropicDegree = None,
+                      loaderOptions = None, multiview = None, numViews = 2):
+        """
+        texturePattern is a string that contains a sequence of one or
+        more hash characters ('#'), which will be filled in with the
+        z-height number.  Returns a 2-D Texture array object, suitable
+        for rendering array of textures.
+
+        okMissing should be True to indicate the method should return
+        None if the texture file is not found.  If it is False, the
+        method will raise an exception if the texture file is not
+        found or cannot be loaded.
+
+        If readMipmaps is True, then the filename string must contain
+        two sequences of hash characters; the first group is filled in
+        with the z-height number, and the second group with the mipmap
+        index number.
+
+        If multiview is true, it indicates to load a multiview or
+        stereo texture.  In this case, numViews should also be
+        specified (the default is 2), and the sequence of texture
+        images will be divided into numViews views.  The total
+        z-height will be (numImages / numViews).  For instance, if you
+        read 16 images with numViews = 2, then you have created a
+        stereo multiview image, with z = 8.  In this example, images
+        numbered 0 - 7 will be part of the left eye view, and images
+        numbered 8 - 15 will be part of the right eye view.
+        """
+        assert Loader.notify.debug("Loading 2-D texture array: %s" % (texturePattern))
+        if loaderOptions is None:
+            loaderOptions = LoaderOptions()
+        else:
+            loaderOptions = LoaderOptions(loaderOptions)
+        if multiview is not None:
+            flags = loaderOptions.getTextureFlags()
+            if multiview:
+                flags |= LoaderOptions.TFMultiview
+            else:
+                flags &= ~LoaderOptions.TFMultiview
+            loaderOptions.setTextureFlags(flags)
+            loaderOptions.setTextureNumViews(numViews)
+
+        texture = TexturePool.load2dTextureArray(texturePattern, readMipmaps, loaderOptions)
+        if not texture and not okMissing:
+            message = 'Could not load 2-D texture array: %s' % (texturePattern)
+            raise IOError(message)
+
+        if minfilter is not None:
+            texture.setMinfilter(minfilter)
+        if magfilter is not None:
+            texture.setMagfilter(magfilter)
+        if anisotropicDegree is not None:
+            texture.setAnisotropicDegree(anisotropicDegree)
+
+        return texture
+
     def loadCubeMap(self, texturePattern, readMipmaps = False, okMissing = False,
                     minfilter = None, magfilter = None, anisotropicDegree = None,
                     loaderOptions = None, multiview = None):

+ 4 - 4
panda/src/putil/loaderOptions.I

@@ -81,10 +81,10 @@ get_texture_flags() const {
 /**
  * Specifies the expected number of views to load for the texture.  This is
  * ignored unless TF_multiview is included in texture_flags.  This must be
- * specified when loading a 3-d multiview texture, in which case it is used to
- * differentiate z levels from separate views; it may be zero in the case of
- * 2-d textures or cube maps, in which case the number of views can be
- * inferred from the number of images found on disk.
+ * specified when loading a 3-d multiview texture or 2-d texture array, in
+ * which case it is used to differentiate z levels from separate views; it
+ * may be zero in the case of 2-d textures or cube maps, in which case the
+ * number of views can be inferred from the number of images found on disk.
  */
 INLINE void LoaderOptions::
 set_texture_num_views(int texture_num_views) {