Commit Graph

74 Commits (7f9117b2bf0636a594eb1f1ba76b9dbe0e8a4e83)

Author SHA1 Message Date
Ryan Pavlik a0e992374d Clean up virtual, override, default, and void params. NFC.
Found by clang-tidy.
2019-09-11 10:31:07 +00:00
Ryan Pavlik b8ee0e941b Remove extraneous semicolon. NFC. 2019-09-10 06:44:34 +00:00
Ryan Pavlik 78819ffca3 Fix "virtual function without virtual destructor" warning. NFC. 2019-09-10 06:44:34 +00:00
Ryan Pavlik c959af1149 Fix a comment. NFC.
Found by clang-tidy.
2019-09-10 06:44:34 +00:00
Ryan Pavlik c0904e2ba8 Use IsEmpty() or .empty() to check if a container is empty. NFC.
Most found by clang-tidy.
2019-09-10 04:22:21 +00:00
Ryan A. Pavlik a4c0022815 Fix a warning about a virtual destructor. 2019-09-10 03:33:05 +00:00
Ryan Pavlik 0bfbbe2bf3 Improve implementation hiding in IdList/List. NFC.
Allows distancing users from the internal "elem" member.

Add Get() and operator[].
Replace direct references to elem.
Make elem and elemsAllocated private in IdList/List.
2019-08-20 15:57:11 +00:00
Ryan Pavlik 5ada4dbd9c Add and use IdList::IsEmpty. NFC.
Removes consuming code from the implementation details, easing swap of
the underlying container, etc.
2019-08-20 15:57:11 +00:00
Ryan Pavlik 5efb09e6d4 Use the new equality/inequality operators of handles to reduce references to .v. NFC. 2019-07-10 15:40:21 +00:00
Ryan Pavlik 7bd4b149f7 Traits work for handles to permit sharing functionality and operators. NFC. 2019-07-10 15:40:21 +00:00
whitequark 43a59e212f Work around MSVC bug 746973.
MSVC has a long history of value initialization bugs, and this one is
no exception. In this case, when some MSVC versions (at least up to
2013) are instructed to value-initialize a non-POD class with
a compiler generated non-trivial constructor, it does not zero out
the POD members.
2019-05-23 20:50:04 +00:00
whitequark e9b9dca2ca Win32: use native OpenGL drivers, if available.
After this commit, if the target system does have modern OpenGL
drivers installed, ANGLE is configured to use them, bypassing most
translation (shaders still have to be translated from ESSL to GLSL).

If there are no OpenGL drivers, such as if the graphics drivers were
installed via Windows Update, DirectX translation is still used. This
results in a very noticeable startup delay and minor performance
degradation.

In addition it is no longer necessary to build with -DOPENGL=1 to be
able to run the binary in wine; everything works out of the box.
Before, wine's incomplete HLSL translator would crash.

This change required renaming the variable `texture` in shaders,
since it shadows the Core GLSL function with the same name, and ANGLE
translates texture2D() calls to texture() calls.
2019-05-23 10:58:31 +00:00
whitequark 75a09c8b67 Minor cleanups. NFC.
A few code style changes extracted from the Emscripten port.
2019-05-21 00:48:20 +00:00
whitequark f43954cc29 Adjust GL1 and GL3 ReadFrame to take pixel ratio into account.
Currently, on HiDPI screens the Export Image command would return
a cropped screenshot.
2019-05-20 19:09:40 +00:00
whitequark 11c5cdc7b0 Adjust GL3 ReadFrame() for GL ES 2.1 compatibility.
Currently on Win32 this errors out and renders a black rectangle.
2019-05-20 19:09:40 +00:00
whitequark a7b2f28999 Silence some gcc 7 warnings.
* Mark switch fallthrough
    (-Wfallthrough);
  * Initialize variables to avoid false positives
    (-Wmaybe-uninitialized);
  * Fudge indentation to avoid false positives
    (-Wmisleading-indentation).
2019-03-28 09:46:16 +00:00
whitequark e383b7fba8 Remove superfluous glPolygonOffset() call in GL3 renderer.
This caused red fringes on mesh boundary with back faces turned on.
2019-02-04 20:41:50 +00:00
whitequark 28fa348859 Use correct polygon winding order in GL3 renderer. 2019-02-04 20:25:45 +00:00
whitequark 80c111bf75 Finish OpenGL 2 to OpenGL 3 renaming started in ecb6550b. 2018-07-31 21:01:28 +00:00
whitequark fb138f496a Add final qualifiers where applicable.
We have a lot of classes with virtual functions but no virtual
destructor, mostly under render/. While this is not a problem
due to how our hierarchy is structured, some versions of clang
warn about this on the delete statement inside shared_ptr.

