Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2.0 RenderTextures are slow for me  (Read 8558 times)

0 Members and 3 Guests are viewing this topic.

zuon

  • Newbie
  • *
  • Posts: 15
    • View Profile
SFML 2.0 RenderTextures are slow for me
« on: April 27, 2012, 09:06:22 am »
Hi, new to SFML. Whipped this up (SFML 2.0)...

Code: [Select]
#include <iostream>
#include <cmath>

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

using namespace std;

int main(){
//create a window
///sf::RenderWindow window(sf::VideoMode(640, 480, 32), "test", sf::Style::Close|sf::Style::Fullscreen);
sf::RenderWindow window(sf::VideoMode(640, 480, 32), "test", sf::Style::Close);
//textures
sf::Texture sceneTexture, lightTexture;
sceneTexture.loadFromFile("scene.png");
lightTexture.loadFromFile("light.png");
//sprites
sf::Sprite sceneSprite, lightSprite;
sceneSprite.setTexture(sceneTexture);
lightSprite.setTexture(lightTexture);
//render textures
sf::RenderTexture scene, light;
scene.create(window.getSize().x, window.getSize().y);
light.create(window.getSize().x, window.getSize().y);
//clock
sf::Clock clock;
//render states
sf::RenderStates add, multiply;
add=sf::RenderStates::Default;
add.blendMode=sf::BlendAdd;
multiply=sf::RenderStates::Default;
multiply.blendMode=sf::BlendMultiply;
//loop
while(window.isOpen()){
sf::Event sfEvent;
while(window.pollEvent(sfEvent))
switch(sfEvent.type){
case sf::Event::Closed: window.close(); break;
case sf::Event::KeyPressed:
if(sfEvent.key.code==sf::Keyboard::Q) window.close();
break;
default: break;
}
lightSprite.setOrigin(sin(clock.getElapsedTime().asSeconds())*100+50, 0);
scene.clear();
light.clear();
scene.draw(sceneSprite);
light.draw(lightSprite, add);
scene.display();
light.display();
window.clear();
window.draw(sf::Sprite(scene.getTexture()));
window.draw(sf::Sprite(light.getTexture()), multiply);
window.display();
sf::sleep(sf::seconds(1/60.0f));
}
//finish
return 0;
}

Found clearing, drawing, and displaying RenderTextures was very slow and processor intensive. Is there a faster way to do this? Is my computer lacking and the rendering being done in software? Do I need to wait for kinks to be sorted out?

Code and images available here:
http://dl.dropbox.com/u/67501358/zuon.zip

zuon

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.0 RenderTextures are slow for me
« Reply #1 on: April 27, 2012, 09:36:29 am »
Tried it on a different computer and it ran much faster. What OpenGL extensions are used by RenderTexture?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.0 RenderTextures are slow for me
« Reply #2 on: April 27, 2012, 12:01:25 pm »
FBO, or nothing (render to a hidden context) if they are not supported.
Laurent Gomila - SFML developer

