Skip to content

Commit feda1b9

Browse files
committed
Made texture properties caching
1 parent 4354708 commit feda1b9

File tree

16 files changed

+354
-144
lines changed

16 files changed

+354
-144
lines changed

doc/footer.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div id="footer-container">
33
<div id="footer">
44
Made by Ivan Kalinin<br>
5+
<a href="/">Docs home</a><br>
56
&nbsp;::&nbsp;Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> &nbsp;::&nbsp;
67
</div>
78
</div>

doc/header.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
1010
<script type="text/javascript" src="jquery.js"></script>
1111
<script type="text/javascript" src="dynsections.js"></script>
12+
<link rel="icon" href="/favicon.ico">
1213
<title>360vr</title>
1314
</head>
1415
<body>

engine/include/Rendering/FrameBuffer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ namespace ej
1313
class FrameBuffer final : public PointerDefs<FrameBuffer>
1414
{
1515
public:
16+
/**
17+
* \param core Main core object
18+
*/
19+
explicit FrameBuffer(const Core& core);
20+
1621
/**
1722
* \brief Destructor. Destroys all buffers
1823
*/

engine/include/Resources/Mesh.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <GL/glew.h>
44

5+
#include "Core/Core.h"
56
#include "MeshGeometry.h"
67
#include "Core/PointerDefs.h"
78

@@ -13,6 +14,11 @@ namespace ej
1314
class Mesh final : public PointerDefs<Mesh>
1415
{
1516
public:
17+
/**
18+
* \param core Main core object
19+
*/
20+
explicit Mesh(const Core& core);
21+
1622
/**
1723
* \brief Destructor. Destroys all buffers
1824
*/

engine/include/Resources/Shader.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#pragma once
22

3-
#include <unordered_map>
43
#include <vector>
54
#include <string>
5+
#include <unordered_map>
66

77
#include <GL/glew.h>
88
#include <glm/vec2.hpp>
99
#include <glm/vec3.hpp>
1010
#include <glm/vec4.hpp>
1111
#include <glm/mat4x4.hpp>
1212

13+
#include "Core/Core.h"
1314
#include "Core/PointerDefs.h"
1415

1516
namespace ej
@@ -26,7 +27,7 @@ namespace ej
2627
* Must not be constructed before any OpenGL context is
2728
* created.
2829
*/
29-
Shader();
30+
explicit Shader(const Core& core);
3031

3132
/**
3233
* \brief Destructor. Destroys native program object

engine/include/Resources/Texture.h

Lines changed: 160 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,198 @@
55
#include <GL/glew.h>
66
#include <glm/vec3.hpp>
77

8+
#include "Core/Core.h"
89
#include "Core/PointerDefs.h"
910

1011
namespace ej
1112
{
13+
class RenderingState;
14+
15+
/**
16+
* \brief Image living on the graphics card that can be used for drawing
17+
*/
1218
class Texture final : public PointerDefs<Texture>
1319
{
1420
public:
15-
Texture(GLenum target = GL_TEXTURE_2D);
21+
/**
22+
* \param core Main core object
23+
* \param target Target to which the texture is bound. Must be
24+
* one of GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
25+
* GL_TEXTURE_1D_ARRAY, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_RECTANGLE,
26+
* GL_TEXTURE_CUBE_MAP, GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BUFFER,
27+
* GL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_MULTISAMPLE_ARRAY
28+
*/
29+
explicit Texture(const Core& core, GLenum target = GL_TEXTURE_2D);
1630
~Texture();
1731

18-
// init as 1D texture
32+
/**
33+
* \brief Initialize as 1D texture
34+
*
35+
* Texture can be initialized only once.
36+
*
37+
* https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage1D.xhtml
38+
*
39+
* \param width Texture width in pixels
40+
* \param internalFormat number of color components in the texture
41+
* \param format format of the pixel data. Must be one of GL_RED,
42+
* GL_RG, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_RED_INTEGER,
43+
* GL_RG_INTEGER, GL_RGB_INTEGER, GL_BGR_INTEGER, GL_RGBA_INTEGER,
44+
* GL_BGRA_INTEGER, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT or
45+
* GL_DEPTH_STENCIL
46+
* \param type Data type of the pixel data. Must be one of
47+
* GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT,
48+
* GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT and etc.
49+
* \param data Pointer to the image data in memory
50+
* \return true if successfully initialized
51+
*/
1952
bool init(unsigned int width,
2053
GLenum internalFormat, GLenum format, GLenum type, const void* data);
2154

22-
// init as 2D texture
55+
/**
56+
* \brief Initialize as 2D texture
57+
*
58+
* Texture can be initialized only once.
59+
*
60+
* https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml
61+
*
62+
* \param width Texture width in pixels
63+
* \param height Texture height in pixels
64+
* \param internalFormat number of color components in the texture
65+
* \param format format of the pixel data. Must be one of GL_RED,
66+
* GL_RG, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_RED_INTEGER,
67+
* GL_RG_INTEGER, GL_RGB_INTEGER, GL_BGR_INTEGER, GL_RGBA_INTEGER,
68+
* GL_BGRA_INTEGER, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT or
69+
* GL_DEPTH_STENCIL
70+
* \param type Data type of the pixel data. Must be one of
71+
* GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT,
72+
* GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT and etc.
73+
* \param data Pointer to the image data in memory
74+
* \return true if successfully initialized
75+
*/
2376
bool init(unsigned int width, unsigned int height,
2477
GLenum internalFormat, GLenum format, GLenum type, const void* data);
2578

26-
// init as 3D texture
79+
/**
80+
* \brief Initialize as 3D texture
81+
*
82+
* Texture can be initialized only once.
83+
*
84+
* https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage3D.xhtml
85+
*
86+
* \param width Texture width in pixels. Must be > 1
87+
* \param height Texture height in pixels. Must be > 1
88+
* \param depth Texture depth in pixels. Must be > 1
89+
* \param internalFormat number of color components in the texture
90+
* \param format format of the pixel data. Must be one of GL_RED,
91+
* GL_RG, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_RED_INTEGER,
92+
* GL_RG_INTEGER, GL_RGB_INTEGER, GL_BGR_INTEGER, GL_RGBA_INTEGER,
93+
* GL_BGRA_INTEGER, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT or
94+
* GL_DEPTH_STENCIL
95+
* \param type Data type of the pixel data. Must be one of
96+
* GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT,
97+
* GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT and etc.
98+
* \param data Pointer to the image data in memory
99+
* \return true if successfully initialized
100+
*/
27101
bool init(unsigned int width, unsigned int height, unsigned int depth,
28102
GLenum internalFormat, GLenum format, GLenum type, const void* data);
29103

104+
/**
105+
* \brief Change size of texture
106+
*
107+
* Only needed components will be used.
108+
* E.g. for TEXTURE_2D - width and height.
109+
*
110+
* \param width New texture with in pixels
111+
* \param height New texture height in pixels
112+
* \param depth New texture depth in pixels
113+
*/
30114
void resize(unsigned int width, unsigned int height = 0, unsigned int depth = 0);
31115

32-
void setFilters(GLenum minFilter, GLenum maxFilter, bool bind = true);
33-
void setWrapMode(GLenum wrapMode, bool bind = true);
34-
116+
/**
117+
* \brief Change sampling arithmetic
118+
*
119+
* When this function is called before initialization, it just set
120+
* parameters locally. When it is called after initialization it will
121+
* change OpenGL state of this texture.
122+
*
123+
* Filter parameters must be one of: GL_NEAREST, GL_LINEAR
124+
*
125+
* \param minFilter Filter used for texture minimization
126+
* \param maxFilter Filter used for texture magnification
127+
*/
128+
void setFilters(GLenum minFilter, GLenum maxFilter);
129+
130+
/**
131+
* \brief Change texture wrapping for all dimensions
132+
*
133+
* When this function is called before initialization, it just set
134+
* parameters locally. When it is called after initialization it will
135+
* change OpenGL state of this texture.
136+
*
137+
* \param wrapMode Component values arithmetic outside [0, 1]. Must
138+
* be one of: GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT,
139+
* GL_REPEAT, or GL_MIRROR_CLAMP_TO_EDGE
140+
*/
141+
void setWrapMode(GLenum wrapMode);
142+
143+
/**
144+
* \brief Change texture wrapping for all dimensions
145+
*
146+
* When this function is called before initialization, it just set
147+
* parameters locally. When it is called after initialization it will
148+
* change OpenGL state of this texture.
149+
*
150+
* \param wrapMode Component values arithmetic outside [0, 1]. Must
151+
* be one of: GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT,
152+
* GL_REPEAT, or GL_MIRROR_CLAMP_TO_EDGE
153+
* \param component Component number. 0 - width, 1 - height, 2 - depth
154+
*/
155+
void setWrapMode(GLenum wrapMode, size_t component);
156+
157+
/**
158+
* \brief Generates LOD textures
159+
*
160+
* Must be called only after initialization
161+
*/
35162
void generateMipmap() const;
36163

164+
/**
165+
* \return Native OpenGL handle
166+
*/
37167
GLuint getHandle() const;
168+
169+
/**
170+
* \return Target to which the texture is bound
171+
*/
38172
GLenum getTarget() const;
39173

40-
glm::ivec3 getSize() const;
174+
/**
175+
* \return Texture dimensions. Useless components will be zeroed
176+
*/
177+
glm::uvec3 getSize() const;
41178

42179
private:
43-
GLuint m_id;
180+
static const unsigned DEFAULT_TEXTURE_UNIT = 16;
181+
182+
RenderingState* m_renderingState = nullptr;
183+
184+
GLuint m_id = 0;
44185
GLenum m_target;
45186

46-
GLenum m_internalFormat;
47-
GLenum m_format;
48-
GLenum m_type;
187+
GLenum m_internalFormat = GL_RGBA;
188+
GLenum m_format = GL_RGBA;
189+
GLenum m_type = GL_UNSIGNED_BYTE;
49190

50-
GLenum m_minFilter;
51-
GLenum m_maxFilter;
191+
GLenum m_minFilter = GL_LINEAR;
192+
GLenum m_maxFilter = GL_LINEAR;
52193

53-
GLenum m_wrapS;
54-
GLenum m_wrapT;
55-
GLenum m_wrapR;
194+
GLenum m_wrapS = GL_REPEAT;
195+
GLenum m_wrapT = GL_REPEAT;
196+
GLenum m_wrapR = GL_REPEAT;
56197

57-
glm::ivec3 m_size;
198+
glm::uvec3 m_size{};
58199

59-
bool m_initialized;
200+
bool m_initialized = false;
60201
};
61202
}

engine/src/Managers/MeshManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ej::PointerDefs<ej::Mesh>::ptr ej::MeshManager::get(const std::string& name)
2727

2828
ej::PointerDefs<ej::Mesh>::ptr ej::MeshManager::load(const Loader& loader) const
2929
{
30-
auto mesh = std::make_shared<Mesh>();
30+
auto mesh = std::make_shared<Mesh>(m_core);
3131
mesh->init(loader());
3232

3333
return mesh;

engine/src/Managers/ShaderManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::shared_ptr<ej::Shader> ej::ShaderManager::get(const std::string & name)
3232

3333
std::shared_ptr<ej::Shader> ej::ShaderManager::load(const FactoryData & factoryData) const
3434
{
35-
auto shader = std::make_unique<Shader>();
35+
auto shader = std::make_unique<Shader>(m_core);
3636

3737
std::string infoLog;
3838

@@ -85,5 +85,5 @@ std::shared_ptr<ej::Shader> ej::ShaderManager::load(const FactoryData & factoryD
8585
throw std::runtime_error("Unable to link shader: " + factoryData.name + ". " + infoLog);
8686
}
8787

88-
return std::move(shader);
88+
return shader;
8989
}

engine/src/Managers/TextureManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::shared_ptr<ej::Texture> ej::TextureManager::get(const std::string& name)
3232

3333
std::shared_ptr<ej::Texture> ej::TextureManager::load(const std::string& path) const
3434
{
35-
auto result = std::make_shared<Texture>();
35+
auto result = std::make_shared<Texture>(m_core);
3636

3737
const auto data = m_fileManager->open(path);
3838

engine/src/Rendering/FrameBuffer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
#include <stdexcept>
44

5+
ej::FrameBuffer::FrameBuffer(const Core& core) :
6+
m_colorTexture(core)
7+
{
8+
}
9+
510
ej::FrameBuffer::~FrameBuffer()
611
{
712
glDeleteFramebuffers(1, &m_id);

0 commit comments

Comments
 (0)