-
Notifications
You must be signed in to change notification settings - Fork 1
/
coreRender.go
68 lines (53 loc) · 2.25 KB
/
coreRender.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package frenyard
// DrawMode represents some form of drawing mode for the primitive. (Documentation for these should include a GLSLish equal for those versed in graphics, ideally translated from the SDL2 documentation.)
type DrawMode uint8
// Do be aware that DrawModeNormal is the zero value. This is "off" from SDL2 order but is done on purpose as this is the default that most people will want.
// DrawModeNormal is a normal blended draw mode; typically "what you want". `vec4(mix(dst.rgb, src.rgb, src.a), src.a + (dstA * (1 - src.a)))`
const DrawModeNormal = 0
// DrawModeNoBlending disables blending. `src`
const DrawModeNoBlending = 1
// DrawModeAdd is an "additive" blend mode. `vec4(dst.rgb + src.rgb, dst.a)`
const DrawModeAdd = 2
// DrawModeModulate is a "modulate" blend mode. `vec4(dst.rgb * src.rgb, dst.a)`
const DrawModeModulate = 3
// DrawRectCommand represents a rectangle-based drawing command.
type DrawRectCommand struct {
// Where to draw
Target Area2i
// Texture
Tex Texture
// Area within texture to get pixels from.
TexSprite Area2i
// Colour [modulation if Texture is given]
Colour uint32
// Blending Mode/etc.
Mode DrawMode
}
// Renderer is an abstract rendering interface.
type Renderer interface {
/* Draw */
// Draws a DrawRectCommand.
DrawRect(DrawRectCommand)
/* Control */
// Translates the renderer's target. Use with defer to undo later.
Translate(vec Vec2i)
// Returns the renderer's translation.
Translation() Vec2i
// Sets the clip area, relative to the current translation.
SetClip(clip Area2i)
// Gets the clip area, relative to the current translation.
Clip() Area2i
/* Outer Control */
// Gets the size of the drawing area.
Size() Vec2i
// Clears & resets clip/translate/etc. You should do this at the start of frame.
Reset(colour uint32)
// Calls drawer() while rendering to a texture. All other operations occur within this texture for that duration. Can be stacked; the latest RenderToTexture applies.
// 'reserved' does nothing but must be left false.
// The resulting texture from this renderer may only be used on this renderer.
RenderToTexture(size Vec2i, drawer func(), reserved bool) Texture
}
// Texture interface. This is automatically deleted on finalization.
type Texture interface {
Size() Vec2i
}