We could add a virtual destructor, but adding final qualifiers
expresses intent better, is generally more efficient (since it allows
devirtualizing most virtual calls in render/), and solves
the potential problem clang is warning us about.
2018-07-19 00:11:04 +00:00
whitequark 738ac02cbf Fix some strict GL ES 2 conformance issues.
This commit fixes two issues that cause issues in WebGL:
  * Non-power-of-two textures must wrap as GL_CLAMP_TO_EDGE.
    This breaks non-power-of-two textures.
  * Render calls with zero primitives should not be issued.
    This just causes warning spam.
2018-07-18 19:40:14 +00:00
whitequark f324477dd0 Implement a platform abstraction for windows.
This commit removes a large amount of code partially duplicated
between the text and the graphics windows, and opens the path to
having more than one model window on screen at any given time,
as well as simplifies platform work.

This commit also adds complete support for High-DPI device pixel
ratio. It adds support for font scale factor (a fractional factor
on top of integral device pixel ratio) on the platform side, but not
on the application side.

This commit also adds error checking to all Windows API calls
(within the abstracted code) and fixes a significant number of
misuses and non-future-proof uses of Windows API.

This commit also makes uses of Windows API idiomatic, e.g. using
the built-in vertical scroll bar, native tooltips, control
subclassing instead of hooks in the global dispatch loop, and so on.

It reinstates tooltip support and removes menu-related hacks.
2018-07-17 13:31:17 +00:00
whitequark 7ab87caa88 Implement a platform abstraction for timers.
This commit temporarily disables tooltip functionality; it will
be handled natively in a platform abstraction for windows using
much simpler code.
2018-07-16 11:21:30 +00:00
whitequark 28f94dcd0a Start using C++ in-place member initialization.
We should make good use of in-place member initialization. Many
new classes have constructors that effectively do nothing but
default-initialize POD members, and when adding new members,
it is very easy to miss initializing them. With in-place
initialization, the code is more compact, the diffs are nicer,
and it's harder to miss them.

This commit only converts render/ and platform/ to use in-place
member initialization, since there was a bug in CairoRenderer,
but we should convert the entire codebase.
2018-07-16 11:21:30 +00:00
whitequark c8fc033047 macOS: fix #include to work on case-sensitive filesystem. 2018-07-12 11:45:15 +00:00
whitequark 9c99f69da5 Clean up unused shader variables. 2018-07-12 11:43:25 +00:00
whitequark 20a4a2b23f Avoid using `tan` as identifier in shaders.
This conflicts with the tan() function, currently only on macOS.
2018-07-12 11:40:51 +00:00
luzpaz 771b415a12 Fix various comment and UI string typos. 2018-07-12 05:05:43 +00:00
whitequark ecb6550b5c Change mentions of OpenGL 2 to OpenGL 3.
We ended up in a confusing state where OpenGL 2 (like in "gl2")
actually refers to OpenGL ES 2, which roughly corresponds to
OpenGL 3. Rectify that.
2017-04-06 07:20:50 +00:00
EvilSpirit aaa9c6df7a Fix a texture memory leak. 2017-03-22 19:12:25 +00:00
EvilSpirit 5744d1d599 Implement an image request. 2017-03-12 00:13:56 +00:00
whitequark e2e74762f4 Rework path and file operations to be more robust.
This commit updates a *lot* of rather questionable path handling
logic to be robust. Specifically:
  * All path operations go through Platform::Path.
  * All ad-hoc path handling functions are removed, together with
    PATH_SEP. This removes code that was in platform-independent
    parts, but had platform-dependent behavior.
  * Group::linkFileRel is removed; only an absolute path is stored
    in Group::linkFile. However, only Group::linkFileRel is saved,
    with the relative path calculated on the fly, from the filename
    passed into SaveToFile. This eliminates dependence on global
    state, and makes it unnecessary to have separare code paths
    for saved and not yet saved files.
  * In a departure from previous practice, functions with
    platform-independent code but platform-dependent behavior
    are all grouped under platform/. This makes it easy to grep
    for functions with platform-dependent behavior.
  * Similarly, new (GUI-independent) code for all platforms is added
    in the same platform.cpp file, guarded with #ifs. It turns out
    that implementations for different platforms had a lot of shared
    code that tended to go out of sync.
