00001 #ifndef OPENTISSUE_GPU_TEXTURE_TEXTURE_CREATE_TEXTURE2D_H
00002 #define OPENTISSUE_GPU_TEXTURE_TEXTURE_CREATE_TEXTURE2D_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/gpu/texture/texture_texture2D.h>
00013 #include <OpenTissue/gpu/texture/gl_is_float_texture_supported.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace texture
00018 {
00029 inline texture2D_pointer create_float_texture(
00030 unsigned int width
00031 , unsigned int height
00032 , unsigned int components
00033 , float const * pixels
00034 )
00035 {
00036 GLenum internal_format;
00037 GLenum external_format;
00038 if (components == 1)
00039 {
00040 internal_format = GL_FLOAT_R32_NV;
00041 external_format = GL_RED;
00042 }
00043 else if (components == 2)
00044 {
00045
00046
00047 internal_format = GL_FLOAT_RG32_NV;
00048 external_format = GL_RED;
00049 }
00050 else if (components == 3)
00051 {
00052
00053 internal_format = GL_FLOAT_RGB32_NV;
00054 external_format = GL_RGB;
00055 }
00056 else if (components == 4)
00057 {
00058 internal_format = GL_FLOAT_RGBA32_NV;
00059 external_format = GL_RGBA;
00060 }
00061 else
00062 {
00063 std::cerr << "create_float_texture(): invalid number of components" << std::endl;
00064 return texture2D_pointer();
00065 }
00066 texture2D_pointer tex;
00067 tex.reset( new Texture2D ( internal_format, width, height, external_format, GL_FLOAT, pixels ) );
00068 tex->bind();
00069 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00070 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00071 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00072 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00073 return tex;
00074 }
00075
00088 inline texture2D_pointer create_float_texture_rectangle(
00089 unsigned int width
00090 , unsigned int height
00091 , unsigned int components
00092 , float const * pixels
00093 )
00094 {
00095 GLenum internal_format;
00096 GLenum external_format;
00097 if (components == 1)
00098 {
00099 internal_format = GL_FLOAT_R32_NV;
00100 external_format = GL_RED;
00101 }
00102 else if (components == 2)
00103 {
00104 internal_format = GL_FLOAT_RG32_NV;
00105 external_format = GL_RED;
00106 }
00107 else if (components == 3)
00108 {
00109
00110 internal_format = GL_FLOAT_RGB32_NV;
00111 external_format = GL_RGB;
00112 }
00113 else if (components == 4)
00114 {
00115 internal_format = GL_FLOAT_RGBA32_NV;
00116 external_format = GL_RGBA;
00117 }
00118 else
00119 {
00120 std::cerr << "create_float_texture_rectangle(): invalid number of components" << std::endl;
00121 return texture2D_pointer();
00122 }
00123 texture2D_pointer tex;
00124 tex.reset(
00125 new Texture2D ( internal_format, width, height, external_format, GL_FLOAT, pixels, true )
00126 );
00127 return tex;
00128 }
00129
00140 inline texture2D_pointer create_unsigned_byte_texture_rectangle(
00141 unsigned int width
00142 , unsigned int height
00143 , unsigned int components
00144 , unsigned char const * pixels
00145 )
00146 {
00147 GLenum internal_format;
00148 GLenum external_format;
00149 if (components == 3)
00150 {
00151 internal_format = GL_RGB8;
00152 external_format = GL_RGB;
00153 }
00154 else if (components == 4)
00155 {
00156 internal_format = GL_RGBA8;
00157 external_format = GL_RGBA;
00158 }
00159 else
00160 {
00161 std::cerr << "create_unsigned_byte_texture_rectangle(): invalid number of components" << std::endl;
00162 return texture2D_pointer();
00163 }
00164 texture2D_pointer tex;
00165 tex.reset( new Texture2D ( internal_format, width, height, external_format, GL_UNSIGNED_BYTE, pixels, true ) );
00166 tex->bind();
00167 glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
00168 glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
00169 glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00170 glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00171 return tex;
00172 }
00173
00184 inline texture2D_pointer create_unsigned_byte_texture(
00185 unsigned int width
00186 , unsigned int height
00187 , unsigned int components
00188 , const unsigned char *pixels
00189 )
00190 {
00191 GLenum internal_format;
00192 GLenum external_format;
00193 if (components == 3)
00194 {
00195 internal_format = GL_RGB8;
00196 external_format = GL_RGB;
00197 }
00198 else if (components == 4)
00199 {
00200 internal_format = GL_RGBA8;
00201 external_format = GL_RGBA;
00202 }
00203 else
00204 {
00205 std::cerr << "create_unsigned_byte_texture(): invalid number of components" << std::endl;
00206 return texture2D_pointer();
00207 }
00208 texture2D_pointer tex;
00209 tex.reset( new Texture2D ( internal_format, width, height, external_format, GL_UNSIGNED_BYTE, pixels ) );
00210 tex->bind();
00211 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00212 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00213 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00214 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00215 return tex;
00216 }
00217
00218 }
00219
00220 }
00221
00222
00223 #endif