2022-03-01 22:58:58 +01:00
|
|
|
Class {
|
|
|
|
#name : #DiyaNode,
|
|
|
|
#superclass : #DiyaBaseObject,
|
|
|
|
#instVars : [
|
|
|
|
'translation',
|
|
|
|
'parent',
|
2022-03-03 19:19:40 +01:00
|
|
|
'children',
|
2022-03-01 22:58:58 +01:00
|
|
|
'scale',
|
|
|
|
'rotation',
|
|
|
|
'tf',
|
2022-03-02 20:11:01 +01:00
|
|
|
'shader',
|
2022-03-04 20:28:38 +01:00
|
|
|
'context',
|
2022-03-06 19:50:19 +01:00
|
|
|
'extent',
|
|
|
|
'dirty'
|
2022-03-01 22:58:58 +01:00
|
|
|
],
|
|
|
|
#pools : [
|
|
|
|
'OpenGLConstants',
|
|
|
|
'OpenGLTypes'
|
|
|
|
],
|
|
|
|
#category : #'Diya-Graphics'
|
|
|
|
}
|
|
|
|
|
2022-03-04 20:28:38 +01:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaNode class >> size: size [
|
|
|
|
^(self new) extent: size; yourself
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaNode class >> size: size shader:s [
|
|
|
|
^(self with:s) extent: size; yourself
|
|
|
|
]
|
|
|
|
|
2022-03-01 22:58:58 +01:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaNode class >> with: shader [
|
|
|
|
^self new shader: shader; yourself
|
|
|
|
]
|
|
|
|
|
2022-03-03 19:19:40 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> addNode: node [
|
|
|
|
^self addNode: node at: 0@0
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> addNode: node at: pos [
|
|
|
|
children ifNil: [ ^self ].
|
|
|
|
node parent: self.
|
|
|
|
node position: pos.
|
|
|
|
children add: node.
|
|
|
|
^ node
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> boundingBox [
|
|
|
|
^ self subclassResponsibility
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> children [
|
|
|
|
^children
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> draw [
|
|
|
|
self subclassResponsibility
|
|
|
|
]
|
|
|
|
|
2022-03-04 20:28:38 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> extent [
|
|
|
|
^ extent
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> extent: anObject [
|
2022-03-06 19:50:19 +01:00
|
|
|
extent := anObject.
|
|
|
|
dirty := true
|
2022-03-03 19:19:40 +01:00
|
|
|
]
|
|
|
|
|
2022-03-04 20:28:38 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> height [
|
|
|
|
^ extent y
|
|
|
|
]
|
|
|
|
|
2022-03-01 22:58:58 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaNode >> initialize [
|
|
|
|
super initialize.
|
|
|
|
parent := nil.
|
2022-03-03 19:19:40 +01:00
|
|
|
shader := nil.
|
2022-03-02 20:11:01 +01:00
|
|
|
context := DiyaRendererContext uniqueInstance.
|
2022-03-03 19:19:40 +01:00
|
|
|
children := OrderedCollection new.
|
2022-03-06 19:50:19 +01:00
|
|
|
dirty := false
|
2022-03-02 20:11:01 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #testing }
|
|
|
|
DiyaNode >> isRoot [
|
|
|
|
^false
|
2022-03-01 22:58:58 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> parent [
|
|
|
|
^ parent
|
|
|
|
]
|
|
|
|
|
2022-03-02 20:11:01 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> parent: anObject [
|
|
|
|
parent := anObject
|
|
|
|
]
|
|
|
|
|
2022-03-01 22:58:58 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> position [
|
|
|
|
^ translation
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> position: anObject [
|
2022-03-02 20:11:01 +01:00
|
|
|
translation := anObject.
|
|
|
|
self updateTF.
|
2022-03-01 22:58:58 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
2022-03-02 20:11:01 +01:00
|
|
|
DiyaNode >> render [
|
2022-03-06 19:50:19 +01:00
|
|
|
dirty ifTrue:[dirty := self update not].
|
2022-03-06 18:33:10 +01:00
|
|
|
shader ifNotNil: [ self setUpShader ].
|
2022-03-03 19:19:40 +01:00
|
|
|
self draw.
|
|
|
|
children ifNil: [ ^self ].
|
|
|
|
children do: [:c | c render ].
|
2022-03-01 22:58:58 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> rotation [
|
|
|
|
^ rotation
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> rotation: anObject [
|
2022-03-02 20:11:01 +01:00
|
|
|
rotation := anObject.
|
|
|
|
self updateTF.
|
2022-03-01 22:58:58 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> scale [
|
|
|
|
^ scale
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> scale: anObject [
|
2022-03-02 20:11:01 +01:00
|
|
|
scale := anObject.
|
|
|
|
self updateTF.
|
2022-03-01 22:58:58 +01:00
|
|
|
]
|
|
|
|
|
2022-03-06 18:33:10 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> setUpShader [
|
2022-03-15 19:11:19 +01:00
|
|
|
|mem|
|
|
|
|
mem := self tf asGLBuffer.
|
2022-03-06 18:33:10 +01:00
|
|
|
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;
|
2022-03-15 19:11:19 +01:00
|
|
|
setUniform: #u_transform value: {GL_TRUE. mem}.
|
2022-03-06 18:33:10 +01:00
|
|
|
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 }.
|
|
|
|
].
|
2022-03-15 19:11:19 +01:00
|
|
|
mem free.
|
2022-03-06 18:33:10 +01:00
|
|
|
]
|
|
|
|
|
2022-03-01 22:58:58 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> shader [
|
2022-03-03 19:19:40 +01:00
|
|
|
shader ifNil: [
|
|
|
|
parent ifNil: [ ^nil ].
|
|
|
|
^parent shader ].
|
2022-03-01 22:58:58 +01:00
|
|
|
^ shader
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> shader: anObject [
|
|
|
|
shader := anObject
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> tf [
|
|
|
|
parent ifNil: [ self error: 'TF: This node is not attached to the main tree' ].
|
|
|
|
^ tf
|
|
|
|
]
|
|
|
|
|
2022-03-06 19:50:19 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> update [
|
|
|
|
^self subclassResponsibility
|
|
|
|
]
|
|
|
|
|
2022-03-01 22:58:58 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> updateTF [
|
|
|
|
self subclassResponsibility
|
|
|
|
]
|
2022-03-04 20:28:38 +01:00
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaNode >> wdith [
|
|
|
|
^ extent x
|
|
|
|
]
|