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
data/src/DirectoriesApple.mm
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
#import <Gosu/Directories.hpp>
|
2
|
-
#import <Gosu/Utility.hpp>
|
3
|
-
#import "AppleUtility.hpp"
|
4
|
-
#import <Foundation/Foundation.h>
|
5
|
-
#import <unistd.h>
|
6
|
-
|
7
|
-
|
8
|
-
static std::wstring stringFromNSString(NSString *string, const wchar_t *fallback)
|
9
|
-
{
|
10
|
-
return string ? Gosu::utf8ToWstring([string UTF8String]) : fallback;
|
11
|
-
}
|
12
|
-
|
13
|
-
void Gosu::useResourceDirectory()
|
14
|
-
{
|
15
|
-
chdir(Gosu::wstringToUTF8(resourcePrefix()).c_str());
|
16
|
-
}
|
17
|
-
|
18
|
-
std::wstring Gosu::userSettingsPrefix()
|
19
|
-
{
|
20
|
-
static std::wstring result = [] {
|
21
|
-
@autoreleasepool {
|
22
|
-
NSString *library =
|
23
|
-
NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0];
|
24
|
-
NSString *preferences = [library stringByAppendingPathComponent:@"Preferences"];
|
25
|
-
|
26
|
-
return stringFromNSString(preferences, L".") + L"/";
|
27
|
-
}
|
28
|
-
}();
|
29
|
-
return result;
|
30
|
-
}
|
31
|
-
|
32
|
-
std::wstring Gosu::userDocsPrefix()
|
33
|
-
{
|
34
|
-
static std::wstring result = [] {
|
35
|
-
@autoreleasepool {
|
36
|
-
NSString *documents =
|
37
|
-
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
38
|
-
|
39
|
-
return stringFromNSString(documents, L".") + L"/";
|
40
|
-
}
|
41
|
-
}();
|
42
|
-
return result;
|
43
|
-
}
|
44
|
-
|
45
|
-
std::wstring Gosu::resourcePrefix()
|
46
|
-
{
|
47
|
-
static std::wstring result = [] {
|
48
|
-
@autoreleasepool {
|
49
|
-
NSString *resources = [NSBundle mainBundle].resourcePath;
|
50
|
-
return stringFromNSString(resources, L".") + L"/";
|
51
|
-
}
|
52
|
-
}();
|
53
|
-
return result;
|
54
|
-
}
|
55
|
-
|
56
|
-
std::wstring Gosu::sharedResourcePrefix()
|
57
|
-
{
|
58
|
-
#ifdef GOSU_IS_IPHONE
|
59
|
-
return resourcePrefix();
|
60
|
-
#else
|
61
|
-
static std::wstring result = [] {
|
62
|
-
@autoreleasepool {
|
63
|
-
NSString *bundlePath = [NSBundle mainBundle].bundlePath;
|
64
|
-
NSString *containingPath = [bundlePath stringByDeletingLastPathComponent];
|
65
|
-
|
66
|
-
return stringFromNSString(containingPath, L".");
|
67
|
-
}
|
68
|
-
}();
|
69
|
-
return result;
|
70
|
-
#endif
|
71
|
-
}
|
@@ -1,142 +0,0 @@
|
|
1
|
-
#include "BlockAllocator.hpp"
|
2
|
-
#include <stdexcept>
|
3
|
-
#include <vector>
|
4
|
-
|
5
|
-
struct Gosu::BlockAllocator::Impl
|
6
|
-
{
|
7
|
-
unsigned width, height;
|
8
|
-
|
9
|
-
typedef std::vector<Block> Blocks;
|
10
|
-
Blocks blocks;
|
11
|
-
unsigned firstX, firstY;
|
12
|
-
unsigned maxW, maxH;
|
13
|
-
|
14
|
-
void markBlockUsed(const Block& block, unsigned aWidth, unsigned aHeight)
|
15
|
-
{
|
16
|
-
firstX += aWidth;
|
17
|
-
if (firstX + aWidth >= width)
|
18
|
-
{
|
19
|
-
firstX = 0;
|
20
|
-
firstY += aHeight;
|
21
|
-
}
|
22
|
-
blocks.push_back(block);
|
23
|
-
}
|
24
|
-
|
25
|
-
bool isBlockFree(const Block& block) const
|
26
|
-
{
|
27
|
-
// (The right-th column and the bottom-th row are outside of the block.)
|
28
|
-
unsigned right = block.left + block.width;
|
29
|
-
unsigned bottom = block.top + block.height;
|
30
|
-
|
31
|
-
// Block isn't valid.
|
32
|
-
if (right > width || bottom > height)
|
33
|
-
return false;
|
34
|
-
|
35
|
-
// Test if the block collides with any existing rects.
|
36
|
-
Blocks::const_iterator i, end = blocks.end();
|
37
|
-
for (i = blocks.begin(); i != end; ++i)
|
38
|
-
if (i->left < right && block.left < i->left + i->width &&
|
39
|
-
i->top < bottom && block.top < i->top + i->height)
|
40
|
-
{
|
41
|
-
return false;
|
42
|
-
}
|
43
|
-
|
44
|
-
return true;
|
45
|
-
}
|
46
|
-
};
|
47
|
-
|
48
|
-
Gosu::BlockAllocator::BlockAllocator(unsigned width, unsigned height)
|
49
|
-
: pimpl(new Impl)
|
50
|
-
{
|
51
|
-
pimpl->width = width;
|
52
|
-
pimpl->height = height;
|
53
|
-
|
54
|
-
pimpl->firstX = 0;
|
55
|
-
pimpl->firstY = 0;
|
56
|
-
|
57
|
-
pimpl->maxW = width;
|
58
|
-
pimpl->maxH = height;
|
59
|
-
}
|
60
|
-
|
61
|
-
Gosu::BlockAllocator::~BlockAllocator()
|
62
|
-
{
|
63
|
-
}
|
64
|
-
|
65
|
-
unsigned Gosu::BlockAllocator::width() const
|
66
|
-
{
|
67
|
-
return pimpl->width;
|
68
|
-
}
|
69
|
-
|
70
|
-
unsigned Gosu::BlockAllocator::height() const
|
71
|
-
{
|
72
|
-
return pimpl->height;
|
73
|
-
}
|
74
|
-
|
75
|
-
bool Gosu::BlockAllocator::alloc(unsigned aWidth, unsigned aHeight, Block& b)
|
76
|
-
{
|
77
|
-
// The rect wouldn't even fit onto the texture!
|
78
|
-
if (aWidth > width() || aHeight > height())
|
79
|
-
return false;
|
80
|
-
|
81
|
-
// We know there's no space left.
|
82
|
-
if (aWidth > pimpl->maxW && aHeight > pimpl->maxH)
|
83
|
-
return false;
|
84
|
-
|
85
|
-
// Start to look for a place next to the last returned rect. Chances are
|
86
|
-
// good we'll find a place there.
|
87
|
-
b = Block(pimpl->firstX, pimpl->firstY, aWidth, aHeight);
|
88
|
-
if (pimpl->isBlockFree(b))
|
89
|
-
{
|
90
|
-
pimpl->markBlockUsed(b, aWidth, aHeight);
|
91
|
-
return true;
|
92
|
-
}
|
93
|
-
|
94
|
-
// Brute force: Look for a free place on this texture.
|
95
|
-
unsigned& x = b.left;
|
96
|
-
unsigned& y = b.top;
|
97
|
-
for (y = 0; y <= height() - aHeight; y += 16)
|
98
|
-
for (x = 0; x <= width() - aWidth; x += 8)
|
99
|
-
{
|
100
|
-
if (!pimpl->isBlockFree(b))
|
101
|
-
continue;
|
102
|
-
|
103
|
-
// Found a nice place!
|
104
|
-
|
105
|
-
// Try to make up for the large for()-stepping.
|
106
|
-
while (y > 0 && pimpl->isBlockFree(Block(x, y - 1, aWidth, aHeight)))
|
107
|
-
--y;
|
108
|
-
while (x > 0 && pimpl->isBlockFree(Block(x - 1, y, aWidth, aHeight)))
|
109
|
-
--x;
|
110
|
-
|
111
|
-
pimpl->markBlockUsed(b, aWidth, aHeight);
|
112
|
-
return true;
|
113
|
-
}
|
114
|
-
|
115
|
-
// So there was no space for the bitmap. Remember this for later.
|
116
|
-
pimpl->maxW = aWidth - 1;
|
117
|
-
pimpl->maxH = aHeight - 1;
|
118
|
-
return false;
|
119
|
-
}
|
120
|
-
|
121
|
-
void Gosu::BlockAllocator::block(unsigned left, unsigned top, unsigned width, unsigned height)
|
122
|
-
{
|
123
|
-
pimpl->blocks.push_back(Block(left, top, width, height));
|
124
|
-
}
|
125
|
-
|
126
|
-
void Gosu::BlockAllocator::free(unsigned left, unsigned top, unsigned width, unsigned height)
|
127
|
-
{
|
128
|
-
for (Impl::Blocks::iterator i = pimpl->blocks.begin();
|
129
|
-
i != pimpl->blocks.end(); ++i)
|
130
|
-
{
|
131
|
-
if (i->left == left && i->top == top && i->width == width && i->height == height)
|
132
|
-
{
|
133
|
-
pimpl->blocks.erase(i);
|
134
|
-
// Be optimistic again!
|
135
|
-
pimpl->maxW = pimpl->width - 1;
|
136
|
-
pimpl->maxH = pimpl->height - 1;
|
137
|
-
return;
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
throw std::logic_error("Tried to free an invalid block");
|
142
|
-
}
|
@@ -1,93 +0,0 @@
|
|
1
|
-
#ifndef GOSU_SRC_GRAPHICS_CLIPRECTSTACK_HPP
|
2
|
-
#define GOSU_SRC_GRAPHICS_CLIPRECTSTACK_HPP
|
3
|
-
|
4
|
-
#include "Common.hpp"
|
5
|
-
#include <cassert>
|
6
|
-
#include <vector>
|
7
|
-
|
8
|
-
class Gosu::ClipRectStack
|
9
|
-
{
|
10
|
-
std::vector<ClipRect> stack;
|
11
|
-
bool hasEffectiveRect; // is effectiveRect valid?
|
12
|
-
ClipRect effectiveRect;
|
13
|
-
|
14
|
-
void updateEffectiveRect()
|
15
|
-
{
|
16
|
-
// Nothing to do, no clipping in place.
|
17
|
-
if (stack.empty())
|
18
|
-
{
|
19
|
-
hasEffectiveRect = false;
|
20
|
-
return;
|
21
|
-
}
|
22
|
-
|
23
|
-
ClipRect result = { 0.0, 0.0, 1e10, 1e10 };
|
24
|
-
for (std::size_t i = 0, end = stack.size(); i < end; ++i)
|
25
|
-
{
|
26
|
-
const ClipRect& rect = stack[i];
|
27
|
-
int resultRight = std::min(result.x + result.width, rect.x + rect.width);
|
28
|
-
int resultBottom = std::min(result.y + result.height, rect.y + rect.height);
|
29
|
-
result.x = std::max(result.x, rect.x);
|
30
|
-
result.y = std::max(result.y, rect.y);
|
31
|
-
|
32
|
-
if (result.x >= resultRight || result.y >= resultBottom)
|
33
|
-
{
|
34
|
-
// We have clipped the world away!
|
35
|
-
hasEffectiveRect = false;
|
36
|
-
return;
|
37
|
-
}
|
38
|
-
|
39
|
-
result.width = resultRight - result.x;
|
40
|
-
result.height = resultBottom - result.y;
|
41
|
-
}
|
42
|
-
|
43
|
-
// On the iPhone, we may have to multiply everything by 2 for Retina displays.
|
44
|
-
// TODO: Doesn't this affect Retina Macs as well?
|
45
|
-
// TODO: This should be handled by a global transform.
|
46
|
-
int fac = clipRectBaseFactor();
|
47
|
-
result.x *= fac, result.y *= fac, result.width *= fac, result.height *= fac;
|
48
|
-
|
49
|
-
// Normal clipping.
|
50
|
-
effectiveRect = result;
|
51
|
-
hasEffectiveRect = true;
|
52
|
-
}
|
53
|
-
|
54
|
-
public:
|
55
|
-
ClipRectStack()
|
56
|
-
: hasEffectiveRect(false)
|
57
|
-
{
|
58
|
-
}
|
59
|
-
|
60
|
-
void clear()
|
61
|
-
{
|
62
|
-
stack.clear();
|
63
|
-
hasEffectiveRect = false;
|
64
|
-
}
|
65
|
-
|
66
|
-
void beginClipping(double x, double y, double width, double height)
|
67
|
-
{
|
68
|
-
ClipRect rect = { x, y, width, height };
|
69
|
-
stack.push_back(rect);
|
70
|
-
updateEffectiveRect();
|
71
|
-
}
|
72
|
-
|
73
|
-
void endClipping()
|
74
|
-
{
|
75
|
-
assert (!stack.empty());
|
76
|
-
stack.pop_back();
|
77
|
-
updateEffectiveRect();
|
78
|
-
}
|
79
|
-
|
80
|
-
const ClipRect* maybeEffectiveRect() const
|
81
|
-
{
|
82
|
-
return hasEffectiveRect ? &effectiveRect : 0;
|
83
|
-
}
|
84
|
-
|
85
|
-
bool clippedWorldAway() const
|
86
|
-
{
|
87
|
-
// When we have no effective rect but the stack is not empty, we have clipped
|
88
|
-
// the whole world away and don't need to render things.
|
89
|
-
return !hasEffectiveRect && !stack.empty();
|
90
|
-
}
|
91
|
-
};
|
92
|
-
|
93
|
-
#endif
|
data/src/Graphics/DrawOp.hpp
DELETED
@@ -1,175 +0,0 @@
|
|
1
|
-
#ifndef GOSU_SRC_DRAWOP_HPP
|
2
|
-
#define GOSU_SRC_DRAWOP_HPP
|
3
|
-
|
4
|
-
#include <Gosu/GraphicsBase.hpp>
|
5
|
-
#include <Gosu/Color.hpp>
|
6
|
-
#include "Common.hpp"
|
7
|
-
#include "RenderState.hpp"
|
8
|
-
#include "TexChunk.hpp"
|
9
|
-
#include <cassert>
|
10
|
-
|
11
|
-
namespace Gosu
|
12
|
-
{
|
13
|
-
struct DrawOp
|
14
|
-
{
|
15
|
-
// For sorting before drawing the queue.
|
16
|
-
ZPos z;
|
17
|
-
|
18
|
-
RenderState renderState;
|
19
|
-
// Only valid if renderState.texName != NO_TEXTURE
|
20
|
-
GLfloat top, left, bottom, right;
|
21
|
-
|
22
|
-
// TODO: Merge with Gosu::ArrayVertex.
|
23
|
-
struct Vertex
|
24
|
-
{
|
25
|
-
float x, y;
|
26
|
-
Color c;
|
27
|
-
Vertex() {}
|
28
|
-
Vertex(float x, float y, Color c) : x(x), y(y), c(c) {}
|
29
|
-
};
|
30
|
-
Vertex vertices[4];
|
31
|
-
|
32
|
-
// Number of vertices used, or: complement index of code block
|
33
|
-
int verticesOrBlockIndex;
|
34
|
-
|
35
|
-
void perform(const DrawOp* next) const
|
36
|
-
{
|
37
|
-
// This should not be called on GL code ops.
|
38
|
-
assert (verticesOrBlockIndex >= 2);
|
39
|
-
assert (verticesOrBlockIndex <= 4);
|
40
|
-
|
41
|
-
#ifdef GOSU_IS_OPENGLES
|
42
|
-
static const unsigned MAX_AUTOGROUP = 24;
|
43
|
-
|
44
|
-
static int spriteCounter = 0;
|
45
|
-
static float spriteVertices[12 * MAX_AUTOGROUP];
|
46
|
-
static float spriteTexcoords[12 * MAX_AUTOGROUP];
|
47
|
-
static unsigned spriteColors[6 * MAX_AUTOGROUP];
|
48
|
-
|
49
|
-
// iPhone specific setup
|
50
|
-
static bool isSetup = false;
|
51
|
-
if (!isSetup)
|
52
|
-
{
|
53
|
-
// Sets up pointers and enables states needed for using vertex arrays and textures
|
54
|
-
glVertexPointer(2, GL_FLOAT, 0, spriteVertices);
|
55
|
-
glEnableClientState(GL_VERTEX_ARRAY);
|
56
|
-
glTexCoordPointer(2, GL_FLOAT, 0, spriteTexcoords);
|
57
|
-
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
58
|
-
// TODO: See if I can somehow change the format of the color pointer, or maybe change the internal color representation on iOS.
|
59
|
-
glColorPointer(4, GL_UNSIGNED_BYTE, 0, spriteColors);
|
60
|
-
glEnableClientState(GL_COLOR_ARRAY);
|
61
|
-
|
62
|
-
isSetup = true;
|
63
|
-
}
|
64
|
-
|
65
|
-
if (renderState.texture)
|
66
|
-
{
|
67
|
-
spriteTexcoords[spriteCounter*12 + 0] = left;
|
68
|
-
spriteTexcoords[spriteCounter*12 + 1] = top;
|
69
|
-
spriteTexcoords[spriteCounter*12 + 2] = right;
|
70
|
-
spriteTexcoords[spriteCounter*12 + 3] = top;
|
71
|
-
spriteTexcoords[spriteCounter*12 + 4] = left;
|
72
|
-
spriteTexcoords[spriteCounter*12 + 5] = bottom;
|
73
|
-
|
74
|
-
spriteTexcoords[spriteCounter*12 + 6] = right;
|
75
|
-
spriteTexcoords[spriteCounter*12 + 7] = top;
|
76
|
-
spriteTexcoords[spriteCounter*12 + 8] = left;
|
77
|
-
spriteTexcoords[spriteCounter*12 + 9] = bottom;
|
78
|
-
spriteTexcoords[spriteCounter*12 + 10] = right;
|
79
|
-
spriteTexcoords[spriteCounter*12 + 11] = bottom;
|
80
|
-
}
|
81
|
-
|
82
|
-
for (int i = 0; i < 3; ++i)
|
83
|
-
{
|
84
|
-
spriteVertices[spriteCounter*12 + i*2] = vertices[i].x;
|
85
|
-
spriteVertices[spriteCounter*12 + i*2+1] = vertices[i].y;
|
86
|
-
spriteColors[spriteCounter*6 + i] = vertices[i].c.abgr();
|
87
|
-
}
|
88
|
-
for (int i = 0; i < 3; ++i)
|
89
|
-
{
|
90
|
-
spriteVertices[spriteCounter*12 + 6 + i*2] = vertices[i + 1].x;
|
91
|
-
spriteVertices[spriteCounter*12 + 6 + i*2+1] = vertices[i + 1].y;
|
92
|
-
spriteColors[spriteCounter*6 + 3 + i] = vertices[i + 1].c.abgr();
|
93
|
-
}
|
94
|
-
|
95
|
-
++spriteCounter;
|
96
|
-
if (spriteCounter == MAX_AUTOGROUP || next == 0 || !(next->renderState == renderState))
|
97
|
-
{
|
98
|
-
glDrawArrays(GL_TRIANGLES, 0, 6 * spriteCounter);
|
99
|
-
//if (spriteCounter > 1)
|
100
|
-
// printf("grouped %d quads\n", spriteCounter);
|
101
|
-
spriteCounter = 0;
|
102
|
-
}
|
103
|
-
#else
|
104
|
-
if (verticesOrBlockIndex == 2)
|
105
|
-
glBegin(GL_LINES);
|
106
|
-
else if (verticesOrBlockIndex == 3)
|
107
|
-
glBegin(GL_TRIANGLES);
|
108
|
-
else // if (verticesOrBlockIndex == 4)
|
109
|
-
glBegin(GL_QUADS);
|
110
|
-
|
111
|
-
for (unsigned i = 0; i < verticesOrBlockIndex; i++)
|
112
|
-
{
|
113
|
-
glColor4ubv(reinterpret_cast<const GLubyte*>(&vertices[i].c));
|
114
|
-
if (renderState.texture)
|
115
|
-
switch (i)
|
116
|
-
{
|
117
|
-
case 0:
|
118
|
-
glTexCoord2f(left, top);
|
119
|
-
break;
|
120
|
-
case 1:
|
121
|
-
glTexCoord2f(right, top);
|
122
|
-
break;
|
123
|
-
case 2:
|
124
|
-
glTexCoord2f(right, bottom);
|
125
|
-
break;
|
126
|
-
case 3:
|
127
|
-
glTexCoord2f(left, bottom);
|
128
|
-
break;
|
129
|
-
}
|
130
|
-
glVertex2f(vertices[i].x, vertices[i].y);
|
131
|
-
}
|
132
|
-
|
133
|
-
glEnd();
|
134
|
-
#endif
|
135
|
-
}
|
136
|
-
|
137
|
-
void compileTo(VertexArrays& vas) const
|
138
|
-
{
|
139
|
-
// Copy vertex data and apply & forget about the transform.
|
140
|
-
// This is important because the pointed-to transform will be gone by the next
|
141
|
-
// frame anyway.
|
142
|
-
ArrayVertex result[4];
|
143
|
-
for (int i = 0; i < 4; ++i)
|
144
|
-
{
|
145
|
-
result[i].vertices[0] = vertices[i].x;
|
146
|
-
result[i].vertices[1] = vertices[i].y;
|
147
|
-
result[i].vertices[2] = 0;
|
148
|
-
result[i].color = vertices[i].c.abgr();
|
149
|
-
applyTransform(*renderState.transform, result[i].vertices[0], result[i].vertices[1]);
|
150
|
-
}
|
151
|
-
RenderState vaRenderState = renderState;
|
152
|
-
vaRenderState.transform = 0;
|
153
|
-
|
154
|
-
result[0].texCoords[0] = left, result[0].texCoords[1] = top;
|
155
|
-
result[1].texCoords[0] = right, result[1].texCoords[1] = top;
|
156
|
-
result[2].texCoords[0] = right, result[2].texCoords[1] = bottom;
|
157
|
-
result[3].texCoords[0] = left, result[3].texCoords[1] = bottom;
|
158
|
-
|
159
|
-
if (vas.empty() || !(vas.back().renderState == vaRenderState))
|
160
|
-
{
|
161
|
-
vas.push_back(VertexArray());
|
162
|
-
vas.back().renderState = vaRenderState;
|
163
|
-
}
|
164
|
-
|
165
|
-
vas.back().vertices.insert(vas.back().vertices.end(), result, result + 4);
|
166
|
-
}
|
167
|
-
|
168
|
-
bool operator<(const DrawOp& other) const
|
169
|
-
{
|
170
|
-
return z < other.z;
|
171
|
-
}
|
172
|
-
};
|
173
|
-
}
|
174
|
-
|
175
|
-
#endif
|