g4tools  5.4.0
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tools::sg::base_tex Class Referenceabstract
Inheritance diagram for tools::sg::base_tex:
Inheritance graph
[legend]
Collaboration diagram for tools::sg::base_tex:
Collaboration graph
[legend]

Public Types

enum  intersect_type { intersect_down, intersect_move, intersect_up }
 

Public Member Functions

virtual void * cast (const std::string &a_class) const
 
virtual bool intersect_value (std::ostream &, intersect_type a_type, const line< vec3f > &a_line, std::string &a_s) const =0
 
 base_tex ()
 
virtual ~base_tex ()
 
 base_tex (const base_tex &a_from)
 
base_texoperator= (const base_tex &a_from)
 

Public Attributes

sf_img< byteimg
 
sf_vec< colorf, float > back_color
 
sf< bool > expand
 
sf< unsigned int > limit
 
sf< bool > nearest
 

Protected Member Functions

void _update_sg_ (std::ostream &a_out)
 
void set_tcs (float a_tcs[8])
 

Static Protected Member Functions

static void dump (std::ostream &a_out, const std::string &a_cmt, const img_byte &a_img)
 
static void dump_not_null (std::ostream &a_out, const std::string &a_cmt, const img_byte &a_img)
 

Protected Attributes

img_byte m_img
 

Detailed Description

Definition at line 19 of file base_tex.

Member Enumeration Documentation

◆ intersect_type

Enumerator
intersect_down 
intersect_move 
intersect_up 

Definition at line 34 of file base_tex.

34  {
38  };

Constructor & Destructor Documentation

◆ base_tex() [1/2]

tools::sg::base_tex::base_tex ( )
inline

Definition at line 41 of file base_tex.

42  :img(img_byte())
43  ,back_color(colorf_white())
44  ,expand(false)
45  ,limit(device::tex_mem_limit()) //OpenGL-ES glTex limitation.
46  ,nearest(true)
47  ,m_img()
48  {}

◆ ~base_tex()

virtual tools::sg::base_tex::~base_tex ( )
inlinevirtual

Definition at line 49 of file base_tex.

49 {}

◆ base_tex() [2/2]

tools::sg::base_tex::base_tex ( const base_tex a_from)
inline

Definition at line 51 of file base_tex.

52  :img(a_from.img)
53  ,back_color(a_from.back_color)
54  ,expand(a_from.expand)
55  ,limit(a_from.limit)
56  ,nearest(a_from.nearest)
57  ,m_img()
58  {}

Member Function Documentation

◆ _update_sg_()

void tools::sg::base_tex::_update_sg_ ( std::ostream &  a_out)
inlineprotected

Definition at line 69 of file base_tex.

