gl_utils: Handle frames that are in PBO already

This commit is contained in:
Martin Piatka
2024-01-30 15:33:29 +01:00
parent 0d465428fe
commit aa74306ba2
3 changed files with 58 additions and 25 deletions

View File

@@ -134,7 +134,7 @@ public:
virtual ~Rendering_convertor() { };
void attach_texture(const Texture& tex) override final {
void attach_texture(Texture& tex) override final {
fbuf.attach_texture(tex);
}
@@ -168,12 +168,12 @@ protected:
class Loading_convertor : public Frame_convertor{
public:
void attach_texture(const Texture& tex) override final{
void attach_texture(Texture& tex) override final{
this->tex = &tex;
}
protected:
const Texture *tex = nullptr;
Texture *tex = nullptr;
};
class Yuv_convertor : public Rendering_convertor{
@@ -184,9 +184,12 @@ public:
private:
void prepare_input_tex(video_frame *f, bool pbo_frame) override final{
input_tex.allocate((f->tiles[0].width + 1) / 2, f->tiles[0].height, GL_RGBA);
glBindTexture(GL_TEXTURE_2D, input_tex.get());
input_tex.upload_frame(f, pbo_frame);
int w = (f->tiles[0].width + 1) / 2;
int h = f->tiles[0].height;
input_tex.load_frame(w, h, GL_RGBA,
GL_RGBA, GL_UNSIGNED_BYTE,
f, pbo_frame);
}
};
@@ -310,16 +313,11 @@ public:
private:
void prepare_input_tex(video_frame *f, bool pbo_frame = false) override final{
//TODO
int w = vc_get_linesize(f->tiles[0].width, v210) / 4;
int h = f->tiles[0].height;
input_tex.allocate(w, h, GL_RGB10_A2);
glBindTexture(GL_TEXTURE_2D, input_tex.get());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2,
w, h, 0,
input_tex.load_frame(w, h, GL_RGB10_A2,
GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV,
f->tiles[0].data);
f, pbo_frame);
}
};
@@ -358,16 +356,11 @@ public:
private:
void prepare_input_tex(video_frame *f, bool pbo_frame = false) override final{
//TODO
int w = f->tiles[0].width;
int h = f->tiles[0].height;
input_tex.allocate(w, h, GL_RGBA);
glBindTexture(GL_TEXTURE_2D, input_tex.get());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
w, h, 0,
input_tex.load_frame(w, h, GL_RGBA,
GL_RGBA, GL_UNSIGNED_SHORT,
f->tiles[0].data);
f, pbo_frame);
}
};
@@ -513,8 +506,9 @@ public:
void put_frame(video_frame *f, bool pbo_frame = false) override{
int w = f->tiles[0].width;
int h = f->tiles[0].height;
glBindTexture(GL_TEXTURE_2D, tex->get());
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, f->tiles[0].data);
tex->load_frame(w, h, GL_RGB,
GL_RGB, GL_UNSIGNED_BYTE,
f, pbo_frame);
}
};
@@ -523,8 +517,9 @@ public:
void put_frame(video_frame *f, bool pbo_frame = false) override{
int w = f->tiles[0].width;
int h = f->tiles[0].height;
glBindTexture(GL_TEXTURE_2D, tex->get());
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, f->tiles[0].data);
tex->load_frame(w, h, GL_RGBA,
GL_RGBA, GL_UNSIGNED_BYTE,
f, pbo_frame);
}
};

View File

@@ -366,6 +366,36 @@ void Texture::upload_frame(video_frame *f, bool pbo_frame){
}
}
void Texture::load_frame(int w, int h,
GLint internal_format,
GLenum src_format,
GLenum type,
video_frame *f,
bool pbo_frame)
{
char *src_data = f->tiles[0].data;
allocate(w, h, internal_format);
glBindTexture(GL_TEXTURE_2D, tex_id);
if(pbo_frame){
GlBuffer *pbo = static_cast<GlBuffer *>(f->callbacks.dispose_udata);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo->get());
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
f->tiles[0].data = nullptr;
src_data = nullptr;
}
glTexImage2D(GL_TEXTURE_2D, 0, internal_format,
w, h, 0,
src_format, type,
src_data);
if(pbo_frame){
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
}
void Texture::allocate(){
if(tex_id != 0)
return;
@@ -464,6 +494,7 @@ void main(){
quad = Model::get_quad();
texture.allocate();
uploader.attach_dst_texture(&texture);
uploader.enable_pbo(false);
}
void FlatVideoScene::put_frame(video_frame *f){

View File

@@ -179,6 +179,13 @@ public:
*/
void upload_frame(video_frame *f, bool pbo_frame);
void load_frame(int w, int h,
GLint internal_format,
GLenum src_format,
GLenum type,
video_frame *f,
bool pbo_frame);
Texture(const Texture&) = delete;
Texture(Texture&& o) { swap(o); }
Texture& operator=(const Texture&) = delete;
@@ -346,7 +353,7 @@ public:
*
* @param tex texture to attach
*/
virtual void attach_texture(const Texture& tex) = 0;
virtual void attach_texture(Texture& tex) = 0;
void set_pbo(GlBuffer *pbo) { internal_pbo = pbo; }
protected: