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-08-06 03:11:36 +02:00
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> borderWidth [
|
2022-08-07 20:43:16 +02:00
|
|
|
^ self ? #border
|
2022-03-16 01:32:01 +01:00
|
|
|
]
|
|
|
|
|
2022-03-19 02:18:29 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
Diya2DPrimShape >> boundingBox [
|
2022-08-13 01:37:42 +02:00
|
|
|
^ self tf localBoundsToGlobal: bbox.
|
2022-03-19 02:18:29 +01:00
|
|
|
]
|
|
|
|
|
2022-03-06 19:50:19 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
Diya2DPrimShape >> draw [
|
|
|
|
vbuffer ifNil: [ ^self ].
|
2022-08-08 00:12:54 +02:00
|
|
|
OpenGL
|
|
|
|
enable: GL_CULL_FACE;
|
|
|
|
enable: GL_BLEND;
|
|
|
|
blendFnWithSfactor: GL_SRC_ALPHA dfactor: GL_ONE_MINUS_SRC_ALPHA.
|
2022-03-06 19:50:19 +01:00
|
|
|
"configure vao vbo for texture QUAD"
|
|
|
|
self texture ifNotNil: [
|
|
|
|
self texture setup.
|
2022-08-14 15:42:59 +02:00
|
|
|
context useTexture: self texture.
|
2022-03-06 19:50:19 +01:00
|
|
|
].
|
2022-08-14 15:42:59 +02:00
|
|
|
context submitData: vbuffer.
|
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-08-06 03:11:36 +02:00
|
|
|
self borderWidth > 0 ifTrue: [ self drawBorder ].
|
2022-08-08 00:12:54 +02:00
|
|
|
OpenGL
|
|
|
|
disable: GL_CULL_FACE;
|
|
|
|
disable: GL_BLEND.
|
2022-03-16 01:32:01 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
Diya2DPrimShape >> drawBorder [
|
|
|
|
"Diya2DShader uniqueInstance use."
|
2022-08-07 20:43:16 +02:00
|
|
|
shader setUniform: #u_color value: (self ? #borderColor) asGL4FArray;
|
2022-08-06 03:11:36 +02:00
|
|
|
setUniform: #u_texture_type value: 1.
|
2022-03-16 01:32:01 +01:00
|
|
|
OpenGL
|
2022-08-06 03:11:36 +02:00
|
|
|
lineWidth: self borderWidth.
|
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
|
|
|
type := GL_TRIANGLES.
|
2022-03-19 02:18:29 +01:00
|
|
|
bbox := Rectangle origin: 0@0 corner: 0@0.
|
|
|
|
]
|
|
|
|
|
2022-08-07 20:43:16 +02:00
|
|
|
{ #category : #accessing }
|
2022-03-19 02:18:29 +01:00
|
|
|
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
|
2022-08-07 20:43:16 +02:00
|
|
|
setUniform: #u_color value: (self ? #color) asGL4FArray;
|
2022-08-14 15:42:59 +02:00
|
|
|
setUniform: #u_bg_color value: (self ? #bgColor) asGL4FArray.
|
|
|
|
self texture ifNotNil: [
|
|
|
|
self shader
|
|
|
|
setUniform: #u_texture value: self texture unit;
|
|
|
|
setUniform: #u_texture_type value: self texture format.
|
|
|
|
]
|
|
|
|
ifNil:
|
|
|
|
[
|
|
|
|
self shader setUniform: #u_texture_type value: 0.
|
|
|
|
].
|
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)
|
|
|
|
]
|