@@ -229,21 +229,11 @@ void BackgroundGLArea::show_image(Glib::RefPtr<BackgroundImage> next_image)
229
229
to_image = next_image;
230
230
231
231
int width, height;
232
- if (from_image)
233
- {
234
- from_image->generate_adjustments (background->window_width , background->window_height );
235
- width = from_image->source ->get_width ();
236
- height = from_image->source ->get_height ();
237
- glBindTexture (GL_TEXTURE_2D, from_tex);
238
- auto format = from_image->source ->get_has_alpha () ? GL_RGBA : GL_RGB;
239
- glTexImage2D (GL_TEXTURE_2D, 0 , format, width, height, 0 , format, GL_UNSIGNED_BYTE,
240
- from_image->source ->get_pixels ());
241
- }
242
232
243
233
to_image->generate_adjustments (background->window_width , background->window_height );
244
234
width = to_image->source ->get_width ();
245
235
height = to_image->source ->get_height ();
246
- glBindTexture (GL_TEXTURE_2D, to_tex );
236
+ glBindTexture (GL_TEXTURE_2D, to_image-> tex_id );
247
237
auto format = to_image->source ->get_has_alpha () ? GL_RGBA : GL_RGB;
248
238
glTexImage2D (GL_TEXTURE_2D, 0 , format, width, height, 0 , format, GL_UNSIGNED_BYTE,
249
239
to_image->source ->get_pixels ());
@@ -258,6 +248,31 @@ void BackgroundGLArea::show_image(Glib::RefPtr<BackgroundImage> next_image)
258
248
this ->queue_draw ();
259
249
}
260
250
251
+ static GLuint create_texture ()
252
+ {
253
+ GLuint tex;
254
+
255
+ glGenTextures (1 , &tex);
256
+ glBindTexture (GL_TEXTURE_2D, tex);
257
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
258
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
259
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
260
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
261
+ glBindTexture (GL_TEXTURE_2D, 0 );
262
+
263
+ return tex;
264
+ }
265
+
266
+ BackgroundImage::BackgroundImage ()
267
+ {
268
+ tex_id = create_texture ();
269
+ }
270
+
271
+ BackgroundImage::~BackgroundImage ()
272
+ {
273
+ glDeleteTextures (1 , &tex_id);
274
+ }
275
+
261
276
Glib::RefPtr<BackgroundImage> WayfireBackground::create_from_file_safe (std::string path)
262
277
{
263
278
Glib::RefPtr<BackgroundImage> image = Glib::RefPtr<BackgroundImage>(new BackgroundImage ());
@@ -451,27 +466,10 @@ void WayfireBackground::reset_cycle_timeout()
451
466
}
452
467
}
453
468
454
- static GLuint create_texture ()
455
- {
456
- GLuint tex;
457
-
458
- glGenTextures (1 , &tex);
459
- glBindTexture (GL_TEXTURE_2D, tex);
460
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
461
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
462
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
463
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
464
- glBindTexture (GL_TEXTURE_2D, 0 );
465
-
466
- return tex;
467
- }
468
-
469
469
void BackgroundGLArea::realize ()
470
470
{
471
471
this ->make_current ();
472
472
program = init_shaders ();
473
- from_tex = create_texture ();
474
- to_tex = create_texture ();
475
473
}
476
474
477
475
bool BackgroundGLArea::render (const Glib::RefPtr<Gdk::GLContext>& context)
@@ -509,12 +507,15 @@ bool BackgroundGLArea::render(const Glib::RefPtr<Gdk::GLContext>& context)
509
507
glClearColor (0.0 , 0.0 , 0.0 , 1.0 );
510
508
glClear (GL_COLOR_BUFFER_BIT);
511
509
glUseProgram (program);
512
- glActiveTexture (GL_TEXTURE0);
513
- glBindTexture (GL_TEXTURE_2D, from_tex);
514
- GLuint from_tex_uniform = glGetUniformLocation (program, " bg_texture_from" );
515
- glUniform1i (from_tex_uniform, 0 );
510
+ if (from_image)
511
+ {
512
+ glActiveTexture (GL_TEXTURE0);
513
+ glBindTexture (GL_TEXTURE_2D, from_image->tex_id );
514
+ GLuint from_tex_uniform = glGetUniformLocation (program, " bg_texture_from" );
515
+ glUniform1i (from_tex_uniform, 0 );
516
+ }
516
517
glActiveTexture (GL_TEXTURE1);
517
- glBindTexture (GL_TEXTURE_2D, to_tex );
518
+ glBindTexture (GL_TEXTURE_2D, to_image-> tex_id );
518
519
GLuint to_tex_uniform = glGetUniformLocation (program, " bg_texture_to" );
519
520
glUniform1i (to_tex_uniform, 1 );
520
521
glEnableVertexAttribArray (0 );
0 commit comments