Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(opengl) #989 #999 Fix transform, rotate and distort #1002

Merged
merged 1 commit into from May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/accelerator/ogl/image/image_kernel.cpp
Expand Up @@ -378,11 +378,13 @@ struct image_kernel::impl

// Draw
switch (params.geometry.type()) {
case core::frame_geometry::geometry_type::triangles: {
case core::frame_geometry::geometry_type::quad: {
GL(glBindVertexArray(vao_));
GL(glBindBuffer(GL_ARRAY_BUFFER, vbo_));

GL(glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizei>(sizeof(core::frame_geometry::coord)) * coords.size(), coords.data(), GL_STATIC_DRAW));
std::vector<core::frame_geometry::coord> coords_triangles { coords[0], coords[1], coords[2], coords[0], coords[2], coords[3] };

GL(glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizei>(sizeof(core::frame_geometry::coord)) * coords_triangles.size(), coords_triangles.data(), GL_STATIC_DRAW));

auto stride = static_cast<GLsizei>(sizeof(core::frame_geometry::coord));

Expand All @@ -393,9 +395,9 @@ struct image_kernel::impl
GL(glEnableVertexAttribArray(tex_loc));

GL(glVertexAttribPointer(vtx_loc, 2, GL_DOUBLE, GL_FALSE, stride, nullptr));
GL(glVertexAttribPointer(tex_loc, 4, GL_DOUBLE, GL_FALSE, stride, nullptr));
GL(glVertexAttribPointer(tex_loc, 4, GL_DOUBLE, GL_FALSE, stride, (GLvoid*)(2 * sizeof(GLdouble))));

for (int i = 0; i < coords.size(); i += 3) {
for (int i = 0; i < coords_triangles.size(); i += 3) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quads or triangles?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frame_geometry is back to defining quads, as it makes the transform maths simpler as that is what it is already expecting.
but opengl doesnt support drawing quads anymore, so I am converting the quads to triangles after any transforms are calculated

GL(glDrawArrays(GL_TRIANGLES, i, 3));
GL(glTextureBarrier());
}
Expand Down
30 changes: 15 additions & 15 deletions src/accelerator/ogl/image/image_shader.cpp
Expand Up @@ -272,39 +272,39 @@ std::string get_fragment()
switch(pixel_format)
{
case 0: //gray
return vec4(get_sample(plane[0], TexCoord.st).rrr, 1.0);
return vec4(get_sample(plane[0], TexCoord.st / TexCoord.q).rrr, 1.0);
case 1: //bgra,
return get_sample(plane[0], TexCoord.st).bgra;
return get_sample(plane[0], TexCoord.st / TexCoord.q).bgra;
case 2: //rgba,
return get_sample(plane[0], TexCoord.st).rgba;
return get_sample(plane[0], TexCoord.st / TexCoord.q).rgba;
case 3: //argb,
return get_sample(plane[0], TexCoord.st).argb;
return get_sample(plane[0], TexCoord.st / TexCoord.q).argb;
case 4: //abgr,
return get_sample(plane[0], TexCoord.st).gbar;
return get_sample(plane[0], TexCoord.st / TexCoord.q).gbar;
case 5: //ycbcr,
{
float y = get_sample(plane[0], TexCoord.st).r;
float cb = get_sample(plane[1], TexCoord.st).r;
float cr = get_sample(plane[2], TexCoord.st).r;
float y = get_sample(plane[0], TexCoord.st / TexCoord.q).r;
float cb = get_sample(plane[1], TexCoord.st / TexCoord.q).r;
float cr = get_sample(plane[2], TexCoord.st / TexCoord.q).r;
return ycbcra_to_rgba(y, cb, cr, 1.0);
}
case 6: //ycbcra
{
float y = get_sample(plane[0], TexCoord.st).r;
float cb = get_sample(plane[1], TexCoord.st).r;
float cr = get_sample(plane[2], TexCoord.st).r;
float a = get_sample(plane[3], TexCoord.st).r;
float y = get_sample(plane[0], TexCoord.st / TexCoord.q).r;
float cb = get_sample(plane[1], TexCoord.st / TexCoord.q).r;
float cr = get_sample(plane[2], TexCoord.st / TexCoord.q).r;
float a = get_sample(plane[3], TexCoord.st / TexCoord.q).r;
return ycbcra_to_rgba(y, cb, cr, a);
}
case 7: //luma
{
vec3 y3 = get_sample(plane[0], TexCoord.st).rrr;
vec3 y3 = get_sample(plane[0], TexCoord.st / TexCoord.q).rrr;
return vec4((y3-0.065)/0.859, 1.0);
}
case 8: //bgr,
return vec4(get_sample(plane[0], TexCoord.st).bgr, 1.0);
return vec4(get_sample(plane[0], TexCoord.st / TexCoord.q).bgr, 1.0);
case 9: //rgb,
return vec4(get_sample(plane[0], TexCoord.st).rgb, 1.0);
return vec4(get_sample(plane[0], TexCoord.st / TexCoord.q).rgb, 1.0);
}
return vec4(0.0, 0.0, 0.0, 0.0);
}
Expand Down
11 changes: 3 additions & 8 deletions src/core/frame/geometry.cpp
Expand Up @@ -43,11 +43,8 @@ struct frame_geometry::impl
impl(frame_geometry::geometry_type type, std::vector<coord> data)
: type_(type)
{
if (type == geometry_type::triangles) {
if (data.size() % 3 != 0)
CASPAR_THROW_EXCEPTION(invalid_argument()
<< msg_info("The number of coordinates needs to be a multiple of 3"));
}
if (type == geometry_type::quad && data.size() != 4)
CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("The number of coordinates needs to be 4"));

data_ = std::move(data);
}
Expand All @@ -71,11 +68,9 @@ const frame_geometry& frame_geometry::get_default()
{0.0, 0.0, 0.0, 0.0}, // upper left
{1.0, 0.0, 1.0, 0.0}, // upper right
{1.0, 1.0, 1.0, 1.0}, // lower right
{0.0, 0.0, 0.0, 0.0}, // upper left
{1.0, 1.0, 1.0, 1.0}, // lower right
{0.0, 1.0, 0.0, 1.0} // lower left
};
static const frame_geometry g(frame_geometry::geometry_type::triangles, data);
static const frame_geometry g(frame_geometry::geometry_type::quad, data);

return g;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/frame/geometry.h
Expand Up @@ -32,7 +32,7 @@ class frame_geometry
public:
enum class geometry_type
{
triangles
quad
};

struct coord
Expand Down Expand Up @@ -62,4 +62,4 @@ class frame_geometry
spl::shared_ptr<impl> impl_;
};

}} // namespace caspar::core
}} // namespace caspar::core