00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027 #include "renderstack/texture.hpp"
00028 #include "renderstack/rs_gl.h"
00029
00030 namespace renderstack {
00031
00032 renderbuffer::renderbuffer()
00033 {
00034 m_gl_renderbuffer_object = (unsigned int)(~0);
00035 }
00036
00037 renderbuffer::renderbuffer(int gl_renderbuffer_object)
00038 : m_gl_renderbuffer_object(gl_renderbuffer_object)
00039 {
00040 }
00041
00042 renderbuffer::renderbuffer(int width, int height, int gl_format, int sample_count)
00043 {
00044 m_gl_renderbuffer_object = (unsigned int)(~0);
00045 set(width, height, gl_format, sample_count);
00046 }
00047
00048 void renderbuffer::set(int gl_renderbuffer_object)
00049 {
00050 ::GLboolean is_renderbuffer = ::rs_gl_is_renderbuffer(m_gl_renderbuffer_object);
00051 if(is_renderbuffer)
00052 {
00053 ::rs_gl_delete_renderbuffers(1, &m_gl_renderbuffer_object);
00054 }
00055 m_gl_renderbuffer_object = gl_renderbuffer_object;
00056 }
00057
00058 void renderbuffer::set(int width, int height, int gl_format, int sample_count)
00059 {
00060 ::GLboolean is_renderbuffer = ::rs_gl_is_renderbuffer(m_gl_renderbuffer_object);
00061 if(is_renderbuffer)
00062 {
00063 ::rs_gl_delete_renderbuffers(1, &m_gl_renderbuffer_object);
00064 }
00065 ::rs_gl_gen_renderbuffers(1, &m_gl_renderbuffer_object);
00066
00067 ::rs_gl_bind_renderbuffer(GL_RENDERBUFFER, m_gl_renderbuffer_object);
00068
00069 ::rs_gl_renderbuffer_storage_multisample(
00070 GL_RENDERBUFFER,
00071 sample_count,
00072 gl_format,
00073 width,
00074 height
00075 );
00076 }
00077
00078 texture::texture()
00079 {
00080 m_gl_texture_object = (unsigned int)(~0);
00081 }
00082
00083 texture::texture(
00084 int width,
00085 int height,
00086 int gl_bind_target,
00087 int gl_teximage_target,
00088 int gl_minification_filter,
00089 int gl_magnification_filter,
00090 int gl_wrap,
00091 int gl_format
00092 )
00093 {
00094 m_gl_texture_object = (unsigned int)(~0);
00095 set(width, height, gl_bind_target, gl_teximage_target, gl_minification_filter, gl_magnification_filter, gl_wrap, gl_format);
00096 }
00097
00098 void texture::set(
00099 int width,
00100 int height,
00101 int gl_bind_target,
00102 int gl_teximage_target,
00103 int gl_minification_filter,
00104 int gl_magnification_filter,
00105 int gl_wrap,
00106 int gl_format
00107 )
00108 {
00109 m_width = width;
00110 m_height = height;
00111 m_gl_bind_target = gl_bind_target;
00112 m_gl_teximage_target = gl_teximage_target;
00113 m_gl_minification_filter = gl_minification_filter;
00114 m_gl_magnification_filter = gl_magnification_filter;
00115 m_gl_wrap = gl_wrap;
00116 m_gl_format = gl_format;
00117
00118 ::GLboolean is_texture = ::rs_gl_is_texture(m_gl_texture_object);
00119
00120 if(is_texture != GL_FALSE)
00121 {
00122 rs_gl_delete_textures(1, &m_gl_texture_object);
00123 }
00124
00125 ::rs_gl_gen_textures(1, &m_gl_texture_object);
00126 ::rs_gl_bind_texture(m_gl_bind_target, m_gl_texture_object);
00127 ::rs_gl_tex_image_2d(
00128 m_gl_teximage_target,
00129 0,
00130 m_gl_format,
00131 m_width,
00132 m_height,
00133 0,
00134 GL_RGB,
00135 GL_UNSIGNED_BYTE,
00136 NULL
00137 );
00138 }
00139
00140 void texture::set_data(std::vector<unsigned char> const &data)
00141 {
00142 ::rs_gl_bind_texture(m_gl_bind_target, m_gl_texture_object);
00143 ::rs_gl_tex_image_2d(
00144 m_gl_teximage_target,
00145 0,
00146 m_gl_format,
00147 m_width,
00148 m_height,
00149 0,
00150 GL_RGB,
00151 GL_UNSIGNED_BYTE,
00152 &data[0]
00153 );
00154 }
00155
00156 void texture::set_data(int format, unsigned char *data)
00157 {
00158 ::rs_gl_bind_texture(m_gl_bind_target, m_gl_texture_object);
00159 ::rs_gl_tex_image_2d(
00160 m_gl_teximage_target,
00161 0,
00162 m_gl_format,
00163 m_width,
00164 m_height,
00165 0,
00166 format,
00167 GL_UNSIGNED_BYTE,
00168 data
00169 );
00170 }
00171
00172 void texture::update()
00173 {
00174 ::rs_gl_bind_texture (m_gl_bind_target, m_gl_texture_object);
00175 ::rs_gl_tex_parameter_i(m_gl_bind_target, GL_TEXTURE_MAG_FILTER, m_gl_magnification_filter);
00176 ::rs_gl_tex_parameter_i(m_gl_bind_target, GL_TEXTURE_MIN_FILTER, m_gl_minification_filter);
00177 ::rs_gl_tex_parameter_i(m_gl_bind_target, GL_TEXTURE_WRAP_S, m_gl_wrap);
00178 ::rs_gl_tex_parameter_i(m_gl_bind_target, GL_TEXTURE_WRAP_T, m_gl_wrap);
00179 }
00180
00181 }
00182