So, I am currently at day 242, keeping up a good fight against OS X graphics API in order to make things work properly. As a person who've never written a line of OpenGL code in my life before this, it is a bit of a struggle.
Originally I've always blitted the bitmap to the screen via OpenGL in my OS X version of the platform layer. Everything turned out much cleaner after I'd implemented Casey's version of basically the same thing, both the render and the blit.
However, I am having some difficulty understanding how to deal with certain features that were introduced in 242. What occurs is Casey introduces detection of availability of modern OpenGL features by looking up wglCreateContextAttribsARB function and attempting to instantiate a device context with a specific set of attributes including major API version and various flags. Then he proceeds to look up available extensions using glGetString and use that information in order to set some parameters (GL_EXT_texture_sRGB, GL_EXT_framebuffer_sRGB) and set up stage for further endeavours. As I understand, this will be needed in the future. For reference, here's a
direct link to a related commit to those who has access to the github repo.
From what I can tell, Windows' implementation of OpenGL API allows request of modern OpenGL features while retaining possibility to use antiquated immediate mode drawing functions.
OS X is not set up that way. The user has a choice to either include gl.h and use direct mode drawing or include gl3.h and completely migrate to a newer API.
My current code to instantiate an OpenGL context looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 | static NSOpenGLContext *
OSXInitOpenGL(NSWindow *Window)
{
NSOpenGLPixelFormatAttribute Attributes[] =
{
NSOpenGLPFAClosestPolicy,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 32,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy,
0
};
NSOpenGLPixelFormatAttribute ModernAttributes[] =
{
NSOpenGLPFAClosestPolicy,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 32,
NSOpenGLPFAAlphaSize, 8,
// NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *PixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes: Attributes];
NSOpenGLContext *Context =
[[NSOpenGLContext alloc] initWithFormat: PixelFormat
shareContext: 0];
/* modern context set up */
b32 IsModernContext = false;
NSOpenGLPixelFormat *ModernPixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes: ModernAttributes];
NSOpenGLContext *ModernContext =
[[NSOpenGLContext alloc] initWithFormat: ModernPixelFormat
shareContext: 0];
if (ModernContext)
{
IsModernContext = true;
[Context dealloc];
Context = ModernContext;
[PixelFormat dealloc];
PixelFormat = ModernPixelFormat;
}
else
{
// NOTE: This is an antiquated version of OpenGL
}
if (Context)
{
[Context makeCurrentContext];
OpenGLInit(IsModernContext);
GLint VSync = 1;
// if (VSync)
{
[Context setValues: &VSync forParameter: NSOpenGLCPSwapInterval];
}
}
else
{
InvalidCodePath;
// TODO: Diagnostic
}
#if 0
GLint Dimensions[] = {FramebufferWidth, FramebufferHeight};
CGLSetParameter(Context.CGLContextObj, kCGLCPSurfaceBackingSize, Dimensions);
CGLEnable(Context.CGLContextObj, kCGLCESurfaceBackingSize);
#endif
NSOpenGLView *View = [[NSOpenGLView alloc] init];
[View setOpenGLContext: Context];
[View setPixelFormat: PixelFormat];
[Window setContentView: View];
[Context setView: View];
return Context;
}
|
Note the commented line inside the definition of the ModernAttributes variable. If I try to enable this profile, the renderer does not function. Although, curiously enough, I can still run the game and see OpenGL clearing up the bitmap to a pre-defined colour and then blit it to the screen. The function glGetString(GL_EXTENSIONS) returns NULL, but it returns all the other requested strings properly. GL_VERSION and GL_SHADING_LANGUAGE_VERSION clearly show a newer version of the driver and shading language which implies that the only things I lose by doing things this way is the access to immediate drawing functions.
Currently, I include OpenGL header files in the following fashion:
| #define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED 1
#import <OpenGL/gl.h>
#import <OpenGL/gl3.h>
|
So here are the questions:
1) why does the implementations are so drastically different? (this is probably rhetorical but still)
2) is there going to be a move towards usage of the modern API by Casey in the future? I.e., should I bite the bullet now and write a completely new version of the current renderer just to satisfy the design decision to support both newer and older version of OpenGL? What sorts of extended features of OpenGL might be used in the Windows implementation that are optional and do not break the main render path written using outdated immediate mode functions?
3) Am I even understanding the situation correctly or there are things that I am missing due to inexperience?
Thank you