diff --git a/Diya/DiyaBoot.class.st b/Diya/DiyaBoot.class.st index ccbbb33..30f66de 100644 --- a/Diya/DiyaBoot.class.st +++ b/Diya/DiyaBoot.class.st @@ -87,7 +87,6 @@ DiyaBoot >> exampleNodes [ text extent: 200@320. text wordWrap: true. ^ root - "text rotation:(Float pi / 4.0); scale: 2.0@2.0." ] { #category : #events } @@ -123,6 +122,7 @@ DiyaBoot >> processEvent: event [ mappedEvt type = SDL_FINGERDOWN ifTrue:[^self setCursorPosition: mappedEvt ]. mappedEvt type = SDL_FINGERMOTION ifTrue:[^self setCursorPosition: mappedEvt ]. mappedEvt type = SDL_MOUSEMOTION ifTrue:[DiyaRendererContext uniqueInstance mouse: (mappedEvt x) @ (mappedEvt y)]. + mappedEvt free. ] { #category : #events } @@ -144,8 +144,8 @@ DiyaBoot >> render [ text extent: 80@40. text fontSize: 20. text color: Color red. + DiyaRendererContext uniqueInstance. self GLinit. - OpenGL viewportX: 0 Y:0 W: display w H: display h. [ running ] whileTrue: [ delta := DiyaClock uniqueInstance delta asMilliSeconds. text data: ('FPS:', (1000/delta) asInteger asString). @@ -154,6 +154,7 @@ DiyaBoot >> render [ self processEvent: event ]. DiyaRenderer uniqueInstance render. + SDL2 glSwapWindow: window. delta := DiyaClock uniqueInstance delta asMilliSeconds. SDL2 delay: (0 max: (1000/ self class maxFPS) asInteger - delta). "60 fps" @@ -234,9 +235,11 @@ DiyaBoot >> startx [ display ifNil: [ ^self error: 'Please run #init before this method' ]. self createWindow. self createGLContext. - SDL2 glMakeCurrent: window context: context. + "SDL2 glMakeCurrent: window context: context." self showSystemInfo. - DiyaRendererContext uniqueInstance display: display; useProjection: OrthoProjectionMatrix. + DiyaRendererContext + uniqueInstance display: display; + useProjection: OrthoProjectionMatrix. self render. context delete. window destroy. diff --git a/Diya/DiyaFontFamily.class.st b/Diya/DiyaFontFamily.class.st index 9633af4..5ce48ed 100644 --- a/Diya/DiyaFontFamily.class.st +++ b/Diya/DiyaFontFamily.class.st @@ -16,7 +16,7 @@ DiyaFontFamily class >> fromFace: face [ { #category : #accessing } DiyaFontFamily >> addFace: face [ name ifNil: [ name := face familyName ]. - styles at: face styleName ifAbsentPut: (DiyaFontStyle fromFace: face). + styles at: face styleName ifAbsentPut: [(DiyaFontStyle fromFace: face)]. ] { #category : #initialization } diff --git a/Diya/DiyaNode.class.st b/Diya/DiyaNode.class.st index d9adb8f..b89d270 100644 --- a/Diya/DiyaNode.class.st +++ b/Diya/DiyaNode.class.st @@ -149,18 +149,21 @@ DiyaNode >> scale: anObject [ { #category : #accessing } DiyaNode >> setUpShader [ + |mem| + mem := self tf asGLBuffer. shader use; setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat; setUniform: #u_projection value: {GL_FALSE. context projection buffer}; setUniform: #u_resolution value: { context resolution x. context resolution y }; setUniform: #u_texture value: 0; - setUniform: #u_transform value: {GL_TRUE. self tf asGLBuffer}. + setUniform: #u_transform value: {GL_TRUE. mem}. context mouse ifNotNil: [ "in shader, window origin is bottom left conor of the window the mouse position should be transformed to this coodinate" shader setUniform: #u_mouse value: { context mouse x. context resolution y - context mouse y }. ]. + mem free. ] { #category : #accessing } diff --git a/Diya/DiyaRendererContext.class.st b/Diya/DiyaRendererContext.class.st index 45658f0..33d7abc 100644 --- a/Diya/DiyaRendererContext.class.st +++ b/Diya/DiyaRendererContext.class.st @@ -18,6 +18,7 @@ Class { { #category : #'instance creation' } DiyaRendererContext class >> cleanUpInstance: singleton [ + singleton ifNil:[^self]. singleton destroy ] @@ -52,7 +53,6 @@ DiyaRendererContext >> initialize [ vao bind. vbo bind: GL_ARRAY_BUFFER. projection := Array2D identity: 4. - ] { #category : #accessing } diff --git a/Diya/DiyaSingleton.class.st b/Diya/DiyaSingleton.class.st index 7d87291..fa8a6e9 100644 --- a/Diya/DiyaSingleton.class.st +++ b/Diya/DiyaSingleton.class.st @@ -24,14 +24,20 @@ DiyaSingleton class >> new [ { #category : #'instance creation' } DiyaSingleton class >> reset [ - |singleton| - singleton := singletons at: self class ifAbsent: [ ^ self ]. + |singleton key| + key := self class asString asSymbol. + singleton := singletons at: key ifAbsent: [ ^ self ]. self cleanUpInstance: singleton. - singletons removeKey: self class + singletons removeKey: key ] { #category : #'instance creation' } DiyaSingleton class >> uniqueInstance [ - singletons at: self class ifAbsentPut: super new. - ^ singletons at: self class + ^singletons at: self class asString asSymbol ifAbsentPut: [ super new ]. +] + +{ #category : #initialization } +DiyaSingleton >> initialize [ + super initialize. + Transcript show: 'Initialise unique instance of ', self className; cr. ] diff --git a/Diya/OpenGLSL.class.st b/Diya/OpenGLSL.class.st index 6963583..a625e05 100644 --- a/Diya/OpenGLSL.class.st +++ b/Diya/OpenGLSL.class.st @@ -19,6 +19,7 @@ OpenGLSL class >> attachShader: shader to: program [ { #category : #'instance creation' } OpenGLSL class >> cleanUpInstance: singleton [ + singleton ifNil:[^self]. singleton delete ] diff --git a/Diya/OpenGLSLUniform.class.st b/Diya/OpenGLSLUniform.class.st index 819693c..3db9222 100644 --- a/Diya/OpenGLSLUniform.class.st +++ b/Diya/OpenGLSLUniform.class.st @@ -3,8 +3,7 @@ Class { #superclass : #DiyaBaseObject, #instVars : [ 'uname', - 'location', - 'value' + 'location' ], #pools : [ 'OpenGLConstants', @@ -89,7 +88,7 @@ OpenGLSLUniform >> location: anObject [ ] { #category : #accessing } -OpenGLSLUniform >> setUniformValue [ +OpenGLSLUniform >> setUniformValue: value [ ^ self subclassResponsibility ] @@ -104,15 +103,9 @@ OpenGLSLUniform >> uname: anObject [ uname := anObject ] -{ #category : #accessing } -OpenGLSLUniform >> value [ - ^ value -] - { #category : #accessing } OpenGLSLUniform >> value: values [ location = -1 ifTrue: [ ^self ]. - value := values. - self setUniformValue. + self setUniformValue: values. ] diff --git a/Diya/Uniform1F.class.st b/Diya/Uniform1F.class.st index 263cf04..660a8bb 100644 --- a/Diya/Uniform1F.class.st +++ b/Diya/Uniform1F.class.st @@ -9,6 +9,6 @@ Class { } { #category : #accessing } -Uniform1F >> setUniformValue [ +Uniform1F >> setUniformValue: value [ OpenGLSLUniform uniform1f: location value: value ] diff --git a/Diya/Uniform1i.class.st b/Diya/Uniform1i.class.st index adf6395..3e5ab9e 100644 --- a/Diya/Uniform1i.class.st +++ b/Diya/Uniform1i.class.st @@ -9,6 +9,6 @@ Class { } { #category : #accessing } -Uniform1i >> setUniformValue [ +Uniform1i >> setUniformValue: value [ OpenGLSLUniform uniform1i: location value: value ] diff --git a/Diya/Uniform2F.class.st b/Diya/Uniform2F.class.st index c196654..58a97a1 100644 --- a/Diya/Uniform2F.class.st +++ b/Diya/Uniform2F.class.st @@ -9,6 +9,6 @@ Class { } { #category : #accessing } -Uniform2F >> setUniformValue [ +Uniform2F >> setUniformValue: value [ OpenGLSLUniform uniform2f: location value: value first value: value last ] diff --git a/Diya/Uniform2i.class.st b/Diya/Uniform2i.class.st index 58266ab..578b100 100644 --- a/Diya/Uniform2i.class.st +++ b/Diya/Uniform2i.class.st @@ -9,6 +9,6 @@ Class { } { #category : #accessing } -Uniform2i >> setUniformValue [ +Uniform2i >> setUniformValue: value [ OpenGLSLUniform uniform2i: location value: value first value: value last ] diff --git a/Diya/Uniform3F.class.st b/Diya/Uniform3F.class.st index 69aa0e5..781d762 100644 --- a/Diya/Uniform3F.class.st +++ b/Diya/Uniform3F.class.st @@ -9,6 +9,6 @@ Class { } { #category : #accessing } -Uniform3F >> setUniformValue [ +Uniform3F >> setUniformValue: value [ OpenGLSLUniform uniform3f: location value: value first value: (value at:2) value: value last ] diff --git a/Diya/Uniform3i.class.st b/Diya/Uniform3i.class.st index 68b912a..0ec826c 100644 --- a/Diya/Uniform3i.class.st +++ b/Diya/Uniform3i.class.st @@ -9,6 +9,6 @@ Class { } { #category : #accessing } -Uniform3i >> setUniformValue [ +Uniform3i >> setUniformValue: value [ OpenGLSLUniform uniform3i: location value: value first value: (value at:2) value: value last ] diff --git a/Diya/Uniform4F.class.st b/Diya/Uniform4F.class.st index 9dd3236..2cbb356 100644 --- a/Diya/Uniform4F.class.st +++ b/Diya/Uniform4F.class.st @@ -9,7 +9,7 @@ Class { } { #category : #accessing } -Uniform4F >> setUniformValue [ +Uniform4F >> setUniformValue: value [ OpenGLSLUniform uniform4f: location value: value first value: (value at:2) diff --git a/Diya/Uniform4i.class.st b/Diya/Uniform4i.class.st index 60661eb..0b19e48 100644 --- a/Diya/Uniform4i.class.st +++ b/Diya/Uniform4i.class.st @@ -9,7 +9,7 @@ Class { } { #category : #accessing } -Uniform4i >> setUniformValue [ +Uniform4i >> setUniformValue: value [ OpenGLSLUniform uniform4i: location value: value first value: (value at:2) diff --git a/Diya/UniformMatrix3fv.class.st b/Diya/UniformMatrix3fv.class.st index 1657aef..b72f457 100644 --- a/Diya/UniformMatrix3fv.class.st +++ b/Diya/UniformMatrix3fv.class.st @@ -9,7 +9,7 @@ Class { } { #category : #accessing } -UniformMatrix3fv >> setUniformValue [ +UniformMatrix3fv >> setUniformValue: value [ OpenGLSLUniform uniformMatrix3fv: location count: 1 diff --git a/Diya/UniformMatrix4fv.class.st b/Diya/UniformMatrix4fv.class.st index 8659220..f06c04f 100644 --- a/Diya/UniformMatrix4fv.class.st +++ b/Diya/UniformMatrix4fv.class.st @@ -9,7 +9,7 @@ Class { } { #category : #accessing } -UniformMatrix4fv >> setUniformValue [ +UniformMatrix4fv >> setUniformValue: value [ OpenGLSLUniform uniformMatrix4fv: location count: 1