@@ -9,11 +9,11 @@ local UniformBlock = require("arisu.gl.uniform_block")
99local TextureManager = require (" arisu.gl.texture_manager" )
1010local FontManager = require (" arisu.gl.font_manager" )
1111
12- local Device = require (" arisu-gfx.device.gl " )
12+ local Instance = require (" arisu-gfx.instance " )
1313
1414--- @class arisu.plugin.Render.Context
1515--- @field window winit.Window
16- --- @field renderCtx gfx.Context
16+ --- @field surface gfx.gl.Surface
1717--- @field quadVAO VAO
1818--- @field quadPipeline Pipeline
1919--- @field quadVertex gfx.Buffer
@@ -42,12 +42,17 @@ local Device = require("arisu-gfx.device.gl")
4242--- @field mainCtx arisu.plugin.Render.Context ?
4343--- @field contexts table<winit.Window , arisu.plugin.Render.Context>
4444--- @field sharedResources arisu.plugin.Render.SharedResources ?
45+ --- @field device gfx.Device
4546local RenderPlugin = {}
4647RenderPlugin .__index = RenderPlugin
4748
4849--- @param windowPlugin arisu.plugin.Window
4950function RenderPlugin .new (windowPlugin )
50- return setmetatable ({ contexts = {}, windowPlugin = windowPlugin }, RenderPlugin )
51+ local instance = Instance .new ()
52+ local adapter = instance :requestAdapter ({ powerPreference = " high-performance" })
53+ local device = adapter :requestDevice ()
54+
55+ return setmetatable ({ device = device , contexts = {}, windowPlugin = windowPlugin }, RenderPlugin )
5156end
5257
5358--- @param window winit.Window
@@ -65,26 +70,23 @@ function RenderPlugin:register(window)
6570 local ctx = self .windowPlugin :getContext (window )
6671 assert (ctx , " Window context not found for render plugin" )
6772
68- ctx .renderCtx :makeCurrent ()
69-
70- -- todo: dont make this here
71- local device = Device .new ()
73+ ctx .surface .context :makeCurrent ()
7274
7375 local vertexDescriptor = VertexLayout .new ()
7476 :withAttribute ({ type = " f32" , size = 3 , offset = 0 }) -- position (vec3)
7577 :withAttribute ({ type = " f32" , size = 4 , offset = 12 }) -- color (rgba)
7678 :withAttribute ({ type = " f32" , size = 2 , offset = 28 }) -- uv
7779 :withAttribute ({ type = " f32" , size = 1 , offset = 36 }) -- texture id
7880
79- local quadVertex = device :createBuffer ({ size = vertexDescriptor :getStride () * 1000 , usages = { " VERTEX" } })
80- local quadIndex = device :createBuffer ({ size = util .sizeof (" u16" ) * 1000 , usages = { " INDEX" } })
81+ local quadVertex = self . device :createBuffer ({ size = vertexDescriptor :getStride () * 1000 , usages = { " VERTEX" } })
82+ local quadIndex = self . device :createBuffer ({ size = util .sizeof (" u16" ) * 1000 , usages = { " INDEX" } })
8183
8284 local quadVAO = VAO .new ()
8385 quadVAO :setVertexBuffer (quadVertex , vertexDescriptor )
8486 quadVAO :setIndexBuffer (quadIndex )
8587
86- local overlayVertex = device :createBuffer ({ size = vertexDescriptor :getStride () * 1000 , usages = { " VERTEX" } })
87- local overlayIndex = device :createBuffer ({ size = util .sizeof (" u16" ) * 1000 , usages = { " INDEX" } })
88+ local overlayVertex = self . device :createBuffer ({ size = vertexDescriptor :getStride () * 1000 , usages = { " VERTEX" } })
89+ local overlayIndex = self . device :createBuffer ({ size = util .sizeof (" u16" ) * 1000 , usages = { " INDEX" } })
8890
8991 local overlayVertexDescriptor = VertexLayout .new ()
9092 :withAttribute ({ type = " f32" , size = 3 , offset = 0 }) -- position (vec3)
@@ -137,7 +139,7 @@ function RenderPlugin:register(window)
137139 --- @type arisu.plugin.Render.Context
138140 local ctx = {
139141 window = window ,
140- renderCtx = ctx .renderCtx ,
142+ surface = ctx .surface ,
141143 quadVAO = quadVAO ,
142144 quadPipeline = quadPipeline ,
143145 quadVertex = quadVertex ,
160162
161163--- @param ctx arisu.plugin.Render.Context
162164function RenderPlugin :draw (ctx )
163- ctx .renderCtx :makeCurrent ()
165+ ctx .surface . context :makeCurrent ()
164166
165167 gl .enable (gl .BLEND )
166168 gl .blendFunc (gl .SRC_ALPHA , gl .ONE_MINUS_SRC_ALPHA )
182184function RenderPlugin :event (event , handler )
183185 if event .name == " resize" then
184186 local ctx = self :getContext (event .window )
185- ctx .renderCtx :makeCurrent ()
187+ ctx .surface . context :makeCurrent ()
186188 gl .viewport (0 , 0 , ctx .window .width , ctx .window .height )
187189
188190 if util .isWindows () then
0 commit comments