Intel sponsors gamedev.net search:   
Promit's VentspaceBy Promit      

Welcome to Ventspace! Most posts here are delayed copies of posts from the real Ventspace.

Wednesday, May 21, 2008
I will note for the record that a 15 hour workday is much less fun than the brochure would have you believe. Oh, and this entry's a bit on the "phoned in" side, I'm afraid.

And one more little thing:
1>SlimDX - 0 error(s), 32551 warning(s)

Windows, OpenGL Versions, and Extensions

Something I've noticed any number of times is that many people are quite vague on how OpenGL works on Windows. This causes a lot of confusion about exactly what the limitations on Windows are with respect to versions, and people tend to say things that don't make sense. The most common misunderstanding is that Windows is limited to OpenGL 1.1. It's time to clear things up.

First, let's start by dissecting the basic OpenGL architecture on Windows. When you build your OpenGL based program, you link to opengl32.lib. This file from the Platform SDK is a companion to the opengl32.dll that ships with Windows. The GL/gl.h header you use matches these two files. When your code runs, some behind the scenes work happens that loads up the functions out of opengl32.dll. However, opengl32.dll is a purely software implementation of OpenGL 1.1, and it's probably not what you want to be using. What you want to be using is the real OpenGL DLL, for example nvoglnt.dll. This file is installed with your video driver.

This is where magic starts to happen. Your calls to opengl32.dll will be redirected to the actual driver specific DLL, which exports at least all the functions in opengl32.dll. The trick is, it also exports a lot more than that. The entire OpenGL API for the version that it supports will be exported, along with all the extensions. Calls to wglGetProcAddress become GetProcAddress calls on the OpenGL DLL that came from the driver. This isn't limited to extensions; you can use it on regular non-extension functions as long as the video driver supports a version of OpenGL that includes them.

The problem here is that, depending on the manufacturer of your video driver and the version, the real DLL that implements OpenGL could be anywhere. Windows provides opengl32.dll as a common place to go to, instead of having to figure out what DLL you need at runtime. That DLL also servves the dual purpose of providing the basic software implementation. That's why it's nearly never been updated; adding new OpenGL functions would mean writing code to implement all of that in software. In Vista they decided to provide a new version built on D3D instead of software, so applications using the Vista headers and libraries can get a baseline of OpenGL 1.4 statically.

All that an extension loader does, then, is to automate the tedious process of making the dozens or hundreds of GetProcAddress calls to retrieve the functions that aren't statically linked and forwarded. Again, these functions don't have to be extensions. You can wglGetProcAddress for glMapBuffer, not just glMapBufferARB. There's no question of what Windows supports. It doesn't matter. The only function you actually need from Windows is wglGetProcAddress, which is your key to accessing the real OpenGL DLL. The rest of the interface is just a convenience in that you don't have to go out and get the addresses for the OpenGL 1.1 functions, since they're already being redirected for you. And since modern extension loaders are machine generated systems that automatically look up everything, it's less relevant than ever before.

Comments: 3 - Leave a Comment

Link



Wednesday, May 7, 2008
Deadlines at work, moving apartments, and GTA IV. Where the heck am I supposed to find time for anything else?

A Complete Listing of C++ String Types

