v 0. Pasted by Anonymous as cpp at 2014-10-31 19:11:45 MSK and set expiration to never.

Paste will expire never.

  1. #pragma once
  2.  
  3. #include "nu_SceneResource.h"
  4. #include "nu_Classes.h"
  5. #include "nu_Vec.h"
  6. #include "nu_GpuLoad.h"
  7. #include "nu_SharedPtr.h"
  8. #include "nu_UI_Image.h"
  9. #include "nu_TextureSetting.h"
  10. #include "nu_Sampler.h"
  11.  
  12. NAMESPACE_NULIGINE_BEGIN;
  13.  
  14. class NU_API TextureDesc
  15. {
  16. public:
  17.     Str name;
  18.     bool is_render_target;
  19.     u32 width, height, mip_count;
  20.     TexFormat format;
  21.     bool is_cube;
  22.     bool is_can_write;
  23.     bool is_can_read;
  24.     bool is_from_file;
  25.     TexGroup group;
  26.     UI_Image init_data;
  27. public:
  28.     TextureDesc();
  29.     void Reset();
  30. };
  31.  
  32. enum TextureLoadFormat{
  33.     tlf_Uncnown,
  34.     tlf_Source,
  35.     tlf_DDS,
  36.     tlf_PVR
  37. };
  38.  
  39. class NU_API TextureGpuRaw : public GpuLoad
  40. {
  41. protected:
  42.     TextureDesc desc;
  43.     bool is_set_desc;
  44.     // CubeMap texture need load 6 faces, 2d texture will be use one slot
  45.     FileStream *file_streams[6];
  46.     TextureLoadFormat load_format[6];
  47.     bool loaded[6];
  48.     u32 file_size;
  49.     TextureSetting *use_setting;
  50.     void *readed_data;
  51.     u32 readed_data_size;
  52.     Mutex readed_data_mutex;
  53. public:
  54.     TextureGpuRaw(Scene *scene);
  55.     virtual ~TextureGpuRaw();
  56.     void RefCoundIsZero();
  57.     void SetLoadFromDesc(TextureDesc &set_desc);
  58.     virtual bool GetCanLoadInThreadGPU();
  59.     virtual void DoLoadInThreadGPU();
  60.     u32 GetFileSize();
  61.     const TextureDesc &Desc() const;
  62.     bool GetIsDepthFormat();
  63.     virtual void ReadTextureData() = 0;
  64.     bool GetCanReadTextureData();
  65.     void *GetReadTextureData();
  66.     u32  GetReadTextureDataSize();
  67.     void ClearReadedTextureData();
  68. protected:
  69.     int GetCountSckipMipLevels(int mip_map_count);
  70.     bool GetUseMipLevels();
  71.     bool GetQualityAccept();
  72.     bool isCanRepeat();
  73.     virtual void CreateTextureAsunc(size_t &size_move_to_gpu) = 0;
  74. private:
  75.     virtual void FileStreamLoadComplite(FileStream *fs);
  76.     void CreateFileStreamsCube();
  77.     void CreateFileStream2D();
  78.     Str GetRealNameCubeMap(Str _name);
  79.     Str GetTexPrefixForCurRender();
  80. };
  81.  
  82. typedef SharedPtr<TextureGpuRaw> TextureGpuPtr;
  83. typedef WeakPtr<TextureGpuRaw> TextureGpuWeakPtr;
  84.  
  85. class NU_API Texture : public SceneResource
  86. {
  87. public:
  88.     TextureDesc desc;
  89.     TextureGpuPtr tex_gpu;
  90.     static bool GetIsLoadFromPak(ProjectFiles *project_files, Str real_file, Str pak_file);
  91.     SCENE_RESOURCE_DERIVED(Texture, SceneResource);
  92.     Texture(Scene *_scene);
  93.     virtual ~Texture();
  94.     virtual bool GetResourceByName(Str &name)override;
  95.     TextureGpuPtr &GetTexureGpu();
  96.     void Unload();
  97.     void SetWritable();
  98.     void SetReadeble();
  99.     void SetFileName(Str set_name, bool set_is_cube = false);
  100.     bool GetIsLoadFromFile();
  101.     void SetName(Str _name);
  102.     Str &GetName();
  103.     int GetWidth() const;
  104.     int GetHeight() const;
  105.     int GetMipCount();
  106.     void SetSize(u32 _w, u32 _h);
  107.     void SetImageData(const UI_Image &image);
  108.     void SetFormat(TexFormat _format);
  109.     TexFormat GetFormat();
  110.     void SetGroup(TexGroup set_group);
  111.     TexGroup GetGroup();
  112.     bool GetIsCube();
  113.     void SetIsCube(bool set_is_cube);
  114.     u32 GetFileLoadSize();
  115.     static void FileChange(Str file_name);
  116. };
  117.  
  118.  
  119. NAMESPACE_NULIGINE_END;