1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2024-12-26 03:18:22 +01:00

rendering improvement
Some checks reported errors
gitea-sync/Diya-API/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
Dany LE 2022-08-16 00:59:35 +02:00
parent 3c00e1d181
commit f61e17de9c
12 changed files with 192 additions and 93 deletions

View File

@ -19,9 +19,9 @@ DiyaApplicationLauncher >> bindGlobalEvent [
|pointer | |pointer |
pointer := node addNode: (DiyaCircle r: 10) at: 200@200. pointer := node addNode: (DiyaCircle r: 10) at: 200@200.
pointer styleName: #pointer. pointer styleName: #pointer.
node on: #keydown do:[:e| self stdlog: 'keydown...'. running := false.]. target on: #keydown do:[:e| self stdlog: 'keydown...'. running := false.].
node on: #quit do: [:e| running := false]. target on: #quit do: [:e| running := false].
node on: #(fingerdown fingermotion mousemotion) do:[:e| target on: #(fingerdown fingermotion mousemotion) do:[:e|
pointer position: e mapped worldPosition. pointer position: e mapped worldPosition.
DiyaRenderer mouse: (e mapped x) @ (e mapped y). DiyaRenderer mouse: (e mapped x) @ (e mapped y).
]. ].
@ -33,37 +33,7 @@ DiyaApplicationLauncher >> defaultApplication [
] ]
{ #category : #initialization } { #category : #initialization }
DiyaApplicationLauncher >> initLoader [ DiyaApplicationLauncher >> defineLayout [
]
{ #category : #initialization }
DiyaApplicationLauncher >> initialize [
super initialize.
node := DiyaRenderer root.
currapp := nil.
]
{ #category : #initialization }
DiyaApplicationLauncher >> launch: app [
currapp ifNotNil: [
currapp quit.
node empty.
].
currapp := app uniqueInstance.
self context assets: currapp am.
self appNode addNode: currapp loader node.
currapp onloaded:[
self appNode empty.
currapp node visibility: false.
self appNode addNode: currapp node.
currapp node visibility: true.
self stdlog: 'Application LOADED'.
].
]
{ #category : #initialization }
DiyaApplicationLauncher >> onloaded: aBlock [
DiyaUIThemesManager uniqueInstance currentTheme DiyaUIThemesManager uniqueInstance currentTheme
define: #fps_text styles: { define: #fps_text styles: {
#color -> Color red. #color -> Color red.
@ -81,9 +51,42 @@ DiyaApplicationLauncher >> onloaded: aBlock [
txtFPS extent: 80@40. txtFPS extent: 80@40.
txtFPS styleName: #fps_text. txtFPS styleName: #fps_text.
self bindGlobalEvent. self bindGlobalEvent.
self loadNode.
]
{ #category : #initialization }
DiyaApplicationLauncher >> initialize [
super initialize.
node := DiyaCompositeNode new.
currapp := nil.
]
{ #category : #initialization }
DiyaApplicationLauncher >> launch: app [
currapp ifNotNil: [
currapp quit.
].
currapp := app uniqueInstance.
self context assets: currapp am.
currapp target: self appNode.
currapp onloaded:[
self stdlog: 'Application LOADED'.
].
]
{ #category : #initialization }
DiyaApplicationLauncher >> onloaded: aBlock [
|loader|
running := true. running := true.
self launch: self defaultApplication. loader := DiyaDefaultSystemLoader on: target.
aBlock value. loader job: [ DiyaFontManager uniqueInstance loadFonts. ] name: 'Loading fonts...'.
loader job: [ self defineLayout ] name: 'Define layout...'.
loader onloaded: [
node children do:[:c| target addNode: c at: c position].
node := target.
aBlock value.
self launch: self defaultApplication.
]
] ]
{ #category : #accessing } { #category : #accessing }

View File

@ -4,7 +4,8 @@ Class {
#instVars : [ #instVars : [
'node', 'node',
'am', 'am',
'loader' 'target',
'context'
], ],
#category : #'Diya-Applications' #category : #'Diya-Applications'
} }
@ -24,20 +25,20 @@ DiyaApplicationModel >> context [
^DiyaRenderer ^DiyaRenderer
] ]
{ #category : #initialization }
DiyaApplicationModel >> initLoader [
self subclassResponsibility
]
{ #category : #initialization } { #category : #initialization }
DiyaApplicationModel >> initialize [ DiyaApplicationModel >> initialize [
super initialize. super initialize.
self initLoader. context := DiyaRenderer
] ]
{ #category : #accessing } { #category : #'as yet unclassified' }
DiyaApplicationModel >> loader [ DiyaApplicationModel >> loadNode [
^ loader |pseudoRoot|
pseudoRoot := DiyaRootNode new.
pseudoRoot addNode: node.
pseudoRoot processQueue do:[:el|
el process
].
] ]
{ #category : #accessing } { #category : #accessing }
@ -52,5 +53,11 @@ DiyaApplicationModel >> onloaded: aBlock [
{ #category : #accessing } { #category : #accessing }
DiyaApplicationModel >> quit [ DiyaApplicationModel >> quit [
node empty.
self cleanup self cleanup
] ]
{ #category : #initialization }
DiyaApplicationModel >> target: aNode [
target := aNode.
]

View File

@ -83,7 +83,6 @@ DiyaBoot >> init [
Smalltalk globals at: #DiyaDisplay put:display. Smalltalk globals at: #DiyaDisplay put:display.
Smalltalk globals at: #DiyaSystemSettings put: DiyaSettings uniqueInstance. Smalltalk globals at: #DiyaSystemSettings put: DiyaSettings uniqueInstance.
Smalltalk globals at: #DiyaSystemClock put: DiyaClock uniqueInstance. Smalltalk globals at: #DiyaSystemClock put: DiyaClock uniqueInstance.
DiyaFontManager uniqueInstance loadFonts.
] ]
{ #category : #events } { #category : #events }
@ -102,6 +101,7 @@ DiyaBoot >> render [
"Init the Open GL view port and enable 2D texture" "Init the Open GL view port and enable 2D texture"
OpenGL viewportX: 0 Y:0 W: display w H: display h. OpenGL viewportX: 0 Y:0 W: display w H: display h.
OpenGL enable: GL_TEXTURE_2D. OpenGL enable: GL_TEXTURE_2D.
launcher target: DiyaRenderer root.
launcher onloaded: [self stdlog: 'Launcher loaded']. launcher onloaded: [self stdlog: 'Launcher loaded'].
[ launcher running ] whileTrue: [ [ launcher running ] whileTrue: [
DiyaSystemClock tick. DiyaSystemClock tick.

View File

@ -1,20 +1,20 @@
Class { Class {
#name : #DiyaDefaultAppLoader, #name : #DiyaDefaultAppLoader,
#superclass : #DiyaLoader, #superclass : #DiyaDefaultSystemLoader,
#instVars : [ #instVars : [
'progress',
'label' 'label'
], ],
#category : #'Diya-Applications' #category : #'Diya-Applications'
} }
{ #category : #initialization } { #category : #initialization }
DiyaDefaultAppLoader >> init [ DiyaDefaultAppLoader >> updateLayout [
progress := node addNode: (DiyaLoadingBar new) at: 20@50. super updateLayout.
progress extent: 420 @ 20. label ifNil:[
label := node addNode: (DiyaText new) at: 20@80. label := node addNode: (DiyaText new) at: (progress position + (0@25)).
label extent: 420 @ 20. label inlineStyle: #xAlign value: #center
label inlineStyle: #xAlign value: #center ].
label extent: (progress extent x) @ 40.
] ]
{ #category : #scheduling } { #category : #scheduling }

View File

@ -0,0 +1,21 @@
Class {
#name : #DiyaDefaultSystemLoader,
#superclass : #DiyaLoader,
#instVars : [
'progress'
],
#category : #'Diya-Applications'
}
{ #category : #initialization }
DiyaDefaultSystemLoader >> updateLayout [
|xtent|
xtent := DiyaRenderer resolution.
progress ifNil:[progress := node addNode: (DiyaLoadingBar new) at: 20@((xtent y >> 1) - 50)].
progress extent: (xtent x - 40) @ 20.
]
{ #category : #scheduling }
DiyaDefaultSystemLoader >> updateProgress: name percent: p [
progress percent: p
]

View File

@ -1,6 +1,9 @@
Class { Class {
#name : #DiyaExampleApp, #name : #DiyaExampleApp,
#superclass : #DiyaBaseApplication, #superclass : #DiyaBaseApplication,
#instVars : [
'loader'
],
#category : #'Diya-Applications' #category : #'Diya-Applications'
} }
@ -12,6 +15,7 @@ DiyaExampleApp >> cleanup [
{ #category : #accessing } { #category : #accessing }
DiyaExampleApp >> defineNodes [ DiyaExampleApp >> defineNodes [
|node2 node1 img ell label icon button texture loading| |node2 node1 img ell label icon button texture loading|
node := DiyaCompositeNode new.
texture := DiyaImageTex new. texture := DiyaImageTex new.
label := node addNode: (DiyaLabel new) at: 10@40. label := node addNode: (DiyaLabel new) at: 10@40.
label extent: 250@24. label extent: 250@24.
@ -159,18 +163,27 @@ DiyaExampleApp >> defineStyleSheet [
} }
] ]
{ #category : #initialization } { #category : #accessing }
DiyaExampleApp >> initLoader [ DiyaExampleApp >> initialize [
loader := DiyaDefaultAppLoader new. super initialize.
loader := nil
] ]
{ #category : #accessing } { #category : #accessing }
DiyaExampleApp >> onloaded: aBlock [ DiyaExampleApp >> onloaded: aBlock [
loader ifNil: [ loader := DiyaDefaultAppLoader on: target ].
loader job: [ self defineStyleSheet ] name: 'Initializing themes...'. loader job: [ self defineStyleSheet ] name: 'Initializing themes...'.
loader job: [ loader job: [
self defineNodes. self defineNodes.
self node forceReload self loadNode.
] name: 'Initializing UI elements...'. ] name: 'Initializing UI elements...'.
loader onloaded: aBlock loader onloaded: [
node children do:[:e|
target addNode: e at: e position.
node := target.
].
aBlock value
].
] ]

View File

@ -94,8 +94,8 @@ DiyaLine >> process [
at: 3 put: 0.0; at: 3 put: 0.0;
at: 4 put: 0.0; at: 4 put: 0.0;
at: 5 put: extent x; at: 5 put: extent x asFloat;
at: 6 put: extent y; at: 6 put: extent y asFloat;
at: 7 put: 0.0; at: 7 put: 0.0;
at: 8 put: 0.0. at: 8 put: 0.0.
^true ^true

View File

@ -3,26 +3,38 @@ Class {
#superclass : #DiyaBaseObject, #superclass : #DiyaBaseObject,
#instVars : [ #instVars : [
'node', 'node',
'jobs' 'jobs',
'target'
], ],
#category : #'Diya-Applications' #category : #'Diya-Applications'
} }
{ #category : #'instance creation' }
DiyaLoader class >> on: target [
^ self new target: target; yourself
]
{ #category : #scheduling } { #category : #scheduling }
DiyaLoader >> executeJobs: callback [ DiyaLoader >> executeJobs: callback [
"target visibility: false."
target empty.
target addNode: node.
"target visibility: true".
node visibility: true.
self updateLayout.
500 milliSeconds wait.
self job: [ 500 milliSeconds wait. ] name: 'finishing' .
jobs withIndexDo: [ :job :i| jobs withIndexDo: [ :job :i|
self updateProgress: job key percent: ((i - 1) * 100 / (jobs size)) asInteger. self updateProgress: job key percent: ((i - 1) * 100 / (jobs size)) asInteger.
job value value. job value value.
]. ].
jobs := OrderedCollection new. jobs := OrderedCollection new.
self updateProgress: 'Finishing...' percent: 100. self updateProgress: 'Finishing...' percent: 100.
500 milliSeconds wait.
node visibility: false.
target empty.
callback value. callback value.
] target visibility: true.
{ #category : #initialization }
DiyaLoader >> init [
self subclassResponsibility
] ]
{ #category : #initialization } { #category : #initialization }
@ -30,7 +42,7 @@ DiyaLoader >> initialize [
super initialize. super initialize.
node := DiyaCompositeNode new. node := DiyaCompositeNode new.
jobs := OrderedCollection new. jobs := OrderedCollection new.
self init. target := nil.
] ]
{ #category : #scheduling } { #category : #scheduling }
@ -48,6 +60,21 @@ DiyaLoader >> onloaded: aBlock [
[ self executeJobs: aBlock ] fork"At: Processor userBackgroundPriority". [ self executeJobs: aBlock ] fork"At: Processor userBackgroundPriority".
] ]
{ #category : #accessing }
DiyaLoader >> target [
^ target
]
{ #category : #accessing }
DiyaLoader >> target: anObject [
target := anObject
]
{ #category : #initialization }
DiyaLoader >> updateLayout [
self subclassResponsibility
]
{ #category : #scheduling } { #category : #scheduling }
DiyaLoader >> updateProgress: name percent: p [ DiyaLoader >> updateProgress: name percent: p [
self subclassResponsibility self subclassResponsibility

View File

@ -49,12 +49,12 @@ DiyaNode >> ? styleAttr [
^ parent ? styleAttr ^ parent ? styleAttr
] ]
{ #category : #accessing } { #category : #'add/remove' }
DiyaNode >> addNode: node [ DiyaNode >> addNode: node [
^self addNode: node at: 0@0 ^self addNode: node at: 0@0
] ]
{ #category : #accessing } { #category : #'add/remove' }
DiyaNode >> addNode: node at: pos [ DiyaNode >> addNode: node at: pos [
children ifNil: [ ^self ]. children ifNil: [ ^self ].
node parent: self. node parent: self.
@ -82,6 +82,13 @@ DiyaNode >> draw [
{ #category : #requirements } { #category : #requirements }
DiyaNode >> empty [ DiyaNode >> empty [
children ifNotNil: [
children do:[:c|
c root: nil.
c setClean.
c visibility: false.
]
].
children := OrderedCollection new. children := OrderedCollection new.
] ]
@ -90,15 +97,6 @@ DiyaNode >> extent [
^ self subclassResponsibility ^ self subclassResponsibility
] ]
{ #category : #processing }
DiyaNode >> forceReload [
self process.
children ifNotNil: [
children do:[:c|
c forceReload
]]
]
{ #category : #accessing } { #category : #accessing }
DiyaNode >> id [ DiyaNode >> id [
^ id ^ id
@ -183,28 +181,42 @@ DiyaNode >> register: aBlock to: eventName [
] ]
{ #category : #removing } { #category : #'add/remove' }
DiyaNode >> remove [ DiyaNode >> remove [
self setClean.
root := nil.
parent ifNotNil: [ parent removeChild: self ] parent ifNotNil: [ parent removeChild: self ]
] ]
{ #category : #removing } { #category : #'add/remove' }
DiyaNode >> removeChild: c [ DiyaNode >> removeChild: c [
c setClean.
c root: nil.
c visibility: false.
children ifNotNil: [ children remove: c ifAbsent:[ ]] children ifNotNil: [ children remove: c ifAbsent:[ ]]
] ]
{ #category : #rendering } { #category : #rendering }
DiyaNode >> render [ DiyaNode >> render [
visibility ifFalse:[^self]. visibility ifFalse:[^self].
root ifNil: [ ^self ].
shader ifNotNil: [self setUpShader]. shader ifNotNil: [self setUpShader].
self draw. self draw.
children ifNil: [ ^self ]. children ifNil: [ ^self ].
root ifNil: [ ^self ].
root renderNext: children root renderNext: children
] ]
{ #category : #'add/remove' }
DiyaNode >> replaceChild: aNode with: anotherNode [
|index|
children ifNil: [ ^ self ].
index := children indexOf: aNode.
index = 0 ifTrue:[^ self].
children at: index put: anotherNode.
anotherNode parent: self.
anotherNode root: self root.
anotherNode setDirtyAll.
aNode root: nil.
]
{ #category : #accessing } { #category : #accessing }
DiyaNode >> root [ DiyaNode >> root [
^ root ^ root
@ -354,5 +366,7 @@ DiyaNode >> visibility [
{ #category : #accessing } { #category : #accessing }
DiyaNode >> visibility: anObject [ DiyaNode >> visibility: anObject [
visibility := anObject visibility := anObject.
children ifNotNil: [
children do:[:c| c visibility: anObject ] ]
] ]

View File

@ -47,16 +47,16 @@ DiyaRectangle >> process [
at: 4 put: 0.0; at: 4 put: 0.0;
at: 5 put: 0.0; at: 5 put: 0.0;
at: 6 put: extent y; at: 6 put: extent y asFloat;
at: 7 put: 0.0; at: 7 put: 0.0;
at: 8 put: 1.0; at: 8 put: 1.0;
at: 9 put: extent x; at: 9 put: extent x asFloat;
at: 10 put: extent y; at: 10 put: extent y asFloat;
at: 11 put: 1.0; at: 11 put: 1.0;
at: 12 put: 1.0; at: 12 put: 1.0;
at: 13 put: extent x; at: 13 put: extent x asFloat;
at: 14 put: 0.0; at: 14 put: 0.0;
at: 15 put: 1.0; at: 15 put: 1.0;
at: 16 put: 0.0. at: 16 put: 0.0.

View File

@ -10,7 +10,8 @@ Class {
'projection', 'projection',
'assets', 'assets',
'window', 'window',
'root' 'root',
'lock'
], ],
#pools : [ #pools : [
'OpenGLConstants', 'OpenGLConstants',
@ -79,6 +80,7 @@ DiyaRendererContext >> initialize [
vbo := OpenGLVertexBuffer new. vbo := OpenGLVertexBuffer new.
vao := OpenGLVertexArray new. vao := OpenGLVertexArray new.
textures := Dictionary new. textures := Dictionary new.
lock := Mutex new.
vao bind. vao bind.
vbo bind: GL_ARRAY_BUFFER. vbo bind: GL_ARRAY_BUFFER.
projection := Array2D identity: 4. projection := Array2D identity: 4.
@ -96,6 +98,11 @@ DiyaRendererContext >> initialize [
(OpenGLTexture fromUnit: i - 1) -> nil] . (OpenGLTexture fromUnit: i - 1) -> nil] .
] ]
{ #category : #accessing }
DiyaRendererContext >> lock [
^ lock
]
{ #category : #accessing } { #category : #accessing }
DiyaRendererContext >> mouse [ DiyaRendererContext >> mouse [
^ mouse ^ mouse

View File

@ -62,6 +62,11 @@ DiyaRootNode >> process [
] ]
{ #category : #controlling }
DiyaRootNode >> processQueue [
^ Q
]
{ #category : #testing } { #category : #testing }
DiyaRootNode >> readyForSwap [ DiyaRootNode >> readyForSwap [
^ R isEmpty ^ R isEmpty
@ -105,10 +110,12 @@ DiyaRootNode >> spinOnce: maxProcessingTime [
Q ifNotEmpty: [ Q ifNotEmpty: [
node := Q removeFirst. node := Q removeFirst.
node process. node process.
"context lock critical: [node process]."
]. ].
R ifNotEmpty: [ R ifNotEmpty: [
node := R removeFirst. node := R removeFirst.
node render. node render.
"context lock critical: [node render]. "
]. ].
(Q isEmpty and: R isEmpty) ifTrue: [ ^false ]. (Q isEmpty and: R isEmpty) ifTrue: [ ^false ].
DiyaSystemSettings renderAtOnce ifTrue: [ ^ true ]. DiyaSystemSettings renderAtOnce ifTrue: [ ^ true ].