-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathperformance.script
64 lines (58 loc) · 1.86 KB
/
performance.script
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
function init(self)
msg.post(".", "acquire_input_focus")
msg.post("@system:", "toggle_profile")
msg.post("@render:", "clear_color", {color = vmath.vector4(1, 1, 1, 1)})
-- size of texture when scaled to nearest power of two
local width = 1024
local height = 2048
local channels = 4
-- we have to create table with next fields: buffer, width, height, channels
self.buffer_info = {
buffer = buffer.create(width * height, {{name = hash("rgba"), type = buffer.VALUE_TYPE_UINT8, count = channels}}),
width = width,
height = height,
channels = channels -- 3 for rgb, 4 for rgba
}
self.dirty = true
self.current_color = vmath.vector4(0, 0, 0, 1)
self.current_tool = "pencil"
-- drawing params
self.prev_pos = vmath.vector3()
self.resource_path = go.get("#sprite", "texture0")
self.header = {
width = width,
height = height,
type = resource.TEXTURE_TYPE_2D,
format = resource.TEXTURE_FORMAT_RGBA,
num_mip_maps = 1
}
end
local function mesure_time(self, times, fun, ...)
local time = os.clock()
for i=1, times do
fun(self, ...)
end
print("time:" .. os.clock() - time)
end
local function fill(self)
drawpixels.fill(self.buffer_info, 255,0,0,0)
end
local function circle(self)
drawpixels.filled_circle(self.buffer_info, 222,222,400,255,0,0,255)
end
local function rect(self)
drawpixels.filled_rect(self.buffer_info, 222,222,400,255,255,0,0,255)
end
function update(self, dt)
mesure_time(self, 1000, rect)
-- mesure_time(self, 100, fill)
resource.set_texture(self.resource_path, self.header, self.buffer_info.buffer)
end
function on_message(self, message_id, message, sender)
end
local function color_vector_to_bytes(color)
return color.x * 255, color.y * 255, color.z * 255, color.w * 255
end
local function bytes_to_color_vector(r, g, b, a)
return vmath.vector4(r / 255, g / 255, b / 255, a / 255)
end