GlTextureResource.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef GLTEXTURERESOURCE_H
00011 #define GLTEXTURERESOURCE_H
00012
00013 #include "AppVerify.h"
00014 #include "Resource.h"
00015
00016 #include <QtOpenGL/QGLContext>
00017
00018
00019
00020
00021
00022
00023 class GlTextureObject
00024 {
00025 public:
00026
00027
00028
00029
00030 class Args
00031 {
00032 public:
00033 Args(GLsizei count) :
00034 mpContext(count <= 0 ? NULL : const_cast<QGLContext*>(QGLContext::currentContext())),
00035 mCount(count < 0 ? 0 : count)
00036 {}
00037
00038 QGLContext* mpContext;
00039 GLsizei mCount;
00040 };
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 GLuint* obtainResource(const Args& args) const
00051 {
00052 if (args.mCount <= 0)
00053 {
00054 return NULL;
00055 }
00056
00057 GLuint* pTextures = new GLuint[args.mCount];
00058 glGenTextures(args.mCount, pTextures);
00059 return pTextures;
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 void releaseResource(const Args& args, GLuint* pTextures) const
00072 {
00073 if (pTextures != NULL)
00074 {
00075 GlContextSave contextSave(args.mpContext);
00076 glDeleteTextures(args.mCount, pTextures);
00077 delete [] pTextures;
00078 }
00079 }
00080 };
00081
00082
00083
00084
00085
00086
00087
00088 class GlTextureResource : public Resource<GLuint, GlTextureObject>
00089 {
00090 public:
00091
00092
00093
00094
00095
00096
00097 GlTextureResource(GLsizei count) :
00098 Resource<GLuint, GlTextureObject>(GlTextureObject::Args(count))
00099 {}
00100
00101
00102
00103
00104
00105
00106
00107
00108 inline QGLContext* getContext() const
00109 {
00110 return getArgs().mpContext;
00111 }
00112
00113
00114
00115
00116
00117
00118 inline GLsizei getCount() const
00119 {
00120 return getArgs().mCount;
00121 }
00122
00123
00124
00125
00126
00127
00128 operator const GLuint*() const
00129 {
00130 return get();
00131 }
00132
00133
00134
00135
00136
00137
00138 operator GLuint() const
00139 {
00140 return getCount() <= 0 ? 0 : *get();
00141 }
00142 };
00143
00144 #endif