zuon

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.0 RenderTextures are slow for me
« Reply #3 on: April 27, 2012, 07:08:57 pm »
The computer that runs slow has
Code: [Select]
GL_EXT_blend_minmax
GL_EXT_blend_subtract
GL_EXT_blend_color
GL_EXT_abgr
GL_EXT_texture3D
GL_EXT_clip_volume_hint
GL_EXT_compiled_vertex_array
GL_SGIS_texture_edge_clamp
GL_SGIS_generate_mipmap
GL_EXT_draw_range_elements
GL_SGIS_texture_lod
GL_EXT_rescale_normal
GL_EXT_packed_pixels
GL_EXT_separate_specular_color
GL_ARB_multitexture
GL_EXT_texture_env_combine
GL_EXT_bgra
GL_EXT_blend_func_separate
GL_EXT_secondary_color
GL_EXT_fog_coord
GL_EXT_texture_env_add
GL_ARB_texture_cube_map
GL_ARB_transpose_matrix
GL_ARB_texture_env_add
GL_IBM_texture_mirrored_repeat
GL_EXT_multi_draw_arrays
GL_NV_blend_square
GL_ARB_texture_compression
GL_3DFX_texture_compression_FXT1
GL_EXT_texture_filter_anisotropic
GL_ARB_texture_border_clamp
GL_ARB_point_parameters
GL_ARB_texture_env_combine
GL_ARB_texture_env_dot3
GL_ARB_texture_env_crossbar
GL_EXT_texture_compression_s3tc
GL_ARB_shadow
GL_ARB_window_pos
GL_EXT_shadow_funcs
GL_EXT_stencil_wrap
GL_ARB_vertex_program
GL_EXT_texture_rectangle
GL_ARB_fragment_program
GL_EXT_stencil_two_side
GL_ATI_separate_stencil
GL_ARB_vertex_buffer_object
GL_EXT_texture_lod_bias
GL_ARB_occlusion_query
GL_ARB_fragment_shader
GL_ARB_shader_objects
GL_ARB_shading_language_100
GL_ARB_texture_non_power_of_two
GL_ARB_vertex_shader
GL_NV_texgen_reflection
GL_ARB_point_sprite
GL_EXT_blend_equation_separate
GL_ARB_depth_texture
GL_ARB_texture_rectangle
GL_ARB_draw_buffers
GL_ARB_pixel_buffer_object
GL_WIN_swap_hint
GL_EXT_framebuffer_object
GL_EXT_texture_sRGB
GL_ARB_color_buffer_float
GL_ARB_half_float_pixel
GL_ARB_texture_float
GL_NV_conditional_render
GL_EXT_texture_swizzle