69  {
70  //clean_texs(); //must reset for all render_manager.
71 
72  const img_byte& _img = img.value();
73 
74  //::printf("debug : base_tex::_update_sg : size = %d, w = %d, h = %d, bpp %d\n",
75  // _img.size(),_img.width(),_img.height(),_img.bpp());
76 
77 
78  if(_img.is_empty()) {
79  m_img.make_empty();
80  return;
81  }
82 
83  unsigned int bpp = _img.bpp();
84  if((bpp!=1)&&(bpp!=3)&&(bpp!=4)) {
85  a_out << "tools::sg::tex_rect::update_sg :"
86  << " bpp " << bpp << " not handled."
87  << std::endl;
88  m_img.make_empty();
89  return;
90  }
91 
92  //a_out << "debug : tools::sg::tex_rect::update_sg :"
93  // << " this " << inlib::p2s(this)
94  // << std::endl;
95 
96  // image must be power of two in width and height.
97 
98  const colorf& bc = back_color.value();
99  //::printf("debug : back_color %g %g %g %g\n",bc.r(),bc.g(),bc.b(),bc.a());
100 
101  byte pixel[4];
102  pixel[0] = bc.ruchar();
103  pixel[1] = bc.guchar();
104  pixel[2] = bc.buchar();
105  pixel[3] = bc.auchar();
106 
107  //dump(a_out,"debug : 0000 :",_img);
108 
109  if((back_color.value().a()!=1)&&(bpp!=4)) {
110  //transparent background.
111 
112  //NOTE : the node must be rendered after the "behind nodes" so that
113  // transparency be taken into account for the "behind nodes".
114 
115  img_byte img4;
116  if(!_img.rgb2rgba(img4,255)){
117  a_out << "tools::sg::tex_rect::update_sg :"
118  << " rgb2rgba failed."
119  << std::endl;
120  m_img.make_empty();
121  return;
122  }
123 
124  if(!img4.to_texture(expand.value(),pixel,m_img)){
125  a_out << "tools::sg::tex_rect::update_sg :"
126  << " problem with inlib::tex_rect::to_texture."
127  << std::endl;
128  m_img.make_empty();
129  return;
130  }
131 
132  } else {
133  if(!_img.to_texture(expand.value(),pixel,m_img)){
134  a_out << "tools::sg::tex_rect::update_sg :"
135  << " problem with inlib::tex_rect::to_texture."
136  << std::endl;
137  m_img.make_empty();
138  return;
139  }
140  }
141 
142  //a_out << "debug : limit : 000 : " << limit.value() << std::endl;
143  if(limit.value()) {
144  unsigned int tw = m_img.width();
145  unsigned int th = m_img.height();
146  if((tw*th*m_img.bpp())>limit.value()) {
147  //a_out << "debug : trunc " << (tw*th) << std::endl;
148  unsigned int fac = 2;
149  while(true) {
150  unsigned int pw = tw/fac;
151  unsigned int ph = th/fac;
152  if((pw*ph)<limit.value()) {
153  unsigned int sx = (tw-pw)/2;
154  unsigned int sy = (th-ph)/2;
155 
156  img_byte part;
157  if(!m_img.get_part(sx,sy,pw,ph,part)) {
158  m_img.make_empty();
159  return;
160  }
161  //a_out << "debug : base_tex : img.get_part due to limit (" << limit.value() << ")." << std::endl;
162  m_img = part;
163  break;
164  }
165  fac *= 2;
166  }
167  }
168  }
169  //dump_not_null(a_out,"debug : base_tex::_update_sg_ :",m_img);
170 
171  }

◆ cast()

virtual void* tools::sg::base_tex::cast ( const std::string &  a_class) const
inlinevirtual

Reimplemented in tools::sg::tex_rect, and tools::sg::tex_quadrilateral.

Definition at line 23 of file base_tex.

23  {
24  if(void* p = cmp_cast<base_tex>(this,a_class)) return p;
25  return 0;
26  }

◆ dump()

static void tools::sg::base_tex::dump ( std::ostream &  a_out,
const std::string &  a_cmt,
const img_byte a_img 
)
inlinestaticprotected

Definition at line 173 of file base_tex.

173  {
174  if(a_cmt.size()) a_out << a_cmt << std::endl;
175  a_out << " width " << a_img.width()
176  << " height " << a_img.height()
177  << " bpp " << a_img.bpp()
178  << std::endl;
179  }

◆ dump_not_null()

static void tools::sg::base_tex::dump_not_null ( std::ostream &  a_out,
const std::string &  a_cmt,
const img_byte a_img 
)
inlinestaticprotected

Definition at line 181 of file base_tex.

181  {
182  if(a_cmt.size()) a_out << a_cmt << std::endl;
183  unsigned int w = a_img.width();
184  unsigned int h = a_img.height();
185  unsigned int n = a_img.bpp();
186  a_out << "img_byte : width " << w << " height " << h << " bpp " << n << std::endl;
187  byte* pos = (byte*)a_img.buffer();
188  if(n==3) {
189  byte r,g,b;
190  for(unsigned int j=0;j<h;j++) {
191  for(unsigned int i=0;i<w;i++) {
192  r = *pos;pos++;
193  g = *pos;pos++;
194  b = *pos;pos++;
195  if(r||g||b)
196  a_out << " " << i << " " << j
197  << " : " << (unsigned int)r << " " << (unsigned int)g << " " << (unsigned int)b
198  << std::endl;
199  }
200  }
201  }
202  }

◆ intersect_value()

