gosu 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gosu/Bitmap.hpp +3 -3
- data/Gosu/Directories.hpp +6 -3
- data/Gosu/Gosu.hpp +0 -1
- data/Gosu/GraphicsBase.hpp +12 -8
- data/Gosu/Input.hpp +5 -16
- data/Gosu/Platform.hpp +1 -0
- data/Gosu/Version.hpp +3 -5
- data/Gosu/Window.hpp +7 -8
- data/README.txt +3 -3
- data/ext/gosu/extconf.rb +17 -16
- data/ext/gosu/gosu_wrap.cxx +59 -58
- data/ext/gosu/gosu_wrap.h +1 -1
- data/rdoc/gosu.rb +285 -283
- data/src/{MacUtility.hpp → AppleUtility.hpp} +24 -42
- data/src/Audio/ALChannelManagement.hpp +1 -1
- data/src/Audio/{AudioOpenAL.cpp → Audio.cpp} +6 -7
- data/src/Audio/Audio.mm +1 -0
- data/src/Audio/AudioFile.hpp +2 -2
- data/src/Audio/AudioToolboxFile.hpp +5 -20
- data/src/Audio/OggFile.hpp +44 -56
- data/src/Audio/SndFile.hpp +2 -2
- data/src/Bitmap/Bitmap.cpp +98 -2
- data/src/Bitmap/BitmapIO.cpp +156 -0
- data/src/DirectoriesApple.mm +76 -0
- data/src/DirectoriesUnix.cpp +5 -12
- data/src/DirectoriesWin.cpp +5 -0
- data/src/Graphics/BlockAllocator.hpp +2 -2
- data/src/Graphics/ClipRectStack.hpp +2 -2
- data/src/Graphics/Common.hpp +2 -2
- data/src/Graphics/DrawOp.hpp +2 -2
- data/src/Graphics/DrawOpQueue.hpp +2 -2
- data/src/Graphics/Graphics.cpp +7 -2
- data/src/Graphics/LargeImageData.cpp +6 -6
- data/src/Graphics/LargeImageData.hpp +3 -3
- data/src/Graphics/Macro.hpp +2 -2
- data/src/Graphics/RenderState.hpp +2 -2
- data/src/Graphics/Resolution.cpp +1 -1
- data/src/Graphics/TexChunk.hpp +2 -2
- data/src/Graphics/Texture.cpp +21 -16
- data/src/Graphics/Texture.hpp +7 -5
- data/src/Graphics/TransformStack.hpp +2 -2
- data/src/Iconv.hpp +2 -2
- data/src/Input/Input.cpp +3 -1
- data/src/Input/{InputTouch.mm → InputUIKit.mm} +32 -26
- data/src/Input/TextInput.cpp +1 -1
- data/src/Text/FormattedString.hpp +2 -2
- data/src/Text/TextApple.mm +8 -8
- data/src/Text/TextMac.cpp +1 -1
- data/src/Text/TextUnix.cpp +1 -1
- data/src/UIKit/GosuAppDelegate.h +8 -0
- data/src/UIKit/GosuAppDelegate.mm +24 -0
- data/src/UIKit/GosuGLView.h +8 -0
- data/src/UIKit/GosuGLView.mm +130 -0
- data/src/UIKit/GosuViewController.h +13 -0
- data/src/UIKit/GosuViewController.mm +214 -0
- data/src/UtilityApple.mm +5 -18
- data/src/Window.cpp +1 -3
- data/src/WindowUIKit.mm +124 -0
- data/src/stb_image.h +6437 -0
- data/src/stb_image_write.h +730 -0
- data/src/stb_vorbis.c +5459 -0
- metadata +18 -26
- data/Gosu/Sockets.hpp +0 -156
- data/src/Audio/AudioOpenAL.mm +0 -1
- data/src/Bitmap/BitmapApple.mm +0 -226
- data/src/Bitmap/BitmapBMP.cpp +0 -79
- data/src/Bitmap/BitmapColorKey.cpp +0 -50
- data/src/Bitmap/BitmapFreeImage.cpp +0 -174
- data/src/Bitmap/BitmapGDIplus.cpp +0 -212
- data/src/Bitmap/BitmapUtils.cpp +0 -76
- data/src/DirectoriesMac.mm +0 -38
- data/src/DirectoriesTouch.mm +0 -38
- data/src/GosuView.hpp +0 -15
- data/src/GosuView.mm +0 -208
- data/src/Input/AccelerometerReader.hpp +0 -10
- data/src/Input/AccelerometerReader.mm +0 -31
- data/src/Sockets/CommSocket.cpp +0 -305
- data/src/Sockets/ListenerSocket.cpp +0 -59
- data/src/Sockets/MessageSocket.cpp +0 -128
- data/src/Sockets/Socket.cpp +0 -145
- data/src/Sockets/Socket.hpp +0 -66
- data/src/WindowTouch.mm +0 -243
- data/src/X11vroot.h +0 -118
data/src/Graphics/Texture.cpp
CHANGED
@@ -10,27 +10,27 @@ namespace Gosu
|
|
10
10
|
bool undocumentedRetrofication = false;
|
11
11
|
}
|
12
12
|
|
13
|
-
Gosu::Texture::Texture(unsigned size)
|
14
|
-
:
|
13
|
+
Gosu::Texture::Texture(unsigned size, bool retro)
|
14
|
+
: allocator_(size, size), retro_(retro)
|
15
15
|
{
|
16
16
|
ensureCurrentContext();
|
17
17
|
|
18
18
|
// Create texture name.
|
19
|
-
glGenTextures(1, &
|
20
|
-
if (
|
19
|
+
glGenTextures(1, &texName_);
|
20
|
+
if (texName_ == static_cast<GLuint>(-1))
|
21
21
|
throw std::runtime_error("Couldn't create OpenGL texture");
|
22
22
|
|
23
23
|
// Create empty texture.
|
24
|
-
glBindTexture(GL_TEXTURE_2D,
|
24
|
+
glBindTexture(GL_TEXTURE_2D, texName_);
|
25
25
|
#ifdef GOSU_IS_OPENGLES
|
26
|
-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
26
|
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, allocator_.width(), allocator_.height(), 0,
|
27
27
|
GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
28
28
|
#else
|
29
|
-
glTexImage2D(GL_TEXTURE_2D, 0, 4,
|
29
|
+
glTexImage2D(GL_TEXTURE_2D, 0, 4, allocator_.width(), allocator_.height(), 0,
|
30
30
|
GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
31
31
|
#endif
|
32
32
|
|
33
|
-
if (undocumentedRetrofication)
|
33
|
+
if (retro || undocumentedRetrofication)
|
34
34
|
{
|
35
35
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
36
36
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
@@ -54,17 +54,22 @@ Gosu::Texture::~Texture()
|
|
54
54
|
{
|
55
55
|
ensureCurrentContext();
|
56
56
|
|
57
|
-
glDeleteTextures(1, &
|
57
|
+
glDeleteTextures(1, &texName_);
|
58
58
|
}
|
59
59
|
|
60
60
|
unsigned Gosu::Texture::size() const
|
61
61
|
{
|
62
|
-
return
|
62
|
+
return allocator_.width(); // == height
|
63
63
|
}
|
64
64
|
|
65
65
|
GLuint Gosu::Texture::texName() const
|
66
66
|
{
|
67
|
-
return
|
67
|
+
return texName_;
|
68
|
+
}
|
69
|
+
|
70
|
+
bool Gosu::Texture::retro() const
|
71
|
+
{
|
72
|
+
return retro_;
|
68
73
|
}
|
69
74
|
|
70
75
|
GOSU_UNIQUE_PTR<Gosu::TexChunk>
|
@@ -73,7 +78,7 @@ GOSU_UNIQUE_PTR<Gosu::TexChunk>
|
|
73
78
|
GOSU_UNIQUE_PTR<Gosu::TexChunk> result;
|
74
79
|
|
75
80
|
BlockAllocator::Block block;
|
76
|
-
if (!
|
81
|
+
if (!allocator_.alloc(bmp.width(), bmp.height(), block))
|
77
82
|
return result;
|
78
83
|
|
79
84
|
result.reset(new TexChunk(ptr, block.left + padding, block.top + padding,
|
@@ -81,7 +86,7 @@ GOSU_UNIQUE_PTR<Gosu::TexChunk>
|
|
81
86
|
|
82
87
|
ensureCurrentContext();
|
83
88
|
|
84
|
-
glBindTexture(GL_TEXTURE_2D,
|
89
|
+
glBindTexture(GL_TEXTURE_2D, texName_);
|
85
90
|
glTexSubImage2D(GL_TEXTURE_2D, 0, block.left, block.top, block.width, block.height,
|
86
91
|
Color::GL_FORMAT, GL_UNSIGNED_BYTE, bmp.data());
|
87
92
|
|
@@ -90,12 +95,12 @@ GOSU_UNIQUE_PTR<Gosu::TexChunk>
|
|
90
95
|
|
91
96
|
void Gosu::Texture::block(unsigned x, unsigned y, unsigned width, unsigned height)
|
92
97
|
{
|
93
|
-
|
98
|
+
allocator_.block(x, y, width, height);
|
94
99
|
}
|
95
100
|
|
96
101
|
void Gosu::Texture::free(unsigned x, unsigned y, unsigned width, unsigned height)
|
97
102
|
{
|
98
|
-
|
103
|
+
allocator_.free(x, y, width, height);
|
99
104
|
}
|
100
105
|
|
101
106
|
Gosu::Bitmap Gosu::Texture::toBitmap(unsigned x, unsigned y, unsigned width, unsigned height) const
|
@@ -106,7 +111,7 @@ Gosu::Bitmap Gosu::Texture::toBitmap(unsigned x, unsigned y, unsigned width, uns
|
|
106
111
|
ensureCurrentContext();
|
107
112
|
|
108
113
|
Gosu::Bitmap fullTexture(size(), size());
|
109
|
-
glBindTexture(GL_TEXTURE_2D,
|
114
|
+
glBindTexture(GL_TEXTURE_2D, texName());
|
110
115
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, fullTexture.data());
|
111
116
|
Gosu::Bitmap bitmap(width, height);
|
112
117
|
bitmap.insert(fullTexture, -int(x), -int(y));
|
data/src/Graphics/Texture.hpp
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#ifndef
|
2
|
-
#define
|
1
|
+
#ifndef GOSU_SRC_GRAPHICS_TEXTURE_HPP
|
2
|
+
#define GOSU_SRC_GRAPHICS_TEXTURE_HPP
|
3
3
|
|
4
4
|
#include <Gosu/Fwd.hpp>
|
5
5
|
#include <Gosu/Bitmap.hpp>
|
@@ -13,14 +13,16 @@ namespace Gosu
|
|
13
13
|
{
|
14
14
|
class Texture
|
15
15
|
{
|
16
|
-
BlockAllocator
|
17
|
-
GLuint
|
16
|
+
BlockAllocator allocator_;
|
17
|
+
GLuint texName_;
|
18
|
+
bool retro_;
|
18
19
|
|
19
20
|
public:
|
20
|
-
Texture(unsigned size);
|
21
|
+
Texture(unsigned size, bool retro);
|
21
22
|
~Texture();
|
22
23
|
unsigned size() const;
|
23
24
|
GLuint texName() const;
|
25
|
+
bool retro() const;
|
24
26
|
GOSU_UNIQUE_PTR<TexChunk>
|
25
27
|
tryAlloc(std::tr1::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding);
|
26
28
|
void block(unsigned x, unsigned y, unsigned width, unsigned height);
|
data/src/Iconv.hpp
CHANGED
data/src/Input/Input.cpp
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#include <Gosu/TextInput.hpp>
|
3
3
|
#include <Gosu/TR1.hpp>
|
4
4
|
#include <Gosu/Utility.hpp>
|
5
|
-
#include <
|
5
|
+
#include <SDL.h>
|
6
6
|
#include <cwctype>
|
7
7
|
#include <cstdlib>
|
8
8
|
#include <algorithm>
|
@@ -381,6 +381,8 @@ void Gosu::Input::setMousePosition(double x, double y)
|
|
381
381
|
SDL_WarpMouseInWindow(pimpl->window,
|
382
382
|
(x - pimpl->mouseOffsetX) / pimpl->mouseFactorX,
|
383
383
|
(y - pimpl->mouseOffsetY) / pimpl->mouseFactorY);
|
384
|
+
|
385
|
+
pimpl->updateMousePosition();
|
384
386
|
}
|
385
387
|
|
386
388
|
void Gosu::Input::setMouseFactors(double factorX, double factorY,
|
@@ -1,8 +1,7 @@
|
|
1
1
|
#include <Gosu/Input.hpp>
|
2
2
|
#include <Gosu/TextInput.hpp>
|
3
3
|
|
4
|
-
#include "
|
5
|
-
#include "AccelerometerReader.hpp"
|
4
|
+
#include "AppleUtility.hpp"
|
6
5
|
#import <UIKit/UIKit.h>
|
7
6
|
|
8
7
|
struct Gosu::TextInput::Impl {};
|
@@ -20,7 +19,7 @@ struct Gosu::Input::Impl
|
|
20
19
|
float factorX, factorY;
|
21
20
|
float updateInterval;
|
22
21
|
|
23
|
-
|
22
|
+
ObjCRef<NSMutableSet> currentTouchesSet;
|
24
23
|
std::auto_ptr<Gosu::Touches> currentTouchesVector;
|
25
24
|
|
26
25
|
Touch translateTouch(UITouch* uiTouch)
|
@@ -30,15 +29,6 @@ struct Gosu::Input::Impl
|
|
30
29
|
touch.x *= factorX, touch.y *= factorY;
|
31
30
|
return touch;
|
32
31
|
}
|
33
|
-
|
34
|
-
ObjRef<AccelerometerReader> accelerometerReader;
|
35
|
-
|
36
|
-
float acceleration(int index)
|
37
|
-
{
|
38
|
-
if (accelerometerReader.get() == 0)
|
39
|
-
accelerometerReader.reset([[AccelerometerReader alloc] initWithUpdateInterval: updateInterval]);
|
40
|
-
return [accelerometerReader.obj() acceleration][index];
|
41
|
-
}
|
42
32
|
};
|
43
33
|
|
44
34
|
Gosu::Input::Input(void* view, float updateInterval)
|
@@ -57,17 +47,33 @@ Gosu::Input::~Input()
|
|
57
47
|
|
58
48
|
void Gosu::Input::feedTouchEvent(int type, void* touches)
|
59
49
|
{
|
60
|
-
NSSet*
|
50
|
+
NSSet *uiTouches = (NSSet *)touches;
|
61
51
|
|
62
52
|
pimpl->currentTouchesVector.reset();
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
[pimpl->currentTouchesSet.get()
|
68
|
-
|
69
|
-
|
70
|
-
|
53
|
+
|
54
|
+
std::tr1::function<void (Touch)>* callback = nullptr;
|
55
|
+
|
56
|
+
if (type == 0) {
|
57
|
+
[pimpl->currentTouchesSet.get() unionSet:uiTouches];
|
58
|
+
callback = &onTouchBegan;
|
59
|
+
}
|
60
|
+
else if (type == 1) {
|
61
|
+
callback = &onTouchMoved;
|
62
|
+
}
|
63
|
+
else if (type == 2) {
|
64
|
+
[pimpl->currentTouchesSet.get() minusSet:uiTouches];
|
65
|
+
callback = &onTouchEnded;
|
66
|
+
}
|
67
|
+
else if (type == 3) {
|
68
|
+
[pimpl->currentTouchesSet.get() minusSet:uiTouches];
|
69
|
+
callback = &onTouchCancelled;
|
70
|
+
}
|
71
|
+
|
72
|
+
if (callback && *callback) {
|
73
|
+
for (UITouch *uiTouch in uiTouches) {
|
74
|
+
(*callback)(pimpl->translateTouch(uiTouch));
|
75
|
+
}
|
76
|
+
}
|
71
77
|
}
|
72
78
|
|
73
79
|
wchar_t Gosu::Input::idToChar(Button btn)
|
@@ -80,7 +86,7 @@ Gosu::Button Gosu::Input::charToId(wchar_t ch)
|
|
80
86
|
return noButton;
|
81
87
|
}
|
82
88
|
|
83
|
-
bool Gosu::Input::down(Button btn)
|
89
|
+
bool Gosu::Input::down(Button btn)
|
84
90
|
{
|
85
91
|
return false;
|
86
92
|
}
|
@@ -120,17 +126,17 @@ const Gosu::Touches& Gosu::Input::currentTouches() const
|
|
120
126
|
|
121
127
|
double Gosu::Input::accelerometerX() const
|
122
128
|
{
|
123
|
-
return
|
129
|
+
return 0;
|
124
130
|
}
|
125
131
|
|
126
132
|
double Gosu::Input::accelerometerY() const
|
127
133
|
{
|
128
|
-
return
|
134
|
+
return 0;
|
129
135
|
}
|
130
136
|
|
131
137
|
double Gosu::Input::accelerometerZ() const
|
132
138
|
{
|
133
|
-
return
|
139
|
+
return 0;
|
134
140
|
}
|
135
141
|
|
136
142
|
void Gosu::Input::update()
|
@@ -138,7 +144,7 @@ void Gosu::Input::update()
|
|
138
144
|
// Check for dead touches and remove from vector if
|
139
145
|
// necessary
|
140
146
|
|
141
|
-
|
147
|
+
ObjCRef<NSMutableSet> deadTouches;
|
142
148
|
|
143
149
|
for (UITouch* touch in pimpl->currentTouchesSet.obj())
|
144
150
|
{
|
data/src/Input/TextInput.cpp
CHANGED
data/src/Text/TextApple.mm
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
#include <Gosu/Bitmap.hpp>
|
7
7
|
#include <Gosu/Utility.hpp>
|
8
8
|
#include <Gosu/Math.hpp>
|
9
|
-
#include "../
|
9
|
+
#include "../AppleUtility.hpp"
|
10
10
|
#include <map>
|
11
11
|
#include <cmath>
|
12
12
|
using namespace std;
|
@@ -22,7 +22,7 @@ typedef NSFont OSXFont;
|
|
22
22
|
|
23
23
|
namespace
|
24
24
|
{
|
25
|
-
using Gosu::
|
25
|
+
using Gosu::ObjCRef;
|
26
26
|
using Gosu::CFRef;
|
27
27
|
|
28
28
|
// If a font is a filename, loads the font and returns its family name that can be used
|
@@ -81,7 +81,7 @@ namespace
|
|
81
81
|
OSXFont* result = usedFonts[make_pair(fontName, make_pair(fontFlags, height))];
|
82
82
|
if (!result)
|
83
83
|
{
|
84
|
-
|
84
|
+
ObjCRef<NSString> name([[NSString alloc] initWithUTF8String: Gosu::wstringToUTF8(fontName).c_str()]);
|
85
85
|
#ifdef GOSU_IS_IPHONE
|
86
86
|
result = [OSXFont fontWithName: name.obj() size: height];
|
87
87
|
#else
|
@@ -120,7 +120,7 @@ namespace
|
|
120
120
|
nil];
|
121
121
|
if (fontFlags & Gosu::ffUnderline)
|
122
122
|
{
|
123
|
-
Gosu::
|
123
|
+
Gosu::ObjCRef<NSNumber> underline([[NSNumber alloc] initWithInt:NSUnderlineStyleSingle]);
|
124
124
|
[dict setValue: underline.obj() forKey:NSUnderlineStyleAttributeName];
|
125
125
|
}
|
126
126
|
return dict;
|
@@ -138,9 +138,9 @@ unsigned Gosu::textWidth(const wstring& text,
|
|
138
138
|
|
139
139
|
// This will, of course, compute a too large size; fontHeight is in pixels,
|
140
140
|
// the method expects point.
|
141
|
-
|
141
|
+
ObjCRef<NSString> string([[NSString alloc] initWithUTF8String: wstringToUTF8(text).c_str()]);
|
142
142
|
#ifndef GOSU_IS_IPHONE
|
143
|
-
|
143
|
+
ObjCRef<NSDictionary> attributes(attributeDictionary(font, fontFlags));
|
144
144
|
NSSize size = [string.obj() sizeWithAttributes: attributes.get()];
|
145
145
|
#else
|
146
146
|
CGSize size = [string.obj() sizeWithFont: font];
|
@@ -158,11 +158,11 @@ void Gosu::drawText(Bitmap& bitmap, const wstring& text, int x, int y,
|
|
158
158
|
throw std::invalid_argument("the argument to drawText cannot contain line breaks");
|
159
159
|
|
160
160
|
OSXFont* font = getFont(fontName, fontFlags, fontHeight);
|
161
|
-
|
161
|
+
ObjCRef<NSString> string([[NSString alloc] initWithUTF8String: wstringToUTF8(text).c_str()]);
|
162
162
|
|
163
163
|
// This will, of course, compute a too large size; fontHeight is in pixels, the method expects point.
|
164
164
|
#ifndef GOSU_IS_IPHONE
|
165
|
-
|
165
|
+
ObjCRef<NSDictionary> attributes(attributeDictionary(font, fontFlags));
|
166
166
|
NSSize size = [string.obj() sizeWithAttributes: attributes.get()];
|
167
167
|
#else
|
168
168
|
CGSize size = [string.obj() sizeWithFont: font];
|
data/src/Text/TextMac.cpp
CHANGED
data/src/Text/TextUnix.cpp
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
#import "GosuAppDelegate.h"
|
2
|
+
#import <Gosu/Gosu.hpp>
|
3
|
+
|
4
|
+
|
5
|
+
@implementation GosuAppDelegate
|
6
|
+
|
7
|
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
8
|
+
{
|
9
|
+
self.window = (UIWindow *)windowInstance().UIWindow();
|
10
|
+
[self.window makeKeyAndVisible];
|
11
|
+
|
12
|
+
return YES;
|
13
|
+
}
|
14
|
+
|
15
|
+
@end
|
16
|
+
|
17
|
+
|
18
|
+
int main(int argc, char *argv[])
|
19
|
+
{
|
20
|
+
@autoreleasepool {
|
21
|
+
Gosu::useResourceDirectory();
|
22
|
+
return UIApplicationMain(argc, argv, nil, NSStringFromClass([GosuAppDelegate class]));
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#import "GosuGLView.h"
|
2
|
+
|
3
|
+
#import <QuartzCore/QuartzCore.h>
|
4
|
+
#import <OpenGLES/EAGLDrawable.h>
|
5
|
+
#import <OpenGLES/EAGL.h>
|
6
|
+
#import <OpenGLES/ES1/gl.h>
|
7
|
+
#import <OpenGLES/ES1/glext.h>
|
8
|
+
|
9
|
+
|
10
|
+
static EAGLContext __weak *globalContext;
|
11
|
+
|
12
|
+
|
13
|
+
namespace Gosu
|
14
|
+
{
|
15
|
+
void ensureCurrentContext()
|
16
|
+
{
|
17
|
+
[EAGLContext setCurrentContext:globalContext];
|
18
|
+
}
|
19
|
+
|
20
|
+
int clipRectBaseFactor()
|
21
|
+
{
|
22
|
+
static int result = [UIScreen mainScreen].scale;
|
23
|
+
return result;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
@implementation GosuGLView
|
29
|
+
{
|
30
|
+
EAGLContext *_context;
|
31
|
+
|
32
|
+
GLint _backingWidth;
|
33
|
+
GLint _backingHeight;
|
34
|
+
|
35
|
+
GLuint _viewRenderbuffer;
|
36
|
+
GLuint _viewFramebuffer;
|
37
|
+
}
|
38
|
+
|
39
|
+
+ (Class)layerClass
|
40
|
+
{
|
41
|
+
return [CAEAGLLayer class];
|
42
|
+
}
|
43
|
+
|
44
|
+
- (id)initWithFrame:(CGRect)frame
|
45
|
+
{
|
46
|
+
if ((self = [super initWithFrame:frame])) {
|
47
|
+
[self initializeGosuGLView];
|
48
|
+
}
|
49
|
+
|
50
|
+
return self;
|
51
|
+
}
|
52
|
+
|
53
|
+
- (id)initWithCoder:(NSCoder *)aDecoder
|
54
|
+
{
|
55
|
+
if ((self = [super initWithCoder:aDecoder])) {
|
56
|
+
[self initializeGosuGLView];
|
57
|
+
}
|
58
|
+
|
59
|
+
return self;
|
60
|
+
}
|
61
|
+
|
62
|
+
- (void)initializeGosuGLView
|
63
|
+
{
|
64
|
+
CAEAGLLayer *layer = (CAEAGLLayer *)self.layer;
|
65
|
+
layer.opaque = YES;
|
66
|
+
|
67
|
+
globalContext = _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
|
68
|
+
[EAGLContext setCurrentContext:_context];
|
69
|
+
|
70
|
+
self.exclusiveTouch = YES;
|
71
|
+
self.multipleTouchEnabled = YES;
|
72
|
+
}
|
73
|
+
|
74
|
+
- (void)dealloc
|
75
|
+
{
|
76
|
+
[EAGLContext setCurrentContext:nil];
|
77
|
+
[_context release];
|
78
|
+
[super dealloc];
|
79
|
+
}
|
80
|
+
|
81
|
+
- (void)redrawGL:(void (^)())code
|
82
|
+
{
|
83
|
+
[EAGLContext setCurrentContext:_context];
|
84
|
+
|
85
|
+
glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer);
|
86
|
+
|
87
|
+
glViewport(0, 0, _backingWidth, _backingHeight);
|
88
|
+
|
89
|
+
if (code) {
|
90
|
+
code();
|
91
|
+
}
|
92
|
+
|
93
|
+
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer);
|
94
|
+
|
95
|
+
[_context presentRenderbuffer:GL_RENDERBUFFER_OES];
|
96
|
+
}
|
97
|
+
|
98
|
+
- (void)layoutSubviews
|
99
|
+
{
|
100
|
+
[EAGLContext setCurrentContext:_context];
|
101
|
+
[self destroyFramebuffer];
|
102
|
+
self.contentScaleFactor = Gosu::clipRectBaseFactor();
|
103
|
+
[self createFramebuffer];
|
104
|
+
}
|
105
|
+
|
106
|
+
- (BOOL)createFramebuffer
|
107
|
+
{
|
108
|
+
glGenFramebuffersOES(1, &_viewFramebuffer);
|
109
|
+
glGenRenderbuffersOES(1, &_viewRenderbuffer);
|
110
|
+
|
111
|
+
glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer);
|
112
|
+
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer);
|
113
|
+
[_context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer *)self.layer];
|
114
|
+
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, _viewRenderbuffer);
|
115
|
+
|
116
|
+
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &_backingWidth);
|
117
|
+
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &_backingHeight);
|
118
|
+
|
119
|
+
return (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
|
120
|
+
}
|
121
|
+
|
122
|
+
- (void)destroyFramebuffer
|
123
|
+
{
|
124
|
+
glDeleteFramebuffersOES(1, &_viewFramebuffer);
|
125
|
+
_viewFramebuffer = 0;
|
126
|
+
glDeleteRenderbuffersOES(1, &_viewRenderbuffer);
|
127
|
+
_viewRenderbuffer = 0;
|
128
|
+
}
|
129
|
+
|
130
|
+
@end
|