Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
   Copyright (c) 2016 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _TEXTURE_H_
#define _TEXTURE_H_

#include "Core/Resources/Headers/Resource.h"

#include "Platform/Video/Headers/RenderAPIWrapper.h"
#include "Platform/Video/Headers/GraphicsResource.h"
#include "Platform/Video/Textures/Headers/TextureDescriptor.h"

#include "Utility/Headers/ImageTools.h"

namespace Divide {

/// An API-independent representation of a texture
class NOINITVTABLE Texture : protected GraphicsResource, public Resource {
    friend class ResourceCache;
    friend class ResourceLoader;
    template <typename T>
    friend class ImplResourceLoader;
    public:
       struct TextureLoadInfo {
           TextureLoadInfo() :
               _type(TextureType::COUNT),
               _layerIndex(0),
               _cubeMapCount(0)
           {
           }

           TextureType _type;
           U32 _layerIndex;
           U32 _cubeMapCount;
       };
    public:

    explicit Texture(GFXDevice& context,
                     const stringImpl& name,
                     const stringImpl& resourceLocation,
                     TextureType type,
                     bool asyncLoad);
    virtual ~Texture();

    /// Bind the texture to the specified texture unit
    virtual void bind(U8 slot, bool flushStateOnRequest = true) = 0;
    /// Bind a single level
    virtual void bindLayer(U8 slot, U8 level, U8 layer, bool layered, bool read, bool write, bool flushStateOnRequest = true) = 0;
    /// Change the texture's mip levels. This can be called at any time
    virtual void setMipMapRange(U16 base = 0, U16 max = 1000) {
        _mipMinLevel = base;
        _mipMaxLevel = max;
    }
    /// Resize the texture to the specified dimensions and upload the new data
    virtual void resize(const bufferPtr ptr,
                        const vec2<U16>& dimensions,
                        const vec2<U16>& mipLevels) = 0;
    // API-dependent loading function that uploads ptr data to the GPU using the
    // specified parameters
    virtual void loadData(const TextureLoadInfo& info,
                          const TextureDescriptor& descriptor,
                          const vectorImpl<ImageTools::ImageLayer>& imageLayers,
                          const vec2<U16>& mipLevels) = 0;
    virtual void loadData(const TextureLoadInfo& info,
                          const TextureDescriptor& descriptor,
                          const bufferPtr data,
                          const vec2<U16>& dimensions,
                          const vec2<U16>& mipLevels) = 0;
    /// Specify the sampler descriptor used to sample from this texture in the
    /// shaders
    inline void setCurrentSampler(const SamplerDescriptor& descriptor) {
        // This can be called at any time
        _descriptor._samplerDescriptor = descriptor;
        _textureData._samplerHash = descriptor.getHash();
        // The sampler will be updated before the next bind call and used in
        // that bind
        _samplerDirty = true;
    }
    /// Get the sampler descriptor used by this texture
    inline const SamplerDescriptor& getCurrentSampler() const {
        return _descriptor._samplerDescriptor;
    }

    inline TextureData& getData() {
        return _textureData;
    }

    inline const TextureData& getData() const {
        return _textureData;
    }
    /// Set/Get the number of layers (used by texture arrays)
    inline void setNumLayers(U32 numLayers) { _numLayers = numLayers; }
    inline U32 getNumLayers() const { return _numLayers; }
    /// Texture width as returned by STB/DDS loader
    inline U16 getWidth() const { return _width; }
    /// Texture height depth as returned by STB/DDS loader
    inline U16 getHeight() const { return _height; }
    /// Texture min mip level
    inline U16 getMinMipLevel() const { return _mipMinLevel; }
    /// Texture ax mip level
    inline U16 getMaxMipLevel() const { return _mipMaxLevel; }
    /// A rendering API level handle used to uniquely identify this texture
    /// (e.g. for OpenGL, it's the texture object)
    inline U32 getHandle() const { return _textureData.getHandleHigh(); }
    /// If the texture has an alpha channel and at least one pixel is
    /// translucent, return true
    inline bool hasTransparency() const { return _hasTransparency; }
    /// Get the type of the texture
    inline TextureType getTextureType() const { return _textureData._textureType; }
    /// Force a full refresh of the mip chain on the next texture bind
    inline void refreshMipMaps() { _mipMapsDirty = !_lockMipMaps; }
    /// Disable/enable automatic calls to mipmap generation calls (e.g. glGenerateMipmaps)
    /// Useful if we compute our own mipmaps
    inline void lockAutomaticMipMapGeneration(bool state) { _lockMipMaps = state; }
    /// Force a full update of the texture (all pending changes and mipmap refresh);
    /// Returns false if the texture is not ready or in an invalid state
    virtual bool flushTextureState() = 0;

    const TextureDescriptor& getDescriptor() const {
        return _descriptor;
    }


