• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1802 (tree)
日時2010-04-25 16:01:02
作者satofumi

ログメッセージ

fixed SDL, OpenGL error

変更サマリ

差分

--- trunk/libs/lua/luabindGui.cpp (revision 1801)
+++ trunk/libs/lua/luabindGui.cpp (revision 1802)
@@ -123,7 +123,8 @@
123123 .def(constructor<const Font&, const char*>())
124124 .def("rect", &TextFadeSurface::rect)
125125 .def("setAlpha", &TextFadeSurface::setAlpha)
126- .def("draw", &TextFadeSurface::draw),
126+ .def("draw", &TextFadeSurface::draw)
127+ .def("setFadePercent", &TextFadeSurface::setFadePercent),
127128
128129 class_<ColorSurface, Surface>("ColorSurface")
129130 .def(constructor<const Rect<long>&, const Color&>())
--- trunk/libs/system/sdl/SdlInit.cpp (revision 1801)
+++ trunk/libs/system/sdl/SdlInit.cpp (revision 1802)
@@ -32,7 +32,7 @@
3232 // !!! 例外を投げるべき
3333 return;
3434 }
35- atexit(SDL_Quit);
35+ //atexit(SDL_Quit);
3636 pimpl->initialized_ = true;
3737 }
3838
--- trunk/libs/gui/Screen.cpp (revision 1801)
+++ trunk/libs/gui/Screen.cpp (revision 1802)
@@ -59,6 +59,7 @@
5959 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
6060 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
6161 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
62+ SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
6263 }
6364
6465
@@ -101,7 +102,7 @@
101102
102103 bool settings_changed_;
103104 Rect<long> next_rect_;
104- size_t next_bpp_;
105+ int next_bpp_;
105106 Uint32 next_flags_;
106107
107108 bool show_cursor_;
--- trunk/libs/gui/SDL_GL_Texture.cpp (revision 1801)
+++ trunk/libs/gui/SDL_GL_Texture.cpp (revision 1802)
@@ -28,6 +28,11 @@
2828
2929 namespace
3030 {
31+ enum {
32+ InvalidTextureId = 0,
33+ };
34+
35+
3136 // Quick utility function for texture creation
3237 int power_of_two(int input)
3338 {
@@ -50,8 +55,8 @@
5055 GLfloat basecoord_[4];
5156 GLfloat alpha_;
5257 Angle rotate_angle_;
53- size_t base_w_;
54- size_t base_h_;
58+ int base_w_;
59+ int base_h_;
5560 bool transparent_;
5661
5762
@@ -76,6 +81,7 @@
7681
7782 ~pImpl(void)
7883 {
84+ // recreateTexture() 用にデストラクタまでリソースを解放をしない
7985 SDL_FreeSurface(surface_);
8086 }
8187
@@ -82,7 +88,8 @@
8288
8389 void recreateTexture(void)
8490 {
85- SDL_GL_LoadTexture(surface_);
91+ is_valid_ = false;
92+ texture_id_ = SDL_GL_LoadTexture(surface_);
8693 if (texture_id_ == InvalidTextureId) {
8794 return;
8895 }
@@ -90,10 +97,10 @@
9097 }
9198
9299
93- void SDL_GL_LoadTexture(SDL_Surface* surface)
100+ GLuint SDL_GL_LoadTexture(SDL_Surface* surface)
94101 {
95102 if (surface == NULL) {
96- return;
103+ return InvalidTextureId;
97104 }
98105 texture_id_ = InvalidTextureId;
99106 base_w_ = surface->w;
@@ -100,12 +107,12 @@
100107 base_h_ = surface->h;
101108
102109 // Use the surface width and height expanded to powers of 2
103- int width = power_of_two(surface->w);
104- int height = power_of_two(surface->h);
110+ int width = power_of_two(base_w_);
111+ int height = power_of_two(base_h_);
105112 basecoord_[0] = 0.0f; // Min X
106113 basecoord_[1] = 0.0f; // Min Y
107- basecoord_[2] = (GLfloat)surface->w / width; // Max X
108- basecoord_[3] = (GLfloat)surface->h / height; // Max Y
114+ basecoord_[2] = static_cast<GLfloat>(base_w_) / width; // Max X
115+ basecoord_[3] = static_cast<GLfloat>(base_h_) / height; // Max Y
109116
110117 SDL_Surface* image = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
111118 #if SDL_BYTEORDER == SDL_LIL_ENDIAN // OpenGL RGBA masks
@@ -121,7 +128,7 @@
121128 #endif
122129 );
123130 if (image == NULL) {
124- return;
131+ return InvalidTextureId;
125132 }
126133
127134 // Save the alpha blending attributes
@@ -133,7 +140,7 @@
133140
134141 // Copy the surface into the GL texture image
135142 SDL_Rect area;
136- set_SdlRect(&area, 0, 0, surface->w, surface->h);
143+ set_SdlRect(&area, 0, 0, base_w_, base_h_);
137144 SDL_BlitSurface(surface, &area, image, &area);
138145
139146 // Restore the alpha blending attributes
@@ -151,7 +158,7 @@
151158 GL_UNSIGNED_BYTE, image->pixels);
152159 SDL_FreeSurface(image); // No longer needed
153160
154- texture_id_ = texture;
161+ return texture;
155162 }
156163 };
157164 set<SDL_GL_Texture*> SDL_GL_Texture::pImpl::textures_;
@@ -175,6 +182,7 @@
175182 {
176183 if (pimpl->texture_id_ != InvalidTextureId) {
177184 glDeleteTextures(1, &pimpl->texture_id_);
185+ pimpl->texture_id_ = InvalidTextureId;
178186 }
179187 }
180188
@@ -333,6 +341,7 @@
333341 {
334342 for_each(pImpl::textures_.begin(), pImpl::textures_.end(),
335343 bind(&SDL_GL_Texture::deleteTexture, _1));
344+ pImpl::textures_.clear();
336345 }
337346
338347
--- trunk/libs/gui/TextFadeSurface.cpp (revision 1801)
+++ trunk/libs/gui/TextFadeSurface.cpp (revision 1802)
@@ -19,7 +19,7 @@
1919 struct TextFadeSurface::pImpl
2020 {
2121 enum {
22- FadeWidthPixel = 100,
22+ FadeWidthPixel = 200,
2323 };
2424
2525 typedef vector<Surface*> Surfaces;
@@ -148,6 +148,6 @@
148148
149149 void TextFadeSurface::setFadePercent(size_t percent)
150150 {
151- pimpl->percent_ = percent;
151+ pimpl->percent_ = min(percent, static_cast<size_t>(100));
152152 pimpl->setAlpha();
153153 }
--- trunk/libs/gui/samples/glTextureDraw.cpp (revision 1801)
+++ trunk/libs/gui/samples/glTextureDraw.cpp (revision 1802)
@@ -361,11 +361,11 @@
361361 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
362362 errorAndExit("SDL_Init");
363363 }
364- atexit(SDL_Quit);
364+ //atexit(SDL_Quit);
365365
366366 Uint32 mode = SDL_OPENGL;
367367 int width = ScreenWidth;
368- int height =ScreenHeight;
368+ int height = ScreenHeight;
369369 int bpp = ScreenBpp;
370370
371371 initializeOpenGl();
--- trunk/libs/gui/samples/fadeText.cpp (revision 1801)
+++ trunk/libs/gui/samples/fadeText.cpp (revision 1802)
@@ -27,15 +27,14 @@
2727 Rect<long> dest_rect = surface.rect();
2828
2929 // 描画した文字列のをフェードさせる
30- for (size_t j = 0; j < 2; ++j) {
31- for (size_t i = 0; i <= 100; ++i) {
32- screen.clear();
33- surface.setFadePercent(i);
34- surface.draw(NULL, &dest_rect);
35- SDL_GL_SwapBuffers();
36- SDL_Delay(10);
37- }
38- SDL_Delay(100);
30+ for (size_t i = 0; i <= 100; ++i) {
31+ screen.clear();
32+ surface.setFadePercent(i);
33+ surface.draw(NULL, &dest_rect);
34+ SDL_GL_SwapBuffers();
35+ SDL_Delay(10);
3936 }
37+ SDL_Delay(100);
38+
4039 return 0;
4140 }
--- trunk/libs/gui/SDL_GL_Texture.h (revision 1801)
+++ trunk/libs/gui/SDL_GL_Texture.h (revision 1802)
@@ -30,9 +30,6 @@
3030 std::auto_ptr<pImpl> pimpl;
3131
3232 public:
33- enum {
34- InvalidTextureId = 0,
35- };
3633 size_t w;
3734 size_t h;
3835
旧リポジトリブラウザで表示