Line data Source code
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"
22 : #include "renderer/backend/ITexture.h"
23 : #include "renderer/backend/Sampler.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 0 : class CTexture final : public ITexture
43 : {
44 : public:
45 : ~CTexture() override;
46 :
47 : IDevice* GetDevice() override;
48 :
49 0 : Type GetType() const override { return m_Type; }
50 0 : uint32_t GetUsage() const override { return m_Usage; }
51 0 : Format GetFormat() const override { return m_Format; }
52 :
53 0 : uint32_t GetWidth() const override { return m_Width; }
54 0 : uint32_t GetHeight() const override { return m_Height; }
55 0 : uint32_t GetMIPLevelCount() const override { return m_MIPLevelCount; }
56 :
57 0 : 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 :
75 : Type m_Type = Type::TEXTURE_2D;
76 : uint32_t m_Usage = 0;
77 : Format m_Format = Format::UNDEFINED;
78 : uint32_t m_Width = 0;
79 : uint32_t m_Height = 0;
80 : uint32_t m_MIPLevelCount = 0;
81 : };
82 :
83 : } // namespace GL
84 :
85 : } // namespace Backend
86 :
87 : } // namespace Renderer
88 :
89 : #endif // INCLUDED_RENDERER_BACKEND_GL_TEXTURE
|