virtual bool tools::sg::base_tex::intersect_value ( std::ostream &  ,
intersect_type  a_type,
const line< vec3f > &  a_line,
std::string &  a_s 
) const
pure virtual

◆ operator=()

base_tex& tools::sg::base_tex::operator= ( const base_tex a_from)
inline

Definition at line 59 of file base_tex.

59  {
60  img = a_from.img;
61  back_color = a_from.back_color;
62  expand = a_from.expand;
63  limit = a_from.limit;
64  nearest = a_from.nearest;
65  m_img.make_empty();
66  return *this;
67  }

◆ set_tcs()

void tools::sg::base_tex::set_tcs ( float  a_tcs[8])
inlineprotected

Definition at line 204 of file base_tex.

204  {
205  const img_byte& _img = img.value();
206 
207  a_tcs[0] = 0;a_tcs[1] = 0;
208  a_tcs[2] = 1;a_tcs[3] = 0;
209  a_tcs[4] = 1;a_tcs[5] = 1;
210  a_tcs[6] = 0;a_tcs[7] = 1;
211 
212  float ax = 1;
213  float bx = 0;
214  float ay = 1;
215  float by = 0;
216  {unsigned int iw = _img.width();
217  unsigned int ih = _img.height();
218  unsigned int rw = m_img.width();
219  unsigned int rh = m_img.height();
220  if(rw>iw) {
221  float part = float(iw)/float(rw);
222  ax = part;
223  bx = 0.5f*(1-part);
224  }
225  if(rh>ih) {
226  float part = float(ih)/float(rh);
227  ay = part;
228  by = 0.5f*(1-part);
229  }}
230 
231  {unsigned int num = 12/3;
232  for(unsigned int index=0;index<num;index++) {
233  a_tcs[2*index] = ax*a_tcs[2*index] +bx;
234  a_tcs[2*index+1] = ay*a_tcs[2*index+1]+by;
235  }}
236 
237  }

Member Data Documentation

◆ back_color

sf_vec<colorf,float> tools::sg::base_tex::back_color

Definition at line 29 of file base_tex.

◆ expand

sf<bool> tools::sg::base_tex::expand

Definition at line 30 of file base_tex.

◆ img

sf_img<byte> tools::sg::base_tex::img

Definition at line 28 of file base_tex.

◆ limit

sf<unsigned int> tools::sg::base_tex::limit

Definition at line 31 of file base_tex.

◆ m_img

img_byte tools::sg::base_tex::m_img
protected

Definition at line 239 of file base_tex.

◆ nearest

sf<bool> tools::sg::base_tex::nearest

Definition at line 32 of file base_tex.


The documentation for this class was generated from the following file:
tools::img_byte
img< unsigned char > img_byte
Definition: img:894
tools::sg::base_tex::intersect_down
@ intersect_down
Definition: base_tex:35
tools::device::tex_mem_limit
unsigned int tex_mem_limit()
Definition: platform:72
tools::sg::base_tex::intersect_up
@ intersect_up
Definition: base_tex:37
tools::sg::base_tex::back_color
sf_vec< colorf, float > back_color
Definition: base_tex:29
tools::img::width
unsigned int width() const
Definition: img:214
tools::sg::base_tex::limit
sf< unsigned int > limit
Definition: base_tex:31
tools::sg::base_tex::img
sf_img< byte > img
Definition: base_tex:28
tools::img::get_part
bool get_part(unsigned int a_sx, unsigned int a_sy, unsigned int a_sw, unsigned int a_sh, img< T > &a_res) const
Definition: img:470
tools::sg::base_tex::intersect_move
@ intersect_move
Definition: base_tex:36
tools::img::make_empty
void make_empty(bool a_delete=true)
Definition: img:186
tools::img::bpp
unsigned int bpp() const
Definition: img:217
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::img::height
unsigned int height() const
Definition: img:215
tools::sg::base_tex::expand
sf< bool > expand
Definition: base_tex:30
tools::sg::base_tex::m_img
img_byte m_img
Definition: base_tex:239
tools::sg::base_tex::nearest
sf< bool > nearest
Definition: base_tex:32