mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-27 03:48:21 +01:00
OPENGL Rendering Performance improvement
This commit is contained in:
parent
a3d00d52ef
commit
2ee103191c
@ -24,7 +24,6 @@ DiyaApplicationLauncher >> bindGlobalEvent [
|
|||||||
root on: #quit do: [:e| running := false].
|
root on: #quit do: [:e| running := false].
|
||||||
root on: #(fingerdown fingermotion mousemotion) do:[:e|
|
root on: #(fingerdown fingermotion mousemotion) do:[:e|
|
||||||
pointer position: e mapped worldPosition.
|
pointer position: e mapped worldPosition.
|
||||||
"Transcript show: e mapped worldPosition asString;cr."
|
|
||||||
DiyaRendererContext uniqueInstance mouse: (e mapped x) @ (e mapped y).
|
DiyaRendererContext uniqueInstance mouse: (e mapped x) @ (e mapped y).
|
||||||
].
|
].
|
||||||
]
|
]
|
||||||
@ -34,14 +33,6 @@ DiyaApplicationLauncher >> defaultApplication [
|
|||||||
^DiyaExampleApp
|
^DiyaExampleApp
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
|
||||||
DiyaApplicationLauncher >> delta: delta [
|
|
||||||
|fps|
|
|
||||||
delta = 0 ifTrue:[^self].
|
|
||||||
fps := ((1000/delta) asInteger).
|
|
||||||
txtFPS data: ('FPS:', fps asString).
|
|
||||||
]
|
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaApplicationLauncher >> initialize [
|
DiyaApplicationLauncher >> initialize [
|
||||||
super initialize.
|
super initialize.
|
||||||
@ -58,18 +49,40 @@ DiyaApplicationLauncher >> launch: app [
|
|||||||
currapp := app uniqueInstance.
|
currapp := app uniqueInstance.
|
||||||
self appNode addNode: currapp root.
|
self appNode addNode: currapp root.
|
||||||
self context assets: currapp am.
|
self context assets: currapp am.
|
||||||
currapp setup.
|
currapp setup
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaApplicationLauncher >> main [
|
DiyaApplicationLauncher >> main [
|
||||||
|
| fps delta|
|
||||||
|
delta := DiyaClock uniqueInstance delta asMilliSeconds.
|
||||||
|
fps := DiyaBoot maxFPS.
|
||||||
|
delta = 0 ifFalse:[ fps := (1000/ delta) asInteger].
|
||||||
|
txtFPS data: ('FPS:', fps asString).
|
||||||
[(SDL2 pollEvent: event) > 0] whileTrue: [
|
[(SDL2 pollEvent: event) > 0] whileTrue: [
|
||||||
root trigger: (DiyaEvent from: event mapped).
|
root trigger: (DiyaEvent from: event mapped).
|
||||||
].
|
].
|
||||||
currapp ifNotNil: [currapp main.].
|
currapp ifNotNil: [currapp main.].
|
||||||
|
"root render."
|
||||||
|
[ root stepDown ] fork.
|
||||||
|
self process.
|
||||||
root render.
|
root render.
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #initialization }
|
||||||
|
DiyaApplicationLauncher >> process [
|
||||||
|
|Q node maxProcessingTime|
|
||||||
|
maxProcessingTime := 1000 / DiyaBoot maxFPS - 100.
|
||||||
|
Q := DiyaRendererContext uniqueInstance processQueue.
|
||||||
|
Q ifEmpty:[^ self].
|
||||||
|
[
|
||||||
|
node := Q removeFirst.
|
||||||
|
node process.
|
||||||
|
Q isNotEmpty and: DiyaClock uniqueInstance lapDelta asMilliSeconds < maxProcessingTime
|
||||||
|
] whileTrue
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaApplicationLauncher >> running [
|
DiyaApplicationLauncher >> running [
|
||||||
^ running
|
^ running
|
||||||
|
@ -102,19 +102,18 @@ DiyaBoot >> initialize [
|
|||||||
|
|
||||||
{ #category : #events }
|
{ #category : #events }
|
||||||
DiyaBoot >> render [
|
DiyaBoot >> render [
|
||||||
|delta launcher|
|
|launcher|
|
||||||
DiyaRendererContext uniqueInstance.
|
DiyaRendererContext uniqueInstance.
|
||||||
launcher := DiyaApplicationLauncher uniqueInstance.
|
launcher := DiyaApplicationLauncher uniqueInstance.
|
||||||
launcher setup.
|
launcher setup.
|
||||||
self GLinit.
|
self GLinit.
|
||||||
[ launcher running ] whileTrue: [
|
[ launcher running ] whileTrue: [
|
||||||
delta := DiyaClock uniqueInstance delta asMilliSeconds.
|
|
||||||
launcher delta: delta.
|
|
||||||
DiyaClock uniqueInstance tick.
|
DiyaClock uniqueInstance tick.
|
||||||
launcher main.
|
launcher main.
|
||||||
SDL2 glSwapWindow: window.
|
SDL2 glSwapWindow: window.
|
||||||
delta := DiyaClock uniqueInstance delta asMilliSeconds.
|
SDL2 delay:
|
||||||
SDL2 delay: (0 max: (1000/ self class maxFPS) asInteger - delta).
|
(0 max:
|
||||||
|
(1000/ self class maxFPS) asInteger - (DiyaClock uniqueInstance lapDelta asMilliSeconds)).
|
||||||
].
|
].
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3,14 +3,15 @@ Class {
|
|||||||
#superclass : #DiyaSingleton,
|
#superclass : #DiyaSingleton,
|
||||||
#instVars : [
|
#instVars : [
|
||||||
'monotonic',
|
'monotonic',
|
||||||
'lastTick'
|
'lastTick',
|
||||||
|
'lapTime'
|
||||||
],
|
],
|
||||||
#category : #'Diya-Runtime'
|
#category : #'Diya-Runtime'
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaClock >> delta [
|
DiyaClock >> delta [
|
||||||
^(DateAndTime now) - lastTick
|
^ self lapDelta + self lapTime
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
@ -22,9 +23,21 @@ DiyaClock >> elapsedTime [
|
|||||||
DiyaClock >> initialize [
|
DiyaClock >> initialize [
|
||||||
monotonic := DateAndTime now.
|
monotonic := DateAndTime now.
|
||||||
lastTick := monotonic.
|
lastTick := monotonic.
|
||||||
|
lapTime := 0 asDuration.
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #initialization }
|
||||||
|
DiyaClock >> lapDelta [
|
||||||
|
^ ((DateAndTime now) - lastTick)
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #initialization }
|
||||||
|
DiyaClock >> lapTime [
|
||||||
|
^ lapTime
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaClock >> tick [
|
DiyaClock >> tick [
|
||||||
|
lapTime := (DateAndTime now) - lastTick.
|
||||||
lastTick := DateAndTime now.
|
lastTick := DateAndTime now.
|
||||||
]
|
]
|
||||||
|
@ -11,6 +11,13 @@ DiyaExampleApp >> cleanup [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaExampleApp >> defineStyleSheet [
|
DiyaExampleApp >> defineStyleSheet [
|
||||||
|
|fmgr style|
|
||||||
|
fmgr := DiyaFontManager uniqueInstance.
|
||||||
|
#(16 24) do:[:fontSize|
|
||||||
|
Transcript show: 'Init font size ', fontSize asString, ' of ', fmgr defaultFamily; cr.
|
||||||
|
style := fmgr style: fmgr defaultStyle from: fmgr defaultFamily.
|
||||||
|
style textureOf: fontSize.
|
||||||
|
].
|
||||||
DiyaUIThemesManager uniqueInstance currentTheme
|
DiyaUIThemesManager uniqueInstance currentTheme
|
||||||
define: #text_icon_1 styles: {
|
define: #text_icon_1 styles: {
|
||||||
#color -> Color orange.
|
#color -> Color orange.
|
||||||
|
@ -142,7 +142,6 @@ DiyaImageTex >> setup [
|
|||||||
DiyaImageTex >> surfaceFromFile: aPath [
|
DiyaImageTex >> surfaceFromFile: aPath [
|
||||||
aPath exists ifFalse: [ ^DiyaCoreAPIError signal:'File not found ', aPath fullName ].
|
aPath exists ifFalse: [ ^DiyaCoreAPIError signal:'File not found ', aPath fullName ].
|
||||||
[^ SDL2Image SDLImgLoad: aPath fullName] on: Error do: [
|
[^ SDL2Image SDLImgLoad: aPath fullName] on: Error do: [
|
||||||
Transcript show: 'FALLLING BACCCCCCCCCCCCCCCCCCCCCCCCK'; cr.
|
|
||||||
^ self surfaceFromForm: (ImageReadWriter formFromFileNamed: aPath)
|
^ self surfaceFromForm: (ImageReadWriter formFromFileNamed: aPath)
|
||||||
].
|
].
|
||||||
]
|
]
|
||||||
|
@ -10,7 +10,6 @@ Class {
|
|||||||
'tf',
|
'tf',
|
||||||
'shader',
|
'shader',
|
||||||
'context',
|
'context',
|
||||||
'dirty',
|
|
||||||
'ehandlers',
|
'ehandlers',
|
||||||
'root',
|
'root',
|
||||||
'styleName',
|
'styleName',
|
||||||
@ -57,7 +56,6 @@ DiyaNode >> addNode: node at: pos [
|
|||||||
node position: pos.
|
node position: pos.
|
||||||
children add: node.
|
children add: node.
|
||||||
node root: self root.
|
node root: self root.
|
||||||
Transcript show:'Added node #', self id asString; cr.
|
|
||||||
^ node
|
^ node
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -111,7 +109,6 @@ DiyaNode >> initialize [
|
|||||||
shader := nil.
|
shader := nil.
|
||||||
context := DiyaRendererContext uniqueInstance.
|
context := DiyaRendererContext uniqueInstance.
|
||||||
children := OrderedCollection new.
|
children := OrderedCollection new.
|
||||||
dirty := false.
|
|
||||||
ehandlers := Dictionary new.
|
ehandlers := Dictionary new.
|
||||||
styleName := nil.
|
styleName := nil.
|
||||||
style := nil.
|
style := nil.
|
||||||
@ -124,11 +121,6 @@ DiyaNode >> inner: aPoint [
|
|||||||
^ self subclassResponsibility
|
^ self subclassResponsibility
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #testing }
|
|
||||||
DiyaNode >> isDirty [
|
|
||||||
^ dirty
|
|
||||||
]
|
|
||||||
|
|
||||||
{ #category : #testing }
|
{ #category : #testing }
|
||||||
DiyaNode >> isRoot [
|
DiyaNode >> isRoot [
|
||||||
^ false
|
^ false
|
||||||
@ -178,9 +170,6 @@ DiyaNode >> register: aBlock to: eventName [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaNode >> render [
|
DiyaNode >> render [
|
||||||
self step.
|
|
||||||
dirty ifTrue:[
|
|
||||||
dirty := self process not].
|
|
||||||
shader ifNotNil: [self setUpShader].
|
shader ifNotNil: [self setUpShader].
|
||||||
self draw.
|
self draw.
|
||||||
children ifNil: [ ^self ].
|
children ifNil: [ ^self ].
|
||||||
@ -194,7 +183,11 @@ DiyaNode >> root [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaNode >> root: anObject [
|
DiyaNode >> root: anObject [
|
||||||
root := anObject
|
root = anObject ifTrue:[^self].
|
||||||
|
root := anObject.
|
||||||
|
children ifNotNil: [
|
||||||
|
children do:[:c | c root: root]
|
||||||
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
@ -221,12 +214,16 @@ DiyaNode >> scale: anObject [
|
|||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaNode >> setClean [
|
DiyaNode >> setClean [
|
||||||
dirty := false
|
|Q|
|
||||||
|
Q := DiyaRendererContext uniqueInstance processQueue.
|
||||||
|
Q remove: self ifAbsent: [ ]
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaNode >> setDirty [
|
DiyaNode >> setDirty [
|
||||||
dirty := true
|
|Q|
|
||||||
|
Q := DiyaRendererContext uniqueInstance processQueue.
|
||||||
|
(Q includes: self ) ifFalse:[ Q add: self].
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
@ -265,6 +262,12 @@ DiyaNode >> shader: anObject [
|
|||||||
DiyaNode >> step [
|
DiyaNode >> step [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #stepping }
|
||||||
|
DiyaNode >> stepDown [
|
||||||
|
self step
|
||||||
|
children ifNotNil: [ children do:[:c | c stepDown ] ]
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaNode >> styleName [
|
DiyaNode >> styleName [
|
||||||
^ styleName
|
^ styleName
|
||||||
|
@ -9,7 +9,8 @@ Class {
|
|||||||
'texture0',
|
'texture0',
|
||||||
'projection',
|
'projection',
|
||||||
'assets',
|
'assets',
|
||||||
'window'
|
'window',
|
||||||
|
'rqueue'
|
||||||
],
|
],
|
||||||
#pools : [
|
#pools : [
|
||||||
'OpenGLConstants',
|
'OpenGLConstants',
|
||||||
@ -66,6 +67,7 @@ DiyaRendererContext >> initialize [
|
|||||||
vbo bind: GL_ARRAY_BUFFER.
|
vbo bind: GL_ARRAY_BUFFER.
|
||||||
projection := Array2D identity: 4.
|
projection := Array2D identity: 4.
|
||||||
assets := AssetManager new.
|
assets := AssetManager new.
|
||||||
|
rqueue := OrderedCollection new.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
@ -78,12 +80,17 @@ DiyaRendererContext >> mouse: anObject [
|
|||||||
mouse := anObject
|
mouse := anObject
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaRendererContext >> processQueue [
|
||||||
|
^ rqueue
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRendererContext >> projection [
|
DiyaRendererContext >> projection [
|
||||||
^ projection
|
^ projection
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'as yet unclassified' }
|
{ #category : #accessing }
|
||||||
DiyaRendererContext >> resolution [
|
DiyaRendererContext >> resolution [
|
||||||
^ (display w) @ (display h)
|
^ (display w) @ (display h)
|
||||||
]
|
]
|
||||||
|
@ -1,9 +1,22 @@
|
|||||||
Class {
|
Class {
|
||||||
#name : #DiyaRootNode,
|
#name : #DiyaRootNode,
|
||||||
#superclass : #DiyaNode,
|
#superclass : #DiyaNode,
|
||||||
|
#instVars : [
|
||||||
|
'Q'
|
||||||
|
],
|
||||||
#category : #'Diya-Graphics'
|
#category : #'Diya-Graphics'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaRootNode >> Q [
|
||||||
|
^ Q
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaRootNode >> Q: v [
|
||||||
|
Q := v
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRootNode >> boundingBox [
|
DiyaRootNode >> boundingBox [
|
||||||
^ Rectangle origin: 0@0 corner: context resolution
|
^ Rectangle origin: 0@0 corner: context resolution
|
||||||
@ -29,10 +42,11 @@ DiyaRootNode >> initialize [
|
|||||||
parent := self.
|
parent := self.
|
||||||
shader := nil.
|
shader := nil.
|
||||||
root := self.
|
root := self.
|
||||||
styleName := #global
|
styleName := #global.
|
||||||
|
Q := OrderedCollection new
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'as yet unclassified' }
|
{ #category : #accessing }
|
||||||
DiyaRootNode >> inner: aPoint [
|
DiyaRootNode >> inner: aPoint [
|
||||||
^true
|
^true
|
||||||
]
|
]
|
||||||
@ -47,6 +61,11 @@ DiyaRootNode >> process [
|
|||||||
^true
|
^true
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaRootNode >> processingQueue [
|
||||||
|
^ Q
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaRootNode >> updateTF [
|
DiyaRootNode >> updateTF [
|
||||||
"donothing"
|
"donothing"
|
||||||
|
@ -101,7 +101,7 @@ DiyaText >> fontStyle [
|
|||||||
^ self ? #fontStyle
|
^ self ? #fontStyle
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #'text-processing' }
|
||||||
DiyaText >> formatText [
|
DiyaText >> formatText [
|
||||||
|offset index line|
|
|offset index line|
|
||||||
lines ifNil: [^self].
|
lines ifNil: [^self].
|
||||||
@ -176,7 +176,7 @@ DiyaText >> initialize [
|
|||||||
maxLineWidth := 0.
|
maxLineWidth := 0.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'as yet unclassified' }
|
{ #category : #'text-processing' }
|
||||||
DiyaText >> lastSeparatorFrom: index [
|
DiyaText >> lastSeparatorFrom: index [
|
||||||
index to: 1 by: -1 do: [:i|
|
index to: 1 by: -1 do: [:i|
|
||||||
(data at: i) isSeparator ifTrue:[^i].
|
(data at: i) isSeparator ifTrue:[^i].
|
||||||
@ -205,6 +205,10 @@ DiyaText >> process [
|
|||||||
bbox ifNil: [ ^true ].
|
bbox ifNil: [ ^true ].
|
||||||
data ifNil:[^true].
|
data ifNil:[^true].
|
||||||
data ifEmpty:[^true].
|
data ifEmpty:[^true].
|
||||||
|
texture ifNil: [ self initTexture ].
|
||||||
|
texheight = texture height ifFalse: [
|
||||||
|
texheight := texture height.
|
||||||
|
].
|
||||||
vbuffer ifNotNil: [vbuffer free].
|
vbuffer ifNotNil: [vbuffer free].
|
||||||
vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16.
|
vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16.
|
||||||
vbuffer autoRelease.
|
vbuffer autoRelease.
|
||||||
@ -226,14 +230,14 @@ DiyaText >> splitLines [
|
|||||||
] whileTrue.
|
] whileTrue.
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaText >> styleName: aName [
|
||||||
|
super styleName: aName.
|
||||||
|
texture := nil.
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaText >> texture [
|
DiyaText >> texture [
|
||||||
texture ifNil: [ self initTexture ].
|
|
||||||
texheight = texture height ifFalse: [
|
|
||||||
texheight := texture height.
|
|
||||||
self process.
|
|
||||||
self setClean.
|
|
||||||
].
|
|
||||||
^texture
|
^texture
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -252,5 +256,5 @@ DiyaText >> valignText:h [
|
|||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaText >> wordWrap: aBool [
|
DiyaText >> wordWrap: aBool [
|
||||||
wrap := aBool.
|
wrap := aBool.
|
||||||
dirty := true
|
self setDirty
|
||||||
]
|
]
|
||||||
|
@ -22,8 +22,8 @@ SDL2Image class >> checkSymbol [
|
|||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
SDL2Image class >> libNames [
|
SDL2Image class >> libNames [
|
||||||
^#(
|
^#(
|
||||||
'libSDL2_image-2.0.so.0'
|
|
||||||
'libSDL2_image.so'
|
'libSDL2_image.so'
|
||||||
|
'libSDL2_image-2.0.so.0'
|
||||||
'libSDL2_image-2.0.so'
|
'libSDL2_image-2.0.so'
|
||||||
'libSDL2_image-2.0.so.0.2.3'
|
'libSDL2_image-2.0.so.0.2.3'
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user