瀏覽代碼

add new texture constructor, set_size() method

cxgeorge 23 年之前
父節點
當前提交
7766b9ced2

+ 14 - 0
panda/src/gobj/pixelBuffer.I

@@ -70,6 +70,20 @@ INLINE PixelBuffer::
 ~PixelBuffer(void) {
 }
 
+
+INLINE void PixelBuffer::
+set_size(int x_org, int y_org, int x_size, int y_size) {
+  if ((_xsize != x_size) || (_ysize != y_size) ||
+      (_xorg != x_org) || (_yorg != y_org)) {
+    make_dirty();
+  }
+
+  _xsize = x_size;
+  _ysize = y_size;
+  _xorg = x_org;
+  _yorg = y_org;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PixelBuffer::set_xsize
 //       Access:

+ 24 - 0
panda/src/gobj/pixelBuffer.cxx

@@ -69,6 +69,30 @@ PixelBuffer(int xsize, int ysize, int components, int component_width,
   _loaded = true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PixelBuffer::Constructor
+//       Access: Public
+//  Description:  create a pixel buffer with specified format but do not alloc CPU RAM for it
+////////////////////////////////////////////////////////////////////
+PixelBuffer::
+PixelBuffer(int xsize, int ysize, int components, int component_width, Type type, Format format,
+            bool bAllocateRAM) : ImageBuffer()
+{
+  _xsize = xsize;
+  _ysize = ysize;
+  _xorg = 0;
+  _yorg = 0;
+  _border = 0;
+  _components = components;
+  _component_width = component_width;
+  _type = type;
+  _format = format;
+  if(bAllocateRAM)
+    _image = PTA_uchar::empty_array((unsigned int)(_xsize * _ysize * _components * _component_width));
+   else _image = PTA_uchar();
+  _loaded = false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PixelBuffer::Copy Constructor
 //       Access: Public

+ 8 - 1
panda/src/gobj/pixelBuffer.h

@@ -70,7 +70,10 @@ public:
     F_blue,
     F_alpha,
     F_rgb,     // any suitable RGB mode, whatever the hardware prefers
-    F_rgb5,    // specifically, 5 bits per R,G,B channel
+    F_rgb5,    // specifically, 5 bits per R,G,B channel.  
+               // this is paired with T_unsigned_byte.  really T_unsigned_byte
+               // should not be specified for this one, it should use
+               // T_unsigned_5bits or something
     F_rgb8,    // 8 bits per R,G,B channel
     F_rgb12,   // 12 bits per R,G,B channel
     F_rgb332,  // 3 bits per R & G, 2 bits for B
@@ -88,6 +91,9 @@ public:
   PixelBuffer(void);
   PixelBuffer(int xsize, int ysize, int components,
               int component_width, Type type, Format format);
+  PixelBuffer(int xsize, int ysize, int components,
+              int component_width, Type type, Format format,
+              bool bAllocateRAM);
   PixelBuffer(const PixelBuffer &copy);
   void operator = (const PixelBuffer &copy);
 
@@ -117,6 +123,7 @@ public:
   INLINE void set_ysize(int size);
   INLINE void set_xorg(int org);
   INLINE void set_yorg(int org);
+  INLINE void set_size(int x_org, int y_org, int x_size, int y_size);
   INLINE void set_format(Format format);
 
   INLINE int get_xsize() const;

+ 2 - 0
panda/src/gobj/texture.I

@@ -138,3 +138,5 @@ INLINE void Texture::
 apply(GraphicsStateGuardianBase *gsg) {
   gsg->apply_texture(prepare(gsg));
 }
+
+

+ 22 - 1
panda/src/gobj/texture.cxx

@@ -124,7 +124,28 @@ Texture() : ImageBuffer() {
   _anisotropic_degree = 1;
   _keep_ram_image = false;
   _pbuffer = new PixelBuffer;
-  _has_requested_size = false;
+  // _has_requested_size = false;
+  _all_dirty_flags = 0;
+  memset(&_border_color,0,sizeof(Colorf));
+}
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: Constructor
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+Texture::
+Texture(int xsize, int ysize, int components, int component_width, PixelBuffer::Type type, 
+        PixelBuffer::Format format, bool bAllocateRAM) : ImageBuffer() {
+  _magfilter = FT_nearest;
+  _minfilter = FT_nearest;
+  _wrapu = WM_repeat;
+  _wrapv = WM_repeat;
+  _anisotropic_degree = 1;
+  _keep_ram_image = bAllocateRAM;
+  _pbuffer = new PixelBuffer(xsize,ysize,components,component_width,type,format,bAllocateRAM);
+  // _has_requested_size = false;
   _all_dirty_flags = 0;
   memset(&_border_color,0,sizeof(Colorf));
 }

+ 4 - 1
panda/src/gobj/texture.h

@@ -75,6 +75,8 @@ PUBLISHED:
 
 PUBLISHED:
   Texture();
+  Texture(int xsize, int ysize, int components, int component_width, PixelBuffer::Type type, PixelBuffer::Format format,
+          bool bAllocateRAM);
   ~Texture();
 
   bool read(const Filename &name);
@@ -158,6 +160,7 @@ public:
   // pixel buffer when needed.  Know what you are doing!
   PT(PixelBuffer) _pbuffer;
 
+/*
   // If you request a region from the framebuffer that is not a power of 2,
   // we need to grab a larger region that is a power of 2 that contains the
   // requested region and set the pixel buffer size accordingly.  We store
@@ -165,7 +168,7 @@ public:
   bool _has_requested_size;
   int _requested_w;
   int _requested_h;
-
+*/
 
 
   // Datagram stuff