Packed record are usually only required when you need to load/save data in a consistent way between different compilers or even languages, or when passing to programming API routines.
Besides that, I haven't noticed any slowdown when using packed records compared to normal records
Games:
Seafox
Pages:
Syntax Error Software
itch.io page
Online Chess
http://gameknot.com/#paul_nicholls
a packed record prevents the compiler from inserting any space into your record if the compiler were to somehow change the size of your record then opengl would not understand these changes and would not work as expected.
I figured out that for the world made of cubes it might be worth a try to feed points to the vertex shader instead of triangles and build cubes in the geometry shader. So I did and it seems to work. But only on the integrated graphics card I have 2 in my laptop and when I switch to nvidia all I see is darkness. Integrated driver says it's opengl 3.1 and nvidia's is 4.3. Can I somehow force nvidia to work in 'older' mode? all the tuts I've seen either use glew or glut (which i don't) to initialize the context so I'm confused how to do that
Can you show shader code? Graphics cards are very picky about that.
hey, you were right i've run test with simplest shaders which resulted in black screen also so after some tinkering with syntax now everything works. too bad that shader linker didn't bother with reporting any problems
Example you quoted says packed, but it is actually byte-aligned to 32 and 64 bit, so it wouldn't make any difference.
This is not aligned. But if you make it an array and compare size:Code:TRGB1 = packed record r, g, b: byte; end;
The arr1 is 256-1280 bytes smaller than arr2. This is because if you take sizeof(TRGB1) you would get 3, but sizeof(TRGB2) would give you 4 or 8 depending on if you compile with 32 or 64 bit compiler, i guess... Now if you're dealing with OpenGL functions, you need to tell it exactly the structure of the data you are using. For that there is usually a "stride"-parameter, to describe the spacing. If you would send it color data, you should use TRGB1 style with size 3 bytes. All the data is in tight sequence without spaces in between. But actually you will notice that most records will be byte aligned anyway.Code:TRGB2 = record r, g, b: byte; end; arr1: array[0..255] of TRGB1; arr2: array[0..255] of TRGB2;
For example shader vertex-data, that will propably be the most time-critical array of them all, is byte-aligned no matter how you twist it:
Code:TModelVertex = packed record v, n: TVector; // 12+12 bytes uv: TVector2f; // 8 bytes end; // = 24+8 = 32 => 32/8 = 4 => aligned to 64 bits
Err, you got it wrong. For the sake of completeness I've just put your data types into FPC/Lazarus (1.0.2) and Delphi XE 3, and SizeOf(arr1) = SizeOf(arr2) = 768; SizeOf(TRGB1) = SizeOf(TRGB2) = 3.
Data alignment works by aligning starting offset of your data, not the size of your data. I also believe that for such cases, "packed" keyword is deprecated, at least in Delphi. What you probably meant was data padding, but I don't see how it can be useful for TRGB1/TRGB2 in terms of performance.
Edit: according to $Align option manual, I could reproduce data padding in the following example:
In above example, "packed" keyword does seems to have effect, specifically for "TinyValue".Code:type TSomeRecord = record TinyValue: Byte; BigValue: Word; end; TSomeArray = array[0..9] of TSomeRecord;
Last edited by LP; 30-11-2012 at 03:25 PM.
I don't know exactly how it goes, but i tested a bit too after your comment. TRGB2 is indeed 3 bytes for some reason.
But these are both 8 bytes, and 5 if packed. Same with Lazarus and Delphi.
So it doesn't matter if the value is last one. Having only 1 variable type in record seems to be special case, that is not adding any padding.Code:TRecord1 = record a: single; b: byte; end; TRecord2 = record b: byte; a: single; end;
Last edited by User137; 30-11-2012 at 04:48 PM.
By the way, I'm mistaken regarding packed being deprecated, after checking manuals again, I did not find any references to it. I remember reading about it somewhere since release of XE 2, but perhaps got it confused with something else. Sorry.
Bookmarks