And the computer that runs fast has
Code: [Select]
GL_ARB_color_buffer_float
GL_ARB_compressed_texture_pixel_storage
GL_ARB_conservative_depth
GL_ARB_copy_buffer
GL_ARB_depth_clamp
GL_ARB_depth_texture
GL_ARB_draw_buffers
GL_ARB_ES2_compatibility
GL_ARB_explicit_attrib_location
GL_ARB_fragment_program
GL_ARB_fragment_program_shadow
GL_ARB_fragment_shader
GL_ARB_framebuffer_object
GL_ARB_get_program_binary
GL_ARB_half_float_pixel
GL_ARB_half_float_vertex
GL_ARB_imaging
GL_ARB_internalformat_query
GL_ARB_map_buffer_alignment
GL_ARB_map_buffer_range
GL_ARB_multisample
GL_ARB_multitexture
GL_ARB_occlusion_query
GL_ARB_occlusion_query2
GL_ARB_pixel_buffer_object
GL_ARB_point_parameters
GL_ARB_point_sprite
GL_ARB_provoking_vertex
GL_ARB_robustness
GL_ARB_sampler_objects
GL_ARB_separate_shader_objects
GL_ARB_shader_objects
GL_ARB_shading_language_100
GL_ARB_shading_language_420pack
GL_ARB_shading_language_include
GL_ARB_shadow
GL_ARB_sync
GL_ARB_texture_border_clamp
GL_ARB_texture_compression
GL_ARB_texture_cube_map
GL_ARB_texture_env_add
GL_ARB_texture_env_combine
GL_ARB_texture_env_crossbar
GL_ARB_texture_env_dot3
GL_ARB_texture_float
GL_ARB_texture_mirrored_repeat
GL_ARB_texture_non_power_of_two
GL_ARB_texture_rectangle
GL_ARB_texture_rg
GL_ARB_texture_storage
GL_ARB_texture_swizzle
GL_ARB_timer_query
GL_ARB_transpose_matrix
GL_ARB_vertex_array_bgra
GL_ARB_vertex_array_object
GL_ARB_vertex_buffer_object
GL_ARB_vertex_program
GL_ARB_vertex_shader
GL_ARB_window_pos
GL_ATI_draw_buffers
GL_ATI_texture_float
GL_ATI_texture_mirror_once
GL_S3_s3tc
GL_EXT_texture_env_add
GL_EXT_abgr
GL_EXT_bgra
GL_EXT_blend_color
GL_EXT_blend_equation_separate
GL_EXT_blend_func_separate
GL_EXT_blend_minmax
GL_EXT_blend_subtract
GL_EXT_compiled_vertex_array
GL_EXT_Cg_shader
GL_EXT_depth_bounds_test
GL_EXT_direct_state_access
GL_EXT_draw_range_elements
GL_EXT_fog_coord
GL_EXT_framebuffer_blit
GL_EXT_framebuffer_multisample
GL_EXT_framebuffer_object
GL_EXT_gpu_program_parameters
GL_EXT_multi_draw_arrays
GL_EXT_packed_depth_stencil
GL_EXT_packed_pixels
GL_EXT_pixel_buffer_object
GL_EXT_point_parameters
GL_EXT_provoking_vertex
GL_EXT_rescale_normal
GL_EXT_secondary_color
GL_EXT_separate_shader_objects
GL_EXT_separate_specular_color
GL_EXT_shadow_funcs
GL_EXT_stencil_two_side
GL_EXT_stencil_wrap
GL_EXT_texture3D
GL_EXT_texture_compression_dxt1
GL_EXT_texture_compression_s3tc
GL_EXT_texture_cube_map
GL_EXT_texture_edge_clamp
GL_EXT_texture_env_combine
GL_EXT_texture_env_dot3
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_format_BGRA8888
GL_EXT_texture_lod
GL_EXT_texture_lod_bias
GL_EXT_texture_mirror_clamp
GL_EXT_texture_object
GL_EXT_texture_sRGB
GL_EXT_texture_sRGB_decode
GL_EXT_texture_storage
GL_EXT_texture_swizzle
GL_EXT_timer_query
GL_EXT_vertex_array
GL_EXT_vertex_array_bgra
GL_EXT_import_sync_object
GL_IBM_rasterpos_clip
GL_IBM_texture_mirrored_repeat
GL_KTX_buffer_region
GL_NV_alpha_test
GL_NV_blend_minmax
GL_NV_blend_square
GL_NV_complex_primitives
GL_NV_copy_depth_to_color
GL_NV_depth_clamp
GL_NV_fbo_color_attachments
GL_NV_fence
GL_NV_float_buffer
GL_NV_fog_distance
GL_NV_fragdepth
GL_NV_fragment_program
GL_NV_fragment_program_option
GL_NV_fragment_program2
GL_NV_framebuffer_multisample_coverage
GL_NV_half_float
GL_NV_light_max_exponent
GL_NV_multisample_filter_hint
GL_NV_occlusion_query
GL_NV_packed_depth_stencil
GL_NV_pixel_data_range
GL_NV_point_sprite
GL_NV_primitive_restart
GL_NV_register_combiners
GL_NV_register_combiners2
GL_NV_texgen_reflection
GL_NV_texture_barrier
GL_NV_texture_compression_vtc
GL_NV_texture_env_combine4
GL_NV_texture_expand_normal
GL_NV_texture_lod_clamp
GL_NV_texture_rectangle
GL_NV_texture_shader
GL_NV_texture_shader2
GL_NV_texture_shader3
GL_NV_vertex_array_range
GL_NV_vertex_array_range2
GL_NV_vertex_program
GL_NV_vertex_program1_1
GL_NV_vertex_program2
GL_NV_vertex_program2_option
GL_NV_vertex_program3
GL_NVX_conditional_render
GL_OES_depth24
GL_OES_depth32
GL_OES_depth_texture
GL_OES_element_index_uint
GL_OES_fbo_render_mipmap
GL_OES_get_program_binary
GL_OES_mapbuffer
GL_OES_packed_depth_stencil
GL_OES_rgb8_rgba8
GL_OES_standard_derivatives
GL_OES_texture_3D
GL_OES_texture_float
GL_OES_texture_float_linear
GL_OES_texture_half_float
GL_OES_texture_half_float_linear
GL_OES_texture_npot
GL_OES_vertex_array_object
GL_OES_vertex_half_float
GL_SGIS_generate_mipmap
GL_SGIS_texture_lod
GL_SGIX_depth_texture
GL_SGIX_shadow
GL_SUN_slice_accum
GL_WIN_swap_hint
WGL_EXT_swap_control

In particular, the slow one does have GL_EXT_framebuffer_object.

And in particular, the fast one has:
GL_ARB_framebuffer_object
GL_EXT_framebuffer_blit
GL_EXT_framebuffer_multisample
GL_EXT_framebuffer_object
GL_NV_framebuffer_multisample_coverage
GL_NV_fbo_color_attachments
GL_OES_fbo_render_mipmap

