MeshLib Documentation
Loading...
Searching...
No Matches
MRGLTexture.h
Go to the documentation of this file.
1#pragma once
2
3#include "exports.h"
4#include "MRMesh/MRMeshFwd.h"
5
6#include "MRGladGlfw.h"
7#include "MRMesh/MRVector3.h"
8
9namespace MR
10{
11
12MRVIEWER_API void setTextureWrapType( WrapType wrapType, GLenum type = GL_TEXTURE_2D );
13MRVIEWER_API void setTextureFilterType( FilterType filterType, GLenum type = GL_TEXTURE_2D );
14
15// represents OpenGL texture owner, and allows uploading data in it remembering texture size
17{
18public:
19 constexpr static GLuint NO_TEX = 0;
20
21 MRVIEWER_API GlTexture( GLenum val );
22
23 GlTexture( const GlTexture& ) = delete;
24 MRVIEWER_API GlTexture( GlTexture&& r );
25 MRVIEWER_API virtual ~GlTexture();
26
27 GlTexture& operator =( const GlTexture& ) = delete;
29 {
30 del(); textureID_ = r.textureID_; size_ = r.size_; r.detach_(); return *this;
31 }
32
33 auto getId() const { return textureID_; }
34 bool valid() const { return textureID_ != NO_TEX; }
35 size_t size() const { return size_; }
36
37 // generates new texture
38 MRVIEWER_API void gen();
39
40 // deletes the texture
41 MRVIEWER_API void del();
42
43 // binds current texture to OpenGL context
44 MRVIEWER_API void bind();
45
46 struct Settings
47 {
48 // the X and Y components are the dimensions of the target texture
49 // Z - 1 for texture2d
50 // Z - number of textures for texture2d array
51 // Z - Z dimensions for texture3d
52 Vector3i resolution;
53 size_t size() const
54 {
55 return size_t( resolution.x ) * resolution.y * resolution.z;
56 }
57
58 GLint internalFormat = GL_RGBA;
59 GLint format = GL_RGBA;
60 GLint type = GL_UNSIGNED_BYTE;
63 };
64
65 // creates GL data texture using given data and binds it
66 MRVIEWER_API void loadData( const Settings& settings, const char* arr );
67 template<typename C>
68 void loadData( const Settings& settings, const C& cont )
69 {
70 assert( cont.size() >= settings.size() );
71 loadData( settings, ( const char* )cont.data() );
72 }
73
74 // binds current texture to OpenGL context, optionally refreshing its data
75 MRVIEWER_API void loadDataOpt( bool refresh, const Settings& settings, const char* arr );
76 template<typename C>
77 void loadDataOpt( bool refresh, const Settings& settings, const C& cont )
78 {
79 assert( !refresh || cont.size() >= settings.size() );
80 loadDataOpt( refresh, settings, ( const char* )cont.data() );
81 }
82
83protected:
84 virtual void texImage_( const Settings& settings, const char* arr ) = 0;
86 size_t size_ = 0;
87 GLenum type_ = NO_TEX;
88
89private:
90
92 void detach_();
93};
94
95} //namespace MR
Definition MRGLTexture.h:17
MRVIEWER_API void del()
size_t size_
Definition MRGLTexture.h:86
size_t size() const
Definition MRGLTexture.h:35
virtual MRVIEWER_API ~GlTexture()
void loadData(const Settings &settings, const C &cont)
Definition MRGLTexture.h:68
GLenum type_
Definition MRGLTexture.h:87
static constexpr GLuint NO_TEX
Definition MRGLTexture.h:19
void loadDataOpt(bool refresh, const Settings &settings, const C &cont)
Definition MRGLTexture.h:77
auto getId() const
Definition MRGLTexture.h:33
MRVIEWER_API void loadDataOpt(bool refresh, const Settings &settings, const char *arr)
GlTexture(const GlTexture &)=delete
MRVIEWER_API GlTexture(GLenum val)
virtual void texImage_(const Settings &settings, const char *arr)=0
MRVIEWER_API void gen()
MRVIEWER_API void loadData(const Settings &settings, const char *arr)
GLuint textureID_
Definition MRGLTexture.h:85
MRVIEWER_API GlTexture(GlTexture &&r)
GlTexture & operator=(const GlTexture &)=delete
MRVIEWER_API void bind()
bool valid() const
Definition MRGLTexture.h:34
Definition MRCameraOrientationPlugin.h:8
WrapType
Definition MRMesh/MRMeshFwd.h:585
MRVIEWER_API void setTextureWrapType(WrapType wrapType, GLenum type=GL_TEXTURE_2D)
FilterType
Definition MRMesh/MRMeshFwd.h:579
MRVIEWER_API void setTextureFilterType(FilterType filterType, GLenum type=GL_TEXTURE_2D)
Definition MRGLTexture.h:47
size_t size() const
Definition MRGLTexture.h:53
GLint internalFormat
Definition MRGLTexture.h:58
GLint format
Definition MRGLTexture.h:59
WrapType wrap
Definition MRGLTexture.h:61
FilterType filter
Definition MRGLTexture.h:62
GLint type
Definition MRGLTexture.h:60
Vector3i resolution
Definition MRGLTexture.h:52