Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why didn't they ever implemented a rectangle primitive to be drawn instead of a triangle ? Anyway, here the perf impact is negligible


Triangles in 3D euclidean space have the advantage of being uniquely defined by 3 vertices that have the nice property of always sitting on a single plane. There's no linear transformation you could apply that results in something other than a well-defined, planar triangle. The worst that might happen is collapsing it into a line or a point.

The same cannot be said for quads. If you e.g. have 4 vertices where 3 are sitting on the same plane, but the 4th isn't, there are 2 different, possible ways to subdivide this into triangles. In addition to all the possible non-linear surfaces one might image occupying that space.

Old OpenGL and Direct3D versions did have quad and arbitrary polygon rendering support. IIRC from vague memory, the above scenario was something you were supposed to avoid and results varied between graphics card vendors.

On a side note: If we are talking purely 2D, some old 2D software rendering systems used trapezoids as basic primitives, defined by their top and bottom edges. For instance, the X11 XRender API explicitly supports drawing trapezoids. They are easy to rasterize, interpolate across and quite flexible. Many other 2D shapes can be conveniently composed from them, including screen space triangles, if you were to implement a software rasterizer.


The OpenGL specification basically had no explanation of what a "Quad" was, it didn't say anything about how to render quads, interpolate quads, etc. Pretty much every driver implemented quads as a funky way of spelling "two triangles". Much like tristrips/trifans/etc., index buffers give you all of the benefits with none of the drawbacks.

> For instance, the X11 XRender API explicitly supports drawing trapezoids.

It should be said XRender trapezoids have extra constraints: the top and bottom edges of the trapezoid must be completely straight (go exactly left to right). So it's basically a rectangle with sloped left/right sides. This makes it extremely easily to software rasterize, while you can still break each trapezoid into two triangles for 3D hardware.


> It should be said XRender trapezoids have extra constraints: the top and bottom edges of the trapezoid must be completely straight (go exactly left to right). So it's basically a rectangle with sloped left/right sides.

Isn't that just the definition of a trapezoid? Do you mean the top and bottom have to be parallel with the x axis or something?


Of course you're right but I was thinking about a subset of features for quads for this kind of use case. But yeah for all features triangles are better !


> Old OpenGL and Direct3D versions did have quad and arbitrary polygon rendering support.

I vaguely recall that at different times people tried to build both PC and phone graphics hardware around quads and basically failed, but I don’t know why that didn’t work (aside from the issues of geometry that you mention).


Sega Saturn being a notable example.


Importantly, the sega saturn kind of wasn't a true 3D engine that had quads as it's primitive, but rather a stamp/sprite based system that allowed to you skew, warp, and transform those rectangular images in very powerful ways, mostly being able to reproduce 3D scenes but with certain caveats about the "polygons" that caused some limitations. One good example was that the system has no concept of UV maps. Each polygon is exactly the whole texture, linearly warped. This means you can't do, for example, environment mapping natively

https://www.youtube.com/watch?v=WDJgeuoaSvQ


And Nvidia's first chip the NV1


A triangle is the simpleste polygon. As soon as you start doing quads the complexity skyrockets: what if it self intersects? What if it's concave? What does a winding order mean when the verts can be all out of order?


Triangles are used to render 3d meshes because of that yes. However, the article is about "Full screen post processing effects", which is easier done in a rectangle


Post processing is often used to generate textures for deferred rendering.


NVIDIA has an OpenGL extension that does just that [1].

[1] https://registry.khronos.org/OpenGL/extensions/NV/NV_fill_re...


Do you mean a bounding rectangle? That exists on a lot of GPUs, where you draw a triangle and the entire bounding box surrounding the triangle is covered. However, the details differ greatly between different GPUs, meaning it's hard to standardize. Full-screen triangles are just fine.


Nvidia's NV1 used quads as primitive. Shortly after its release, in 1995, Microsoft introduced DirectX which was triangle based. It didn't do well...


Every three points forms a triangle where all points are on a single plane.

This makes interpolation for normals, texture, etc trivial.

This is not true for every 4 points.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: