Milen
Milen

Reputation: 11

GLScene triangles count

Is there any way to find the total count of triangles in the scene? I searched in the documentation and class references, but was not able to find any procedure or method about that.

Upvotes: 0

Views: 358

Answers (3)

Kainax
Kainax

Reputation: 1481

Those who said that you have to keep track of added objects yourself are right. But those who said that it is imposible to count triangles in GLScene are wrong. If you track all added GlFreeForms in a TStrings, you can count GLScene triangles with this small function that I wrote for that purpose:

function CountSceneTriangles(GLScene: TGlScene; SceneObjectList: TStrings): Integer;
var
  I, ITriCount: Integer;
  TempSceneObject: TGLBaseSceneObject;
begin
  ITriCount := 0;

  if (SceneObjectList.Count > 0) then
  begin
    for I := 0 to SceneObjectList.Count-1 do
    begin
      TempSceneObject:= Form1.GLScene1.FindSceneObject(SceneObjectList[I]));
      if (TempSceneObject <> nil) then
      begin
        ITriCount := ITriCount + (TGLFreeForm(TempSceneObject).MeshObjects.TriangleCount);
      end;
    end;
  end;

  result := ITriCount;
end;

Just pass your TGLScene component name and tracked list of all added GLFreeForm objects to it like that:

procedure TForm1.FormCreate(Sender: TObject);
var
  SObjList: TStrings;
begin
  SObjList := TStrings.Create;
  SObjList.Add('GlFreeForm1'); //examples of tracked TGlFreeForms
  SObjList.Add('GlFreeForm2');
  SObjList.Add('GlFreeForm3');
  Form1.Caption := 'Triangles Count: ' + IntToStr(SObjList(Form1.GlScene1, SObjList));
  SObjList.Free;
end;

If you need to count triangles for other objects than TGlFreeForm you can extend this function on the same principle. Good luck.

Upvotes: 0

Jerry Dodge
Jerry Dodge

Reputation: 27266

OpenGL does not keep track of any particular shapes you may have drawn. Instead, it tracks connections between vertices. When a triangle is drawn, OpenGL doesn't necessarily know this is a triangle. Therefore, you need to implement your own means of tracking what shapes you're drawing, and query your own shape references instead. Remember that drawing in general (2D or 3D) are not based on straight-forward shapes. There may be very abstract shapes which don't even have a name to call them.

Upvotes: 0

abenci
abenci

Reputation: 8651

As far as I know there is no way to query the total number of vertices or triangles in the scene in OpenGL ...

Upvotes: 0

Related Questions