dxTextureContext8.h
00001 // Filename: dxTextureContext8.h
00002 // Created by:  drose (07Oct99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef DXTEXTURECONTEXT8_H
00016 #define DXTEXTURECONTEXT8_H
00017 
00018 #include "dxgsg8base.h"
00019 #include "texture.h"
00020 #include "textureContext.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //       Class : DXTextureContext8
00024 // Description :
00025 ////////////////////////////////////////////////////////////////////
00026 class EXPCL_PANDADX DXTextureContext8 : public TextureContext {
00027 public:
00028   DXTextureContext8(PreparedGraphicsObjects *pgo, Texture *tex, int view);
00029   virtual ~DXTextureContext8();
00030 
00031   virtual void evict_lru();
00032 
00033   bool create_texture(DXScreenData &scrn);
00034   bool create_simple_texture(DXScreenData &scrn);
00035   void delete_texture();
00036   bool extract_texture_data();
00037 
00038   INLINE bool has_mipmaps() const;
00039   INLINE IDirect3DBaseTexture8 *get_d3d_texture() const;
00040   INLINE IDirect3DTexture8 *get_d3d_2d_texture() const;
00041   INLINE IDirect3DVolumeTexture8 *get_d3d_volume_texture() const;
00042   INLINE IDirect3DCubeTexture8 *get_d3d_cube_texture() const;
00043 
00044   static HRESULT d3d_surface_to_texture(RECT &source_rect,
00045           IDirect3DSurface8 *d3d_surface,
00046           bool inverted, Texture *result,
00047           int z);
00048 
00049 private:
00050   HRESULT fill_d3d_texture_mipmap_pixels(int mip_level, int depth_index, D3DFORMAT source_format);
00051   HRESULT fill_d3d_texture_pixels();
00052   HRESULT fill_d3d_texture_pixels(DXScreenData &scrn);
00053   HRESULT fill_d3d_volume_texture_pixels(DXScreenData &scrn);
00054   static int down_to_power_2(int value);
00055   unsigned int get_bits_per_pixel(Texture::Format format, int *alphbits);
00056 
00057 private:
00058   D3DFORMAT _d3d_format;    // the 'D3DFORMAT' the Panda TextureBuffer fmt corresponds to
00059   IDirect3DBaseTexture8 *_d3d_texture;
00060   IDirect3DTexture8 *_d3d_2d_texture;
00061   IDirect3DVolumeTexture8 *_d3d_volume_texture;
00062   IDirect3DCubeTexture8 *_d3d_cube_texture;
00063 
00064   bool _has_mipmaps;
00065 
00066 public:
00067   static TypeHandle get_class_type() {
00068     return _type_handle;
00069   }
00070   static void init_type() {
00071     TextureContext::init_type();
00072     register_type(_type_handle, "DXTextureContext8",
00073           TextureContext::get_class_type());
00074   }
00075   virtual TypeHandle get_type() const {
00076     return get_class_type();
00077   }
00078   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00079 
00080 private:
00081   static TypeHandle _type_handle;
00082 
00083   friend class wdxGraphicsBuffer8;
00084 };
00085 
00086 #include "dxTextureContext8.I"
00087 
00088 #endif
00089