2022-03-06 18:33:10 +01:00
|
|
|
Class {
|
|
|
|
#name : #Diya2DPrimShape,
|
|
|
|
#superclass : #Diya2DNode,
|
|
|
|
#instVars : [
|
2022-03-16 01:32:01 +01:00
|
|
|
'texture',
|
|
|
|
'type',
|
2022-03-19 02:18:29 +01:00
|
|
|
'bbox'
|
2022-03-06 18:33:10 +01:00
|
|
|
],
|
|
|
|
#category : #'Diya-Graphics'
|
|
|
|
}
|
|
|
|
|
2022-03-23 00:52:15 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> border [
|
|
|
|
^style get: #border
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> borderColor [
|
|
|
|
^style get: #borderColor
|
|
|
|
]
|
|
|
|
|
2022-03-16 01:32:01 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> borderColor: c [
|
2022-03-23 00:52:15 +01:00
|
|
|
style set: #borderColor value: c.
|
2022-03-16 01:32:01 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> borderWidth: w [
|
2022-03-23 00:52:15 +01:00
|
|
|
style set: #border value: w.
|
2022-03-16 01:32:01 +01:00
|
|
|
]
|
|
|
|
|
2022-03-19 02:18:29 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> boundingBox [
|
|
|
|
^ bbox applyTf: self tf.
|
|
|
|
]
|
|
|
|
|
2022-03-06 19:50:19 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
Diya2DPrimShape >> draw [
|
|
|
|
vbuffer ifNil: [ ^self ].
|
|
|
|
"configure vao vbo for texture QUAD"
|
|
|
|
self texture ifNotNil: [
|
|
|
|
self texture setup.
|
2022-03-08 23:30:01 +01:00
|
|
|
context texture0 setImage2D: self texture.
|
2022-03-06 19:50:19 +01:00
|
|
|
context texture0 active.
|
|
|
|
].
|
|
|
|
context vao enableAttribute: 0.
|
|
|
|
OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil .
|
|
|
|
context vbo data: GL_ARRAY_BUFFER data: vbuffer usage: GL_STATIC_DRAW.
|
2022-03-16 01:32:01 +01:00
|
|
|
OpenGL drawArrays: type first:0 count:((vbuffer size )>> 2 ).
|
2022-03-06 19:50:19 +01:00
|
|
|
"reset value"
|
|
|
|
self texture ifNotNil: [self texture drop.].
|
2022-03-23 00:52:15 +01:00
|
|
|
self border > 0 ifTrue: [ self drawBorder ].
|
2022-03-16 01:32:01 +01:00
|
|
|
context vao disableAttribute: 0.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
Diya2DPrimShape >> drawBorder [
|
|
|
|
"Diya2DShader uniqueInstance use."
|
2022-03-23 00:52:15 +01:00
|
|
|
shader setUniform: #u_color value: self borderColor asGL4FArray;
|
|
|
|
setUniform: #u_texture_type value: 0.
|
2022-03-16 01:32:01 +01:00
|
|
|
OpenGL
|
2022-03-23 00:52:15 +01:00
|
|
|
lineWidth: self border.
|
2022-03-16 01:32:01 +01:00
|
|
|
self drawLines.
|
|
|
|
OpenGL lineWidth: 1.0.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
Diya2DPrimShape >> drawLineAt: offset [
|
|
|
|
OpenGL drawArrays: GL_LINES first:(offset) count:2.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
Diya2DPrimShape >> drawLines [
|
|
|
|
self subclassResponsibility
|
2022-03-06 19:50:19 +01:00
|
|
|
]
|
|
|
|
|
2022-03-19 02:18:29 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> extent [
|
|
|
|
^ bbox extent
|
|
|
|
]
|
|
|
|
|
2022-03-06 18:33:10 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
Diya2DPrimShape >> initialize [
|
|
|
|
super initialize.
|
|
|
|
texture := nil.
|
2022-03-16 01:32:01 +01:00
|
|
|
children := nil.
|
|
|
|
type := GL_TRIANGLES.
|
2022-03-19 02:18:29 +01:00
|
|
|
bbox := Rectangle origin: 0@0 corner: 0@0.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'as yet unclassified' }
|
|
|
|
Diya2DPrimShape >> inner: aPoint [
|
|
|
|
bbox ifNil: [ ^false ].
|
|
|
|
^ bbox containsPoint: (self local: aPoint)
|
2022-03-06 18:33:10 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
Diya2DPrimShape >> setUpShader [
|
2022-03-19 02:18:29 +01:00
|
|
|
super setUpShader.
|
|
|
|
self shader
|
|
|
|
setUniform: #u_texture_type value:
|
|
|
|
(self texture ifNil: [ 0 ] ifNotNil:[self texture format]).
|
2022-03-06 18:33:10 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> texture [
|
|
|
|
^ texture
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> texture: anObject [
|
|
|
|
texture := anObject
|
|
|
|
]
|
2022-03-21 18:03:15 +01:00
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> textureNamed: name [
|
|
|
|
self texture: (context assets texture: name)
|
|
|
|
]
|