mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-26 03:18:22 +01:00
API improvement
- Refactor code - Texture performance improvement
This commit is contained in:
parent
6f5c6b8551
commit
9442050825
6
Diya/DiskStore.extension.st
Normal file
6
Diya/DiskStore.extension.st
Normal file
@ -0,0 +1,6 @@
|
||||
Extension { #name : #DiskStore }
|
||||
|
||||
{ #category : #'*Diya' }
|
||||
DiskStore class >> inform: string [
|
||||
Transcript show: string; cr.
|
||||
]
|
@ -34,7 +34,7 @@ DiyaApplicationLauncher >> defaultApplication [
|
||||
^DiyaExampleApp
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
{ #category : #accessing }
|
||||
DiyaApplicationLauncher >> delta: delta [
|
||||
|fps|
|
||||
delta = 0 ifTrue:[^self].
|
||||
|
@ -84,14 +84,12 @@ DiyaBoot >> init [
|
||||
status = 0
|
||||
ifFalse: [ ^ DiyaCoreAPIError signal: SDL2 getErrorMessage ].
|
||||
display := SDL_DisplayMode externalNew autoRelease.
|
||||
Smalltalk globals at: #Display ifAbsentPut:display.
|
||||
Smalltalk globals at: #DiyaDisplay put:display.
|
||||
SDL2 SDLGetCurrentDisplayMode: display from:0.
|
||||
SDL2 showCursor: 0.
|
||||
Smalltalk globals at: #Display ifAbsentPut:display.
|
||||
Smalltalk globals at: #DiyaDisplay put:display.
|
||||
DiyaSingleton resetAll.
|
||||
DiyaFontManager uniqueInstance loadFonts.
|
||||
|
||||
Form class removeSelector: #serviceImageAsBackground
|
||||
]
|
||||
|
||||
{ #category : #events }
|
||||
@ -191,6 +189,7 @@ DiyaBoot >> showSystemInfo [
|
||||
].
|
||||
stream cr.
|
||||
stream nextPutAll: DiyaDisplay asString; cr.
|
||||
stream cr.
|
||||
self stdout nextPutAll: stream contents
|
||||
|
||||
]
|
||||
@ -203,8 +202,10 @@ DiyaBoot >> startx [
|
||||
"SDL2 glMakeCurrent: window context: context."
|
||||
self showSystemInfo.
|
||||
DiyaRendererContext
|
||||
uniqueInstance display: display;
|
||||
useProjection: OrthoProjectionMatrix.
|
||||
uniqueInstance
|
||||
display: display;
|
||||
window: window;
|
||||
useProjection: OrthoProjectionMatrix.
|
||||
self render.
|
||||
context delete.
|
||||
window destroy.
|
||||
|
@ -39,14 +39,14 @@ DiyaButton >> label [
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaButton >> text: string [
|
||||
label txt: string.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaButton >> update [
|
||||
DiyaButton >> process [
|
||||
rec extent: self extent.
|
||||
label position: 0@0.
|
||||
label extent: self extent.
|
||||
^true
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaButton >> text: string [
|
||||
label txt: string.
|
||||
]
|
||||
|
@ -49,6 +49,21 @@ DiyaEllipse >> inner: aPoint [
|
||||
^ ((((dxy x) ** 2)/(rx**2)) + (((dxy y) ** 2) / (ry**2))) < 1.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaEllipse >> process [
|
||||
bbox := Rectangle origin: ((rx negated) @ (ry negated)) corner: (rx @ ry).
|
||||
{
|
||||
bbox origin x. bbox origin y. 0.0. 0.0.
|
||||
bbox origin x. bbox corner y. 0.0. 1.0.
|
||||
bbox corner x. bbox corner y. 1.0. 1.0.
|
||||
|
||||
bbox corner x. bbox corner y. 1.0. 1.0.
|
||||
bbox corner x. bbox origin y. 1.0. 0.0.
|
||||
bbox origin x. bbox origin y. 0.0. 0.0.
|
||||
} doWithIndex: [:e :i| vbuffer at: i put: e].
|
||||
^true
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaEllipse >> rx [
|
||||
^ rx
|
||||
@ -80,18 +95,3 @@ DiyaEllipse >> setUpShader [
|
||||
setUniform: #u_rx value: rx;
|
||||
setUniform: #u_ry value: ry.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaEllipse >> update [
|
||||
bbox := Rectangle origin: ((rx negated) @ (ry negated)) corner: (rx @ ry).
|
||||
{
|
||||
bbox origin x. bbox origin y. 0.0. 0.0.
|
||||
bbox origin x. bbox corner y. 0.0. 1.0.
|
||||
bbox corner x. bbox corner y. 1.0. 1.0.
|
||||
|
||||
bbox corner x. bbox corner y. 1.0. 1.0.
|
||||
bbox corner x. bbox origin y. 1.0. 0.0.
|
||||
bbox origin x. bbox origin y. 0.0. 0.0.
|
||||
} doWithIndex: [:e :i| vbuffer at: i put: e].
|
||||
^true
|
||||
]
|
||||
|
@ -130,5 +130,6 @@ DiyaExampleApp >> setup [
|
||||
button icon:16rF185"'mrsang.png'".
|
||||
"button rotation: Float pi / 2.0."
|
||||
button styleName: #button_view.
|
||||
Transcript show: 'Application setup';cr.
|
||||
^ root
|
||||
]
|
||||
|
@ -59,8 +59,8 @@ DiyaFontIcon >> lastSeparatorFrom: i [
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaFontIcon >> update [
|
||||
DiyaFontIcon >> process [
|
||||
data ifNil: [ ^self ].
|
||||
bbox := Rectangle origin: 0@0 corner: ((data size) * (self fontSize) ) @ self fontSize.
|
||||
^ super update.
|
||||
^ super process.
|
||||
]
|
||||
|
@ -20,9 +20,9 @@ DiyaImageIcon >> initialize [
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaImageIcon >> update [
|
||||
DiyaImageIcon >> process [
|
||||
|v|
|
||||
v := self iconSize.
|
||||
self extent: (v@v).
|
||||
^super update
|
||||
^super process
|
||||
]
|
||||
|
@ -36,32 +36,28 @@ DiyaImageTex >> drop [
|
||||
|
||||
{ #category : #capture }
|
||||
DiyaImageTex >> flipY [
|
||||
|buffer idx idxf|
|
||||
buffer := FFIExternalArray externalNewType: GLubyte size: width * height * 4.
|
||||
|buffer size linesize top bottom|
|
||||
size := self bytesSize.
|
||||
linesize := width << 2.
|
||||
buffer := FFIExternalArray externalNewType: GLubyte size: linesize.
|
||||
LibC memset: buffer getHandle value: 0 size: buffer size.
|
||||
buffer autoRelease.
|
||||
0 to: height - 1 do:[:y|
|
||||
0 to: width - 1 do:[:x|
|
||||
idx := ((y * width) + x)*4 + 1.
|
||||
idxf := ((height - y)*width + x)*4 + 1.
|
||||
buffer at: idx put: (data at: idxf).
|
||||
buffer at: idx+1 put: (data at: idxf+1).
|
||||
buffer at: idx+2 put: (data at: idxf+2).
|
||||
buffer at: idx+3 put: (data at: idxf+3).
|
||||
].
|
||||
0 to: (height >> 1) -1 do: [ :line|
|
||||
top := line * linesize.
|
||||
bottom := (size - (linesize * (line + 1))).
|
||||
LibC memCopy: (data getHandle) + top to: buffer getHandle size: linesize.
|
||||
LibC memCopy: (data getHandle) + bottom to: (data getHandle) + top size: linesize.
|
||||
LibC memCopy: buffer getHandle to: (data getHandle) + bottom size: linesize.
|
||||
].
|
||||
data free.
|
||||
data := buffer.
|
||||
|
||||
|
||||
buffer free
|
||||
]
|
||||
|
||||
{ #category : #capture }
|
||||
DiyaImageTex >> fromDisplay: aRect as: assetName [
|
||||
surface ifNotNil: [ surface free ] ifNil: [data ifNotNil: [data free]].
|
||||
surface := nil.
|
||||
Transcript show:'allocate ', ((aRect extent x) * (aRect extent y) * 4) asInteger asString,' bytes';cr.
|
||||
data := FFIExternalArray externalNewType: GLubyte size:((aRect extent x) * (aRect extent y) * 4) asInteger.
|
||||
width := aRect extent x asInteger.
|
||||
height := aRect extent y asInteger.
|
||||
data := FFIExternalArray externalNewType: GLubyte size: self bytesSize.
|
||||
LibC memset: data getHandle value: 0 size: data size.
|
||||
data autoRelease.
|
||||
OpenGL readPixelsOn: data getHandle
|
||||
@ -71,11 +67,8 @@ DiyaImageTex >> fromDisplay: aRect as: assetName [
|
||||
h: aRect extent y
|
||||
format:GL_RGBA
|
||||
type: GL_UNSIGNED_BYTE.
|
||||
width := aRect extent x.
|
||||
height := aRect extent y.
|
||||
name := assetName.
|
||||
self flipY.
|
||||
|
||||
]
|
||||
|
||||
{ #category : #capture }
|
||||
|
@ -52,18 +52,7 @@ DiyaLabel >> initialize [
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLabel >> txt [
|
||||
^ txt
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLabel >> txt: anObject [
|
||||
txt data: anObject.
|
||||
self setDirty
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLabel >> update [
|
||||
DiyaLabel >> process [
|
||||
|offset isize align|
|
||||
offset := 0.
|
||||
icon ifNotNil: [
|
||||
@ -73,7 +62,7 @@ DiyaLabel >> update [
|
||||
].
|
||||
txt extent: (extent x - offset) @ (extent y).
|
||||
"lookahead update"
|
||||
txt update.
|
||||
txt process.
|
||||
align := self getHAlign: offset.
|
||||
txt position: offset @ ( (self extent y - txt extent y ) >> 1).
|
||||
|
||||
@ -83,3 +72,14 @@ DiyaLabel >> update [
|
||||
^ true
|
||||
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLabel >> txt [
|
||||
^ txt
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLabel >> txt: anObject [
|
||||
txt data: anObject.
|
||||
self setDirty
|
||||
]
|
||||
|
@ -82,18 +82,7 @@ DiyaLine >> inner: aPoint [
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLine >> to [
|
||||
^ to
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLine >> to: anObject [
|
||||
to := anObject.
|
||||
self setDirty
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLine >> update [
|
||||
DiyaLine >> process [
|
||||
|extent|
|
||||
bbox := (Rectangle origin: from corner: to ).
|
||||
bbox origin = translation ifFalse:[self position: bbox origin].
|
||||
@ -108,3 +97,14 @@ DiyaLine >> update [
|
||||
} doWithIndex: [:e :i| vbuffer at: i put: e].
|
||||
^true
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLine >> to [
|
||||
^ to
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaLine >> to: anObject [
|
||||
to := anObject.
|
||||
self setDirty
|
||||
]
|
||||
|
@ -57,7 +57,21 @@ DiyaNode >> addNode: node at: pos [
|
||||
node position: pos.
|
||||
children add: node.
|
||||
node root: self root.
|
||||
^ node
|
||||
Transcript show:'Added node #', self id asString; cr.
|
||||
^ node
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> allChildren [
|
||||
|nodes|
|
||||
nodes := OrderedCollection new.
|
||||
children ifNil: [ ^ nodes ].
|
||||
children do:[:c|
|
||||
nodes add: c.
|
||||
c allChildren do:[:e| nodes add:e].
|
||||
].
|
||||
^nodes
|
||||
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
@ -148,6 +162,11 @@ DiyaNode >> position: anObject [
|
||||
self updateTF.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> process [
|
||||
^self subclassResponsibility
|
||||
]
|
||||
|
||||
{ #category : #convenience }
|
||||
DiyaNode >> register: aBlock to: eventName [
|
||||
|evtCode|
|
||||
@ -159,12 +178,13 @@ DiyaNode >> register: aBlock to: eventName [
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> render [
|
||||
self step.
|
||||
dirty ifTrue:[
|
||||
dirty := self update not].
|
||||
dirty := self process not].
|
||||
shader ifNotNil: [self setUpShader].
|
||||
self draw.
|
||||
children ifNil: [ ^self ].
|
||||
children do: [:c | c render ].
|
||||
children do: [:c | c render ].
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
@ -241,6 +261,10 @@ DiyaNode >> shader: anObject [
|
||||
shader := anObject
|
||||
]
|
||||
|
||||
{ #category : #stepping }
|
||||
DiyaNode >> step [
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> styleName [
|
||||
^ styleName
|
||||
@ -276,11 +300,6 @@ DiyaNode >> trigger: evt [
|
||||
].
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> update [
|
||||
^self subclassResponsibility
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> updateTF [
|
||||
self subclassResponsibility
|
||||
|
@ -40,6 +40,16 @@ DiyaPolygon >> points: anObject [
|
||||
self setDirty
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaPolygon >> process [
|
||||
bbox := self recFromPoints.
|
||||
translation = bbox origin ifFalse:[ self position: bbox origin].
|
||||
points := points collect:[:e | e - bbox origin].
|
||||
bbox := self recFromPoints.
|
||||
self calculateVertices.
|
||||
^true
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaPolygon >> recFromPoints [
|
||||
|maxX maxY minX minY x y|
|
||||
@ -55,13 +65,3 @@ DiyaPolygon >> recFromPoints [
|
||||
].
|
||||
^ Rectangle origin: minX@minY corner: maxX @ maxY
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaPolygon >> update [
|
||||
bbox := self recFromPoints.
|
||||
translation = bbox origin ifFalse:[ self position: bbox origin].
|
||||
points := points collect:[:e | e - bbox origin].
|
||||
bbox := self recFromPoints.
|
||||
self calculateVertices.
|
||||
^true
|
||||
]
|
||||
|
@ -37,7 +37,7 @@ DiyaRectangle >> initialize [
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRectangle >> update [
|
||||
DiyaRectangle >> process [
|
||||
|extent|
|
||||
extent := self extent.
|
||||
{
|
||||
|
@ -8,7 +8,8 @@ Class {
|
||||
'vao',
|
||||
'texture0',
|
||||
'projection',
|
||||
'assets'
|
||||
'assets',
|
||||
'window'
|
||||
],
|
||||
#pools : [
|
||||
'OpenGLConstants',
|
||||
@ -106,3 +107,13 @@ DiyaRendererContext >> vao [
|
||||
DiyaRendererContext >> vbo [
|
||||
^ vbo
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRendererContext >> window [
|
||||
^ window
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaRendererContext >> window: anObject [
|
||||
window := anObject
|
||||
]
|
||||
|
@ -43,7 +43,7 @@ DiyaRootNode >> isRoot [
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaRootNode >> update [
|
||||
DiyaRootNode >> process [
|
||||
^true
|
||||
]
|
||||
|
||||
|
@ -200,6 +200,18 @@ DiyaText >> maxLineWidth [
|
||||
^ maxLineWidth
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaText >> process [
|
||||
bbox ifNil: [ ^true ].
|
||||
data ifNil:[^true].
|
||||
data ifEmpty:[^true].
|
||||
vbuffer ifNotNil: [vbuffer free].
|
||||
vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16.
|
||||
vbuffer autoRelease.
|
||||
self drawText.
|
||||
^true
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> splitLines [
|
||||
|line ret tex2D|
|
||||
@ -219,24 +231,12 @@ DiyaText >> texture [
|
||||
texture ifNil: [ self initTexture ].
|
||||
texheight = texture height ifFalse: [
|
||||
texheight := texture height.
|
||||
self update.
|
||||
self process.
|
||||
self setClean.
|
||||
].
|
||||
^texture
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaText >> update [
|
||||
bbox ifNil: [ ^true ].
|
||||
data ifNil:[^true].
|
||||
data ifEmpty:[^true].
|
||||
vbuffer ifNotNil: [vbuffer free].
|
||||
vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16.
|
||||
vbuffer autoRelease.
|
||||
self drawText.
|
||||
^true
|
||||
]
|
||||
|
||||
{ #category : #'menu messages' }
|
||||
DiyaText >> valign [
|
||||
^ self ? #yAlign
|
||||
|
@ -29,6 +29,11 @@ OpenGLTexImage2D >> border: anObject [
|
||||
border := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLTexImage2D >> bytesSize [
|
||||
^(width * height) << 2
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
OpenGLTexImage2D >> data [
|
||||
^ data
|
||||
|
@ -6,6 +6,11 @@ SDL2 class >> SDLAllocFormat: pixel_format [
|
||||
|
||||
]
|
||||
|
||||
{ #category : #'*Diya' }
|
||||
SDL2 class >> SDLBlitSurface: src srcRect: srcrect dest: dst dstRect: dstrect [
|
||||
^ self ffiCall: #(int SDL_UpperBlit(SDL_Surface* src,SDL_Rect* srcrect,SDL_Surface* dst,SDL_Rect* dstrect))
|
||||
]
|
||||
|
||||
{ #category : #'*Diya' }
|
||||
SDL2 class >> SDLClearError [
|
||||
^ self ffiCall: #(void SDL_ClearError(void))
|
||||
|
Loading…
Reference in New Issue
Block a user