When you say FBO, do you mean GL_ARB_framebuffer_object? Or more?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.0 RenderTextures are slow for me
« Reply #4 on: April 27, 2012, 07:32:17 pm »
Quote
When you say FBO, do you mean GL_ARB_framebuffer_object?
Yep, I mean this one. Would it be possible for you to do a modification to SFML and test if it's faster? Ie. add GL_EXT_framebuffer_object to the test in RenderTextureImplFBO::isAvailable.
Laurent Gomila - SFML developer

zuon

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.0 RenderTextures are slow for me
« Reply #5 on: April 27, 2012, 08:51:56 pm »
Yeah, I'd be happy to help. I'll give it a go tonight. I haven't compiled from source yet, so it might be a little while.

Just to be clear, the goal is to allow SFML 2.0 to use either FBO variation for RenderTexture?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.0 RenderTextures are slow for me
« Reply #6 on: April 27, 2012, 10:35:44 pm »
Yep :)
Laurent Gomila - SFML developer

zuon

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.0 RenderTextures are slow for me
« Reply #7 on: April 28, 2012, 04:58:31 am »
When I got there, RenderTextureImplFBO::isAvailable was already checking for GL_EXT_framebuffer_object only. I stuck in some printfs.

Code: [Select]
bool RenderTextureImplFBO::isAvailable()
{
    ensureGlContext();

    // Make sure that GLEW is initialized
    priv::ensureGlewInit();

    if(GLEW_EXT_framebuffer_object!=0) printf("GLEW_EXT_framebuffer_object!=0\n");
    else printf("GLEW_EXT_framebuffer_object==0\n");
    fflush(stdout);

    return GLEW_EXT_framebuffer_object != 0;
}

And got this output:

Code: [Select]
GLEW_EXT_framebuffer_object!=0
GLEW_EXT_framebuffer_object!=0

Any ideas as to what that means? I'm going to delve into the code a bit.

zuon

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.0 RenderTextures are slow for me
« Reply #8 on: April 28, 2012, 06:28:41 am »
Doesn't seem to be any obvious gotchas -- it's using hardware.

In particular, I don't think it's the wglMakeCurrent function in WglContext::makeCurrent, which apparently can be slow. I measured it and it takes anywhere from 0 to 4 ms. Which isn't happily fast, but at 60 fps, I get 16 ms per frame (I know I'm doing a hard 16ms delay, but I think it's still a meaningful calculation).

Is it possible that the hardware is that slow? I don't know if I should've said this up front, but the graphics card is integrated. Specs here:
http://support.acer.com/acerpanam/notebook/2009/acer/aspire/Aspire4810TZ/Aspire4810TZsp2.shtml
Just seems stupid to have a hardware implementation of something that's as slow as software though... hm... Hah! It's WAY slower than software. Or whatever I get when I force RenderTextureImplFBO::isAvailable to return false.

I'm going to check out what the default implementation is out of interest, but I'm out of ideas otherwise. Oh, is there a way to profile OpenGL performance so I can be sure of whether or not it's the hardware's fault?

zuon

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.0 RenderTextures are slow for me
« Reply #9 on: April 28, 2012, 06:39:52 am »
The plot thickens again -- I ran the executable produced by Visual Studio from outside and it ran much faster.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.0 RenderTextures are slow for me
« Reply #10 on: April 28, 2012, 09:22:09 am »
Quote
When I got there, RenderTextureImplFBO::isAvailable was already checking for GL_EXT_framebuffer_object only.
OH, so it was already correct, sorry I had forgotten.

Quote
I ran the executable produced by Visual Studio from outside and it ran much faster.
You are (were) not running it in Debug mode, are you?
Laurent Gomila - SFML developer

zuon

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.0 RenderTextures are slow for me
« Reply #11 on: April 28, 2012, 07:40:42 pm »
I tried both. It's inconsequential. That is, both debug and release run slow from VS, and both run fast when run from outside VS. There's should be very little CPU work here, right?

zuon

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.0 RenderTextures are slow for me
« Reply #12 on: April 28, 2012, 07:47:40 pm »
Hm. So I just learned there's further debug/non-debug in VS -- F5 debugs (whether in release or debug configuration) and ctrl-F5 doesn't. When I use ctrl-f5, the program runs fine.

First time I've seen the program slowed down this way, so I still don't get why the slowing happens, but it's not a big issue.