Inspired by a recent IRC conversation, I decided to make a complete list of all of the major string types you're in danger of encountering when working in C++, along with a brief description.
  • char[] -- By far the most primitive string type, but fairly common. A fixed size array of (almost certainly ANSI) characters. Might be null terminated, might not. Kinda depends on what the programmer felt like at the time.

  • char*, unsigned char*, signed char* -- Your good ol' (usually) null terminated array of bytes. Usually correspond 1<->1 with characters, unless you're using an actual encoding such as UTF-8.

  • wchar_t* -- The most basic Unicode string type; very nearly always indicates a UCS2 encoding. Again, null terminated.
  • std::string -- Still an array of bytes, but null termination is dispensed with in favor of a length stored inside the string class (not in the string data itself). It's pretty much assumed that you're looking at ANSI here without any encoding.

  • std::wstring -- Like the string class, but an array of wchar_t instead of char. UCS2 encoding is assumed.

  • std::basic_string<T> -- This is the template that's used to form std::string and std::wstring.

  • boost::const_string -- An immutable string that provides a subset of std::basic_string functionality.

  • LPSTR -- This one's a Win32 typedef for char*.

  • LPWSTR -- And this one's a Win32 typedef for wchar_t*.

  • TCHAR* -- A null terminated array of wchar_t if UNICODE is defined, or char otherwise.

  • LPTSTR -- Win32 typedef for TCHAR*.

  • LPCSTR, LPCWSTR, LPCTSTR -- Const versions of the Win32 string types. Take out the C to figure out what they are.

  • BSTR -- This is a COM string. It's an array of characters, prefixed by a 4 byte length specifier. It's an array of OLECHAR; the characters are UCS2 on Windows, ANSI on Mac. It can can contain null characters. It's also terminated by two null characters. The BSTR pointer always points to the first character, so the length is at ptr[-2], at least on Windows. Oh, and Visual Basic 6 uses these for all its strings.

  • CString -- ATL/MFC string class. C++ code that does anything serious with Windows inevitably ends up using these things. Character size is controlled by the UNICODE define again. Oh, and it comes in CStringA and CStringW variations if you want.

  • CStringT -- This is the template class used to form CString.

  • CSimpleStringT -- This is the base class for CStringT.

  • PXSTR, PYSTR -- PXSTR is the internal type used by CSimpleStringT.
  • If PXSTR is Unicode, then PYSTR isn't, and vice versa. Also comes in const (C) variations.
  • CAtlString -- Apparently this appears when you're using ATL but not the CRT or something. Also comes in A and W variations. It's actually just a typedef for CString.

  • CComBSTR -- This is a class that wraps BSTR.

  • _bstr_t -- This is also a class that wraps BSTR.

  • VARIANT -- Here's a fun one. It's a COM variant type. It can be VT_BSTR, VT_LPSTR, or VT_LPWSTR. (And it doesn't have to be a string, of course.)

  • wxString -- The string class from wxWidgets. Can be Unicode or not, and can contain null characters.

  • GString -- The string class from GLIB, used by GTK+ and GNOME. It stores the length of the string and can contain null characters. Sadly, the people working on and with these libraries still think the name is funny.

  • QString -- The string class from Qt. It's a null terminated array of Unicode/UCS2 characters.

  • QCString -- Same as QString, but with ANSI single byte characters instead.

  • FString -- The string class from Unreal.

  • CStr -- The string class from 3D Studio Max.

  • MString -- The string class from Maya.

  • System::String^ -- If you're lucky enough to be working with C++/CLI, you get to use this .NET string, which is an immutable UTF-16 string. You heard me. UTF-16. Not UCS2. A single character can be more than one System::Char long.

  • System::StringBuilder^ -- A mutable statically sized buffer of System::Char. This is usually for doing a lot of string manipulation without ending up with tons of extra allocations.

Current list length: 30

This list is still a work in progress, mind you. I'm sure there's plenty of string types from major libraries that I'm missing, and there's probably lots of detail that can be added to the ones I've listed so far.

Comments: 7 - Leave a Comment

Link


All times are ET (US)

 
S
M
T
W
T
F
S
1
2
3
4
5
6
8
9
10
11
12
13
14
15
16
17
18
19
20
22
23
24
25
26
27
28
29
30
31

OPTIONS
Track this Journal

 RSS 

ARCHIVES
October, 2009
September, 2009
August, 2009
July, 2009
June, 2009
October, 2008
June, 2008
May, 2008
April, 2008
March, 2008
February, 2008
January, 2008
December, 2007
November, 2007
October, 2007
September, 2007
August, 2007
July, 2007
June, 2007
May, 2007
February, 2007