2017-03-11 18:58:53 +00:00
whitequark 27b59f601e Fix type conversion warnings. 2017-03-10 21:05:52 +00:00
whitequark 8370382a33 Fix reference to a shader that no longer exists. 2017-01-17 11:26:04 +00:00
whitequark 5b2ad9b5f1 Fix 2d stippling of hovered and selected faces.
This was broken in ec07516.
2017-01-17 11:26:04 +00:00
whitequark 6931979b8e Fix an OpenGL initialization glitch.
Before this commit, the first time NewFrame() is called,
the background color would not be filled, leading to interference
with whatever the GUI toolkit decided to put there.
2017-01-14 06:06:55 +00:00
whitequark 6b67cfe63f Except when using OpenGL ES 2, use OpenGL 3.2+ Core profile.
This is primarily done to lower the GTK version dependency below
GTK 3.22, since GTK 3.22 is unlikely to be widely availale any
time soon.
2017-01-13 23:43:02 +00:00
EvilSpirit fb667fb8bb Use a dedicated BitmapFont instance per Canvas.
Before this commit, updates to the bitmap font in the graphics window
cause missing characters in the text window and vice versa. This is
because BitmapFont contains a texture that's mutated, and sharing it
would also require sharing display lists between GL contexts, which
is not done (and overly complicated for this case anyway).
2017-01-11 03:33:10 +00:00
whitequark 6bb73a162c GTK: remove GlWidget, use standard Gtk::GLArea.
This removes a large number of hacks from the codebase, speeds up
the rendering, and removes tearing when dragging entities.
2017-01-02 16:21:05 +00:00
EvilSpirit 25631d4fb2 Choose entities to select in a way appropriate for the operation.
Before this commit, when an entity is clicked at or dragged, and it
shares a place with other entities, which of them is selected is
decided more or less at random. This is particularly annoying when
dragging.

After this commit, when clicking, an entity from the current group
is given preference, and when dragging, an entity from a request
is given preference. This allows e.g. dragging points of a sketch
even when an extrusion of that sketch is active.
2017-01-02 12:21:01 +00:00
EvilSpirit 10251c6484 In OpenGl2Renderer, do not issue a draw call per DrawVectorText call.
This significantly improves performance with ANGLE.
2016-12-21 18:58:20 +00:00
Evil-Spirit 3858cbe249 Fix a possible use-after-free in OpenGl2Batch.
IdList could reallocate its storage after we grab an interior
pointer, so just make a copy instead.
2016-12-03 08:22:12 +00:00
whitequark b975380493 Fix refactoring issue in gl2shader.h.
Oops, I accidentally changed the order of fields where I shouldn't
have; add a comment to avoid this in the future.
2016-12-02 11:13:31 +00:00
EvilSpirit 37defcbc33 Unbreak Camera::UnProjectPoint3.
The handedness was wrong, and this resulted in weird glitches
while drawing anything that depends on AlignToPixelGrid, like
normals.
2016-11-19 09:50:00 +00:00
EvilSpirit 01ae452507 Unbreak drawing of DEPTH_ONLY meshes via OpenGL 2 batch canvas. 2016-11-19 09:04:47 +00:00
whitequark d3f2ac7513 Remove most dependencies on config.h.
The only thing we need it anymore is the package version and platform
configuration, so only include it for that. As a result, less files
are rebuilt when the git commit changes and config.h is regenerated.
2016-11-19 01:00:11 +00:00
whitequark 73844f7202 Draw triangle back faces like the front, unless we draw them in red.
The configuration option "draw back faces in red" aids debugging,
in that it allows to visually identify a non-watertight mesh.
When it is disabled, or when the mesh is transparent, we used to not
draw them at all before this commit; after, they are drawn just like
the front faces.

This has two consequences:
  1. Inner surfaces of non-watertight meshes are not see-through
     anymore. That used to be the behavior in version 2.0, and it
     was accidentally broken in 2.1.
  2. Transparent meshes look *much* better.
  3. Solids made from a union of a non-transparent and a transparent
     one look sensibly at all.

This commit also updates the OpenGL 1 renderer to let it render
such meshes correctly.
2016-11-18 11:38:45 +00:00
whitequark c8ff17f4a2 Add OpenGL 2 support on Windows using ANGLE.
This commit performs two main changes:
  * Alters the shaders to use only strictly conformant GLSL 2.0.
  * Alters the Windows UI to use ANGLE via GL ES 2.0 and EGL 1.4.

This commit also drops official support for Windows XP, since ANGLE
requires a non-XP toolset to build. It is still possible to build
SolveSpace for Windows XP using:

  cmake -T v120_xp -DOPENGL=1
2016-11-18 11:38:45 +00:00
whitequark 9db50ed077 Refactor the renderer frame flush functionality.
This commit does three things:
  * Recognizes that BeginFrame()/EndFrame() are badly named, since
    BeginFrame() sets up framebuffer, and EndFrame() flushes a frame,
    and they do not have to be called in pairs; and so renames them
    to NewFrame()/FlushFrame().
  * Reduces the amount of frame flushes in GraphicsWindow::Paint()
    to two, which is the minimum since we use two different cameras
    for geometry and UI;
  * Changes the FPS measurement code to only take into account
    the time spent rendering our main geometry, and not the UI
    rendering or window system interaction time.
2016-11-18 04:05:12 +00:00
whitequark 156fe73bee Allow using z-index in UiCanvas, and use it for tooltips.
Before this commit, tooltips in the text window are drawn under
the red "X" indicating a disabled button. After this commit, they
are moved on top of that.

This commit also alters the OpenGL renderers' SetCamera() method
to clear the depth buffer, as that would interfere with drawing
the UI; the toolbar would get occluded by geometry.
2016-11-18 04:05:12 +00:00