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