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

Author Topic: sf::Image private member "myTexture"  (Read 2754 times)

0 Members and 1 Guest are viewing this topic.

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
sf::Image private member "myTexture"
« on: December 01, 2011, 05:24:08 pm »
I am using sf::Image as a texture class. However, my implementation of resource manager makes calls to Bind() very unefficient.

I wanted to remember the texture number in some of my drawing calls, but got an unpassable problem - private.

I am not using sf::Image directly; I created my own wrapper class.
However, I wasn't able to access this field because I can't get access to it.

I used following code as a workaround, I'd however be very happy to see some of the private variables changed to protected or be given accessors in new API.

Code: [Select]
#define private protected
#include <SFML/Graphics/Image.hpp>
#define private private


//EDIT : this code, surprisingly, didn't work. I just edited the Image.hpp file and changed this.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Image private member "myTexture"
« Reply #1 on: December 01, 2011, 06:34:18 pm »
It's not private just to bother people. It's private to ensure a clean and consistent design.

Why do you need to access this member?
Laurent Gomila - SFML developer

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
sf::Image private member "myTexture"
« Reply #2 on: December 02, 2011, 06:12:23 pm »
Because I need to use it repeteadly in main loop. When I don't have access to it, I need to repeatedly dereference my resource pointer and then call bind. Also, my resource manager is pretty bad-designed right now, so getting resource pointer takes a little bit too much time.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Image private member "myTexture"
« Reply #3 on: December 02, 2011, 07:03:01 pm »
Why don't you store your resource pointer?

Or directly repair your design, so that no hacks in SFML are necessary? :P
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
sf::Image private member "myTexture"
« Reply #4 on: December 05, 2011, 11:41:31 am »
Well, i guess, maybe that problem is the sign that the redesign I've been planning for month can now commence ;p

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
sf::Image private member "myTexture"
« Reply #5 on: December 07, 2011, 09:31:37 pm »
I've found another example in which this accessor could be helpful:
Code: [Select]
glBindMultiTextureEXT()
It's direct access function (new in OpenGL 3.x I believe) which is considered to be much safer and cleaner than usual glActiveTexture/glBindTexture pair.

Of course, it requires the explicit texture number, hence the need for accessor.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Image private member "myTexture"
« Reply #6 on: December 07, 2011, 10:02:05 pm »
Why would you bind a sf::Image with this function, and not an OpenGL texture?
Laurent Gomila - SFML developer

bananu7

  • Newbie
  • *
  • Posts: 25
    • View Profile
sf::Image private member "myTexture"
« Reply #7 on: December 08, 2011, 11:36:47 am »
I use sf::Image to load image to memory. Additional benefit is that it automatically creates the openGL texture identifier, so I was using it - I mean, I gonna create it anyway, so why not?
But then, I needed to access this texture identifier. So I am using now glBindMultiTextureEXT with the texture identifier extracted from sf::Image. (with the hacked code i mentioned earlier).

One of the drawbacks is that I had to force pixel update through Bind().
I think that Bind could actually get a parameter describing what texture unit I want to bind my texture to.

Or do you think that I should not use sf::Image as texture container and use it only for loading purposes?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Image private member "myTexture"
« Reply #8 on: December 08, 2011, 12:15:03 pm »
Quote
Or do you think that I should not use sf::Image as texture container and use it only for loading purposes?

Definitely.
sf::Image is not a generic purpose texture wrapper, it's just the image class of the SFML graphics module, and it's only designed to work with the other classes of this module.
Laurent Gomila - SFML developer

 

anything