OpenGL with C ++: problems with vtable when passing an array of classes to glTexImage2d

I made a class Colorwith float r, float g, float b, float alpha. It has a base class with a virtual destructor .

I am trying to pass the Color array to an opengl function glTexImage2D, with an organization of GL_RGBAtype float (which will be an array of {float r, float g, float b, float alpha}). For this, you Coloronly need to contain 4 floats ( size 16 bytes ).

However, it sizeof(Color)shows that my class is 20 bytes in size due to the base class Colorhaving vtable , thanks to the destructor.

How can I save a vtable and still pass my array of colors to glTexImage2D?

+4
source share
2 answers

Short answer: No, you cannot do this.

You can see all the additional options for glTexImage2D()in the glPixelStore()documentation . As you can see, there are no options for adding a “step” or “fill” between pixels. There are options for adding space at the beginning or end of lines or between images (3D), but nothing between pixels.

: 4D- vtable . . , C, . , , .

, .

+4

gl stride , , , . sizeof(Color), , ... , , . . , float[4]...

, glTexImage2D , .

, : ? , , , / / .

POD , , , , POD, ..

+4

Source: https://habr.com/ru/post/1623477/


All Articles