Pyrogenesis  trunk
Texture.h
Go to the documentation of this file.
1 /* Copyright (C) 2022 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_RENDERER_BACKEND_GL_TEXTURE
19 #define INCLUDED_RENDERER_BACKEND_GL_TEXTURE
20 
21 #include "lib/ogl.h"
24 
25 #include <cstdint>
26 #include <memory>
27 
28 namespace Renderer
29 {
30 
31 namespace Backend
32 {
33 
34 namespace GL
35 {
36 
37 class CDevice;
38 
39 /**
40  * Represents a low-level GL texture, encapsulates all properties initialization.
41  */
42 class CTexture final : public ITexture
43 {
44 public:
45  ~CTexture() override;
46 
47  IDevice* GetDevice() override;
48 
49  Type GetType() const override { return m_Type; }
50  uint32_t GetUsage() const override { return m_Usage; }
51  Format GetFormat() const override { return m_Format; }
52 
53  uint32_t GetWidth() const override { return m_Width; }
54  uint32_t GetHeight() const override { return m_Height; }
55  uint32_t GetMIPLevelCount() const override { return m_MIPLevelCount; }
56 
57  GLuint GetHandle() const { return m_Handle; }
58 
59 private:
60  friend class CDevice;
61 
62  CTexture();
63 
64  CDevice* m_Device = nullptr;
65 
66  // GL before 3.3 doesn't support sampler objects, so each texture should have
67  // an own default sampler.
68  static std::unique_ptr<CTexture> Create(
69  CDevice* device, const char* name, const Type type, const uint32_t usage,
70  const Format format, const uint32_t width, const uint32_t height,
71  const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount);
72 
73  GLuint m_Handle = 0;
74 
81 };
82 
83 } // namespace GL
84 
85 } // namespace Backend
86 
87 } // namespace Renderer
88 
89 #endif // INCLUDED_RENDERER_BACKEND_GL_TEXTURE
Type m_Type
Definition: Texture.h:75
uint32_t m_Height
Definition: Texture.h:79
GLuint GetHandle() const
Definition: Texture.h:57
IDevice * GetDevice() override
Definition: Texture.cpp:320
Type
Definition: ITexture.h:36
Definition: ITexture.h:33
uint32_t m_Usage
Definition: Texture.h:76
CDevice * m_Device
Definition: Texture.h:64
~CTexture() override
Definition: Texture.cpp:313
Format
Definition: Format.h:27
uint32_t m_MIPLevelCount
Definition: Texture.h:80
uint32_t GetMIPLevelCount() const override
Definition: Texture.h:55
Definition: IDevice.h:47
static std::unique_ptr< CTexture > Create(CDevice *device, const char *name, const Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc &defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount)
Definition: Texture.cpp:90
Backend
Definition: Backend.h:27
uint32_t m_Width
Definition: Texture.h:78
Format GetFormat() const override
Definition: Texture.h:51
Type GetType() const override
Definition: Texture.h:49
Represents a low-level GL texture, encapsulates all properties initialization.
Definition: Texture.h:42
uint32_t GetUsage() const override
Definition: Texture.h:50
unsigned int uint32_t
Definition: wposix_types.h:53
Definition: VideoMode.h:28
GLuint m_Handle
Definition: Texture.h:73
Format m_Format
Definition: Texture.h:77
Definition: Sampler.h:56
uint32_t GetWidth() const override
Definition: Texture.h:53
uint32_t GetHeight() const override
Definition: Texture.h:54
Definition: Device.h:50