ReneMiner
24-10-2014, 12:07
Is there a possibility to use the functionality of GBuffers ( TBGL_GBufferDefineFromArray ) to blast the data directly into an entity (static) or is there a way if one could send or copy that GBuffer to a displaylist as first?
Or can't i just create some virtual Entity upon the GBuffer?
It's mostly about the speed and i want to use the entity-system.
Passing all data at once is much faster then each vertex line by line.
Also saving to binary would make sense then.
Any ideas? Functionslot is no option here...
Were it possible to add a native (fast) function to load *.obj-files into displayllist/entity? I have to admit, *.obj is not my first choice since they lack vertex-colors but they are widely common and since we don't have no own Entity-Format yet - probably because of slow loading-speed...
Petr Schreiber
25-10-2014, 16:32
Hi Rene,
this is custom GBufferEntity, which you can modify. Let me know...
Petr
ReneMiner
28-10-2014, 09:39
i played a little around- somehow i fear if i set up different fov/aspect the GBuffer-Entity is not affected by the setting as i know it from 3d-fonts - not tried out yet...
But anyway I wrapped a little -all hidden at heap-memory, be surprised what's possible in thinBasic - and the code reads now like that:
Uses "TBGL"
#INCLUDE "t_Entity.tBasicU"
Begin Const
' -- Scene IDs
%sScene = 1
End Const
Function TBMain()
Local hWnd As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", _
640, 480, 32, _
%TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX )
TBGL_ShowWindow
' -- Create scene
TBGL_SceneCreate(%sScene)
' create entities from 0 - don't have even a real local variable
Local Entity As t_Entity At 0
SetAt( Entity, Entity.Create(%sScene, %TBGL_CAMERA) )
Entity.SetPos(0, 10, 20)
Entity.SetTargetPos( 0, 0, 0)
%hCamera = GetAt( Entity ) As DWord ' if want to store it...
' -- Create directional light, don't need its ptr...
SetAt( Entity, Entity.Create(%sScene, %TBGL_LIGHT, %TBGL_LIGHTTYPE_DIRECTIONAL) )
Entity.SetPos(0, 25, 20) ' above camera
Entity.SetTargetPos( 0, 0, 0)
Entity.SetParent( %hCamera )
' -- Define data for mesh
' -- Vertices
Dim VertexA(3) As TBGL_TVECTOR3F At HEAP_Alloc( 3 * SizeOf(TBGL_TVECTOR3F) )
VertexA(1).x = -2
VertexA(1).y = -2
VertexA(1).z = 0
VertexA(2).x = 2
VertexA(2).y = -2
VertexA(2).z = 0
VertexA(3).x = 0
VertexA(3).y = 2
VertexA(3).z = 0
' -- Colors
Dim ColorA(3) As TBGL_TRGB At HEAP_Alloc( 3 * SizeOf(TBGL_TRGB) )
ColorA(1).r = 255
ColorA(1).g = 128
ColorA(1).b = 64
ColorA(2).r = 0
ColorA(2).g = 255
ColorA(2).b = 0
ColorA(3).r = 0
ColorA(3).g = 0
ColorA(3).b = 255
' -- Entity
%hTriangle = Entity.Create(%sScene, _
%TBGL_GBufferStatic, _
%TBGL_TRIANGLES, _
GetAt(VertexA), _
GetAt(ColorA) )
TBGL_ResetKeyState()
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
SetAt( Entity, %hTriangle )
Entity.Turn( 0,-90/FrameRate, 0)
ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
SetAt( Entity, %hTriangle )
Entity.Turn( 0, 90/FrameRate, 0)
ElseIf TBGL_GetWindowKeyState(hWnd, %VK_UP) Then
SetAt( Entity, %hCamera )
Entity.Move( 0, 16/FrameRate, 0 )
Entity.SetTarget( %hTriangle )
ElseIf TBGL_GetWindowKeyState(hWnd, %VK_DOWN) Then
SetAt( Entity, %hCamera )
Entity.Move( 0, -16/FrameRate, 0 )
Entity.SetTarget( %hTriangle )
EndIf
Wend
TBGL_DestroyWindow
End Function
just a raw sketch, the entity does not have a texture yet, neither is the DisplayList-creation done...
As you probably see- it's all arranged to have a future Mesh-udt that's single entities (groups) can have different types of data.
ReneMiner
29-10-2014, 13:58
one more question:
is it possible to retrieve the pointers of vertex-, color-, normal- and texel-array from a once setup-GBuffer again?
Or do i have to save them to some variable?
ReneMiner
10-11-2014, 09:02
one more about this topic, help says for TBGL_GBufferCreate
Syntax
TBGL_GBufferCreate( gType, gDims )
parameter-description for gType
Use one of the following equates:
%TBGL_POINTS
%TBGL_LINES
%TBGL_LINESTRIP
%TBGL_LINELOOP
%TBGL_TRIANGLES
%TBGL_TRIANGLEFAN
%TBGL_TRIANGLELOOP
%TBGL_QUADS
%TBGL_QUADSTRIP
%TBGL_POLYGON
this can not be correct.
There is missing %TBGL_TRIANGLESTRIP while %TBGL_TRIANGLELOOP is not recognized as keyword by thinAir...
however- it took me a while to find out what went wrong and how to solve it...
Petr Schreiber
12-11-2014, 22:05
Hi Rene,
my apologies - nothing worse than bad docs, and now I fell into this category!
I will fix it for next release! :)
Petr
the Entity from Gbuffers deserve to be added to the official thinbasic distribution Like Entity from display List or from a Function
it is much speedier than display list for some tasks
here is a proof using the Petr example above
galaxy shape from display list: 600000 points : FPS= 20
galaxy shape from Gbuffer: 600000 points : FPS= 60
from display list:
'adapted from:
' The entity skeleton for TBGL
' Petr Schreiber, started on 10-25-2014
'
#Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc"
Uses "TBGL"
Begin Const
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%lMyPoints 'display List number
%ePoints 'the number to represent the Entity made from the Display List
End Const
Function TBMain()
Local hWnd As DWord
Local FrameRate As Long 'Double
Global tot As Long
' -- Create and show window
hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Create scene
TBGL_SceneCreate(%sScene)
' -- Create basic entities
' -- Create camera to look from 15, 15, 15 to 0, 0, 0
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 3, 8)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
TBGL_EntityCreateDLSlot(%sScene, %ePoints, 0, %lMyPoints)
TBGL_EntityCreateDLSlot(%sScene, %ePoints, 0, %lMyPoints)
TBGL_EntitySetColor(%sScene, %ePoints, 255, 255, 255)
TBGL_EntitySetPos(%sScene, %ePoints, 0, 0, 0)
' -- Define data for it
DrawPoints()
' -- Resets status of all keys
TBGL_ResetKeyState()
'TBGL_PointSize 2
'glEnable(%GL_POINT_SMOOTH)
TBGL_UseLighting %FALSE
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+" points = "+Str$(tot))
TBGL_EntityTurn(%sScene, %ePoints, 0,30/FrameRate, 0)
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
TBGL_EntityTurn(%sScene, %ePoints, 0,-90/FrameRate, 0)
ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
TBGL_EntityTurn(%sScene, %ePoints, 0, 90/FrameRate, 0)
End If
Wend
TBGL_DestroyWindow
End Function
Sub DrawPoints()
Dim e As Single
Dim x, y, z, y1 As Single
Dim rand, indx As Long
e = 2.718281828459
x=-4: z=-4
TBGL_NewList %lMyPoints
TBGL_BeginPoly %GL_POINTS
While z<= 4
'Randomize
While x<=4
'Randomize
tot = tot + 1
If x*x+z*z<=13 Then
y = Pow(e,(0.1-x*x-z*z)) ' the formula
'Repeat
rand = Rnd(-1,1)'Rnd(-2,2)
'Until rand <> 0 ' To Get rid of Value zero
y1 = y * rand + Rndf(0.1, 0.4)' y * rand: let the point go up And down the galaxy disk, Rndf(0.1, 0.4): And let the disk have Some thickness like a sponge
Select Case y
Case <=0.00005
TBGL_Point(x,y1, z)
TBGL_Color(50,255,0)
Case <=0.001
TBGL_Point(x,y1, z)
TBGL_Color(255,200,0) 'orange
Case <=0.01
TBGL_Point(x,y1, z)
TBGL_Color(255,20,0) 'red
Case <=0.8
TBGL_Point(x,y1, z)
TBGL_Color(0,160,255) 'bluesh
Case >0.8
TBGL_Point(x,y1, z)
TBGL_Color(255,255,255) 'white
End Select
End If
x+0.01
Wend
x = -4
z+0.01
Wend
'================================================
TBGL_EndPoly
TBGL_EndList
End Sub
from Gbuffer: needs the file "GBufferEntity.tBasicU" inside GBufferAsEntity.zip by Petr posted above
'adapted from:
' The entity skeleton for TBGL
' Petr Schreiber, started on 10-25-2014
'
#Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc"
Uses "TBGL" , "Console"
#Include "GBufferEntity.tBasicU"
Begin Const
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
'%eLight
%eGBuffer
End Const
Function TBMain()
Local hWnd As DWord
Local FrameRate As Long 'Double
Global i As Long ' number of points
' -- Create and show window
hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Create scene
TBGL_SceneCreate(%sScene)
' -- Create basic entities
' -- Create camera to look from 15, 15, 15 to 0, 0, 0
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 3, 8)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
TBGL_EntitySetPos(%sScene, %eGbuffer, 0, 0, 0)
%eGbuffer = GbufferEntity_Create(%sScene, %TBGL_POINTS, %TBGL_3D)
Global NumOfPoints = 641601
' -- Define data for it
Global VertexA(NumOfPoints) As TBGL_TVECTOR3F
Global ColorA(NumOfPoints) As TBGL_TRGB
GBufferEntity_DefineFromArray(%sScene, %eGbuffer, %TBGL_DYNAMIC, NumOfPoints, VertexA(1), ColorA(1))
' -- Define data for it
DrawPoints()
' -- Resets status of all keys
TBGL_ResetKeyState()
'TBGL_PointSize 2
'glEnable(%GL_POINT_SMOOTH)
TBGL_UseLighting %FALSE
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+" points = "+Str$(i))
TBGL_EntityTurn(%sScene, %eGbuffer, 0,30/FrameRate, 0)
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
TBGL_EntityTurn(%sScene, %eGbuffer, 0,-90/FrameRate, 0)
ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
TBGL_EntityTurn(%sScene, %eGbuffer, 0, 90/FrameRate, 0)
End If
Wend
TBGL_DestroyWindow
End Function
Sub DrawPoints()
Dim e As Single
Dim x, y, z, y1 As Single
Dim rand, indx As Long
e = 2.718281828459
x=-4: z=-4
While z<= 4
'Randomize
While x<=4
'Randomize
i = i + 1
If x*x+z*z<=13 Then
y = Pow(e,(0.1-x*x-z*z)) ' the formula
'Repeat
rand = Rnd(-1,1)'Rnd(-2,2)
'Until rand <> 0 ' To Get rid of Value zero
y1 = y * rand + Rndf(0.1, 0.4)' y * rand: let the point go up And down the galaxy disk, Rndf(0.1, 0.4): And let the disk have Some thickness like a sponge
Select Case y
Case <=0.00005
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=50: ColorA(i).g=255: ColorA(i).b=0
Case <=0.001
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=255: ColorA(i).g=200: ColorA(i).b=0 'orange
Case <=0.01
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=255: ColorA(i).g=20: ColorA(i).b=0 'red
Case <=0.8
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=0: ColorA(i).g=160: ColorA(i).b=255 'bluesh
Case >0.8
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=255: ColorA(i).g=255: ColorA(i).b=255 'white
End Select
End If
x+0.01
Wend
x = -4
z+0.01
Wend
'================================================
End Sub
suggestion 2: powerBasic lacks a good 3D graphics engine, we can't consider OpenGL an engine for the home users. also the available xors3d and N3xtD depends on DirectX9, the xors3d is abandoned and the N3xtD depends on the DX9. most users of windows 10 usualy don't like to install DX9 on their machines even for psychological reasons only. while Opengl is backward compatible . so the door is open to provide especialy the Petr entity system friendly and easy to use to the powerbasic users. you can sell the engine in windows store for 29$.
https://www.microsoft.com/store/apps
when you do this i will buy powerbasic v10 immediately.
Petr Schreiber
16-01-2018, 08:56
Hi Primo,
thank you very much for your kind words, it really made my day :)
As for GBuffer entity - I will have a look at it, it would nicely complete the set.
To get further performance improvements... I will check some OpenGL extensions. I am playing with Vulkan as well. It has huge performance boost, but it is very fragile.
Petr