sdl/pixels: make SDL_PIXELFORMAT aliases use the C values directly
SDL_PIXELFORMAT aliases were not calculated during compile-time. This
change makes the aliases refer to the C values directly. In SDL2 < 2.0.5,
we define the missing enums ourselves.
package sdl
// #include "sdl_wrapper.h"
+//
+// #if !(SDL_VERSION_ATLEAST(2,0,5))
+//
+// enum
+// {
+// #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+// SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
+// SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
+// SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
+// SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888
+// #else
+// SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
+// SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
+// SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
+// SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888
+// #endif
+// };
+//
+// #endif
+//
// int bytesPerPixel(Uint32 format) {
// return SDL_BYTESPERPIXEL(format);
// }
+//
// int bitsPerPixel(Uint32 format) {
// return SDL_BITSPERPIXEL(format);
// }
@@ -162,10 +183,10 @@ const (
// Pixel format variables.
var (
- PIXELFORMAT_RGBA32 int
- PIXELFORMAT_ARGB32 int
- PIXELFORMAT_BGRA32 int
- PIXELFORMAT_ABGR32 int
+ PIXELFORMAT_RGBA32 = C.SDL_PIXELFORMAT_RGBA32
+ PIXELFORMAT_ARGB32 = C.SDL_PIXELFORMAT_ARGB32
+ PIXELFORMAT_BGRA32 = C.SDL_PIXELFORMAT_BGRA32
+ PIXELFORMAT_ABGR32 = C.SDL_PIXELFORMAT_ABGR32
)
// These define alpha as the opacity of a surface.
@@ -174,20 +195,6 @@ const (
ALPHA_TRANSPARENT = C.SDL_ALPHA_TRANSPARENT
)
-func init() {
- if BYTEORDER == BIG_ENDIAN {
- PIXELFORMAT_RGBA32 = PIXELFORMAT_RGBA8888
- PIXELFORMAT_ARGB32 = PIXELFORMAT_ARGB8888
- PIXELFORMAT_BGRA32 = PIXELFORMAT_BGRA8888
- PIXELFORMAT_ABGR32 = PIXELFORMAT_ABGR8888
- } else {
- PIXELFORMAT_RGBA32 = PIXELFORMAT_ABGR8888
- PIXELFORMAT_ARGB32 = PIXELFORMAT_BGRA8888
- PIXELFORMAT_BGRA32 = PIXELFORMAT_ARGB8888
- PIXELFORMAT_ABGR32 = PIXELFORMAT_RGBA8888
- }
-}
-
func (format *PixelFormat) cptr() *C.SDL_PixelFormat {
return (*C.SDL_PixelFormat)(unsafe.Pointer(format))
}