    static U16 computeMipCount(U16 width, U16 height);
   protected:
    /// Use STB/NV_DDS to load a file into a Texture Object
    bool loadFile(const TextureLoadInfo& info, const stringImpl& name);
    /// Load texture data using the specified file name
    virtual bool load() override;
    virtual void threadedLoad();
    /// Force a refresh of the entire mipmap chain
    virtual void updateMipMaps() = 0;

   protected:
    U32 _numLayers;
    U16 _width;
    U16 _height;
    U16 _mipMaxLevel;
    U16 _mipMinLevel;
    bool _lockMipMaps;
    bool _mipMapsDirty;
    bool _samplerDirty;
    bool _hasTransparency;
    bool _asyncLoad;
    TextureData  _textureData;
    TextureDescriptor _descriptor;
};

TYPEDEF_SMART_POINTERS_FOR_CLASS(Texture);

};  // namespace Divide
#endif // _TEXTURE_H_

Commits for Divide-Framework/trunk/Source Code/Platform/Video/Textures/Headers/Texture.h

Diff revisions: vs.
Revision Author Commited Message
795 Diff Diff IonutCava picture IonutCava Wed 23 Nov, 2016 17:14:33 +0000

[IonutCava]
- Remove ULL. Use U64 instead
- Various small bug fixes and typos.

776 Diff Diff IonutCava picture IonutCava Thu 06 Oct, 2016 15:57:56 +0000

[IonutCava]
- Improve the CommandBuffer system to include the notion of a RenderPass /RenderSubPass with output render target info stored in them (not used yet)

758 Diff Diff IonutCava picture IonutCava Tue 02 Aug, 2016 16:05:09 +0000

[IonutCava]
- Added a cross platform method of naming threads (helps with debugging)
- Reduced dependency on VAR.dvd_drawID in shaders.
- Work on Single/Multi thread toggle for GFX resource loading (crashes, bugs, etc)
- Fix a bug in TaskPool where task states were never actually updated properly
- Change threadpool implementation to use std::thread instead of boost::thread

750 Diff Diff IonutCava picture IonutCava Thu 07 Jul, 2016 16:02:03 +0000

[IonutCava]
- Static analysis based fixes and improvements

749 Diff Diff IonutCava picture IonutCava Mon 04 Jul, 2016 16:01:34 +0000

[IonutCava]
- Added initial environment mapping code:
— Allow adding, per scene, of multiple environment probes that generate cube map reflections
— Support 2 types of probes: infinite (such as sky only probes) and local. Local probes use an AABB that will later be used for parallax correction
— Probes are held in a scene specific pool, can be updated at different rates and their results can be passed on to materials (if materials don’t need specific reflection systems such as for water or mirrors)
- ToDo:
— Blend between probes (currently, only the closes one is selected)
— Reduce VRAM usage
— Set as fallback for screen space reflections

722 Diff Diff IonutCava picture IonutCava Thu 09 Jun, 2016 16:15:33 +0000

[IonutCava]
- Restructure RenderTarget system:
— Separate attachments, use an attachment pool, use draw descriptors, require explicit information for RT calls, etc

709 Diff Diff IonutCava picture IonutCava Thu 19 May, 2016 16:21:46 +0000

[IonutCava]
- Massive rewrite of the resource system:
— ResourceCache now uses a map of weak pointers and passes shared pointers to the call point of CreateResource
— RemoveResource is no longer needed, but resource based smart pointers use a custom deleter that calls unload()
— Keep a shared_ptr of the resource in the entity that needs it and pass shared_ptr references from getter methods
-— All of this removed the need for calls to RemoveResource, REGISTER_TRACKED_DEPENDENCY and UNREGISTER_TRACKED_DEPENDENCY reducing the number of mutex locks and atomic exchanges
- Singleton cleanup:
— Removed ShaderManager singleton and merged it’s data and responsibilities in static methods in both ShaderProgram and Shader classes.
Explanation: Due to the complex interdependency chains in the system, copying, updating, tracking the cache in a thread safe way became a lot more slower than a straight forward smart pointer based implementation. (e.g. scene graph nodes have 3d objects and material instances, 3d objects have materials, materials have textures and shaders, etc)

692 Diff Diff IonutCava picture IonutCava Wed 27 Apr, 2016 16:24:26 +0000

[IonutCava]
- Resource system cleanup:
— Resource name and resource file location (if any) is now passed only via explicit constructors! (ResourceDescriptors already contain this data, so why use setters?)
- Fix a bug with ortho projection matrix calculation (set m[3][3] to 1. this was skipped when the identity() call was changed to zero() in the ortho() function)
— This also fixed text rendering

652 Diff Diff IonutCava picture IonutCava Thu 25 Feb, 2016 17:13:10 +0000

[IonutCava]
- More work on compressed texture loading (DXT1, DXT3, DXT5)

648 IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these