1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2024-12-26 19:38:22 +01:00
Diya-API/Diya/Diya2DPrimShape.class.st

115 lines
2.5 KiB
Smalltalk
Raw Permalink Normal View History

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'
}
{ #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 [
^ self tf localBoundsToGlobal: bbox.
2022-03-19 02:18:29 +01:00
]
{ #category : #initialization }
Diya2DPrimShape >> draw [
vbuffer ifNil: [ ^self ].
OpenGL
enable: GL_CULL_FACE;
enable: GL_BLEND;
blendFnWithSfactor: GL_SRC_ALPHA dfactor: GL_ONE_MINUS_SRC_ALPHA.
"configure vao vbo for texture QUAD"
self texture ifNotNil: [
self texture setup.
context useTexture: self texture.
].
context submitData: vbuffer.
2022-03-16 01:32:01 +01:00
OpenGL drawArrays: type first:0 count:((vbuffer size )>> 2 ).
"reset value"
self texture ifNotNil: [self texture drop.].
self borderWidth > 0 ifTrue: [ self drawBorder ].
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;
setUniform: #u_texture_type value: 1.
2022-03-16 01:32:01 +01:00
OpenGL
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-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;
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
]
{ #category : #accessing }
Diya2DPrimShape >> textureNamed: name [
self texture: (context assets texture: name)
]