mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-27 11:58:21 +01:00
Fix memory leak bug
This commit is contained in:
parent
172a62192e
commit
fcc7b13d28
@ -87,7 +87,6 @@ DiyaBoot >> exampleNodes [
|
|||||||
text extent: 200@320.
|
text extent: 200@320.
|
||||||
text wordWrap: true.
|
text wordWrap: true.
|
||||||
^ root
|
^ root
|
||||||
"text rotation:(Float pi / 4.0); scale: 2.0@2.0."
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #events }
|
{ #category : #events }
|
||||||
@ -123,6 +122,7 @@ DiyaBoot >> processEvent: event [
|
|||||||
mappedEvt type = SDL_FINGERDOWN ifTrue:[^self setCursorPosition: mappedEvt ].
|
mappedEvt type = SDL_FINGERDOWN ifTrue:[^self setCursorPosition: mappedEvt ].
|
||||||
mappedEvt type = SDL_FINGERMOTION 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 type = SDL_MOUSEMOTION ifTrue:[DiyaRendererContext uniqueInstance mouse: (mappedEvt x) @ (mappedEvt y)].
|
||||||
|
mappedEvt free.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #events }
|
{ #category : #events }
|
||||||
@ -144,8 +144,8 @@ DiyaBoot >> render [
|
|||||||
text extent: 80@40.
|
text extent: 80@40.
|
||||||
text fontSize: 20.
|
text fontSize: 20.
|
||||||
text color: Color red.
|
text color: Color red.
|
||||||
|
DiyaRendererContext uniqueInstance.
|
||||||
self GLinit.
|
self GLinit.
|
||||||
OpenGL viewportX: 0 Y:0 W: display w H: display h.
|
|
||||||
[ running ] whileTrue: [
|
[ running ] whileTrue: [
|
||||||
delta := DiyaClock uniqueInstance delta asMilliSeconds.
|
delta := DiyaClock uniqueInstance delta asMilliSeconds.
|
||||||
text data: ('FPS:', (1000/delta) asInteger asString).
|
text data: ('FPS:', (1000/delta) asInteger asString).
|
||||||
@ -154,6 +154,7 @@ DiyaBoot >> render [
|
|||||||
self processEvent: event
|
self processEvent: event
|
||||||
].
|
].
|
||||||
DiyaRenderer uniqueInstance render.
|
DiyaRenderer uniqueInstance render.
|
||||||
|
|
||||||
SDL2 glSwapWindow: window.
|
SDL2 glSwapWindow: window.
|
||||||
delta := DiyaClock uniqueInstance delta asMilliSeconds.
|
delta := DiyaClock uniqueInstance delta asMilliSeconds.
|
||||||
SDL2 delay: (0 max: (1000/ self class maxFPS) asInteger - delta). "60 fps"
|
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' ].
|
display ifNil: [ ^self error: 'Please run #init before this method' ].
|
||||||
self createWindow.
|
self createWindow.
|
||||||
self createGLContext.
|
self createGLContext.
|
||||||
SDL2 glMakeCurrent: window context: context.
|
"SDL2 glMakeCurrent: window context: context."
|
||||||
self showSystemInfo.
|
self showSystemInfo.
|
||||||
DiyaRendererContext uniqueInstance display: display; useProjection: OrthoProjectionMatrix.
|
DiyaRendererContext
|
||||||
|
uniqueInstance display: display;
|
||||||
|
useProjection: OrthoProjectionMatrix.
|
||||||
self render.
|
self render.
|
||||||
context delete.
|
context delete.
|
||||||
window destroy.
|
window destroy.
|
||||||
|
@ -16,7 +16,7 @@ DiyaFontFamily class >> fromFace: face [
|
|||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaFontFamily >> addFace: face [
|
DiyaFontFamily >> addFace: face [
|
||||||
name ifNil: [ name := face familyName ].
|
name ifNil: [ name := face familyName ].
|
||||||
styles at: face styleName ifAbsentPut: (DiyaFontStyle fromFace: face).
|
styles at: face styleName ifAbsentPut: [(DiyaFontStyle fromFace: face)].
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
|
@ -149,18 +149,21 @@ DiyaNode >> scale: anObject [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaNode >> setUpShader [
|
DiyaNode >> setUpShader [
|
||||||
|
|mem|
|
||||||
|
mem := self tf asGLBuffer.
|
||||||
shader use;
|
shader use;
|
||||||
setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat;
|
setUniform: #u_time value: DiyaClock uniqueInstance elapsedTime asFloat;
|
||||||
setUniform: #u_projection value: {GL_FALSE. context projection buffer};
|
setUniform: #u_projection value: {GL_FALSE. context projection buffer};
|
||||||
setUniform: #u_resolution value: { context resolution x. context resolution y };
|
setUniform: #u_resolution value: { context resolution x. context resolution y };
|
||||||
setUniform: #u_texture value: 0;
|
setUniform: #u_texture value: 0;
|
||||||
setUniform: #u_transform value: {GL_TRUE. self tf asGLBuffer}.
|
setUniform: #u_transform value: {GL_TRUE. mem}.
|
||||||
context mouse ifNotNil: [
|
context mouse ifNotNil: [
|
||||||
"in shader, window origin is bottom left conor of the window
|
"in shader, window origin is bottom left conor of the window
|
||||||
the mouse position should be transformed to this coodinate"
|
the mouse position should be transformed to this coodinate"
|
||||||
shader setUniform: #u_mouse value:
|
shader setUniform: #u_mouse value:
|
||||||
{ context mouse x. context resolution y - context mouse y }.
|
{ context mouse x. context resolution y - context mouse y }.
|
||||||
].
|
].
|
||||||
|
mem free.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
|
@ -18,6 +18,7 @@ Class {
|
|||||||
|
|
||||||
{ #category : #'instance creation' }
|
{ #category : #'instance creation' }
|
||||||
DiyaRendererContext class >> cleanUpInstance: singleton [
|
DiyaRendererContext class >> cleanUpInstance: singleton [
|
||||||
|
singleton ifNil:[^self].
|
||||||
singleton destroy
|
singleton destroy
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -52,7 +53,6 @@ DiyaRendererContext >> initialize [
|
|||||||
vao bind.
|
vao bind.
|
||||||
vbo bind: GL_ARRAY_BUFFER.
|
vbo bind: GL_ARRAY_BUFFER.
|
||||||
projection := Array2D identity: 4.
|
projection := Array2D identity: 4.
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
|
@ -24,14 +24,20 @@ DiyaSingleton class >> new [
|
|||||||
|
|
||||||
{ #category : #'instance creation' }
|
{ #category : #'instance creation' }
|
||||||
DiyaSingleton class >> reset [
|
DiyaSingleton class >> reset [
|
||||||
|singleton|
|
|singleton key|
|
||||||
singleton := singletons at: self class ifAbsent: [ ^ self ].
|
key := self class asString asSymbol.
|
||||||
|
singleton := singletons at: key ifAbsent: [ ^ self ].
|
||||||
self cleanUpInstance: singleton.
|
self cleanUpInstance: singleton.
|
||||||
singletons removeKey: self class
|
singletons removeKey: key
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'instance creation' }
|
{ #category : #'instance creation' }
|
||||||
DiyaSingleton class >> uniqueInstance [
|
DiyaSingleton class >> uniqueInstance [
|
||||||
singletons at: self class ifAbsentPut: super new.
|
^singletons at: self class asString asSymbol ifAbsentPut: [ super new ].
|
||||||
^ singletons at: self class
|
]
|
||||||
|
|
||||||
|
{ #category : #initialization }
|
||||||
|
DiyaSingleton >> initialize [
|
||||||
|
super initialize.
|
||||||
|
Transcript show: 'Initialise unique instance of ', self className; cr.
|
||||||
]
|
]
|
||||||
|
@ -19,6 +19,7 @@ OpenGLSL class >> attachShader: shader to: program [
|
|||||||
|
|
||||||
{ #category : #'instance creation' }
|
{ #category : #'instance creation' }
|
||||||
OpenGLSL class >> cleanUpInstance: singleton [
|
OpenGLSL class >> cleanUpInstance: singleton [
|
||||||
|
singleton ifNil:[^self].
|
||||||
singleton delete
|
singleton delete
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3,8 +3,7 @@ Class {
|
|||||||
#superclass : #DiyaBaseObject,
|
#superclass : #DiyaBaseObject,
|
||||||
#instVars : [
|
#instVars : [
|
||||||
'uname',
|
'uname',
|
||||||
'location',
|
'location'
|
||||||
'value'
|
|
||||||
],
|
],
|
||||||
#pools : [
|
#pools : [
|
||||||
'OpenGLConstants',
|
'OpenGLConstants',
|
||||||
@ -89,7 +88,7 @@ OpenGLSLUniform >> location: anObject [
|
|||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
OpenGLSLUniform >> setUniformValue [
|
OpenGLSLUniform >> setUniformValue: value [
|
||||||
^ self subclassResponsibility
|
^ self subclassResponsibility
|
||||||
|
|
||||||
]
|
]
|
||||||
@ -104,15 +103,9 @@ OpenGLSLUniform >> uname: anObject [
|
|||||||
uname := anObject
|
uname := anObject
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
|
||||||
OpenGLSLUniform >> value [
|
|
||||||
^ value
|
|
||||||
]
|
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
OpenGLSLUniform >> value: values [
|
OpenGLSLUniform >> value: values [
|
||||||
location = -1 ifTrue: [ ^self ].
|
location = -1 ifTrue: [ ^self ].
|
||||||
value := values.
|
self setUniformValue: values.
|
||||||
self setUniformValue.
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -9,6 +9,6 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Uniform1F >> setUniformValue [
|
Uniform1F >> setUniformValue: value [
|
||||||
OpenGLSLUniform uniform1f: location value: value
|
OpenGLSLUniform uniform1f: location value: value
|
||||||
]
|
]
|
||||||
|
@ -9,6 +9,6 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Uniform1i >> setUniformValue [
|
Uniform1i >> setUniformValue: value [
|
||||||
OpenGLSLUniform uniform1i: location value: value
|
OpenGLSLUniform uniform1i: location value: value
|
||||||
]
|
]
|
||||||
|
@ -9,6 +9,6 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Uniform2F >> setUniformValue [
|
Uniform2F >> setUniformValue: value [
|
||||||
OpenGLSLUniform uniform2f: location value: value first value: value last
|
OpenGLSLUniform uniform2f: location value: value first value: value last
|
||||||
]
|
]
|
||||||
|
@ -9,6 +9,6 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Uniform2i >> setUniformValue [
|
Uniform2i >> setUniformValue: value [
|
||||||
OpenGLSLUniform uniform2i: location value: value first value: value last
|
OpenGLSLUniform uniform2i: location value: value first value: value last
|
||||||
]
|
]
|
||||||
|
@ -9,6 +9,6 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Uniform3F >> setUniformValue [
|
Uniform3F >> setUniformValue: value [
|
||||||
OpenGLSLUniform uniform3f: location value: value first value: (value at:2) value: value last
|
OpenGLSLUniform uniform3f: location value: value first value: (value at:2) value: value last
|
||||||
]
|
]
|
||||||
|
@ -9,6 +9,6 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Uniform3i >> setUniformValue [
|
Uniform3i >> setUniformValue: value [
|
||||||
OpenGLSLUniform uniform3i: location value: value first value: (value at:2) value: value last
|
OpenGLSLUniform uniform3i: location value: value first value: (value at:2) value: value last
|
||||||
]
|
]
|
||||||
|
@ -9,7 +9,7 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Uniform4F >> setUniformValue [
|
Uniform4F >> setUniformValue: value [
|
||||||
OpenGLSLUniform uniform4f: location
|
OpenGLSLUniform uniform4f: location
|
||||||
value: value first
|
value: value first
|
||||||
value: (value at:2)
|
value: (value at:2)
|
||||||
|
@ -9,7 +9,7 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Uniform4i >> setUniformValue [
|
Uniform4i >> setUniformValue: value [
|
||||||
OpenGLSLUniform uniform4i: location
|
OpenGLSLUniform uniform4i: location
|
||||||
value: value first
|
value: value first
|
||||||
value: (value at:2)
|
value: (value at:2)
|
||||||
|
@ -9,7 +9,7 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
UniformMatrix3fv >> setUniformValue [
|
UniformMatrix3fv >> setUniformValue: value [
|
||||||
OpenGLSLUniform
|
OpenGLSLUniform
|
||||||
uniformMatrix3fv: location
|
uniformMatrix3fv: location
|
||||||
count: 1
|
count: 1
|
||||||
|
@ -9,7 +9,7 @@ Class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
UniformMatrix4fv >> setUniformValue [
|
UniformMatrix4fv >> setUniformValue: value [
|
||||||
OpenGLSLUniform
|
OpenGLSLUniform
|
||||||
uniformMatrix4fv: location
|
uniformMatrix4fv: location
|
||||||
count: 1
|
count: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user