Skip to content

Commit 73c1e42

Browse files
committed
refactor(app): move gl calls to utils functions
1 parent 63a1762 commit 73c1e42

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

src/app/webview/gl.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,21 @@ pub fn update_texture(
179179
BindTexture(TEXTURE_2D, 0);
180180
}
181181
}
182+
183+
pub fn resize_viewport(width: i32, height: i32) {
184+
unsafe {
185+
epoxy::Viewport(0, 0, width, height);
186+
}
187+
}
188+
189+
pub fn draw_texture(program: GLuint, texture: GLuint, texture_uniform: GLint, vao: GLuint) {
190+
unsafe {
191+
epoxy::UseProgram(program);
192+
epoxy::ActiveTexture(epoxy::TEXTURE0);
193+
epoxy::BindTexture(epoxy::TEXTURE_2D, texture);
194+
epoxy::Uniform1i(texture_uniform, 0);
195+
196+
epoxy::BindVertexArray(vao);
197+
epoxy::DrawArrays(epoxy::TRIANGLE_STRIP, 0, 4);
198+
}
199+
}

src/app/webview/imp.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,17 @@ impl GLAreaImpl for WebView {
121121
&frame.buffer,
122122
);
123123

124-
unsafe {
125-
epoxy::Viewport(
126-
0,
127-
0,
128-
frame.full_width * scale_factor,
129-
frame.full_height * scale_factor,
130-
);
131-
132-
epoxy::UseProgram(self.program.get());
133-
epoxy::ActiveTexture(epoxy::TEXTURE0);
134-
epoxy::BindTexture(epoxy::TEXTURE_2D, self.texture.get());
135-
epoxy::Uniform1i(self.texture_uniform.get(), 0);
136-
137-
epoxy::BindVertexArray(self.vao.get());
138-
epoxy::DrawArrays(epoxy::TRIANGLE_STRIP, 0, 4);
139-
}
124+
gl::resize_viewport(
125+
frame.full_width * scale_factor,
126+
frame.full_height * scale_factor,
127+
);
128+
129+
gl::draw_texture(
130+
self.program.get(),
131+
self.texture.get(),
132+
self.texture_uniform.get(),
133+
self.vao.get(),
134+
);
140135
} else {
141136
break;
142137
}

0 commit comments

Comments
 (0)