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

Scissor test failure on Mac #136

Closed
kanthoney opened this issue May 7, 2015 · 25 comments

Comments

@kanthoney
Copy link
Contributor

commented May 7, 2015

As reported on the BB here, the scissor test in the short range chart screen fails:

image

The problem appears to be confusion between points and pixels on the Mac retina screen. There is some deleveloper information available which may help solve this problem.

@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 7, 2015

So the Mac retina display is a display where each point on the screen is a square of four pixels. OpenGL doesn't know about points, so a Mac OpenGL application has two options. The default "lo-res" option is to request a viewport size based on points and then double everything in both directions to map it to pixels. The "hi-res" option is to request a viewport size based on pixels instead of points.

What seems to be happening here is that OpenGL is rendering everything, then doubling it up, and then applying the scissor test without first doubling the coordinates of the scissor rectangle. Consequently, it's scissoring the bottom left quarter of the window instead of the whole one. Could it be a buggy driver?

@iandol

This comment has been minimized.

Copy link

commented May 7, 2015

Just to provide screenshot machine context, this is a retina Macbook Pro running the latest public beta of 10.10.4 with up-to-date drivers -- the resolution where the problem happens is 1440x900HiDPI — I can fix it by disabling the HiDPI mode but this causes havoc for other applications (you need special software to disable a HiDPI mode, OS X doesn't allow this normally). Most of the rest of Oolite works fine, and rendering is nice and crisp in HiDPI mode, it doesn't look fuzzy etc.

@AnotherCommander

This comment has been minimized.

Copy link
Member

commented May 8, 2015

Kevin, remember the code you had written when you initially implemented the scrolling chart feature? The code which was removed soon after we found that the scissor test method does exactly what we wanted but much faster? In case there is no fix to this issue soon, how about re-introducing that code for Mac only and make the game switch to it via an e.g. defaults file setting? I know it is not the perfect fix, but given the absence of our Mac maintainers, maybe this could be a way out of the problem, at the expense of speed of scrolling on retina Macs. What do you think?

@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 8, 2015

I'm looking at this Mac code in MyOpenGLView.m:

- (void) initialiseGLWithSize:(NSSize)v_size
{
        viewSize = v_size;
        if (viewSize.width/viewSize.height > 4.0/3.0) {
                display_z = 480.0 * viewSize.width/viewSize.height;
                x_offset = 240.0 * viewSize.width/viewSize.height;
                y_offset = 240.0;
        } else {
                display_z = 640.0;
                x_offset = 320.0;
                y_offset = 320.0 * viewSize.height/viewSize.width;
        }

        if ([self respondsToSelector:@selector(convertSizeToBacking:)])
        {
                // High resolution mode support.
                v_size = [self convertSizeToBacking:v_size];
        }

        [self openGLContext];   // Force lazy setup if needed.
        [[self gameController] setUpBasicOpenGLStateWithSize:v_size];
        [[self openGLContext] flushBuffer];

        m_glContextInitialized = YES;
}

I've got a hunch that if we insert a [self setWantsBestResolutionOpenGLSurface:YES]; in the bit that mentions high resolution support, that may fix the problem. (It's possible that it'd make the game only use the bottom left hand corner of the screen on retina displays. I think the fix for that would be to add viewSize = v_size; after the convertSizeToBacking call.)

It's probably worth trying that before the nasty hack. I'll look into it a bit more this evening.

@cim-- cim-- added this to the Version 1.82 milestone May 9, 2015

@AnotherCommander

This comment has been minimized.

Copy link
Member

commented May 9, 2015

@iandol Kevin commited an attempted fix a little while ago. Can you please test tomorow's nightly build and let us know if it has resolved the problem?

@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 10, 2015

Did we get any build errors?

@AnotherCommander

This comment has been minimized.

Copy link
Member

commented May 10, 2015

Unfortunately it looks like the nightly build for Mac is stuck on May 5th. Last revision built was 389e3d4. We really need Mac maintainers to look at this or feedback from iandol, in case he can build the source himself.

@iandol

This comment has been minimized.

Copy link

commented May 10, 2015

Sadly I can't build oolite, so I'll have to wait for a new nightly before I can confirm a fix. Thanks for looking at this!!!

@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2015

If you want to give it a go (no pressure if you don't), you just need a git client (available free from http://git-scm.com/) and xcode (available free from the app store).

To check out the source code using git, open a command line and run

git clone https://github.com/OoliteProject/oolite
cd oolite
git submodule update --init

(There'll be an equivalent procedure with one of the gui clients, but you'll be on your own with those.)

This will create a folder called oolite, with a subfolder Oolite.xcodeproj. If you open the file project.pbxproj inside that it should launch xcode, and then (according to the readme, anyway) hit Build.

@iandol

This comment has been minimized.

Copy link

commented May 11, 2015

I get the following build errors/warnings:

/Users/ian/Code/oolite/src/Core/OOOXZManager.m:781:59: error: values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead [-Werror,-Wformat]
        OOLog(kOOOXZDebugLog,@"Dependency stack has %u elements",[_dependencyStack count]);
                                                    ~~           ^~~~~~~~~~~~~~~~~~~~~~~~
                                                    %lu
In file included from /Users/ian/Code/oolite/src/Core/OOOXZManager.m:27:
In file included from /Users/ian/Code/oolite/src/Core/OOOXZManager.h:27:
In file included from /Users/ian/Code/oolite/src/Core/OOCocoa.h:261:
/Users/ian/Code/oolite/src/Core/OOLogging.h:88:185: note: expanded from macro 'OOLog'
        #define OOLog(class, format, ...)                               do { if (OOLogWillDisplayMessagesInClass(class)) { OOLogWithFunctionFileAndLine(class, OOLOG_FUNCTION_NAME, OOLOG_FILE_NAME, __LINE__, format, ## __VA_ARGS__); }} while (0)
                                                                                                                                                                                                                          ^
/Users/ian/Code/oolite/src/Core/OOOXZManager.m:848:71: error: values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead [-Werror,-Wformat]
                                OOLog(kOOOXZDebugLog,@"Dependency stack: installing %u from list",index);
                                                                                    ~~            ^~~~~
                                                                                    %lu
In file included from /Users/ian/Code/oolite/src/Core/OOOXZManager.m:27:
In file included from /Users/ian/Code/oolite/src/Core/OOOXZManager.h:27:
In file included from /Users/ian/Code/oolite/src/Core/OOCocoa.h:261:
/Users/ian/Code/oolite/src/Core/OOLogging.h:88:185: note: expanded from macro 'OOLog'
        #define OOLog(class, format, ...)                               do { if (OOLogWillDisplayMessagesInClass(class)) { OOLogWithFunctionFileAndLine(class, OOLOG_FUNCTION_NAME, OOLOG_FILE_NAME, __LINE__, format, ## __VA_ARGS__); }} while (0)

It offered me a chance to auto-fix it which I tried but then I got the following error:\

/Users/ian/Code/oolite/src/Core/OOOXZManager.m:848:72: Expected expression
@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2015

Thanks very much. I think I've fixed the error, although I've only done what the auto fix probably did.

To fetch the changes, command line again and cd to the oolite folder. Then

git checkout -- .

to clear any changes made by the autofix (notice the . at the end), then

git fetch origin
git pull origin master

And then try another build. And again, thanks for your help!

@iandol

This comment has been minimized.

Copy link

commented May 11, 2015

So, I clean (⇧⌘K) then I run (⌘R, I also tried building then manually running the app in the Products/ folder) in XCode and no build errors, then I start a new commander in strict mode but I still see this problem :-(
screen shot 2015-05-11 at 17 00 57

My source tree is on cd71bf1

@iandol

This comment has been minimized.

Copy link

commented May 11, 2015

Note, I also tried to build oolite - Deployment just in case it was somehow differenrt and got this build error:

Debug Bundle Group
/Users/ian/Code/oolite/src/Core/Scripting/OOJSPropID.h
/Users/ian/Code/oolite/src/Core/Scripting/OOJSPropID.h:26:10: 'jsapi.h' file not found
@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2015

The fix isn't enabled by default, in case it breaks stuff for non-retina users. To enable it (I'm blagging the instructions from here), try the following from the command line:

defaults write org.aegidian.oolite issue_136_fix <value>

where <value> is 0 (off), 1 (possible fix no. 1), or 2 (possible fix no. 2)

I'm guessing that the first fix might work, or it might restrict Oolite to the bottom left hand corner of the window, in which case try fix number 2.

@iandol

This comment has been minimized.

Copy link

commented May 11, 2015

Value 1: still broken
Value 2: star map now is working fine! The problems I saw were the mouse cursor (the cross hair that tracks the system cursor) maps to a 1/4 of the screen (system cursor top right = middle of the screen). And in fullscreen mode the HUD and planet flickers (looks "interlaced"). Flicker is worse in some positions than others, facing the sun and it is bad enough to induce epilepsy!

@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2015

Bugger!

From the command line again, try

git checkout origin/issue_136

and try another build, then set the issue_136_fix value to 3.

@iandol

This comment has been minimized.

Copy link

commented May 11, 2015

Value 3 (with commit 1667290) shows oolite in the bottom left quadrant, with the star map properly drawn at least!:

screen shot 2015-05-12 at 00 34 03

@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 12, 2015

OK then:

git pull origin issue_136

Then build, and

defaults write org.aegidian.oolite issue_136_fix YES
@iandol

This comment has been minimized.

Copy link

commented May 12, 2015

So on commit 2d926ab with YES as the defaults:

screen shot 2015-05-12 at 09 46 04

But then I tried cycling through the other options again just in case and on value==1 it now seems to work!!!

screen shot 2015-05-12 at 09 59 43

Double checking the value:

>>  defaults read org.aegidian.oolite issue_136_fix     
1

I can't see any flickering or problems with mouse co-ordinates etc. I'm a newbie ooliter so I could have missed something but it all seems OK. Well done!!!

@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 12, 2015

Yay! I'll take that!

By the way, I got the command wrong - it should have been

defaults write org.aegidian.oolite key -bool YES

The issue you had with the truncated screen shots probably hasn't been fixed (I've just remembered about that). Can you give that a try?

@iandol

This comment has been minimized.

Copy link

commented May 12, 2015

Screenshots are still truncated in windowed or full-screen mode, but system screen shots work fine so this isn't a major platform issue. Congrats on the fix!

@iandol

This comment has been minimized.

Copy link

commented May 12, 2015

I also tried switching to master and pulling the changes there and star map still works fine...

@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 12, 2015

I think I've fixed the screenshot bug as well, so that's

git checkout issue_136
git pull origin issue_136
defaults write org.aegidian.oolite key -bool YES

Thanks for the help!

@iandol

This comment has been minimized.

Copy link

commented May 12, 2015

Screenshots also fixed :-) 👍

@kanthoney

This comment has been minimized.

Copy link
Contributor Author

commented May 12, 2015

Fantastic! Thanks again for all the help with that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.