1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2024-12-25 10:58: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 := node addNode: (DiyaCircle r: 10) at: 200@200.
pointer styleName: #pointer.
node on: #keydown do:[:e| self stdlog: 'keydown...'. running := false.].
node on: #quit do: [:e| running := false].
node on: #(fingerdown fingermotion mousemotion) do:[:e|
target on: #keydown do:[:e| self stdlog: 'keydown...'. running := false.].
target on: #quit do: [:e| running := false].
target on: #(fingerdown fingermotion mousemotion) do:[:e|
pointer position: e mapped worldPosition.
DiyaRenderer mouse: (e mapped x) @ (e mapped y).
].
@ -33,37 +33,7 @@ DiyaApplicationLauncher >> defaultApplication [
]
{ #category : #initialization }
DiyaApplicationLauncher >> initLoader [
]
{ #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 [
DiyaApplicationLauncher >> defineLayout [
DiyaUIThemesManager uniqueInstance currentTheme
define: #fps_text styles: {
#color -> Color red.
@ -81,9 +51,42 @@ DiyaApplicationLauncher >> onloaded: aBlock [
txtFPS extent: 80@40.
txtFPS styleName: #fps_text.
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.
self launch: self defaultApplication.
aBlock value.
loader := DiyaDefaultSystemLoader on: target.
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 }

View File

@ -4,7 +4,8 @@ Class {
#instVars : [
'node',
'am',
'loader'
'target',
'context'
],
#category : #'Diya-Applications'
}
@ -24,20 +25,20 @@ DiyaApplicationModel >> context [
^DiyaRenderer
]
{ #category : #initialization }
DiyaApplicationModel >> initLoader [
self subclassResponsibility
]
{ #category : #initialization }
DiyaApplicationModel >> initialize [
super initialize.
self initLoader.
context := DiyaRenderer
]
{ #category : #accessing }
DiyaApplicationModel >> loader [
^ loader
{ #category : #'as yet unclassified' }
DiyaApplicationModel >> loadNode [
|pseudoRoot|
pseudoRoot := DiyaRootNode new.
pseudoRoot addNode: node.
pseudoRoot processQueue do:[:el|
el process
].
]
{ #category : #accessing }
@ -52,5 +53,11 @@ DiyaApplicationModel >> onloaded: aBlock [
{ #category : #accessing }
DiyaApplicationModel >> quit [
node empty.
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: #DiyaSystemSettings put: DiyaSettings uniqueInstance.
Smalltalk globals at: #DiyaSystemClock put: DiyaClock uniqueInstance.
DiyaFontManager uniqueInstance loadFonts.
]
{ #category : #events }
@ -102,6 +101,7 @@ DiyaBoot >> render [
"Init the Open GL view port and enable 2D texture"
OpenGL viewportX: 0 Y:0 W: display w H: display h.
OpenGL enable: GL_TEXTURE_2D.
launcher target: DiyaRenderer root.
launcher onloaded: [self stdlog: 'Launcher loaded'].
[ launcher running ] whileTrue: [
DiyaSystemClock tick.

View File

@ -1,20 +1,20 @@
Class {
#name : #DiyaDefaultAppLoader,
#superclass : #DiyaLoader,
#superclass : #DiyaDefaultSystemLoader,
#instVars : [
'progress',
'label'
],
#category : #'Diya-Applications'
}
{ #category : #initialization }
DiyaDefaultAppLoader >> init [
progress := node addNode: (DiyaLoadingBar new) at: 20@50.
progress extent: 420 @ 20.
label := node addNode: (DiyaText new) at: 20@80.
label extent: 420 @ 20.
label inlineStyle: #xAlign value: #center
DiyaDefaultAppLoader >> updateLayout [
super updateLayout.
label ifNil:[
label := node addNode: (DiyaText new) at: (progress position + (0@25)).
label inlineStyle: #xAlign value: #center
].
label extent: (progress extent x) @ 40.
]
{ #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 {
#name : #DiyaExampleApp,
#superclass : #DiyaBaseApplication,
#instVars : [
'loader'
],
#category : #'Diya-Applications'
}
@ -12,6 +15,7 @@ DiyaExampleApp >> cleanup [
{ #category : #accessing }
DiyaExampleApp >> defineNodes [
|node2 node1 img ell label icon button texture loading|
node := DiyaCompositeNode new.
texture := DiyaImageTex new.
label := node addNode: (DiyaLabel new) at: 10@40.
label extent: 250@24.
@ -159,18 +163,27 @@ DiyaExampleApp >> defineStyleSheet [
}
]
{ #category : #initialization }
DiyaExampleApp >> initLoader [
loader := DiyaDefaultAppLoader new.
{ #category : #accessing }
DiyaExampleApp >> initialize [
super initialize.
loader := nil
]
{ #category : #accessing }
DiyaExampleApp >> onloaded: aBlock [
loader ifNil: [ loader := DiyaDefaultAppLoader on: target ].
loader job: [ self defineStyleSheet ] name: 'Initializing themes...'.
loader job: [
self defineNodes.
self node forceReload
self loadNode.
] 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: 4 put: 0.0;
at: 5 put: extent x;
at: 6 put: extent y;
at: 5 put: extent x asFloat;
at: 6 put: extent y asFloat;
at: 7 put: 0.0;
at: 8 put: 0.0.
^true

View File

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

View File

@ -49,12 +49,12 @@ DiyaNode >> ? styleAttr [
^ parent ? styleAttr
]
{ #category : #accessing }
{ #category : #'add/remove' }
DiyaNode >> addNode: node [
^self addNode: node at: 0@0
]
{ #category : #accessing }
{ #category : #'add/remove' }
DiyaNode >> addNode: node at: pos [
children ifNil: [ ^self ].
node parent: self.
@ -82,6 +82,13 @@ DiyaNode >> draw [
{ #category : #requirements }
DiyaNode >> empty [
children ifNotNil: [
children do:[:c|
c root: nil.
c setClean.
c visibility: false.
]
].
children := OrderedCollection new.
]
@ -90,15 +97,6 @@ DiyaNode >> extent [
^ self subclassResponsibility
]
{ #category : #processing }
DiyaNode >> forceReload [
self process.
children ifNotNil: [
children do:[:c|
c forceReload
]]
]
{ #category : #accessing }
DiyaNode >> id [
^ id
@ -183,28 +181,42 @@ DiyaNode >> register: aBlock to: eventName [
]
{ #category : #removing }
{ #category : #'add/remove' }
DiyaNode >> remove [
self setClean.
root := nil.
parent ifNotNil: [ parent removeChild: self ]
]
{ #category : #removing }
{ #category : #'add/remove' }
DiyaNode >> removeChild: c [
c setClean.
c root: nil.
c visibility: false.
children ifNotNil: [ children remove: c ifAbsent:[ ]]
]
{ #category : #rendering }
DiyaNode >> render [
visibility ifFalse:[^self].
root ifNil: [ ^self ].
shader ifNotNil: [self setUpShader].
self draw.
children ifNil: [ ^self ].
root ifNil: [ ^self ].
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 }
DiyaNode >> root [
^ root
@ -354,5 +366,7 @@ DiyaNode >> visibility [
{ #category : #accessing }
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: 5 put: 0.0;
at: 6 put: extent y;
at: 6 put: extent y asFloat;
at: 7 put: 0.0;
at: 8 put: 1.0;
at: 9 put: extent x;
at: 10 put: extent y;
at: 9 put: extent x asFloat;
at: 10 put: extent y asFloat;
at: 11 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: 15 put: 1.0;
at: 16 put: 0.0.

View File

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

View File

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