Added Texture (by image) update in TextureImage (and tileset) Added lolimgui first integration passundefined
| @@ -1,7 +1,7 @@ | |||
| include $(top_srcdir)/build/autotools/common.am | |||
| SUBDIRS = bullet lua data . t | |||
| SUBDIRS = bullet lua imgui data . t | |||
| noinst_LIBRARIES = liblolcore.a | |||
| @@ -9,7 +9,8 @@ liblolcore_a_SOURCES = \ | |||
| tiler.cpp tiler.h dict.cpp dict.h \ | |||
| audio.cpp audio.h scene.cpp scene.h font.cpp font.h \ | |||
| entity.cpp entity.h ticker.cpp ticker.h lolgl.h \ | |||
| tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h \ | |||
| textureimage.cpp textureimage.h tileset.cpp tileset.h \ | |||
| forge.cpp forge.h video.cpp video.h \ | |||
| world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \ | |||
| profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.h \ | |||
| numeric.h utils.h messageservice.cpp messageservice.h \ | |||
| @@ -25,8 +26,8 @@ liblolcore_a_SOURCES = \ | |||
| $(sdl_sources) \ | |||
| $(d3d9_sources) \ | |||
| $(android_sources) | |||
| #liblolcore_a_CPPFLAGS = -include-pch $(srcdir)/lol/engine-internal.h.pch $(AM_CPPFLAGS) -I$(srcdir)/bullet -I$(srcdir)/lua | |||
| liblolcore_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/bullet -I$(srcdir)/lua | |||
| #liblolcore_a_CPPFLAGS = -include-pch $(srcdir)/lol/engine-internal.h.pch $(AM_CPPFLAGS) -I$(srcdir)/bullet -I$(srcdir)/lua -I$(srcdir)/imgui | |||
| liblolcore_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/bullet -I$(srcdir)/lua -I$(srcdir)/imgui | |||
| EXTRA_DIST += easymesh/easymesh-scanner.l easymesh/easymesh-parser.y | |||
| @@ -130,6 +130,15 @@ void Image::DummyFill() | |||
| } | |||
| } | |||
| void Image::Copy(uint8_t* pixels, ivec2 const& size, PixelFormat fmt) | |||
| { | |||
| ASSERT(fmt != PixelFormat::Unknown); | |||
| SetFormat(fmt); | |||
| SetSize(size); | |||
| memcpy(m_data->m_pixels[(int)fmt]->data(), pixels, | |||
| size.x * size.y * BytesPerPixel(fmt)); | |||
| } | |||
| void Image::Copy(Image const &other) | |||
| { | |||
| ivec2 size = other.GetSize(); | |||
| @@ -0,0 +1,13 @@ | |||
| include $(top_srcdir)/build/autotools/common.am | |||
| noinst_LIBRARIES = libimgui.a | |||
| libimgui_a_SOURCES = $(imgui_sources) | |||
| libimgui_a_CPPFLAGS = $(AM_CPPFLAGS) | |||
| imgui_sources = \ | |||
| stb_rect_pack.h stb_textedit.h stb_truetype.h \ | |||
| imconfig.h imgui.cpp imgui.h \ | |||
| lolimgui.cpp lolimgui.h | |||
| @@ -0,0 +1,299 @@ | |||
| // | |||
| // imGui integration in lolengine | |||
| // | |||
| // Copyright © 2009-2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // This program is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||
| // See http://www.wtfpl.net/ for more details. | |||
| // | |||
| #if HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include <cstdio> | |||
| #include <lol/engine.h> | |||
| #include "loldebug.h" | |||
| using namespace lol; | |||
| //----------------------------------------------------------------------------- | |||
| LolImGui::LolImGui() | |||
| { | |||
| m_drawgroup = DRAWGROUP_HUD; | |||
| } | |||
| LolImGui::~LolImGui() | |||
| { | |||
| ImGui::GetIO().Fonts->TexID = nullptr; | |||
| Ticker::Unref(m_font); | |||
| m_font = nullptr; | |||
| } | |||
| //------------------------------------------------------------------------- | |||
| LolImGui* g_lolimgui = nullptr; | |||
| void LolImGui::Init() | |||
| { | |||
| Ticker::Ref(g_lolimgui = new LolImGui()); | |||
| ImGuiIO& io = ImGui::GetIO(); | |||
| //io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. | |||
| //io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; | |||
| //io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; | |||
| //io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; | |||
| //io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; | |||
| //io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; | |||
| //io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; | |||
| //io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; | |||
| //io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; | |||
| //io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; | |||
| //io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; | |||
| //io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; | |||
| //io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; | |||
| //io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; | |||
| //io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; | |||
| //io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; | |||
| //io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; | |||
| //Func pointer | |||
| io.RenderDrawListsFn = LolImGui::RenderDrawLists; | |||
| io.SetClipboardTextFn = LolImGui::SetClipboard; | |||
| io.GetClipboardTextFn = LolImGui::GetClipboard; | |||
| /* nope | |||
| #ifdef _MSC_VER | |||
| io.ImeWindowHandle = glfwGetWin32Window(g_Window); | |||
| #endif | |||
| */ | |||
| /* Callback not needed but look into these to send IO stuff | |||
| if (install_callbacks) | |||
| { | |||
| glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback); | |||
| glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback); | |||
| glfwSetKeyCallback(window, ImGui_ImplGlFw_KeyCallback); | |||
| glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback); | |||
| } | |||
| */ | |||
| } | |||
| /* CALLBACKS | |||
| void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) | |||
| { | |||
| if (action == GLFW_PRESS && button >= 0 && button < 3) | |||
| g_MousePressed[button] = true; | |||
| } | |||
| void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) | |||
| { | |||
| g_MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines. | |||
| } | |||
| void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) | |||
| { | |||
| ImGuiIO& io = ImGui::GetIO(); | |||
| if (action == GLFW_PRESS) | |||
| io.KeysDown[key] = true; | |||
| if (action == GLFW_RELEASE) | |||
| io.KeysDown[key] = false; | |||
| io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0; | |||
| io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0; | |||
| } | |||
| void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c) | |||
| { | |||
| ImGuiIO& io = ImGui::GetIO(); | |||
| if (c > 0 && c < 0x10000) | |||
| io.AddInputCharacter((unsigned short)c); | |||
| } | |||
| */ | |||
| void LolImGui::Shutdown() | |||
| { | |||
| Ticker::Unref(g_lolimgui); | |||
| ImGui::Shutdown(); | |||
| } | |||
| //------------------------------------------------------------------------- | |||
| static String g_clipboard; | |||
| void LolImGui::SetClipboard(const char* text) | |||
| { | |||
| g_clipboard = text; | |||
| } | |||
| const char* LolImGui::GetClipboard() | |||
| { | |||
| return g_clipboard.C(); | |||
| } | |||
| //------------------------------------------------------------------------- | |||
| void LolImGui::TickGame(float seconds) | |||
| { | |||
| super::TickGame(seconds); | |||
| ImGuiIO& io = ImGui::GetIO(); | |||
| //Init Texture | |||
| if (!m_font) | |||
| { | |||
| ImGuiIO& io = ImGui::GetIO(); | |||
| // Build texture | |||
| unsigned char* pixels; | |||
| ivec2 size; | |||
| io.Fonts->GetTexDataAsAlpha8(&pixels, &size.w, &size.h); | |||
| Image* image = new Image(); | |||
| image->Copy(pixels, size, PixelFormat::RGBA_8); | |||
| image->SetSize(size); | |||
| Ticker::Ref(m_font = new TextureImage("", image)); | |||
| //// Create texture | |||
| //glGenTextures(1, &g_FontTexture); | |||
| //glBindTexture(GL_TEXTURE_2D, g_FontTexture); | |||
| //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |||
| //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |||
| //glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels); | |||
| //// Store our identifier | |||
| //io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; | |||
| //return true; | |||
| } | |||
| //Texture has been created | |||
| if (m_font && m_font->GetTexture()) | |||
| { | |||
| io.Fonts->TexID = (void *)(intptr_t)m_font; | |||
| } | |||
| // Setup display size (every frame to accommodate for window resizing) | |||
| vec2 video_size = vec2(0); | |||
| video_size = vec2(Video::GetSize()); | |||
| io.DisplaySize = ImVec2(video_size.w, video_size.h); | |||
| // Setup time step | |||
| io.DeltaTime = seconds; | |||
| // Setup inputs | |||
| // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) | |||
| //double mouse_x, mouse_y; | |||
| //glfwGetCursorPos(g_Window, &mouse_x, &mouse_y); | |||
| //mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels | |||
| //mouse_y *= (float)display_h / h; | |||
| //io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) | |||
| /* | |||
| for (int i = 0; i < 3; i++) | |||
| { | |||
| io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. | |||
| g_MousePressed[i] = false; | |||
| } | |||
| io.MouseWheel = g_MouseWheel; | |||
| g_MouseWheel = 0.0f; | |||
| */ | |||
| // Start the frame | |||
| ImGui::NewFrame(); | |||
| } | |||
| void LolImGui::TickDraw(float seconds, Scene &scene) | |||
| { | |||
| super::TickDraw(seconds, scene); | |||
| ImGui::Render(); | |||
| } | |||
| //// Data | |||
| //static GLFWwindow* g_Window = NULL; | |||
| //static double g_Time = 0.0f; | |||
| //static bool g_MousePressed[3] = { false, false, false }; | |||
| //static float g_MouseWheel = 0.0f; | |||
| //static GLuint g_FontTexture = 0; | |||
| //------------------------------------------------------------------------- | |||
| // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) | |||
| // If text or lines are blurry when integrating ImGui in your engine: | |||
| // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) | |||
| //------------------------------------------------------------------------- | |||
| void LolImGui::RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) | |||
| { | |||
| if (cmd_lists_count == 0) | |||
| return; | |||
| /* | |||
| // We are using the OpenGL fixed pipeline to make the example code simpler to read! | |||
| // A probable faster way to render would be to collate all vertices from all cmd_lists into a single vertex buffer. | |||
| // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers. | |||
| glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT); | |||
| glEnable(GL_BLEND); | |||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
| glDisable(GL_CULL_FACE); | |||
| glDisable(GL_DEPTH_TEST); | |||
| glEnable(GL_SCISSOR_TEST); | |||
| glEnableClientState(GL_VERTEX_ARRAY); | |||
| glEnableClientState(GL_TEXTURE_COORD_ARRAY); | |||
| glEnableClientState(GL_COLOR_ARRAY); | |||
| glEnable(GL_TEXTURE_2D); | |||
| // Setup orthographic projection matrix | |||
| const float width = ImGui::GetIO().DisplaySize.x; | |||
| const float height = ImGui::GetIO().DisplaySize.y; | |||
| glMatrixMode(GL_PROJECTION); | |||
| glPushMatrix(); | |||
| glLoadIdentity(); | |||
| glOrtho(0.0f, width, height, 0.0f, -1.0f, +1.0f); | |||
| glMatrixMode(GL_MODELVIEW); | |||
| glPushMatrix(); | |||
| glLoadIdentity(); | |||
| // Render command lists | |||
| #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) | |||
| for (int n = 0; n < cmd_lists_count; n++) | |||
| { | |||
| const ImDrawList* cmd_list = cmd_lists[n]; | |||
| const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->vtx_buffer.front(); | |||
| glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, pos))); | |||
| glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, uv))); | |||
| glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF(ImDrawVert, col))); | |||
| int vtx_offset = 0; | |||
| for (size_t cmd_i = 0; cmd_i < cmd_list->commands.size(); cmd_i++) | |||
| { | |||
| const ImDrawCmd* pcmd = &cmd_list->commands[cmd_i]; | |||
| if (pcmd->user_callback) | |||
| { | |||
| pcmd->user_callback(cmd_list, pcmd); | |||
| } | |||
| else | |||
| { | |||
| glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->texture_id); | |||
| glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y)); | |||
| glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count); | |||
| } | |||
| vtx_offset += pcmd->vtx_count; | |||
| } | |||
| } | |||
| #undef OFFSETOF | |||
| // Restore modified state | |||
| glDisableClientState(GL_COLOR_ARRAY); | |||
| glDisableClientState(GL_TEXTURE_COORD_ARRAY); | |||
| glDisableClientState(GL_VERTEX_ARRAY); | |||
| glMatrixMode(GL_MODELVIEW); | |||
| glPopMatrix(); | |||
| glMatrixMode(GL_PROJECTION); | |||
| glPopMatrix(); | |||
| glPopAttrib(); | |||
| */ | |||
| } | |||
| @@ -0,0 +1,64 @@ | |||
| // | |||
| // imGui integration in lolengine | |||
| // | |||
| // Copyright © 2009-2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // This program is free software. It comes without any warranty, to | |||
| // the extent permitted by applicable law. You can redistribute it | |||
| // and/or modify it under the terms of the Do What the Fuck You Want | |||
| // to Public License, Version 2, as published by the WTFPL Task Force. | |||
| // See http://www.wtfpl.net/ for more details. | |||
| // | |||
| #pragma once | |||
| #include "imgui.h" | |||
| namespace lol | |||
| { | |||
| //LolImGui -------------------------------------------------------------------- | |||
| class LolImGui : public Entity | |||
| { | |||
| typedef Entity super; | |||
| //------------------------------------------------------------------------- | |||
| LolImGui(); | |||
| ~LolImGui(); | |||
| char const *GetName() { return "<LolImGui>"; } | |||
| //------------------------------------------------------------------------- | |||
| static void Init(); | |||
| static void Shutdown(); | |||
| //------------------------------------------------------------------------- | |||
| static void SetClipboard(const char* text); | |||
| static const char* GetClipboard(); | |||
| protected: | |||
| virtual void TickGame(float seconds); | |||
| virtual void TickDraw(float seconds, Scene &scene); | |||
| static void RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count); | |||
| TextureImage* m_font = nullptr; | |||
| }; | |||
| //bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks); | |||
| //void ImGui_ImplGlfw_Shutdown(); | |||
| //void ImGui_ImplGlfw_NewFrame(); | |||
| // | |||
| //// Use if you want to reset your rendering device without losing ImGui state. | |||
| //void ImGui_ImplGlfw_InvalidateDeviceObjects(); | |||
| //bool ImGui_ImplGlfw_CreateDeviceObjects(); | |||
| // | |||
| //// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization) | |||
| //// Provided here if you want to chain callbacks. | |||
| //// You can also handle inputs yourself and use those as a reference. | |||
| //void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); | |||
| //void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); | |||
| //void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); | |||
| //void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); | |||
| } /* namespace lol */ | |||
| @@ -62,14 +62,21 @@ | |||
| </ItemDefinitionGroup> | |||
| <ItemGroup> | |||
| <ClCompile Include="imgui.cpp" /> | |||
| <ClCompile Include="lolimgui.cpp" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ClInclude Include="imgui.h" /> | |||
| <ClInclude Include="imconfig.h" /> | |||
| <ClInclude Include="lolimgui.h" /> | |||
| <ClInclude Include="stb_rect_pack.h" /> | |||
| <ClInclude Include="stb_textedit.h" /> | |||
| <ClInclude Include="stb_truetype.h" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <None Include="Makefile.am"> | |||
| <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> | |||
| </None> | |||
| </ItemGroup> | |||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
| <ImportGroup Label="ExtensionTargets"> | |||
| <Import Project="$(SolutionDir)\msbuild\lolfx.targets" /> | |||
| @@ -42,9 +42,11 @@ | |||
| #include <lol/../sample.h> | |||
| #include <lol/../sprite.h> | |||
| #include <lol/../text.h> | |||
| #include <lol/../textureimage.h> | |||
| #include <lol/../tileset.h> | |||
| #include <lol/../lolua/baselua.h> | |||
| #include <lol/../world.h> | |||
| #include <lol/../imgui/lolimgui.h> | |||
| // Other objects | |||
| #include <lol/../dict.h> | |||
| @@ -72,6 +72,7 @@ public: | |||
| ~Image(); | |||
| void DummyFill(); | |||
| void Copy(uint8_t* pixels, ivec2 const& size, PixelFormat fmt); | |||
| void Copy(Image const &other); | |||
| bool Load(char const *path); | |||
| bool Save(char const *path); | |||
| @@ -277,42 +277,43 @@ struct vec_t<T,2> | |||
| union | |||
| { | |||
| struct { T x, y; }; | |||
| struct { T r, g; }; | |||
| struct { T s, t; }; | |||
| struct { T r, t; }; | |||
| struct { T x, y; }; /* axis */ | |||
| struct { T r, g; }; /* red, green */ | |||
| struct { T s, t; }; | |||
| struct { T r, t; }; /* radius, theta */ | |||
| struct { T w, h; }; /* width, height */ | |||
| #if !_DOXYGEN_SKIP_ME | |||
| vec_t<T, 2, 9000> const xx, rr, ss/**/; | |||
| vec_t<T, 2, 9001> _____ xy, rg, st, rt; | |||
| vec_t<T, 2, 9010> _____ yx, gr, ts, tr; | |||
| vec_t<T, 2, 9011> const yy, gg, tt/**/; | |||
| vec_t<T, 3, 90000> const xxx, rrr, sss /**/; | |||
| vec_t<T, 3, 90001> const xxy, rrg, sst, rrt; | |||
| vec_t<T, 3, 90010> const xyx, rgr, sts, rtr; | |||
| vec_t<T, 3, 90011> const xyy, rgg, stt, rtt; | |||
| vec_t<T, 3, 90100> const yxx, grr, tss, trr; | |||
| vec_t<T, 3, 90101> const yxy, grg, tst, trt; | |||
| vec_t<T, 3, 90110> const yyx, ggr, tts, ttr; | |||
| vec_t<T, 3, 90111> const yyy, ggg, ttt /**/; | |||
| vec_t<T, 4, 900000> const xxxx, rrrr, ssss /**/; | |||
| vec_t<T, 4, 900001> const xxxy, rrrg, ssst, rrrt; | |||
| vec_t<T, 4, 900010> const xxyx, rrgr, ssts, rrtr; | |||
| vec_t<T, 4, 900011> const xxyy, rrgg, sstt, rrtt; | |||
| vec_t<T, 4, 900100> const xyxx, rgrr, stss, rtrr; | |||
| vec_t<T, 4, 900101> const xyxy, rgrg, stst, rtrt; | |||
| vec_t<T, 4, 900110> const xyyx, rggr, stts, rttr; | |||
| vec_t<T, 4, 900111> const xyyy, rggg, sttt, rttt; | |||
| vec_t<T, 4, 901000> const yxxx, grrr, tsss, trrr; | |||
| vec_t<T, 4, 901001> const yxxy, grrg, tsst, trrt; | |||
| vec_t<T, 4, 901010> const yxyx, grgr, tsts, trtr; | |||
| vec_t<T, 4, 901011> const yxyy, grgg, tstt, trtt; | |||
| vec_t<T, 4, 901100> const yyxx, ggrr, ttss, ttrr; | |||
| vec_t<T, 4, 901101> const yyxy, ggrg, ttst, ttrt; | |||
| vec_t<T, 4, 901110> const yyyx, gggr, ttts, tttr; | |||
| vec_t<T, 4, 901111> const yyyy, gggg, tttt /**/; | |||
| vec_t<T, 2, 9000> const xx, rr, ss/**/, ww; | |||
| vec_t<T, 2, 9001> _____ xy, rg, st, rt, wh; | |||
| vec_t<T, 2, 9010> _____ yx, gr, ts, tr, hw; | |||
| vec_t<T, 2, 9011> const yy, gg, tt/**/, hh; | |||
| vec_t<T, 3, 90000> const xxx, rrr, sss /**/, www; | |||
| vec_t<T, 3, 90001> const xxy, rrg, sst, rrt, wwh; | |||
| vec_t<T, 3, 90010> const xyx, rgr, sts, rtr, whw; | |||
| vec_t<T, 3, 90011> const xyy, rgg, stt, rtt, whh; | |||
| vec_t<T, 3, 90100> const yxx, grr, tss, trr, hww; | |||
| vec_t<T, 3, 90101> const yxy, grg, tst, trt, hwh; | |||
| vec_t<T, 3, 90110> const yyx, ggr, tts, ttr, hhw; | |||
| vec_t<T, 3, 90111> const yyy, ggg, ttt /**/, hhh; | |||
| vec_t<T, 4, 900000> const xxxx, rrrr, ssss /**/, wwww; | |||
| vec_t<T, 4, 900001> const xxxy, rrrg, ssst, rrrt, wwwh; | |||
| vec_t<T, 4, 900010> const xxyx, rrgr, ssts, rrtr, wwhw; | |||
| vec_t<T, 4, 900011> const xxyy, rrgg, sstt, rrtt, wwhh; | |||
| vec_t<T, 4, 900100> const xyxx, rgrr, stss, rtrr, whww; | |||
| vec_t<T, 4, 900101> const xyxy, rgrg, stst, rtrt, whwh; | |||
| vec_t<T, 4, 900110> const xyyx, rggr, stts, rttr, whhw; | |||
| vec_t<T, 4, 900111> const xyyy, rggg, sttt, rttt, whhh; | |||
| vec_t<T, 4, 901000> const yxxx, grrr, tsss, trrr, hwww; | |||
| vec_t<T, 4, 901001> const yxxy, grrg, tsst, trrt, hwwh; | |||
| vec_t<T, 4, 901010> const yxyx, grgr, tsts, trtr, hwhw; | |||
| vec_t<T, 4, 901011> const yxyy, grgg, tstt, trtt, hwhh; | |||
| vec_t<T, 4, 901100> const yyxx, ggrr, ttss, ttrr, hhww; | |||
| vec_t<T, 4, 901101> const yyxy, ggrg, ttst, ttrt, hhwh; | |||
| vec_t<T, 4, 901110> const yyyx, gggr, ttts, tttr, hhhw; | |||
| vec_t<T, 4, 901111> const yyyy, gggg, tttt /**/, hhhh; | |||
| #endif | |||
| T m_data[count]; | |||
| @@ -434,49 +435,50 @@ struct vec_t<T,3> | |||
| union | |||
| { | |||
| struct { T x, y, z; }; | |||
| struct { T r, g, b; }; | |||
| struct { T x, y, z; }; /* axis */ | |||
| struct { T r, g, b; }; /* red, green, blue */ | |||
| struct { T s, t, p; }; | |||
| struct { T r, t, p; }; | |||
| struct { T r, t, p; }; /* radius, theta, phi */ | |||
| struct { T w, h, d; }; /* width, height, depth */ | |||
| #if !_DOXYGEN_SKIP_ME | |||
| vec_t<T, 2, 9000> const xx, rr, ss/**/; | |||
| vec_t<T, 2, 9001> _____ xy, rg, st, rt; | |||
| vec_t<T, 2, 9002> _____ xz, rb, sp, rp; | |||
| vec_t<T, 2, 9010> _____ yx, gr, ts, tr; | |||
| vec_t<T, 2, 9011> const yy, gg, tt/**/; | |||
| vec_t<T, 2, 9012> _____ yz, gb, tp/**/; | |||
| vec_t<T, 2, 9020> _____ zx, br, ps, pr; | |||
| vec_t<T, 2, 9021> _____ zy, bg, pt/**/; | |||
| vec_t<T, 2, 9022> const zz, bb, pp/**/; | |||
| vec_t<T, 3, 90000> const xxx, rrr, sss /**/; | |||
| vec_t<T, 3, 90001> const xxy, rrg, sst, rrt; | |||
| vec_t<T, 3, 90002> const xxz, rrb, ssp, rrp; | |||
| vec_t<T, 3, 90010> const xyx, rgr, sts, rtr; | |||
| vec_t<T, 3, 90011> const xyy, rgg, stt, rtt; | |||
| vec_t<T, 3, 90012> _____ xyz, rgb, stp, rtp; | |||
| vec_t<T, 3, 90020> const xzx, rbr, sps, rpr; | |||
| vec_t<T, 3, 90021> _____ xzy, rbg, spt, rpt; | |||
| vec_t<T, 3, 90022> const xzz, rbb, spp, rpp; | |||
| vec_t<T, 3, 90100> const yxx, grr, tss, trr; | |||
| vec_t<T, 3, 90101> const yxy, grg, tst, trt; | |||
| vec_t<T, 3, 90102> _____ yxz, grb, tsp, trp; | |||
| vec_t<T, 3, 90110> const yyx, ggr, tts, ttr; | |||
| vec_t<T, 3, 90111> const yyy, ggg, ttt /**/; | |||
| vec_t<T, 3, 90112> const yyz, ggb, ttp /**/; | |||
| vec_t<T, 3, 90120> _____ yzx, gbr, tps, tpr; | |||
| vec_t<T, 3, 90121> const yzy, gbg, tpt /**/; | |||
| vec_t<T, 3, 90122> const yzz, gbb, tpp /**/; | |||
| vec_t<T, 3, 90200> const zxx, brr, pss, prr; | |||
| vec_t<T, 3, 90201> _____ zxy, brg, pst, prt; | |||
| vec_t<T, 3, 90202> const zxz, brb, psp, prp; | |||
| vec_t<T, 3, 90210> _____ zyx, bgr, pts, ptr; | |||
| vec_t<T, 3, 90211> const zyy, bgg, ptt /**/; | |||
| vec_t<T, 3, 90212> const zyz, bgb, ptp /**/; | |||
| vec_t<T, 3, 90220> const zzx, bbr, pps, ppr; | |||
| vec_t<T, 3, 90221> const zzy, bbg, ppt /**/; | |||
| vec_t<T, 3, 90222> const zzz, bbb, ppp /**/; | |||
| vec_t<T, 2, 9000> const xx, rr, ss/**/, ww; | |||
| vec_t<T, 2, 9001> _____ xy, rg, st, rt, wh; | |||
| vec_t<T, 2, 9002> _____ xz, rb, sp, rp, wd; | |||
| vec_t<T, 2, 9010> _____ yx, gr, ts, tr, hw; | |||
| vec_t<T, 2, 9011> const yy, gg, tt/**/, hh; | |||
| vec_t<T, 2, 9012> _____ yz, gb, tp/**/, hd; | |||
| vec_t<T, 2, 9020> _____ zx, br, ps, pr, dw; | |||
| vec_t<T, 2, 9021> _____ zy, bg, pt/**/, dh; | |||
| vec_t<T, 2, 9022> const zz, bb, pp/**/, dd; | |||
| vec_t<T, 3, 90000> const xxx, rrr, sss /**/, www; | |||
| vec_t<T, 3, 90001> const xxy, rrg, sst, rrt, wwh; | |||
| vec_t<T, 3, 90002> const xxz, rrb, ssp, rrp, wwd; | |||
| vec_t<T, 3, 90010> const xyx, rgr, sts, rtr, whw; | |||
| vec_t<T, 3, 90011> const xyy, rgg, stt, rtt, whh; | |||
| vec_t<T, 3, 90012> _____ xyz, rgb, stp, rtp, whd; | |||
| vec_t<T, 3, 90020> const xzx, rbr, sps, rpr, wdw; | |||
| vec_t<T, 3, 90021> _____ xzy, rbg, spt, rpt, wdh; | |||
| vec_t<T, 3, 90022> const xzz, rbb, spp, rpp, wdd; | |||
| vec_t<T, 3, 90100> const yxx, grr, tss, trr, hww; | |||
| vec_t<T, 3, 90101> const yxy, grg, tst, trt, hwh; | |||
| vec_t<T, 3, 90102> _____ yxz, grb, tsp, trp, hwd; | |||
| vec_t<T, 3, 90110> const yyx, ggr, tts, ttr, hhw; | |||
| vec_t<T, 3, 90111> const yyy, ggg, ttt /**/, hhh; | |||
| vec_t<T, 3, 90112> const yyz, ggb, ttp /**/, hhd; | |||
| vec_t<T, 3, 90120> _____ yzx, gbr, tps, tpr, hdw; | |||
| vec_t<T, 3, 90121> const yzy, gbg, tpt /**/, hdh; | |||
| vec_t<T, 3, 90122> const yzz, gbb, tpp /**/, hdd; | |||
| vec_t<T, 3, 90200> const zxx, brr, pss, prr, dww; | |||
| vec_t<T, 3, 90201> _____ zxy, brg, pst, prt, dwh; | |||
| vec_t<T, 3, 90202> const zxz, brb, psp, prp, dwd; | |||
| vec_t<T, 3, 90210> _____ zyx, bgr, pts, ptr, dhw; | |||
| vec_t<T, 3, 90211> const zyy, bgg, ptt /**/, dhh; | |||
| vec_t<T, 3, 90212> const zyz, bgb, ptp /**/, dhd; | |||
| vec_t<T, 3, 90220> const zzx, bbr, pps, ppr, ddw; | |||
| vec_t<T, 3, 90221> const zzy, bbg, ppt /**/, ddh; | |||
| vec_t<T, 3, 90222> const zzz, bbb, ppp /**/, ddd; | |||
| vec_t<T,4,900000> const xxxx, rrrr, ssss; | |||
| vec_t<T,4,900001> const xxxy, rrrg, ssst; | |||
| @@ -654,8 +656,8 @@ struct vec_t<T,4> | |||
| union | |||
| { | |||
| struct { T x, y, z, w; }; | |||
| struct { T r, g, b, a; }; | |||
| struct { T x, y, z, w; }; /* axis */ | |||
| struct { T r, g, b, a; }; /* red, green, blue, alpha */ | |||
| struct { T s, t, p, q; }; | |||
| #if !_DOXYGEN_SKIP_ME | |||
| @@ -225,6 +225,7 @@ | |||
| <ClCompile Include="sys\threadtypes.cpp" /> | |||
| <ClCompile Include="sys\timer.cpp" /> | |||
| <ClCompile Include="text.cpp" /> | |||
| <ClCompile Include="textureimage.cpp" /> | |||
| <ClCompile Include="ticker.cpp" /> | |||
| <ClCompile Include="tiler.cpp" /> | |||
| <ClCompile Include="tileset.cpp" /> | |||
| @@ -381,6 +382,8 @@ | |||
| <ClInclude Include="sprite.h" /> | |||
| <ClInclude Include="sys\threadbase.h" /> | |||
| <ClInclude Include="text.h" /> | |||
| <ClInclude Include="textureimage-private.h" /> | |||
| <ClInclude Include="textureimage.h" /> | |||
| <ClInclude Include="ticker.h" /> | |||
| <ClInclude Include="tiler.h" /> | |||
| <ClInclude Include="tileset.h" /> | |||
| @@ -406,7 +409,9 @@ | |||
| <LolFxCompile Include="gradient.lolfx" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <None Include="Makefile.am" /> | |||
| <None Include="Makefile.am"> | |||
| <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> | |||
| </None> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="bullet\lolbullet.vcxproj"> | |||
| @@ -91,6 +91,12 @@ | |||
| <Filter Include="lolua"> | |||
| <UniqueIdentifier>{25cc0513-ad71-4fbe-bd24-acc88aa66833}</UniqueIdentifier> | |||
| </Filter> | |||
| <Filter Include="tileset"> | |||
| <UniqueIdentifier>{7fb4105d-4f17-4824-8d40-948553fdcde1}</UniqueIdentifier> | |||
| </Filter> | |||
| <Filter Include="entities"> | |||
| <UniqueIdentifier>{3bd5fe6f-c9cd-45f3-98a9-958d86d415e8}</UniqueIdentifier> | |||
| </Filter> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ClCompile Include="image\crop.cpp"> | |||
| @@ -210,9 +216,6 @@ | |||
| <ClCompile Include="emitter.cpp"> | |||
| <Filter>...</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="entity.cpp"> | |||
| <Filter>...</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="font.cpp"> | |||
| <Filter>...</Filter> | |||
| </ClCompile> | |||
| @@ -249,21 +252,12 @@ | |||
| <ClCompile Include="text.cpp"> | |||
| <Filter>...</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="tiler.cpp"> | |||
| <Filter>...</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="tileset.cpp"> | |||
| <Filter>...</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="video.cpp"> | |||
| <Filter>...</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="world.cpp"> | |||
| <Filter>...</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="worldentity.cpp"> | |||
| <Filter>...</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="gpu\framebuffer.cpp"> | |||
| <Filter>gpu</Filter> | |||
| </ClCompile> | |||
| @@ -415,6 +409,21 @@ | |||
| <ClCompile Include="sys\threadtypes.cpp"> | |||
| <Filter>sys</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="tiler.cpp"> | |||
| <Filter>tileset</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="tileset.cpp"> | |||
| <Filter>tileset</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="worldentity.cpp"> | |||
| <Filter>entities</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="entity.cpp"> | |||
| <Filter>entities</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="textureimage.cpp"> | |||
| <Filter>tileset</Filter> | |||
| </ClCompile> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ClInclude Include="debug\fps.h"> | |||
| @@ -537,9 +546,6 @@ | |||
| <ClInclude Include="emitter.h"> | |||
| <Filter>...</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="entity.h"> | |||
| <Filter>...</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="font.h"> | |||
| <Filter>...</Filter> | |||
| </ClInclude> | |||
| @@ -588,15 +594,6 @@ | |||
| <ClInclude Include="ticker.h"> | |||
| <Filter>...</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="worldentity.h"> | |||
| <Filter>...</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="tiler.h"> | |||
| <Filter>...</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="tileset.h"> | |||
| <Filter>...</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="video.h"> | |||
| <Filter>...</Filter> | |||
| </ClInclude> | |||
| @@ -775,6 +772,24 @@ | |||
| <ClInclude Include="lol\sys\threadtypes.h"> | |||
| <Filter>lol\sys</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="tiler.h"> | |||
| <Filter>tileset</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="tileset.h"> | |||
| <Filter>tileset</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="worldentity.h"> | |||
| <Filter>entities</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="entity.h"> | |||
| <Filter>entities</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="textureimage.h"> | |||
| <Filter>tileset</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="textureimage-private.h"> | |||
| <Filter>tileset</Filter> | |||
| </ClInclude> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <LolFxCompile Include="gpu\emptymaterial.lolfx"> | |||
| @@ -795,9 +810,6 @@ | |||
| <LolFxCompile Include="gpu\line.lolfx"> | |||
| <Filter>...</Filter> | |||
| </LolFxCompile> | |||
| <LolFxCompile Include="gpu\tile.lolfx"> | |||
| <Filter>...</Filter> | |||
| </LolFxCompile> | |||
| <LolFxCompile Include="easymesh\shiny_SK.lolfx"> | |||
| <Filter>easymesh</Filter> | |||
| </LolFxCompile> | |||
| @@ -819,6 +831,9 @@ | |||
| <LolFxCompile Include="gpu\palette.lolfx"> | |||
| <Filter>...</Filter> | |||
| </LolFxCompile> | |||
| <LolFxCompile Include="gpu\tile.lolfx"> | |||
| <Filter>tileset</Filter> | |||
| </LolFxCompile> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <None Include="Makefile.am" /> | |||
| @@ -322,6 +322,7 @@ protected: | |||
| } | |||
| }; | |||
| //----------------------------------------------------------------------------- | |||
| /* TODO: FIX THAT TOUKY !! | |||
| template<typename T> | |||
| class VarPtrLight | |||
| { | |||
| @@ -337,7 +338,7 @@ protected: | |||
| m_value = obj ? *obj : nullptr; | |||
| } | |||
| }; | |||
| */ | |||
| //----------------------------------------------------------------------------- | |||
| template<typename T> | |||
| class Var | |||
| @@ -123,6 +123,11 @@ | |||
| <ClInclude Include="lvm.h" /> | |||
| <ClInclude Include="lzio.h" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <None Include="Makefile.am"> | |||
| <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> | |||
| </None> | |||
| </ItemGroup> | |||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
| <ImportGroup Label="ExtensionTargets"> | |||
| <Import Project="$(SolutionDir)\msbuild\lolfx.targets" /> | |||
| @@ -0,0 +1,39 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://www.wtfpl.net/ for more details. | |||
| // | |||
| #pragma once | |||
| // | |||
| // The TileSet class | |||
| // ----------------- | |||
| // A TileSet is a collection of tiles stored in a texture. Texture uploading | |||
| // and freeing is done in the render tick method. When the refcount drops to | |||
| // zero, the texture is freed. | |||
| // | |||
| namespace lol | |||
| { | |||
| class TextureImageData | |||
| { | |||
| friend class TextureImage; | |||
| //T'was protected .... should it be ? | |||
| public: | |||
| String m_name; | |||
| /* Pixels, then texture coordinates */ | |||
| ivec2 m_image_size, m_texture_size; | |||
| Image *m_image = nullptr; | |||
| Texture *m_texture = nullptr; | |||
| }; | |||
| } /* namespace lol */ | |||
| @@ -0,0 +1,186 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://www.wtfpl.net/ for more details. | |||
| // | |||
| #include <lol/engine-internal.h> | |||
| #include <cstdlib> | |||
| #include <cstdio> | |||
| #include <cstring> | |||
| #if defined(_WIN32) && !defined(_XBOX) | |||
| # define WIN32_LEAN_AND_MEAN | |||
| # include <windows.h> | |||
| # if defined USE_D3D9 | |||
| # define FAR | |||
| # define NEAR | |||
| # include <d3d9.h> | |||
| # endif | |||
| #endif | |||
| #include "textureimage-private.h" | |||
| namespace lol | |||
| { | |||
| /* | |||
| * TileSet implementation class | |||
| */ | |||
| TextureImageData* TextureImage::GetNewData() | |||
| { | |||
| return new TextureImageData(); | |||
| } | |||
| /* | |||
| * Public TextureImage class | |||
| */ | |||
| TextureImage::TextureImage(char const *path) | |||
| : m_data(GetNewData()) | |||
| { | |||
| Init(path); | |||
| } | |||
| TextureImage::TextureImage(char const *path, Image* image) | |||
| : m_data(GetNewData()) | |||
| { | |||
| Init(path, image); | |||
| } | |||
| TextureImage::~TextureImage() | |||
| { | |||
| delete m_data; | |||
| } | |||
| void TextureImage::Init(char const *path) | |||
| { | |||
| Init(path, new Image(path)); | |||
| } | |||
| void TextureImage::Init(char const *path, Image* image) | |||
| { | |||
| m_data->m_name = String("<textureimage> ") + path; | |||
| m_data->m_texture = nullptr; | |||
| m_data->m_image = image; | |||
| m_data->m_image_size = m_data->m_image->GetSize(); | |||
| m_data->m_texture_size = ivec2(PotUp(m_data->m_image_size.x), | |||
| PotUp(m_data->m_image_size.y)); | |||
| m_drawgroup = DRAWGROUP_BEFORE; | |||
| } | |||
| void TextureImage::TickDraw(float seconds, Scene &scene) | |||
| { | |||
| super::TickDraw(seconds, scene); | |||
| if (IsDestroying()) | |||
| { | |||
| if (m_data->m_image) | |||
| { | |||
| delete m_data->m_image; | |||
| m_data->m_image = nullptr; | |||
| } | |||
| else | |||
| { | |||
| delete m_data->m_texture; | |||
| m_data->m_texture = nullptr; | |||
| } | |||
| } | |||
| else if (m_data->m_image) | |||
| { | |||
| //Update texture is needed | |||
| if (m_data->m_texture) | |||
| { | |||
| delete m_data->m_texture; | |||
| m_data->m_texture = nullptr; | |||
| } | |||
| PixelFormat format = m_data->m_image->GetFormat(); | |||
| int planes = BytesPerPixel(format); | |||
| int w = m_data->m_texture_size.x; | |||
| int h = m_data->m_texture_size.y; | |||
| uint8_t *pixels = (uint8_t *)m_data->m_image->Lock(); | |||
| bool resized = false; | |||
| if (w != m_data->m_image_size.x || h != m_data->m_image_size.y) | |||
| { | |||
| uint8_t *tmp = new uint8_t[planes * w * h]; | |||
| for (int line = 0; line < m_data->m_image_size.y; line++) | |||
| memcpy(tmp + planes * w * line, | |||
| pixels + planes * m_data->m_image_size.x * line, | |||
| planes * m_data->m_image_size.x); | |||
| pixels = tmp; | |||
| resized = false; | |||
| } | |||
| m_data->m_texture = new Texture(ivec2(w, h), format); | |||
| m_data->m_texture->SetData(pixels); | |||
| if (resized) | |||
| delete[] pixels; | |||
| delete m_data->m_image; | |||
| m_data->m_image = nullptr; | |||
| } | |||
| } | |||
| //----------------------------------------------------------------------------- | |||
| char const *TextureImage::GetName() | |||
| { | |||
| return m_data->m_name.C(); | |||
| } | |||
| void TextureImage::UpdateTexture(Image* image) | |||
| { | |||
| m_data->m_image = image; | |||
| m_data->m_image_size = m_data->m_image->GetSize(); | |||
| m_data->m_texture_size = ivec2(PotUp(m_data->m_image_size.x), | |||
| PotUp(m_data->m_image_size.y)); | |||
| } | |||
| Texture * TextureImage::GetTexture() | |||
| { | |||
| return m_data->m_texture; | |||
| } | |||
| Texture const * TextureImage::GetTexture() const | |||
| { | |||
| return m_data->m_texture; | |||
| } | |||
| Image * TextureImage::GetImage() | |||
| { | |||
| return m_data->m_image; | |||
| } | |||
| Image const * TextureImage::GetImage() const | |||
| { | |||
| return m_data->m_image; | |||
| } | |||
| ivec2 TextureImage::GetTextureSize() const | |||
| { | |||
| return m_data->m_texture_size; | |||
| } | |||
| void TextureImage::Bind() | |||
| { | |||
| if (!m_data->m_image && m_data->m_texture) | |||
| m_data->m_texture->Bind(); | |||
| } | |||
| void TextureImage::Unbind() | |||
| { | |||
| ; | |||
| } | |||
| } /* namespace lol */ | |||
| @@ -0,0 +1,69 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://www.wtfpl.net/ for more details. | |||
| // | |||
| #pragma once | |||
| // | |||
| // The TileSet class | |||
| // ----------------- | |||
| // A TileSet is a collection of tiles stored in a texture. Texture uploading | |||
| // and freeing is done in the render tick method. When the refcount drops to | |||
| // zero, the texture is freed. | |||
| // | |||
| #include <lol/image/image.h> | |||
| #include <lol/gpu/texture.h> | |||
| #include <stdint.h> | |||
| #include "entity.h" | |||
| namespace lol | |||
| { | |||
| class TextureImageData; | |||
| class TextureImage : public Entity | |||
| { | |||
| typedef Entity super; | |||
| protected: | |||
| virtual TextureImageData* GetNewData(); | |||
| public: | |||
| TextureImage(char const *path); | |||
| TextureImage(char const *path, Image* image); | |||
| virtual ~TextureImage(); | |||
| protected: | |||
| void Init(char const *path); | |||
| virtual void Init(char const *path, Image* image); | |||
| protected: | |||
| virtual void TickDraw(float seconds, Scene &scene); | |||
| public: | |||
| /* Inherited from Entity */ | |||
| virtual char const *GetName(); | |||
| void UpdateTexture(Image* image); | |||
| Texture * GetTexture(); | |||
| Texture const * GetTexture() const; | |||
| Image * GetImage(); | |||
| Image const * GetImage() const; | |||
| ivec2 GetTextureSize() const; | |||
| void Bind(); | |||
| void Unbind(); | |||
| protected: | |||
| TextureImageData* m_data = nullptr; | |||
| }; | |||
| } /* namespace lol */ | |||
| @@ -24,6 +24,8 @@ | |||
| # endif | |||
| #endif | |||
| #include "textureimage-private.h" | |||
| namespace lol | |||
| { | |||
| @@ -31,30 +33,38 @@ namespace lol | |||
| * TileSet implementation class | |||
| */ | |||
| class TileSetData | |||
| class TileSetData : public TextureImageData | |||
| { | |||
| friend class TileSet; | |||
| private: | |||
| String m_name; | |||
| protected: | |||
| /* Pixels, then texture coordinates */ | |||
| array<ibox2, box2> m_tiles; | |||
| ivec2 m_tile_size, m_image_size, m_texture_size; | |||
| Image *m_image; | |||
| Texture *m_texture; | |||
| ivec2 m_tile_size; | |||
| }; | |||
| TextureImageData* TileSet::GetNewData() | |||
| { | |||
| return new TileSetData(); | |||
| } | |||
| TileSetData* TileSet::GetData() | |||
| { | |||
| return (TileSetData*)m_data; | |||
| } | |||
| TileSetData const* TileSet::GetData() const | |||
| { | |||
| return (TileSetData const*)m_data; | |||
| } | |||
| /* | |||
| * Public TileSet class | |||
| */ | |||
| TileSet::TileSet(char const *path) | |||
| : m_data(new TileSetData()) | |||
| : TextureImage(path) | |||
| { | |||
| Init(path); | |||
| array<ivec2, ivec2> tiles; | |||
| if (m_data->m_image->RetrieveTiles(tiles)) | |||
| for (ptrdiff_t i = 0; i < tiles.Count(); i++) | |||
| @@ -62,10 +72,8 @@ TileSet::TileSet(char const *path) | |||
| } | |||
| TileSet::TileSet(char const *path, Image* image) | |||
| : m_data(new TileSetData()) | |||
| : TextureImage(path, image) | |||
| { | |||
| Init(path, image); | |||
| array<ivec2, ivec2> tiles; | |||
| if (m_data->m_image->RetrieveTiles(tiles)) | |||
| for (ptrdiff_t i = 0; i < tiles.Count(); i++) | |||
| @@ -73,10 +81,8 @@ TileSet::TileSet(char const *path, Image* image) | |||
| } | |||
| TileSet::TileSet(char const *path, ivec2 size, ivec2 count) | |||
| : m_data(new TileSetData()) | |||
| : TileSet(path) | |||
| { | |||
| Init(path); | |||
| /* If count is valid, fix size; otherwise, fix count. */ | |||
| if (count.x > 0 && count.y > 0) | |||
| { | |||
| @@ -95,18 +101,11 @@ TileSet::TileSet(char const *path, ivec2 size, ivec2 count) | |||
| AddTile(ibox2(size * ivec2(i, j), | |||
| size * ivec2(i + 1, j + 1))); | |||
| } | |||
| array<ivec2, ivec2> tiles; | |||
| if (m_data->m_image->RetrieveTiles(tiles)) | |||
| for (ptrdiff_t i = 0; i < tiles.Count(); i++) | |||
| AddTile(ibox2(tiles[i].m1, tiles[i].m1 + tiles[i].m2)); | |||
| } | |||
| TileSet::TileSet(char const *path, Image* image, ivec2 size, ivec2 count) | |||
| : m_data(new TileSetData()) | |||
| : TileSet(path, image) | |||
| { | |||
| Init(path, image); | |||
| /* If count is valid, fix size; otherwise, fix count. */ | |||
| if (count.x > 0 && count.y > 0) | |||
| { | |||
| @@ -125,38 +124,33 @@ TileSet::TileSet(char const *path, Image* image, ivec2 size, ivec2 count) | |||
| AddTile(ibox2(size * ivec2(i, j), | |||
| size * ivec2(i + 1, j + 1))); | |||
| } | |||
| array<ivec2, ivec2> tiles; | |||
| if (m_data->m_image->RetrieveTiles(tiles)) | |||
| for (ptrdiff_t i = 0; i < tiles.Count(); i++) | |||
| AddTile(ibox2(tiles[i].m1, tiles[i].m1 + tiles[i].m2)); | |||
| } | |||
| void TileSet::Init(char const *path) | |||
| TileSet::~TileSet() | |||
| { | |||
| Init(path, new Image(path)); | |||
| } | |||
| void TileSet::Init(char const *path, Image* image) | |||
| { | |||
| m_data->m_name = String("<tileset> ") + path; | |||
| super::Init(path, image); | |||
| m_palette = nullptr; | |||
| m_data->m_texture = 0; | |||
| m_data->m_image = image; | |||
| m_data->m_image_size = m_data->m_image->GetSize(); | |||
| m_data->m_texture_size = ivec2(PotUp(m_data->m_image_size.x), | |||
| PotUp(m_data->m_image_size.y)); | |||
| m_data->m_name = String("<tileset> ") + path; | |||
| } | |||
| m_drawgroup = DRAWGROUP_BEFORE; | |||
| //Inherited from Entity ------------------------------------------------------- | |||
| char const *TileSet::GetName() | |||
| { | |||
| return m_data->m_name.C(); | |||
| } | |||
| //New methods ----------------------------------------------------------------- | |||
| ptrdiff_t TileSet::AddTile(ibox2 rect) | |||
| { | |||
| m_data->m_tiles.Push(rect, | |||
| box2((vec2)rect.A / (vec2)m_data->m_texture_size, | |||
| (vec2)rect.B / (vec2)m_data->m_texture_size)); | |||
| return m_data->m_tiles.Count() - 1; | |||
| TileSetData* data = GetData(); | |||
| data->m_tiles.Push(rect, | |||
| box2((vec2)rect.A / (vec2)m_data->m_texture_size, | |||
| (vec2)rect.B / (vec2)m_data->m_texture_size)); | |||
| return data->m_tiles.Count() - 1; | |||
| } | |||
| void TileSet::AddTile(ivec2 count) | |||
| @@ -171,100 +165,18 @@ void TileSet::AddTile(ivec2 count) | |||
| } | |||
| } | |||
| TileSet::~TileSet() | |||
| { | |||
| delete m_data; | |||
| } | |||
| void TileSet::TickDraw(float seconds, Scene &scene) | |||
| { | |||
| Entity::TickDraw(seconds, scene); | |||
| if (IsDestroying()) | |||
| { | |||
| if (m_data->m_image) | |||
| { | |||
| delete m_data->m_image; | |||
| m_data->m_image = nullptr; | |||
| } | |||
| else | |||
| { | |||
| delete m_data->m_texture; | |||
| m_data->m_texture = nullptr; | |||
| } | |||
| } | |||
| else if (m_data->m_image) | |||
| { | |||
| PixelFormat format = m_data->m_image->GetFormat(); | |||
| int planes = BytesPerPixel(format); | |||
| int w = m_data->m_texture_size.x; | |||
| int h = m_data->m_texture_size.y; | |||
| uint8_t *pixels = (uint8_t *)m_data->m_image->Lock(); | |||
| bool resized = false; | |||
| if (w != m_data->m_image_size.x || h != m_data->m_image_size.y) | |||
| { | |||
| uint8_t *tmp = new uint8_t[planes * w * h]; | |||
| for (int line = 0; line < m_data->m_image_size.y; line++) | |||
| memcpy(tmp + planes * w * line, | |||
| pixels + planes * m_data->m_image_size.x * line, | |||
| planes * m_data->m_image_size.x); | |||
| pixels = tmp; | |||
| resized = false; | |||
| } | |||
| m_data->m_texture = new Texture(ivec2(w, h), format); | |||
| m_data->m_texture->SetData(pixels); | |||
| if (resized) | |||
| delete[] pixels; | |||
| delete m_data->m_image; | |||
| m_data->m_image = nullptr; | |||
| } | |||
| } | |||
| char const *TileSet::GetName() | |||
| { | |||
| return m_data->m_name.C(); | |||
| } | |||
| ptrdiff_t TileSet::GetTileCount() const | |||
| { | |||
| return m_data->m_tiles.Count(); | |||
| return GetData()->m_tiles.Count(); | |||
| } | |||
| ivec2 TileSet::GetTileSize(ptrdiff_t tileid) const | |||
| { | |||
| ibox2 const &box = m_data->m_tiles[tileid].m1; | |||
| ibox2 const &box = GetData()->m_tiles[tileid].m1; | |||
| return box.B - box.A; | |||
| } | |||
| ivec2 TileSet::GetTextureSize() const | |||
| { | |||
| return m_data->m_texture_size; | |||
| } | |||
| Texture * TileSet::GetTexture() | |||
| { | |||
| return m_data->m_texture; | |||
| } | |||
| Texture const * TileSet::GetTexture() const | |||
| { | |||
| return m_data->m_texture; | |||
| } | |||
| Image * TileSet::GetImage() | |||
| { | |||
| return m_data->m_image; | |||
| } | |||
| Image const * TileSet::GetImage() const | |||
| { | |||
| return m_data->m_image; | |||
| } | |||
| //Palette --------------------------------------------------------------------- | |||
| void TileSet::SetPalette(TileSet* palette) | |||
| { | |||
| m_palette = palette; | |||
| @@ -280,22 +192,12 @@ TileSet const* TileSet::GetPalette() const | |||
| return m_palette; | |||
| } | |||
| void TileSet::Bind() | |||
| { | |||
| if (!m_data->m_image && m_data->m_texture) | |||
| m_data->m_texture->Bind(); | |||
| } | |||
| void TileSet::Unbind() | |||
| { | |||
| ; | |||
| } | |||
| void TileSet::BlitTile(uint32_t id, vec3 pos, int o, vec2 scale, float angle, | |||
| vec3 *vertex, vec2 *texture) | |||
| { | |||
| ibox2 pixels = m_data->m_tiles[id].m1; | |||
| box2 texels = m_data->m_tiles[id].m2; | |||
| TileSetData* data = GetData(); | |||
| ibox2 pixels = data->m_tiles[id].m1; | |||
| box2 texels = data->m_tiles[id].m2; | |||
| float dtx = texels.B.x - texels.A.x; | |||
| float dty = texels.B.y - texels.A.y; | |||
| float tx = texels.A.x; | |||
| @@ -18,59 +18,60 @@ | |||
| // zero, the texture is freed. | |||
| // | |||
| /* | |||
| #include <lol/image/image.h> | |||
| #include <lol/gpu/texture.h> | |||
| #include <stdint.h> | |||
| #include "entity.h" | |||
| */ | |||
| #include "textureimage.h" | |||
| namespace lol | |||
| { | |||
| class TextureImageData; | |||
| class TileSetData; | |||
| class TileSet : public Entity | |||
| class TileSet : public TextureImage | |||
| { | |||
| typedef TextureImage super; | |||
| protected: | |||
| virtual TextureImageData* GetNewData(); | |||
| TileSetData* GetData(); | |||
| TileSetData const* GetData() const; | |||
| public: | |||
| TileSet(char const *path); | |||
| TileSet(char const *path, Image* image); | |||
| virtual ~TileSet(); | |||
| /* Old style: path to PNG file */ | |||
| TileSet(char const *path, ivec2 size, ivec2 count); | |||
| TileSet(char const *path, Image* image, ivec2 size, ivec2 count); | |||
| virtual ~TileSet(); | |||
| /* Inherited from Entity */ | |||
| virtual char const *GetName(); | |||
| protected: | |||
| virtual void TickDraw(float seconds, Scene &scene); | |||
| virtual void Init(char const *path, Image* image); | |||
| public: | |||
| /* Inherited from Entity */ | |||
| virtual char const *GetName(); | |||
| /* New methods */ | |||
| ptrdiff_t AddTile(ibox2 rect); | |||
| void AddTile(ivec2 count); | |||
| ptrdiff_t GetTileCount() const; | |||
| ivec2 GetTileSize(ptrdiff_t tileid) const; | |||
| Texture * GetTexture(); | |||
| Texture const * GetTexture() const; | |||
| Image * GetImage(); | |||
| Image const * GetImage() const; | |||
| void SetPalette(TileSet* palette); | |||
| TileSet* GetPalette(); | |||
| TileSet const * GetPalette() const; | |||
| ivec2 GetTextureSize() const; | |||
| void Bind(); | |||
| void Unbind(); | |||
| void BlitTile(uint32_t id, vec3 pos, int o, vec2 scale, float angle, | |||
| vec3 *vertex, vec2 *texture); | |||
| private: | |||
| void Init(char const *path); | |||
| void Init(char const *path, Image* image); | |||
| TileSetData* m_data; | |||
| protected: | |||
| TileSet* m_palette; | |||
| }; | |||