diff --git a/Diya/DiyaApplicationLauncher.class.st b/Diya/DiyaApplicationLauncher.class.st index 4f1fd88..d94b26d 100644 --- a/Diya/DiyaApplicationLauncher.class.st +++ b/Diya/DiyaApplicationLauncher.class.st @@ -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 } diff --git a/Diya/DiyaNode.class.st b/Diya/DiyaNode.class.st index 77bf113..05e0fcf 100644 --- a/Diya/DiyaNode.class.st +++ b/Diya/DiyaNode.class.st @@ -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 } diff --git a/Diya/DiyaRendererContext.class.st b/Diya/DiyaRendererContext.class.st index 832f103..81b29e0 100644 --- a/Diya/DiyaRendererContext.class.st +++ b/Diya/DiyaRendererContext.class.st @@ -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 ] diff --git a/Diya/DiyaRootNode.class.st b/Diya/DiyaRootNode.class.st index 4ef80fd..7b80fab 100644 --- a/Diya/DiyaRootNode.class.st +++ b/Diya/DiyaRootNode.class.st @@ -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 }