diff options
author | chai <chaifix@163.com> | 2018-07-25 20:27:55 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-07-25 20:27:55 +0800 |
commit | 0371f99359d1f58dbec6353234c2b1ebd86a7585 (patch) | |
tree | 59da821f194dd067e8bf196ebe422712cd975346 /src | |
parent | 128b6dd3e3a803e475ec03493ee26e6b20d7e42b (diff) |
*image->texture
Diffstat (limited to 'src')
-rw-r--r-- | src/libjin/audio/audio.h | 3 | ||||
-rw-r--r-- | src/libjin/audio/sdl/audio.h | 2 | ||||
-rw-r--r-- | src/libjin/audio/source.cpp | 2 | ||||
-rw-r--r-- | src/libjin/common/data.h | 6 | ||||
-rw-r--r-- | src/libjin/common/modules.h | 14 | ||||
-rw-r--r-- | src/libjin/common/subsystem.h | 6 | ||||
-rw-r--r-- | src/libjin/render/graphics.h | 2 | ||||
-rw-r--r-- | src/libjin/render/jsl.cpp | 4 | ||||
-rw-r--r-- | src/libjin/render/jsl.h | 4 | ||||
-rw-r--r-- | src/libjin/render/render.h | 2 | ||||
-rw-r--r-- | src/libjin/render/texture.cpp (renamed from src/libjin/render/image.cpp) | 50 | ||||
-rw-r--r-- | src/libjin/render/texture.h (renamed from src/libjin/render/image.h) | 10 | ||||
-rw-r--r-- | src/libjin/render/window.cpp | 12 | ||||
-rw-r--r-- | src/libjin/render/window.h | 6 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_Image.cpp | 16 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_JSL.cpp | 4 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_graphics.cpp | 6 |
17 files changed, 75 insertions, 74 deletions
diff --git a/src/libjin/audio/audio.h b/src/libjin/audio/audio.h index 7b27e1f..239b718 100644 --- a/src/libjin/audio/audio.h +++ b/src/libjin/audio/audio.h @@ -12,7 +12,8 @@ namespace audio { class Source; - class AudioSystem : public Subsystem<AudioSystem> + template<class SubAudioSystem> + class AudioSystem : public Subsystem<SubAudioSystem> { public: diff --git a/src/libjin/audio/sdl/audio.h b/src/libjin/audio/sdl/audio.h index 861acb3..83ad255 100644 --- a/src/libjin/audio/sdl/audio.h +++ b/src/libjin/audio/sdl/audio.h @@ -13,7 +13,7 @@ namespace audio #define SDLAUDIO_BYTEDEPTH (SDLAUDIO_BITDEPTH >> 3) #define SDLAUDIO_CHANNELS 2 - class SDLAudio : public AudioSystem + class SDLAudio : public AudioSystem<SDLAudio> { public: diff --git a/src/libjin/audio/source.cpp b/src/libjin/audio/source.cpp index a09bbab..f6da44b 100644 --- a/src/libjin/audio/source.cpp +++ b/src/libjin/audio/source.cpp @@ -21,4 +21,4 @@ namespace audio } } -}
\ No newline at end of file +} diff --git a/src/libjin/common/data.h b/src/libjin/common/data.h index 51a3252..6f1c504 100644 --- a/src/libjin/common/data.h +++ b/src/libjin/common/data.h @@ -4,10 +4,10 @@ namespace jin { - struct Data + struct Buffer { - void* data; - int len; + unsigned int len; + char data[0]; }; } diff --git a/src/libjin/common/modules.h b/src/libjin/common/modules.h new file mode 100644 index 0000000..52b0160 --- /dev/null +++ b/src/libjin/common/modules.h @@ -0,0 +1,14 @@ +#ifndef __JIN_COMMON_MODULES_H +#define __JIN_COMMON_MODULES_H + +#define JIN_MODULES_AUDIO 1 +#define JIN_MODULES_RENDER 1 +#define JIN_MODULES_DEBUG 1 +#define JIN_MODULES_FILESYSTEM 1 +#define JIN_MODULES_INPUT 1 +#define JIN_MODULES_MATH 1 +#define JIN_MODULES_NET 1 +#define JIN_MODULES_PHYSICS 1 +#define JIN_MODULES_TILEMAP 1 + +#endif
\ No newline at end of file diff --git a/src/libjin/common/subsystem.h b/src/libjin/common/subsystem.h index 90e8570..35563da 100644 --- a/src/libjin/common/subsystem.h +++ b/src/libjin/common/subsystem.h @@ -21,7 +21,7 @@ namespace jin void quit() { - quitSystem(); + CALLONCE(quitSystem()); destroy(); } @@ -32,8 +32,8 @@ namespace jin SINGLETON(System); - virtual bool initSystem(const Setting* setting) = 0; - virtual void quitSystem() = 0; + virtual onlyonce bool initSystem(const Setting* setting) = 0; + virtual onlyonce void quitSystem() = 0; }; diff --git a/src/libjin/render/graphics.h b/src/libjin/render/graphics.h index a3125c5..579158d 100644 --- a/src/libjin/render/graphics.h +++ b/src/libjin/render/graphics.h @@ -3,7 +3,7 @@ #include "color.h" #include "canvas.h" -#include "image.h" +#include "texture.h" namespace jin { diff --git a/src/libjin/render/jsl.cpp b/src/libjin/render/jsl.cpp index 003f93a..ee3c824 100644 --- a/src/libjin/render/jsl.cpp +++ b/src/libjin/render/jsl.cpp @@ -85,7 +85,7 @@ namespace render glUniform1f(loc, number); } - void JSLProgram::sendImage(const char* variable, const Image* image) + void JSLProgram::sendTexture(const char* variable, const Texture* tex) { checkJSL(); @@ -95,7 +95,7 @@ namespace render GLint texture_unit = getTextureUnit(variable); glUniform1i(location, texture_unit); glActiveTexture(GL_TEXTURE0 + texture_unit); - glBindTexture(GL_TEXTURE_2D, image->getTexture()); + glBindTexture(GL_TEXTURE_2D, tex->getTexture()); glActiveTexture(GL_TEXTURE0); } diff --git a/src/libjin/render/jsl.h b/src/libjin/render/jsl.h index 520a6eb..5943fbe 100644 --- a/src/libjin/render/jsl.h +++ b/src/libjin/render/jsl.h @@ -4,7 +4,7 @@ #include <string> #include <map> #include "color.h" -#include "image.h" +#include "texture.h" #include "canvas.h" #include "3rdparty/GLee/GLee.h" @@ -35,7 +35,7 @@ namespace render } void sendFloat(const char* name, float number); - void sendImage(const char* name, const Image* image); + void sendTexture(const char* name, const Texture* image); void sendVec2(const char* name, float x, float y); void sendVec3(const char* name, float x, float y, float z); void sendVec4(const char* name, float x, float y, float z, float w); diff --git a/src/libjin/render/render.h b/src/libjin/render/render.h index 6c0d6bf..1bf9082 100644 --- a/src/libjin/render/render.h +++ b/src/libjin/render/render.h @@ -5,7 +5,7 @@ #include "color.h" #include "font.h" #include "graphics.h" -#include "image.h" +#include "texture.h" #include "jsl.h" #include "window.h" diff --git a/src/libjin/render/image.cpp b/src/libjin/render/texture.cpp index 564b54e..d5cd695 100644 --- a/src/libjin/render/image.cpp +++ b/src/libjin/render/texture.cpp @@ -1,5 +1,5 @@ #include <fstream> -#include "image.h" +#include "texture.h" #include "3rdparty/stb/stb_image.h" #include "../utils/utils.h" #include "../math/math.h" @@ -9,11 +9,11 @@ namespace jin namespace render { - Image* Image::createImage(const char* file) + Texture* Texture::createTexture(const char* file) { std::ifstream fs; fs.open(file, std::ios::binary); - Image* img = nullptr; + Texture* tex = nullptr; if (fs.is_open()) { fs.seekg(0, std::ios::end); @@ -22,35 +22,35 @@ namespace render char* buffer = (char*)malloc(size); memset(buffer, 0, size); fs.read(buffer, size); - img = createImage(buffer, size); + tex = createTexture(buffer, size); free(buffer); } fs.close(); - return img; + return tex; } - Image* Image::createImage(const void* mem, size_t size) + Texture* Texture::createTexture(const void* mem, size_t size) { - Image* img = new Image(); - if(!img->loadb(mem, size)) + Texture* tex = new Texture(); + if(!tex->loadb(mem, size)) { - delete img; - img = nullptr; + delete tex; + tex = nullptr; } - return img; + return tex; } - Image::Image() + Texture::Texture() : Drawable(), pixels(0) { } - Image::~Image() + Texture::~Texture() { stbi_image_free(pixels); } - color Image::getPixel(int x, int y) + color Texture::getPixel(int x, int y) { if (without(x, 0, width) || without(y, 0, height)) { @@ -59,33 +59,33 @@ namespace render return pixels[x + y * width]; } - bool Image::loadb(const void* b, size_t size) + bool Texture::loadb(const void* b, size_t size) { // ʹstbi_load_from_memory - unsigned char* imageData = stbi_load_from_memory((unsigned char *)b, size, &width, &height, NULL, STBI_rgb_alpha); - if (imageData == 0) return false; - pixels = (color*)imageData; + unsigned char* textureData = stbi_load_from_memory((unsigned char *)b, size, &width, &height, NULL, STBI_rgb_alpha); + if (textureData == 0) return false; + pixels = (color*)textureData; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, - height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); + height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData); // set render vertices Drawable::setVertices( new float [DRAWABLE_V_SIZE] { 0, 0, - 0, (float)height, - (float)width, (float)height, - (float)width, 0, + 0, (float)height, + (float)width, (float)height, + (float)width, 0, }, new float [DRAWABLE_V_SIZE] { 0, 0, - 0, 1, - 1, 1, - 1, 0 + 0, 1, + 1, 1, + 1, 0 } ); diff --git a/src/libjin/render/image.h b/src/libjin/render/texture.h index 95b4e4f..6b0c699 100644 --- a/src/libjin/render/image.h +++ b/src/libjin/render/texture.h @@ -7,21 +7,21 @@ namespace jin { namespace render { - class Image: public Drawable + class Texture: public Drawable { public: - static Image* createImage(const char* file); - static Image* createImage(const void* mem, size_t size); + static Texture* createTexture(const char* file); + static Texture* createTexture(const void* mem, size_t size); - ~Image(); + ~Texture(); color getPixel(int x, int y); private: - Image(); + Texture(); bool loadb(const void* buffer, size_t size); diff --git a/src/libjin/render/window.cpp b/src/libjin/render/window.cpp index 3357f07..1107a53 100644 --- a/src/libjin/render/window.cpp +++ b/src/libjin/render/window.cpp @@ -32,6 +32,8 @@ namespace render SDL_FlushEvent(SDL_WINDOWEVENT); } + SDL_GLContext ctx = NULL; + if (ctx) { SDL_GL_DeleteContext(ctx); @@ -74,16 +76,6 @@ namespace render SDL_DestroyWindow(wnd); } - SDL_Window* WindowSystem::getWnd() - { - return wnd; - } - - SDL_GLContext WindowSystem::getCtx() - { - return ctx; - } - inline void WindowSystem::swapBuffers() { if (wnd) diff --git a/src/libjin/render/window.h b/src/libjin/render/window.h index c7e2651..48ead67 100644 --- a/src/libjin/render/window.h +++ b/src/libjin/render/window.h @@ -21,10 +21,6 @@ namespace render const char* title; // }; - SDL_Window* getWnd(); - - SDL_GLContext getCtx(); - inline int getW() { return width; @@ -46,8 +42,6 @@ namespace render SDL_Window* wnd; - SDL_GLContext ctx; - int width, height; onlyonce bool initSystem(const SettingBase* setting) override; diff --git a/src/lua/graphics/luaopen_Image.cpp b/src/lua/graphics/luaopen_Image.cpp index c5648a5..d651e20 100644 --- a/src/lua/graphics/luaopen_Image.cpp +++ b/src/lua/graphics/luaopen_Image.cpp @@ -9,31 +9,31 @@ namespace jin namespace lua { - static inline Image* checkImage(lua_State* L) + static inline Texture* checkTexture(lua_State* L) { Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_IMAGE); if (proxy != 0 && proxy != nullptr) - return (Image*)proxy->object; + return (Texture*)proxy->object; return nullptr; } static int l_getWidth(lua_State* L) { - Image* i = checkImage(L); + Texture* i = checkTexture(L); luax_pushnumber(L, i->getWidth()); return 1; } static int l_getHeight(lua_State *L) { - Image* i = checkImage(L); + Texture* i = checkTexture(L); luax_pushnumber(L, i->getHeight()); return 1; } static int l_getPixel(lua_State* L) { - Image* i = checkImage(L); + Texture* i = checkTexture(L); int x = luax_checknumber(L, 2); int y = luax_checknumber(L, 3); color c = i->getPixel(x, y); @@ -46,7 +46,7 @@ namespace lua static int l_setAnchor(lua_State* L) { - Image* i = checkImage(L); + Texture* i = checkTexture(L); int x = luax_checknumber(L, 2); int y = luax_checknumber(L, 3); i->setAnchor(x, y); @@ -55,7 +55,7 @@ namespace lua static int l_getSize(lua_State* L) { - Image* i = checkImage(L); + Texture* i = checkTexture(L); luax_pushnumber(L, i->getWidth()); luax_pushnumber(L, i->getHeight()); return 2; @@ -64,7 +64,7 @@ namespace lua static int l_gc(lua_State* L) { Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_IMAGE); - Image* img = (Image*)proxy->object; + Texture* img = (Texture*)proxy->object; delete img; return 0; } diff --git a/src/lua/graphics/luaopen_JSL.cpp b/src/lua/graphics/luaopen_JSL.cpp index 236d8a6..5289a43 100644 --- a/src/lua/graphics/luaopen_JSL.cpp +++ b/src/lua/graphics/luaopen_JSL.cpp @@ -67,8 +67,8 @@ namespace lua case IMAGE: { Proxy* proxy = (Proxy*)luax_checktype(L, 4, TYPE_IMAGE); - Image* img = (Image*)proxy->object; - jsl->sendImage(variable, img); + Texture* tex = (Texture*)proxy->object; + jsl->sendTexture(variable, tex); break; } case CANVAS: diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp index 44b0a2c..be40247 100644 --- a/src/lua/graphics/luaopen_graphics.cpp +++ b/src/lua/graphics/luaopen_graphics.cpp @@ -72,7 +72,7 @@ namespace lua fs->read(f, &b); Proxy* proxy = (Proxy*)luax_newinstance(L, TYPE_IMAGE, sizeof(Proxy)); - Image* img = Image::createImage(b.data, b.size); + Texture* img = Texture::createTexture(b.data, b.size); proxy->bind(img); return 1; } @@ -142,8 +142,8 @@ namespace lua if (luax_istype(L, 1, TYPE_IMAGE)) { Proxy* proxy = (Proxy*)luax_toudata(L, 1); - Image* img = (Image*)proxy->object; - img->draw(x, y, sx, sy, r); + Texture* tex = (Texture*)proxy->object; + tex->draw(x, y, sx, sy, r); } else if (luax_istype(L, 1, TYPE_CANVAS)) { |