gosu 0.10.9.pre1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gosu/Audio.hpp +35 -66
- data/Gosu/AutoLink.hpp +14 -16
- data/Gosu/Bitmap.hpp +50 -37
- data/Gosu/Buttons.hpp +246 -265
- data/Gosu/Color.hpp +32 -76
- data/Gosu/Directories.hpp +14 -17
- data/Gosu/Font.hpp +28 -34
- data/Gosu/Fwd.hpp +27 -31
- data/Gosu/Gosu.hpp +2 -5
- data/Gosu/Graphics.hpp +31 -48
- data/Gosu/GraphicsBase.hpp +27 -58
- data/Gosu/IO.hpp +44 -56
- data/Gosu/Image.hpp +29 -73
- data/Gosu/ImageData.hpp +13 -17
- data/Gosu/Input.hpp +42 -57
- data/Gosu/Inspection.hpp +2 -6
- data/Gosu/Math.hpp +32 -38
- data/Gosu/Platform.hpp +10 -29
- data/Gosu/Text.hpp +30 -39
- data/Gosu/TextInput.hpp +29 -36
- data/Gosu/Timing.hpp +14 -16
- data/Gosu/Utility.hpp +10 -15
- data/Gosu/Version.hpp +13 -14
- data/Gosu/Window.hpp +53 -68
- data/README.md +23 -11
- data/ext/gosu/extconf.rb +31 -81
- data/lib/gosu/patches.rb +35 -19
- data/lib/gosu/run.rb +13 -4
- data/rdoc/gosu.rb +24 -20
- data/src/ALChannelManagement.hpp +119 -0
- data/src/{Audio/Audio.cpp → Audio.cpp} +177 -211
- data/src/AudioFile.hpp +57 -0
- data/src/AudioToolboxFile.hpp +214 -0
- data/src/Bitmap.cpp +159 -0
- data/src/BitmapIO.cpp +141 -0
- data/src/BlockAllocator.cpp +133 -0
- data/src/{Graphics/BlockAllocator.hpp → BlockAllocator.hpp} +34 -35
- data/src/ClipRectStack.hpp +87 -0
- data/src/{Graphics/Color.cpp → Color.cpp} +30 -28
- data/src/DirectoriesApple.cpp +68 -0
- data/src/DirectoriesUnix.cpp +20 -18
- data/src/DirectoriesWin.cpp +40 -41
- data/src/DrawOp.hpp +168 -0
- data/src/DrawOpQueue.hpp +190 -0
- data/src/FileUnix.cpp +40 -46
- data/src/FileWin.cpp +42 -38
- data/src/Font.cpp +165 -0
- data/src/{Text/FormattedString.hpp → FormattedString.hpp} +114 -114
- data/src/GosuAppDelegate.cpp +30 -0
- data/src/{UIKit/GosuAppDelegate.h → GosuAppDelegate.h} +0 -0
- data/src/{UIKit/GosuGLView.mm → GosuGLView.cpp} +22 -17
- data/src/{UIKit/GosuGLView.h → GosuGLView.h} +0 -0
- data/src/GosuViewController.cpp +231 -0
- data/src/{UIKit/GosuViewController.h → GosuViewController.h} +0 -0
- data/src/Graphics.cpp +464 -0
- data/src/{Graphics/Common.hpp → GraphicsImpl.hpp} +29 -32
- data/src/IO.cpp +17 -16
- data/src/Iconv.hpp +13 -22
- data/src/Image.cpp +142 -0
- data/src/Input.cpp +459 -0
- data/src/InputUIKit.cpp +197 -0
- data/src/Inspection.cpp +4 -5
- data/src/LargeImageData.cpp +151 -0
- data/src/LargeImageData.hpp +43 -0
- data/src/{Graphics/Macro.cpp → Macro.cpp} +77 -78
- data/src/Macro.hpp +30 -0
- data/src/Math.cpp +17 -29
- data/src/{Audio/OggFile.hpp → OggFile.hpp} +19 -24
- data/src/RenderState.hpp +205 -0
- data/src/Resolution.cpp +86 -0
- data/src/ResolutionApple.cpp +25 -0
- data/{ext/gosu/gosu_wrap.cxx → src/RubyGosu.cxx} +2256 -1707
- data/{ext/gosu/gosu_wrap.h → src/RubyGosu.h} +9 -9
- data/src/{Audio/SndFile.hpp → SndFile.hpp} +54 -43
- data/src/TexChunk.cpp +117 -0
- data/src/{Graphics/TexChunk.hpp → TexChunk.hpp} +13 -18
- data/src/Text.cpp +371 -0
- data/src/TextApple.cpp +209 -0
- data/src/TextInput.cpp +278 -0
- data/src/TextTTFWin.cpp +251 -0
- data/src/{Text/TextUnix.cpp → TextUnix.cpp} +96 -92
- data/src/TextWin.cpp +194 -0
- data/src/{Graphics/Texture.cpp → Texture.cpp} +35 -38
- data/src/{Graphics/Texture.hpp → Texture.hpp} +9 -13
- data/src/TimingApple.cpp +11 -7
- data/src/TimingUnix.cpp +13 -7
- data/src/TimingWin.cpp +6 -1
- data/src/{Graphics/Transform.cpp → Transform.cpp} +17 -12
- data/src/{Graphics/TransformStack.hpp → TransformStack.hpp} +24 -25
- data/src/Utility.cpp +29 -70
- data/src/UtilityApple.cpp +52 -0
- data/src/UtilityWin.cpp +7 -4
- data/src/Version.cpp +22 -0
- data/src/WinMain.cpp +30 -33
- data/src/WinUtility.cpp +24 -22
- data/src/WinUtility.hpp +11 -20
- data/src/Window.cpp +142 -112
- data/src/WindowUIKit.cpp +155 -0
- data/src/stb_image.h +384 -173
- data/src/stb_vorbis.c +20 -18
- metadata +60 -62
- data/Gosu/TR1.hpp +0 -56
- data/src/AppleUtility.hpp +0 -66
- data/src/Audio/ALChannelManagement.hpp +0 -114
- data/src/Audio/Audio.mm +0 -1
- data/src/Audio/AudioFile.hpp +0 -53
- data/src/Audio/AudioToolboxFile.hpp +0 -207
- data/src/Bitmap/Bitmap.cpp +0 -183
- data/src/Bitmap/BitmapIO.cpp +0 -176
- data/src/DirectoriesApple.mm +0 -71
- data/src/Graphics/BlockAllocator.cpp +0 -142
- data/src/Graphics/ClipRectStack.hpp +0 -93
- data/src/Graphics/DrawOp.hpp +0 -175
- data/src/Graphics/DrawOpQueue.hpp +0 -188
- data/src/Graphics/Graphics.cpp +0 -478
- data/src/Graphics/Image.cpp +0 -193
- data/src/Graphics/LargeImageData.cpp +0 -133
- data/src/Graphics/LargeImageData.hpp +0 -46
- data/src/Graphics/Macro.hpp +0 -36
- data/src/Graphics/RenderState.hpp +0 -211
- data/src/Graphics/Resolution.cpp +0 -91
- data/src/Graphics/ResolutionApple.mm +0 -19
- data/src/Graphics/TexChunk.cpp +0 -112
- data/src/Input/Input.cpp +0 -463
- data/src/Input/InputUIKit.mm +0 -190
- data/src/Input/TextInput.cpp +0 -261
- data/src/Text/Font.cpp +0 -175
- data/src/Text/Text.cpp +0 -391
- data/src/Text/TextApple.mm +0 -227
- data/src/Text/TextTTFWin.cpp +0 -249
- data/src/Text/TextWin.cpp +0 -186
- data/src/UIKit/GosuAppDelegate.mm +0 -24
- data/src/UIKit/GosuViewController.mm +0 -211
- data/src/UtilityApple.mm +0 -63
- data/src/WindowUIKit.mm +0 -139
@@ -1,188 +0,0 @@
|
|
1
|
-
#ifndef GOSU_SRC_GRAPHICS_DRAWOPQUEUE_HPP
|
2
|
-
#define GOSU_SRC_GRAPHICS_DRAWOPQUEUE_HPP
|
3
|
-
|
4
|
-
#include <Gosu/TR1.hpp>
|
5
|
-
#include "Common.hpp"
|
6
|
-
#include "TransformStack.hpp"
|
7
|
-
#include "ClipRectStack.hpp"
|
8
|
-
#include "DrawOp.hpp"
|
9
|
-
#include <cassert>
|
10
|
-
#include <algorithm>
|
11
|
-
#include <map>
|
12
|
-
#include <vector>
|
13
|
-
#include <cmath>
|
14
|
-
|
15
|
-
class Gosu::DrawOpQueue
|
16
|
-
{
|
17
|
-
TransformStack transformStack;
|
18
|
-
ClipRectStack clipRectStack;
|
19
|
-
bool rec;
|
20
|
-
|
21
|
-
typedef std::vector<DrawOp> DrawOps;
|
22
|
-
DrawOps ops;
|
23
|
-
typedef std::vector<std::tr1::function<void()> > GLBlocks;
|
24
|
-
GLBlocks glBlocks;
|
25
|
-
|
26
|
-
public:
|
27
|
-
DrawOpQueue()
|
28
|
-
: rec(false)
|
29
|
-
{
|
30
|
-
}
|
31
|
-
|
32
|
-
bool recording() const
|
33
|
-
{
|
34
|
-
return rec;
|
35
|
-
}
|
36
|
-
|
37
|
-
void setRecording()
|
38
|
-
{
|
39
|
-
rec = true;
|
40
|
-
}
|
41
|
-
|
42
|
-
void scheduleDrawOp(DrawOp op)
|
43
|
-
{
|
44
|
-
if (clipRectStack.clippedWorldAway())
|
45
|
-
return;
|
46
|
-
|
47
|
-
#ifdef GOSU_IS_OPENGLES
|
48
|
-
// No triangles, no lines supported
|
49
|
-
assert (op.verticesOrBlockIndex == 4);
|
50
|
-
#endif
|
51
|
-
|
52
|
-
op.renderState.transform = &transformStack.current();
|
53
|
-
if (const ClipRect* cr = clipRectStack.maybeEffectiveRect())
|
54
|
-
op.renderState.clipRect = *cr;
|
55
|
-
ops.push_back(op);
|
56
|
-
}
|
57
|
-
|
58
|
-
void scheduleGL(std::tr1::function<void()> glBlock, ZPos z)
|
59
|
-
{
|
60
|
-
// TODO: Document this case: Clipped-away GL blocks are *not* being run.
|
61
|
-
if (clipRectStack.clippedWorldAway())
|
62
|
-
return;
|
63
|
-
|
64
|
-
int complementOfBlockIndex = ~(int)glBlocks.size();
|
65
|
-
glBlocks.push_back(glBlock);
|
66
|
-
|
67
|
-
DrawOp op;
|
68
|
-
op.verticesOrBlockIndex = complementOfBlockIndex;
|
69
|
-
op.renderState.transform = &transformStack.current();
|
70
|
-
if (const ClipRect* cr = clipRectStack.maybeEffectiveRect())
|
71
|
-
op.renderState.clipRect = *cr;
|
72
|
-
op.z = z;
|
73
|
-
ops.push_back(op);
|
74
|
-
}
|
75
|
-
|
76
|
-
void beginClipping(double x, double y, double width, double height, double screenHeight)
|
77
|
-
{
|
78
|
-
if (recording())
|
79
|
-
throw std::logic_error("Clipping is not allowed while creating a macro yet");
|
80
|
-
|
81
|
-
// Apply current transformation.
|
82
|
-
|
83
|
-
double left = x, right = x + width;
|
84
|
-
double top = y, bottom = y + height;
|
85
|
-
|
86
|
-
applyTransform(transformStack.current(), left, top);
|
87
|
-
applyTransform(transformStack.current(), right, bottom);
|
88
|
-
|
89
|
-
double physX = std::min(left, right);
|
90
|
-
double physY = std::min(top, bottom);
|
91
|
-
double physWidth = std::abs(left - right);
|
92
|
-
double physHeight = std::abs(top - bottom);
|
93
|
-
|
94
|
-
// Adjust for OpenGL having the wrong idea of where y=0 is.
|
95
|
-
physY = screenHeight - physY - physHeight;
|
96
|
-
|
97
|
-
clipRectStack.beginClipping(physX, physY, physWidth, physHeight);
|
98
|
-
}
|
99
|
-
|
100
|
-
void endClipping()
|
101
|
-
{
|
102
|
-
clipRectStack.endClipping();
|
103
|
-
}
|
104
|
-
|
105
|
-
void setBaseTransform(const Transform& baseTransform)
|
106
|
-
{
|
107
|
-
transformStack.setBaseTransform(baseTransform);
|
108
|
-
}
|
109
|
-
|
110
|
-
void pushTransform(const Transform& transform)
|
111
|
-
{
|
112
|
-
transformStack.push(transform);
|
113
|
-
}
|
114
|
-
|
115
|
-
void popTransform()
|
116
|
-
{
|
117
|
-
transformStack.pop();
|
118
|
-
}
|
119
|
-
|
120
|
-
void performDrawOpsAndCode()
|
121
|
-
{
|
122
|
-
if (recording())
|
123
|
-
throw std::logic_error("Flushing to the screen is not allowed while recording a macro");
|
124
|
-
|
125
|
-
// Apply Z-Ordering.
|
126
|
-
std::stable_sort(ops.begin(), ops.end());
|
127
|
-
|
128
|
-
RenderStateManager manager;
|
129
|
-
#ifdef GOSU_IS_OPENGLES
|
130
|
-
if (ops.empty())
|
131
|
-
return;
|
132
|
-
|
133
|
-
DrawOps::const_iterator current = ops.begin(), last = ops.end() - 1;
|
134
|
-
for (; current != last; ++current)
|
135
|
-
{
|
136
|
-
manager.setRenderState(current->renderState);
|
137
|
-
current->perform(&*(current + 1));
|
138
|
-
}
|
139
|
-
manager.setRenderState(last->renderState);
|
140
|
-
last->perform(0);
|
141
|
-
#else
|
142
|
-
for (DrawOps::const_iterator current = ops.begin(), last = ops.end();
|
143
|
-
current != last; ++current)
|
144
|
-
{
|
145
|
-
manager.setRenderState(current->renderState);
|
146
|
-
if (current->verticesOrBlockIndex >= 0)
|
147
|
-
current->perform(0);
|
148
|
-
else
|
149
|
-
{
|
150
|
-
// GL code
|
151
|
-
int blockIndex = ~current->verticesOrBlockIndex;
|
152
|
-
assert (blockIndex >= 0);
|
153
|
-
assert (blockIndex < glBlocks.size());
|
154
|
-
glBlocks[blockIndex]();
|
155
|
-
manager.enforceAfterUntrustedGL();
|
156
|
-
}
|
157
|
-
}
|
158
|
-
#endif
|
159
|
-
}
|
160
|
-
|
161
|
-
void compileTo(VertexArrays& vas)
|
162
|
-
{
|
163
|
-
if (!glBlocks.empty())
|
164
|
-
throw std::logic_error("Custom OpenGL code cannot be recorded as a macro");
|
165
|
-
|
166
|
-
std::stable_sort(ops.begin(), ops.end());
|
167
|
-
for (DrawOps::const_iterator op = ops.begin(), end = ops.end(); op != end; ++op)
|
168
|
-
op->compileTo(vas);
|
169
|
-
}
|
170
|
-
|
171
|
-
// This retains the current stack of transforms and clippings.
|
172
|
-
void clearQueue()
|
173
|
-
{
|
174
|
-
glBlocks.clear();
|
175
|
-
ops.clear();
|
176
|
-
}
|
177
|
-
|
178
|
-
// This clears the queue and starts with new stacks. This must not be called
|
179
|
-
// when endClipping/popTransform calls might still be pending.
|
180
|
-
void reset()
|
181
|
-
{
|
182
|
-
transformStack.reset();
|
183
|
-
clipRectStack.clear();
|
184
|
-
clearQueue();
|
185
|
-
}
|
186
|
-
};
|
187
|
-
|
188
|
-
#endif
|
data/src/Graphics/Graphics.cpp
DELETED
@@ -1,478 +0,0 @@
|
|
1
|
-
#include <Gosu/Graphics.hpp>
|
2
|
-
#include "Common.hpp"
|
3
|
-
#include "DrawOp.hpp"
|
4
|
-
#include "DrawOpQueue.hpp"
|
5
|
-
#include "Texture.hpp"
|
6
|
-
#include "TexChunk.hpp"
|
7
|
-
#include "LargeImageData.hpp"
|
8
|
-
#include "Macro.hpp"
|
9
|
-
#include <Gosu/Bitmap.hpp>
|
10
|
-
#include <Gosu/Image.hpp>
|
11
|
-
#include <Gosu/Platform.hpp>
|
12
|
-
#include <cmath>
|
13
|
-
#include <algorithm>
|
14
|
-
#include <limits>
|
15
|
-
|
16
|
-
namespace Gosu
|
17
|
-
{
|
18
|
-
namespace
|
19
|
-
{
|
20
|
-
Graphics* currentGraphicsPointer = 0;
|
21
|
-
|
22
|
-
Graphics& currentGraphics()
|
23
|
-
{
|
24
|
-
if (currentGraphicsPointer == 0)
|
25
|
-
throw std::logic_error("Gosu::Graphics can only be drawn to while rendering");
|
26
|
-
|
27
|
-
return *currentGraphicsPointer;
|
28
|
-
}
|
29
|
-
|
30
|
-
typedef std::vector<std::tr1::shared_ptr<Texture> > Textures;
|
31
|
-
Textures textures;
|
32
|
-
|
33
|
-
DrawOpQueueStack queues;
|
34
|
-
|
35
|
-
DrawOpQueue& currentQueue()
|
36
|
-
{
|
37
|
-
if (queues.empty())
|
38
|
-
throw std::logic_error("There is no rendering queue for this operation");
|
39
|
-
return queues.back();
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
struct Gosu::Graphics::Impl
|
45
|
-
{
|
46
|
-
unsigned virtWidth, virtHeight;
|
47
|
-
unsigned physWidth, physHeight;
|
48
|
-
double blackWidth, blackHeight;
|
49
|
-
bool fullscreen;
|
50
|
-
Transform baseTransform;
|
51
|
-
|
52
|
-
DrawOpQueueStack warmedUpQueues;
|
53
|
-
|
54
|
-
void updateBaseTransform()
|
55
|
-
{
|
56
|
-
double scaleX = 1.0 * physWidth / virtWidth;
|
57
|
-
double scaleY = 1.0 * physHeight / virtHeight;
|
58
|
-
double scaleFactor = std::min(scaleX, scaleY);
|
59
|
-
|
60
|
-
Transform scaleTransform = scale(scaleFactor);
|
61
|
-
Transform translateTransform = translate(blackWidth, blackHeight);
|
62
|
-
baseTransform = concat(translateTransform, scaleTransform);
|
63
|
-
}
|
64
|
-
};
|
65
|
-
|
66
|
-
Gosu::Graphics::Graphics(unsigned physWidth, unsigned physHeight, bool fullscreen)
|
67
|
-
: pimpl(new Impl)
|
68
|
-
{
|
69
|
-
pimpl->virtWidth = physWidth;
|
70
|
-
pimpl->virtHeight = physHeight;
|
71
|
-
pimpl->fullscreen = fullscreen;
|
72
|
-
pimpl->blackWidth = 0;
|
73
|
-
pimpl->blackHeight = 0;
|
74
|
-
|
75
|
-
// TODO: Should be merged into RenderState and removed from Graphics.
|
76
|
-
glMatrixMode(GL_MODELVIEW);
|
77
|
-
glLoadIdentity();
|
78
|
-
glEnable(GL_BLEND);
|
79
|
-
|
80
|
-
setPhysicalResolution(physWidth, physHeight);
|
81
|
-
}
|
82
|
-
|
83
|
-
Gosu::Graphics::~Graphics()
|
84
|
-
{
|
85
|
-
if (currentGraphicsPointer == this)
|
86
|
-
currentGraphicsPointer = 0;
|
87
|
-
}
|
88
|
-
|
89
|
-
unsigned Gosu::Graphics::width() const
|
90
|
-
{
|
91
|
-
return pimpl->virtWidth;
|
92
|
-
}
|
93
|
-
|
94
|
-
unsigned Gosu::Graphics::height() const
|
95
|
-
{
|
96
|
-
return pimpl->virtHeight;
|
97
|
-
}
|
98
|
-
|
99
|
-
bool Gosu::Graphics::fullscreen() const
|
100
|
-
{
|
101
|
-
return pimpl->fullscreen;
|
102
|
-
}
|
103
|
-
|
104
|
-
void Gosu::Graphics::setResolution(unsigned virtualWidth, unsigned virtualHeight,
|
105
|
-
double horizontalBlackBarWidth, double verticalBlackBarHeight)
|
106
|
-
{
|
107
|
-
if (virtualWidth == 0 || virtualHeight == 0)
|
108
|
-
throw std::invalid_argument("Invalid virtual resolution.");
|
109
|
-
|
110
|
-
pimpl->virtWidth = virtualWidth;
|
111
|
-
pimpl->virtHeight = virtualHeight;
|
112
|
-
pimpl->blackWidth = horizontalBlackBarWidth;
|
113
|
-
pimpl->blackHeight = verticalBlackBarHeight;
|
114
|
-
|
115
|
-
pimpl->updateBaseTransform();
|
116
|
-
}
|
117
|
-
|
118
|
-
bool Gosu::Graphics::begin(Gosu::Color clearWithColor)
|
119
|
-
{
|
120
|
-
if (currentGraphicsPointer != 0)
|
121
|
-
throw std::logic_error("Cannot nest calls to Gosu::Graphics::begin()");
|
122
|
-
|
123
|
-
// Cancel all recording or whatever that might still be in progress...
|
124
|
-
queues.clear();
|
125
|
-
|
126
|
-
if (pimpl->warmedUpQueues.size() == 1)
|
127
|
-
{
|
128
|
-
// If we already have a "warmed up" queue, use that instead.
|
129
|
-
// -> All internals std::vectors will already have a lot of capacity.
|
130
|
-
// This helps reduce allocations during normal operation.
|
131
|
-
queues.clear();
|
132
|
-
queues.swap(pimpl->warmedUpQueues);
|
133
|
-
}
|
134
|
-
else
|
135
|
-
{
|
136
|
-
// Create default draw-op queue.
|
137
|
-
queues.resize(1);
|
138
|
-
}
|
139
|
-
|
140
|
-
queues.back().setBaseTransform(pimpl->baseTransform);
|
141
|
-
|
142
|
-
glClearColor(clearWithColor.red() / 255.f, clearWithColor.green() / 255.f,
|
143
|
-
clearWithColor.blue() / 255.f, clearWithColor.alpha() / 255.f);
|
144
|
-
glClear(GL_COLOR_BUFFER_BIT);
|
145
|
-
|
146
|
-
currentGraphicsPointer = this;
|
147
|
-
|
148
|
-
return true;
|
149
|
-
}
|
150
|
-
|
151
|
-
void Gosu::Graphics::end()
|
152
|
-
{
|
153
|
-
// If recording is in process, cancel it.
|
154
|
-
while (currentQueue().recording()) {
|
155
|
-
queues.pop_back();
|
156
|
-
}
|
157
|
-
|
158
|
-
flush();
|
159
|
-
|
160
|
-
if (pimpl->blackHeight || pimpl->blackWidth) {
|
161
|
-
if (pimpl->blackHeight) {
|
162
|
-
drawQuad(0, -pimpl->blackHeight, Color::BLACK,
|
163
|
-
width(), -pimpl->blackHeight, Color::BLACK,
|
164
|
-
0, 0, Color::BLACK,
|
165
|
-
width(), 0, Color::BLACK, 0);
|
166
|
-
drawQuad(0, height(), Color::BLACK,
|
167
|
-
width(), height(), Color::BLACK,
|
168
|
-
0, height() + pimpl->blackHeight, Color::BLACK,
|
169
|
-
width(), height() + pimpl->blackHeight, Color::BLACK, 0);
|
170
|
-
}
|
171
|
-
else if (pimpl->blackWidth) {
|
172
|
-
drawQuad(-pimpl->blackWidth, 0, Color::BLACK,
|
173
|
-
0, 0, Color::BLACK,
|
174
|
-
-pimpl->blackWidth, height(), Color::BLACK,
|
175
|
-
0, height(), Color::BLACK, 0);
|
176
|
-
drawQuad(width(), 0, Color::BLACK,
|
177
|
-
width() + pimpl->blackWidth, 0, Color::BLACK,
|
178
|
-
width(), height(), Color::BLACK,
|
179
|
-
width() + pimpl->blackWidth, height(), Color::BLACK, 0);
|
180
|
-
}
|
181
|
-
flush();
|
182
|
-
}
|
183
|
-
|
184
|
-
glFlush();
|
185
|
-
|
186
|
-
currentGraphicsPointer = 0;
|
187
|
-
|
188
|
-
// Clear leftover transforms, clip rects etc.
|
189
|
-
if (queues.size() == 1)
|
190
|
-
{
|
191
|
-
queues.swap(pimpl->warmedUpQueues);
|
192
|
-
pimpl->warmedUpQueues.back().reset();
|
193
|
-
}
|
194
|
-
else
|
195
|
-
{
|
196
|
-
queues.clear();
|
197
|
-
}
|
198
|
-
}
|
199
|
-
|
200
|
-
void Gosu::Graphics::flush()
|
201
|
-
{
|
202
|
-
currentQueue().performDrawOpsAndCode();
|
203
|
-
currentQueue().clearQueue();
|
204
|
-
}
|
205
|
-
|
206
|
-
void Gosu::Graphics::beginGL()
|
207
|
-
{
|
208
|
-
if (currentQueue().recording())
|
209
|
-
throw std::logic_error("Custom OpenGL is not allowed while creating a macro");
|
210
|
-
|
211
|
-
#ifdef GOSU_IS_OPENGLES
|
212
|
-
throw std::logic_error("Custom OpenGL ES is not supported yet");
|
213
|
-
#else
|
214
|
-
flush();
|
215
|
-
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
216
|
-
glDisable(GL_BLEND);
|
217
|
-
while (glGetError() != GL_NO_ERROR);
|
218
|
-
#endif
|
219
|
-
}
|
220
|
-
|
221
|
-
void Gosu::Graphics::endGL()
|
222
|
-
{
|
223
|
-
#ifdef GOSU_IS_OPENGLES
|
224
|
-
throw std::logic_error("Custom OpenGL ES is not supported yet");
|
225
|
-
#else
|
226
|
-
Graphics& cg = currentGraphics();
|
227
|
-
|
228
|
-
glPopAttrib();
|
229
|
-
|
230
|
-
// Restore matrices.
|
231
|
-
// TODO: Should be merged into RenderState and removed from Graphics.
|
232
|
-
|
233
|
-
glMatrixMode(GL_PROJECTION);
|
234
|
-
glLoadIdentity();
|
235
|
-
glViewport(0, 0, cg.pimpl->physWidth, cg.pimpl->physHeight);
|
236
|
-
glOrtho(0, cg.pimpl->physWidth, cg.pimpl->physHeight, 0, -1, 1);
|
237
|
-
|
238
|
-
glMatrixMode(GL_MODELVIEW);
|
239
|
-
glLoadIdentity();
|
240
|
-
glEnable(GL_BLEND);
|
241
|
-
#endif
|
242
|
-
}
|
243
|
-
|
244
|
-
#ifdef GOSU_IS_OPENGLES
|
245
|
-
void Gosu::Graphics::scheduleGL(const std::tr1::function<void()>& functor, Gosu::ZPos z)
|
246
|
-
{
|
247
|
-
throw std::logic_error("Custom OpenGL ES is not supported yet");
|
248
|
-
}
|
249
|
-
#else
|
250
|
-
namespace Gosu
|
251
|
-
{
|
252
|
-
struct RunGLFunctor
|
253
|
-
{
|
254
|
-
Graphics& graphics;
|
255
|
-
std::tr1::function<void()> functor;
|
256
|
-
|
257
|
-
RunGLFunctor(Graphics& graphics, const std::tr1::function<void()>& functor)
|
258
|
-
: graphics(graphics), functor(functor)
|
259
|
-
{
|
260
|
-
}
|
261
|
-
|
262
|
-
void operator()() const
|
263
|
-
{
|
264
|
-
// Inlined beginGL() to avoid flushing.
|
265
|
-
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
266
|
-
glDisable(GL_BLEND);
|
267
|
-
while (glGetError() != GL_NO_ERROR);
|
268
|
-
|
269
|
-
functor();
|
270
|
-
|
271
|
-
graphics.endGL();
|
272
|
-
}
|
273
|
-
};
|
274
|
-
}
|
275
|
-
|
276
|
-
void Gosu::Graphics::scheduleGL(const std::tr1::function<void()>& functor, Gosu::ZPos z)
|
277
|
-
{
|
278
|
-
currentQueue().scheduleGL(RunGLFunctor(currentGraphics(), functor), z);
|
279
|
-
}
|
280
|
-
#endif
|
281
|
-
|
282
|
-
void Gosu::Graphics::beginClipping(double x, double y, double width, double height)
|
283
|
-
{
|
284
|
-
double screenHeight = currentGraphics().pimpl->physHeight;
|
285
|
-
currentQueue().beginClipping(x, y, width, height, screenHeight);
|
286
|
-
}
|
287
|
-
|
288
|
-
void Gosu::Graphics::endClipping()
|
289
|
-
{
|
290
|
-
currentQueue().endClipping();
|
291
|
-
}
|
292
|
-
|
293
|
-
void Gosu::Graphics::beginRecording()
|
294
|
-
{
|
295
|
-
queues.resize(queues.size() + 1);
|
296
|
-
currentQueue().setRecording();
|
297
|
-
}
|
298
|
-
|
299
|
-
GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::endRecording(int width, int height)
|
300
|
-
{
|
301
|
-
if (! currentQueue().recording())
|
302
|
-
throw std::logic_error("No macro recording in progress that can be captured");
|
303
|
-
|
304
|
-
GOSU_UNIQUE_PTR<ImageData> result(new Macro(currentQueue(), width, height));
|
305
|
-
queues.pop_back();
|
306
|
-
return result;
|
307
|
-
}
|
308
|
-
|
309
|
-
void Gosu::Graphics::pushTransform(const Gosu::Transform& transform)
|
310
|
-
{
|
311
|
-
currentQueue().pushTransform(transform);
|
312
|
-
}
|
313
|
-
|
314
|
-
void Gosu::Graphics::popTransform()
|
315
|
-
{
|
316
|
-
currentQueue().popTransform();
|
317
|
-
}
|
318
|
-
|
319
|
-
void Gosu::Graphics::drawLine(double x1, double y1, Color c1,
|
320
|
-
double x2, double y2, Color c2, ZPos z, AlphaMode mode)
|
321
|
-
{
|
322
|
-
DrawOp op;
|
323
|
-
op.renderState.mode = mode;
|
324
|
-
op.verticesOrBlockIndex = 2;
|
325
|
-
op.vertices[0] = DrawOp::Vertex(x1, y1, c1);
|
326
|
-
op.vertices[1] = DrawOp::Vertex(x2, y2, c2);
|
327
|
-
op.z = z;
|
328
|
-
|
329
|
-
currentQueue().scheduleDrawOp(op);
|
330
|
-
}
|
331
|
-
|
332
|
-
void Gosu::Graphics::drawTriangle(double x1, double y1, Color c1,
|
333
|
-
double x2, double y2, Color c2, double x3, double y3, Color c3,
|
334
|
-
ZPos z, AlphaMode mode)
|
335
|
-
{
|
336
|
-
DrawOp op;
|
337
|
-
op.renderState.mode = mode;
|
338
|
-
op.verticesOrBlockIndex = 3;
|
339
|
-
op.vertices[0] = DrawOp::Vertex(x1, y1, c1);
|
340
|
-
op.vertices[1] = DrawOp::Vertex(x2, y2, c2);
|
341
|
-
op.vertices[2] = DrawOp::Vertex(x3, y3, c3);
|
342
|
-
#ifdef GOSU_IS_OPENGLES
|
343
|
-
op.verticesOrBlockIndex = 4;
|
344
|
-
op.vertices[3] = op.vertices[2];
|
345
|
-
#endif
|
346
|
-
op.z = z;
|
347
|
-
|
348
|
-
currentQueue().scheduleDrawOp(op);
|
349
|
-
}
|
350
|
-
|
351
|
-
void Gosu::Graphics::drawQuad(double x1, double y1, Color c1,
|
352
|
-
double x2, double y2, Color c2, double x3, double y3, Color c3,
|
353
|
-
double x4, double y4, Color c4, ZPos z, AlphaMode mode)
|
354
|
-
{
|
355
|
-
reorderCoordinatesIfNecessary(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
|
356
|
-
|
357
|
-
DrawOp op;
|
358
|
-
op.renderState.mode = mode;
|
359
|
-
op.verticesOrBlockIndex = 4;
|
360
|
-
op.vertices[0] = DrawOp::Vertex(x1, y1, c1);
|
361
|
-
op.vertices[1] = DrawOp::Vertex(x2, y2, c2);
|
362
|
-
// TODO: Should be harmonized
|
363
|
-
#ifdef GOSU_IS_OPENGLES
|
364
|
-
op.vertices[2] = DrawOp::Vertex(x3, y3, c3);
|
365
|
-
op.vertices[3] = DrawOp::Vertex(x4, y4, c4);
|
366
|
-
#else
|
367
|
-
op.vertices[3] = DrawOp::Vertex(x3, y3, c3);
|
368
|
-
op.vertices[2] = DrawOp::Vertex(x4, y4, c4);
|
369
|
-
#endif
|
370
|
-
op.z = z;
|
371
|
-
|
372
|
-
currentQueue().scheduleDrawOp(op);
|
373
|
-
}
|
374
|
-
|
375
|
-
void Gosu::Graphics::scheduleDrawOp(const Gosu::DrawOp &op)
|
376
|
-
{
|
377
|
-
currentQueue().scheduleDrawOp(op);
|
378
|
-
}
|
379
|
-
|
380
|
-
void Gosu::Graphics::setPhysicalResolution(unsigned physWidth, unsigned physHeight)
|
381
|
-
{
|
382
|
-
pimpl->physWidth = physWidth;
|
383
|
-
pimpl->physHeight = physHeight;
|
384
|
-
// TODO: Should be merged into RenderState and removed from Graphics.
|
385
|
-
glMatrixMode(GL_PROJECTION);
|
386
|
-
glLoadIdentity();
|
387
|
-
glViewport(0, 0, physWidth, physHeight);
|
388
|
-
#ifdef GOSU_IS_OPENGLES
|
389
|
-
glOrthof(0, physWidth, physHeight, 0, -1, 1);
|
390
|
-
#else
|
391
|
-
glOrtho(0, physWidth, physHeight, 0, -1, 1);
|
392
|
-
#endif
|
393
|
-
|
394
|
-
pimpl->updateBaseTransform();
|
395
|
-
}
|
396
|
-
|
397
|
-
GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::createImage(
|
398
|
-
const Bitmap& src, unsigned srcX, unsigned srcY,
|
399
|
-
unsigned srcWidth, unsigned srcHeight, unsigned flags)
|
400
|
-
{
|
401
|
-
static const unsigned maxSize = MAX_TEXTURE_SIZE;
|
402
|
-
|
403
|
-
// Backwards compatibility: This used to be 'bool tileable'.
|
404
|
-
if (flags == 1)
|
405
|
-
flags = ifTileable;
|
406
|
-
|
407
|
-
bool wantsRetro = (flags & ifRetro);
|
408
|
-
|
409
|
-
// Special case: If the texture is supposed to have hard borders, is
|
410
|
-
// quadratic, has a size that is at least 64 pixels but no more than maxSize
|
411
|
-
// pixels and a power of two, create a single texture just for this image.
|
412
|
-
if ((flags & ifTileable) == ifTileable &&
|
413
|
-
srcWidth == srcHeight &&
|
414
|
-
(srcWidth & (srcWidth - 1)) == 0 &&
|
415
|
-
srcWidth >= 64 && srcWidth <= maxSize)
|
416
|
-
{
|
417
|
-
std::tr1::shared_ptr<Texture> texture(new Texture(srcWidth, wantsRetro));
|
418
|
-
GOSU_UNIQUE_PTR<ImageData> data;
|
419
|
-
|
420
|
-
// Use the source bitmap directly if the source area completely covers
|
421
|
-
// it.
|
422
|
-
if (srcX == 0 && srcWidth == src.width() &&
|
423
|
-
srcY == 0 && srcHeight == src.height())
|
424
|
-
{
|
425
|
-
data = texture->tryAlloc(texture, src, 0);
|
426
|
-
}
|
427
|
-
else
|
428
|
-
{
|
429
|
-
Bitmap bmp(srcWidth, srcHeight);
|
430
|
-
bmp.insert(src, 0, 0, srcX, srcY, srcWidth, srcHeight);
|
431
|
-
data = texture->tryAlloc(texture, bmp, 0);
|
432
|
-
}
|
433
|
-
|
434
|
-
if (!data.get())
|
435
|
-
throw std::logic_error("Internal texture block allocation error");
|
436
|
-
return GOSU_MOVE_UNIQUE_PTR(data);
|
437
|
-
}
|
438
|
-
|
439
|
-
// Too large to fit on a single texture.
|
440
|
-
if (srcWidth > maxSize - 2 || srcHeight > maxSize - 2)
|
441
|
-
{
|
442
|
-
Bitmap bmp(srcWidth, srcHeight);
|
443
|
-
bmp.insert(src, 0, 0, srcX, srcY, srcWidth, srcHeight);
|
444
|
-
GOSU_UNIQUE_PTR<ImageData> lidi;
|
445
|
-
lidi.reset(new LargeImageData(bmp, maxSize - 2, maxSize - 2, flags));
|
446
|
-
return GOSU_MOVE_UNIQUE_PTR(lidi);
|
447
|
-
}
|
448
|
-
|
449
|
-
Bitmap bmp;
|
450
|
-
applyBorderFlags(bmp, src, srcX, srcY, srcWidth, srcHeight, flags);
|
451
|
-
|
452
|
-
// Try to put the bitmap into one of the already allocated textures.
|
453
|
-
for (Textures::iterator i = textures.begin(); i != textures.end(); ++i)
|
454
|
-
{
|
455
|
-
std::tr1::shared_ptr<Texture> texture(*i);
|
456
|
-
|
457
|
-
if (texture->retro() != wantsRetro)
|
458
|
-
continue;
|
459
|
-
|
460
|
-
GOSU_UNIQUE_PTR<ImageData> data;
|
461
|
-
data = texture->tryAlloc(texture, bmp, 1);
|
462
|
-
if (data.get())
|
463
|
-
return GOSU_MOVE_UNIQUE_PTR(data);
|
464
|
-
}
|
465
|
-
|
466
|
-
// All textures are full: Create a new one.
|
467
|
-
|
468
|
-
std::tr1::shared_ptr<Texture> texture;
|
469
|
-
texture.reset(new Texture(maxSize, wantsRetro));
|
470
|
-
textures.push_back(texture);
|
471
|
-
|
472
|
-
GOSU_UNIQUE_PTR<ImageData> data;
|
473
|
-
data = texture->tryAlloc(texture, bmp, 1);
|
474
|
-
if (!data.get())
|
475
|
-
throw std::logic_error("Internal texture block allocation error");
|
476
|
-
|
477
|
-
return GOSU_MOVE_UNIQUE_PTR(data);
|
478
|
-
}
|