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
/*
   Copyright (c) 2018 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 CachedResource, public GraphicsResource {
    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 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) {
        ACKNOWLEDGE_UNUSED(base);
        ACKNOWLEDGE_UNUSED(max);
    }
    /// 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 {
        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 _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.getHandle(); }
    /// 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; }

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

    static U16 computeMipCount(U16 width, U16 height);

    virtual void refreshMipMaps(bool immediate) = 0;

   protected:
    /// Use STB/NV_DDS to load a file into a Texture Object
    bool loadFile(const TextureLoadInfo& info, const stringImpl& name, ImageTools::ImageData& fileData);
    /// 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);

    virtual void validateDescriptor();

   protected:
    U32 _numLayers;
    U16 _width;
    U16 _height;
    bool _flipped;
    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
1029 Diff Diff IonutCava picture IonutCava Tue 30 Jan, 2018 17:28:39 +0000

[Ionut]
- Update copyright notices

996 Diff Diff IonutCava picture IonutCava Tue 12 Dec, 2017 17:16:54 +0000

[Ionut]
- Update and improve SGN creation and destruction
- Fix cleanup issues
- Fix GPU object memory leaks
- Fix duplicate GUID values being generated
- Misc cleanups and optimizations

976 Diff Diff IonutCava picture IonutCava Sun 19 Nov, 2017 23:10:18 +0000

[Ionut]
- Texture mipmaps are now compute before bind if they need a refresh (to avoid recalculation if they’re not used)
- More work on the editor: cleanup, load/save functionality, etc
- Input scaling: Mouse position is now relative to the scene preview position in editor mode. (the scene preview rect is used to re-map X/Y absolute and relative mouse positions)

951 Diff Diff IonutCava picture IonutCava Mon 23 Oct, 2017 23:25:49 +0000

[Ionut]
- Added a new project to the solution: Divide-Editor
— This project will be a Unity-style tool for the framework built using IMGUI and ImWindow
— Examples:

- Modified DisplayWindow class heavily to support new requirements

938 Diff Diff IonutCava picture IonutCava Wed 16 Aug, 2017 21:35:55 +0000

[Ionut]
- Separate texture binding slot from TextureData
- Binding slot is now a property of the descriptor set
- Remove bind() calls from texture’s public interface
ToDo
- Add image layer binding options (addTextureLayer(data, binding, layer, ...)

920 Diff Diff IonutCava picture IonutCava Thu 27 Jul, 2017 22:16:17 +0000

[Ionut]
- Attempt to fix HiZConstructions. Didn’t work, but fixed some bugs in the process.

919 Diff Diff IonutCava picture IonutCava Wed 26 Jul, 2017 22:37:18 +0000

[Ionut]
- Add a configurable log printing system to the networking library.
- Remove the need to specify swap buffer necessity with endFrame calls. Swap buffer requirement is now a per-window property.
- Do not load an image file multiple times for the same texture. cache data for each array layer to speed up duplicates. ToDo: Cache data globally?
- Other small bugfixes

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 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