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{
14
15
16MRVIEWER_API void setTextureWrapType( WrapType wrapType, GLenum type = GL_TEXTURE_2D );
17MRVIEWER_API void setTextureFilterType( FilterType filterType, GLenum type = GL_TEXTURE_2D );
18
21{
22public:
23 constexpr static GLuint NO_TEX = 0;
24
25 MRVIEWER_API GlTexture( GLenum val );
26
27 GlTexture( const GlTexture& ) = delete;
28 MRVIEWER_API GlTexture( GlTexture&& r );
29 MRVIEWER_API virtual ~GlTexture();
30
31 GlTexture& operator =( const GlTexture& ) = delete;
33 {
34 del(); textureID_ = r.textureID_; size_ = r.size_; r.detach_(); return *this;
35 }
36
37 auto getId() const { return textureID_; }
38 bool valid() const { return textureID_ != NO_TEX; }
39 size_t size() const { return size_; }
40
42 MRVIEWER_API void gen();
43
45 MRVIEWER_API void del();
46
48 MRVIEWER_API void bind();
49
50 struct Settings
51 {
56 Vector3i resolution;
57 size_t size() const
58 {
59 return size_t( resolution.x ) * resolution.y * resolution.z;
60 }
61
62 GLint internalFormat = GL_RGBA;
63 GLint format = GL_RGBA;
64 GLint type = GL_UNSIGNED_BYTE;
67 };
68
70 MRVIEWER_API void loadData( const Settings& settings, const char* arr );
71 template<typename C>
72 void loadData( const Settings& settings, const C& cont )
73 {
74 assert( cont.size() >= settings.size() );
75 loadData( settings, ( const char* )cont.data() );
76 }
77
79 MRVIEWER_API void loadDataOpt( bool refresh, const Settings& settings, const char* arr );
80 template<typename C>
81 void loadDataOpt( bool refresh, const Settings& settings, const C& cont )
82 {
83 assert( !refresh || cont.size() >= settings.size() );
84 loadDataOpt( refresh, settings, ( const char* )cont.data() );
85 }
86
87protected:
88 virtual void texImage_( const Settings& settings, const char* arr ) = 0;
90 size_t size_ = 0;
91 GLenum type_ = NO_TEX;
92
93private:
94
96 void detach_();
97};
98
99}
represents OpenGL texture owner, and allows uploading data in it remembering texture size
Definition MRGLTexture.h:21
WrapType
Definition MREnums.h:18
MRVIEWER_API void del()
deletes the texture
size_t size_
Definition MRGLTexture.h:90
size_t size() const
Definition MRGLTexture.h:39
MRVIEWER_API void setTextureWrapType(WrapType wrapType, GLenum type=GL_TEXTURE_2D)
virtual MRVIEWER_API ~GlTexture()
size_t size() const
Definition MRGLTexture.h:57
void loadData(const Settings &settings, const C &cont)
Definition MRGLTexture.h:72
GLenum type_
Definition MRGLTexture.h:91
GLint internalFormat
Definition MRGLTexture.h:62
static constexpr GLuint NO_TEX
Definition MRGLTexture.h:23
GLint format
Definition MRGLTexture.h:63
void loadDataOpt(bool refresh, const Settings &settings, const C &cont)
Definition MRGLTexture.h:81
auto getId() const
Definition MRGLTexture.h:37
MRVIEWER_API void loadDataOpt(bool refresh, const Settings &settings, const char *arr)
binds current texture to OpenGL context, optionally refreshing its data
WrapType wrap
Definition MRGLTexture.h:65
GlTexture(const GlTexture &)=delete
FilterType
Definition MREnums.h:12
MRVIEWER_API GlTexture(GLenum val)
virtual void texImage_(const Settings &settings, const char *arr)=0
FilterType filter
Definition MRGLTexture.h:66
MRVIEWER_API void gen()
generates new texture
MRVIEWER_API void loadData(const Settings &settings, const char *arr)
creates GL data texture using given data and binds it
GLuint textureID_
Definition MRGLTexture.h:89
MRVIEWER_API GlTexture(GlTexture &&r)
MRVIEWER_API void setTextureFilterType(FilterType filterType, GLenum type=GL_TEXTURE_2D)
GlTexture & operator=(const GlTexture &)=delete
GLint type
Definition MRGLTexture.h:64
MRVIEWER_API void bind()
binds current texture to OpenGL context
bool valid() const
Definition MRGLTexture.h:38
Vector3i resolution
Definition MRGLTexture.h:56
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRGLTexture.h:51