mirror of
https://github.com/lxsang/Diya-API.git
synced 2025-03-12 18:42:48 +01:00
Rendering improvement: render a limited number of nodes (based on FPS setting) on the back buffer each iterration.
The back buffer is only swapped when all nodes are rendered
This commit is contained in:
parent
c7af75550f
commit
26368c37ab
@ -36,7 +36,7 @@ DiyaApplicationLauncher >> defaultApplication [
|
||||
{ #category : #initialization }
|
||||
DiyaApplicationLauncher >> initialize [
|
||||
super initialize.
|
||||
root := DiyaRootNode new.
|
||||
root := DiyaRendererContext uniqueInstance root.
|
||||
currapp := nil.
|
||||
]
|
||||
|
||||
@ -52,8 +52,8 @@ DiyaApplicationLauncher >> launch: app [
|
||||
self stdlog: 'Loading application'.
|
||||
currapp root visibility: false.
|
||||
currapp setup.
|
||||
currapp root forceReload.
|
||||
self appNode addNode: currapp root.
|
||||
self process: true.
|
||||
currapp root visibility: true.
|
||||
self stdlog: 'Application LOADED'.
|
||||
] fork.
|
||||
@ -70,24 +70,6 @@ DiyaApplicationLauncher >> main [
|
||||
root trigger: (DiyaEvent from: event mapped).
|
||||
].
|
||||
currapp ifNotNil: [currapp main.].
|
||||
root stepDown.
|
||||
self process: false.
|
||||
root render.
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaApplicationLauncher >> process: force [
|
||||
|Q node maxProcessingTime|
|
||||
maxProcessingTime := (1000 / DiyaBoot maxFPS) asInteger >> 1.
|
||||
Q := root processingQueue.
|
||||
Q ifEmpty:[^ self].
|
||||
[
|
||||
node := Q removeFirst.
|
||||
node process.
|
||||
Q isNotEmpty and: (
|
||||
(DiyaClock uniqueInstance lapDelta asMilliSeconds < maxProcessingTime) or: force)
|
||||
] whileTrue
|
||||
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
|
@ -90,6 +90,7 @@ DiyaNode >> extent [
|
||||
{ #category : #processing }
|
||||
DiyaNode >> forceReload [
|
||||
self process.
|
||||
self setClean.
|
||||
children ifNotNil: [
|
||||
children do:[:c|
|
||||
c forceReload
|
||||
@ -189,10 +190,11 @@ DiyaNode >> removeChild: c [
|
||||
{ #category : #rendering }
|
||||
DiyaNode >> render [
|
||||
visibility ifFalse:[^self].
|
||||
root ifNil: [ ^self ].
|
||||
shader ifNotNil: [self setUpShader].
|
||||
self draw.
|
||||
children ifNil: [ ^self ].
|
||||
children do: [:c| c render ].
|
||||
root renderNext: children
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
|
@ -9,7 +9,8 @@ Class {
|
||||
'texture0',
|
||||
'projection',
|
||||
'assets',
|
||||
'window'
|
||||
'window',
|
||||
'root'
|
||||
],
|
||||
#pools : [
|
||||
'OpenGLConstants',
|
||||
@ -86,17 +87,34 @@ DiyaRendererContext >> projection [
|
||||
^ projection
|
||||
]
|
||||
|
||||
{ #category : #rendering }
|
||||
DiyaRendererContext >> render [
|
||||
root render.
|
||||
root readyForSwap ifTrue: [
|
||||
SDL2 glSwapWindow: window.
|
||||
]
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRendererContext >> resolution [
|
||||
^ (display w) @ (display h)
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRendererContext >> root [
|
||||
root ifNil: [ root := DiyaRootNode new ].
|
||||
^ root
|
||||
|
||||
|
||||
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRendererContext >> texture0 [
|
||||
^ texture0
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
{ #category : #'transformation matrices' }
|
||||
DiyaRendererContext >> useProjection: aClass [
|
||||
projection := aClass fromDisplay: self display
|
||||
]
|
||||
|
@ -2,16 +2,12 @@ Class {
|
||||
#name : #DiyaRootNode,
|
||||
#superclass : #DiyaNode,
|
||||
#instVars : [
|
||||
'Q'
|
||||
'Q',
|
||||
'R'
|
||||
],
|
||||
#category : #'Diya-Graphics'
|
||||
}
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRootNode >> Q [
|
||||
^ Q
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRootNode >> boundingBox [
|
||||
^ Rectangle origin: 0@0 corner: context resolution
|
||||
@ -28,12 +24,11 @@ DiyaRootNode >> draw [
|
||||
c := self ? #bgColor.
|
||||
OpenGL clearColorR: c red G: c green B: c blue A: c alpha.
|
||||
OpenGL clear: GL_COLOR_BUFFER_BIT.
|
||||
"context vbo bind: GL_ARRAY_BUFFER."
|
||||
]
|
||||
|
||||
{ #category : #'add/remove' }
|
||||
DiyaRootNode >> enqueueDirtyNode: aNode [
|
||||
(Q includes: aNode ) ifFalse:[ Q add: aNode].
|
||||
Q addIfNotPresent: aNode
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
@ -48,7 +43,8 @@ DiyaRootNode >> initialize [
|
||||
shader := nil.
|
||||
root := self.
|
||||
styleName := #global.
|
||||
Q := OrderedCollection new
|
||||
Q := OrderedCollection new.
|
||||
R := OrderedCollection new.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
@ -66,9 +62,37 @@ DiyaRootNode >> process [
|
||||
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRootNode >> processingQueue [
|
||||
^ Q
|
||||
{ #category : #testing }
|
||||
DiyaRootNode >> readyForSwap [
|
||||
^ R isEmpty
|
||||
]
|
||||
|
||||
{ #category : #rendering }
|
||||
DiyaRootNode >> render [
|
||||
|node maxProcessingTime|
|
||||
self stepDown.
|
||||
R ifEmpty: [
|
||||
self draw.
|
||||
self renderNext: children
|
||||
].
|
||||
maxProcessingTime := (1000 / DiyaBoot maxFPS) asInteger.
|
||||
[
|
||||
Q ifNotEmpty: [
|
||||
node := Q removeFirst.
|
||||
node process.
|
||||
].
|
||||
R ifNotEmpty: [
|
||||
node := R removeFirst.
|
||||
node render.
|
||||
].
|
||||
(R isNotEmpty or: Q isNotEmpty) and:
|
||||
(DiyaClock uniqueInstance lapDelta asMilliSeconds < maxProcessingTime)
|
||||
] whileTrue
|
||||
]
|
||||
|
||||
{ #category : #rendering }
|
||||
DiyaRootNode >> renderNext: nodes [
|
||||
R addAllFirstUnlessAlreadyPresent: nodes.
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
|
Loading…
x
Reference in New Issue
Block a user