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
/*
   Copyright (c) 2017 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 : public GraphicsResource, public CachedResource {
    friend class ResourceCache;
    friend class ResourceLoader;
    template <typename T>
    friend class ImplResourceLoader;
    public:
       struct TextureLoadInfo {
           TextureLoadInfo() :
               _layerIndex(0),
               _cubeMapCount(0)
           {
           }

           U32 _layerIndex;
           U32 _cubeMapCount;
       };
    public:

    explicit Texture(GFXDevice& context,
                     size_t descriptorHash,
                     const stringImpl& name,
                     const stringImpl& resourceName,
                     const stringImpl& resourceLocation,
                     bool isFlipped,
                     bool asyncLoad,
                     const TextureDescriptor& texDescriptor);

    virtual ~Texture();

    /// Bind the texture to the specified texture unit
    virtual void bind(U8 slot) = 0;
    /// Bind a single level
    virtual void bindLayer(U8 slot, U8 level, U8 layer, bool layered, bool read, bool write) = 0;
    /// Change the texture's mip levels. This can be called at any time
    virtual void setMipMapRange(U16 base = 0, U16 max = 1000) {
    }
    /// Resize the texture to the specified dimensions and upload the new data
    virtual void resize(const bufferPtr ptr,
                        const vec2<U16>& dimensions) = 0;
    // API-dependent loading function that uploads ptr data to the GPU using the
    // specified parameters
    virtual void loadData(const TextureLoadInfo& info,
                          const vectorImpl<ImageTools::ImageLayer>& imageLayers) = 0;

    virtual void loadData(const TextureLoadInfo& info,
                          const bufferPtr data,
                          const vec2<U16>& dimensions) = 0;

    // Other must have same size!
    virtual void copy(const Texture_ptr& other) = 0;

    /// Specify the sampler descriptor used to sample from this texture in the shaders
    virtual void setCurrentSampler(const SamplerDescriptor& descriptor);

    /// Get the sampler descriptor used by this texture
    inline const SamplerDescriptor& getCurrentSampler() const {
        return _descriptor._samplerDescriptor;
    }

    inline TextureData getData() const {
        TextureData ret;
        ret.setHandleLow(_textureData.getHandleLow());
        ret.setHandleHigh(_textureData.getHandleHigh());
        ret._textureType = _descriptor.type();
        ret._samplerHash = _descriptor.getSampler().getHash();
        return ret;
    }

    /// 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 _descriptor._mipLevels.min; }
    /// Texture ax mip level
    inline U16 getMaxMipLevel() const { return _descriptor._mipLevels.max; }
    /// 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 hasTranslucency() const { return _hasTranslucency; }
    /// If the texture has an alpha channel and at least on pixel is fully transparent and
    // no pixels are partially transparent, 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 = true; }

    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(const DELEGATE_CBK<void, CachedResource_wptr>& onLoadCallback) override;
    virtual void threadedLoad(DELEGATE_CBK<void, CachedResource_wptr> onLoadCallback);
    /// Force a refresh of the entire mipmap chain
    virtual void updateMipMaps() { _mipMapsDirty = false; }

    virtual void validateDescriptor();

   protected:
    U32 _numLayers;
    U16 _width;
    U16 _height;
    bool _flipped;
    bool _mipMapsDirty;
    bool _hasTransparency;
    bool _hasTranslucency;
    bool _asyncLoad;
    TextureData  _textureData;
    TextureDescriptor _descriptor;

  protected:
    static const char* s_missingTextureFileName;
};

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
909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

907 Diff Diff IonutCava picture IonutCava Wed 28 Jun, 2017 23:16:40 +0000

[Ionut]
- Rework texture loading, mip map generation, sampler usage, etc
- ResourceDescriptor for textures now ONLY takes a TextureDescriptor as a property descriptor. Sampler must be assigned to the tex descriptor:
— ToDo: Separate samplers completely from textures and assign them from a pool to textures at bind time

905 Diff Diff IonutCava picture IonutCava Mon 26 Jun, 2017 15:56:21 +0000

[Ionut]
Untested code

- Rework RenderBin/RenderPass/RenderQueue system to allow per-bin type rendering decision
— Added to allow implementation of Weighted, Blended Order-Independent Transparency later on
- Better detection of transparency and translucency in textures and materials. Used to separate Alpha-Discard based geometry from OIT translucent geometry

885 Diff Diff IonutCava picture IonutCava Mon 27 Mar, 2017 21:16:49 +0000

[Ionut]
- Match terrain collision mesh with rendered mesh

863 Diff Diff IonutCava picture IonutCava Wed 15 Feb, 2017 16:27:26 +0000

[IonutCava]
- Split Resource class into Resource and CachedResource
— CachedResource is the only resource held in a ResourceCache and loaded from a ResourceDescriptor
— CachedResource is mapped by its creation descriptor’s hash value, instead of the resource name
-— Multiple cached resources can now exist with the same name if the have different properties, for example.

860 Diff Diff IonutCava picture IonutCava Mon 13 Feb, 2017 21:07:59 +0000

[IonutCava]
- Fix shared_ptr leak in resource loading callbacks

858 Diff Diff IonutCava picture IonutCava Sun 12 Feb, 2017 20:55:05 +0000

[IonutCava]
- More resource loading updates

856 Diff Diff IonutCava picture IonutCava Fri 10 Feb, 2017 17:19:06 +0000

[IonutCava]
- Attempt to improve resource creation mechanism by adding a callback for when the resource finishes loading
— This is useful for multi-threaded loading: shaders, textures, terrain, etc

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

832 IonutCava picture IonutCava Thu 26 Jan, 2017 17:23:11 +0000

[IonutCava]
- More path related work
- Initial code to centralize file I/O (does not compile yet)