1 /*
2  Copyright (c) 2013 yvt
3 
4  This file is part of OpenSpades.
5 
6  OpenSpades is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OpenSpades is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OpenSpades.  If not, see <http://www.gnu.org/licenses/>.
18 
19  */
20 
21 #pragma once
22 
23 #include <Client/IImage.h>
24 #include "IGLDevice.h"
25 
26 namespace spades {
27 	class Bitmap;
28 	namespace draw {
29 		class IGLDevice;
30 		class GLImage : public client::IImage {
31 			IGLDevice *device;
32 			IGLDevice::UInteger tex;
33 			float width, height;
34 			float invWidth, invHeight;
35 			bool autoDelete;
36 			bool valid;
37 			void MakeSureValid();
38 
39 		protected:
40 			~GLImage();
41 
42 		public:
43 			GLImage(IGLDevice::UInteger textureObject, IGLDevice *device, float w, float h,
44 			        bool autoDelete = true);
45 			static GLImage *FromBitmap(Bitmap *, IGLDevice *);
46 			void Bind(IGLDevice::Enum target);
47 
GetWidth()48 			float GetWidth() override { return width; }
GetHeight()49 			float GetHeight() override { return height; }
50 
GetInvWidth()51 			float GetInvWidth() { return invWidth; }
GetInvHeight()52 			float GetInvHeight() { return invHeight; }
53 
54 			void SubImage(Bitmap *bmp, int x, int y);
55 			void Invalidate();
56 
Update(Bitmap & bmp,int x,int y)57 			void Update(Bitmap &bmp, int x, int y) override { SubImage(&bmp, x, y); }
58 		};
59 	}
60 }
61