Thanks for that, i always woundered what the difference between the two was
Thanks for that, i always woundered what the difference between the two was
M109uk
<br />--------------------------------------------------------
<br />www.pulse-soft.oneuk.com
Okay, this is the problem and is my fault. What you need is this type for the buffers:Originally Posted by M109uk
You should understand how to expand upon this by now, but I'll give you the basics. Sometimes pointers really aren't worth it--especially for arrays. Now, you could do a single/double linked list, but there would be no increase in speed to set the vertex buffer that way (the API's are C and want arrays...).Code:type TVector3fArray = array of Vector3f; PVector3fArray = ^TVector3fArray; //... TVolumetricCloud = Class vBuffer: PVector3fArray; //... end; //.. //OnCreate... var cur: PVector3f; counter: Integer; begin GetMem(vBuffer, SizeOf(TVector3f) * Length(Puffs)); cur := Pointer(vBuffer^[0]); counter := Length(Puffs); while counter > 0 do begin // Manipulation here... Inc(Cur); Dec(Counter); end; end;
Propably That code is trying to increase pointers by 1 like you showed in class definition. TryOriginally Posted by M109uk
Inc(Cloud.vBuffer^);
etc...
User137:
Thanks for the idea,
i gave it a try, and it just kept coming back with an invalid typcast error.
Robert Kosek:
Thanks again,
I had to make a small adjustment (otherwise i kept getting access violations again)
TVector3fArray = Array [0..0] Of TVector3f;
PVector3fArray = ^TVector3fArray;
I hav'nt properly tested it to see if the values are going in ok, since now i have another problem i completly forgot about, haha.
I have another procedure that sorts the records depending on the puffs distance from the camera, now i know my sort routine is uterly trash, and probably contributes to the most of the lack of speed, however here it is:
[pascal]
procedure TGLVolumetricClouds.SortParticles(Cloud: TVolumetricCloud; mode: Integer);
procedure swap(iFrom,iTo: Integer);
var
tmpPuff: TCloudPuff;
begin
tmpPuff := Cloud.Puffs[iFrom];
Cloud.Puffs[iFrom] := Cloud.Puffs[iTo];
Cloud.Puffs[iTo] := tmpPuff;
end;
procedure sort(Toward: Boolean);
var
i,j: Integer;
tmpPuff: TCloudPuff;
begin
For i := 0 To High(Cloud.Puffs) Do
For j := 0 To High(Cloud.Puffs) Do
Begin
If ((Toward) And (Cloud.Puffs[i].DistanceToCam > Cloud.Puffs[j].DistanceToCam)) Or
((Not Toward) And (Cloud.Puffs[i].DistanceToCam < Cloud.Puffs[j].DistanceToCam)) Then
swap(i, j);
End;
end;
var
done,do_swap,useSTL: Boolean;
i,j: Integer;
begin
done := False;
useSTL := True;
If useSTL Then
Begin
Case mode Of
SORT_AWAY: sort(False);
SORT_TOWARD: sort(True);
End;
End Else
Begin
while (Not done) Do
Begin
done := True;
For i := 0 To High(Cloud.Puffs) Do
For j := i+1 To High(Cloud.Puffs) Do
Begin
do_swap := false;
Case mode Of
SORT_AWAY: do_swap := (Cloud.Puffs[i].DistanceToCam <Cloud> Cloud.Puffs[j].DistanceToCam);
End;
If do_swap Then
Begin
swap(i, j);
done := False;
End;
End;
End;
End;
end;
[/pascal]
Im guessing this would'nt effect the pointers, but i have an assign procedure for the cloud, which needs to copy the pointer, now im assuming if i just did Cloud.vBuffer := Source.vBuffer; that if i make changes this will effect both clouds. would it be best to clear and recreate the pointer (cloud.vBuffer) and then copy the memory (somehow)?
Many Thanks
Nic
M109uk
<br />--------------------------------------------------------
<br />www.pulse-soft.oneuk.com
Well, the sorting is beyond me, but not the swappage of pointers. That's really simple once you figure it out. Here's the gist:It really is that simple. If it complains about the pointer type or anything, just typecast it into a pointer when you pass it.Code:procedure SwapPointers(var p1,p2: Pointer); var tmp: pointer; begin tmp := p1; p1 := p2; p2 := tmp; end;
Great thanks
seems to work, now i seem to be having problems again with the following section, it loops through a few times and then an access violation:
[pascal]
glVertexPointer(3, GL_FLOAT, 0, Cloud.vBuffer);
glColorPointer(4, GL_FLOAT, 0, Cloud.cBuffer);
glTexCoordPointer(2, GL_FLOAT, 0, Cloud.tBuffer);
glDrawArrays(GL_QUADS, 0, Length(Cloud.Puffs)*4);
[/pascal]
i assumed to change from '@Cloud.vBuffer[0]' to 'Cloud.vBuffer'?
Thanks again
Nic
M109uk
<br />--------------------------------------------------------
<br />www.pulse-soft.oneuk.com
Try this instead, as far as I can remember this is the correct form. Though, why do you keep multiplying the size by 4? That is beyond me a little, since I'm trying to figure out why you need 4 times the size of the one array.
This just gets the pointer to the first item like before, rather than the array. C prefers it this way AFAIK.Code:glVertexPointer(3, GL_FLOAT, 0, Pointer(Cloud.vBuffer^[0])); glColorPointer(4, GL_FLOAT, 0, Pointer(Cloud.cBuffer^[0])); glTexCoordPointer(2, GL_FLOAT, 0, Pointer(Cloud.tBuffer^[0]));
I tryed that and got an invalid typcast error, would this work:
[pascal]
glVertexPointer(3, GL_FLOAT, 0, @Cloud.vBuffer^[0]);
glColorPointer(4, GL_FLOAT, 0, @Cloud.cBuffer^[0]);
glTexCoordPointer(2, GL_FLOAT, 0, @Cloud.tBuffer^[0]);
[/pascal]
Im multiplying them by 4 because each puff is actually Quad so i pass 4 vertices for each puff.
M109uk
<br />--------------------------------------------------------
<br />www.pulse-soft.oneuk.com
Ah, okay. So what is the function expecting, typewise? Maybe try removing the array index portion and just throw it the buffer with a @ prefix to the whole thing. IE: @Cloud.vBuffer);
*sigh* I wasn't really thinking clearly when i wrote that :lol: procedure AddToMem says something about what you want to do in it... Original procedure propably did something only C can do, now in pascal you likely need a new approach completely. So.. i think plan is to add 1 vertex to array and same time make preparations so next call will also add 1 after it. Need to make sure the array is resized and update some Count variable, then assign parameter info to vBuffer[Count-1] that is last index.Originally Posted by User137
And about sorting, this is 1 efficient structure:
[pascal]for i:=0 to Count-2 do
for j:=i+1 to Count-1 do
// Compare here and swap if needed
// Notice how it ignores all useless calls, like this way would make final compare to item itself, not to mention amount of extra calls it there wasn't i+1
for i:=0 to Count-1 do
for j:=i+1 to Count-1 do[/pascal]
But still there exist faster ways, i'm not very much familiarized with them and they are propably made for certain kinds of arrays.
Edit: Ok i take my words back a bit, it is all propably possible in pascal too, but this line
Inc(Cloud.vBuffer);
was actually made to increase the pointer (the place that array starts, note you would need to revert it backwards too if want to use it), and likely not by 1, but 12 that is sizeof(TVector3f). Maybe something like (i'm not sure):
pointer(Cloud.vBuffer):=pointer(integer(Cloud.vBuf fer)+12);
Bookmarks