From aa3f63fd497558a02feb3ddbc44f31eac091f39b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 10 Oct 2017 22:14:45 +0300 Subject: Remove most unused files. --- src/render/graphics.cpp | 775 ----------- src/render/graphics.h | 557 -------- src/render/graphics_calcImageRect.hpp | 94 -- src/render/graphics_drawImageRect.hpp | 83 -- src/render/graphicsdef.hpp | 154 -- src/render/imagegraphics.cpp | 64 - src/render/imagegraphics.h | 208 --- src/render/mobileopengl2graphics.cpp | 1389 ------------------ src/render/mobileopengl2graphics.h | 164 --- src/render/mobileopenglgraphics.cpp | 1385 ------------------ src/render/mobileopenglgraphics.h | 115 -- src/render/modernopenglgraphics.cpp | 1403 ------------------- src/render/modernopenglgraphics.h | 159 --- src/render/nacl/naclfunctions.h | 35 - src/render/nacl/naclgles.cpp | 55 - src/render/nacl/naclgles.h | 32 - src/render/normalopenglgraphics.cpp | 1782 ------------------------ src/render/normalopenglgraphics.h | 133 -- src/render/nullopenglgraphics.cpp | 1251 ----------------- src/render/nullopenglgraphics.h | 111 -- src/render/opengl/mgl.cpp | 34 - src/render/opengl/mgl.h | 38 - src/render/opengl/mgl.hpp | 144 -- src/render/opengl/mglcheck.h | 30 - src/render/opengl/mgldefines.h | 136 -- src/render/opengl/mglemu.cpp | 54 - src/render/opengl/mglemu.h | 41 - src/render/opengl/mglfunctions.h | 101 -- src/render/opengl/mgltypes.h | 226 --- src/render/opengl/naclglfunctions.h | 322 ----- src/render/opengl/opengldebug.h | 38 - src/render/openglgraphicsdef.hpp | 58 - src/render/openglgraphicsdef1.hpp | 30 - src/render/openglgraphicsdefadvanced.hpp | 43 - src/render/openglx/mglx.cpp | 34 - src/render/openglx/mglx.h | 35 - src/render/openglx/mglx.hpp | 29 - src/render/openglx/mglxinit.cpp | 42 - src/render/openglx/mglxinit.h | 32 - src/render/openglx/mglxtypes.h | 41 - src/render/renderers.cpp | 117 -- src/render/renderers.h | 32 - src/render/rendererslistsdl.h | 176 --- src/render/rendererslistsdl2.h | 184 --- src/render/safeopenglgraphics.cpp | 763 ---------- src/render/safeopenglgraphics.h | 80 -- src/render/sdl2graphics.cpp | 789 ----------- src/render/sdl2graphics.h | 116 -- src/render/sdl2softwaregraphics.cpp | 1530 -------------------- src/render/sdl2softwaregraphics.h | 89 -- src/render/sdlgraphics.cpp | 1518 -------------------- src/render/sdlgraphics.h | 75 - src/render/shaders/shader.cpp | 41 - src/render/shaders/shader.h | 45 - src/render/shaders/shaderprogram.cpp | 54 - src/render/shaders/shaderprogram.h | 51 - src/render/shaders/shadersmanager.cpp | 146 -- src/render/shaders/shadersmanager.h | 57 - src/render/softwaregraphicsdef.hpp | 27 - src/render/surfacegraphics.cpp | 156 --- src/render/surfacegraphics.h | 218 --- src/render/vertexes/imagecollection.cpp | 52 - src/render/vertexes/imagecollection.h | 52 - src/render/vertexes/imagevertexes.cpp | 41 - src/render/vertexes/imagevertexes.h | 59 - src/render/vertexes/openglgraphicsvertexes.cpp | 225 --- src/render/vertexes/openglgraphicsvertexes.h | 109 -- 67 files changed, 18259 deletions(-) delete mode 100644 src/render/graphics.cpp delete mode 100644 src/render/graphics.h delete mode 100644 src/render/graphics_calcImageRect.hpp delete mode 100644 src/render/graphics_drawImageRect.hpp delete mode 100644 src/render/graphicsdef.hpp delete mode 100644 src/render/imagegraphics.cpp delete mode 100644 src/render/imagegraphics.h delete mode 100644 src/render/mobileopengl2graphics.cpp delete mode 100644 src/render/mobileopengl2graphics.h delete mode 100644 src/render/mobileopenglgraphics.cpp delete mode 100644 src/render/mobileopenglgraphics.h delete mode 100644 src/render/modernopenglgraphics.cpp delete mode 100644 src/render/modernopenglgraphics.h delete mode 100644 src/render/nacl/naclfunctions.h delete mode 100644 src/render/nacl/naclgles.cpp delete mode 100644 src/render/nacl/naclgles.h delete mode 100644 src/render/normalopenglgraphics.cpp delete mode 100644 src/render/normalopenglgraphics.h delete mode 100644 src/render/nullopenglgraphics.cpp delete mode 100644 src/render/nullopenglgraphics.h delete mode 100644 src/render/opengl/mgl.cpp delete mode 100644 src/render/opengl/mgl.h delete mode 100644 src/render/opengl/mgl.hpp delete mode 100644 src/render/opengl/mglcheck.h delete mode 100644 src/render/opengl/mgldefines.h delete mode 100644 src/render/opengl/mglemu.cpp delete mode 100644 src/render/opengl/mglemu.h delete mode 100644 src/render/opengl/mglfunctions.h delete mode 100644 src/render/opengl/mgltypes.h delete mode 100644 src/render/opengl/naclglfunctions.h delete mode 100644 src/render/opengl/opengldebug.h delete mode 100644 src/render/openglgraphicsdef.hpp delete mode 100644 src/render/openglgraphicsdef1.hpp delete mode 100644 src/render/openglgraphicsdefadvanced.hpp delete mode 100644 src/render/openglx/mglx.cpp delete mode 100644 src/render/openglx/mglx.h delete mode 100644 src/render/openglx/mglx.hpp delete mode 100644 src/render/openglx/mglxinit.cpp delete mode 100644 src/render/openglx/mglxinit.h delete mode 100644 src/render/openglx/mglxtypes.h delete mode 100644 src/render/renderers.cpp delete mode 100644 src/render/renderers.h delete mode 100644 src/render/rendererslistsdl.h delete mode 100644 src/render/rendererslistsdl2.h delete mode 100644 src/render/safeopenglgraphics.cpp delete mode 100644 src/render/safeopenglgraphics.h delete mode 100644 src/render/sdl2graphics.cpp delete mode 100644 src/render/sdl2graphics.h delete mode 100644 src/render/sdl2softwaregraphics.cpp delete mode 100644 src/render/sdl2softwaregraphics.h delete mode 100644 src/render/sdlgraphics.cpp delete mode 100644 src/render/sdlgraphics.h delete mode 100644 src/render/shaders/shader.cpp delete mode 100644 src/render/shaders/shader.h delete mode 100644 src/render/shaders/shaderprogram.cpp delete mode 100644 src/render/shaders/shaderprogram.h delete mode 100644 src/render/shaders/shadersmanager.cpp delete mode 100644 src/render/shaders/shadersmanager.h delete mode 100644 src/render/softwaregraphicsdef.hpp delete mode 100644 src/render/surfacegraphics.cpp delete mode 100644 src/render/surfacegraphics.h delete mode 100644 src/render/vertexes/imagecollection.cpp delete mode 100644 src/render/vertexes/imagecollection.h delete mode 100644 src/render/vertexes/imagevertexes.cpp delete mode 100644 src/render/vertexes/imagevertexes.h delete mode 100644 src/render/vertexes/openglgraphicsvertexes.cpp delete mode 100644 src/render/vertexes/openglgraphicsvertexes.h (limited to 'src/render') diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp deleted file mode 100644 index 09a21fff1..000000000 --- a/src/render/graphics.cpp +++ /dev/null @@ -1,775 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "render/graphics.h" - -#ifdef USE_OPENGL -#include "configuration.h" -#include "graphicsmanager.h" -#endif // USE_OPENGL - -#if defined(USE_OPENGL) && defined(USE_X11) -#include "render/openglx/mglxinit.h" -#endif // defined(USE_OPENGL) && defined(USE_X11) - -#ifdef USE_OPENGL -#include "resources/openglimagehelper.h" -#ifndef ANDROID -#include "resources/safeopenglimagehelper.h" -#endif // ANDROID -#ifdef __native_client__ -#include "render/nacl/naclfunctions.h" -#include "render/nacl/naclgles.h" -#endif // __native_client__ -#else // USE_OPENGL -#ifndef USE_SDL2 -#include "resources/imagehelper.h" -#endif // USE_SDL2 -#endif // USE_OPENGL - -#ifdef USE_OPENGL -#ifdef __APPLE__ -#include -#endif // __APPLE__ -#include "render/opengl/mgldefines.h" -RENDER_OPENGL_MGLDEFINES_H -#endif // USE_OPENGL - -#include "debug.h" - -#ifdef USE_OPENGL -#ifndef GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX -#define GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049 -#endif // GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX -#endif // USE_OPENGL - -Graphics *mainGraphics A_NONNULLPOINTER = nullptr; - -#ifdef USE_SDL2 -SDL_Renderer *restrict Graphics::mRenderer = nullptr; -#endif // USE_SDL2 -#ifdef USE_OPENGL -#ifdef USE_SDL2 -SDL_GLContext Graphics::mGLContext = nullptr; -#else // USE_SDL2 - -void *restrict Graphics::mGLContext = nullptr; -#endif // USE_SDL2 -#endif // USE_OPENGL - -Graphics::Graphics() : - mWidth(0), - mHeight(0), - mActualWidth(0), - mActualHeight(0), - mClipStack(1000), - mWindow(nullptr), - mBpp(0), - mAlpha(false), - mFullscreen(false), - mHWAccel(false), - mRedraw(false), - mDoubleBuffer(false), - mRect(), - mSecure(false), - mOpenGL(RENDER_SOFTWARE), - mEnableResize(false), - mNoFrame(false), - mAllowHighDPI(false), - mName("Unknown"), - mStartFreeMem(0), - mSync(false), - mScale(1), - mColor() -{ - mRect.x = 0; - mRect.y = 0; - mRect.w = 0; - mRect.h = 0; -} - -Graphics::~Graphics() -{ - endDraw(); -} - -void Graphics::cleanUp() -{ -#ifdef USE_SDL2 - if (mRenderer) - { - SDL_DestroyRenderer(mRenderer); - mRenderer = nullptr; - } -#ifdef USE_OPENGL - if (mGLContext) - { - SDL_GL_DeleteContext(mGLContext); - mGLContext = nullptr; - } -#endif // USE_OPENGL -#endif // USE_SDL2 -} - -void Graphics::setSync(const bool sync) restrict2 -{ - mSync = sync; -} - -void Graphics::setMainFlags(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - logger->log("graphics backend: %s", getName().c_str()); - logger->log("Setting video mode %dx%d %s", - w, h, fs ? "fullscreen" : "windowed"); - - mBpp = bpp; - mFullscreen = fs; - mHWAccel = hwaccel; - mEnableResize = resize; - mNoFrame = noFrame; - mAllowHighDPI = allowHighDPI; - mActualWidth = w; - mActualHeight = h; - setScale(scale); -} - -void Graphics::setScale(int scale) restrict2 -{ - if (isAllowScale()) - { - if (scale == 0) - scale = 1; - int scaleW = mActualWidth / scale; - int scaleH = mActualHeight / scale; - if (scaleW < 470) - { - scale = mActualWidth / 470; - if (scale < 1) - scale = 1; - scaleH = mActualHeight / scale; - } - if (scaleH < 320) - { - scale = mActualHeight / 320; - if (scale < 1) - scale = 1; - } - logger->log("set scale: %d", scale); - mScale = scale; - mWidth = mActualWidth / mScale; - mHeight = mActualHeight / mScale; - } - else - { - mScale = 1; - mWidth = mActualWidth; - mHeight = mActualHeight; - } - mRect.w = static_cast(mWidth); - mRect.h = static_cast(mHeight); -} - -int Graphics::getOpenGLFlags() const restrict2 -{ -#ifdef USE_OPENGL - -#ifdef USE_SDL2 - int displayFlags = SDL_WINDOW_OPENGL; - if (mFullscreen) - displayFlags |= SDL_WINDOW_FULLSCREEN; -#if SDL_VERSION_ATLEAST(2, 0, 1) - if (mAllowHighDPI) - displayFlags |= SDL_WINDOW_ALLOW_HIGHDPI; -#endif // SDL_VERSION_ATLEAST(2, 0, 1) -#else // USE_SDL2 - - int displayFlags = SDL_ANYFORMAT | SDL_OPENGL; -#endif // USE_SDL2 - - if (mFullscreen) - { - displayFlags |= SDL_FULLSCREEN; - } - else - { - // Resizing currently not supported on Windows, where it would require - // reuploading all textures. -#if !defined(_WIN32) - if (mEnableResize) - displayFlags |= SDL_RESIZABLE; -#endif // !defined(_WIN32) - } - - if (mNoFrame) - displayFlags |= SDL_NOFRAME; - - return displayFlags; -#else // USE_OPENGL - - return 0; -#endif // USE_OPENGL -} - -bool Graphics::setOpenGLMode() restrict2 -{ -#ifdef USE_OPENGL - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if ((mWindow = graphicsManager.createWindow( - mActualWidth, mActualHeight, - mBpp, getOpenGLFlags())) == nullptr) - { - logger->log("Window/context creation failed"); - mRect.w = 0; - mRect.h = 0; - return false; - } - -#if defined(USE_X11) - Glx::initFunctions(); -#endif // defined(USE_X11) -#ifdef __native_client__ - NaclGles::initGles(); -#endif // __native_client__ - -#ifdef USE_SDL2 - int w1 = 0; - int h1 = 0; - SDL_GetWindowSize(mWindow, &w1, &h1); - mRect.w = CAST_S32(w1 / mScale); - mRect.h = CAST_S32(h1 / mScale); - - createGLContext(config.getBoolValue("openglContext")); -#else // USE_SDL2 - - createGLContext(config.getBoolValue("openglContext")); - mRect.w = CAST_U16(mWindow->w / mScale); - mRect.h = CAST_U16(mWindow->h / mScale); - -#endif // USE_SDL2 - -#ifdef __APPLE__ - if (mSync) - { - const GLint VBL = 1; - CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); - } -#endif // __APPLE__ - - graphicsManager.setGLVersion(); - graphicsManager.logVersion(); - - // Setup OpenGL - glViewport(0, 0, mActualWidth, mActualHeight); - int gotDoubleBuffer = 0; - SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer); - logger->log("Using OpenGL %s double buffering.", - (gotDoubleBuffer != 0 ? "with" : "without")); - - graphicsManager.initOpenGL(); - initArrays(graphicsManager.getMaxVertices()); - graphicsManager.updateTextureCompressionFormat(); - graphicsManager.updateTextureFormat(); - updateMemoryInfo(); - - GLint texSize; - bool rectTex = graphicsManager.supportExtension( - "GL_ARB_texture_rectangle") || - graphicsManager.supportExtension("GL_EXT_texture_rectangle"); - - if (rectTex - && OpenGLImageHelper::getInternalTextureType() == 4 - && getOpenGL() != RENDER_GLES_OPENGL - && getOpenGL() != RENDER_GLES2_OPENGL - && getOpenGL() != RENDER_MODERN_OPENGL - && config.getBoolValue("rectangulartextures") - && !graphicsManager.isUseTextureSampler()) - { - logger->log1("using GL_ARB_texture_rectangle"); - OpenGLImageHelper::mTextureType = GL_TEXTURE_RECTANGLE_ARB; - glEnable(GL_TEXTURE_RECTANGLE_ARB); - glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize); - OpenGLImageHelper::mTextureSize = texSize; - logger->log("OpenGL texture size: %d pixels (rectangle textures)", - OpenGLImageHelper::mTextureSize); -#ifndef ANDROID - SafeOpenGLImageHelper::mTextureType = GL_TEXTURE_RECTANGLE_ARB; - SafeOpenGLImageHelper::mTextureSize = texSize; -#endif // ANDROID - } - else - { - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); - OpenGLImageHelper::mTextureType = GL_TEXTURE_2D; - OpenGLImageHelper::mTextureSize = texSize; -#ifndef ANDROID - SafeOpenGLImageHelper::mTextureType = GL_TEXTURE_2D; - SafeOpenGLImageHelper::mTextureSize = texSize; -#endif // ANDROID - - logger->log("OpenGL texture size: %d pixels", - OpenGLImageHelper::mTextureSize); - } - return videoInfo(); -#else // USE_OPENGL - - return false; -#endif // USE_OPENGL -} - -int Graphics::getSoftwareFlags() const restrict2 -{ -#ifdef USE_SDL2 - int displayFlags = SDL_WINDOW_SHOWN; -#if SDL_VERSION_ATLEAST(2, 0, 1) - if (mAllowHighDPI) - displayFlags |= SDL_WINDOW_ALLOW_HIGHDPI; -#endif // SDL_VERSION_ATLEAST(2, 0, 1) -#else // USE_SDL2 - - int displayFlags = SDL_ANYFORMAT; - - if (mHWAccel) - displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; - else - displayFlags |= SDL_SWSURFACE; -#endif // USE_SDL2 - - if (mFullscreen) - displayFlags |= SDL_FULLSCREEN; - else if (mEnableResize) - displayFlags |= SDL_RESIZABLE; - - if (mNoFrame) - displayFlags |= SDL_NOFRAME; - return displayFlags; -} - -#ifdef USE_OPENGL -void Graphics::createGLContext(const bool custom A_UNUSED) restrict2 -{ -#ifdef USE_SDL2 - mGLContext = SDL_GL_CreateContext(mWindow); -#endif // USE_SDL2 -} -#endif // USE_OPENGL - -void Graphics::updateMemoryInfo() restrict2 -{ -#ifdef USE_OPENGL - if (mStartFreeMem != 0) - return; - - if (graphicsManager.supportExtension("GL_NVX_gpu_memory_info")) - { - glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, - &mStartFreeMem); - logger->log("free video memory: %d", mStartFreeMem); - } -#endif // USE_OPENGL -} - -int Graphics::getMemoryUsage() const restrict2 -{ -#ifdef USE_OPENGL - if (mStartFreeMem == 0) - return 0; - - if (graphicsManager.supportExtension("GL_NVX_gpu_memory_info")) - { - GLint val; - glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, - &val); - return mStartFreeMem - val; - } -#endif // USE_OPENGL - return 0; -} - -#ifdef USE_SDL2 -void Graphics::dumpRendererInfo(const char *restrict const str, - const SDL_RendererInfo &restrict info) - restrict2 -{ - logger->log(str, info.name); - logger->log("flags:"); - if (info.flags & SDL_RENDERER_SOFTWARE) - logger->log(" software"); - if (info.flags & SDL_RENDERER_ACCELERATED) - logger->log(" accelerated"); - if (info.flags & SDL_RENDERER_PRESENTVSYNC) - logger->log(" vsync"); - if (info.flags & SDL_RENDERER_TARGETTEXTURE) - logger->log(" texture target"); - logger->log("max texture size: %d,%d", - info.max_texture_width, - info.max_texture_height); - const size_t sz = CAST_SIZE(info.num_texture_formats); - logger->log("texture formats:"); - for (size_t f = 0; f < sz; f ++) - logger->log(" %u", info.texture_formats[f]); -} -#endif // USE_SDL2 - -bool Graphics::videoInfo() restrict2 -{ - logger->log("SDL video info"); -#ifdef USE_SDL2 - logger->log("Using video driver: %s", SDL_GetCurrentVideoDriver()); - - if (mRenderer) - { - SDL_RendererInfo info; - SDL_GetRendererInfo(mRenderer, &info); - dumpRendererInfo("Current SDL renderer name: %s", info); - - const int num = SDL_GetNumRenderDrivers(); - logger->log("Known renderers"); - for (int f = 0; f < num; f ++) - { - if (!SDL_GetRenderDriverInfo(f, &info)) - dumpRendererInfo("renderer name: %s", info); - } - } -#else // USE_SDL2 - - char videoDriverName[65]; - if (SDL_VideoDriverName(videoDriverName, 64) != nullptr) - logger->log("Using video driver: %s", videoDriverName); - else - logger->log1("Using video driver: unknown"); - mDoubleBuffer = ((mWindow->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF); - logger->log("Double buffer mode: %s", mDoubleBuffer ? "yes" : "no"); - - ImageHelper::dumpSurfaceFormat(mWindow); - - const SDL_VideoInfo *restrict const vi = SDL_GetVideoInfo(); - if (vi == nullptr) - return false; - - logger->log("Possible to create hardware surfaces: %s", - ((vi->hw_available) != 0u ? "yes" : "no")); - logger->log("Window manager available: %s", - ((vi->wm_available) != 0u ? "yes" : "no")); - logger->log("Accelerated hardware to hardware blits: %s", - ((vi->blit_hw) != 0u ? "yes" : "no")); - logger->log("Accelerated hardware to hardware colorkey blits: %s", - ((vi->blit_hw_CC) != 0u ? "yes" : "no")); - logger->log("Accelerated hardware to hardware alpha blits: %s", - ((vi->blit_hw_A) != 0u ? "yes" : "no")); - logger->log("Accelerated software to hardware blits: %s", - ((vi->blit_sw) != 0u ? "yes" : "no")); - logger->log("Accelerated software to hardware colorkey blits: %s", - ((vi->blit_sw_CC) != 0u ? "yes" : "no")); - logger->log("Accelerated software to hardware alpha blits: %s", - ((vi->blit_sw_A) != 0u ? "yes" : "no")); - logger->log("Accelerated color fills: %s", - ((vi->blit_fill) != 0u ? "yes" : "no")); -#endif // USE_SDL2 - - return true; -} - -bool Graphics::setFullscreen(const bool fs) restrict2 -{ - if (mFullscreen == fs) - return true; - - return setVideoMode(mActualWidth, - mActualHeight, - mScale, - mBpp, - fs, - mHWAccel, - mEnableResize, - mNoFrame, - mAllowHighDPI); -} - -bool Graphics::resizeScreen(const int width, - const int height) restrict2 -{ -#ifdef USE_SDL2 - endDraw(); - - mRect.w = CAST_S32(width / mScale); - mRect.h = CAST_S32(height / mScale); - mWidth = width / mScale; - mHeight = height / mScale; - mActualWidth = width; - mActualHeight = height; - -#ifdef USE_OPENGL - // +++ probably this way will not work in windows/mac - // Setup OpenGL - glViewport(0, 0, mActualWidth, mActualHeight); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); -#else // USE_OPENGL - // +++ need impliment resize in soft mode -#endif // USE_OPENGL - - screenResized(); - beginDraw(); - return true; - -#else // USE_SDL2 - - const int prevWidth = mWidth; - const int prevHeight = mHeight; - - endDraw(); - - bool success = true; -#ifdef __native_client__ - if (mOpenGL != RENDER_SOFTWARE) - { - mRect.w = CAST_S32(width / mScale); - mRect.h = CAST_S32(height / mScale); - mWidth = width / mScale; - mHeight = height / mScale; - mActualWidth = width; - mActualHeight = height; -#ifdef USE_OPENGL - naclResizeBuffers(mActualWidth, mActualHeight); - glViewport(0, 0, mActualWidth, mActualHeight); -#endif // USE_OPENGL - } - else -#endif // __native_client__ - { - success = setVideoMode(width, height, - mScale, - mBpp, - mFullscreen, - mHWAccel, - mEnableResize, - mNoFrame, - mAllowHighDPI); - - // If it didn't work, try to restore the previous size. If that didn't - // work either, bail out (but then we're in deep trouble). - if (!success) - { - if (!setVideoMode(prevWidth, prevHeight, - mScale, - mBpp, - mFullscreen, - mHWAccel, - mEnableResize, - mNoFrame, - mAllowHighDPI)) - { - return false; - } - } - } - - screenResized(); - beginDraw(); - - return success; -#endif // USE_SDL2 -} - -int Graphics::getWidth() const restrict2 -{ - return mWidth; -} - -int Graphics::getHeight() const restrict2 -{ - return mHeight; -} - -void Graphics::drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) restrict2 -{ - for (int y = y1; y < y2; y += height) - drawLine(x1, y, x2, y); - - for (int x = x1; x < x2; x += width) - drawLine(x, y1, x, y2); -} - -#ifdef USE_SDL2 -void Graphics::setWindowSize(const int width, - const int height) restrict2 -{ - SDL_SetWindowSize(mWindow, width, height); -} -#else // USE_SDL2 -void Graphics::setWindowSize(const int width A_UNUSED, - const int height A_UNUSED) restrict2 -{ -} -#endif // USE_SDL2 - -void Graphics::pushClipArea(const Rect &restrict area) restrict2 -{ - // Ignore area with a negate width or height - // by simple pushing an empty clip area - // to the stack. - if (area.width < 0 || area.height < 0) - { - ClipRect &carea = mClipStack.push(); - carea.x = 0; - carea.y = 0; - carea.width = 0; - carea.height = 0; - carea.xOffset = 0; - carea.yOffset = 0; - return; - } - - if (mClipStack.empty()) - { - ClipRect &carea = mClipStack.push(); - carea.x = area.x; - carea.y = area.y; - carea.width = area.width; - carea.height = area.height; - carea.xOffset = area.x; - carea.yOffset = area.y; - return; - } - - const ClipRect &top = mClipStack.top(); - ClipRect &carea = mClipStack.push(); - carea.x = area.x + top.xOffset; - carea.y = area.y + top.yOffset; - carea.width = area.width; - carea.height = area.height; - carea.xOffset = top.xOffset + area.x; - carea.yOffset = top.yOffset + area.y; - - // Clamp the pushed clip rectangle. - if (carea.x < top.x) - carea.x = top.x; - - if (carea.y < top.y) - carea.y = top.y; - - if (carea.x + carea.width > top.x + top.width) - { - carea.width = top.x + top.width - carea.x; - - if (carea.width < 0) - carea.width = 0; - } - - if (carea.y + carea.height > top.y + top.height) - { - carea.height = top.y + top.height - carea.y; - - if (carea.height < 0) - carea.height = 0; - } -} - -void Graphics::popClipArea() restrict2 -{ - if (mClipStack.empty()) - return; - - mClipStack.pop(); -} - -#ifdef USE_OPENGL -void Graphics::setOpenGLFlags() restrict2 -{ - // here disable/enable probably need convert to mgl - - glEnable(GL_SCISSOR_TEST); - - glDisable(GL_MULTISAMPLE); - glDisable(GL_DITHER); - glDisable(GL_DEPTH_TEST); - glDisable(GL_LINE_SMOOTH); - glDisable(GL_POLYGON_SMOOTH); - glDisable(GL_STENCIL_TEST); - glDisable(GL_COLOR_LOGIC_OP); - glDisable(GL_DEPTH_BOUNDS_TEST_EXT); - glDisable(GL_DEPTH_CLAMP); - glDisable(GL_RASTERIZER_DISCARD); - glDisable(GL_SAMPLE_MASK); - -#ifndef ANDROID -#ifndef __MINGW32__ - glHint(GL_TEXTURE_COMPRESSION_HINT, GL_FASTEST); -#endif // __MINGW32__ -#endif // ANDROID - - glHint(GL_TEXTURE_COMPRESSION_HINT_ARB, GL_FASTEST); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -} -#endif // USE_OPENGL diff --git a/src/render/graphics.h b/src/render/graphics.h deleted file mode 100644 index 87f2f1429..000000000 --- a/src/render/graphics.h +++ /dev/null @@ -1,557 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef RENDER_GRAPHICS_H -#define RENDER_GRAPHICS_H - -#include "sdlshared.h" - -#include "enums/render/rendertype.h" - -#include "gui/color.h" -#include "gui/cliprect.h" - -#include "resources/mstack.h" - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifdef USE_SDL2 -#include -#else // USE_SDL2 -#include -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic pop) - -#include "localconsts.h" - -#ifdef USE_SDL2 -#define RectPos int32_t -#define RectSize int32_t -#else // USE_SDL2 -#define RectPos int16_t -#define RectSize uint16_t -#endif // USE_SDL2 - -class Image; -class ImageCollection; -class ImageRect; -class ImageVertexes; - -struct SDL_Window; - -/** - * A central point of control for graphics. - */ -class Graphics notfinal -{ - public: -#ifdef USE_OPENGL - friend class OpenGLScreenshotHelper; -#endif // USE_SDL2 - - friend class SdlScreenshotHelper; - - A_DELETE_COPY(Graphics) - - /** - * Destructor. - */ - virtual ~Graphics(); - - static void cleanUp(); - - /** - * Alignments for text drawing. - */ - enum Alignment - { - LEFT = 0, - CENTER, - RIGHT - }; - - void setWindow(SDL_Window *restrict const window, - const int width, const int height) restrict2 noexcept2 - { - mWindow = window; - mRect.w = static_cast(width); - mRect.h = static_cast(height); - } - - SDL_Window *getWindow() const restrict2 noexcept2 - { return mWindow; } - - /** - * Sets whether vertical refresh syncing is enabled. Takes effect after - * the next call to setVideoMode(). Only implemented on MacOS for now. - */ - void setSync(const bool sync) restrict2; - - bool getSync() const restrict2 noexcept2 A_WARN_UNUSED - { return mSync; } - - /** - * Try to create a window with the given settings. - */ - virtual bool setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 = 0; - - /** - * Set fullscreen mode. - */ - bool setFullscreen(const bool fs) restrict2; - - /** - * Resize the window to the specified size. - */ - virtual bool resizeScreen(const int width, - const int height) restrict2; - - virtual void restoreContext() restrict2 - { } - - /** - * Draws a resclaled version of the image - */ - virtual void drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 = 0; - - virtual void drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 = 0; - - /** - * Draw a pattern based on a rescaled version of the given image... - */ - virtual void drawRescaledPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) restrict2 = 0; - - virtual void drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 = 0; - - virtual void calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 = 0; - - virtual void calcPattern(ImageCollection *restrict const vert, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 = 0; - - virtual void calcTileVertexes(ImageVertexes *restrict const vert, - const Image *restrict const image, - int x, - int y) const restrict2 A_NONNULL(2, 3) - = 0; - - virtual void calcTileSDL(ImageVertexes *restrict const vert A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) const restrict2 - { - } - - virtual void drawTileVertexes(const ImageVertexes *restrict const vert) - restrict2 = 0; - - virtual void drawTileCollection(const ImageCollection - *restrict const vertCol) restrict2 - A_NONNULL(2) = 0; - - virtual void calcTileCollection(ImageCollection *restrict const - vertCol, - const Image *restrict const image, - int x, - int y) restrict2 = 0; - - virtual void calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 A_NONNULL(2) = 0; - - virtual void fillRectangle(const Rect &restrict rectangle) - restrict2 = 0; - - /** - * Updates the screen. This is done by either copying the buffer to the - * screen or swapping pages. - */ - virtual void updateScreen() restrict2 = 0; - - void setWindowSize(const int width, -#ifdef USE_SDL2 - const int height) restrict2; -#else // USE_SDL2 - const int height) restrict2 A_CONST; -#endif // USE_SDL2 - - /** - * Returns the width of the screen. - */ - int getWidth() const restrict2 A_WARN_UNUSED; - - /** - * Returns the height of the screen. - */ - int getHeight() const restrict2 A_WARN_UNUSED; - - int getMemoryUsage() const restrict2 A_WARN_UNUSED; - - virtual void drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) restrict2; - - ClipRect &getTopClip() const restrict2 A_WARN_UNUSED - { return mClipStack.top(); } - - void setRedraw(const bool n) restrict2 noexcept2 - { mRedraw = n; } - - bool getRedraw() const restrict2 noexcept2 A_WARN_UNUSED - { return mRedraw; } - - void setSecure(const bool n) restrict2 noexcept2 - { mSecure = n; } - - bool getSecure() const restrict2 noexcept2 A_WARN_UNUSED - { return mSecure; } - - int getBpp() const restrict2 noexcept2 A_WARN_UNUSED - { return mBpp; } - - bool getFullScreen() const restrict2 noexcept2 A_WARN_UNUSED - { return mFullscreen; } - - bool getHWAccel() const restrict2 noexcept2 A_WARN_UNUSED - { return mHWAccel; } - - bool getDoubleBuffer() const restrict2 noexcept2 A_WARN_UNUSED - { return mDoubleBuffer; } - - RenderType getOpenGL() const restrict2 noexcept2 A_WARN_UNUSED - { return mOpenGL; } - - void setNoFrame(const bool n) restrict2 noexcept2 - { mNoFrame = n; } - - const std::string &getName() const restrict2 noexcept2 A_WARN_UNUSED - { return mName; } - - virtual void initArrays(const int vertCount A_UNUSED) restrict2 - { } - - virtual void setColor(const Color &restrict color) restrict2 - { - mColor = color; - mAlpha = (color.a != 255); - } - - const Color &getColor() const restrict2 noexcept2 - { return mColor; } - -#ifdef DEBUG_DRAW_CALLS - virtual unsigned int getDrawCalls() const restrict2 - { return 0; } -#endif // DEBUG_DRAW_CALLS -#ifdef DEBUG_BIND_TEXTURE - virtual unsigned int getBinds() const restrict2 - { return 0; } -#endif // DEBUG_BIND_TEXTURE -#ifdef USE_SDL2 - void dumpRendererInfo(const char *restrict const str, - const SDL_RendererInfo &restrict info) restrict2; - - virtual void setRendererFlags(const uint32_t flags A_UNUSED) restrict2 - { } -#endif // USE_SDL2 - - /** - * Blits an image onto the screen. - * - * @return true if the image was blitted properly - * false otherwise. - */ - virtual void drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 = 0; - - virtual void copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 = 0; - - virtual void drawImageCached(const Image *restrict const image, - int srcX, int srcY) restrict2 = 0; - - virtual void drawPatternCached(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 = 0; - - virtual void completeCache() restrict2 = 0; - - int getScale() const restrict2 noexcept2 - { return mScale; } - - virtual bool isAllowScale() const restrict2 noexcept2 - { return false; } - - void setScale(int scale) restrict2; - - /** - * Pushes a clip area onto the stack. The x and y coordinates in the - * rectangle is relative to the last pushed clip area. - * If the new area falls outside the current clip area, it will be - * clipped as necessary. - * - * If a clip area is outside of the top clip area a clip area with - * zero width and height will be pushed. - * - * @param area The clip area to be pushed onto the stack. - */ - virtual void pushClipArea(const Rect &restrict area) restrict2; - - /** - * Removes the top most clip area from the stack. - * - * @throws Exception if the stack is empty. - */ - virtual void popClipArea() restrict2; - - /** - * Ddraws a line. - * - * @param x1 The first x coordinate. - * @param y1 The first y coordinate. - * @param x2 The second x coordinate. - * @param y2 The second y coordinate. - */ - virtual void drawLine(int x1, int y1, - int x2, int y2) restrict2 = 0; - - /** - * Draws a simple, non-filled, rectangle with a one pixel width. - * - * @param rectangle The rectangle to draw. - */ - virtual void drawRectangle(const Rect &restrict rectangle) - restrict2 = 0; - -#ifdef USE_OPENGL -#ifdef USE_SDL2 - virtual void createGLContext(const bool custom) restrict2; -#else // USE_SDL2 - - virtual void createGLContext(const bool custom) restrict2 A_CONST; -#endif // USE_SDL2 -#endif // USE_OPENGL - - /** - * Draws a single point/pixel. - * - * @param x The x coordinate. - * @param y The y coordinate. - */ - virtual void drawPoint(int x, int y) restrict2 = 0; - - /** - * Initializes drawing. Called by the Gui when Gui::draw() is called. - * It is needed by some implementations of Graphics to perform - * preparations before drawing. An example of such an implementation - * is the OpenGLGraphics. - * - * NOTE: You will never need to call this function yourself, unless - * you use a Graphics object outside of Guichan. - * - * @see endDraw, Gui::draw - */ - virtual void beginDraw() restrict2 - { } - - /** - * Deinitializes drawing. Called by the Gui when a Gui::draw() is done. - * done. It should reset any state changes made by beginDraw(). - * - * NOTE: You will never need to call this function yourself, unless - * you use a Graphics object outside of Guichan. - * - * @see beginDraw, Gui::draw - */ - virtual void endDraw() restrict2 - { } - - virtual void clearScreen() const restrict2 - { } - - virtual void deleteArrays() restrict2 - { } - - virtual void postInit() restrict2 - { } - - virtual void finalize(ImageCollection *restrict const col A_UNUSED) - restrict2 - { } - - virtual void finalize(ImageVertexes *restrict const vert A_UNUSED) - restrict2 - { } - - virtual void testDraw() restrict2 - { } - - virtual void removeArray(const uint32_t sz A_UNUSED, - uint32_t *restrict const arr A_UNUSED) - restrict2 - { } - - virtual void screenResized() restrict2 - { } - - int mWidth; - int mHeight; - int mActualWidth; - int mActualHeight; - - protected: - /** - * Constructor. - */ - Graphics(); - - void setMainFlags(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2; - - int getOpenGLFlags() const restrict2 A_WARN_UNUSED; - - int getSoftwareFlags() const restrict2 A_WARN_UNUSED; - - bool setOpenGLMode() restrict2; - - void updateMemoryInfo() restrict2; - - bool videoInfo() restrict2; - -#ifdef USE_OPENGL - void setOpenGLFlags() restrict2; -#endif // USE_OPENGL - - /** - * Holds the clip area stack. - */ - MStack mClipStack; - - SDL_Window *restrict mWindow; - -#ifdef USE_SDL2 - static SDL_Renderer *restrict mRenderer; -#endif // USE_SDL2 -#ifdef USE_OPENGL -#ifdef USE_SDL2 - static SDL_GLContext mGLContext; -#else // USE_SDL2 - - static void *restrict mGLContext; -#endif // USE_SDL2 -#endif // USE_OPENGL - - int mBpp; - bool mAlpha; - bool mFullscreen; - bool mHWAccel; - bool mRedraw; - bool mDoubleBuffer; - SDL_Rect mRect; - bool mSecure; - RenderType mOpenGL; - bool mEnableResize; - bool mNoFrame; - bool mAllowHighDPI; - std::string mName; - int mStartFreeMem; - bool mSync; - int mScale; - Color mColor; -}; - -extern Graphics *mainGraphics A_NONNULLPOINTER; - -#endif // RENDER_GRAPHICS_H diff --git a/src/render/graphics_calcImageRect.hpp b/src/render/graphics_calcImageRect.hpp deleted file mode 100644 index ea04a95cc..000000000 --- a/src/render/graphics_calcImageRect.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -// bool GraphicsX::calcImageRect(ImageVertexes *const vert, -// const int x, const int y, -// const int w, const int h, -// const ImageRect &imgRect) - -if (!vert) - return; - -BLOCK_START("Graphics::calcImageRect") - -const Image *restrict const *restrict const grid = imgRect.grid; -const Image *restrict const topLeft = grid[0]; -const Image *restrict const topRight = grid[2]; -const Image *restrict const bottomLeft = grid[6]; -const Image *restrict const bottomRight = grid[8]; -const Image *restrict const top = grid[1]; -const Image *restrict const right = grid[5]; -const Image *restrict const bottom = grid[7]; -const Image *restrict const left = grid[3]; -const Image *restrict const center = grid[4]; - -const bool drawMain = center && topLeft && topRight - && bottomLeft && bottomRight; - -// Draw the center area -if (center && drawMain) -{ - const int tlw = topLeft->getWidth(); - const int tlh = topLeft->getHeight(); - calcPatternInline(vert, center, tlw + x, tlh + y, - w - tlw - topRight->getWidth(), - h - tlh - bottomLeft->getHeight()); -} -// Draw the sides -if (top && left && bottom && right) -{ - const int lw = left->getWidth(); - const int rw = right->getWidth(); - const int th = top->getHeight(); - const int bh = bottom->getHeight(); - calcPatternInline(vert, top, x + lw, y, w - lw - rw, th); - calcPatternInline(vert, bottom, x + lw, y + h - bh, w - lw - rw, bh); - calcPatternInline(vert, left, x, y + th, lw, h - th - bh); - if (w > rw) - calcPatternInline(vert, right, x + w - rw, y + th, rw, h - th - bh); -} - -if (topLeft) - calcTileVertexesInline(vert, topLeft, x, y); -if (topRight) -{ - const int trw = topRight->getWidth(); - if (w > trw) - calcTileVertexesInline(vert, topRight, x + w - trw, y); -} -if (bottomLeft) -{ - calcTileVertexesInline(vert, bottomLeft, - x, y + h - bottomLeft->getHeight()); -} -if (bottomRight) -{ - const int brw = bottomRight->getWidth(); - if (w > brw) - { - calcTileVertexesInline(vert, bottomRight, x + w - brw, - y + h - bottomRight->getHeight()); - } -} - -BLOCK_END("Graphics::calcImageRect") diff --git a/src/render/graphics_drawImageRect.hpp b/src/render/graphics_drawImageRect.hpp deleted file mode 100644 index 1f3c5a38d..000000000 --- a/src/render/graphics_drawImageRect.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -// void GraphicsX::drawImageRect(const int x, const int y, -// const int w, const int h, -// const ImageRect &imgRect) - -BLOCK_START("Graphics::drawImageRect") - -const Image *restrict const *restrict const grid = imgRect.grid; -const Image *restrict const topLeft = grid[0]; -const Image *restrict const topRight = grid[2]; -const Image *restrict const bottomLeft = grid[6]; -const Image *restrict const bottomRight = grid[8]; -const Image *restrict const top = grid[1]; -const Image *restrict const right = grid[5]; -const Image *restrict const bottom = grid[7]; -const Image *restrict const left = grid[3]; -const Image *restrict const center = grid[4]; - -const bool drawMain = center && topLeft && topRight - && bottomLeft && bottomRight; - -// Draw the center area -if (center && drawMain) -{ - const int tlw = topLeft->getWidth(); - const int tlh = topLeft->getHeight(); - drawPatternInline(center, tlw + x, tlh + y, - w - tlw - topRight->getWidth(), - h - tlh - bottomLeft->getHeight()); -} - -// Draw the sides -if (top && left && bottom && right) -{ - const int lw = left->getWidth(); - const int rw = right->getWidth(); - const int th = top->getHeight(); - const int bh = bottom->getHeight(); - drawPatternInline(top, x + lw, y, w - lw - rw, th); - drawPatternInline(bottom, x + lw, h - bh + y, w - lw - rw, bh); - drawPatternInline(left, x, y + th, lw, h - th - bh); - if (w > rw) - drawPatternInline(right, x + w - rw, th + y, rw, h - th - bh); -} -// Draw the corners -if (drawMain) -{ - drawImageInline(topLeft, x, y); - const int trw = topRight->getWidth(); - if (w > trw) - drawImageInline(topRight, x + w - trw, y); - drawImageInline(bottomLeft, x, h - bottomLeft->getHeight() + y); - const int brw = bottomRight->getWidth(); - if (w > brw) - { - drawImageInline(bottomRight, - x + w - brw, - y + h - bottomRight->getHeight()); - } -} -BLOCK_END("Graphics::drawImageRect") diff --git a/src/render/graphicsdef.hpp b/src/render/graphicsdef.hpp deleted file mode 100644 index 8f8cf93ed..000000000 --- a/src/render/graphicsdef.hpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define RENDER_GRAPHICSDEF_HPP - -public: - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(int x, int y, - int w, int h, - const ImageRect &restrict imgRect) - restrict2 override final; - - void beginDraw() restrict2 override final; - - void endDraw() restrict2 override final; - - void pushClipArea(const Rect &restrict area) restrict2 override final; - - void popClipArea() restrict2 override final; - - /** - * Draws a resclaled version of the image - */ - void drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 override final; - - void drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 override final; - - void inline drawPatternInline(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 A_INLINE; - - void drawRescaledPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) restrict2 override final; - - void calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 override final; - - void calcPattern(ImageCollection *restrict const vert, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 override final; - - void calcTileVertexes(ImageVertexes *restrict const vert, - const Image *restrict const image, - int x, int y) const restrict2 override final - A_NONNULL(2, 3); - - void calcTileCollection(ImageCollection *restrict const vertCol, - const Image *restrict const image, - int x, int y) restrict2 override final; - - void drawTileVertexes(const ImageVertexes *restrict const vert) - restrict2 override final; - - void drawTileCollection(const ImageCollection - *restrict const vertCol) restrict2 override final - A_NONNULL(2); - - void updateScreen() restrict2 override final; - - void calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 override final A_NONNULL(2); - - void drawRectangle(const Rect &restrict rect) restrict2 override final; - - void fillRectangle(const Rect &restrict rect) restrict2 override final; - - void drawPoint(int x, int y) restrict2 override final; - - void drawLine(int x1, int y1, - int x2, int y2) restrict2 override final; - - bool setVideoMode(const int w, const int h, - const int scalle, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 override final; - - void drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 override final; - - void copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 override final; - - void drawImageCached(const Image *restrict const image, - int x, int y) restrict2 override final; - - void drawPatternCached(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 override final; - - void completeCache() restrict2 override final; - -private: - void inline calcImageRect(ImageVertexes *restrict const vert, - int x, int y, - int w, int h, - const ImageRect &restrict imgRect) - restrict2 A_INLINE; - - void inline calcPatternInline(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 A_INLINE; - - void inline calcTileVertexesInline(ImageVertexes *restrict const vert, - const Image *restrict const image, - int x, - int y) const restrict2 - A_INLINE A_NONNULL(2, 3); - - void inline drawImageInline(const Image *restrict const image, - int dstX, - int dstY) restrict2 A_INLINE; diff --git a/src/render/imagegraphics.cpp b/src/render/imagegraphics.cpp deleted file mode 100644 index 02a1f460d..000000000 --- a/src/render/imagegraphics.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifdef USE_OPENGL - -#include "render/imagegraphics.h" - -#include "debug.h" - -ImegeGraphics::ImegeGraphics() : - Graphics(), - mTarget(nullptr) -{ - mOpenGL = RENDER_SOFTWARE; - mName = "Image"; -} - -ImegeGraphics::~ImegeGraphics() -{ -} - -void ImegeGraphics::drawImage(const Image *restrict const image A_UNUSED, - int dstX A_UNUSED, int dstY A_UNUSED) restrict2 -{ - // for now not implemented -} - -void ImegeGraphics::copyImage(const Image *restrict const image, - int dstX A_UNUSED, int dstY A_UNUSED) restrict2 -{ - if ((mTarget == nullptr) || (image == nullptr)) - return; -} - -void ImegeGraphics::drawImageCached(const Image *restrict const image, - int x, int y) restrict2 -{ - drawImage(image, x, y); -} - -void ImegeGraphics::completeCache() restrict2 -{ -} - -#endif // USE_OPENGL diff --git a/src/render/imagegraphics.h b/src/render/imagegraphics.h deleted file mode 100644 index 2b3e5bd71..000000000 --- a/src/render/imagegraphics.h +++ /dev/null @@ -1,208 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_IMAGEGRAPHICS_H -#define RENDER_IMAGEGRAPHICS_H - -#ifdef USE_OPENGL - -#include "render/graphics.h" - -#include "localconsts.h" - -class Image; -class ImageCollection; -class ImageVertexes; - -/** - * A central point of control for graphics. - */ -class ImegeGraphics final : public Graphics -{ - public: - ImegeGraphics(); - - A_DELETE_COPY(ImegeGraphics) - - ~ImegeGraphics(); - - void setTarget(Image *const target) restrict2 noexcept2 - { mTarget = target; } - - Image *getTarget() const restrict2 noexcept2 - { return mTarget; } - - void beginDraw() restrict2 override final - { } - - void endDraw() restrict2 override final - { } - - void pushClipArea(const Rect &restrict rect A_UNUSED) - restrict2 override final - { } - - void popClipArea() restrict2 override final - { } - - void drawRescaledImage(const Image *restrict const image A_UNUSED, - int dstX A_UNUSED, int dstY A_UNUSED, - const int desiredWidth A_UNUSED, - const int desiredHeight A_UNUSED) - restrict2 override final - { } - - void drawPattern(const Image *restrict const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) restrict2 override final - { } - - void drawRescaledPattern(const Image *const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED, - const int scaledWidth A_UNUSED, - const int scaledHeight A_UNUSED) - override final - { } - - void calcPattern(ImageVertexes *restrict const vert A_UNUSED, - const Image *restrict const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) const restrict2 override final - { } - - void calcPattern(ImageCollection *restrict const vert A_UNUSED, - const Image *restrict const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) const restrict2 override final - { } - - void calcTileVertexes(ImageVertexes *restrict const vert A_UNUSED, - const Image *restrict const image A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) const restrict2 override final - A_NONNULL(2, 3) - { } - - void calcTileSDL(ImageVertexes *restrict const vert A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) const restrict2 override final - { } - - void calcTileCollection(ImageCollection *restrict const - vertCol A_UNUSED, - const Image *restrict const image A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) restrict2 override final - { } - - void drawTileVertexes(const ImageVertexes *const - vert A_UNUSED) override final - { } - - void drawTileCollection(const ImageCollection *const vertCol A_UNUSED) - override final A_NONNULL(2) - { } - - void updateScreen() override final - { } - - void drawNet(const int x1 A_UNUSED, - const int y1 A_UNUSED, - const int x2 A_UNUSED, - const int y2 A_UNUSED, - const int width A_UNUSED, - const int height A_UNUSED) override final - { } - - void calcWindow(ImageCollection *restrict const vertCol A_UNUSED, - const int x A_UNUSED, const int y A_UNUSED, - const int w A_UNUSED, const int h A_UNUSED, - const ImageRect &restrict imgRect A_UNUSED) - restrict2 override final A_NONNULL(2) - { } - - void fillRectangle(const Rect &rect A_UNUSED) override final - { } - - void drawRectangle(const Rect &rect A_UNUSED) restrict2 override final - { } - - void drawPoint(int x A_UNUSED, int y A_UNUSED) override final - { } - - void drawLine(int x1 A_UNUSED, int y1 A_UNUSED, - int x2 A_UNUSED, int y2 A_UNUSED) - restrict2 override final - { } - - bool setVideoMode(const int w A_UNUSED, const int h A_UNUSED, - const int scale A_UNUSED, - const int bpp A_UNUSED, - const bool fs A_UNUSED, const bool hwaccel A_UNUSED, - const bool resize A_UNUSED, - const bool noFrame A_UNUSED, - const bool allowHighDPI A_UNUSED) - restrict2 override final - { return false; } - - void drawImage(const Image *const image, - int dstX, int dstY) override final; - - void copyImage(const Image *const image, - int dstX, int dstY) restrict2 override final; - - void drawImageCached(const Image *const image, - int x, int y) override final; - - void drawPatternCached(const Image *restrict const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) restrict2 override final - { } - - void completeCache() restrict2 override final; - - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(const int x A_UNUSED, const int y A_UNUSED, - const int w A_UNUSED, const int h A_UNUSED, - const ImageRect &imgRect A_UNUSED) override final - { } - - protected: - Image *mTarget; -}; - -#endif // USE_OPENGL -#endif // RENDER_IMAGEGRAPHICS_H diff --git a/src/render/mobileopengl2graphics.cpp b/src/render/mobileopengl2graphics.cpp deleted file mode 100644 index 03fe5d016..000000000 --- a/src/render/mobileopengl2graphics.cpp +++ /dev/null @@ -1,1389 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if defined USE_OPENGL && !defined ANDROID - -#include "render/mobileopengl2graphics.h" - -#include "graphicsmanager.h" - -#include "render/opengl/mgl.h" -#ifdef __native_client__ -#include "render/opengl/naclglfunctions.h" -#endif // __native_client__ - -#include "render/shaders/shaderprogram.h" -#include "render/shaders/shadersmanager.h" - -#include "render/vertexes/imagecollection.h" - -#include "resources/imagerect.h" - -#include "resources/image/image.h" - -#include "utils/delete2.h" -#include "utils/foreach.h" -#include "utils/sdlcheckutils.h" - -#include "debug.h" - -#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h) \ - var[vp + 0] = dstX; \ - var[vp + 1] = dstY; \ - var[vp + 2] = x1; \ - var[vp + 3] = y1; \ - \ - var[vp + 4] = dstX + w; \ - var[vp + 5] = dstY; \ - var[vp + 6] = x2; \ - var[vp + 7] = y1; \ - \ - var[vp + 8] = dstX + w; \ - var[vp + 9] = dstY + h; \ - var[vp + 10] = x2; \ - var[vp + 11] = y2; \ - \ - var[vp + 12] = dstX; \ - var[vp + 13] = dstY; \ - var[vp + 14] = x1; \ - var[vp + 15] = y1; \ - \ - var[vp + 16] = dstX; \ - var[vp + 17] = dstY + h; \ - var[vp + 18] = x1; \ - var[vp + 19] = y2; \ - \ - var[vp + 20] = dstX + w; \ - var[vp + 21] = dstY + h; \ - var[vp + 22] = x2; \ - var[vp + 23] = y2; - -#define toGL static_cast - -GLuint MobileOpenGL2Graphics::mTextureBinded = 0U; -GLuint MobileOpenGL2Graphics::mTextureSizeUniform = 0U; -int MobileOpenGL2Graphics::mTextureWidth = 1; -int MobileOpenGL2Graphics::mTextureHeight = 1; -#ifdef DEBUG_DRAW_CALLS -unsigned int MobileOpenGL2Graphics::mDrawCalls = 0U; -unsigned int MobileOpenGL2Graphics::mLastDrawCalls = 0U; -#endif // DEBUG_DRAW_CALLS - -MobileOpenGL2Graphics::MobileOpenGL2Graphics() : - mFloatArray(nullptr), - mFloatArrayCached(nullptr), - mProgram(nullptr), - mAlphaCached(1.0F), - mVpCached(0), - mFloatColor(1.0F), - mMaxVertices(500), - mProgramId(0U), - mSimpleColorUniform(0U), - mPosAttrib(0), - mTextureColorUniform(0U), - mScreenUniform(0U), - mDrawTypeUniform(0U), -#ifndef __native_client__ - mVao(0U), -#endif // __native_client__ - mVbo(0U), - mVboBinded(0U), - mAttributesBinded(0U), - mColorAlpha(false), - mTextureDraw(false), -#ifdef DEBUG_BIND_TEXTURE - mOldTexture(), - mOldTextureId(0), -#endif // DEBUG_BIND_TEXTURE - mFbo() -{ - mOpenGL = RENDER_GLES2_OPENGL; - mName = "mobile OpenGL ES 2"; -} - -MobileOpenGL2Graphics::~MobileOpenGL2Graphics() -{ - deleteArraysInternal(); - deleteGLObjects(); -} - -void MobileOpenGL2Graphics::deleteGLObjects() restrict2 -{ - delete2(mProgram); - if (mVbo != 0u) - mglDeleteBuffers(1, &mVbo); -#ifndef __native_client__ - if (mVao != 0u) - mglDeleteVertexArrays(1, &mVao); -#endif // __native_client__ -} - -void MobileOpenGL2Graphics::initArrays(const int vertCount) restrict2 -{ - mMaxVertices = vertCount; - if (mMaxVertices < 500) - mMaxVertices = 500; - else if (mMaxVertices > 1024) - mMaxVertices = 1024; - - // need alocate small size, after if limit reached reallocate to double size - const size_t sz = mMaxVertices * 4 + 30; - vertexBufSize = mMaxVertices; - if (mFloatArray == nullptr) - mFloatArray = new GLfloat[sz]; - if (mFloatArrayCached == nullptr) - mFloatArrayCached = new GLfloat[sz]; -} - -void MobileOpenGL2Graphics::postInit() restrict2 -{ -#ifndef __native_client__ - mglGenVertexArrays(1, &mVao); - mglBindVertexArray(mVao); -#endif // __native_client__ - mglGenBuffers(1, &mVbo); -// logger->log("gen vbo buffer: %u", mVbo); - bindArrayBuffer(mVbo); - - logger->log("Compiling shaders"); - mProgram = shaders.getGles2Program(); - if (mProgram == nullptr) - { - graphicsManager.logError(); - logger->safeError("Shader creation error. See manaplus.log."); - } - mProgramId = mProgram->getProgramId(); - if (mProgramId == 0u) - logger->safeError("Shaders compilation error."); - - logger->log("Shaders compilation done."); - mglUseProgram(mProgramId); - - mPosAttrib = 0; - - mSimpleColorUniform = mglGetUniformLocation(mProgramId, "color"); - mScreenUniform = mglGetUniformLocation(mProgramId, "screen"); - mDrawTypeUniform = mglGetUniformLocation(mProgramId, "drawType"); - mTextureColorUniform = mglGetUniformLocation(mProgramId, "alpha"); - mTextureSizeUniform = mglGetUniformLocation(mProgramId, "textureSize"); - - mglUniform1f(mTextureColorUniform, 1.0f); - - mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr); - mglEnableVertexAttribArray(0); - mAttributesBinded = mVbo; - - mglUniform2f(mScreenUniform, - static_cast(mWidth) / 2.0f, - static_cast(mHeight) / 2.0f); - // for safty init texture size to 1x1 - mglUniform2f(mTextureSizeUniform, - 1.0f, - 1.0f); - mglUniform4f(mSimpleColorUniform, - 0.0F, - 0.0F, - 0.0F, - 0.0F); - - mglActiveTexture(GL_TEXTURE0); -} - -void MobileOpenGL2Graphics::screenResized() restrict2 -{ - deleteGLObjects(); - mVboBinded = 0U; - mAttributesBinded = 0U; - mColor = Color(0, 0, 0, 0); - postInit(); -} - -void MobileOpenGL2Graphics::deleteArrays() restrict2 -{ - deleteArraysInternal(); -} - -void MobileOpenGL2Graphics::deleteArraysInternal() restrict2 -{ - delete [] mFloatArray; - mFloatArray = nullptr; - delete [] mFloatArrayCached; - mFloatArrayCached = nullptr; -} - -bool MobileOpenGL2Graphics::setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - setMainFlags(w, h, - scale, - bpp, - fs, - hwaccel, - resize, - noFrame, - allowHighDPI); - - return setOpenGLMode(); -} - -void MobileOpenGL2Graphics::setColor(const Color &restrict color) restrict2 -{ - mColorAlpha = (color.a != 255); - if (mColor != color) - { - mColor = color; - mglUniform4f(mSimpleColorUniform, - static_cast(color.r) / 255.0F, - static_cast(color.g) / 255.0F, - static_cast(color.b) / 255.0F, - static_cast(color.a) / 255.0F); - } -} - -void MobileOpenGL2Graphics::setColorAlpha(const float alpha) restrict2 -{ - if (mAlphaCached != alpha) - { - mAlphaCached = alpha; - mglUniform1f(mTextureColorUniform, alpha); - } -} - -void MobileOpenGL2Graphics::drawQuad(const int srcX, - const int srcY, - const int dstX, - const int dstY, - const int width, - const int height) restrict2 -{ - const GLfloat texX2 = static_cast(srcX + width); - const GLfloat texY2 = static_cast(srcY + height); - const GLfloat x2 = static_cast(dstX + width); - const GLfloat y2 = static_cast(dstY + height); - const GLfloat srcX2 = toGL(srcX); - const GLfloat srcY2 = toGL(srcY); - const GLfloat dstX2 = toGL(dstX); - const GLfloat dstY2 = toGL(dstY); - - GLfloat vertices[] = - { - dstX2, dstY2, srcX2, srcY2, - x2, dstY2, texX2, srcY2, - dstX2, y2, srcX2, texY2, - x2, y2, texX2, texY2 - }; - - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGL2Graphics::drawRescaledQuad(const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - const GLfloat texX2 = static_cast(srcX + width); - const GLfloat texY2 = static_cast(srcY + height); - const GLfloat x2 = static_cast(dstX + desiredWidth); - const GLfloat y2 = static_cast(dstY + desiredHeight); - const GLfloat srcX2 = toGL(srcX); - const GLfloat srcY2 = toGL(srcY); - const GLfloat dstX2 = toGL(dstX); - const GLfloat dstY2 = toGL(dstY); - - GLfloat vertices[] = - { - dstX2, dstY2, srcX2, srcY2, - x2, dstY2, texX2, srcY2, - dstX2, y2, srcX2, texY2, - x2, y2, texX2, texY2 - }; - - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGL2Graphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void MobileOpenGL2Graphics::drawImageInline(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - if (image == nullptr) - return; - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture2(GL_TEXTURE_2D, image); - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - setColorAlpha(image->mAlpha); - - const ClipRect &clipArea = mClipStack.top(); - const SDL_Rect &imageRect = image->mBounds; - drawQuad(imageRect.x, - imageRect.y, - dstX + clipArea.xOffset, - dstY + clipArea.yOffset, - imageRect.w, - imageRect.h); -} - -void MobileOpenGL2Graphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void MobileOpenGL2Graphics::testDraw() restrict2 -{ -/* - GLfloat vertices[] = - { - 0, 0, 0, 0, - 800, 0, 800, 0, - 0, 600, 0, 600, - 800, 600, 800, 600 - }; -*/ -// logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices)); -// mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), -// vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -// glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGL2Graphics::drawImageCached(const Image *restrict const image - A_UNUSED, - int A_UNUSED x, - int y A_UNUSED) restrict2 -{ -} - -void MobileOpenGL2Graphics::drawPatternCached(const Image *restrict const image - A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) restrict2 -{ -} - -void MobileOpenGL2Graphics::completeCache() restrict2 -{ -} - -void MobileOpenGL2Graphics::drawRescaledImage(const Image * - restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) - restrict2 -{ - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - - // Just draw the image normally when no resizing is necessary, - if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) - { - drawImageInline(image, dstX, dstY); - return; - } - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture2(GL_TEXTURE_2D, image); - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - - const ClipRect &clipArea = mClipStack.top(); - // Draw a textured quad. - drawRescaledQuad(imageRect.x, - imageRect.y, - dstX + clipArea.xOffset, - dstY + clipArea.yOffset, - imageRect.w, - imageRect.h, - desiredWidth, - desiredHeight); -} - -void MobileOpenGL2Graphics::drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - drawPatternInline(image, x, y, w, h); -} - -void MobileOpenGL2Graphics::drawPatternInline(const Image * - restrict const image, - const int x, const int y, - const int w, const int h) - restrict2 -{ - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const GLfloat srcX2 = toGL(srcX); - const GLfloat srcY2 = toGL(srcY); - const ClipRect &clipArea = mClipStack.top(); - const int x2 = x + clipArea.xOffset; - const int y2 = y + clipArea.yOffset; - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture2(GL_TEXTURE_2D, image); - - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - setColorAlpha(image->mAlpha); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const GLfloat texY2 = static_cast(srcY + height); - const GLfloat dstY = static_cast(y2 + py); - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const GLfloat dstX = static_cast(x2 + px); - const GLfloat texX2 = static_cast(srcX + width); - - vertFill2D(mFloatArray, - srcX2, srcY2, texX2, texY2, - dstX, dstY, width, height); - - vp += 24; - if (vp >= vLimit) - { - drawTriangleArray(vp); - vp = 0; - } - } - } - if (vp > 0) - drawTriangleArray(vp); -} - -void MobileOpenGL2Graphics::drawRescaledPattern(const Image * - restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) - restrict2 -{ - if (image == nullptr) - return; - - if (scaledWidth == 0 || scaledHeight == 0) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int iw = imageRect.w; - const int ih = imageRect.h; - if (iw == 0 || ih == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const GLfloat srcX2 = toGL(srcX); - const GLfloat srcY2 = toGL(srcY); - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture2(GL_TEXTURE_2D, image); - - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - setColorAlpha(image->mAlpha); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - const ClipRect &clipArea = mClipStack.top(); - const int x2 = x + clipArea.xOffset; - const int y2 = y + clipArea.yOffset; - - const float scaleFactorW = static_cast(scaledWidth) / iw; - const float scaleFactorH = static_cast(scaledHeight) / ih; - - for (int py = 0; py < h; py += scaledHeight) - { - const int height = (py + scaledHeight >= h) - ? h - py : scaledHeight; - const GLfloat dstY = static_cast(y2 + py); - const GLfloat scaledY = srcY + height / scaleFactorH; - for (int px = 0; px < w; px += scaledWidth) - { - const int width = (px + scaledWidth >= w) - ? w - px : scaledWidth; - const GLfloat dstX = static_cast(x2 + px); - const GLfloat scaledX = srcX + width / scaleFactorW; - - vertFill2D(mFloatArray, - srcX2, srcY2, - scaledX, scaledY, - dstX, dstY, - static_cast(width), static_cast(height)); - - vp += 24; - if (vp >= vLimit) - { - drawTriangleArray(vp); - vp = 0; - } - } - } - if (vp > 0) - drawTriangleArray(vp); -} - -inline void MobileOpenGL2Graphics::drawVertexes(const - OpenGLGraphicsVertexes & - restrict ogl) restrict2 -{ - const STD_VECTOR &vp = ogl.mVp; - const STD_VECTOR &vbos = ogl.mVbo; - STD_VECTOR::const_iterator ivp; - STD_VECTOR::const_iterator ivbo; - const STD_VECTOR::const_iterator ivp_end = vp.end(); - - for (ivp = vp.begin(), ivbo = vbos.begin(); - ivp != ivp_end; - ++ ivp, ++ ivbo) - { - bindArrayBufferAndAttributes(*ivbo); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLES, 0, *ivp / 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } -} - -void MobileOpenGL2Graphics::calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - calcPatternInline(vert, image, x, y, w, h); -} - -void MobileOpenGL2Graphics::calcPatternInline(ImageVertexes * - restrict const vert, - const Image * - restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - if (image == nullptr || vert == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const GLfloat srcX2 = toGL(srcX); - const GLfloat srcY2 = toGL(srcY); - - const ClipRect &clipArea = mClipStack.top(); - const int x2 = x + clipArea.xOffset; - const int y2 = y + clipArea.yOffset; - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - unsigned int vp = ogl.continueVp(); - - GLfloat *floatArray = ogl.continueFloatTexArray(); - - for (int py = 0; py < h; py += ih) - { - const GLfloat height = static_cast( - (py + ih >= h) ? h - py : ih); - const GLfloat dstY = static_cast(y2 + py); - const GLfloat texY2 = srcY + height; - for (int px = 0; px < w; px += iw) - { - const GLfloat width = static_cast( - (px + iw >= w) ? w - px : iw); - const GLfloat dstX = static_cast(x2 + px); - const GLfloat texX2 = srcX2 + width; - - vertFill2D(floatArray, - srcX2, srcY2, texX2, texY2, - dstX, dstY, width, height); - - vp += 24; - if (vp >= vLimit) - { - floatArray = ogl.switchFloatTexArray(); - ogl.switchVp(vp); - vp = 0; - } - } - } - ogl.switchVp(vp); -} - -void MobileOpenGL2Graphics::calcTileCollection(ImageCollection * - restrict const vertCol, - const Image * - restrict const image, - int x, int y) restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - ImageVertexes *const vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - calcTileVertexesInline(vert, image, x, y); - } - else - { - calcTileVertexesInline(vertCol->currentVert, image, x, y); - } -} - -void MobileOpenGL2Graphics::drawTileCollection(const ImageCollection - *restrict const vertCol) - restrict2 -{ - enableTexturingAndBlending(); - const ImageVertexesVector &draws = vertCol->draws; - const ImageCollectionCIter it_end = draws.end(); - for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) - { - const ImageVertexes *const vert = *it; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture2(GL_TEXTURE_2D, image); - drawVertexes(vert->ogl); - } -} - -void MobileOpenGL2Graphics::calcPattern(ImageCollection *restrict const - vertCol, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - ImageVertexes *vert = nullptr; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - - calcPatternInline(vert, image, x, y, w, h); -} - -void MobileOpenGL2Graphics::calcTileVertexes(ImageVertexes * - restrict const vert, - const Image *restrict const image, - int dstX, - int dstY) const restrict2 -{ - calcTileVertexesInline(vert, image, dstX, dstY); -} - -void MobileOpenGL2Graphics::calcTileVertexesInline(ImageVertexes * - restrict const vert, - const Image * - restrict const image, - int dstX, - int dstY) const restrict2 -{ - const SDL_Rect &imageRect = image->mBounds; - const int w = imageRect.w; - const int h = imageRect.h; - - if (w == 0 || h == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const GLfloat srcX2 = toGL(srcX); - const GLfloat srcY2 = toGL(srcY); - - const ClipRect &clipArea = mClipStack.top(); - const GLfloat x2 = static_cast(dstX + clipArea.xOffset); - const GLfloat y2 = static_cast(dstY + clipArea.yOffset); - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - - unsigned int vp = ogl.continueVp(); - - GLfloat texX2 = static_cast(srcX + w); - GLfloat texY2 = static_cast(srcY + h); - - GLfloat *const floatArray = ogl.continueFloatTexArray(); - - vertFill2D(floatArray, - srcX2, srcY2, texX2, texY2, - x2, y2, w, h); - - vp += 24; - if (vp >= vLimit) - { - ogl.switchFloatTexArray(); - ogl.switchVp(vp); - vp = 0; - } - - ogl.switchVp(vp); -} - -void MobileOpenGL2Graphics::drawTileVertexes(const ImageVertexes * - restrict const vert) restrict2 -{ - if (vert == nullptr) - return; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture2(GL_TEXTURE_2D, image); - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - - drawVertexes(vert->ogl); -} - -void MobileOpenGL2Graphics::calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - ImageVertexes *vert = nullptr; - const Image *const image = imgRect.grid[4]; - if (image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - calcImageRect(vert, x, y, w, h, imgRect); -} - -void MobileOpenGL2Graphics::updateScreen() restrict2 -{ - BLOCK_START("Graphics::updateScreen") -#ifdef DEBUG_DRAW_CALLS - mLastDrawCalls = mDrawCalls; - mDrawCalls = 0; -#endif // DEBUG_DRAW_CALLS -#ifdef USE_SDL2 - SDL_GL_SwapWindow(mWindow); -#else // USE_SDL2 - SDL_GL_SwapBuffers(); -#endif // USE_SDL2 -#ifdef DEBUG_OPENGL - if (isGLNotNull(mglFrameTerminator)) - mglFrameTerminator(); -#endif // DEBUG_OPENGL - BLOCK_END("Graphics::updateScreen") -} - -void MobileOpenGL2Graphics::beginDraw() restrict2 -{ - setOpenGLFlags(); -#ifndef __native_client__ - mglDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); - mglHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB, GL_FASTEST); -#endif // __native_client__ - pushClipArea(Rect(0, 0, mRect.w, mRect.h)); -} - -void MobileOpenGL2Graphics::endDraw() restrict2 -{ - popClipArea(); -} - -void MobileOpenGL2Graphics::pushClipArea(const Rect &restrict area) restrict2 -{ - Graphics::pushClipArea(area); - const ClipRect &clipArea = mClipStack.top(); - - mglScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -void MobileOpenGL2Graphics::popClipArea() restrict2 -{ - if (mClipStack.empty()) - return; - Graphics::popClipArea(); - if (mClipStack.empty()) - return; - - const ClipRect &clipArea = mClipStack.top(); - mglScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -void MobileOpenGL2Graphics::drawPoint(int x, int y) restrict2 -{ - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - GLfloat vertices[] = - { - toGL(x + clipArea.xOffset), toGL(y + clipArea.yOffset), 0.0f, 0.0f - }; - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_POINTS, 0, 1); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGL2Graphics::drawLine(int x1, int y1, - int x2, int y2) restrict2 -{ - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - GLfloat vertices[] = - { - toGL(x1 + clipArea.xOffset), toGL(y1 + clipArea.yOffset), 0.0f, 0.0f, - toGL(x2 + clipArea.xOffset), toGL(y2 + clipArea.yOffset), 0.0f, 0.0f - }; - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_LINES, 0, 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGL2Graphics::drawRectangle(const Rect &restrict rect) restrict2 -{ - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - const GLfloat x1 = static_cast(rect.x + clipArea.xOffset); - const GLfloat y1 = static_cast(rect.y + clipArea.yOffset); - const GLfloat x2 = x1 + static_cast(rect.width); - const GLfloat y2 = y1 + static_cast(rect.height); - GLfloat vertices[] = - { - x1, y1, 0.0f, 0.0f, - x1, y2, 0.0f, 0.0f, - x2, y2, 0.0f, 0.0f, - x2, y1, 0.0f, 0.0f - }; - - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_LINE_LOOP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGL2Graphics::fillRectangle(const Rect &restrict rect) restrict2 -{ - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - const GLfloat x1 = static_cast(rect.x + clipArea.xOffset); - const GLfloat y1 = static_cast(rect.y + clipArea.yOffset); - const GLfloat x2 = x1 + static_cast(rect.width); - const GLfloat y2 = y1 + static_cast(rect.height); - GLfloat vertices[] = - { - x1, y1, 0.0f, 0.0f, - x2, y1, 0.0f, 0.0f, - x1, y2, 0.0f, 0.0f, - x2, y2, 0.0f, 0.0f - }; - - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGL2Graphics::enableTexturingAndBlending() restrict2 -{ - if (!mTextureDraw) - { - mTextureDraw = true; - mglUniform1f(mDrawTypeUniform, 1.0f); - } - if (!mAlpha) - { - mglEnable(GL_BLEND); - mAlpha = true; - } -} - -void MobileOpenGL2Graphics::disableTexturingAndBlending() restrict2 -{ - if (mTextureDraw) - { - mTextureDraw = false; - mglUniform1f(mDrawTypeUniform, 0.0f); - } - if (mAlpha && !mColorAlpha) - { - mglDisable(GL_BLEND); - mAlpha = false; - } - else if (!mAlpha && mColorAlpha) - { - mglEnable(GL_BLEND); - mAlpha = true; - } -} - -void MobileOpenGL2Graphics::drawRectangle(const Rect &restrict rect A_UNUSED, - const bool filled A_UNUSED) restrict2 -{ -} - -void MobileOpenGL2Graphics::drawNet(const int x1, - const int y1, - const int x2, - const int y2, - const int width, - const int height) restrict2 -{ - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - const GLfloat dx = static_cast(clipArea.xOffset); - const GLfloat dy = static_cast(clipArea.yOffset); - - const GLfloat xs1 = x1 + dx; - const GLfloat xs2 = x2 + dx; - const GLfloat ys1 = y1 + dy; - const GLfloat ys2 = y2 + dy; - - for (int y = y1; y < y2; y += height) - { - mFloatArray[vp + 0] = xs1; - mFloatArray[vp + 1] = toGL(y); - mFloatArray[vp + 2] = 0.0f; - mFloatArray[vp + 3] = 0.0f; - - mFloatArray[vp + 4] = xs2; - mFloatArray[vp + 5] = toGL(y); - mFloatArray[vp + 6] = 0.0f; - mFloatArray[vp + 7] = 0.0f; - - vp += 8; - if (vp >= vLimit) - { - drawLineArrays(vp); - vp = 0; - } - } - - for (int x = x1; x < x2; x += width) - { - mFloatArray[vp + 0] = toGL(x); - mFloatArray[vp + 1] = ys1; - mFloatArray[vp + 2] = 0.0f; - mFloatArray[vp + 3] = 0.0f; - - mFloatArray[vp + 4] = toGL(x); - mFloatArray[vp + 5] = ys2; - mFloatArray[vp + 6] = 0.0f; - mFloatArray[vp + 7] = 0.0f; - - vp += 8; - if (vp >= vLimit) - { - drawLineArrays(vp); - vp = 0; - } - } - - if (vp > 0) - drawLineArrays(vp); -} - -void MobileOpenGL2Graphics::bindTexture2(const GLenum target, - const Image *restrict const image) -{ - const GLuint texture = image->mGLImage; - if (mTextureBinded != texture) - { - mTextureBinded = texture; - mglBindTexture(target, texture); - if (mTextureWidth != image->mTexWidth || - mTextureHeight != image->mTexHeight) - { - mTextureWidth = image->mTexWidth; - mTextureHeight = image->mTexHeight; - mglUniform2f(mTextureSizeUniform, - static_cast(image->mTexWidth), - static_cast(image->mTexHeight)); - } - } -} - -void MobileOpenGL2Graphics::bindTexture(const GLenum target, - const GLuint texture) -{ - if (mTextureBinded != texture) - { - // for safty not storing textures because cant update size uniform - mTextureBinded = 0; - mglBindTexture(target, texture); - } -} - -void MobileOpenGL2Graphics::removeArray(const uint32_t sz, - uint32_t *restrict const arr) restrict2 -{ - mglDeleteBuffers(sz, arr); - for (size_t f = 0; f < sz; f ++) - { - if (arr[f] == mVboBinded) - mVboBinded = 0; - } -} - -void MobileOpenGL2Graphics::bindArrayBuffer(const GLuint vbo) restrict2 -{ - if (mVboBinded != vbo) - { - mVboBinded = vbo; - mglBindBuffer(GL_ARRAY_BUFFER, vbo); - mAttributesBinded = 0U; - } -} - -void MobileOpenGL2Graphics::bindArrayBufferAndAttributes(const GLuint vbo) - restrict2 -{ - if (mVboBinded != vbo) - { - mVboBinded = vbo; - mglBindBuffer(GL_ARRAY_BUFFER, vbo); - - mAttributesBinded = mVboBinded; - mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr); - } - else if (mAttributesBinded != mVboBinded) - { - mAttributesBinded = mVboBinded; - mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr); - } -} - -void MobileOpenGL2Graphics::bindAttributes() restrict2 -{ - if (mAttributesBinded != mVboBinded) - { - mAttributesBinded = mVboBinded; - mglVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr); - } -} - -void MobileOpenGL2Graphics::dumpSettings() -{ - GLint test[1000]; - logger->log("\n\n"); - logger->log("start opengl dump"); - for (int f = 0; f < 65535; f ++) - { - test[0] = 0; - test[1] = 0; - test[2] = 0; - test[3] = 0; - mglGetIntegerv(f, &test[0]); - if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0) - { - logger->log("\n%d = %d, %d, %d, %d", f, - test[0], test[1], test[2], test[3]); - } - } -} - -void MobileOpenGL2Graphics::drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_drawImageRect.hpp" -} - -void MobileOpenGL2Graphics::calcImageRect(ImageVertexes *restrict const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_calcImageRect.hpp" -} - -void MobileOpenGL2Graphics::clearScreen() const restrict2 -{ - mglClear(GL_COLOR_BUFFER_BIT | - GL_DEPTH_BUFFER_BIT | - GL_STENCIL_BUFFER_BIT); -} - -void MobileOpenGL2Graphics::createGLContext(const bool custom) restrict2 -{ - Graphics::createGLContext(custom); -/* - if (mGLContext) - SDL::makeCurrentContext(mGLContext); - else - mGLContext = SDL::createGLContext(mWindow, 2, 0, 0x04); -*/ -} - -void MobileOpenGL2Graphics::finalize(ImageCollection *restrict const col) - restrict2 -{ - if (col == nullptr) - return; - FOR_EACH (ImageCollectionIter, it, col->draws) - finalize(*it); -} - -void MobileOpenGL2Graphics::finalize(ImageVertexes *restrict const vert) - restrict2 -{ - // in future need convert in each switchVp/continueVp - - if (vert == nullptr) - return; - OpenGLGraphicsVertexes &ogl = vert->ogl; - const STD_VECTOR &vp = ogl.mVp; - STD_VECTOR::const_iterator ivp; - const STD_VECTOR::const_iterator ivp_end = vp.end(); - STD_VECTOR &floatTexPool = ogl.mFloatTexPool; - STD_VECTOR::const_iterator ft; - const STD_VECTOR::const_iterator ft_end = floatTexPool.end(); - STD_VECTOR &vbos = ogl.mVbo; - STD_VECTOR::const_iterator ivbo; - - const int sz = CAST_S32(floatTexPool.size()); - vbos.resize(sz); - mglGenBuffers(sz, &vbos[0]); - - for (ft = floatTexPool.begin(), ivp = vp.begin(), ivbo = vbos.begin(); - ft != ft_end && ivp != ivp_end; - ++ ft, ++ ivp, ++ ivbo) - { - bindArrayBuffer(*ivbo); - mglBufferData(GL_ARRAY_BUFFER, (*ivp) * sizeof(GLfloat), - *ft, GL_STATIC_DRAW); - } - - for (STD_VECTOR::iterator it = floatTexPool.begin(); - it != floatTexPool.end(); ++ it) - { - delete [] (*it); - } - floatTexPool.clear(); -} - -void MobileOpenGL2Graphics::drawTriangleArray(const int size) restrict2 -{ - mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), - mFloatArray, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLES, 0, size / 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGL2Graphics::drawTriangleArray(const GLfloat *restrict const - array, - const int size) restrict2 -{ - mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), - array, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLES, 0, size / 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGL2Graphics::drawLineArrays(const int size) restrict2 -{ - mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), - mFloatArray, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_LINES, 0, size / 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -#ifdef DEBUG_BIND_TEXTURE -void MobileOpenGL2Graphics::debugBindTexture(const Image *restrict const image) - restrict2 -{ - const std::string texture = image->mIdPath; - if (mOldTexture != texture) - { - if ((!mOldTexture.empty() || !texture.empty()) - && mOldTextureId != image->mGLImage) - { - logger->log("bind: %s (%d) to %s (%d)", mOldTexture.c_str(), - mOldTextureId, texture.c_str(), image->mGLImage); - } - mOldTextureId = image->mGLImage; - mOldTexture = texture; - } -} -#else // DEBUG_BIND_TEXTURE -void MobileOpenGL2Graphics::debugBindTexture(const Image *restrict const - image A_UNUSED) restrict2 -{ -} -#endif // DEBUG_BIND_TEXTURE - -#endif // USE_OPENGL diff --git a/src/render/mobileopengl2graphics.h b/src/render/mobileopengl2graphics.h deleted file mode 100644 index 3148c5fd7..000000000 --- a/src/render/mobileopengl2graphics.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_MOBILEOPENGL2GRAPHICS_H -#define RENDER_MOBILEOPENGL2GRAPHICS_H - -#if defined(USE_OPENGL) && !defined(ANDROID) - -#include "localconsts.h" - -#include "render/graphics.h" - -#include "resources/fboinfo.h" - -#ifdef ANDROID -#include -#include -#include -#else // ANDROID -#ifndef USE_SDL2 -#define GL_GLEXT_PROTOTYPES 1 -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#include -PRAGMA48(GCC diagnostic pop) -#if defined(__APPLE__) -#include -#elif !defined(__native_client__) -#include -#endif // defined(__APPLE__) -#endif // ANDROID - -class OpenGLGraphicsVertexes; -class ShaderProgram; - -class MobileOpenGL2Graphics final : public Graphics -{ - public: - MobileOpenGL2Graphics(); - - A_DELETE_COPY(MobileOpenGL2Graphics) - - ~MobileOpenGL2Graphics(); - - void postInit() restrict2 override final; - - void setColor(const Color &restrict color) restrict2 override final; - - void screenResized() restrict2 override final; - - void finalize(ImageCollection *restrict const col) - restrict2 override final; - - void finalize(ImageVertexes *restrict const vert) - restrict2 override final; - - void testDraw() restrict2 override final; - - void removeArray(const uint32_t id, - uint32_t *restrict const arr) - restrict2 override final A_NONNULL(3); - - void createGLContext(const bool custom) restrict2 override final; - - #include "render/graphicsdef.hpp" - RENDER_GRAPHICSDEF_HPP - - #include "render/openglgraphicsdef.hpp" - RENDER_OPENGLGRAPHICSDEF_HPP - - #include "render/openglgraphicsdefadvanced.hpp" - RENDER_OPENGLGRAPHICSDEFADVANCED_HPP - - private: - void deleteGLObjects() restrict2; - - inline void drawQuad(const int srcX, - const int srcY, - const int dstX, - const int dstY, - const int width, - const int height) restrict2 A_INLINE; - - inline void drawRescaledQuad(const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) - restrict2 A_INLINE; - - inline void drawTriangleArray(const int size) restrict2 A_INLINE; - - inline void drawTriangleArray(const GLfloat *restrict const array, - const int size) restrict2 A_INLINE; - - inline void drawLineArrays(const int size) restrict2 A_INLINE; - - inline void bindArrayBuffer(const GLuint vbo) restrict2 A_INLINE; - - inline void bindArrayBufferAndAttributes(const GLuint vbo) - restrict2 A_INLINE; - - inline void bindAttributes() restrict2 A_INLINE; - - static void bindTexture2(const GLenum target, - const Image *restrict const image); - - static GLuint mTextureSizeUniform; - static int mTextureWidth; - static int mTextureHeight; - - GLfloat *mFloatArray A_NONNULLPOINTER; - GLfloat *mFloatArrayCached A_NONNULLPOINTER; - ShaderProgram *mProgram; - float mAlphaCached; - int mVpCached; - - float mFloatColor; - int mMaxVertices; - GLuint mProgramId; - GLuint mSimpleColorUniform; - GLint mPosAttrib; - GLint mTextureColorUniform; - GLuint mScreenUniform; - GLuint mDrawTypeUniform; -#ifndef __native_client__ - GLuint mVao; -#endif // __native_client__ - - GLuint mVbo; - GLuint mVboBinded; - GLuint mAttributesBinded; - bool mColorAlpha; - bool mTextureDraw; -#ifdef DEBUG_BIND_TEXTURE - std::string mOldTexture; - unsigned mOldTextureId; -#endif // DEBUG_BIND_TEXTURE - - FBOInfo mFbo; -}; -#endif // defined(USE_OPENGL) && !defined(ANDROID) - -#endif // RENDER_MOBILEOPENGL2GRAPHICS_H diff --git a/src/render/mobileopenglgraphics.cpp b/src/render/mobileopenglgraphics.cpp deleted file mode 100644 index 0f3ce09ea..000000000 --- a/src/render/mobileopenglgraphics.cpp +++ /dev/null @@ -1,1385 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if defined(USE_OPENGL) && !defined(__native_client__) - -#include "render/mobileopenglgraphics.h" - -#ifdef OPENGLERRORS -#include "graphicsmanager.h" -#endif // OPENGLERRORS - -#include "render/opengl/mgl.h" -#ifdef __native_client__ -#include "render/opengl/naclglfunctions.h" -#endif // __native_client__ - -#include "render/vertexes/imagecollection.h" - -#include "resources/imagerect.h" -#include "resources/openglimagehelper.h" - -#include "resources/image/image.h" - -#include "utils/sdlcheckutils.h" - -#include "debug.h" - -#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h) \ - tVar[vp + 0] = x1; \ - tVar[vp + 1] = y1; \ - tVar[vp + 2] = x2; \ - tVar[vp + 3] = y1; \ - tVar[vp + 4] = x2; \ - tVar[vp + 5] = y2; \ - tVar[vp + 6] = x1; \ - tVar[vp + 7] = y1; \ - tVar[vp + 8] = x1; \ - tVar[vp + 9] = y2; \ - tVar[vp + 10] = x2; \ - tVar[vp + 11] = y2; \ - vVar[vp + 0] = static_cast(dstX); \ - vVar[vp + 1] = static_cast(dstY); \ - vVar[vp + 2] = static_cast(dstX + w); \ - vVar[vp + 3] = static_cast(dstY); \ - vVar[vp + 4] = static_cast(dstX + w); \ - vVar[vp + 5] = static_cast(dstY + h); \ - vVar[vp + 6] = static_cast(dstX); \ - vVar[vp + 7] = static_cast(dstY); \ - vVar[vp + 8] = static_cast(dstX); \ - vVar[vp + 9] = static_cast(dstY + h); \ - vVar[vp + 10] = static_cast(dstX + w); \ - vVar[vp + 11] = static_cast(dstY + h); - -GLuint MobileOpenGLGraphics::mTextureBinded = 0; -#ifdef DEBUG_DRAW_CALLS -unsigned int MobileOpenGLGraphics::mDrawCalls = 0; -unsigned int MobileOpenGLGraphics::mLastDrawCalls = 0; -#endif // DEBUG_DRAW_CALLS - -MobileOpenGLGraphics::MobileOpenGLGraphics() : - mFloatTexArray(nullptr), - mShortVertArray(nullptr), - mFloatTexArrayCached(nullptr), - mShortVertArrayCached(nullptr), - mAlphaCached(1.0F), - mVpCached(0), - mTexture(false), - mIsByteColor(false), - mByteColor(), - mImageCached(0), - mFloatColor(1.0F), - mMaxVertices(500), - mColorAlpha(false), -#ifdef DEBUG_BIND_TEXTURE - mOldTexture(), - mOldTextureId(0), -#endif // DEBUG_BIND_TEXTURE - mFbo() -{ - mOpenGL = RENDER_GLES_OPENGL; - mName = "mobile OpenGL ES"; -} - -MobileOpenGLGraphics::~MobileOpenGLGraphics() -{ - deleteArraysInternal(); -} - -void MobileOpenGLGraphics::postInit() restrict2 -{ -// glesTest(); -} - -void MobileOpenGLGraphics::initArrays(const int vertCount) restrict2 -{ - mMaxVertices = vertCount; - if (mMaxVertices < 500) - mMaxVertices = 500; - else if (mMaxVertices > 1024) - mMaxVertices = 1024; - - // need alocate small size, after if limit reached reallocate to double size - const size_t sz = mMaxVertices * 4 + 30; - vertexBufSize = mMaxVertices; - if (mFloatTexArray == nullptr) - mFloatTexArray = new GLfloat[sz]; - if (mShortVertArray == nullptr) - mShortVertArray = new GLshort[sz]; - if (mFloatTexArrayCached == nullptr) - mFloatTexArrayCached = new GLfloat[sz]; - if (mShortVertArrayCached == nullptr) - mShortVertArrayCached = new GLshort[sz]; -} - -void MobileOpenGLGraphics::deleteArrays() restrict2 -{ - deleteArraysInternal(); -} - -void MobileOpenGLGraphics::deleteArraysInternal() restrict2 -{ - delete [] mFloatTexArray; - mFloatTexArray = nullptr; - delete [] mShortVertArray; - mShortVertArray = nullptr; - delete [] mFloatTexArrayCached; - mFloatTexArrayCached = nullptr; - delete [] mShortVertArrayCached; - mShortVertArrayCached = nullptr; -} - -bool MobileOpenGLGraphics::setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - setMainFlags(w, h, - scale, - bpp, - fs, - hwaccel, - resize, - noFrame, - allowHighDPI); - - return setOpenGLMode(); -} - -static inline void drawQuad(const Image *restrict const image, - const int srcX, - const int srcY, - const int dstX, - const int dstY, - const int width, - const int height) A_NONNULL(1) A_INLINE; - -static inline void drawQuad(const Image *restrict const image, - const int srcX, - const int srcY, - const int dstX, - const int dstY, - const int width, - const int height) -{ -// if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - const float texX2 = static_cast(srcX + width) / tw; - const float texY2 = static_cast(srcY + height) / th; - - GLfloat tex[] = - { - texX1, texY1, - texX2, texY1, - texX1, texY2, - texX2, texY2 - }; - - GLshort vert[] = - { - static_cast(dstX), static_cast(dstY), - static_cast(dstX + width), static_cast(dstY), - static_cast(dstX), static_cast(dstY + height), - static_cast(dstX + width), - static_cast(dstY + height) - }; - - glVertexPointer(2, GL_SHORT, 0, &vert); - glTexCoordPointer(2, GL_FLOAT, 0, &tex); - -#ifdef DEBUG_DRAW_CALLS - MobileOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } -} - -static inline void drawRescaledQuad(const Image *restrict const image, - const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) - A_NONNULL(1) A_INLINE; - -static inline void drawRescaledQuad(const Image *restrict const image, - const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) -{ -// if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - const float texX2 = static_cast(srcX + width) / tw; - const float texY2 = static_cast(srcY + height) / th; - - GLfloat tex[] = - { - texX1, texY1, - texX2, texY1, - texX1, texY2, - texX2, texY2 - }; - - GLshort vert[] = - { - static_cast(dstX), static_cast(dstY), - static_cast(dstX + desiredWidth), - static_cast(dstY), - static_cast(dstX), static_cast( - dstY + desiredHeight), - static_cast(dstX + desiredWidth), - static_cast(dstY + desiredHeight) - }; - glVertexPointer(2, GL_SHORT, 0, &vert); - glTexCoordPointer(2, GL_FLOAT, 0, &tex); - -#ifdef DEBUG_DRAW_CALLS - MobileOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } -} - -void MobileOpenGLGraphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void MobileOpenGLGraphics::drawImageInline(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - if (image == nullptr) - return; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - const SDL_Rect &imageRect = image->mBounds; - drawQuad(image, imageRect.x, imageRect.y, - dstX, dstY, imageRect.w, imageRect.h); -} - -void MobileOpenGLGraphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void MobileOpenGLGraphics::drawImageCached(const Image *restrict const image, - int x, int y) restrict2 -{ - if (image == nullptr) - return; - - if (image->mGLImage != mImageCached) - { - completeCache(); - mImageCached = image->mGLImage; - mAlphaCached = image->mAlpha; - } - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int w = imageRect.w; - const int h = imageRect.h; - - if (w == 0 || h == 0) - return; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const unsigned int vLimit = mMaxVertices * 4; - - unsigned int vp = mVpCached; - - // Draw a set of textured rectangles -// if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - float texX1 = static_cast(srcX) / tw; - float texY1 = static_cast(srcY) / th; - float texX2 = static_cast(srcX + w) / tw; - float texY2 = static_cast(srcY + h) / th; - - vertFill2D(mFloatTexArrayCached, mShortVertArrayCached, - texX1, texY1, texX2, texY2, - x, y, w, h); - - vp += 12; - if (vp >= vLimit) - { - completeCache(); - vp = 0; - } - else - { - mVpCached = vp; - } - } -} - -void MobileOpenGLGraphics::drawPatternCached(const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) restrict2 -{ - if (image == nullptr) - return; - - if (image->mGLImage != mImageCached) - { - completeCache(); - mImageCached = image->mGLImage; - } - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - unsigned int vp = mVpCached; - const unsigned int vLimit = mMaxVertices * 4; - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const float texY2 = static_cast(srcY + height) / th; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - - const float texX2 = static_cast(srcX + width) / tw; - - vertFill2D(mFloatTexArrayCached, mShortVertArrayCached, - texX1, texY1, texX2, texY2, - dstX, dstY, width, height); - - vp += 12; - if (vp >= vLimit) - { - completeCache(); - vp = 0; - } - } - } - mVpCached = vp; -} - -void MobileOpenGLGraphics::completeCache() restrict2 -{ - if (mImageCached == 0u) - return; - - setColorAlpha(mAlphaCached); -#ifdef DEBUG_BIND_TEXTURE -// debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture(OpenGLImageHelper::mTextureType, mImageCached); - enableTexturingAndBlending(); - - drawTriangleArrayfsCached(mVpCached); - mImageCached = 0; - mVpCached = 0; -} - -void MobileOpenGLGraphics::drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - FUNC_BLOCK("Graphics::drawRescaledImage", 1) - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - - // Just draw the image normally when no resizing is necessary, - if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) - { - drawImageInline(image, dstX, dstY); - return; - } - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - // Draw a textured quad. - drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY, - imageRect.w, imageRect.h, desiredWidth, desiredHeight); -} - -void MobileOpenGLGraphics::drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - drawPatternInline(image, x, y, w, h); -} - -void MobileOpenGLGraphics::drawPatternInline(const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPattern", 1) - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - setColorAlpha(image->mAlpha); - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - - enableTexturingAndBlending(); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - // Draw a set of textured rectangles - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const float texY2 = static_cast(srcY + height) / th; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - - const float texX2 = static_cast(srcX + width) / tw; - - vertFill2D(mFloatTexArray, mShortVertArray, - texX1, texY1, texX2, texY2, - dstX, dstY, width, height); - - vp += 12; - if (vp >= vLimit) - { - drawTriangleArrayfs(vp); - vp = 0; - } - } - } - if (vp > 0) - drawTriangleArrayfs(vp); -} - -void MobileOpenGLGraphics::drawRescaledPattern(const Image * - restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) - restrict2 -{ - if (image == nullptr) - return; - - if (scaledWidth == 0 || scaledHeight == 0) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - if (iw == 0 || ih == 0) - return; - - setColorAlpha(image->mAlpha); - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - - enableTexturingAndBlending(); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - // Draw a set of textured rectangles - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - const float tFractionW = iw / tw; - const float tFractionH = ih / th; - - for (int py = 0; py < h; py += scaledHeight) - { - const int height = (py + scaledHeight >= h) - ? h - py : scaledHeight; - const int dstY = y + py; - const float visibleFractionH = static_cast(height) - / scaledHeight; - const float texY2 = texY1 + tFractionH * visibleFractionH; - for (int px = 0; px < w; px += scaledWidth) - { - const int width = (px + scaledWidth >= w) - ? w - px : scaledWidth; - const int dstX = x + px; - const float visibleFractionW = static_cast(width) - / scaledWidth; - const float texX2 = texX1 + tFractionW * visibleFractionW; - - vertFill2D(mFloatTexArray, mShortVertArray, - texX1, texY1, texX2, texY2, - dstX, dstY, width, height); - - vp += 12; - if (vp >= vLimit) - { - drawTriangleArrayfs(vp); - vp = 0; - } - } - } - if (vp > 0) - drawTriangleArrayfs(vp); -} - -inline void MobileOpenGLGraphics::drawVertexes(const - OpenGLGraphicsVertexes - &restrict ogl) restrict2 -{ - const STD_VECTOR &shortVertPool = ogl.mShortVertPool; - STD_VECTOR::const_iterator iv; - const STD_VECTOR::const_iterator iv_end = shortVertPool.end(); - const STD_VECTOR &vp = ogl.mVp; - STD_VECTOR::const_iterator ivp; - const STD_VECTOR::const_iterator ivp_end = vp.end(); - - // Draw a set of textured rectangles -// if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const STD_VECTOR &floatTexPool = ogl.mFloatTexPool; - STD_VECTOR::const_iterator ft; - const STD_VECTOR::const_iterator - ft_end = floatTexPool.end(); - - for (iv = shortVertPool.begin(), ft = floatTexPool.begin(), - ivp = vp.begin(); - iv != iv_end && ft != ft_end && ivp != ivp_end; - ++ iv, ++ ft, ++ ivp) - { - drawTriangleArrayfs(*iv, *ft, *ivp); - } - } -} - -void MobileOpenGLGraphics::calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - calcPatternInline(vert, image, x, y, w, h); -} - -void MobileOpenGLGraphics::calcPatternInline(ImageVertexes * - restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - if (image == nullptr || vert == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - unsigned int vp = ogl.continueVp(); - - // Draw a set of textured rectangles -// if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - GLfloat *floatTexArray = ogl.continueFloatTexArray(); - GLshort *shortVertArray = ogl.continueShortVertArray(); - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - const float texY2 = static_cast(srcY + height) / th; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - const float texX2 = static_cast(srcX + width) / tw; - - vertFill2D(floatTexArray, shortVertArray, - texX1, texY1, texX2, texY2, - dstX, dstY, width, height); - - vp += 12; - if (vp >= vLimit) - { - floatTexArray = ogl.switchFloatTexArray(); - shortVertArray = ogl.switchShortVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - } - } - ogl.switchVp(vp); -} - -void MobileOpenGLGraphics::calcTileCollection(ImageCollection * - restrict const vertCol, - const Image * - restrict const image, - int x, int y) restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - ImageVertexes *const vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - calcTileVertexesInline(vert, image, x, y); - } - else - { - calcTileVertexesInline(vertCol->currentVert, image, x, y); - } -} - -void MobileOpenGLGraphics::drawTileCollection(const ImageCollection * - restrict const vertCol) - restrict2 -{ - const ImageVertexesVector &draws = vertCol->draws; - const ImageCollectionCIter it_end = draws.end(); - for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) - { - const ImageVertexes *const vert = *it; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - drawVertexes(vert->ogl); - } -} - -void MobileOpenGLGraphics::calcPattern(ImageCollection *restrict const vertCol, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - ImageVertexes *vert = nullptr; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - - calcPatternInline(vert, image, x, y, w, h); -} - -void MobileOpenGLGraphics::calcTileVertexes(ImageVertexes *restrict const vert, - const Image *restrict const image, - int dstX, int dstY) const restrict2 -{ - calcTileVertexesInline(vert, image, dstX, dstY); -} - -void MobileOpenGLGraphics::calcTileVertexesInline(ImageVertexes * - restrict const vert, - const Image * - restrict const image, - int dstX, - int dstY) const restrict2 -{ - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int w = imageRect.w; - const int h = imageRect.h; - - if (w == 0 || h == 0) - return; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - -// STD_VECTOR *vps = ogl.getVp(); - unsigned int vp = ogl.continueVp(); - - // Draw a set of textured rectangles -// if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - float texX1 = static_cast(srcX) / tw; - float texY1 = static_cast(srcY) / th; - float texX2 = static_cast(srcX + w) / tw; - float texY2 = static_cast(srcY + h) / th; - - GLfloat *const floatTexArray = ogl.continueFloatTexArray(); - GLshort *const shortVertArray = ogl.continueShortVertArray(); - - vertFill2D(floatTexArray, shortVertArray, - texX1, texY1, texX2, texY2, - dstX, dstY, w, h); - - vp += 12; - if (vp >= vLimit) - { - ogl.switchFloatTexArray(); - ogl.switchShortVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - ogl.switchVp(vp); -} - -void MobileOpenGLGraphics::drawTileVertexes(const ImageVertexes * - restrict const vert) restrict2 -{ - if (vert == nullptr) - return; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - drawVertexes(vert->ogl); -} - -void MobileOpenGLGraphics::calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - ImageVertexes *vert = nullptr; - const Image *const image = imgRect.grid[4]; - if (image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - calcImageRect(vert, x, y, w, h, imgRect); -} - - -void MobileOpenGLGraphics::updateScreen() restrict2 -{ - BLOCK_START("Graphics::updateScreen") -// glFlush(); -// glFinish(); -#ifdef DEBUG_DRAW_CALLS - mLastDrawCalls = mDrawCalls; - mDrawCalls = 0; -#endif // DEBUG_DRAW_CALLS -#ifdef USE_SDL2 - SDL_GL_SwapWindow(mWindow); -#else // USE_SDL2 - - SDL_GL_SwapBuffers(); -#endif // USE_SDL2 -#ifdef DEBUG_OPENGL - if (isGLNotNull(mglFrameTerminator)) - mglFrameTerminator(); -#endif // DEBUG_OPENGL - - BLOCK_END("Graphics::updateScreen") -} - -void MobileOpenGLGraphics::beginDraw() restrict2 -{ - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - -#ifdef ANDROID - glOrthof(0.0, static_cast(mRect.w), - static_cast(mRect.h), - 0.0, -1.0, 1.0); -#else // ANDROID - - glOrtho(0.0, static_cast(mRect.w), - static_cast(mRect.h), - 0.0, -1.0, 1.0); -#endif // ANDROID - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - setOpenGLFlags(); - mglDisable(GL_LIGHTING); - mglDisable(GL_FOG); - mglDisable(GL_COLOR_MATERIAL); - - glShadeModel(GL_FLAT); - - glEnableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - -#ifndef ANDROID - mglHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); - mglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); - mglHint(GL_POINT_SMOOTH_HINT, GL_FASTEST); - mglHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST); -#endif // ANDROID - - pushClipArea(Rect(0, 0, mRect.w, mRect.h)); -} - -void MobileOpenGLGraphics::endDraw() restrict2 -{ - popClipArea(); -} - -void MobileOpenGLGraphics::pushClipArea(const Rect &restrict area) restrict2 -{ - int transX = 0; - int transY = 0; - - if (!mClipStack.empty()) - { - const ClipRect &clipArea = mClipStack.top(); - transX = -clipArea.xOffset; - transY = -clipArea.yOffset; - } - - Graphics::pushClipArea(area); - - const ClipRect &clipArea = mClipStack.top(); - transX += clipArea.xOffset; - transY += clipArea.yOffset; - - if (transX != 0 || transY != 0) - { - glTranslatef(static_cast(transX), - static_cast(transY), 0); - } - mglScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -void MobileOpenGLGraphics::popClipArea() restrict2 -{ - if (mClipStack.empty()) - return; - - const ClipRect &clipArea1 = mClipStack.top(); - int transX = -clipArea1.xOffset; - int transY = -clipArea1.yOffset; - - Graphics::popClipArea(); - - if (mClipStack.empty()) - return; - - const ClipRect &clipArea = mClipStack.top(); - transX += clipArea.xOffset; - transY += clipArea.yOffset; - if (transX != 0 || transY != 0) - { - glTranslatef(static_cast(transX), - static_cast(transY), 0); - } - mglScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -#ifdef ANDROID -void MobileOpenGLGraphics::drawPoint(int x A_UNUSED, int y A_UNUSED) restrict2 -#else // ANDROID -void MobileOpenGLGraphics::drawPoint(int x, int y) restrict2 -#endif // ANDROID -{ - disableTexturingAndBlending(); - restoreColor(); - -#ifdef ANDROID - // TODO need fix -#else // ANDROID - - glBegin(GL_POINTS); - glVertex2i(x, y); - glEnd(); -#endif // ANDROID -} - -void MobileOpenGLGraphics::drawLine(int x1, int y1, - int x2, int y2) restrict2 -{ - disableTexturingAndBlending(); - restoreColor(); - - mShortVertArray[0] = static_cast(x1); - mShortVertArray[1] = static_cast(y1); - mShortVertArray[2] = static_cast(x2); - mShortVertArray[3] = static_cast(y2); - - drawLineArrays(4); -} - -void MobileOpenGLGraphics::drawRectangle(const Rect &restrict rect) restrict2 -{ - drawRectangle(rect, false); -} - -void MobileOpenGLGraphics::fillRectangle(const Rect &restrict rect) restrict2 -{ - drawRectangle(rect, true); -} - -void MobileOpenGLGraphics::enableTexturingAndBlending() restrict2 -{ - if (!mTexture) - { - mglEnable(OpenGLImageHelper::mTextureType); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - mTexture = true; - } - - if (!mAlpha) - { - mglEnable(GL_BLEND); - mAlpha = true; - } -} - -void MobileOpenGLGraphics::disableTexturingAndBlending() restrict2 -{ - mTextureBinded = 0; - if (mAlpha && !mColorAlpha) - { - mglDisable(GL_BLEND); - mAlpha = false; - } - else if (!mAlpha && mColorAlpha) - { - mglEnable(GL_BLEND); - mAlpha = true; - } - - if (mTexture) - { - mglDisable(OpenGLImageHelper::mTextureType); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - mTexture = false; - } -} - -void MobileOpenGLGraphics::drawRectangle(const Rect &restrict rect, - const bool filled) restrict2 -{ - BLOCK_START("Graphics::drawRectangle") - disableTexturingAndBlending(); - restoreColor(); - - const GLshort x = static_cast(rect.x); - const GLshort y = static_cast(rect.y); - const GLshort width = static_cast(rect.width); - const GLshort height = static_cast(rect.height); - const GLshort xw = static_cast(rect.x + width); - const GLshort yh = static_cast(rect.y + height); - - if (filled) - { - GLshort vert[] = - { - x, y, - xw, y, - x, yh, - xw, yh - }; - - glVertexPointer(2, GL_SHORT, 0, &vert); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } - else - { - GLshort vert[] = - { - x, y, - xw, y, - xw, yh, - x, yh - }; - - glVertexPointer(2, GL_SHORT, 0, &vert); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - mglDrawArrays(GL_LINE_LOOP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } - BLOCK_END("Graphics::drawRectangle") -} - -void MobileOpenGLGraphics::drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) restrict2 -{ - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - disableTexturingAndBlending(); - restoreColor(); - - const GLshort xs1 = static_cast(x1); - const GLshort xs2 = static_cast(x2); - const GLshort ys1 = static_cast(y1); - const GLshort ys2 = static_cast(y2); - const int16_t width1 = CAST_S16(width); - const int16_t height1 = CAST_S16(height); - - for (int16_t y = CAST_S16(y1); y < y2; y += height1) - { - mShortVertArray[vp + 0] = xs1; - mShortVertArray[vp + 1] = y; - - mShortVertArray[vp + 2] = xs2; - mShortVertArray[vp + 3] = y; - - vp += 4; - if (vp >= vLimit) - { - drawLineArrays(vp); - vp = 0; - } - } - - for (int16_t x = CAST_S16(x1); x < x2; x += width1) - { - mShortVertArray[vp + 0] = x; - mShortVertArray[vp + 1] = ys1; - - mShortVertArray[vp + 2] = x; - mShortVertArray[vp + 3] = ys2; - - vp += 4; - if (vp >= vLimit) - { - drawLineArrays(vp); - vp = 0; - } - } - - if (vp > 0) - drawLineArrays(vp); -} - -void MobileOpenGLGraphics::bindTexture(const GLenum target, - const GLuint texture) -{ - if (mTextureBinded != texture) - { - mTextureBinded = texture; - mglBindTexture(target, texture); - } -} - -inline void MobileOpenGLGraphics::drawTriangleArrayfs(const int size) restrict2 -{ - glVertexPointer(2, GL_SHORT, 0, mShortVertArray); - glTexCoordPointer(2, GL_FLOAT, 0, mFloatTexArray); - -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - mglDrawArrays(GL_TRIANGLES, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void MobileOpenGLGraphics::drawTriangleArrayfsCached(const int size) - restrict2 -{ - glVertexPointer(2, GL_SHORT, 0, mShortVertArrayCached); - glTexCoordPointer(2, GL_FLOAT, 0, mFloatTexArrayCached); - -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - mglDrawArrays(GL_TRIANGLES, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void MobileOpenGLGraphics::drawTriangleArrayfs(const GLshort *restrict - const shortVertArray, - const GLfloat *restrict - const floatTexArray, - const int size) restrict2 -{ - glVertexPointer(2, GL_SHORT, 0, shortVertArray); - glTexCoordPointer(2, GL_FLOAT, 0, floatTexArray); - -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - mglDrawArrays(GL_TRIANGLES, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void MobileOpenGLGraphics::drawLineArrays(const int size) restrict2 -{ - glVertexPointer(2, GL_SHORT, 0, mShortVertArray); - -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - mglDrawArrays(GL_LINES, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void MobileOpenGLGraphics::dumpSettings() -{ - GLint test[1000]; - logger->log("\n\n"); - logger->log("start opengl dump"); - for (int f = 0; f < 65535; f ++) - { - test[0] = 0; - test[1] = 0; - test[2] = 0; - test[3] = 0; - mglGetIntegerv(f, &test[0]); - if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0) - { - logger->log("\n%d = %d, %d, %d, %d", f, - test[0], test[1], test[2], test[3]); - } - } -} - -void MobileOpenGLGraphics::setColorAlpha(const float alpha) restrict2 -{ - if (!mIsByteColor && mFloatColor == alpha) - return; - - glColor4f(1.0F, 1.0F, 1.0F, alpha); - mIsByteColor = false; - mFloatColor = alpha; -} - -void MobileOpenGLGraphics::restoreColor() restrict2 -{ - if (mIsByteColor && mByteColor == mColor) - return; - - glColor4ub(static_cast(mColor.r), - static_cast(mColor.g), - static_cast(mColor.b), - static_cast(mColor.a)); - mIsByteColor = true; - mByteColor = mColor; -} - -void MobileOpenGLGraphics::drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_drawImageRect.hpp" -} - -void MobileOpenGLGraphics::calcImageRect(ImageVertexes *restrict const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_calcImageRect.hpp" -} - -void MobileOpenGLGraphics::clearScreen() const restrict2 -{ - mglClear(GL_COLOR_BUFFER_BIT | - GL_DEPTH_BUFFER_BIT | - GL_STENCIL_BUFFER_BIT); -} - -#ifdef DEBUG_BIND_TEXTURE -void MobileOpenGLGraphics::debugBindTexture(const Image *restrict const image) - restrict2 -{ - const std::string texture = image->mIdPath; - if (mOldTexture != texture) - { - if ((!mOldTexture.empty() || !texture.empty()) - && mOldTextureId != image->mGLImage) - { - logger->log("bind: %s (%d) to %s (%d)", mOldTexture.c_str(), - mOldTextureId, texture.c_str(), image->mGLImage); - } - mOldTextureId = image->mGLImage; - mOldTexture = texture; - } -} -#else // DEBUG_BIND_TEXTURE - -void MobileOpenGLGraphics::debugBindTexture(const Image *restrict const - image A_UNUSED) restrict2 -{ -} -#endif // DEBUG_BIND_TEXTURE - -#endif // defined(USE_OPENGL) && !defined(__native_client__) diff --git a/src/render/mobileopenglgraphics.h b/src/render/mobileopenglgraphics.h deleted file mode 100644 index 7f4da86da..000000000 --- a/src/render/mobileopenglgraphics.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_MOBILEOPENGLGRAPHICS_H -#define RENDER_MOBILEOPENGLGRAPHICS_H - -#if defined(USE_OPENGL) && !defined(__native_client__) - -#include "localconsts.h" - -#include "render/graphics.h" - -#include "resources/fboinfo.h" - -#ifdef ANDROID -#include -#include -#include -#else // ANDROID -#ifndef USE_SDL2 -#define GL_GLEXT_PROTOTYPES 1 -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#include -PRAGMA48(GCC diagnostic pop) -#if defined(__APPLE__) -#include -#elif !defined(__native_client__) -#include -#endif // defined(__APPLE__) -#endif // ANDROID - -class OpenGLGraphicsVertexes; - -class MobileOpenGLGraphics final : public Graphics -{ - public: - MobileOpenGLGraphics(); - - A_DELETE_COPY(MobileOpenGLGraphics) - - ~MobileOpenGLGraphics(); - - void postInit() restrict2 override final; - - inline void drawTriangleArrayfs(const GLshort *restrict const - shortVertArray, - const GLfloat *restrict const - floatTexArray, - const int size) restrict2 A_INLINE; - - inline void drawTriangleArrayfs(const int size) restrict2 A_INLINE; - - inline void drawTriangleArrayfsCached(const int size) - restrict2 A_INLINE; - - inline void drawLineArrays(const int size) restrict2 A_INLINE; - - #include "render/graphicsdef.hpp" - RENDER_GRAPHICSDEF_HPP - - #include "render/openglgraphicsdef1.hpp" - RENDER_OPENGLGRAPHICSDEF1_HPP - - #include "render/openglgraphicsdef.hpp" - RENDER_OPENGLGRAPHICSDEF_HPP - - #include "render/openglgraphicsdefadvanced.hpp" - RENDER_OPENGLGRAPHICSDEFADVANCED_HPP - - private: - GLfloat *mFloatTexArray; - GLshort *mShortVertArray; - GLfloat *mFloatTexArrayCached; - GLshort *mShortVertArrayCached; - float mAlphaCached; - int mVpCached; - bool mTexture; - - bool mIsByteColor; - Color mByteColor; - GLuint mImageCached; - float mFloatColor; - int mMaxVertices; - bool mColorAlpha; -#ifdef DEBUG_BIND_TEXTURE - std::string mOldTexture; - unsigned mOldTextureId; -#endif // DEBUG_BIND_TEXTURE - - FBOInfo mFbo; -}; -#endif // defined(USE_OPENGL) && !defined(__native_client__) - -#endif // RENDER_MOBILEOPENGLGRAPHICS_H diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp deleted file mode 100644 index be1ec4f73..000000000 --- a/src/render/modernopenglgraphics.cpp +++ /dev/null @@ -1,1403 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__native_client__) - -#include "render/modernopenglgraphics.h" - -#include "graphicsmanager.h" - -#include "render/opengl/mgl.h" -#ifdef __native_client__ -#include "render/opengl/naclglfunctions.h" -#endif // __native_client__ - -#include "render/shaders/shaderprogram.h" -#include "render/shaders/shadersmanager.h" - -#include "render/vertexes/imagecollection.h" - -#include "resources/imagerect.h" -#include "resources/openglimagehelper.h" - -#include "resources/image/image.h" - -#include "utils/delete2.h" -#include "utils/foreach.h" -#include "utils/sdlcheckutils.h" -#include "utils/sdlhelper.h" - -#include "debug.h" - -#define vertFill2D(var, x1, y1, x2, y2, dstX, dstY, w, h) \ - var[vp + 0] = dstX; \ - var[vp + 1] = dstY; \ - var[vp + 2] = x1; \ - var[vp + 3] = y1; \ - \ - var[vp + 4] = dstX + w; \ - var[vp + 5] = dstY; \ - var[vp + 6] = x2; \ - var[vp + 7] = y1; \ - \ - var[vp + 8] = dstX + w; \ - var[vp + 9] = dstY + h; \ - var[vp + 10] = x2; \ - var[vp + 11] = y2; \ - \ - var[vp + 12] = dstX; \ - var[vp + 13] = dstY; \ - var[vp + 14] = x1; \ - var[vp + 15] = y1; \ - \ - var[vp + 16] = dstX; \ - var[vp + 17] = dstY + h; \ - var[vp + 18] = x1; \ - var[vp + 19] = y2; \ - \ - var[vp + 20] = dstX + w; \ - var[vp + 21] = dstY + h; \ - var[vp + 22] = x2; \ - var[vp + 23] = y2; - -GLuint ModernOpenGLGraphics::mTextureBinded = 0; -#ifdef DEBUG_DRAW_CALLS -unsigned int ModernOpenGLGraphics::mDrawCalls = 0; -unsigned int ModernOpenGLGraphics::mLastDrawCalls = 0; -#endif // DEBUG_DRAW_CALLS - -ModernOpenGLGraphics::ModernOpenGLGraphics() : - mIntArray(nullptr), - mIntArrayCached(nullptr), - mProgram(nullptr), - mAlphaCached(1.0F), - mVpCached(0), - mFloatColor(1.0F), - mMaxVertices(500), - mProgramId(0U), - mSimpleColorUniform(0U), - mPosAttrib(0), - mTextureColorUniform(0U), - mScreenUniform(0U), - mDrawTypeUniform(0U), - mVao(0U), - mVbo(0U), - mEbo(0U), - mVboBinded(0U), - mEboBinded(0U), - mAttributesBinded(0U), - mColorAlpha(false), - mTextureDraw(false), -#ifdef DEBUG_BIND_TEXTURE - mOldTexture(), - mOldTextureId(0), -#endif // DEBUG_BIND_TEXTURE - mFbo() -{ - mOpenGL = RENDER_MODERN_OPENGL; - mName = "modern OpenGL"; -} - -ModernOpenGLGraphics::~ModernOpenGLGraphics() -{ - deleteArraysInternal(); - deleteGLObjects(); -} - -void ModernOpenGLGraphics::deleteGLObjects() restrict2 -{ - delete2(mProgram); - if (mVbo != 0u) - { -// logger->log("delete buffer vbo: %u", mVbo); - mglDeleteBuffers(1, &mVbo); - } - if (mEbo != 0u) - { -// logger->log("delete buffer ebo: %u", mEbo); - mglDeleteBuffers(1, &mEbo); - } - if (mVao != 0u) - mglDeleteVertexArrays(1, &mVao); -} - -void ModernOpenGLGraphics::initArrays(const int vertCount) restrict2 -{ - mMaxVertices = vertCount; - if (mMaxVertices < 500) - mMaxVertices = 500; - else if (mMaxVertices > 1024) - mMaxVertices = 1024; - - // need alocate small size, after if limit reached reallocate to double size - const size_t sz = mMaxVertices * 4 + 30; - vertexBufSize = mMaxVertices; - if (mIntArray == nullptr) - mIntArray = new GLint[sz]; - if (mIntArrayCached == nullptr) - mIntArrayCached = new GLint[sz]; -} - -void ModernOpenGLGraphics::postInit() restrict2 -{ - mglGenVertexArrays(1, &mVao); - mglBindVertexArray(mVao); - mglGenBuffers(1, &mVbo); -// logger->log("gen vbo buffer: %u", mVbo); - bindArrayBuffer(mVbo); - mglGenBuffers(1, &mEbo); -// logger->log("gen ebo buffer: %u", mEbo); - bindElementBuffer(mEbo); - - logger->log("Compiling shaders"); - mProgram = shaders.getSimpleProgram(); - if (mProgram == nullptr) - { - graphicsManager.logError(); - logger->safeError("Shader creation error. See manaplus.log."); - } - mProgramId = mProgram->getProgramId(); - if (mProgramId == 0u) - logger->error("Shaders compilation error."); - - logger->log("Shaders compilation done."); - mglUseProgram(mProgramId); - - mPosAttrib = mglGetAttribLocation(mProgramId, "position"); - mglEnableVertexAttribArray(mPosAttrib); - mglVertexAttribIFormat(mPosAttrib, 4, GL_INT, 0); - - mSimpleColorUniform = mglGetUniformLocation(mProgramId, "color"); - mScreenUniform = mglGetUniformLocation(mProgramId, "screen"); - mDrawTypeUniform = mglGetUniformLocation(mProgramId, "drawType"); - mTextureColorUniform = mglGetUniformLocation(mProgramId, "alpha"); - - mglUniform1f(mTextureColorUniform, 1.0f); - - mglBindVertexBuffer(0, mVbo, 0, 4 * sizeof(GLint)); - mglVertexAttribBinding(mPosAttrib, 0); -// mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0); - mAttributesBinded = mVbo; - - mglUniform2f(mScreenUniform, - static_cast(mWidth) / 2.0f, - static_cast(mHeight) / 2.0f); - mglUniform4f(mSimpleColorUniform, - 0.0F, - 0.0F, - 0.0F, - 0.0F); -} - -void ModernOpenGLGraphics::screenResized() restrict2 -{ - deleteGLObjects(); - mVboBinded = 0U; - mEboBinded = 0U; - mAttributesBinded = 0U; - mColor = Color(0, 0, 0, 0); - postInit(); -} - -void ModernOpenGLGraphics::deleteArrays() restrict2 -{ - deleteArraysInternal(); -} - -void ModernOpenGLGraphics::deleteArraysInternal() restrict2 -{ - delete [] mIntArray; - mIntArray = nullptr; - delete [] mIntArrayCached; - mIntArrayCached = nullptr; -} - -bool ModernOpenGLGraphics::setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - setMainFlags(w, h, - scale, - bpp, - fs, - hwaccel, - resize, - noFrame, - allowHighDPI); - - return setOpenGLMode(); -} - -void ModernOpenGLGraphics::setColor(const Color &restrict color) restrict2 -{ - mColorAlpha = (color.a != 255); - if (mColor != color) - { - mColor = color; - mglUniform4f(mSimpleColorUniform, - static_cast(color.r) / 255.0F, - static_cast(color.g) / 255.0F, - static_cast(color.b) / 255.0F, - static_cast(color.a) / 255.0F); - } -} - -void ModernOpenGLGraphics::setColorAlpha(const float alpha) restrict2 -{ - if (mAlphaCached != alpha) - { - mAlphaCached = alpha; - mglUniform1f(mTextureColorUniform, alpha); - } -} - -void ModernOpenGLGraphics::drawQuad(const int srcX, - const int srcY, - const int dstX, - const int dstY, - const int width, - const int height) restrict2 -{ - const int texX2 = srcX + width; - const int texY2 = srcY + height; - const int x2 = dstX + width; - const int y2 = dstY + height; - - GLint vertices[] = - { - dstX, dstY, srcX, srcY, - x2, dstY, texX2, srcY, - dstX, y2, srcX, texY2, - x2, y2, texX2, texY2 - }; - -// logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices)); - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void ModernOpenGLGraphics::drawRescaledQuad(const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - const int texX2 = srcX + width; - const int texY2 = srcY + height; - const int x2 = dstX + desiredWidth; - const int y2 = dstY + desiredHeight; - - GLint vertices[] = - { - dstX, dstY, srcX, srcY, - x2, dstY, texX2, srcY, - dstX, y2, srcX, texY2, - x2, y2, texX2, texY2 - }; - -// logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices)); - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void ModernOpenGLGraphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void ModernOpenGLGraphics::drawImageInline(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - if (image == nullptr) - return; - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture(GL_TEXTURE_2D, image->mGLImage); - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - setColorAlpha(image->mAlpha); - - const ClipRect &clipArea = mClipStack.top(); - const SDL_Rect &imageRect = image->mBounds; - drawQuad(imageRect.x, imageRect.y, - dstX + clipArea.xOffset, dstY + clipArea.yOffset, - imageRect.w, imageRect.h); -} - -void ModernOpenGLGraphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void ModernOpenGLGraphics::testDraw() restrict2 -{ -/* - GLint vertices[] = - { - 0, 0, 0, 0, - 800, 0, 800, 0, - 0, 600, 0, 600, - 800, 600, 800, 600 - }; -*/ -// logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices)); -// logger->log("allocate ebo: %d, %ld", mEboBinded, sizeof(elements)); -// mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), -// vertices, GL_STREAM_DRAW); -// mglBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), -// elements, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -// glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void ModernOpenGLGraphics::drawImageCached(const Image *restrict const image - A_UNUSED, - int A_UNUSED x, - int y A_UNUSED) restrict2 -{ -} - -void ModernOpenGLGraphics::drawPatternCached(const Image *restrict const image - A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) restrict2 -{ -} - -void ModernOpenGLGraphics::completeCache() restrict2 -{ -} - -void ModernOpenGLGraphics::drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - - // Just draw the image normally when no resizing is necessary, - if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) - { - drawImageInline(image, dstX, dstY); - return; - } - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - - const ClipRect &clipArea = mClipStack.top(); - // Draw a textured quad. - drawRescaledQuad(imageRect.x, imageRect.y, - dstX + clipArea.xOffset, dstY + clipArea.yOffset, - imageRect.w, imageRect.h, - desiredWidth, desiredHeight); -} - -void ModernOpenGLGraphics::drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - drawPatternInline(image, x, y, w, h); -} - -void ModernOpenGLGraphics::drawPatternInline(const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) restrict2 -{ - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const ClipRect &clipArea = mClipStack.top(); - const int x2 = x + clipArea.xOffset; - const int y2 = y + clipArea.yOffset; - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - setColorAlpha(image->mAlpha); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int texY2 = srcY + height; - const int dstY = y2 + py; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x2 + px; - - const int texX2 = srcX + width; - - vertFill2D(mIntArray, - srcX, srcY, texX2, texY2, - dstX, dstY, width, height); - - vp += 24; - if (vp >= vLimit) - { - drawTriangleArray(vp); - vp = 0; - } - } - } - if (vp > 0) - drawTriangleArray(vp); -} - -void ModernOpenGLGraphics::drawRescaledPattern(const Image * - restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) - restrict2 -{ - if (image == nullptr) - return; - - if (scaledWidth == 0 || scaledHeight == 0) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - if (iw == 0 || ih == 0) - return; - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - setColorAlpha(image->mAlpha); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - const ClipRect &clipArea = mClipStack.top(); - const int x2 = x + clipArea.xOffset; - const int y2 = y + clipArea.yOffset; - - const float scaleFactorW = static_cast(scaledWidth) / iw; - const float scaleFactorH = static_cast(scaledHeight) / ih; - - for (int py = 0; py < h; py += scaledHeight) - { - const int height = (py + scaledHeight >= h) - ? h - py : scaledHeight; - const int dstY = y2 + py; - const int scaledY = srcY + height / scaleFactorH; - for (int px = 0; px < w; px += scaledWidth) - { - const int width = (px + scaledWidth >= w) - ? w - px : scaledWidth; - const int dstX = x2 + px; - const int scaledX = srcX + width / scaleFactorW; - - vertFill2D(mIntArray, - srcX, srcY, scaledX, scaledY, - dstX, dstY, width, height); - - vp += 24; - if (vp >= vLimit) - { - drawTriangleArray(vp); - vp = 0; - } - } - } - if (vp > 0) - drawTriangleArray(vp); -} - -inline void ModernOpenGLGraphics::drawVertexes(const - OpenGLGraphicsVertexes & - restrict ogl) restrict2 -{ - const STD_VECTOR &vp = ogl.mVp; - const STD_VECTOR &vbos = ogl.mVbo; - STD_VECTOR::const_iterator ivp; - STD_VECTOR::const_iterator ivbo; - const STD_VECTOR::const_iterator ivp_end = vp.end(); - -/* - if (vp.size() != vbos.size()) - logger->log("different size in vp and vbos"); -*/ - - for (ivp = vp.begin(), ivbo = vbos.begin(); - ivp != ivp_end; - ++ ivp, ++ ivbo) - { - bindArrayBufferAndAttributes(*ivbo); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS -// logger->log("draw from array: %u", *ivbo); - mglDrawArrays(GL_TRIANGLES, 0, *ivp / 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } -} - -void ModernOpenGLGraphics::calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - calcPatternInline(vert, image, x, y, w, h); -} - -void ModernOpenGLGraphics::calcPatternInline(ImageVertexes * - restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - if (image == nullptr || vert == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const ClipRect &clipArea = mClipStack.top(); - const int x2 = x + clipArea.xOffset; - const int y2 = y + clipArea.yOffset; - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - unsigned int vp = ogl.continueVp(); - - GLint *intArray = ogl.continueIntTexArray(); - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y2 + py; - const int texY2 = srcY + height; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x2 + px; - const int texX2 = srcX + width; - - vertFill2D(intArray, - srcX, srcY, texX2, texY2, - dstX, dstY, width, height); - - vp += 24; - if (vp >= vLimit) - { - intArray = ogl.switchIntTexArray(); - ogl.switchVp(vp); - vp = 0; - } - } - } - ogl.switchVp(vp); -} - -void ModernOpenGLGraphics::calcTileCollection(ImageCollection * - restrict const vertCol, - const Image * - restrict const image, - int x, int y) restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - ImageVertexes *const vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - calcTileVertexesInline(vert, image, x, y); - } - else - { - calcTileVertexesInline(vertCol->currentVert, image, x, y); - } -} - -void ModernOpenGLGraphics::drawTileCollection(const ImageCollection - *restrict const vertCol) - restrict2 -{ - enableTexturingAndBlending(); -/* - if (!vertCol) - { - logger->log("ModernOpenGLGraphics::drawTileCollection" - " vertCol is nullptr"); - } -*/ - const ImageVertexesVector &draws = vertCol->draws; - const ImageCollectionCIter it_end = draws.end(); - for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) - { - const ImageVertexes *const vert = *it; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - drawVertexes(vert->ogl); - } -} - -void ModernOpenGLGraphics::calcPattern(ImageCollection *restrict const vertCol, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - ImageVertexes *vert = nullptr; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - - calcPatternInline(vert, image, x, y, w, h); -} - -void ModernOpenGLGraphics::calcTileVertexes(ImageVertexes *restrict const vert, - const Image *restrict const image, - int dstX, int dstY) const restrict2 -{ - calcTileVertexesInline(vert, image, dstX, dstY); -} - -void ModernOpenGLGraphics::calcTileVertexesInline(ImageVertexes * - restrict const vert, - const Image * - restrict const image, - int dstX, - int dstY) const restrict2 -{ - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int w = imageRect.w; - const int h = imageRect.h; - - if (w == 0 || h == 0) - return; - - const ClipRect &clipArea = mClipStack.top(); - const int x2 = dstX + clipArea.xOffset; - const int y2 = dstY + clipArea.yOffset; - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - - unsigned int vp = ogl.continueVp(); - - int texX2 = srcX + w; - int texY2 = srcY + h; - - GLint *const intArray = ogl.continueIntTexArray(); - - vertFill2D(intArray, - srcX, srcY, texX2, texY2, - x2, y2, w, h); - - vp += 24; - if (vp >= vLimit) - { - ogl.switchIntTexArray(); - ogl.switchVp(vp); - vp = 0; - } - - ogl.switchVp(vp); -} - -void ModernOpenGLGraphics::drawTileVertexes(const ImageVertexes * - restrict const vert) restrict2 -{ - if (vert == nullptr) - return; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - - drawVertexes(vert->ogl); -} - -void ModernOpenGLGraphics::calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - ImageVertexes *vert = nullptr; - const Image *const image = imgRect.grid[4]; - if (image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - calcImageRect(vert, x, y, w, h, imgRect); -} - -void ModernOpenGLGraphics::updateScreen() restrict2 -{ - BLOCK_START("Graphics::updateScreen") -#ifdef DEBUG_DRAW_CALLS - mLastDrawCalls = mDrawCalls; - mDrawCalls = 0; -#endif // DEBUG_DRAW_CALLS -#ifdef USE_SDL2 - SDL_GL_SwapWindow(mWindow); -#else // USE_SDL2 - SDL_GL_SwapBuffers(); -#endif // USE_SDL2 -#ifdef DEBUG_OPENGL - if (isGLNotNull(mglFrameTerminator)) - mglFrameTerminator(); -#endif // DEBUG_OPENGL - BLOCK_END("Graphics::updateScreen") -} - -void ModernOpenGLGraphics::beginDraw() restrict2 -{ - setOpenGLFlags(); - mglDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); - mglHint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB, GL_FASTEST); - pushClipArea(Rect(0, 0, mRect.w, mRect.h)); -} - -void ModernOpenGLGraphics::endDraw() restrict2 -{ - popClipArea(); -} - -void ModernOpenGLGraphics::pushClipArea(const Rect &restrict area) restrict2 -{ - Graphics::pushClipArea(area); - const ClipRect &clipArea = mClipStack.top(); - - mglScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -void ModernOpenGLGraphics::popClipArea() restrict2 -{ - if (mClipStack.empty()) - return; - Graphics::popClipArea(); - if (mClipStack.empty()) - return; - - const ClipRect &clipArea = mClipStack.top(); - mglScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -void ModernOpenGLGraphics::drawPoint(int x, int y) restrict2 -{ - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - GLint vertices[] = - { - x + clipArea.xOffset, y + clipArea.yOffset, 0, 0 - }; -// logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices)); - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_POINTS, 0, 1); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void ModernOpenGLGraphics::drawLine(int x1, int y1, - int x2, int y2) restrict2 -{ - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - GLint vertices[] = - { - x1 + clipArea.xOffset, y1 + clipArea.yOffset, 0, 0, - x2 + clipArea.xOffset, y2 + clipArea.yOffset, 0, 0 - }; -// logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices)); - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_LINES, 0, 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void ModernOpenGLGraphics::drawRectangle(const Rect &restrict rect) restrict2 -{ - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - const int x1 = rect.x + clipArea.xOffset; - const int y1 = rect.y + clipArea.yOffset; - const int x2 = x1 + rect.width; - const int y2 = y1 + rect.height; - GLint vertices[] = - { - x1, y1, 0, 0, - x1, y2, 0, 0, - x2, y2, 0, 0, - x2, y1, 0, 0 - }; - -// logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices)); - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_LINE_LOOP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void ModernOpenGLGraphics::fillRectangle(const Rect &restrict rect) restrict2 -{ - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - const int x1 = rect.x + clipArea.xOffset; - const int y1 = rect.y + clipArea.yOffset; - const int x2 = x1 + rect.width; - const int y2 = y1 + rect.height; - GLint vertices[] = - { - x1, y1, 0, 0, - x2, y1, 0, 0, - x1, y2, 0, 0, - x2, y2, 0, 0 - }; - -// logger->log("allocate: %d, %ld", mVboBinded, sizeof(vertices)); - mglBufferData(GL_ARRAY_BUFFER, sizeof(vertices), - vertices, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLE_STRIP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void ModernOpenGLGraphics::enableTexturingAndBlending() restrict2 -{ - if (!mTextureDraw) - { - mTextureDraw = true; - mglUniform1f(mDrawTypeUniform, 1.0f); - } - if (!mAlpha) - { - mglEnable(GL_BLEND); - mAlpha = true; - } -} - -void ModernOpenGLGraphics::disableTexturingAndBlending() restrict2 -{ - if (mTextureDraw) - { - mTextureDraw = false; - mglUniform1f(mDrawTypeUniform, 0.0f); - } - if (mAlpha && !mColorAlpha) - { - mglDisable(GL_BLEND); - mAlpha = false; - } - else if (!mAlpha && mColorAlpha) - { - mglEnable(GL_BLEND); - mAlpha = true; - } -} - -void ModernOpenGLGraphics::drawRectangle(const Rect &restrict rect A_UNUSED, - const bool filled A_UNUSED) restrict2 -{ -} - -void ModernOpenGLGraphics::drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) restrict2 -{ - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - disableTexturingAndBlending(); - bindArrayBufferAndAttributes(mVbo); - const ClipRect &clipArea = mClipStack.top(); - const GLint dx = clipArea.xOffset; - const GLint dy = clipArea.yOffset; - - const GLint xs1 = x1 + dx; - const GLint xs2 = x2 + dx; - const GLint ys1 = y1 + dy; - const GLint ys2 = y2 + dy; - - for (int y = y1; y < y2; y += height) - { - mIntArray[vp + 0] = xs1; - mIntArray[vp + 1] = y; - mIntArray[vp + 2] = 0; - mIntArray[vp + 3] = 0; - - mIntArray[vp + 4] = xs2; - mIntArray[vp + 5] = y; - mIntArray[vp + 6] = 0; - mIntArray[vp + 7] = 0; - - vp += 8; - if (vp >= vLimit) - { - drawLineArrays(vp); - vp = 0; - } - } - - for (int x = x1; x < x2; x += width) - { - mIntArray[vp + 0] = x; - mIntArray[vp + 1] = ys1; - mIntArray[vp + 2] = 0.0f; - mIntArray[vp + 3] = 0.0f; - - mIntArray[vp + 4] = x; - mIntArray[vp + 5] = ys2; - mIntArray[vp + 6] = 0.0f; - mIntArray[vp + 7] = 0.0f; - - vp += 8; - if (vp >= vLimit) - { - drawLineArrays(vp); - vp = 0; - } - } - - if (vp > 0) - drawLineArrays(vp); -} - -void ModernOpenGLGraphics::bindTexture(const GLenum target, - const GLuint texture) -{ - if (mTextureBinded != texture) - { - mTextureBinded = texture; - mglBindTexture(target, texture); - } -} - -void ModernOpenGLGraphics::removeArray(const uint32_t sz, - uint32_t *restrict const arr) restrict2 -{ - mglDeleteBuffers(sz, arr); - for (size_t f = 0; f < sz; f ++) - { - if (arr[f] == mVboBinded) - mVboBinded = 0; -// logger->log("delete buffers: %u", arr[f]); - } -} - -void ModernOpenGLGraphics::bindArrayBuffer(const GLuint vbo) restrict2 -{ - if (mVboBinded != vbo) - { - mVboBinded = vbo; -// logger->log("bind array: %u", vbo); - mglBindBuffer(GL_ARRAY_BUFFER, vbo); -/* - if (mglIsBuffer(vbo) != GL_TRUE) - logger->log("bind wrong buffer: %u", vbo); -*/ - mAttributesBinded = 0U; - } -} - -void ModernOpenGLGraphics::bindElementBuffer(const GLuint ebo) restrict2 -{ - if (mEboBinded != ebo) - { - mEboBinded = ebo; - logger->log("bind element: %u", ebo); - mglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); -/* - if (mglIsBuffer(ebo) != GL_TRUE) - logger->log("bind wrong buffer: %u", vbo); -*/ - } -} - -void ModernOpenGLGraphics::bindArrayBufferAndAttributes(const GLuint vbo) - restrict2 -{ - if (mVboBinded != vbo) - { - mVboBinded = vbo; -// logger->log("bind array: %u", vbo); - mglBindBuffer(GL_ARRAY_BUFFER, vbo); -/* - if (mglIsBuffer(vbo) != GL_TRUE) - logger->log("bind wrong buffer: %u", vbo); -*/ - - mAttributesBinded = mVboBinded; -// logger->log("bind vertex buffer: %u", mVboBinded); - mglBindVertexBuffer(0, mVboBinded, 0, 4 * sizeof(GLint)); -// mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0); -// mglVertexAttribBinding(mPosAttrib, 0); - } - else if (mAttributesBinded != mVboBinded) - { - mAttributesBinded = mVboBinded; -// logger->log("bind vertex buffer: %u", mVboBinded); - mglBindVertexBuffer(0, mVboBinded, 0, 4 * sizeof(GLint)); -// mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0); -// mglVertexAttribBinding(mPosAttrib, 0); - } -} - -void ModernOpenGLGraphics::bindAttributes() restrict2 -{ - if (mAttributesBinded != mVboBinded) - { - mAttributesBinded = mVboBinded; - mglBindVertexBuffer(0, mVboBinded, 0, 4 * sizeof(GLint)); -// mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0); -// mglVertexAttribBinding(mPosAttrib, 0); - } -} - -void ModernOpenGLGraphics::dumpSettings() -{ - GLint test[1000]; - logger->log("\n\n"); - logger->log("start opengl dump"); - for (int f = 0; f < 65535; f ++) - { - test[0] = 0; - test[1] = 0; - test[2] = 0; - test[3] = 0; - mglGetIntegerv(f, &test[0]); - if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0) - { - logger->log("\n%d = %d, %d, %d, %d", f, - test[0], test[1], test[2], test[3]); - } - } -} - -void ModernOpenGLGraphics::drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_drawImageRect.hpp" -} - -void ModernOpenGLGraphics::calcImageRect(ImageVertexes *restrict const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_calcImageRect.hpp" -} - -void ModernOpenGLGraphics::clearScreen() const restrict2 -{ - mglClear(GL_COLOR_BUFFER_BIT | - GL_DEPTH_BUFFER_BIT | - GL_STENCIL_BUFFER_BIT); -} - -void ModernOpenGLGraphics::createGLContext(const bool custom) restrict2 -{ - if (custom) - { - if (mGLContext != nullptr) - SDL::makeCurrentContext(mGLContext); - else - mGLContext = SDL::createGLContext(mWindow, 3, 3, 0x01); - } - else - { - Graphics::createGLContext(false); - } -} - -void ModernOpenGLGraphics::finalize(ImageCollection *restrict const col) - restrict2 -{ - if (col == nullptr) - return; - FOR_EACH (ImageCollectionIter, it, col->draws) - finalize(*it); -} - -void ModernOpenGLGraphics::finalize(ImageVertexes *restrict const vert) - restrict2 -{ - // in future need convert in each switchVp/continueVp - - if (vert == nullptr) - return; - OpenGLGraphicsVertexes &ogl = vert->ogl; - const STD_VECTOR &vp = ogl.mVp; - STD_VECTOR::const_iterator ivp; - const STD_VECTOR::const_iterator ivp_end = vp.end(); - STD_VECTOR &intTexPool = ogl.mIntTexPool; - STD_VECTOR::const_iterator ft; - const STD_VECTOR::const_iterator ft_end = intTexPool.end(); - STD_VECTOR &vbos = ogl.mVbo; - STD_VECTOR::const_iterator ivbo; - - const int sz = CAST_S32(intTexPool.size()); - vbos.resize(sz); - mglGenBuffers(sz, &vbos[0]); -/* - for (int f = 0; f < sz; f ++) - logger->log("gen buffers: %u", vbos[f]); -*/ - - for (ft = intTexPool.begin(), ivp = vp.begin(), ivbo = vbos.begin(); - ft != ft_end && ivp != ivp_end; - ++ ft, ++ ivp, ++ ivbo) - { - bindArrayBuffer(*ivbo); -/* - logger->log("allocate: %d, %ld", mVboBinded, - (*ivp) * sizeof(GLint)); -*/ - mglBufferData(GL_ARRAY_BUFFER, (*ivp) * sizeof(GLint), - *ft, GL_STATIC_DRAW); - } - - for (STD_VECTOR::iterator it = intTexPool.begin(); - it != intTexPool.end(); ++ it) - { - delete [] (*it); - } - intTexPool.clear(); -} - -void ModernOpenGLGraphics::drawTriangleArray(const int size) restrict2 -{ -// logger->log("allocate: %d, %ld", mVboBinded, size * sizeof(GLint)); - mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLint), - mIntArray, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLES, 0, size / 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void ModernOpenGLGraphics::drawTriangleArray(const GLint *restrict const array, - const int size) restrict2 -{ -// logger->log("allocate: %d, %ld", mVboBinded, size * sizeof(GLint)); - mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLint), - array, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_TRIANGLES, 0, size / 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void ModernOpenGLGraphics::drawLineArrays(const int size) -{ -// logger->log("allocate: %d, %ld", mVboBinded, size * sizeof(GLint)); - mglBufferData(GL_ARRAY_BUFFER, size * sizeof(GLint), - mIntArray, GL_STREAM_DRAW); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - mglDrawArrays(GL_LINES, 0, size / 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -#ifdef DEBUG_BIND_TEXTURE -void ModernOpenGLGraphics::debugBindTexture(const Image *restrict const image) - restrict2 -{ - const std::string texture = image->mIdPath; - if (mOldTexture != texture) - { - if ((!mOldTexture.empty() || !texture.empty()) - && mOldTextureId != image->mGLImage) - { - logger->log("bind: %s (%d) to %s (%d)", mOldTexture.c_str(), - mOldTextureId, texture.c_str(), image->mGLImage); - } - mOldTextureId = image->mGLImage; - mOldTexture = texture; - } -} -#else // DEBUG_BIND_TEXTURE -void ModernOpenGLGraphics::debugBindTexture(const Image *restrict const - image A_UNUSED) restrict2 -{ -} -#endif // DEBUG_BIND_TEXTURE - -#endif // defined(USE_OPENGL) && !defined(ANDROID) && - // !defined(__native_client__) diff --git a/src/render/modernopenglgraphics.h b/src/render/modernopenglgraphics.h deleted file mode 100644 index f20acab1b..000000000 --- a/src/render/modernopenglgraphics.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_MODERNOPENGLGRAPHICS_H -#define RENDER_MODERNOPENGLGRAPHICS_H - -#if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__native_client__) - -#include "localconsts.h" - -#include "render/graphics.h" - -#include "resources/fboinfo.h" - -#ifdef ANDROID -#include -#include -#include -#else // ANDROID -#ifndef USE_SDL2 -#define GL_GLEXT_PROTOTYPES 1 -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#include -PRAGMA48(GCC diagnostic pop) -#if defined(__APPLE__) -#include -#elif !defined(__native_client__) -#include -#endif // defined(__APPLE__) -#endif // ANDROID - -class OpenGLGraphicsVertexes; -class ShaderProgram; - -class ModernOpenGLGraphics final : public Graphics -{ - public: - ModernOpenGLGraphics(); - - A_DELETE_COPY(ModernOpenGLGraphics) - - ~ModernOpenGLGraphics(); - - void postInit() restrict2 override final; - - void setColor(const Color &restrict color) restrict2 override final; - - void screenResized() restrict2 override final; - - void finalize(ImageCollection *restrict const col) - restrict2 override final; - - void finalize(ImageVertexes *restrict const vert) - restrict2 override final; - - void testDraw() restrict2 override final; - - void removeArray(const uint32_t id, - uint32_t *restrict const arr) - restrict2 override final A_NONNULL(3); - - void createGLContext(const bool custom) restrict2 override final; - - #include "render/graphicsdef.hpp" - RENDER_GRAPHICSDEF_HPP - - #include "render/openglgraphicsdef.hpp" - RENDER_OPENGLGRAPHICSDEF_HPP - - #include "render/openglgraphicsdefadvanced.hpp" - RENDER_OPENGLGRAPHICSDEFADVANCED_HPP - - private: - void deleteGLObjects() restrict2; - - inline void drawQuad(const int srcX, - const int srcY, - const int dstX, - const int dstY, - const int width, - const int height) restrict2 A_INLINE; - - inline void drawRescaledQuad(const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) - restrict2 A_INLINE; - - inline void drawTriangleArray(const int size) restrict2 A_INLINE; - - inline void drawTriangleArray(const GLint *restrict const array, - const int size) restrict2 A_INLINE; - - inline void drawLineArrays(const int size) restrict2 A_INLINE; - - inline void bindArrayBuffer(const GLuint vbo) restrict2 A_INLINE; - - inline void bindArrayBufferAndAttributes(const GLuint vbo) - restrict2 A_INLINE; - - inline void bindAttributes() restrict2 A_INLINE; - - inline void bindElementBuffer(const GLuint ebo) restrict2 A_INLINE; - - GLint *mIntArray A_NONNULLPOINTER; - GLint *mIntArrayCached A_NONNULLPOINTER; - ShaderProgram *mProgram; - float mAlphaCached; - int mVpCached; - - float mFloatColor; - int mMaxVertices; - GLuint mProgramId; - GLuint mSimpleColorUniform; - GLint mPosAttrib; - GLint mTextureColorUniform; - GLuint mScreenUniform; - GLuint mDrawTypeUniform; - GLuint mVao; - GLuint mVbo; - GLuint mEbo; - GLuint mVboBinded; - GLuint mEboBinded; - GLuint mAttributesBinded; - bool mColorAlpha; - bool mTextureDraw; -#ifdef DEBUG_BIND_TEXTURE - std::string mOldTexture; - unsigned mOldTextureId; -#endif // DEBUG_BIND_TEXTURE - - FBOInfo mFbo; -}; -#endif // defined(USE_OPENGL) && !defined(ANDROID) && - // !defined(__native_client__) - -#endif // RENDER_MODERNOPENGLGRAPHICS_H diff --git a/src/render/nacl/naclfunctions.h b/src/render/nacl/naclfunctions.h deleted file mode 100644 index c7b24f10d..000000000 --- a/src/render/nacl/naclfunctions.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2015-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_NACL_NACLFUNCTIONS_H -#define RENDER_NACL_NACLFUNCTIONS_H - -#if defined(__native_client__) && defined(USE_OPENGL) - -#include - -extern const struct PPB_Graphics3D_1_0 *graphics3dInterface; -extern PP_Resource gles2Context; - -#define naclResizeBuffers(...) \ - graphics3dInterface->ResizeBuffers(gles2Context, __VA_ARGS__) - -#endif // defined(__native_client__) && defined(USE_OPENGL) -#endif // RENDER_NACL_NACLFUNCTIONS_H diff --git a/src/render/nacl/naclgles.cpp b/src/render/nacl/naclgles.cpp deleted file mode 100644 index 98e863594..000000000 --- a/src/render/nacl/naclgles.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2015-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if defined(__native_client__) && defined(USE_OPENGL) - -#include "render/nacl/naclgles.h" - -#include "logger.h" - -#include "render/opengl/mglfunctions.h" - -#include - -#include -#include - -#include - -#include "debug.h" - -const struct PPB_OpenGLES2* gles2Interface = nullptr; -PP_Resource gles2Context = 0; -const struct PPB_Graphics3D_1_0 *graphics3dInterface = nullptr; - -void NaclGles::initGles() -{ - gles2Interface = static_cast( - PSGetInterface(PPB_OPENGLES2_INTERFACE)); - graphics3dInterface = static_cast( - PSGetInterface(PPB_GRAPHICS_3D_INTERFACE_1_0)); - gles2Context = glGetCurrentContextPPAPI(); - - logger->log("InitGles: %p, %d", - reinterpret_cast(gles2Interface), - gles2Context); -} - -#endif // defined(__native_client__) && defined(USE_OPENGL) diff --git a/src/render/nacl/naclgles.h b/src/render/nacl/naclgles.h deleted file mode 100644 index 6d7683190..000000000 --- a/src/render/nacl/naclgles.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_NACL_NACLGLES_H -#define RENDER_NACL_NACLGLES_H - -#if defined(__native_client__) && defined(USE_OPENGL) - -namespace NaclGles -{ - void initGles(); -} // namespace NaclGles - -#endif // defined(__native_client__) && defined(USE_OPENGL) -#endif // RENDER_NACL_NACLGLES_H diff --git a/src/render/normalopenglgraphics.cpp b/src/render/normalopenglgraphics.cpp deleted file mode 100644 index 96aca6f15..000000000 --- a/src/render/normalopenglgraphics.cpp +++ /dev/null @@ -1,1782 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__native_client__) - -#include "render/normalopenglgraphics.h" - -#ifdef OPENGLERRORS -#include "graphicsmanager.h" -#endif // OPENGLERRORS - -#ifdef DEBUG_OPENGL -#include "render/opengl/mgl.h" -#endif // DEBUG_OPENGL - -#include "render/vertexes/imagecollection.h" - -#include "resources/imagerect.h" -#include "resources/openglimagehelper.h" - -#include "resources/image/image.h" - -#include "utils/sdlcheckutils.h" - -#include "debug.h" - -#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h) \ - tVar[vp + 0] = x1; \ - tVar[vp + 1] = y1; \ - tVar[vp + 2] = x2; \ - tVar[vp + 3] = y1; \ - tVar[vp + 4] = x2; \ - tVar[vp + 5] = y2; \ - tVar[vp + 6] = x1; \ - tVar[vp + 7] = y2; \ - vVar[vp + 0] = dstX; \ - vVar[vp + 1] = dstY; \ - vVar[vp + 2] = dstX + w; \ - vVar[vp + 3] = dstY; \ - vVar[vp + 4] = dstX + w; \ - vVar[vp + 5] = dstY + h; \ - vVar[vp + 6] = dstX; \ - vVar[vp + 7] = dstY + h; - - -#define vertFillNv(tVar, vVar, srcX, srcY, dstX, dstY, w, h) \ - tVar[vp + 0] = srcX; \ - tVar[vp + 1] = srcY; \ - tVar[vp + 2] = srcX + w; \ - tVar[vp + 3] = srcY; \ - tVar[vp + 4] = srcX + w; \ - tVar[vp + 5] = srcY + h; \ - tVar[vp + 6] = srcX; \ - tVar[vp + 7] = srcY + h; \ - vVar[vp + 0] = dstX; \ - vVar[vp + 1] = dstY; \ - vVar[vp + 2] = dstX + w; \ - vVar[vp + 3] = dstY; \ - vVar[vp + 4] = dstX + w; \ - vVar[vp + 5] = dstY + h; \ - vVar[vp + 6] = dstX; \ - vVar[vp + 7] = dstY + h; - -namespace -{ - const void *vertPtr = nullptr; -} // namespace - -GLuint NormalOpenGLGraphics::mTextureBinded = 0; -#ifdef DEBUG_DRAW_CALLS -unsigned int NormalOpenGLGraphics::mDrawCalls = 0; -unsigned int NormalOpenGLGraphics::mLastDrawCalls = 0; -#endif // DEBUG_DRAW_CALLS -#ifdef DEBUG_BIND_TEXTURE -unsigned int NormalOpenGLGraphics::mBinds = 0; -unsigned int NormalOpenGLGraphics::mLastBinds = 0; -#endif // DEBUG_BIND_TEXTURE - -NormalOpenGLGraphics::NormalOpenGLGraphics() : - mFloatTexArray(nullptr), - mIntTexArray(nullptr), - mIntVertArray(nullptr), - mFloatTexArrayCached(nullptr), - mIntTexArrayCached(nullptr), - mIntVertArrayCached(nullptr), - mAlphaCached(1.0F), - mVpCached(0), - mTexture(false), - mIsByteColor(false), - mByteColor(), - mImageCached(0), - mFloatColor(1.0F), - mMaxVertices(500), - mColorAlpha(false), -#ifdef DEBUG_BIND_TEXTURE - mOldTexture(), - mOldTextureId(0), -#endif // DEBUG_BIND_TEXTURE - mFbo() -{ - mOpenGL = RENDER_NORMAL_OPENGL; - mName = "normal OpenGL"; -} - -NormalOpenGLGraphics::~NormalOpenGLGraphics() -{ - deleteArraysInternal(); -} - -void NormalOpenGLGraphics::initArrays(const int vertCount) restrict2 -{ - mMaxVertices = vertCount; - if (mMaxVertices < 500) - mMaxVertices = 500; - else if (mMaxVertices > 1024) - mMaxVertices = 1024; - - // need alocate small size, after if limit reached reallocate to double size - vertexBufSize = mMaxVertices; - const size_t sz = mMaxVertices * 4 + 30; - if (mFloatTexArray == nullptr) - mFloatTexArray = new GLfloat[sz]; - if (mIntTexArray == nullptr) - mIntTexArray = new GLint[sz]; - if (mIntVertArray == nullptr) - mIntVertArray = new GLint[sz]; - if (mFloatTexArrayCached == nullptr) - mFloatTexArrayCached = new GLfloat[sz]; - if (mIntTexArrayCached == nullptr) - mIntTexArrayCached = new GLint[sz]; - if (mIntVertArrayCached == nullptr) - mIntVertArrayCached = new GLint[sz]; -} - -void NormalOpenGLGraphics::deleteArrays() restrict2 -{ - deleteArraysInternal(); -} - -void NormalOpenGLGraphics::deleteArraysInternal() restrict2 -{ - delete [] mFloatTexArray; - mFloatTexArray = nullptr; - delete [] mIntTexArray; - mIntTexArray = nullptr; - delete [] mIntVertArray; - mIntVertArray = nullptr; - delete [] mFloatTexArrayCached; - mFloatTexArrayCached = nullptr; - delete [] mIntTexArrayCached; - mIntTexArrayCached = nullptr; - delete [] mIntVertArrayCached; - mIntVertArrayCached = nullptr; -} - -bool NormalOpenGLGraphics::setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - setMainFlags(w, h, - scale, - bpp, - fs, - hwaccel, - resize, - noFrame, - allowHighDPI); - - return setOpenGLMode(); -} - -static inline void bindPointerIntFloat(const GLint *restrict const vert, - const GLfloat *restrict const tex) - A_INLINE; - -static inline void bindPointerIntFloat(const GLint *restrict const vert, - const GLfloat *restrict const tex) -{ - if (vertPtr != vert) - { - vertPtr = vert; - glVertexPointer(2, GL_INT, 0, vert); - glTexCoordPointer(2, GL_FLOAT, 0, tex); - } -} - -static inline void bindPointerInt(const GLint *restrict const vert, - const GLint *restrict const tex) A_INLINE; - -static inline void bindPointerInt(const GLint *restrict const vert, - const GLint *restrict const tex) -{ - if (vertPtr != vert) - { - vertPtr = vert; - glVertexPointer(2, GL_INT, 0, vert); - glTexCoordPointer(2, GL_INT, 0, tex); - } -} - -static inline void drawQuad(const Image *restrict const image, - const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height) - A_NONNULL(1) A_INLINE; - -static inline void drawQuad(const Image *restrict const image, - const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height) -{ - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - const float texX2 = static_cast(srcX + width) / tw; - const float texY2 = static_cast(srcY + height) / th; - - GLfloat tex[] = - { - texX1, texY1, - texX2, texY1, - texX2, texY2, - texX1, texY2 - }; - - GLint vert[] = - { - dstX, dstY, - dstX + width, dstY, - dstX + width, dstY + height, - dstX, dstY + height - }; - - bindPointerIntFloat(&vert[0], &tex[0]); -#ifdef DEBUG_DRAW_CALLS - NormalOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } - else - { - GLint tex[] = - { - srcX, srcY, - srcX + width, srcY, - srcX + width, srcY + height, - srcX, srcY + height - }; - GLint vert[] = - { - dstX, dstY, - dstX + width, dstY, - dstX + width, dstY + height, - dstX, dstY + height - }; - - bindPointerInt(&vert[0], &tex[0]); -#ifdef DEBUG_DRAW_CALLS - NormalOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } -} - -static inline void drawRescaledQuad(const Image *restrict const image, - const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) - A_NONNULL(1) A_INLINE; - -static inline void drawRescaledQuad(const Image *restrict const image, - const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) -{ - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - const float texX2 = static_cast(srcX + width) / tw; - const float texY2 = static_cast(srcY + height) / th; - - GLfloat tex[] = - { - texX1, texY1, - texX2, texY1, - texX2, texY2, - texX1, texY2 - }; - - GLint vert[] = - { - dstX, dstY, - dstX + desiredWidth, dstY, - dstX + desiredWidth, dstY + desiredHeight, - dstX, dstY + desiredHeight - }; - - bindPointerIntFloat(&vert[0], &tex[0]); -#ifdef DEBUG_DRAW_CALLS - NormalOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } - else - { - GLint tex[] = - { - srcX, srcY, - srcX + width, srcY, - srcX + width, srcY + height, - srcX, srcY + height - }; - GLint vert[] = - { - dstX, dstY, - dstX + desiredWidth, dstY, - dstX + desiredWidth, dstY + desiredHeight, - dstX, dstY + desiredHeight - }; - - bindPointerInt(&vert[0], &tex[0]); -#ifdef DEBUG_DRAW_CALLS - NormalOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } -} - -void NormalOpenGLGraphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void NormalOpenGLGraphics::drawImageInline(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - if (image == nullptr) - return; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - const SDL_Rect &imageRect = image->mBounds; - drawQuad(image, imageRect.x, imageRect.y, - dstX, dstY, imageRect.w, imageRect.h); -} - -void NormalOpenGLGraphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void NormalOpenGLGraphics::testDraw() restrict2 -{ - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - GLfloat tex[] = - { - 0.0f, 0.781250f, - 0.0f, 0.781250f, - 0.0f, 0.585938f, - 0.0f, 0.585938f - }; - - GLint vert[] = - { - 0, 0, - 800, 0, - 800, 600, - 0, 600 - }; - - bindPointerIntFloat(&vert[0], &tex[0]); -#ifdef DEBUG_DRAW_CALLS - NormalOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } - else - { - GLint tex[] = - { - 0, 0, - 800, 0, - 800, 600, - 0, 600 - }; - - GLint vert[] = - { - 0, 0, - 800, 0, - 800, 600, - 0, 600 - }; - - bindPointerInt(&vert[0], &tex[0]); -#ifdef DEBUG_DRAW_CALLS - NormalOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - } -} - -void NormalOpenGLGraphics::drawImageCached(const Image *restrict const image, - int x, int y) restrict2 -{ - if (image == nullptr) - return; - - if (image->mGLImage != mImageCached) - { - completeCache(); - mImageCached = image->mGLImage; - mAlphaCached = image->mAlpha; - } - - const SDL_Rect &imageRect = image->mBounds; - const int w = imageRect.w; - const int h = imageRect.h; - - if (w == 0 || h == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const unsigned int vLimit = mMaxVertices * 4; - - unsigned int vp = mVpCached; - - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - const float texX2 = static_cast(srcX + w) / tw; - const float texY2 = static_cast(srcY + h) / th; - - vertFill2D(mFloatTexArrayCached, mIntVertArrayCached, - texX1, texY1, texX2, texY2, - x, y, w, h); - - vp += 8; - if (vp >= vLimit) - { - completeCache(); - vp = 0; - } - else - { - mVpCached = vp; - } - } - else - { - vertFillNv(mIntTexArrayCached, mIntVertArrayCached, - srcX, srcY, x, y, w, h); - - vp += 8; - if (vp >= vLimit) - { - completeCache(); - vp = 0; - } - else - { - mVpCached = vp; - } - } -} - -void NormalOpenGLGraphics::drawPatternCached(const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPatternCached", 1) - if (image == nullptr) - return; - - if (image->mGLImage != mImageCached) - { - completeCache(); - mImageCached = image->mGLImage; - } - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - unsigned int vp = mVpCached; - const unsigned int vLimit = mMaxVertices * 4; - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - const float texY2 = static_cast(srcY + height) / th; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - - const float texX2 = static_cast(srcX + width) / tw; - - vertFill2D(mFloatTexArrayCached, mIntVertArrayCached, - texX1, texY1, texX2, texY2, - dstX, dstY, width, height); - - vp += 8; - if (vp >= vLimit) - { - completeCache(); - vp = 0; - } - } - } - } - else - { - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - - vertFillNv(mIntTexArrayCached, mIntVertArrayCached, - srcX, srcY, dstX, dstY, width, height); - - vp += 8; - if (vp >= vLimit) - { - completeCache(); - vp = 0; - } - } - } - } - mVpCached = vp; -} - -void NormalOpenGLGraphics::completeCache() restrict2 -{ - if (mImageCached == 0u) - return; - - setColorAlpha(mAlphaCached); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, mImageCached); - enableTexturingAndBlending(); - - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - drawQuadArrayfiCached(mVpCached); - else - drawQuadArrayiiCached(mVpCached); - - mImageCached = 0; - mVpCached = 0; -} - -void NormalOpenGLGraphics::drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - FUNC_BLOCK("Graphics::drawRescaledImage", 1) - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - - // Just draw the image normally when no resizing is necessary, - if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) - { - drawImageInline(image, dstX, dstY); - return; - } - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - // Draw a textured quad. - drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY, - imageRect.w, imageRect.h, desiredWidth, desiredHeight); -} - -void NormalOpenGLGraphics::drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - drawPatternInline(image, x, y, w, h); -} - -void NormalOpenGLGraphics::drawPatternInline(const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPattern", 1) - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - setColorAlpha(image->mAlpha); - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - - enableTexturingAndBlending(); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - const float texY2 = static_cast(srcY + height) / th; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - const float texX2 = static_cast(srcX + width) / tw; - - vertFill2D(mFloatTexArray, mIntVertArray, - texX1, texY1, texX2, texY2, - dstX, dstY, width, height); - - vp += 8; - if (vp >= vLimit) - { - drawQuadArrayfi(vp); - vp = 0; - } - } - } - if (vp > 0) - drawQuadArrayfi(vp); - } - else - { - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - - vertFillNv(mIntTexArray, mIntVertArray, - srcX, srcY, dstX, dstY, width, height); - - vp += 8; - if (vp >= vLimit) - { - drawQuadArrayii(vp); - vp = 0; - } - } - } - if (vp > 0) - drawQuadArrayii(vp); - } -} - -void NormalOpenGLGraphics::drawRescaledPattern(const Image * - restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) - restrict2 -{ - if (image == nullptr) - return; - - if (scaledWidth == 0 || scaledHeight == 0) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int iw = imageRect.w; - const int ih = imageRect.h; - if (iw == 0 || ih == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - - setColorAlpha(image->mAlpha); - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - - enableTexturingAndBlending(); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - const float tFractionW = iw / tw; - const float tFractionH = ih / th; - - for (int py = 0; py < h; py += scaledHeight) - { - const int height = (py + scaledHeight >= h) - ? h - py : scaledHeight; - const int dstY = y + py; - const float visibleFractionH = static_cast(height) - / scaledHeight; - const float texY2 = texY1 + tFractionH * visibleFractionH; - for (int px = 0; px < w; px += scaledWidth) - { - const int width = (px + scaledWidth >= w) - ? w - px : scaledWidth; - const int dstX = x + px; - const float visibleFractionW = static_cast(width) - / scaledWidth; - const float texX2 = texX1 + tFractionW * visibleFractionW; - - vertFill2D(mFloatTexArray, mIntVertArray, - texX1, texY1, texX2, texY2, - dstX, dstY, width, height); - - vp += 8; - if (vp >= vLimit) - { - drawQuadArrayfi(vp); - vp = 0; - } - } - } - if (vp > 0) - drawQuadArrayfi(vp); - } - else - { - const float scaleFactorW = static_cast(scaledWidth) / iw; - const float scaleFactorH = static_cast(scaledHeight) / ih; - - for (int py = 0; py < h; py += scaledHeight) - { - const int height = (py + scaledHeight >= h) - ? h - py : scaledHeight; - const int dstY = y + py; - const int scaledY = srcY + height / scaleFactorH; - for (int px = 0; px < w; px += scaledWidth) - { - const int width = (px + scaledWidth >= w) - ? w - px : scaledWidth; - const int dstX = x + px; - const int scaledX = srcX + width / scaleFactorW; - - mIntTexArray[vp + 0] = srcX; - mIntTexArray[vp + 1] = srcY; - - mIntTexArray[vp + 2] = scaledX; - mIntTexArray[vp + 3] = srcY; - - mIntTexArray[vp + 4] = scaledX; - mIntTexArray[vp + 5] = scaledY; - - mIntTexArray[vp + 6] = srcX; - mIntTexArray[vp + 7] = scaledY; - - mIntVertArray[vp + 0] = dstX; - mIntVertArray[vp + 1] = dstY; - - mIntVertArray[vp + 2] = dstX + width; - mIntVertArray[vp + 3] = dstY; - - mIntVertArray[vp + 4] = dstX + width; - mIntVertArray[vp + 5] = dstY + height; - - mIntVertArray[vp + 6] = dstX; - mIntVertArray[vp + 7] = dstY + height; - - vp += 8; - if (vp >= vLimit) - { - drawQuadArrayii(vp); - vp = 0; - } - } - } - if (vp > 0) - drawQuadArrayii(vp); - } -} - -inline void NormalOpenGLGraphics::drawVertexes(const - OpenGLGraphicsVertexes - &restrict ogl) restrict2 -{ - const STD_VECTOR &intVertPool = ogl.mIntVertPool; - STD_VECTOR::const_iterator iv; - const STD_VECTOR::const_iterator iv_end = intVertPool.end(); - const STD_VECTOR &vp = ogl.mVp; - STD_VECTOR::const_iterator ivp; - const STD_VECTOR::const_iterator ivp_end = vp.end(); - - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const STD_VECTOR &floatTexPool = ogl.mFloatTexPool; - STD_VECTOR::const_iterator ft; - const STD_VECTOR::const_iterator - ft_end = floatTexPool.end(); - - for (iv = intVertPool.begin(), ft = floatTexPool.begin(), - ivp = vp.begin(); - iv != iv_end && ft != ft_end && ivp != ivp_end; - ++ iv, ++ ft, ++ ivp) - { - drawQuadArrayfi(*iv, *ft, *ivp); - } - } - else - { - const STD_VECTOR &intTexPool = ogl.mIntTexPool; - STD_VECTOR::const_iterator it; - const STD_VECTOR::const_iterator it_end = intTexPool.end(); - - for (iv = intVertPool.begin(), it = intTexPool.begin(), - ivp = vp.begin(); - iv != iv_end && it != it_end && ivp != ivp_end; - ++ iv, ++ it, ++ ivp) - { - drawQuadArrayii(*iv, *it, *ivp); - } - } -} - -void NormalOpenGLGraphics::calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - calcPatternInline(vert, image, x, y, w, h); -} - -void NormalOpenGLGraphics::calcPatternInline(ImageVertexes * - restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - if (image == nullptr || vert == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - unsigned int vp = ogl.continueVp(); - - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - GLfloat *floatTexArray = ogl.continueFloatTexArray(); - GLint *intVertArray = ogl.continueIntVertArray(); - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - const float texY2 = static_cast(srcY + height) / th; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - const float texX2 = static_cast(srcX + width) / tw; - - vertFill2D(floatTexArray, intVertArray, - texX1, texY1, texX2, texY2, - dstX, dstY, width, height); - - vp += 8; - if (vp >= vLimit) - { - floatTexArray = ogl.switchFloatTexArray(); - intVertArray = ogl.switchIntVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - } - } - else - { - GLint *intTexArray = ogl.continueIntTexArray(); - GLint *intVertArray = ogl.continueIntVertArray(); - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - - vertFillNv(intTexArray, intVertArray, - srcX, srcY, dstX, dstY, width, height); - - vp += 8; - if (vp >= vLimit) - { - intTexArray = ogl.switchIntTexArray(); - intVertArray = ogl.switchIntVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - } - } - ogl.switchVp(vp); -} - -void NormalOpenGLGraphics::calcTileCollection(ImageCollection * - restrict const vertCol, - const Image * - restrict const image, - int x, int y) restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - ImageVertexes *const vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - calcTileVertexesInline(vert, image, x, y); - } - else - { - calcTileVertexesInline(vertCol->currentVert, image, x, y); - } -} - -void NormalOpenGLGraphics::drawTileCollection(const ImageCollection - *restrict const vertCol) - restrict2 -{ - const ImageVertexesVector &draws = vertCol->draws; - const ImageCollectionCIter it_end = draws.end(); - for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) - { - const ImageVertexes *const vert = *it; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - drawVertexes(vert->ogl); - } -} - -void NormalOpenGLGraphics::calcPattern(ImageCollection *restrict const vertCol, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - ImageVertexes *vert = nullptr; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - - calcPatternInline(vert, image, x, y, w, h); -} - -void NormalOpenGLGraphics::calcTileVertexes(ImageVertexes *restrict const vert, - const Image *restrict const image, - int dstX, int dstY) const restrict2 -{ - calcTileVertexesInline(vert, image, dstX, dstY); -} - -void NormalOpenGLGraphics::calcTileVertexesInline(ImageVertexes * - restrict const vert, - const Image * - restrict const image, - int dstX, - int dstY) const restrict2 -{ - const SDL_Rect &imageRect = image->mBounds; - const int w = imageRect.w; - const int h = imageRect.h; - - if (w == 0 || h == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - -// STD_VECTOR *vps = ogl.getVp(); - unsigned int vp = ogl.continueVp(); - - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - const float texX2 = static_cast(srcX + w) / tw; - const float texY2 = static_cast(srcY + h) / th; - - GLfloat *const floatTexArray = ogl.continueFloatTexArray(); - GLint *const intVertArray = ogl.continueIntVertArray(); - - vertFill2D(floatTexArray, intVertArray, - texX1, texY1, texX2, texY2, - dstX, dstY, w, h); - - vp += 8; - if (vp >= vLimit) - { - ogl.switchFloatTexArray(); - ogl.switchIntVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - else - { - GLint *const intTexArray = ogl.continueIntTexArray(); - GLint *const intVertArray = ogl.continueIntVertArray(); - - vertFillNv(intTexArray, intVertArray, - srcX, srcY, dstX, dstY, w, h); - - vp += 8; - if (vp >= vLimit) - { - ogl.switchIntTexArray(); - ogl.switchIntVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - ogl.switchVp(vp); -} - -void NormalOpenGLGraphics::drawTileVertexes(const ImageVertexes * - restrict const vert) restrict2 -{ - if (vert == nullptr) - return; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - drawVertexes(vert->ogl); -} - -void NormalOpenGLGraphics::calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - ImageVertexes *vert = nullptr; - Image *const image = imgRect.grid[4]; - if (image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - calcImageRect(vert, x, y, w, h, imgRect); -} - -void NormalOpenGLGraphics::updateScreen() restrict2 -{ - BLOCK_START("Graphics::updateScreen") -// glFlush(); -// glFinish(); -#ifdef DEBUG_DRAW_CALLS - mLastDrawCalls = mDrawCalls; - mDrawCalls = 0; -#endif // DEBUG_DRAW_CALLS -#ifdef DEBUG_BIND_TEXTURE - mLastBinds = mBinds; - mBinds = 0; -#endif // DEBUG_BIND_TEXTURE -#ifdef USE_SDL2 - SDL_GL_SwapWindow(mWindow); -#else // USE_SDL2 - SDL_GL_SwapBuffers(); -#endif // USE_SDL2 -#ifdef DEBUG_OPENGL - if (isGLNotNull(mglFrameTerminator)) - mglFrameTerminator(); -#endif // DEBUG_OPENGL - -// may be need clear? -// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - BLOCK_END("Graphics::updateScreen") -} - -void NormalOpenGLGraphics::beginDraw() restrict2 -{ - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - const int w = mRect.w; - const int h = mRect.h; - -#ifdef ANDROID - glOrthof(0.0, static_cast(w), - static_cast(h), - 0.0, -1.0, 1.0); -#else // ANDROID - - glOrtho(0.0, static_cast(w), - static_cast(h), - 0.0, -1.0, 1.0); -#endif // ANDROID - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - setOpenGLFlags(); - glDisable(GL_LIGHTING); - glDisable(GL_FOG); - glDisable(GL_COLOR_MATERIAL); - - glEnableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - - glShadeModel(GL_FLAT); - glDepthMask(GL_FALSE); - - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); -#ifndef ANDROID - glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); - glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST); - glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST); -#endif // ANDROID - - pushClipArea(Rect(0, 0, w, h)); -} - -void NormalOpenGLGraphics::endDraw() restrict2 -{ - popClipArea(); -} - -void NormalOpenGLGraphics::pushClipArea(const Rect &restrict area) restrict2 -{ - int transX = 0; - int transY = 0; - - if (!mClipStack.empty()) - { - const ClipRect &clipArea = mClipStack.top(); - transX = -clipArea.xOffset; - transY = -clipArea.yOffset; - } - - Graphics::pushClipArea(area); - - const ClipRect &clipArea = mClipStack.top(); - transX += clipArea.xOffset; - transY += clipArea.yOffset; - - if (transX != 0 || transY != 0) - { - glTranslatef(static_cast(transX), - static_cast(transY), 0); - } - glScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -void NormalOpenGLGraphics::popClipArea() restrict2 -{ - if (mClipStack.empty()) - return; - - const ClipRect &clipArea1 = mClipStack.top(); - int transX = -clipArea1.xOffset; - int transY = -clipArea1.yOffset; - - Graphics::popClipArea(); - - if (mClipStack.empty()) - return; - - const ClipRect &clipArea = mClipStack.top(); - transX += clipArea.xOffset; - transY += clipArea.yOffset; - if (transX != 0 || transY != 0) - { - glTranslatef(static_cast(transX), - static_cast(transY), 0); - } - glScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -void NormalOpenGLGraphics::drawPoint(int x, int y) restrict2 -{ - disableTexturingAndBlending(); - restoreColor(); - -#ifdef ANDROID - // TODO need fix -#else // ANDROID - - glBegin(GL_POINTS); - glVertex2i(x, y); - glEnd(); -#endif // ANDROID -} - -void NormalOpenGLGraphics::drawLine(int x1, int y1, - int x2, int y2) restrict2 -{ - disableTexturingAndBlending(); - restoreColor(); - - mFloatTexArray[0] = static_cast(x1) + 0.5F; - mFloatTexArray[1] = static_cast(y1) + 0.5F; - mFloatTexArray[2] = static_cast(x2) + 0.5F; - mFloatTexArray[3] = static_cast(y2) + 0.5F; - - drawLineArrayf(4); -} - -void NormalOpenGLGraphics::drawRectangle(const Rect &restrict rect) restrict2 -{ - drawRectangle(rect, false); -} - -void NormalOpenGLGraphics::fillRectangle(const Rect &restrict rect) restrict2 -{ - drawRectangle(rect, true); -} - -void NormalOpenGLGraphics::enableTexturingAndBlending() restrict2 -{ - if (!mTexture) - { - glEnable(OpenGLImageHelper::mTextureType); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - mTexture = true; - } - - if (!mAlpha) - { - glEnable(GL_BLEND); - mAlpha = true; - } -} - -void NormalOpenGLGraphics::disableTexturingAndBlending() restrict2 -{ - mTextureBinded = 0; - if (mAlpha && !mColorAlpha) - { - glDisable(GL_BLEND); - mAlpha = false; - } - else if (!mAlpha && mColorAlpha) - { - glEnable(GL_BLEND); - mAlpha = true; - } - - if (mTexture) - { - glDisable(OpenGLImageHelper::mTextureType); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - mTexture = false; - } -} - -void NormalOpenGLGraphics::drawRectangle(const Rect &restrict rect, - const bool filled) restrict2 -{ - BLOCK_START("Graphics::drawRectangle") - const float offset = filled ? 0 : 0.5F; - const float x = static_cast(rect.x); - const float y = static_cast(rect.y); - const float width = static_cast(rect.width); - const float height = static_cast(rect.height); - - disableTexturingAndBlending(); - restoreColor(); - - GLfloat vert[] = - { - x + offset, y + offset, - x + width - offset, y + offset, - x + width - offset, y + height - offset, - x + offset, y + height - offset - }; - - glVertexPointer(2, GL_FLOAT, 0, &vert); - vertPtr = nullptr; -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(filled ? GL_QUADS : GL_LINE_LOOP, 0, 4); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS - BLOCK_END("Graphics::drawRectangle") -} - -void NormalOpenGLGraphics::drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) restrict2 -{ - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - disableTexturingAndBlending(); - restoreColor(); - - const float xf1 = static_cast(x1); - const float xf2 = static_cast(x2); - const float yf1 = static_cast(y1); - const float yf2 = static_cast(y2); - - for (int y = y1; y < y2; y += height) - { - mFloatTexArray[vp + 0] = xf1; - mFloatTexArray[vp + 1] = static_cast(y); - - mFloatTexArray[vp + 2] = xf2; - mFloatTexArray[vp + 3] = static_cast(y); - - vp += 4; - if (vp >= vLimit) - { - drawLineArrayf(vp); - vp = 0; - } - } - - for (int x = x1; x < x2; x += width) - { - mFloatTexArray[vp + 0] = static_cast(x); - mFloatTexArray[vp + 1] = yf1; - - mFloatTexArray[vp + 2] = static_cast(x); - mFloatTexArray[vp + 3] = yf2; - - vp += 4; - if (vp >= vLimit) - { - drawLineArrayf(vp); - vp = 0; - } - } - - if (vp > 0) - drawLineArrayf(vp); -} - -void NormalOpenGLGraphics::bindTexture(const GLenum target, - const GLuint texture) -{ - if (mTextureBinded != texture) - { - mTextureBinded = texture; - glBindTexture(target, texture); -#ifdef DEBUG_BIND_TEXTURE - mBinds ++; -#endif // DEBUG_BIND_TEXTURE - } -} - -inline void NormalOpenGLGraphics::drawQuadArrayfi(const int size) restrict2 -{ - bindPointerIntFloat(&mIntVertArray[0], &mFloatTexArray[0]); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void NormalOpenGLGraphics::drawQuadArrayfiCached(const int size) - restrict2 -{ - bindPointerIntFloat(&mIntVertArrayCached[0], &mFloatTexArrayCached[0]); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void NormalOpenGLGraphics::drawQuadArrayfi(const GLint *restrict const - intVertArray, - const GLfloat *restrict const - floatTexArray, - const int size) restrict2 -{ - vertPtr = intVertArray; - glVertexPointer(2, GL_INT, 0, intVertArray); - glTexCoordPointer(2, GL_FLOAT, 0, floatTexArray); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void NormalOpenGLGraphics::drawQuadArrayii(const int size) restrict2 -{ - bindPointerInt(&mIntVertArray[0], &mIntTexArray[0]); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void NormalOpenGLGraphics::drawQuadArrayiiCached(const int size) - restrict2 -{ - bindPointerInt(&mIntVertArrayCached[0], &mIntTexArrayCached[0]); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void NormalOpenGLGraphics::drawQuadArrayii(const GLint *restrict const - intVertArray, - const GLint *restrict const - intTexArray, - const int size) restrict2 -{ - vertPtr = intVertArray; - glVertexPointer(2, GL_INT, 0, intVertArray); - glTexCoordPointer(2, GL_INT, 0, intTexArray); -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_QUADS, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void NormalOpenGLGraphics::drawLineArrayi(const int size) restrict2 -{ - glVertexPointer(2, GL_INT, 0, mIntVertArray); - vertPtr = nullptr; -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_LINES, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -inline void NormalOpenGLGraphics::drawLineArrayf(const int size) restrict2 -{ - glVertexPointer(2, GL_FLOAT, 0, mFloatTexArray); - vertPtr = nullptr; -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - glDrawArrays(GL_LINES, 0, size / 2); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void NormalOpenGLGraphics::dumpSettings() -{ - GLint test[1000]; - logger->log("\n\n"); - logger->log("start opengl dump"); - for (int f = 0; f < 65535; f ++) - { - test[0] = 0; - test[1] = 0; - test[2] = 0; - test[3] = 0; - glGetIntegerv(f, &test[0]); - if (test[0] != 0 || test[1] != 0 || test[2] != 0 || test[3] != 0) - { - logger->log("\n%d = %d, %d, %d, %d", f, - test[0], test[1], test[2], test[3]); - } - } -} - -void NormalOpenGLGraphics::setColorAlpha(const float alpha) restrict2 -{ - if (!mIsByteColor && mFloatColor == alpha) - return; - - glColor4f(1.0F, 1.0F, 1.0F, alpha); - mIsByteColor = false; - mFloatColor = alpha; -} - -void NormalOpenGLGraphics::restoreColor() restrict2 -{ - if (mIsByteColor && mByteColor == mColor) - return; - - glColor4ub(static_cast(mColor.r), - static_cast(mColor.g), - static_cast(mColor.b), - static_cast(mColor.a)); - mIsByteColor = true; - mByteColor = mColor; -} - -void NormalOpenGLGraphics::drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_drawImageRect.hpp" -} - -void NormalOpenGLGraphics::calcImageRect(ImageVertexes *restrict const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_calcImageRect.hpp" -} - -void NormalOpenGLGraphics::clearScreen() const restrict2 -{ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); -} - -#ifdef DEBUG_BIND_TEXTURE -void NormalOpenGLGraphics::debugBindTexture(const Image *restrict const image) - restrict2 -{ - const std::string texture = image->mIdPath; - if (mOldTexture != texture) - { - if ((!mOldTexture.empty() || !texture.empty()) - && mOldTextureId != image->mGLImage) - { - logger->log("bind: %s (%d) to %s (%d)", mOldTexture.c_str(), - mOldTextureId, texture.c_str(), image->mGLImage); - } - mOldTextureId = image->mGLImage; - mOldTexture = texture; - } -} -#else // DEBUG_BIND_TEXTURE - -void NormalOpenGLGraphics::debugBindTexture(const Image *restrict const - image A_UNUSED) restrict2 -{ -} -#endif // DEBUG_BIND_TEXTURE - -#endif // defined(USE_OPENGL) && !defined(ANDROID) && - // !defined(__native_client__) diff --git a/src/render/normalopenglgraphics.h b/src/render/normalopenglgraphics.h deleted file mode 100644 index ee7ecd9ce..000000000 --- a/src/render/normalopenglgraphics.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_NORMALOPENGLGRAPHICS_H -#define RENDER_NORMALOPENGLGRAPHICS_H - -#if defined USE_OPENGL && !defined ANDROID && !defined(__native_client__) - -#include "localconsts.h" - -#include "render/graphics.h" - -#include "resources/fboinfo.h" - -#ifdef ANDROID -#include -#include -#include -#else // ANDROID -#ifndef USE_SDL2 -#define GL_GLEXT_PROTOTYPES 1 -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#include -PRAGMA48(GCC diagnostic pop) -#if defined(__APPLE__) -#include -#elif !defined(__native_client__) -#include -#endif // defined(__APPLE__) -#endif // ANDROID - -class OpenGLGraphicsVertexes; - -class NormalOpenGLGraphics final : public Graphics -{ - public: - NormalOpenGLGraphics(); - - A_DELETE_COPY(NormalOpenGLGraphics) - - ~NormalOpenGLGraphics(); - - inline void drawQuadArrayfi(const int size) restrict2 A_INLINE; - - inline void drawQuadArrayfiCached(const int size) restrict2 A_INLINE; - - inline void drawQuadArrayfi(const GLint *restrict const intVertArray, - const GLfloat *restrict const - floatTexArray, - const int size) restrict2 A_INLINE; - - inline void drawQuadArrayii(const int size) restrict2 A_INLINE; - - inline void drawQuadArrayiiCached(const int size) restrict2 A_INLINE; - - inline void drawQuadArrayii(const GLint *restrict const intVertArray, - const GLint *restrict const intTexArray, - const int size) restrict2 A_INLINE; - - inline void drawLineArrayi(const int size) restrict2 A_INLINE; - - inline void drawLineArrayf(const int size) restrict2 A_INLINE; - - void testDraw() restrict2 override final; - - #include "render/graphicsdef.hpp" - RENDER_GRAPHICSDEF_HPP - - #include "render/openglgraphicsdef.hpp" - RENDER_OPENGLGRAPHICSDEF_HPP - - #include "render/openglgraphicsdef1.hpp" - RENDER_OPENGLGRAPHICSDEF1_HPP - - #include "render/openglgraphicsdefadvanced.hpp" - RENDER_OPENGLGRAPHICSDEFADVANCED_HPP - -#ifdef DEBUG_BIND_TEXTURE - unsigned int getBinds() const restrict2 noexcept2 - { return mLastBinds; } -#endif // DEBUG_BIND_TEXTURE - - private: - GLfloat *mFloatTexArray A_NONNULLPOINTER; - GLint *mIntTexArray A_NONNULLPOINTER; - GLint *mIntVertArray A_NONNULLPOINTER; - GLfloat *mFloatTexArrayCached A_NONNULLPOINTER; - GLint *mIntTexArrayCached A_NONNULLPOINTER; - GLint *mIntVertArrayCached A_NONNULLPOINTER; - float mAlphaCached; - int mVpCached; - bool mTexture; - - bool mIsByteColor; - Color mByteColor; - GLuint mImageCached; - float mFloatColor; - int mMaxVertices; - bool mColorAlpha; -#ifdef DEBUG_BIND_TEXTURE - std::string mOldTexture; - unsigned int mOldTextureId; - static unsigned int mBinds; - static unsigned int mLastBinds; -#endif // DEBUG_BIND_TEXTURE - - FBOInfo mFbo; -}; -#endif // defined USE_OPENGL && !defined ANDROID && - // !defined(__native_client__) - -#endif // RENDER_NORMALOPENGLGRAPHICS_H diff --git a/src/render/nullopenglgraphics.cpp b/src/render/nullopenglgraphics.cpp deleted file mode 100644 index 265ac92f1..000000000 --- a/src/render/nullopenglgraphics.cpp +++ /dev/null @@ -1,1251 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if defined USE_OPENGL - -#include "render/nullopenglgraphics.h" - -#ifdef DEBUG_BIND_TEXTURE -#include "logger.h" -#endif // DEBUG_BIND_TEXTURE - -#include "render/vertexes/imagecollection.h" - -#include "resources/imagerect.h" -#include "resources/openglimagehelper.h" - -#include "resources/image/image.h" - -#include "debug.h" - -GLuint NullOpenGLGraphics::mTextureBinded = 0; -#ifdef DEBUG_DRAW_CALLS -unsigned int NullOpenGLGraphics::mDrawCalls = 0; -unsigned int NullOpenGLGraphics::mLastDrawCalls = 0; -#endif // DEBUG_DRAW_CALLS - -NullOpenGLGraphics::NullOpenGLGraphics() : - mFloatTexArray(nullptr), - mIntTexArray(nullptr), - mIntVertArray(nullptr), - mTexture(false), - mIsByteColor(false), - mByteColor(), - mFloatColor(1.0F), - mMaxVertices(500), - mColorAlpha(false), -#ifdef DEBUG_BIND_TEXTURE - mOldTexture(), - mOldTextureId(0), -#endif // DEBUG_BIND_TEXTURE - mFbo() -{ - mOpenGL = RENDER_NULL; - mName = "null OpenGL"; -} - -NullOpenGLGraphics::~NullOpenGLGraphics() -{ - delete [] mFloatTexArray; - delete [] mIntTexArray; - delete [] mIntVertArray; -} - -void NullOpenGLGraphics::initArrays(const int vertCount) restrict2 -{ - mMaxVertices = vertCount; - if (mMaxVertices < 500) - mMaxVertices = 500; - else if (mMaxVertices > 1024) - mMaxVertices = 1024; - - // need alocate small size, after if limit reached reallocate to double size - vertexBufSize = mMaxVertices; - const size_t sz = mMaxVertices * 4 + 30; - if (mFloatTexArray == nullptr) - mFloatTexArray = new GLfloat[sz]; - if (mIntTexArray == nullptr) - mIntTexArray = new GLint[sz]; - if (mIntVertArray == nullptr) - mIntVertArray = new GLint[sz]; -} - -void NullOpenGLGraphics::deleteArrays() restrict2 -{ -} - -bool NullOpenGLGraphics::setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - setMainFlags(w, h, - scale, - bpp, - fs, - hwaccel, - resize, - noFrame, - allowHighDPI); - - return setOpenGLMode(); -} - -static inline void drawQuad(const Image *restrict const image A_UNUSED, - const int srcX A_UNUSED, const int srcY A_UNUSED, - const int dstX A_UNUSED, const int dstY A_UNUSED, - const int width A_UNUSED, - const int height A_UNUSED) A_NONNULL(1); - -static inline void drawQuad(const Image *restrict const image A_UNUSED, - const int srcX A_UNUSED, const int srcY A_UNUSED, - const int dstX A_UNUSED, const int dstY A_UNUSED, - const int width A_UNUSED, - const int height A_UNUSED) -{ - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { -#ifdef DEBUG_DRAW_CALLS - NullOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - } - else - { -#ifdef DEBUG_DRAW_CALLS - NullOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - } -} - -static inline void drawRescaledQuad(const Image *restrict const image A_UNUSED, - const int srcX A_UNUSED, - const int srcY A_UNUSED, - const int dstX A_UNUSED, - const int dstY A_UNUSED, - const int width A_UNUSED, - const int height A_UNUSED, - const int desiredWidth A_UNUSED, - const int desiredHeight A_UNUSED) -{ - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { -#ifdef DEBUG_DRAW_CALLS - NullOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - } - else - { -#ifdef DEBUG_DRAW_CALLS - NullOpenGLGraphics::mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - } -} - -void NullOpenGLGraphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void NullOpenGLGraphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void NullOpenGLGraphics::drawImageInline(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - if (image == nullptr) - return; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - const SDL_Rect &imageRect = image->mBounds; - drawQuad(image, imageRect.x, imageRect.y, dstX, dstY, - imageRect.w, imageRect.h); -} - -void NullOpenGLGraphics::drawImageCached(const Image *restrict const image - A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) restrict2 -{ -} - -void NullOpenGLGraphics::drawPatternCached(const Image *restrict const image - A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) restrict2 -{ -} - -void NullOpenGLGraphics::completeCache() restrict2 -{ -} - -void NullOpenGLGraphics::drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - FUNC_BLOCK("Graphics::drawRescaledImage", 1) - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - - // Just draw the image normally when no resizing is necessary, - if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) - { - drawImageInline(image, dstX, dstY); - return; - } - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - // Draw a textured quad. - drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY, - imageRect.w, imageRect.h, desiredWidth, desiredHeight); -} - -void NullOpenGLGraphics::drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - drawPatternInline(image, x, y, w, h); -} - -void NullOpenGLGraphics::drawPatternInline(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPattern", 1) - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - setColorAlpha(image->mAlpha); - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - - enableTexturingAndBlending(); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - const float texY2 = static_cast(srcY + height) / th; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - - const float texX2 = static_cast(srcX + width) / tw; - - mFloatTexArray[vp + 0] = texX1; - mFloatTexArray[vp + 1] = texY1; - - mFloatTexArray[vp + 2] = texX2; - mFloatTexArray[vp + 3] = texY1; - - mFloatTexArray[vp + 4] = texX2; - mFloatTexArray[vp + 5] = texY2; - - mFloatTexArray[vp + 6] = texX1; - mFloatTexArray[vp + 7] = texY2; - - mIntVertArray[vp + 0] = dstX; - mIntVertArray[vp + 1] = dstY; - - mIntVertArray[vp + 2] = dstX + width; - mIntVertArray[vp + 3] = dstY; - - mIntVertArray[vp + 4] = dstX + width; - mIntVertArray[vp + 5] = dstY + height; - - mIntVertArray[vp + 6] = dstX; - mIntVertArray[vp + 7] = dstY + height; - - vp += 8; - if (vp >= vLimit) - { - drawQuadArrayfi(vp); - vp = 0; - } - } - } - if (vp > 0) - drawQuadArrayfi(vp); - } - else - { - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - - mIntTexArray[vp + 0] = srcX; - mIntTexArray[vp + 1] = srcY; - - mIntTexArray[vp + 2] = srcX + width; - mIntTexArray[vp + 3] = srcY; - - mIntTexArray[vp + 4] = srcX + width; - mIntTexArray[vp + 5] = srcY + height; - - mIntTexArray[vp + 6] = srcX; - mIntTexArray[vp + 7] = srcY + height; - - mIntVertArray[vp + 0] = dstX; - mIntVertArray[vp + 1] = dstY; - - mIntVertArray[vp + 2] = dstX + width; - mIntVertArray[vp + 3] = dstY; - - mIntVertArray[vp + 4] = dstX + width; - mIntVertArray[vp + 5] = dstY + height; - - mIntVertArray[vp + 6] = dstX; - mIntVertArray[vp + 7] = dstY + height; - - vp += 8; - if (vp >= vLimit) - { - drawQuadArrayii(vp); - vp = 0; - } - } - } - if (vp > 0) - drawQuadArrayii(vp); - } -} - -void NullOpenGLGraphics::drawRescaledPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) restrict2 -{ - if (image == nullptr) - return; - - if (scaledWidth == 0 || scaledHeight == 0) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int iw = imageRect.w; - const int ih = imageRect.h; - if (iw == 0 || ih == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - - setColorAlpha(image->mAlpha); - -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - - enableTexturingAndBlending(); - - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - const float tFractionW = iw / tw; - const float tFractionH = ih / th; - - for (int py = 0; py < h; py += scaledHeight) - { - const int height = (py + scaledHeight >= h) - ? h - py : scaledHeight; - const int dstY = y + py; - const float visibleFractionH = static_cast(height) - / scaledHeight; - const float texY2 = texY1 + tFractionH * visibleFractionH; - for (int px = 0; px < w; px += scaledWidth) - { - const int width = (px + scaledWidth >= w) - ? w - px : scaledWidth; - const int dstX = x + px; - const float visibleFractionW = static_cast(width) - / scaledWidth; - const float texX2 = texX1 + tFractionW * visibleFractionW; - - mFloatTexArray[vp + 0] = texX1; - mFloatTexArray[vp + 1] = texY1; - - mFloatTexArray[vp + 2] = texX2; - mFloatTexArray[vp + 3] = texY1; - - mFloatTexArray[vp + 4] = texX2; - mFloatTexArray[vp + 5] = texY2; - - mFloatTexArray[vp + 6] = texX1; - mFloatTexArray[vp + 7] = texY2; - - mIntVertArray[vp + 0] = dstX; - mIntVertArray[vp + 1] = dstY; - - mIntVertArray[vp + 2] = dstX + width; - mIntVertArray[vp + 3] = dstY; - - mIntVertArray[vp + 4] = dstX + width; - mIntVertArray[vp + 5] = dstY + height; - - mIntVertArray[vp + 6] = dstX; - mIntVertArray[vp + 7] = dstY + height; - - vp += 8; - if (vp >= vLimit) - { - drawQuadArrayfi(vp); - vp = 0; - } - } - } - if (vp > 0) - drawQuadArrayfi(vp); - } - else - { - const float scaleFactorW = static_cast(scaledWidth) / iw; - const float scaleFactorH = static_cast(scaledHeight) / ih; - - for (int py = 0; py < h; py += scaledHeight) - { - const int height = (py + scaledHeight >= h) - ? h - py : scaledHeight; - const int dstY = y + py; - const int scaledY = srcY + height / scaleFactorH; - for (int px = 0; px < w; px += scaledWidth) - { - const int width = (px + scaledWidth >= w) - ? w - px : scaledWidth; - const int dstX = x + px; - const int scaledX = srcX + width / scaleFactorW; - - mIntTexArray[vp + 0] = srcX; - mIntTexArray[vp + 1] = srcY; - - mIntTexArray[vp + 2] = scaledX; - mIntTexArray[vp + 3] = srcY; - - mIntTexArray[vp + 4] = scaledX; - mIntTexArray[vp + 5] = scaledY; - - mIntTexArray[vp + 6] = srcX; - mIntTexArray[vp + 7] = scaledY; - - mIntVertArray[vp + 0] = dstX; - mIntVertArray[vp + 1] = dstY; - - mIntVertArray[vp + 2] = dstX + width; - mIntVertArray[vp + 3] = dstY; - - mIntVertArray[vp + 4] = dstX + width; - mIntVertArray[vp + 5] = dstY + height; - - mIntVertArray[vp + 6] = dstX; - mIntVertArray[vp + 7] = dstY + height; - - vp += 8; - if (vp >= vLimit) - { - drawQuadArrayii(vp); - vp = 0; - } - } - } - if (vp > 0) - drawQuadArrayii(vp); - } -} - -inline void NullOpenGLGraphics::drawVertexes(const - OpenGLGraphicsVertexes - &restrict ogl) restrict2 -{ - const STD_VECTOR &intVertPool = ogl.mIntVertPool; - STD_VECTOR::const_iterator iv; - const STD_VECTOR::const_iterator iv_end = intVertPool.end(); - const STD_VECTOR &vp = ogl.mVp; - STD_VECTOR::const_iterator ivp; - const STD_VECTOR::const_iterator ivp_end = vp.end(); - - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const STD_VECTOR &floatTexPool = ogl.mFloatTexPool; - STD_VECTOR::const_iterator ft; - const STD_VECTOR::const_iterator - ft_end = floatTexPool.end(); - - for (iv = intVertPool.begin(), ft = floatTexPool.begin(), - ivp = vp.begin(); - iv != iv_end && ft != ft_end && ivp != ivp_end; - ++ iv, ++ ft, ++ ivp) - { - drawQuadArrayfi(*iv, *ft, *ivp); - } - } - else - { - const STD_VECTOR &intTexPool = ogl.mIntTexPool; - STD_VECTOR::const_iterator it; - const STD_VECTOR::const_iterator it_end = intTexPool.end(); - - for (iv = intVertPool.begin(), it = intTexPool.begin(), - ivp = vp.begin(); - iv != iv_end && it != it_end && ivp != ivp_end; - ++ iv, ++ it, ++ ivp) - { - drawQuadArrayii(*iv, *it, *ivp); - } - } -} - -void NullOpenGLGraphics::calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 -{ - calcPatternInline(vert, image, x, y, w, h); -} - -void NullOpenGLGraphics::calcPatternInline(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - if (image == nullptr || vert == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int iw = imageRect.w; - const int ih = imageRect.h; - - if (iw == 0 || ih == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - unsigned int vp = ogl.continueVp(); - - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - GLfloat *floatTexArray = ogl.continueFloatTexArray(); - GLint *intVertArray = ogl.continueIntVertArray(); - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - const float texY2 = static_cast(srcY + height) / th; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - const float texX2 = static_cast(srcX + width) / tw; - - floatTexArray[vp + 0] = texX1; - floatTexArray[vp + 1] = texY1; - - floatTexArray[vp + 2] = texX2; - floatTexArray[vp + 3] = texY1; - - floatTexArray[vp + 4] = texX2; - floatTexArray[vp + 5] = texY2; - - floatTexArray[vp + 6] = texX1; - floatTexArray[vp + 7] = texY2; - - intVertArray[vp + 0] = dstX; - intVertArray[vp + 1] = dstY; - - intVertArray[vp + 2] = dstX + width; - intVertArray[vp + 3] = dstY; - - intVertArray[vp + 4] = dstX + width; - intVertArray[vp + 5] = dstY + height; - - intVertArray[vp + 6] = dstX; - intVertArray[vp + 7] = dstY + height; - - vp += 8; - if (vp >= vLimit) - { - floatTexArray = ogl.switchFloatTexArray(); - intVertArray = ogl.switchIntVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - } - } - else - { - GLint *intTexArray = ogl.continueIntTexArray(); - GLint *intVertArray = ogl.continueIntVertArray(); - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - const int width = (px + iw >= w) ? w - px : iw; - const int dstX = x + px; - - intTexArray[vp + 0] = srcX; - intTexArray[vp + 1] = srcY; - - intTexArray[vp + 2] = srcX + width; - intTexArray[vp + 3] = srcY; - - intTexArray[vp + 4] = srcX + width; - intTexArray[vp + 5] = srcY + height; - - intTexArray[vp + 6] = srcX; - intTexArray[vp + 7] = srcY + height; - - intVertArray[vp + 0] = dstX; - intVertArray[vp + 1] = dstY; - - intVertArray[vp + 2] = dstX + width; - intVertArray[vp + 3] = dstY; - - intVertArray[vp + 4] = dstX + width; - intVertArray[vp + 5] = dstY + height; - - intVertArray[vp + 6] = dstX; - intVertArray[vp + 7] = dstY + height; - - vp += 8; - if (vp >= vLimit) - { - intTexArray = ogl.switchIntTexArray(); - intVertArray = ogl.switchIntVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - } - } - ogl.switchVp(vp); -} - -void NullOpenGLGraphics::calcTileCollection(ImageCollection * - restrict const vertCol, - const Image *restrict const image, - int x, int y) restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - ImageVertexes *const vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - calcTileVertexesInline(vert, image, x, y); - } - else - { - calcTileVertexesInline(vertCol->currentVert, image, x, y); - } -} - -void NullOpenGLGraphics::drawTileCollection(const ImageCollection - *restrict const vertCol) restrict2 -{ - const ImageVertexesVector &draws = vertCol->draws; - const ImageCollectionCIter it_end = draws.end(); - for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) - { - const ImageVertexes *const vert = *it; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - drawVertexes(vert->ogl); - } -} - -void NullOpenGLGraphics::calcPattern(ImageCollection *restrict const vertCol, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - ImageVertexes *vert = nullptr; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - - calcPatternInline(vert, image, x, y, w, h); -} - -void NullOpenGLGraphics::calcTileVertexes(ImageVertexes *restrict const vert, - const Image *restrict const image, - int dstX, int dstY) const restrict2 -{ - calcTileVertexesInline(vert, image, dstX, dstY); -} - -void NullOpenGLGraphics::calcTileVertexesInline(ImageVertexes * - restrict const vert, - const Image * - restrict const image, - int dstX, - int dstY) const restrict2 -{ - const SDL_Rect &imageRect = image->mBounds; - const int w = imageRect.w; - const int h = imageRect.h; - - if (w == 0 || h == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - - const unsigned int vLimit = mMaxVertices * 4; - - OpenGLGraphicsVertexes &ogl = vert->ogl; - -// STD_VECTOR *vps = ogl.getVp(); - unsigned int vp = ogl.continueVp(); - - // Draw a set of textured rectangles - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - - const float texX2 = static_cast(srcX + w) / tw; - const float texY2 = static_cast(srcY + h) / th; - - GLfloat *const floatTexArray = ogl.continueFloatTexArray(); - GLint *const intVertArray = ogl.continueIntVertArray(); - - floatTexArray[vp + 0] = texX1; - floatTexArray[vp + 1] = texY1; - - floatTexArray[vp + 2] = texX2; - floatTexArray[vp + 3] = texY1; - - floatTexArray[vp + 4] = texX2; - floatTexArray[vp + 5] = texY2; - - floatTexArray[vp + 6] = texX1; - floatTexArray[vp + 7] = texY2; - - intVertArray[vp + 0] = dstX; - intVertArray[vp + 1] = dstY; - - intVertArray[vp + 2] = dstX + w; - intVertArray[vp + 3] = dstY; - - intVertArray[vp + 4] = dstX + w; - intVertArray[vp + 5] = dstY + h; - - intVertArray[vp + 6] = dstX; - intVertArray[vp + 7] = dstY + h; - - vp += 8; - if (vp >= vLimit) - { - ogl.switchFloatTexArray(); - ogl.switchIntVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - else - { - GLint *const intTexArray = ogl.continueIntTexArray(); - GLint *const intVertArray = ogl.continueIntVertArray(); - - intTexArray[vp + 0] = srcX; - intTexArray[vp + 1] = srcY; - - intTexArray[vp + 2] = srcX + w; - intTexArray[vp + 3] = srcY; - - intTexArray[vp + 4] = srcX + w; - intTexArray[vp + 5] = srcY + h; - - intTexArray[vp + 6] = srcX; - intTexArray[vp + 7] = srcY + h; - - intVertArray[vp + 0] = dstX; - intVertArray[vp + 1] = dstY; - - intVertArray[vp + 2] = dstX + w; - intVertArray[vp + 3] = dstY; - - intVertArray[vp + 4] = dstX + w; - intVertArray[vp + 5] = dstY + h; - - intVertArray[vp + 6] = dstX; - intVertArray[vp + 7] = dstY + h; - - vp += 8; - if (vp >= vLimit) - { - ogl.switchIntTexArray(); - ogl.switchIntVertArray(); - ogl.switchVp(vp); - vp = 0; - } - } - ogl.switchVp(vp); -} - -void NullOpenGLGraphics::drawTileVertexes(const ImageVertexes * - restrict const vert) restrict2 -{ - if (vert == nullptr) - return; - const Image *const image = vert->image; - - setColorAlpha(image->mAlpha); -#ifdef DEBUG_BIND_TEXTURE - debugBindTexture(image); -#endif // DEBUG_BIND_TEXTURE - - bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - drawVertexes(vert->ogl); -} - -void NullOpenGLGraphics::calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - ImageVertexes *vert = nullptr; - Image *const image = imgRect.grid[4]; - if (image == nullptr) - return; - if (vertCol->currentGLImage != image->mGLImage) - { - vert = new ImageVertexes; - vertCol->currentGLImage = image->mGLImage; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - calcImageRect(vert, x, y, w, h, imgRect); -} - -void NullOpenGLGraphics::updateScreen() restrict2 -{ - BLOCK_START("Graphics::updateScreen") -#ifdef DEBUG_DRAW_CALLS - mLastDrawCalls = mDrawCalls; - mDrawCalls = 0; -#endif // DEBUG_DRAW_CALLS - - BLOCK_END("Graphics::updateScreen") -} - -void NullOpenGLGraphics::beginDraw() restrict2 -{ - pushClipArea(Rect(0, 0, 640, 480)); -} - -void NullOpenGLGraphics::endDraw() restrict2 -{ - popClipArea(); -} - -void NullOpenGLGraphics::pushClipArea(const Rect &restrict area) restrict2 -{ - int transX = 0; - int transY = 0; - - if (!mClipStack.empty()) - { - const ClipRect &clipArea = mClipStack.top(); - transX = -clipArea.xOffset; - transY = -clipArea.yOffset; - } - - Graphics::pushClipArea(area); - - const ClipRect &clipArea = mClipStack.top(); - transX += clipArea.xOffset; - transY += clipArea.yOffset; -} - -void NullOpenGLGraphics::popClipArea() restrict2 -{ - Graphics::popClipArea(); - - if (mClipStack.empty()) - return; -} - -void NullOpenGLGraphics::drawPoint(int x A_UNUSED, int y A_UNUSED) restrict2 -{ - disableTexturingAndBlending(); - restoreColor(); -} - -void NullOpenGLGraphics::drawLine(int x1, int y1, - int x2, int y2) restrict2 -{ - disableTexturingAndBlending(); - restoreColor(); - - mFloatTexArray[0] = static_cast(x1) + 0.5F; - mFloatTexArray[1] = static_cast(y1) + 0.5F; - mFloatTexArray[2] = static_cast(x2) + 0.5F; - mFloatTexArray[3] = static_cast(y2) + 0.5F; - - drawLineArrayf(4); -} - -void NullOpenGLGraphics::drawRectangle(const Rect &restrict rect) restrict2 -{ - drawRectangle(rect, false); -} - -void NullOpenGLGraphics::fillRectangle(const Rect &restrict rect) restrict2 -{ - drawRectangle(rect, true); -} - -void NullOpenGLGraphics::enableTexturingAndBlending() restrict2 -{ - if (!mTexture) - mTexture = true; - - if (!mAlpha) - mAlpha = true; -} - -void NullOpenGLGraphics::disableTexturingAndBlending() restrict2 -{ - mTextureBinded = 0; - if (mAlpha && !mColorAlpha) - mAlpha = false; - else if (!mAlpha && mColorAlpha) - mAlpha = true; - - if (mTexture) - mTexture = false; -} - -void NullOpenGLGraphics::drawRectangle(const Rect &restrict rect A_UNUSED, - const bool filled A_UNUSED) restrict2 -{ - BLOCK_START("Graphics::drawRectangle") - disableTexturingAndBlending(); - restoreColor(); - -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS - - BLOCK_END("Graphics::drawRectangle") -} - -void NullOpenGLGraphics::drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) restrict2 -{ - unsigned int vp = 0; - const unsigned int vLimit = mMaxVertices * 4; - - disableTexturingAndBlending(); - restoreColor(); - - const float xf1 = static_cast(x1); - const float xf2 = static_cast(x2); - const float yf1 = static_cast(y1); - const float yf2 = static_cast(y2); - - for (int y = y1; y < y2; y += height) - { - mFloatTexArray[vp + 0] = xf1; - mFloatTexArray[vp + 1] = static_cast(y); - - mFloatTexArray[vp + 2] = xf2; - mFloatTexArray[vp + 3] = static_cast(y); - - vp += 4; - if (vp >= vLimit) - { - drawLineArrayf(vp); - vp = 0; - } - } - - for (int x = x1; x < x2; x += width) - { - mFloatTexArray[vp + 0] = static_cast(x); - mFloatTexArray[vp + 1] = yf1; - - mFloatTexArray[vp + 2] = static_cast(x); - mFloatTexArray[vp + 3] = yf2; - - vp += 4; - if (vp >= vLimit) - { - drawLineArrayf(vp); - vp = 0; - } - } - - if (vp > 0) - drawLineArrayf(vp); -} - -void NullOpenGLGraphics::bindTexture(const GLenum target A_UNUSED, - const GLuint texture) -{ - if (mTextureBinded != texture) - mTextureBinded = texture; -} - -inline void NullOpenGLGraphics::drawQuadArrayfi(const int size A_UNUSED) - restrict2 -{ -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS -} - -inline void NullOpenGLGraphics::drawQuadArrayfi(const GLint *restrict const - intVertArray A_UNUSED, - const GLfloat *restrict const - floatTexArray A_UNUSED, - const int size A_UNUSED) - restrict2 -{ -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS -} - -inline void NullOpenGLGraphics::drawQuadArrayii(const int size A_UNUSED) - restrict2 -{ -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS -} - -inline void NullOpenGLGraphics::drawQuadArrayii(const GLint *restrict const - intVertArray A_UNUSED, - const GLint *restrict const - intTexArray A_UNUSED, - const int size A_UNUSED) - restrict2 -{ -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS -} - -inline void NullOpenGLGraphics::drawLineArrayi(const int size A_UNUSED) - restrict2 -{ -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS -} - -inline void NullOpenGLGraphics::drawLineArrayf(const int size A_UNUSED) - restrict2 -{ -#ifdef DEBUG_DRAW_CALLS - mDrawCalls ++; -#endif // DEBUG_DRAW_CALLS -} - -void NullOpenGLGraphics::dumpSettings() -{ -} - -void NullOpenGLGraphics::setColorAlpha(const float alpha) restrict2 -{ - if (!mIsByteColor && mFloatColor == alpha) - return; - - mIsByteColor = false; - mFloatColor = alpha; -} - -void NullOpenGLGraphics::restoreColor() restrict2 -{ - if (mIsByteColor && mByteColor == mColor) - return; - - mIsByteColor = true; - mByteColor = mColor; -} - -void NullOpenGLGraphics::drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_drawImageRect.hpp" -} - -void NullOpenGLGraphics::calcImageRect(ImageVertexes *restrict const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_calcImageRect.hpp" -} - -void NullOpenGLGraphics::clearScreen() const restrict2 -{ -} - -#ifdef DEBUG_BIND_TEXTURE -void NullOpenGLGraphics::debugBindTexture(const Image *restrict const image) - restrict2 -{ - const std::string texture = image->mIdPath; - if (mOldTexture != texture) - { - if ((!mOldTexture.empty() || !texture.empty()) - && mOldTextureId != image->mGLImage) - { - logger->log("bind: %s (%d) to %s (%d)", mOldTexture.c_str(), - mOldTextureId, texture.c_str(), image->mGLImage); - } - mOldTextureId = image->mGLImage; - mOldTexture = texture; - } -} -#else // DEBUG_BIND_TEXTURE - -void NullOpenGLGraphics::debugBindTexture(const Image *restrict const - image A_UNUSED) restrict2 -{ -} -#endif // DEBUG_BIND_TEXTURE -#endif // USE_OPENGL diff --git a/src/render/nullopenglgraphics.h b/src/render/nullopenglgraphics.h deleted file mode 100644 index f496c0a35..000000000 --- a/src/render/nullopenglgraphics.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_NULLOPENGLGRAPHICS_H -#define RENDER_NULLOPENGLGRAPHICS_H - -#if defined USE_OPENGL - -#include "localconsts.h" - -#include "render/graphics.h" - -#include "resources/fboinfo.h" - -#ifdef ANDROID -#include -#include -#include -#else // ANDROID -#ifndef USE_SDL2 -#define GL_GLEXT_PROTOTYPES 1 -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#include -PRAGMA48(GCC diagnostic pop) -#if defined(__APPLE__) -#include -#elif !defined(__native_client__) -#include -#endif // defined(__APPLE__) -#endif // ANDROID - -class OpenGLGraphicsVertexes; - -class NullOpenGLGraphics final : public Graphics -{ - public: - NullOpenGLGraphics(); - - A_DELETE_COPY(NullOpenGLGraphics) - - ~NullOpenGLGraphics(); - - inline void drawQuadArrayfi(const int size) restrict2 A_INLINE; - - inline void drawQuadArrayfi(const GLint *restrict const intVertArray, - const GLfloat *restrict const - floatTexArray, - const int size) restrict2 A_INLINE; - - inline void drawQuadArrayii(const int size) restrict2 A_INLINE; - - inline void drawQuadArrayii(const GLint *restrict const intVertArray, - const GLint *restrict const intTexArray, - const int size) restrict2 A_INLINE; - - inline void drawLineArrayi(const int size) restrict2 A_INLINE; - - inline void drawLineArrayf(const int size) restrict2 A_INLINE; - - #include "render/graphicsdef.hpp" - RENDER_GRAPHICSDEF_HPP - - #include "render/openglgraphicsdef.hpp" - RENDER_OPENGLGRAPHICSDEF_HPP - - #include "render/openglgraphicsdef1.hpp" - RENDER_OPENGLGRAPHICSDEF1_HPP - - #include "render/openglgraphicsdefadvanced.hpp" - RENDER_OPENGLGRAPHICSDEFADVANCED_HPP - - private: - GLfloat *mFloatTexArray A_NONNULLPOINTER; - GLint *mIntTexArray A_NONNULLPOINTER; - GLint *mIntVertArray A_NONNULLPOINTER; - bool mTexture; - - bool mIsByteColor; - Color mByteColor; - float mFloatColor; - int mMaxVertices; - bool mColorAlpha; -#ifdef DEBUG_BIND_TEXTURE - std::string mOldTexture; - unsigned mOldTextureId; -#endif // DEBUG_BIND_TEXTURE - FBOInfo mFbo; -}; -#endif // defined USE_OPENGL -#endif // RENDER_NULLOPENGLGRAPHICS_H diff --git a/src/render/opengl/mgl.cpp b/src/render/opengl/mgl.cpp deleted file mode 100644 index b2fd24c83..000000000 --- a/src/render/opengl/mgl.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifdef USE_OPENGL - -#include "render/opengl/mgl.h" - -#include "debug.h" - -#define defName(name) name##_t m##name = nullptr - -// include function defines -#include "render/opengl/mgl.hpp" - -MGL_DEFINE - -#endif // USE_OPENGL diff --git a/src/render/opengl/mgl.h b/src/render/opengl/mgl.h deleted file mode 100644 index c761c2131..000000000 --- a/src/render/opengl/mgl.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGL_MGL_H -#define RENDER_OPENGL_MGL_H - -#ifdef USE_OPENGL - -#include "render/opengl/mgltypes.h" - -#define defName(name) extern name##_t m##name - -#include "render/opengl/mgl.hpp" - -MGL_DEFINE - -#undef defName -#undef MGL_DEFINE - -#endif // USE_OPENGL -#endif // RENDER_OPENGL_MGL_H diff --git a/src/render/opengl/mgl.hpp b/src/render/opengl/mgl.hpp deleted file mode 100644 index 980746edd..000000000 --- a/src/render/opengl/mgl.hpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define MGL_DEFINE - -defName(glGenRenderbuffers); -defName(glBindRenderbuffer); -defName(glRenderbufferStorage); -defName(glGenFramebuffers); -defName(glBindFramebuffer); -defName(glFramebufferTexture2D); -defName(glFramebufferRenderbuffer); -defName(glDeleteFramebuffers); -defName(glDeleteRenderbuffers); -defName(glGetStringi); -defName(glGenSamplers); -defName(glDeleteSamplers); -defName(glBindSampler); -defName(glSamplerParameteri); -defName(glDebugMessageControl); -defName(glDebugMessageCallback); -defName(glFrameTerminator); -defName(glLabelObject); -defName(glGetObjectLabel); -defName(glInsertEventMarker); -defName(glPushGroupMarker); -defName(glPopGroupMarker); -defName(glGenVertexArrays); -defName(glBindVertexArray); -defName(glDeleteVertexArrays); -defName(glDisableVertexAttribArray); -defName(glDeleteShader); -defName(glGetShaderInfoLog); -defName(glGetShaderSource); -defName(glDetachShader); -defName(glGetAttachedShaders); -defName(glGetActiveUniform); -defName(glBindFragDataLocation); -#ifndef __native_client__ -defName(glDeleteProgram); -defName(glCreateProgram); -defName(glGetProgramiv); -defName(glLinkProgram); -defName(glAttachShader); -defName(glGetShaderiv); -defName(glCompileShader); -defName(glShaderSource); -defName(glCreateShader); -defName(glGetUniformLocation); -defName(glGenBuffers); -defName(glDeleteBuffers); -defName(glBindBuffer); -defName(glBufferData); -defName(glEnableVertexAttribArray); -defName(glVertexAttribPointer); -defName(glUseProgram); -defName(glUniform1f); -defName(glUniform2f); -defName(glUniform4f); -defName(glValidateProgram); -defName(glGetProgramInfoLog); -defName(glBindAttribLocation); -defName(glActiveTexture); - -#define mglDrawArrays(...) \ - glDrawArrays(__VA_ARGS__) -#define mglDisable(...) \ - glDisable(__VA_ARGS__) -#define mglHint(...) \ - glHint(__VA_ARGS__) -#define mglScissor(...) \ - glScissor(__VA_ARGS__) -#define mglEnable(...) \ - glEnable(__VA_ARGS__) -#define mglBindTexture(...) \ - glBindTexture(__VA_ARGS__) -#define mglGetIntegerv(...) \ - glGetIntegerv(__VA_ARGS__) -#define mglClear(...) \ - glClear(__VA_ARGS__) -#define mglGetString(...) \ - glGetString(__VA_ARGS__) -#define mglTexParameteri(...) \ - glTexParameteri(__VA_ARGS__) -#define mglTexImage2D(...) \ - glTexImage2D(__VA_ARGS__) -#define mglGenTextures(...) \ - glGenTextures(__VA_ARGS__) -#define mglPixelStorei(...) \ - glPixelStorei(__VA_ARGS__) -#define mglReadPixels(...) \ - glReadPixels(__VA_ARGS__) - -#endif -defName(glGetAttribLocation); -defName(glUniform3f); -defName(glCheckFramebufferStatus); -defName(glProgramUniform1f); -defName(glProgramUniform2f); -defName(glProgramUniform3f); -defName(glProgramUniform4f); -defName(glBindVertexBuffer); -defName(glVertexAttribBinding); -defName(glVertexAttribFormat); -defName(glBindVertexBuffers); -defName(glIsBuffer); -defName(glVertexAttribIFormat); -defName(glVertexAttribIPointer); -defName(glInvalidateTexImage); -defName(glCopyImageSubData); -defName(glPushDebugGroup); -defName(glPopDebugGroup); -defName(glObjectLabel); -defName(glTexStorage2D); -defName(glGenQueries); -defName(glBeginQuery); -defName(glEndQuery); -defName(glDeleteQueries); -defName(glGetQueryObjectiv); -defName(glGetQueryObjectui64v); -defName(glTextureSubImage2D); -defName(glTextureSubImage2DEXT); -defName(glClearTexImage); -defName(glClearTexSubImage); -#ifdef WIN32 -defName(wglGetExtensionsString); -#endif diff --git a/src/render/opengl/mglcheck.h b/src/render/opengl/mglcheck.h deleted file mode 100644 index 0fa2e4ba6..000000000 --- a/src/render/opengl/mglcheck.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGL_MGLCHECK_H -#define RENDER_OPENGL_MGLCHECK_H - -#ifdef USE_OPENGL - -#define isGLNull(func) (!(func)) -#define isGLNotNull(func) ((func) != nullptr) - -#endif // USE_OPENGL -#endif // RENDER_OPENGL_MGLCHECK_H diff --git a/src/render/opengl/mgldefines.h b/src/render/opengl/mgldefines.h deleted file mode 100644 index 7f3a09334..000000000 --- a/src/render/opengl/mgldefines.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGL_MGLDEFINES_H -#define RENDER_OPENGL_MGLDEFINES_H - -#ifdef USE_OPENGL - -#ifndef GL_NUM_EXTENSIONS -#define GL_NUM_EXTENSIONS 0x821D -#define GL_DEPTH_ATTACHMENT 0x8D00 -#define GL_COLOR_ATTACHMENT0 0x8CE0 -#define GL_FRAMEBUFFER 0x8D40 -#define GL_RENDERBUFFER 0x8D41 -#endif // GL_NUM_EXTENSIONS - -#ifndef GL_COMPRESSED_RGBA_ARB -#define GL_COMPRESSED_RGBA_ARB 0x84EE -#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 -#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 -#endif // GL_COMPRESSED_RGBA_ARB -#ifndef GL_MAX_ELEMENTS_VERTICES -#define GL_MAX_ELEMENTS_VERTICES 0x80E8 -#define GL_MAX_ELEMENTS_INDICES 0x80E9 -#endif // GL_MAX_ELEMENTS_VERTICES - -#ifndef GL_DEBUG_OUTPUT -#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 -#define GL_DEBUG_OUTPUT 0x92E0 -#define GL_DEBUG_SOURCE_API 0x8246 -#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 -#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 -#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 -#define GL_DEBUG_SOURCE_APPLICATION 0x824A -#define GL_DEBUG_SOURCE_OTHER 0x824B -#define GL_DEBUG_TYPE_ERROR 0x824C -#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D -#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E -#define GL_DEBUG_TYPE_PORTABILITY 0x824F -#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 -#define GL_DEBUG_TYPE_OTHER 0x8251 -#define GL_DEBUG_TYPE_MARKER 0x8268 -#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B -#define GL_DEBUG_SEVERITY_HIGH 0x9146 -#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 -#define GL_DEBUG_SEVERITY_LOW 0x9148 -#endif // GL_DEBUG_OUTPUT - -#ifndef GL_DEBUG_TYPE_PUSH_GROUP -#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269 -#endif // GL_DEBUG_TYPE_PUSH_GROUP -#ifndef GL_DEBUG_TYPE_POP_GROUP -#define GL_DEBUG_TYPE_POP_GROUP 0x826a -#endif // GL_DEBUG_TYPE_POP_GROUP - -#ifndef GL_EXT_debug_label -#define GL_PROGRAM_PIPELINE_OBJECT_EXT 0x8A4F -#define GL_PROGRAM_OBJECT_EXT 0x8B40 -#define GL_SHADER_OBJECT_EXT 0x8B48 -#define GL_BUFFER_OBJECT_EXT 0x9151 -#define GL_QUERY_OBJECT_EXT 0x9153 -#define GL_VERTEX_ARRAY_OBJECT_EXT 0x9154 -#endif // GL_EXT_debug_label - -#ifndef GL_ARRAY_BUFFER -#define GL_ARRAY_BUFFER 0x8892 -#define GL_ELEMENT_ARRAY_BUFFER 0x8893 -#endif // GL_ARRAY_BUFFER - -#ifndef GL_STREAM_DRAW -#define GL_STREAM_DRAW 0x88E0 -#define GL_STATIC_DRAW 0x88E4 -#define GL_DYNAMIC_DRAW 0x88E8 -#endif // GL_STREAM_DRAW - -#ifndef GL_COMPILE_STATUS -#define GL_FRAGMENT_SHADER 0x8B30 -#define GL_VERTEX_SHADER 0x8B31 -#define GL_COMPILE_STATUS 0x8B81 -#define GL_LINK_STATUS 0x8B82 -#define GL_VALIDATE_STATUS 0x8B83 -#define GL_INFO_LOG_LENGTH 0x8B84 -#endif // GL_COMPILE_STATUS - -#ifndef GL_DEPTH_CLAMP -#define GL_DEPTH_CLAMP 0x864F -#define GL_RASTERIZER_DISCARD 0x8C89 -#define GL_SAMPLE_MASK 0x8E51 -#endif // GL_DEPTH_CLAMP - -#ifndef GL_POLYGON_SMOOTH -#define GL_POLYGON_SMOOTH 0x0B41 -#endif // GL_POLYGON_SMOOTH - -#ifndef GL_DEPTH_BOUNDS_TEST_EXT -#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890 -#endif // GL_DEPTH_BOUNDS_TEST_EXT - -#ifndef GL_TEXTURE_COMPRESSION_HINT_ARB -#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF -#endif // GL_TEXTURE_COMPRESSION_HINT_ARB - -#ifndef GLX_CONTEXT_PROFILE_MASK_ARB -#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 -#endif // GLX_CONTEXT_PROFILE_MASK_ARB - -#ifndef GLX_CONTEXT_MAJOR_VERSION_ARB -#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 -#define GLX_CONTEXT_FLAGS_ARB 0x2094 -#endif // GLX_CONTEXT_MAJOR_VERSION_ARB - -#ifndef GL_COMPRESSED_RGBA_BPTC_UNORM_ARB -#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C -#endif // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB - -#endif // USE_OPENGL - -#endif // RENDER_OPENGL_MGLDEFINES_H diff --git a/src/render/opengl/mglemu.cpp b/src/render/opengl/mglemu.cpp deleted file mode 100644 index 864b130ef..000000000 --- a/src/render/opengl/mglemu.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifdef USE_OPENGL - -#include "render/opengl/mglemu.h" - -#ifdef OPENGLERRORS -#include "graphicsmanager.h" -#endif // OPENGLERRORS - -#include "resources/openglimagehelper.h" - -#include "debug.h" - -void APIENTRY emuglTextureSubImage2DEXT(GLuint texture, GLenum target, - GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const void *pixels) -{ - OpenGLImageHelper::bindTexture(texture); - glTexSubImage2D(target, level, - xoffset, yoffset, - width, height, - format, type, pixels); -#ifdef OPENGLERRORS - graphicsManager.logError(); -#endif // OPENGLERRORS -} - -void APIENTRY emuglActiveTexture(GLenum texture A_UNUSED) -{ -} - -#endif // USE_OPENGL diff --git a/src/render/opengl/mglemu.h b/src/render/opengl/mglemu.h deleted file mode 100644 index cb31eaef2..000000000 --- a/src/render/opengl/mglemu.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGL_MGLEMU_H -#define RENDER_OPENGL_MGLEMU_H -#ifdef USE_OPENGL - -#include "render/opengl/mgltypes.h" - -void APIENTRY emuglTextureSubImage2DEXT(GLuint texture, - GLenum target, - GLint level, - GLint xoffset, - GLint yoffset, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - const void *pixels); - -void APIENTRY emuglActiveTexture(GLenum texture); - -#endif // USE_OPENGL -#endif // RENDER_OPENGL_MGLEMU_H diff --git a/src/render/opengl/mglfunctions.h b/src/render/opengl/mglfunctions.h deleted file mode 100644 index 2323283d2..000000000 --- a/src/render/opengl/mglfunctions.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGL_MGLFUNCTIONS_H -#define RENDER_OPENGL_MGLFUNCTIONS_H - -#ifdef USE_OPENGL - -#include "logger.h" - -LOGGER_H - -#ifdef WIN32 -#define getFunction(name) wglGetProcAddress(name) -#elif defined ANDROID -#define getFunction(name) eglGetProcAddress(name) -#elif defined __APPLE__ -#define getFunction(name) nullptr -#elif defined __native_client__ -#define getFunction(name) glGetProcAddressREGAL(name) -#else // WIN32 -#define getFunction(name) glXGetProcAddress(\ - reinterpret_cast(name)) -#endif // WIN32 - -#define assignFunction(func) \ - { \ - m##func = reinterpret_cast(getFunction(#func)); \ - if (m##func == nullptr) \ - logger->log("function not found: " #func); \ - else \ - logger->log("assigned function: " #func); \ - } - -#define assignFunction3(func, ext) \ - { \ - m##func = reinterpret_cast(getFunction(#func#ext)); \ - if (m##func == nullptr) \ - { \ - logger->log("function not found: " #func#ext); \ - m##func = reinterpret_cast(getFunction(#func)); \ - if (m##func == nullptr) \ - logger->log("function not found: " #func); \ - else \ - logger->log("assigned function: " #func); \ - } \ - else \ - { \ - logger->log("assigned function: " #func#ext); \ - } \ - } - -#define assignFunctionARB(func) assignFunction3(func, ARB) - -#define assignFunctionEXT(func) assignFunction3(func, EXT) - -#define assignFunction2(func, name) \ - { \ - m##func = reinterpret_cast(getFunction(name)); \ - if (m##func == nullptr) \ - logger->log(std::string("function not found: ") + name); \ - else \ - logger->log(std::string("assigned function: ") + name); \ - } - -#define assignFunctionEmu2(func, name) \ - { \ - m##func = reinterpret_cast(getFunction(name)); \ - if (m##func == nullptr) \ - { \ - m##func = emu##func; \ - logger->log(std::string("emulated function: ") + name); \ - } \ - else \ - { \ - logger->log(std::string("assigned function: ") + name); \ - } \ - } - -#define emulateFunction(func) m##func = emu##func; \ - logger->log("emulated function: " #func) - -#endif // USE_OPENGL -#endif // RENDER_OPENGL_MGLFUNCTIONS_H diff --git a/src/render/opengl/mgltypes.h b/src/render/opengl/mgltypes.h deleted file mode 100644 index d6ad9fee5..000000000 --- a/src/render/opengl/mgltypes.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGL_MGLTYPES_H -#define RENDER_OPENGL_MGLTYPES_H - -#ifdef USE_OPENGL - -#ifdef ANDROID -#include -#include -#define APIENTRY GL_APIENTRY -#else // ANDROID -#include "localconsts.h" -#ifndef USE_SDL2 -#define GL_GLEXT_PROTOTYPES 1 -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#include -PRAGMA48(GCC diagnostic pop) -#ifdef __native_client__ -#include -#else // __native_client__ -#if defined(__APPLE__) -#include -#else // defined(__APPLE__) -// probably this include need for some os / libs -// #include -#ifndef __glext_h_ -#error missing include -#endif // __glext_h_ -#endif // defined(__APPLE__) -#endif // __native_client__ -#endif // ANDROID - -#include "render/opengl/mgldefines.h" -RENDER_OPENGL_MGLDEFINES_H - -#ifndef USE_SDL2 -#if defined(__GXX_EXPERIMENTAL_CXX0X__) -#include -#endif // defined(__GXX_EXPERIMENTAL_CXX0X__) -#endif // USE_SDL2 - -typedef void (APIENTRY *glGenRenderbuffers_t)(GLsizei, GLuint *); -typedef void (APIENTRY *glBindRenderbuffer_t)(GLenum target, - GLuint renderbuffer); -typedef void (APIENTRY *glRenderbufferStorage_t)(GLenum target, - GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRY *glGenFramebuffers_t)(GLsizei n, GLuint *framebuffers); -typedef void (APIENTRY *glBindFramebuffer_t)(GLenum target, - GLuint framebuffer); -typedef void (APIENTRY *glFramebufferTexture2D_t)(GLenum target, - GLenum attachment, GLenum textarget, GLuint texture, GLint level); -typedef void (APIENTRY *glFramebufferRenderbuffer_t)(GLenum target, - GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); -typedef void (APIENTRY *glDeleteFramebuffers_t) (GLsizei, const GLuint *); -typedef void (APIENTRY *glDeleteRenderbuffers_t) (GLsizei, const GLuint *); -typedef const GLubyte *(APIENTRY *glGetStringi_t) (GLenum, GLuint); -typedef void (APIENTRY *glGenSamplers_t) (GLsizei count, GLuint *samplers); -typedef void (APIENTRY *glDeleteSamplers_t) - (GLsizei count, const GLuint * samplers); -typedef void (APIENTRY *glBindSampler_t) (GLuint unit, GLuint sampler); -typedef void (APIENTRY *glSamplerParameteri_t) - (GLuint sampler, GLenum pname, GLint param); -typedef void (APIENTRY *glDebugMessageControl_t) (GLenum source, GLenum type, - GLenum severity, GLsizei count, const GLuint* ids, GLboolean enabled); -typedef void (APIENTRY *glFrameTerminator_t) (void); -typedef void (APIENTRY *glLabelObject_t) (GLenum type, GLuint object, - GLsizei length, const GLchar *label); -typedef void (APIENTRY *glGetObjectLabel_t) (GLenum type, GLuint object, - GLsizei bufSize, GLsizei *length, GLchar *label); -typedef void (APIENTRY *glInsertEventMarker_t) - (GLsizei length, const char *marker); -typedef void (APIENTRY *glPushGroupMarker_t) - (GLsizei length, const char *marker); -typedef void (APIENTRY *glPopGroupMarker_t) (void); -typedef void (APIENTRY *glGenVertexArrays_t) (GLsizei n, GLuint *arrays); -typedef void (APIENTRY *glBindVertexArray_t) (GLuint array); -typedef void (APIENTRY *glDeleteVertexArrays_t) (GLsizei n, GLuint *arrays); -typedef void (APIENTRY *glDisableVertexAttribArray_t) (GLuint index); -typedef void (APIENTRY *glDeleteShader_t) (GLenum shader); -typedef void (APIENTRY *glGetShaderInfoLog_t) (GLuint shader, - GLsizei maxLength, GLsizei *length, GLchar *infoLog); -typedef void (APIENTRY *glGetShaderSource_t) (GLuint shader, - GLsizei bufSize, GLsizei *length, GLchar *source); -typedef void (APIENTRY *glDetachShader_t) (GLuint program, GLuint shader); -typedef void (APIENTRY *glGetAttachedShaders_t) (GLuint program, - GLsizei maxCount, GLsizei *count, GLuint *shaders); -typedef void (APIENTRY *glGetActiveUniform_t) (GLuint program, GLuint index, - GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); -typedef GLint (APIENTRY *glBindFragDataLocation_t) (GLuint program, - GLuint colorNumber, const char *name); -#ifndef __native_client__ -typedef void (APIENTRY *glDeleteProgram_t) (GLuint program); -typedef GLuint (APIENTRY *glCreateProgram_t) (void); -typedef void (APIENTRY *glGetProgramiv_t) (GLuint program, - GLenum pname, GLint *params); -typedef void (APIENTRY *glLinkProgram_t) (GLuint program); -typedef void (APIENTRY *glAttachShader_t) (GLuint program, GLuint shader); -typedef void (APIENTRY *glGetShaderiv_t) (GLuint shader, - GLenum pname, GLint *params); -typedef void (APIENTRY *glCompileShader_t) (GLuint shader); -typedef void (APIENTRY *glShaderSource_t) (GLuint shader, - GLsizei count, const GLchar **string, const GLint *length); -typedef GLuint (APIENTRY *glCreateShader_t) (GLenum shaderType); -typedef GLint (APIENTRY *glGetUniformLocation_t) (GLuint program, - const GLchar *name); -typedef void (APIENTRY *glGenBuffers_t) (GLsizei n, GLuint *buffers); -typedef void (APIENTRY *glDeleteBuffers_t) (GLsizei n, GLuint *buffers); -typedef void (APIENTRY *glBindBuffer_t) (GLenum target, GLuint buffer); -typedef void (APIENTRY *glBufferData_t) (GLenum target, GLsizeiptr size, - const GLvoid *data, GLenum usage); -typedef void (APIENTRY *glEnableVertexAttribArray_t) (GLuint index); -typedef void (APIENTRY *glVertexAttribPointer_t) (GLuint index, GLint size, - GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRY *glUseProgram_t) (GLuint program); -typedef void (APIENTRY *glUniform1f_t) (GLint location, GLfloat v0); -typedef void (APIENTRY *glUniform2f_t) (GLint location, - GLfloat v0, GLfloat v1); -typedef void (APIENTRY *glUniform4f_t) (GLint location, - GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRY *glValidateProgram_t) (GLuint program); -typedef void (APIENTRY *glGetProgramInfoLog_t) (GLuint program, - GLsizei maxLength, GLsizei *length, GLchar *infoLog); -typedef void (APIENTRY *glBindAttribLocation_t) (GLuint program, - GLuint index, const GLchar *name); -typedef void (APIENTRY *glActiveTexture_t) (GLenum texture); -#endif // __native_client__ - -typedef GLint (APIENTRY *glGetAttribLocation_t) (GLuint program, - const GLchar *name); -typedef void (APIENTRY *glUniform3f_t) (GLint location, - GLfloat v0, GLfloat v1, GLfloat v2); -typedef GLenum (APIENTRY *glCheckFramebufferStatus_t) (GLenum target); -typedef void (APIENTRY *glProgramUniform1f_t) (GLuint program, - GLint location, GLfloat v0); -typedef void (APIENTRY *glProgramUniform2f_t) (GLuint program, - GLint location, GLfloat v0, GLfloat v1); -typedef void (APIENTRY *glProgramUniform3f_t) (GLuint program, - GLint location, GLfloat v0, GLfloat v1, GLfloat v2); -typedef void (APIENTRY *glProgramUniform4f_t) (GLuint program, - GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); -typedef void (APIENTRY *glBindVertexBuffer_t) (GLuint bindingindex, - GLuint buffer, GLintptr offset, GLintptr stride); -typedef void (APIENTRY *glVertexAttribBinding_t) (GLuint attribindex, - GLuint bindingindex); -typedef void (APIENTRY *glVertexAttribFormat_t) (GLuint attribindex, - GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); -typedef void (APIENTRY *glBindVertexBuffers_t) (GLuint first, GLsizei count, - const GLuint *buffers, const GLuint *offsets, const GLsizei *strides); -typedef GLboolean (APIENTRY *glIsBuffer_t) (GLuint buffer); -typedef void (APIENTRY *glVertexAttribIFormat_t) (GLuint attribindex, - GLint size, GLenum type, GLuint relativeoffset); -typedef void (APIENTRY *glVertexAttribIPointer_t) (GLuint index, GLint size, - GLenum type, GLsizei stride, const GLvoid * pointer); -typedef void (APIENTRY *glInvalidateTexImage_t) (GLuint texture, GLint level); -typedef void (APIENTRY *glCopyImageSubData_t) (GLuint srcName, - GLenum srcTarget, GLint srcLevel, - GLint srcX, GLint srcY, GLint srcZ, - GLuint dstName, GLenum dstTarget, GLint dstLevel, - GLint dstX, GLint dstY, GLint dstZ, - GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); -typedef void (APIENTRY *glPushDebugGroup_t) (GLenum source, GLuint id, - GLsizei length, const GLchar * message); -typedef void (APIENTRY *glPopDebugGroup_t) (void); -typedef void (APIENTRY *glObjectLabel_t) (GLenum identifier, GLuint name, - GLsizei length, const GLchar *label); -typedef void (APIENTRY *glTexStorage2D_t) (GLenum target, GLsizei levels, - GLenum internalformat, GLsizei width, GLsizei height); -typedef void (APIENTRY *glGenQueries_t) (GLsizei n, GLuint *ids); -typedef void (APIENTRY *glBeginQuery_t) (GLenum target, GLuint id); -typedef void (APIENTRY *glEndQuery_t) (GLenum target); -typedef void (APIENTRY *glDeleteQueries_t) (GLsizei n, const GLuint *ids); -typedef void (APIENTRY *glGetQueryObjectiv_t) (GLuint id, - GLenum pname, GLint *params); -typedef void (APIENTRY *glGetQueryObjectui64v_t) (GLuint id, - GLenum pname, uint64_t *params); -typedef void (APIENTRY *glTextureSubImage2DEXT_t) (GLuint texture, - GLenum target, GLint level, GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, GLenum format, GLenum type, - const void *pixels); -typedef void (APIENTRY *glTextureSubImage2D_t) (GLuint texture, - GLint level, GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, GLenum format, GLenum type, - const void *pixels); -typedef void (APIENTRY *glClearTexImage_t) (GLuint texture, GLint level, - GLenum format, GLenum type, const void * data); -typedef void (APIENTRY *glClearTexSubImage_t) (GLuint texture, GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, - GLsizei depth, GLenum format, GLenum type, const void * data); - -// callback -typedef void (APIENTRY *GLDEBUGPROC_t) (GLenum source, GLenum type, GLuint id, - GLenum severity, GLsizei length, const GLchar *message, GLvoid *userParam); - -typedef void (APIENTRY *glDebugMessageCallback_t) (GLDEBUGPROC_t callback, - const void *userParam); - - -#ifdef WIN32 -typedef const char* (APIENTRY * wglGetExtensionsString_t) (HDC hdc); -#else // WIN32 -#define CALLBACK -#endif // WIN32 - -#endif // USE_OPENGL -#endif // RENDER_OPENGL_MGLTYPES_H diff --git a/src/render/opengl/naclglfunctions.h b/src/render/opengl/naclglfunctions.h deleted file mode 100644 index 4dc8424eb..000000000 --- a/src/render/opengl/naclglfunctions.h +++ /dev/null @@ -1,322 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGL_NACLGLFUNCTIONS_H -#define RENDER_OPENGL_NACLGLFUNCTIONS_H - -#if defined(__native_client__) && defined(USE_OPENGL) - -#include - -extern const struct PPB_OpenGLES2* gles2Interface; -extern PP_Resource gles2Context; - -#define mglDrawArrays(...) \ - gles2Interface->DrawArrays(gles2Context, __VA_ARGS__) -#define mglEnableVertexAttribArray(...) \ - gles2Interface->EnableVertexAttribArray(gles2Context, __VA_ARGS__) -#define mglVertexAttribPointer(...) \ - gles2Interface->VertexAttribPointer(gles2Context, __VA_ARGS__) -#define mglUseProgram(...) \ - gles2Interface->UseProgram(gles2Context, __VA_ARGS__) -#define mglViewport(...) \ - gles2Interface->Viewport(gles2Context, __VA_ARGS__) -#define mglGenBuffers(...) \ - gles2Interface->GenBuffers(gles2Context, __VA_ARGS__) -#define mglBindBuffer(...) \ - gles2Interface->BindBuffer(gles2Context, __VA_ARGS__) -#define mglBufferData(...) \ - gles2Interface->BufferData(gles2Context, __VA_ARGS__) -#define mglDeleteBuffers(...) \ - gles2Interface->DeleteBuffers(gles2Context, __VA_ARGS__) -#define mglGetUniformLocation(...) \ - gles2Interface->GetUniformLocation(gles2Context, __VA_ARGS__) -#define mglCreateShader(...) \ - gles2Interface->CreateShader(gles2Context, __VA_ARGS__) -#define mglShaderSource(...) \ - gles2Interface->ShaderSource(gles2Context, __VA_ARGS__) -#define mglCompileShader(...) \ - gles2Interface->CompileShader(gles2Context, __VA_ARGS__) -#define mglGetShaderiv(...) \ - gles2Interface->GetShaderiv(gles2Context, __VA_ARGS__) -#define mglAttachShader(...) \ - gles2Interface->AttachShader(gles2Context, __VA_ARGS__) -#define mglBindAttribLocation(...) \ - gles2Interface->BindAttribLocation(gles2Context, __VA_ARGS__) -#define mglLinkProgram(...) \ - gles2Interface->LinkProgram(gles2Context, __VA_ARGS__) -#define mglGetProgramiv(...) \ - gles2Interface->GetProgramiv(gles2Context, __VA_ARGS__) -#define mglClearColor(...) \ - gles2Interface->ClearColor(gles2Context, __VA_ARGS__) -#define mglUniform1f(...) \ - gles2Interface->Uniform1f(gles2Context, __VA_ARGS__) -#define mglUniform2f(...) \ - gles2Interface->Uniform2f(gles2Context, __VA_ARGS__) -#define mglUniform3f(...) \ - gles2Interface->Uniform3f(gles2Context, __VA_ARGS__) -#define mglUniform4f(...) \ - gles2Interface->Uniform4f(gles2Context, __VA_ARGS__) -#define mglUniform1i(...) \ - gles2Interface->Uniform1i(gles2Context, __VA_ARGS__) -#define mglUniform2i(...) \ - gles2Interface->Uniform2i(gles2Context, __VA_ARGS__) -#define mglUniform3i(...) \ - gles2Interface->Uniform3i(gles2Context, __VA_ARGS__) -#define mglUniform4i(...) \ - gles2Interface->Uniform4i(gles2Context, __VA_ARGS__) -#define mglUniform1fv(...) \ - gles2Interface->Uniform1fv(gles2Context, __VA_ARGS__) -#define mglUniform2fv(...) \ - gles2Interface->Uniform2fv(gles2Context, __VA_ARGS__) -#define mglUniform3fv(...) \ - gles2Interface->Uniform3fv(gles2Context, __VA_ARGS__) -#define mglUniform4fv(...) \ - gles2Interface->Uniform4fv(gles2Context, __VA_ARGS__) -#define mglUniform1iv(...) \ - gles2Interface->Uniform1iv(gles2Context, __VA_ARGS__) -#define mglUniform2iv(...) \ - gles2Interface->Uniform2iv(gles2Context, __VA_ARGS__) -#define mglUniform3iv(...) \ - gles2Interface->Uniform3iv(gles2Context, __VA_ARGS__) -#define mglUniform4iv(...) \ - gles2Interface->Uniform4iv(gles2Context, __VA_ARGS__) -#define mglActiveTexture(...) \ - gles2Interface->ActiveTexture(gles2Context, __VA_ARGS__) -#define mglBindTexture(...) \ - gles2Interface->BindTexture(gles2Context, __VA_ARGS__) -#define mglEnable(...) \ - gles2Interface->Enable(gles2Context, __VA_ARGS__) -#define mglClear(...) \ - gles2Interface->Clear(gles2Context, __VA_ARGS__) -#define mglValidateProgram(...) \ - gles2Interface->ValidateProgram(gles2Context, __VA_ARGS__) -#define mglDeleteProgram(...) \ - gles2Interface->DeleteProgram(gles2Context, __VA_ARGS__) -#define mglCreateProgram() \ - gles2Interface->CreateProgram(gles2Context) -#define mglGetProgramInfoLog(...) \ - gles2Interface->GetProgramInfoLog(gles2Context, __VA_ARGS__) -#define mglDisable(...) \ - gles2Interface->Disable(gles2Context, __VA_ARGS__) -#define mglHint(...) \ - gles2Interface->Hint(gles2Context, __VA_ARGS__) -#define mglScissor(...) \ - gles2Interface->Scissor(gles2Context, __VA_ARGS__) -#define mglEnable(...) \ - gles2Interface->Enable(gles2Context, __VA_ARGS__) -#define mglGetIntegerv(...) \ - gles2Interface->GetIntegerv(gles2Context, __VA_ARGS__) -#define mglGetString(...) \ - gles2Interface->GetString(gles2Context, __VA_ARGS__) -#define mglBindFramebuffer(...) \ - gles2Interface->BindFramebuffer(gles2Context, __VA_ARGS__) -#define mglBindRenderbuffer(...) \ - gles2Interface->BindRenderbuffer(gles2Context, __VA_ARGS__) -#define mglBlendColor(...) \ - gles2Interface->BlendColor(gles2Context, __VA_ARGS__) -#define mglBlendEquation(...) \ - gles2Interface->BlendEquation(gles2Context, __VA_ARGS__) -#define mglBlendEquationSeparate(...) \ - gles2Interface->BlendEquationSeparate(gles2Context, __VA_ARGS__) -#define mglBlendFunc(...) \ - gles2Interface->BlendFunc(gles2Context, __VA_ARGS__) -#define mglBlendFuncSeparate(...) \ - gles2Interface->BlendFuncSeparate(gles2Context, __VA_ARGS__) -#define mglBufferSubData(...) \ - gles2Interface->BufferSubData(gles2Context, __VA_ARGS__) -#define mglCheckFramebufferStatus(...) \ - gles2Interface->CheckFramebufferStatus(gles2Context, __VA_ARGS__) -#define mglClearDepthf(...) \ - gles2Interface->ClearDepthf(gles2Context, __VA_ARGS__) -#define mglClearStencil(...) \ - gles2Interface->ClearStencil(gles2Context, __VA_ARGS__) -#define mglColorMask(...) \ - gles2Interface->ColorMask(gles2Context, __VA_ARGS__) -#define mglCompressedTexImage2D(...) \ - gles2Interface->CompressedTexImage2D(gles2Context, __VA_ARGS__) -#define mglCompressedTexSubImage2D(...) \ - gles2Interface->CompressedTexSubImage2D(gles2Context, __VA_ARGS__) -#define mglCopyTexImage2D(...) \ - gles2Interface->CopyTexImage2D(gles2Context, __VA_ARGS__) -#define mglCopyTexSubImage2D(...) \ - gles2Interface->CopyTexSubImage2D(gles2Context, __VA_ARGS__) -#define mglCullFace(...) \ - gles2Interface->CullFace(gles2Context, __VA_ARGS__) -#define mglDeleteFramebuffers(...) \ - gles2Interface->DeleteFramebuffers(gles2Context, __VA_ARGS__) -#define mglDeleteRenderbuffers(...) \ - gles2Interface->DeleteRenderbuffers(gles2Context, __VA_ARGS__) -#define mglDeleteShader(...) \ - gles2Interface->DeleteShader(gles2Context, __VA_ARGS__) -#define mglDeleteTextures(...) \ - gles2Interface->DeleteTextures(gles2Context, __VA_ARGS__) -#define mglDepthFunc(...) \ - gles2Interface->DepthFunc(gles2Context, __VA_ARGS__) -#define mglDepthMask(...) \ - gles2Interface->DepthMask(gles2Context, __VA_ARGS__) -#define mglDepthRangef(...) \ - gles2Interface->DepthRangef(gles2Context, __VA_ARGS__) -#define mglDetachShader(...) \ - gles2Interface->DetachShader(gles2Context, __VA_ARGS__) -#define mglDisableVertexAttribArray(...) \ - gles2Interface->DisableVertexAttribArray(gles2Context, __VA_ARGS__) -#define mglDrawElements(...) \ - gles2Interface->DrawElements(gles2Context, __VA_ARGS__) -#define mglFinish(...) \ - gles2Interface->Finish(gles2Context, __VA_ARGS__) -#define mglFlush(...) \ - gles2Interface->Flush(gles2Context, __VA_ARGS__) -#define mglFramebufferRenderbuffer(...) \ - gles2Interface->FramebufferRenderbuffer(gles2Context, __VA_ARGS__) -#define mglFramebufferTexture2D(...) \ - gles2Interface->FramebufferTexture2D(gles2Context, __VA_ARGS__) -#define mglFrontFace(...) \ - gles2Interface->FrontFace(gles2Context, __VA_ARGS__) -#define mglGenerateMipmap(...) \ - gles2Interface->GenerateMipmap(gles2Context, __VA_ARGS__) -#define mglGenFramebuffers(...) \ - gles2Interface->GenFramebuffers(gles2Context, __VA_ARGS__) -#define mglGenRenderbuffers(...) \ - gles2Interface->GenRenderbuffers(gles2Context, __VA_ARGS__) -#define mglGenTextures(...) \ - gles2Interface->GenTextures(gles2Context, __VA_ARGS__) -#define mglGetActiveAttrib(...) \ - gles2Interface->GetActiveAttrib(gles2Context, __VA_ARGS__) -#define mglGetActiveUniform(...) \ - gles2Interface->GetActiveUniform(gles2Context, __VA_ARGS__) -#define mglGetAttachedShaders(...) \ - gles2Interface->GetAttachedShaders(gles2Context, __VA_ARGS__) -#define mglGetAttribLocation(...) \ - gles2Interface->GetAttribLocation(gles2Context, __VA_ARGS__) -#define mglGetBooleanv(...) \ - gles2Interface->GetBooleanv(gles2Context, __VA_ARGS__) -#define mglGetBufferParameteriv(...) \ - gles2Interface->GetBufferParameteriv(gles2Context, __VA_ARGS__) -#define mglGetError(...) \ - gles2Interface->GetError(gles2Context, __VA_ARGS__) -#define mglGetFloatv(...) \ - gles2Interface->GetFloatv(gles2Context, __VA_ARGS__) -#define mglGetFramebufferAttachmentParameteriv(...) \ - gles2Interface->GetFramebufferAttachmentParameteriv(gles2Context, \ - __VA_ARGS__) -#define mglGetIntegerv(...) \ - gles2Interface->GetIntegerv(gles2Context, __VA_ARGS__) -#define mglGetRenderbufferParameteriv(...) \ - gles2Interface->GetRenderbufferParameteriv(gles2Context, __VA_ARGS__) -#define mglGetShaderInfoLog(...) \ - gles2Interface->GetShaderInfoLog(gles2Context, __VA_ARGS__) -#define mglGetShaderPrecisionFormat(...) \ - gles2Interface->GetShaderPrecisionFormat(gles2Context, __VA_ARGS__) -#define mglGetShaderSource(...) \ - gles2Interface->GetShaderSource(gles2Context, __VA_ARGS__) -#define mglGetTexParameterfv(...) \ - gles2Interface->GetTexParameterfv(gles2Context, __VA_ARGS__) -#define mglGetTexParameteriv(...) \ - gles2Interface->GetTexParameteriv(gles2Context, __VA_ARGS__) -#define mglGetUniformfv(...) \ - gles2Interface->GetUniformfv(gles2Context, __VA_ARGS__) -#define mglGetUniformiv(...) \ - gles2Interface->GetUniformiv(gles2Context, __VA_ARGS__) -#define mglGetVertexAttribfv(...) \ - gles2Interface->GetVertexAttribfv(gles2Context, __VA_ARGS__) -#define mglGetVertexAttribiv(...) \ - gles2Interface->GetVertexAttribiv(gles2Context, __VA_ARGS__) -#define mglGetVertexAttribPointerv(...) \ - gles2Interface->GetVertexAttribPointerv(gles2Context, __VA_ARGS__) -#define mglIsBuffer(...) \ - gles2Interface->IsBuffer(gles2Context, __VA_ARGS__) -#define mglIsEnabled(...) \ - gles2Interface->IsEnabled(gles2Context, __VA_ARGS__) -#define mglIsFramebuffer(...) \ - gles2Interface->IsFramebuffer(gles2Context, __VA_ARGS__) -#define mglIsProgram(...) \ - gles2Interface->IsProgram(gles2Context, __VA_ARGS__) -#define mglIsRenderbuffer(...) \ - gles2Interface->IsRenderbuffer(gles2Context, __VA_ARGS__) -#define mglIsShader(...) \ - gles2Interface->IsShader(gles2Context, __VA_ARGS__) -#define mglIsTexture(...) \ - gles2Interface->IsTexture(gles2Context, __VA_ARGS__) -#define mglLineWidth(...) \ - gles2Interface->LineWidth(gles2Context, __VA_ARGS__) -#define mglPixelStorei(...) \ - gles2Interface->PixelStorei(gles2Context, __VA_ARGS__) -#define mglPolygonOffset(...) \ - gles2Interface->PolygonOffset(gles2Context, __VA_ARGS__) -#define mglReadPixels(...) \ - gles2Interface->ReadPixels(gles2Context, __VA_ARGS__) -#define mglReleaseShaderCompiler(...) \ - gles2Interface->ReleaseShaderCompiler(gles2Context, __VA_ARGS__) -#define mglRenderbufferStorage(...) \ - gles2Interface->RenderbufferStorage(gles2Context, __VA_ARGS__) -#define mglSampleCoverage(...) \ - gles2Interface->SampleCoverage(gles2Context, __VA_ARGS__) -#define mglShaderBinary(...) \ - gles2Interface->ShaderBinary(gles2Context, __VA_ARGS__) -#define mglStencilFunc(...) \ - gles2Interface->StencilFunc(gles2Context, __VA_ARGS__) -#define mglStencilFuncSeparate(...) \ - gles2Interface->StencilFuncSeparate(gles2Context, __VA_ARGS__) -#define mglStencilMask(...) \ - gles2Interface->StencilMask(gles2Context, __VA_ARGS__) -#define mglStencilMaskSeparate(...) \ - gles2Interface->StencilMaskSeparate(gles2Context, __VA_ARGS__) -#define mglStencilOp(...) \ - gles2Interface->StencilOp(gles2Context, __VA_ARGS__) -#define mglStencilOpSeparate(...) \ - gles2Interface->StencilOpSeparate(gles2Context, __VA_ARGS__) -#define mglTexImage2D(...) \ - gles2Interface->TexImage2D(gles2Context, __VA_ARGS__) -#define mglTexParameterf(...) \ - gles2Interface->TexParameterf(gles2Context, __VA_ARGS__) -#define mglTexParameterfv(...) \ - gles2Interface->TexParameterfv(gles2Context, __VA_ARGS__) -#define mglTexParameteri(...) \ - gles2Interface->TexParameteri(gles2Context, __VA_ARGS__) -#define mglTexParameteriv(...) \ - gles2Interface->TexParameteriv(gles2Context, __VA_ARGS__) -#define mglTexSubImage2D(...) \ - gles2Interface->TexSubImage2D(gles2Context, __VA_ARGS__) -#define mglUniformMatrix2fv(...) \ - gles2Interface->UniformMatrix2fv(gles2Context, __VA_ARGS__) -#define mglUniformMatrix3fv(...) \ - gles2Interface->UniformMatrix3fv(gles2Context, __VA_ARGS__) -#define mglUniformMatrix4fv(...) \ - gles2Interface->UniformMatrix4fv(gles2Context, __VA_ARGS__) -#define mglVertexAttrib1f(...) \ - gles2Interface->VertexAttrib1f(gles2Context, __VA_ARGS__) -#define mglVertexAttrib2f(...) \ - gles2Interface->VertexAttrib2f(gles2Context, __VA_ARGS__) -#define mglVertexAttrib3f(...) \ - gles2Interface->VertexAttrib3f(gles2Context, __VA_ARGS__) -#define mglVertexAttrib4f(...) \ - gles2Interface->VertexAttrib4f(gles2Context, __VA_ARGS__) -#define mglVertexAttrib1fv(...) \ - gles2Interface->VertexAttrib1fv(gles2Context, __VA_ARGS__) -#define mglVertexAttrib2fv(...) \ - gles2Interface->VertexAttrib2fv(gles2Context, __VA_ARGS__) -#define mglVertexAttrib3fv(...) \ - gles2Interface->VertexAttrib3fv(gles2Context, __VA_ARGS__) -#define mglVertexAttrib4fv(...) \ - gles2Interface->VertexAttrib4fv(gles2Context, __VA_ARGS__) - -#endif // defined(__native_client__) && defined(USE_OPENGL) -#endif // RENDER_OPENGL_NACLGLFUNCTIONS_H diff --git a/src/render/opengl/opengldebug.h b/src/render/opengl/opengldebug.h deleted file mode 100644 index 4afe25491..000000000 --- a/src/render/opengl/opengldebug.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGL_OPENGLDEBUG_H -#define RENDER_OPENGL_OPENGLDEBUG_H - -#include "render/opengl/mgl.h" - -RENDER_OPENGL_MGL_H - -#if defined(DEBUG_OPENGL) && defined(USE_OPENGL) -#define GLDEBUG_START(text) if (mglPushGroupMarker) \ - mglPushGroupMarker(sizeof(text), text); -#define GLDEBUG_END() if (mglPopGroupMarker) \ - mglPopGroupMarker(); -#else // defined(DEBUG_OPENGL) && defined(USE_OPENGL) -#define GLDEBUG_START(text) -#define GLDEBUG_END() -#endif // defined(DEBUG_OPENGL) && defined(USE_OPENGL) - -#endif // RENDER_OPENGL_OPENGLDEBUG_H diff --git a/src/render/openglgraphicsdef.hpp b/src/render/openglgraphicsdef.hpp deleted file mode 100644 index 7a4fd4e1e..000000000 --- a/src/render/openglgraphicsdef.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define RENDER_OPENGLGRAPHICSDEF_HPP - -public: - void drawRectangle(const Rect &restrict rect, - const bool filled) restrict2; - - void drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) restrict2 override final; - - static void dumpSettings(); - - int getMemoryUsage() restrict2 A_WARN_UNUSED; - - void updateTextureFormat() restrict2; - - bool isAllowScale() const restrict2 noexcept2 override final - { return true; } - - void clearScreen() const restrict2 override final; - - void deleteArrays() restrict2 override final; - - static void bindTexture(const GLenum target, const GLuint texture); - - static GLuint mTextureBinded; - -protected: - void enableTexturingAndBlending() restrict2; - - void disableTexturingAndBlending() restrict2; - -private: - void inline setColorAlpha(const float alpha) restrict2 A_INLINE; - - void inline restoreColor() restrict2 A_INLINE; diff --git a/src/render/openglgraphicsdef1.hpp b/src/render/openglgraphicsdef1.hpp deleted file mode 100644 index ba921494d..000000000 --- a/src/render/openglgraphicsdef1.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define RENDER_OPENGLGRAPHICSDEF1_HPP - -public: - void setColor(const Color &restrict color) override final - { - mColor = color; - mColorAlpha = (color.a != 255); - } diff --git a/src/render/openglgraphicsdefadvanced.hpp b/src/render/openglgraphicsdefadvanced.hpp deleted file mode 100644 index 4205b525f..000000000 --- a/src/render/openglgraphicsdefadvanced.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define RENDER_OPENGLGRAPHICSDEFADVANCED_HPP - -public: - inline void drawVertexes(const OpenGLGraphicsVertexes &restrict ogl) - restrict2 A_INLINE; - - void initArrays(const int vertCount) restrict2 override final; - -#ifdef DEBUG_DRAW_CALLS - unsigned int getDrawCalls() restrict2 const noexcept2 - { return mLastDrawCalls; } - - static unsigned int mDrawCalls; - - static unsigned int mLastDrawCalls; -#endif - -protected: - void debugBindTexture(const Image *restrict const image) restrict2; - - void deleteArraysInternal() restrict2; diff --git a/src/render/openglx/mglx.cpp b/src/render/openglx/mglx.cpp deleted file mode 100644 index a02c8e326..000000000 --- a/src/render/openglx/mglx.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if defined(USE_OPENGL) && defined(USE_X11) - -#include "render/openglx/mglx.h" - -#include "debug.h" - -#define defName(name) name##_t m##name = nullptr - -// include function defines -#include "render/openglx/mglx.hpp" - -MGLX_DEFINE - -#endif // defined(USE_OPENGL) && defined(USE_X11) diff --git a/src/render/openglx/mglx.h b/src/render/openglx/mglx.h deleted file mode 100644 index 3f591f26f..000000000 --- a/src/render/openglx/mglx.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGLX_MGLX_H -#define RENDER_OPENGLX_MGLX_H - -#if defined(USE_OPENGL) && defined(USE_X11) - -#include "render/openglx/mglxtypes.h" - -#define defName(name) extern name##_t m##name -#include "render/openglx/mglx.hpp" -MGLX_DEFINE -#undef defName -#undef MGLX_DEFINE - -#endif // defined(USE_OPENGL) && defined(USE_X11) -#endif // RENDER_OPENGLX_MGLX_H diff --git a/src/render/openglx/mglx.hpp b/src/render/openglx/mglx.hpp deleted file mode 100644 index 0e3e2b9ac..000000000 --- a/src/render/openglx/mglx.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define MGLX_DEFINE - -defName(glXCreateContext); -defName(glXGetCurrentContext); -defName(glXCreateContextAttribs); -defName(glXChooseFBConfig); -defName(glXDestroyContext); -defName(glXMakeCurrent); -defName(glXSwapBuffers); diff --git a/src/render/openglx/mglxinit.cpp b/src/render/openglx/mglxinit.cpp deleted file mode 100644 index 10eb93567..000000000 --- a/src/render/openglx/mglxinit.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if defined(USE_OPENGL) && defined(USE_X11) - -#include "render/openglx/mglxinit.h" - -#include "render/opengl/mglfunctions.h" - -#include "render/openglx/mglx.h" - -#include "debug.h" - -void Glx::initFunctions() -{ - assignFunction(glXCreateContext); - assignFunction(glXGetCurrentContext); - assignFunctionARB(glXCreateContextAttribs); - assignFunction(glXChooseFBConfig); - assignFunction(glXDestroyContext); - assignFunction(glXMakeCurrent); - assignFunction(glXSwapBuffers); -} - -#endif // defined(USE_OPENGL) && defined(USE_X11) diff --git a/src/render/openglx/mglxinit.h b/src/render/openglx/mglxinit.h deleted file mode 100644 index 96704821e..000000000 --- a/src/render/openglx/mglxinit.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGLX_MGLXINIT_H -#define RENDER_OPENGLX_MGLXINIT_H - -#if defined(USE_OPENGL) && defined(USE_X11) - -namespace Glx -{ - void initFunctions(); -} // namespace Glx - -#endif // defined(USE_OPENGL) && defined(USE_X11) -#endif // RENDER_OPENGLX_MGLXINIT_H diff --git a/src/render/openglx/mglxtypes.h b/src/render/openglx/mglxtypes.h deleted file mode 100644 index b9aa0a55d..000000000 --- a/src/render/openglx/mglxtypes.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_OPENGLX_MGLXTYPES_H -#define RENDER_OPENGLX_MGLXTYPES_H - -#if defined(USE_OPENGL) && defined(USE_X11) - -#include - -typedef void *(*glXCreateContext_t) (Display *dpy, XVisualInfo *vis, - void *shareList, bool direct); -typedef void *(*glXGetCurrentContext_t) (void); -typedef void *(*glXCreateContextAttribs_t) (Display *dpy, GLXFBConfig config, - void *share_context, bool direct, const int *attrib_list); -typedef GLXFBConfig *(*glXChooseFBConfig_t) (Display *dpy, int screen, - const int *attrib_list, int *nelements); -typedef void (*glXDestroyContext_t) (Display *dpy, void *ctx); -typedef bool (*glXMakeCurrent_t) (Display *dpy, - GLXDrawable drawable, void *ctx); -typedef void (*glXSwapBuffers_t) (Display *dpy, GLXDrawable drawable); - -#endif // USE_OPENGL -#endif // RENDER_OPENGLX_MGLXTYPES_H diff --git a/src/render/renderers.cpp b/src/render/renderers.cpp deleted file mode 100644 index 0f8baf6e4..000000000 --- a/src/render/renderers.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "render/renderers.h" - -#include "debug.h" - -static RenderType getDefault() noexcept2 A_CONST; - -static RenderType getDefault() noexcept2 -{ -#ifdef USE_OPENGL -#ifdef ANDROID - return RENDER_GLES_OPENGL; -#else // ANDROID - - return RENDER_NORMAL_OPENGL; -#endif // ANDROID -#else // USE_OPENGL - - return RENDER_SOFTWARE; -#endif // USE_OPENGL -} - -RenderType intToRenderType(const int mode) noexcept2 -{ - if (mode < 0 || mode >= RENDER_LAST) - return getDefault(); - - if (mode != RENDER_SOFTWARE -#if defined(USE_OPENGL) - -// with OpenGL start -#if defined(ANDROID) - -// with OpenGL + with ANDROID start -#if defined(USE_SDL2) - && mode != RENDER_GLES_OPENGL - && mode != RENDER_SDL2_DEFAULT) -#else // defined(USE_SDL2) - - && mode != RENDER_GLES_OPENGL) -#endif // defined(USE_SDL2) -// with OpenGL + with ANDROID end - -#elif defined(__native_client__) - -// with OpenGL + with nacl start -#if defined(USE_SDL2) - && mode != RENDER_SAFE_OPENGL - && mode != RENDER_GLES2_OPENGL - && mode != RENDER_SDL2_DEFAULT) -#else // defined(USE_SDL2) - - && mode != RENDER_SAFE_OPENGL - && mode != RENDER_GLES2_OPENGL) -#endif // defined(USE_SDL2) -// with OpenGL + with nacl end - -#else // defined(ANDROID) - -// with OpenGL + without ANDROID start -#if defined(USE_SDL2) - && mode != RENDER_NORMAL_OPENGL - && mode != RENDER_MODERN_OPENGL - && mode != RENDER_SAFE_OPENGL - && mode != RENDER_GLES_OPENGL - && mode != RENDER_GLES2_OPENGL - && mode != RENDER_SDL2_DEFAULT) -#else // defined(USE_SDL2) - - && mode != RENDER_NORMAL_OPENGL - && mode != RENDER_MODERN_OPENGL - && mode != RENDER_SAFE_OPENGL - && mode != RENDER_GLES_OPENGL - && mode != RENDER_GLES2_OPENGL) -#endif // defined(USE_SDL2) -// with OpenGL + without ANDROID end - -#endif // defined(ANDROID) -// with OpenGL end - -#else // defined(USE_OPENGL) - -// without OpenGL start -#if defined(USE_SDL2) - && mode != RENDER_SDL2_DEFAULT) -#elif !defined(USE_SDL2) - ) -#endif // defined(USE_SDL2) -// without OpenGL end - -#endif // defined(USE_OPENGL) - - { - return getDefault(); - } - - return static_cast(mode); -} diff --git a/src/render/renderers.h b/src/render/renderers.h deleted file mode 100644 index f2f5d3928..000000000 --- a/src/render/renderers.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_RENDERERS_H -#define RENDER_RENDERERS_H - -#include "enums/render/rendertype.h" - -#include "localconsts.h" - -RenderType intToRenderType(const int mode) noexcept2 A_CONST; - -#define isBatchDrawRenders(val) ((val) != RENDER_SAFE_OPENGL) - -#endif // RENDER_RENDERERS_H diff --git a/src/render/rendererslistsdl.h b/src/render/rendererslistsdl.h deleted file mode 100644 index 8fc833247..000000000 --- a/src/render/rendererslistsdl.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_RENDERERSLISTSDL_H -#define RENDER_RENDERERSLISTSDL_H - -#ifdef USE_SDL2 -#include "render/rendererslistsdl2.h" -RENDER_RENDERERSLISTSDL2_H - -#else // USE_SDL2 - -#include "utils/gettext.h" - -#include "render/renderers.h" - -#ifdef USE_OPENGL -#ifdef ANDROID -// defined OPENGL ANDROID - -// map for index to RenderType -const RenderType indexToRender[] = -{ - RENDER_SOFTWARE, - RENDER_GLES_OPENGL -}; - -const char *OPENGL_NAME[] = -{ - // TRANSLATORS: draw backend - N_("Software"), - // TRANSLATORS: draw backend - N_("Mobile OpenGL ES") -}; - -const int renderModesListSize = 2; - -const int renderToIndex[] = -{ - 0, // RENDER_SOFTWARE - 1, // RENDER_NORMAL_OPENGL - 1, // RENDER_SAFE_OPENGL - 1, // RENDER_GLES_OPENGL - 1, // RENDER_SDL2_DEFAULT - 1, // RENDER_MODERN_OPENGL - 1 // RENDER_GLES2_OPENGL -}; - -#elif defined(__native_client__) -// defined OPENGL nacl - -// map for index to RenderType -const RenderType indexToRender[] = -{ - RENDER_SOFTWARE, - RENDER_SAFE_OPENGL, - RENDER_GLES2_OPENGL -}; - -const char *OPENGL_NAME[] = -{ - // TRANSLATORS: draw backend - N_("Software"), - // TRANSLATORS: draw backend - N_("Safe OpenGL"), - // TRANSLATORS: draw backend - N_("Mobile OpenGL ES 2"), -}; - -const int renderModesListSize = 3; - -const int renderToIndex[] = -{ - 0, // RENDER_SOFTWARE - 2, // RENDER_NORMAL_OPENGL - 1, // RENDER_SAFE_OPENGL - 2, // RENDER_GLES_OPENGL - 0, // RENDER_SDL2_DEFAULT - 2, // RENDER_MODERN_OPENGL - 2 // RENDER_GLES2_OPENGL -}; - -#else // ANDROID or nacl -// defined OPENGL - -// map for index to RenderType -const RenderType indexToRender[] = -{ - RENDER_SOFTWARE, - RENDER_NORMAL_OPENGL, - RENDER_SAFE_OPENGL, - RENDER_GLES_OPENGL, - RENDER_MODERN_OPENGL, - RENDER_GLES2_OPENGL -}; - -const char *OPENGL_NAME[] = -{ - // TRANSLATORS: draw backend - N_("Software"), - // TRANSLATORS: draw backend - N_("Normal OpenGL"), - // TRANSLATORS: draw backend - N_("Safe OpenGL"), - // TRANSLATORS: draw backend - N_("Mobile OpenGL ES"), - // TRANSLATORS: draw backend - N_("Modern OpenGL"), - // TRANSLATORS: draw backend - N_("Mobile OpenGL ES 2"), -}; - -const int renderModesListSize = 6; - -const int renderToIndex[] = -{ - 0, // RENDER_SOFTWARE - 1, // RENDER_NORMAL_OPENGL - 2, // RENDER_SAFE_OPENGL - 3, // RENDER_GLES_OPENGL - 0, // RENDER_SDL2_DEFAULT - 4, // RENDER_MODERN_OPENGL - 5 // RENDER_GLES2_OPENGL -}; - -#endif // ANDROID - -#else // USE_OPENGL -// no defines - -// map for index to RenderType -const RenderType indexToRender[] = -{ - RENDER_SOFTWARE -}; - -const char *OPENGL_NAME[] = -{ - // TRANSLATORS: draw backend - N_("Software") -}; - -const int renderModesListSize = 1; - -const int renderToIndex[] = -{ - 0, // RENDER_SOFTWARE - 0, // RENDER_NORMAL_OPENGL - 0, // RENDER_SAFE_OPENGL - 0, // RENDER_GLES_OPENGL - 0, // RENDER_SDL2_DEFAULT - 0, // RENDER_MODERN_OPENGL - 0 // RENDER_GLES2_OPENGL -}; - -#endif // USE_OPENGL - -#endif // USE_SDL2 -#endif // RENDER_RENDERERSLISTSDL_H diff --git a/src/render/rendererslistsdl2.h b/src/render/rendererslistsdl2.h deleted file mode 100644 index 22a975cfa..000000000 --- a/src/render/rendererslistsdl2.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_RENDERERSLISTSDL2_H -#define RENDER_RENDERERSLISTSDL2_H - -#ifdef USE_SDL2 - -#include "utils/gettext.h" - -#include "render/renderers.h" - -#ifdef USE_OPENGL -#ifdef ANDROID -// defined OPENGL ANDROID - -// map for index to RenderType -const RenderType indexToRender[] = -{ - RENDER_SOFTWARE, - RENDER_SDL2_DEFAULT, - RENDER_GLES_OPENGL -}; - -const char *OPENGL_NAME[] = -{ - // TRANSLATORS: draw backend - N_("Software"), - // TRANSLATORS: draw backend - N_("SDL2 default"), - // TRANSLATORS: draw backend - N_("Mobile OpenGL ES") -}; - -const int renderModesListSize = 3; - -const int renderToIndex[] = -{ - 0, // RENDER_SOFTWARE - 2, // RENDER_NORMAL_OPENGL - 2, // RENDER_SAFE_OPENGL - 2, // RENDER_GLES_OPENGL - 1, // RENDER_SDL2_DEFAULT - 2, // RENDER_MODERN_OPENGL - 2 // RENDER_GLES_OPENGL -}; - -#elif defined(__native_client__) -// defined OPENGL nacl - -// map for index to RenderType -const RenderType indexToRender[] = -{ - RENDER_SOFTWARE, - RENDER_SDL2_DEFAULT, - RENDER_SAFE_OPENGL, - RENDER_GLES2_OPENGL -}; - -const char *OPENGL_NAME[] = -{ - // TRANSLATORS: draw backend - N_("Software"), - // TRANSLATORS: draw backend - N_("SDL2 default"), - // TRANSLATORS: draw backend - N_("Safe OpenGL"), - // TRANSLATORS: draw backend - N_("Mobile OpenGL ES 2") -}; - -const int renderModesListSize = 4; - -const int renderToIndex[] = -{ - 0, // RENDER_SOFTWARE - 3, // RENDER_NORMAL_OPENGL - 2, // RENDER_SAFE_OPENGL - 3, // RENDER_GLES_OPENGL - 1, // RENDER_SDL2_DEFAULT - 3, // RENDER_MODERN_OPENGL - 3 // RENDER_GLES2_OPENGL -}; - -#else // ANDROID or nacl -// defined OPENGL - -// map for index to RenderType -const RenderType indexToRender[] = -{ - RENDER_SOFTWARE, - RENDER_SDL2_DEFAULT, - RENDER_NORMAL_OPENGL, - RENDER_SAFE_OPENGL, - RENDER_GLES_OPENGL, - RENDER_MODERN_OPENGL, - RENDER_GLES2_OPENGL -}; - -const char *OPENGL_NAME[] = -{ - // TRANSLATORS: draw backend - N_("Software"), - // TRANSLATORS: draw backend - N_("SDL2 default"), - // TRANSLATORS: draw backend - N_("Normal OpenGL"), - // TRANSLATORS: draw backend - N_("Safe OpenGL"), - // TRANSLATORS: draw backend - N_("Mobile OpenGL ES"), - // TRANSLATORS: draw backend - N_("Modern OpenGL"), - // TRANSLATORS: draw backend - N_("Mobile OpenGL ES 2") -}; - -const int renderModesListSize = 7; - -const int renderToIndex[] = -{ - 0, // RENDER_SOFTWARE - 2, // RENDER_NORMAL_OPENGL - 3, // RENDER_SAFE_OPENGL - 4, // RENDER_GLES_OPENGL - 1, // RENDER_SDL2_DEFAULT - 5, // RENDER_MODERN_OPENGL - 6 // RENDER_GLES2_OPENGL -}; - -#endif // ANDROID - -#else // USE_OPENGL -// no defines - -// map for index to RenderType -const RenderType indexToRender[] = -{ - RENDER_SOFTWARE, - RENDER_SDL2_DEFAULT -}; - -const char *OPENGL_NAME[] = -{ - // TRANSLATORS: draw backend - N_("Software"), - // TRANSLATORS: draw backend - N_("SDL2 default") -}; - -const int renderModesListSize = 2; - -const int renderToIndex[] = -{ - 0, // RENDER_SOFTWARE - 0, // RENDER_NORMAL_OPENGL - 0, // RENDER_SAFE_OPENGL - 0, // RENDER_GLES_OPENGL - 1, // RENDER_SDL2_DEFAULT - 0, // RENDER_MODERN_OPENGL - 0 // RENDER_GLES2_OPENGL -}; - -#endif // USE_OPENGL - -#endif // USE_SDL2 -#endif // RENDER_RENDERERSLISTSDL2_H diff --git a/src/render/safeopenglgraphics.cpp b/src/render/safeopenglgraphics.cpp deleted file mode 100644 index e65ff94b0..000000000 --- a/src/render/safeopenglgraphics.cpp +++ /dev/null @@ -1,763 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if defined USE_OPENGL && !defined ANDROID -#include "render/safeopenglgraphics.h" - -#ifdef DEBUG_OPENGL -#include "render/opengl/mgl.h" -#endif // DEBUG_OPENGL - -#include "resources/imagerect.h" -#include "resources/safeopenglimagehelper.h" - -#include "resources/image/image.h" - -#include "utils/sdlcheckutils.h" - -#include "debug.h" - -GLuint SafeOpenGLGraphics::mTextureBinded = 0; - -SafeOpenGLGraphics::SafeOpenGLGraphics() : - mTexture(false), - mIsByteColor(false), - mByteColor(), - mFloatColor(1.0F), - mColorAlpha(false), - mFbo() -{ - mOpenGL = RENDER_SAFE_OPENGL; - mName = "safe OpenGL"; -} - -SafeOpenGLGraphics::~SafeOpenGLGraphics() -{ -} - -void SafeOpenGLGraphics::deleteArrays() restrict2 -{ -} - -bool SafeOpenGLGraphics::setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - setMainFlags(w, h, - scale, - bpp, - fs, - hwaccel, - resize, - noFrame, - allowHighDPI); - - return setOpenGLMode(); -} - -static inline void drawQuad(const Image *restrict image, - const int srcX, - const int srcY, - const int dstX, - const int dstY, - const int width, - const int height) A_NONNULL(1) A_INLINE; - -static inline void drawQuad(const Image *restrict image, - const int srcX, - const int srcY, - const int dstX, - const int dstY, - const int width, - const int height) -{ - if (SafeOpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - const float texX2 = static_cast(srcX + width) / tw; - const float texY2 = static_cast(srcY + height) / th; - - glTexCoord2f(texX1, texY1); - glVertex2i(dstX, dstY); - glTexCoord2f(texX2, texY1); - glVertex2i(dstX + width, dstY); - glTexCoord2f(texX2, texY2); - glVertex2i(dstX + width, dstY + height); - glTexCoord2f(texX1, texY2); - glVertex2i(dstX, dstY + height); - } - else - { - glTexCoord2i(srcX, srcY); - glVertex2i(dstX, dstY); - glTexCoord2i(srcX + width, srcY); - glVertex2i(dstX + width, dstY); - glTexCoord2i(srcX + width, srcY + height); - glVertex2i(dstX + width, dstY + height); - glTexCoord2i(srcX, srcY + height); - glVertex2i(dstX, dstY + height); - } -} - -static inline void drawRescaledQuad(const Image *restrict const image, - const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) - A_NONNULL(1) A_INLINE; - -static inline void drawRescaledQuad(const Image *restrict const image, - const int srcX, const int srcY, - const int dstX, const int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight) -{ - if (SafeOpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - const float tw = static_cast(image->mTexWidth); - const float th = static_cast(image->mTexHeight); - // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast(srcX) / tw; - const float texY1 = static_cast(srcY) / th; - const float texX2 = static_cast(srcX + width) / tw; - const float texY2 = static_cast(srcY + height) / th; - - glTexCoord2f(texX1, texY1); - glVertex2i(dstX, dstY); - glTexCoord2f(texX2, texY1); - glVertex2i(dstX + desiredWidth, dstY); - glTexCoord2f(texX2, texY2); - glVertex2i(dstX + desiredWidth, dstY + desiredHeight); - glTexCoord2f(texX1, texY2); - glVertex2i(dstX, dstY + desiredHeight); - } - else - { - glTexCoord2i(srcX, srcY); - glVertex2i(dstX, dstY); - glTexCoord2i(srcX + width, srcY); - glVertex2i(dstX + desiredWidth, dstY); - glTexCoord2i(srcX + width, srcY + height); - glVertex2i(dstX + desiredWidth, dstY + desiredHeight); - glTexCoord2i(srcX, srcY + height); - glVertex2i(dstX, dstY + desiredHeight); - } -} - -void SafeOpenGLGraphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void SafeOpenGLGraphics::drawImageInline(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - if (image == nullptr) - return; - - setColorAlpha(image->mAlpha); - bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - const SDL_Rect &bounds = image->mBounds; - // Draw a textured quad. - glBegin(GL_QUADS); - drawQuad(image, bounds.x, bounds.y, - dstX, dstY, bounds.w, bounds.h); - glEnd(); -} - -void SafeOpenGLGraphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void SafeOpenGLGraphics::testDraw() restrict2 -{ - if (SafeOpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - { - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.781250f); - glVertex2i(0, 0); - glTexCoord2f(0.0f, 0.781250f); - glVertex2i(800, 0); - glTexCoord2f(0.0f, 0.585938f); - glVertex2i(800, 600); - glTexCoord2f(0.0f, 0.585938f); - glVertex2i(0, 600); - glEnd(); - } - else - { - glBegin(GL_QUADS); - glTexCoord2i(0, 0); - glVertex2i(0, 0); - glTexCoord2i(800, 0); - glVertex2i(800, 0); - glTexCoord2i(800, 600); - glVertex2i(800, 600); - glTexCoord2i(0, 600); - glVertex2i(0, 600); - glEnd(); - } -} - -void SafeOpenGLGraphics::drawImageCached(const Image *restrict const image, - int x, int y) restrict2 -{ - FUNC_BLOCK("Graphics::drawImageCached", 1) - if (image == nullptr) - return; - - setColorAlpha(image->mAlpha); - bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - const SDL_Rect &bounds = image->mBounds; - // Draw a textured quad. - glBegin(GL_QUADS); - drawQuad(image, bounds.x, bounds.y, x, y, bounds.w, bounds.h); - glEnd(); -} - -void SafeOpenGLGraphics::drawPatternCached(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPatternCached", 1) - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int iw = imageRect.w; - const int ih = imageRect.h; - if (iw == 0 || ih == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - - setColorAlpha(image->mAlpha); - bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - // Draw a set of textured rectangles - glBegin(GL_QUADS); - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - int width = (px + iw >= w) ? w - px : iw; - int dstX = x + px; - drawQuad(image, srcX, srcY, dstX, dstY, width, height); - } - } - - glEnd(); -} - -void SafeOpenGLGraphics::completeCache() restrict2 -{ -} - -void SafeOpenGLGraphics::drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - FUNC_BLOCK("Graphics::drawRescaledImage", 1) - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - - // Just draw the image normally when no resizing is necessary, - if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) - { - drawImageInline(image, dstX, dstY); - return; - } - - setColorAlpha(image->mAlpha); - bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - // Draw a textured quad. - glBegin(GL_QUADS); - drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY, - imageRect.w, imageRect.h, desiredWidth, desiredHeight); - glEnd(); -} - -void SafeOpenGLGraphics::drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - drawPatternInline(image, x, y, w, h); -} - -void SafeOpenGLGraphics::drawPatternInline(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPattern", 1) - if (image == nullptr) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int iw = imageRect.w; - const int ih = imageRect.h; - if (iw == 0 || ih == 0) - return; - - const int srcX = imageRect.x; - const int srcY = imageRect.y; - - setColorAlpha(image->mAlpha); - bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - // Draw a set of textured rectangles - glBegin(GL_QUADS); - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - int width = (px + iw >= w) ? w - px : iw; - int dstX = x + px; - drawQuad(image, srcX, srcY, dstX, dstY, width, height); - } - } - - glEnd(); -} - -void SafeOpenGLGraphics::drawRescaledPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) restrict2 -{ - if (image == nullptr) - return; - - const int iw = scaledWidth; - const int ih = scaledHeight; - if (iw == 0 || ih == 0) - return; - - const SDL_Rect &imageRect = image->mBounds; - const int srcX = imageRect.x; - const int srcY = imageRect.y; - - setColorAlpha(image->mAlpha); - bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage); - enableTexturingAndBlending(); - - // Draw a set of textured rectangles - glBegin(GL_QUADS); - - const float scaleFactorW = static_cast(scaledWidth) - / image->getWidth(); - const float scaleFactorH = static_cast(scaledHeight) - / image->getHeight(); - - for (int py = 0; py < h; py += ih) - { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) - { - int width = (px + iw >= w) ? w - px : iw; - int dstX = x + px; - - drawRescaledQuad(image, srcX, srcY, dstX, dstY, - width / scaleFactorW, height / scaleFactorH, - scaledWidth, scaledHeight); - } - } - - glEnd(); -} - -void SafeOpenGLGraphics::calcTileCollection(ImageCollection *restrict const - vertCol A_UNUSED, - const Image *restrict const image - A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) restrict2 -{ -} - -void SafeOpenGLGraphics::calcTileVertexes(ImageVertexes *restrict const vert - A_UNUSED, - const Image *restrict const image - A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) const restrict2 -{ -} - -void SafeOpenGLGraphics::calcTileVertexesInline(ImageVertexes *restrict const - vert A_UNUSED, - const Image *restrict const - image A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) const restrict2 -{ -} - -void SafeOpenGLGraphics::calcPattern(ImageVertexes *restrict const vert - A_UNUSED, - const Image *restrict const image - A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) const restrict2 -{ -} - -void SafeOpenGLGraphics::calcPatternInline(ImageVertexes *restrict const vert - A_UNUSED, - const Image *restrict const image - A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) - const restrict2 -{ -} - -void SafeOpenGLGraphics::calcPattern(ImageCollection *restrict const vert - A_UNUSED, - const Image *restrict const image - A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) const restrict2 -{ -} - -void SafeOpenGLGraphics::drawTileVertexes(const ImageVertexes - *restrict const vert A_UNUSED) - restrict2 -{ -} - -void SafeOpenGLGraphics::drawTileCollection(const ImageCollection * - restrict const vertCol A_UNUSED) - restrict2 -{ -} - -void SafeOpenGLGraphics::updateScreen() restrict2 -{ - BLOCK_START("Graphics::updateScreen") - glFlush(); - glFinish(); -#ifdef USE_SDL2 - SDL_GL_SwapWindow(mWindow); -#else - SDL_GL_SwapBuffers(); -#endif // USE_SDL2 -#ifdef DEBUG_OPENGL - if (isGLNotNull(mglFrameTerminator)) - mglFrameTerminator(); -#endif // DEBUG_OPENGL - - BLOCK_END("Graphics::updateScreen") -} - -void SafeOpenGLGraphics::calcWindow(ImageCollection *restrict const vertCol - A_UNUSED, - const int x A_UNUSED, const int y A_UNUSED, - const int w A_UNUSED, const int h A_UNUSED, - const ImageRect &restrict imgRect A_UNUSED) - restrict2 -{ -} - -void SafeOpenGLGraphics::beginDraw() restrict2 -{ - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glOrtho(0.0, static_cast(mRect.w), - static_cast(mRect.h), - 0.0, -1.0, 1.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - setOpenGLFlags(); - glDisable(GL_LIGHTING); - glDisable(GL_FOG); - glDisable(GL_COLOR_MATERIAL); - - glShadeModel(GL_FLAT); - - pushClipArea(Rect(0, 0, mRect.w, mRect.h)); -} - -void SafeOpenGLGraphics::endDraw() restrict2 -{ - popClipArea(); -} - -void SafeOpenGLGraphics::pushClipArea(const Rect &restrict area) restrict2 -{ - int transX = 0; - int transY = 0; - - if (!mClipStack.empty()) - { - const ClipRect &clipArea = mClipStack.top(); - transX = -clipArea.xOffset; - transY = -clipArea.yOffset; - } - - Graphics::pushClipArea(area); - - const ClipRect &clipArea = mClipStack.top(); - - glPushMatrix(); - glTranslatef(static_cast(transX + clipArea.xOffset), - static_cast(transY + clipArea.yOffset), 0); - glScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -void SafeOpenGLGraphics::popClipArea() restrict2 -{ - Graphics::popClipArea(); - - if (mClipStack.empty()) - return; - - glPopMatrix(); - const ClipRect &clipArea = mClipStack.top(); - glScissor(clipArea.x * mScale, - (mRect.h - clipArea.y - clipArea.height) * mScale, - clipArea.width * mScale, - clipArea.height * mScale); -} - -void SafeOpenGLGraphics::drawPoint(int x, int y) restrict2 -{ - disableTexturingAndBlending(); - restoreColor(); - - glBegin(GL_POINTS); - glVertex2i(x, y); - glEnd(); -} - -void SafeOpenGLGraphics::drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) restrict2 -{ - disableTexturingAndBlending(); - restoreColor(); - - glBegin(GL_LINES); - for (int y = y1; y < y2; y += height) - { - glVertex2f(static_cast(x1) + 0.5F, - static_cast(y) + 0.5F); - glVertex2f(static_cast(x2) + 0.5F, - static_cast(y) + 0.5F); - } - - for (int x = x1; x < x2; x += width) - { - glVertex2f(static_cast(x) + 0.5F, - static_cast(y1) + 0.5F); - glVertex2f(static_cast(x) + 0.5F, - static_cast(y2) + 0.5F); - } - glEnd(); -} - -void SafeOpenGLGraphics::drawLine(int x1, int y1, - int x2, int y2) restrict2 -{ - disableTexturingAndBlending(); - restoreColor(); - - glBegin(GL_LINES); - glVertex2f(static_cast(x1) + 0.5F, static_cast(y1) + 0.5F); - glVertex2f(static_cast(x2) + 0.5F, static_cast(y2) + 0.5F); - glEnd(); -} - -void SafeOpenGLGraphics::drawRectangle(const Rect &restrict rect) restrict2 -{ - drawRectangle(rect, false); -} - -void SafeOpenGLGraphics::fillRectangle(const Rect &restrict rect) restrict2 -{ - drawRectangle(rect, true); -} - -void SafeOpenGLGraphics::enableTexturingAndBlending() restrict2 -{ - if (!mTexture) - { - glEnable(SafeOpenGLImageHelper::mTextureType); - mTexture = true; - } - - if (!mAlpha) - { - glEnable(GL_BLEND); - mAlpha = true; - } -} - -void SafeOpenGLGraphics::disableTexturingAndBlending() restrict2 -{ - mTextureBinded = 0; - if (mAlpha && !mColorAlpha) - { - glDisable(GL_BLEND); - mAlpha = false; - } - else if (!mAlpha && mColorAlpha) - { - glEnable(GL_BLEND); - mAlpha = true; - } - - if (mTexture) - { - glDisable(SafeOpenGLImageHelper::mTextureType); - mTexture = false; - } -} - -void SafeOpenGLGraphics::drawRectangle(const Rect &restrict rect, - const bool filled) restrict2 -{ - BLOCK_START("Graphics::drawRectangle") - const float offset = filled ? 0 : 0.5F; - - disableTexturingAndBlending(); - restoreColor(); - - glBegin(filled ? GL_QUADS : GL_LINE_LOOP); - glVertex2f(static_cast(rect.x) + offset, - static_cast(rect.y) + offset); - glVertex2f(static_cast(rect.x + rect.width) - offset, - static_cast(rect.y) + offset); - glVertex2f(static_cast(rect.x + rect.width) - offset, - static_cast(rect.y + rect.height) - offset); - glVertex2f(static_cast(rect.x) + offset, - static_cast(rect.y + rect.height) - offset); - glEnd(); - BLOCK_END("Graphics::drawRectangle") -} - -void SafeOpenGLGraphics::bindTexture(const GLenum target, - const GLuint texture) -{ - if (mTextureBinded != texture) - { - mTextureBinded = texture; - glBindTexture(target, texture); - } -} - -void SafeOpenGLGraphics::setColorAlpha(const float alpha) restrict2 -{ - if (!mIsByteColor && mFloatColor == alpha) - return; - - glColor4f(1.0F, 1.0F, 1.0F, alpha); - mIsByteColor = false; - mFloatColor = alpha; -} - -void SafeOpenGLGraphics::restoreColor() restrict2 -{ - if (mIsByteColor && mByteColor == mColor) - return; - - glColor4ub(static_cast(mColor.r), - static_cast(mColor.g), - static_cast(mColor.b), - static_cast(mColor.a)); - mIsByteColor = true; - mByteColor = mColor; -} - -void SafeOpenGLGraphics::clearScreen() const restrict2 -{ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); -} - -void SafeOpenGLGraphics::drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_drawImageRect.hpp" -} - -void SafeOpenGLGraphics::calcImageRect(ImageVertexes *restrict const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_calcImageRect.hpp" -} - -#endif // USE_OPENGL diff --git a/src/render/safeopenglgraphics.h b/src/render/safeopenglgraphics.h deleted file mode 100644 index 5c85ee058..000000000 --- a/src/render/safeopenglgraphics.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_SAFEOPENGLGRAPHICS_H -#define RENDER_SAFEOPENGLGRAPHICS_H - -#if defined USE_OPENGL && !defined ANDROID - -#include "render/graphics.h" - -#include "resources/fboinfo.h" - -#ifdef ANDROID -#include -#include -#else // ANDROID -#ifndef USE_SDL2 -#define GL_GLEXT_PROTOTYPES 1 -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#include -PRAGMA48(GCC diagnostic pop) -#if defined(__APPLE__) -#include -#elif !defined(__native_client__) -#include -#endif // defined(__APPLE__) -#endif // ANDROID - -class SafeOpenGLGraphics final : public Graphics -{ - public: - SafeOpenGLGraphics(); - - A_DELETE_COPY(SafeOpenGLGraphics) - - ~SafeOpenGLGraphics(); - - void testDraw() restrict2 override final; - - #include "render/graphicsdef.hpp" - RENDER_GRAPHICSDEF_HPP - - #include "render/openglgraphicsdef.hpp" - RENDER_OPENGLGRAPHICSDEF_HPP - - #include "render/openglgraphicsdef1.hpp" - RENDER_OPENGLGRAPHICSDEF1_HPP - - private: - bool mTexture; - bool mIsByteColor; - Color mByteColor; - float mFloatColor; - bool mColorAlpha; - FBOInfo mFbo; -}; - -#endif // defined USE_OPENGL && !defined ANDROID -#endif // RENDER_SAFEOPENGLGRAPHICS_H diff --git a/src/render/sdl2graphics.cpp b/src/render/sdl2graphics.cpp deleted file mode 100644 index baa69ca69..000000000 --- a/src/render/sdl2graphics.cpp +++ /dev/null @@ -1,789 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef USE_SDL2 - -#include "render/sdl2graphics.h" - -#include "graphicsmanager.h" - -#include "render/vertexes/imagecollection.h" - -#include "resources/imagerect.h" -#include "resources/sdl2imagehelper.h" - -#include "resources/image/image.h" - -#include "utils/sdlcheckutils.h" - -#include "debug.h" - -#ifdef DEBUG_SDL_SURFACES - -#define MSDL_RenderCopy(render, texture, src, dst) \ - FakeSDL_RenderCopy(render, texture, src, dst) - -static int FakeSDL_RenderCopy(SDL_Renderer *restrict const renderer, - SDL_Texture *restrict const texture, - const SDL_Rect *restrict const srcrect, - const SDL_Rect *restrict const dstrect) -{ - int ret = SDL_RenderCopy(renderer, texture, srcrect, dstrect); - if (ret) - { - logger->log("rendering error in texture %p: %s", - static_cast(texture), SDL_GetError()); - } - return ret; -} - -#else // DEBUG_SDL_SURFACES - -#define MSDL_RenderCopy(render, texture, src, dst) \ - SDL_RenderCopy(render, texture, src, dst) - -#endif // DEBUG_SDL_SURFACES - -#define setRenderDrawColor(mColor) \ - SDL_SetRenderDrawColor(mRenderer, \ - CAST_U8(mColor.r), \ - CAST_U8(mColor.g), \ - CAST_U8(mColor.b), \ - CAST_U8(mColor.a)) - -#define defRectFromArea(rect, area) \ - const SDL_Rect rect = \ - { \ - CAST_S32(area.x), \ - CAST_S32(area.y), \ - CAST_S32(area.width), \ - CAST_S32(area.height) \ - } - -SDLGraphics::SDLGraphics() : - Graphics(), - mRendererFlags(SDL_RENDERER_SOFTWARE), - mOldPixel(0), - mOldAlpha(0) -{ - mOpenGL = RENDER_SDL2_DEFAULT; - mName = "SDL2 default"; -} - -SDLGraphics::~SDLGraphics() -{ -} - -void SDLGraphics::drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - FUNC_BLOCK("Graphics::drawRescaledImage", 1) - // Check that preconditions for blitting are met. - if (!mWindow || !image || !image->mTexture) - return; - - const ClipRect &top = mClipStack.top(); - const SDL_Rect &bounds = image->mBounds; - const SDL_Rect srcRect = - { - CAST_S32(bounds.x), - CAST_S32(bounds.y), - CAST_S32(bounds.w), - CAST_S32(bounds.h) - }; - const SDL_Rect dstRect = - { - CAST_S32(dstX + top.xOffset), - CAST_S32(dstY + top.yOffset), - CAST_S32(desiredWidth), - CAST_S32(desiredHeight) - }; - - MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); -} - -void SDLGraphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void SDLGraphics::drawImageInline(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - // Check that preconditions for blitting are met. - if (!mWindow || !image || !image->mTexture) - return; - - const ClipRect &top = mClipStack.top(); - if (!top.width || !top.height) - return; - - const SDL_Rect &bounds = image->mBounds; - const SDL_Rect srcRect = - { - CAST_S32(bounds.x), - CAST_S32(bounds.y), - CAST_S32(bounds.w), - CAST_S32(bounds.h) - }; - - const SDL_Rect dstRect = - { - CAST_S32(dstX + top.xOffset), - CAST_S32(dstY + top.yOffset), - CAST_S32(bounds.w), - CAST_S32(bounds.h) - }; - - MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); -} - -void SDLGraphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void SDLGraphics::drawImageCached(const Image *restrict const image, - int x, int y) restrict2 -{ - FUNC_BLOCK("Graphics::drawImageCached", 1) - // Check that preconditions for blitting are met. - if (!mWindow || !image || !image->mTexture) - return; - - const ClipRect &top = mClipStack.top(); - if (!top.width || !top.height) - return; - - const SDL_Rect &bounds = image->mBounds; - const SDL_Rect srcRect = - { - CAST_S32(bounds.x), - CAST_S32(bounds.y), - CAST_S32(bounds.w), - CAST_S32(bounds.h) - }; - - const SDL_Rect dstRect = - { - CAST_S32(x + top.xOffset), - CAST_S32(y + top.yOffset), - CAST_S32(bounds.w), - CAST_S32(bounds.h) - }; - - MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); -} - -void SDLGraphics::drawPatternCached(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPatternCached", 1) - // Check that preconditions for blitting are met. - if (!mWindow || !image) - return; - if (!image->mTexture) - return; - - const ClipRect &top = mClipStack.top(); - if (!top.width || !top.height) - return; - - const SDL_Rect &bounds = image->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - - SDL_Rect dstRect; - SDL_Rect srcRect; - srcRect.x = CAST_S32(bounds.x); - srcRect.y = CAST_S32(bounds.y); - for (int py = 0; py < h; py += ih) - { - const int dh = (py + ih >= h) ? h - py : ih; - dstRect.y = CAST_S32(py + yOffset); - srcRect.h = CAST_S32(dh); - dstRect.h = CAST_S32(dh); - - for (int px = 0; px < w; px += iw) - { - const int dw = (px + iw >= w) ? w - px : iw; - dstRect.x = CAST_S32(px + xOffset); - srcRect.w = CAST_S32(dw); - dstRect.w = CAST_S32(dw); - - MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); - } - } -} - -void SDLGraphics::completeCache() restrict2 -{ -} - -void SDLGraphics::drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - drawPatternInline(image, x, y, w, h); -} - -void SDLGraphics::drawPatternInline(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPattern", 1) - // Check that preconditions for blitting are met. - if (!mWindow || !image) - return; - if (!image->mTexture) - return; - - const ClipRect &top = mClipStack.top(); - if (!top.width || !top.height) - return; - - const SDL_Rect &bounds = image->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - - SDL_Rect dstRect; - SDL_Rect srcRect; - srcRect.x = CAST_S32(bounds.x); - srcRect.y = CAST_S32(bounds.y); - for (int py = 0; py < h; py += ih) - { - const int dh = (py + ih >= h) ? h - py : ih; - dstRect.y = CAST_S32(py + yOffset); - srcRect.h = CAST_S32(dh); - dstRect.h = CAST_S32(dh); - - for (int px = 0; px < w; px += iw) - { - const int dw = (px + iw >= w) ? w - px : iw; - dstRect.x = CAST_S32(px + xOffset); - srcRect.w = CAST_S32(dw); - dstRect.w = CAST_S32(dw); - - MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); - } - } -} - -void SDLGraphics::drawRescaledPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) restrict2 -{ - // Check that preconditions for blitting are met. - if (!mWindow || !image) - return; - if (!image->mTexture) - return; - - if (scaledHeight == 0 || scaledWidth == 0) - return; - - const ClipRect &top = mClipStack.top(); - if (!top.width || !top.height) - return; - - Image *const tmpImage = image->SDLgetScaledImage( - scaledWidth, scaledHeight); - if (!tmpImage) - return; - - const SDL_Rect &bounds = tmpImage->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - - SDL_Rect dstRect; - SDL_Rect srcRect; - srcRect.x = CAST_S32(bounds.x); - srcRect.y = CAST_S32(bounds.y); - for (int py = 0; py < h; py += ih) - { - const int dh = (py + ih >= h) ? h - py : ih; - dstRect.y = CAST_S32(py + yOffset); - srcRect.h = CAST_S32(dh); - dstRect.h = CAST_S32(dh); - - for (int px = 0; px < w; px += iw) - { - const int dw = (px + iw >= w) ? w - px : iw; - dstRect.x = CAST_S32(px + xOffset); - srcRect.w = CAST_S32(dw); - dstRect.w = CAST_S32(dw); - - MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); - } - } - - delete tmpImage; -} - -void SDLGraphics::calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 -{ - calcPatternInline(vert, image, x, y, w, h); -} - -void SDLGraphics::calcPatternInline(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 -{ - // Check that preconditions for blitting are met. - if (!vert || !mWindow || !image || !image->mTexture) - return; - - const ClipRect &top = mClipStack.top(); - if (!top.width || !top.height) - return; - - const SDL_Rect &bounds = image->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - const int srcX = bounds.x; - const int srcY = bounds.y; - for (int py = 0; py < h; py += ih) - { - const int dh = (py + ih >= h) ? h - py : ih; - const int dstY = py + yOffset; - - for (int px = 0; px < w; px += iw) - { - const int dw = (px + iw >= w) ? w - px : iw; - const int dstX = px + xOffset; - - DoubleRect *const r = new DoubleRect; - SDL_Rect &dstRect = r->dst; - SDL_Rect &srcRect = r->src; - srcRect.x = CAST_S32(srcX); - srcRect.y = CAST_S32(srcY); - srcRect.w = CAST_S32(dw); - srcRect.h = CAST_S32(dh); - dstRect.x = CAST_S32(dstX); - dstRect.y = CAST_S32(dstY); - dstRect.w = CAST_S32(dw); - dstRect.h = CAST_S32(dh); - - vert->sdl.push_back(r); - } - } -} - -void SDLGraphics::calcPattern(ImageCollection *restrict const vertCol, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 -{ - ImageVertexes *vert = nullptr; - if (vertCol->currentImage != image) - { - vert = new ImageVertexes; - vertCol->currentImage = image; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - - calcPatternInline(vert, image, x, y, w, h); -} - -void SDLGraphics::calcTileVertexes(ImageVertexes *restrict const vert, - const Image *restrict const image, - int x, int y) const restrict2 -{ - vert->image = image; - calcTileSDL(vert, x, y); -} - -void SDLGraphics::calcTileVertexesInline(ImageVertexes *restrict const vert, - const Image *restrict const image, - int x, int y) const restrict2 -{ - vert->image = image; - calcTileSDL(vert, x, y); -} - -void SDLGraphics::calcTileSDL(ImageVertexes *restrict const vert, - int x, int y) const restrict2 -{ - // Check that preconditions for blitting are met. - if (!vert || !vert->image || !vert->image->mTexture) - return; - - const ClipRect &top = mClipStack.top(); - if (!top.width || !top.height) - return; - - const Image *const image = vert->image; - const SDL_Rect &bounds = image->mBounds; - - x += top.xOffset; - y += top.yOffset; - - DoubleRect *rect = new DoubleRect; - SDL_Rect &dstRect = rect->dst; - SDL_Rect &srcRect = rect->src; - - srcRect.x = CAST_S32(bounds.x); - srcRect.y = CAST_S32(bounds.y); - srcRect.w = CAST_S32(bounds.w); - srcRect.h = CAST_S32(bounds.h); - dstRect.x = CAST_S32(x); - dstRect.y = CAST_S32(y); - dstRect.w = CAST_S32(bounds.w); - dstRect.h = CAST_S32(bounds.h); - - vert->sdl.push_back(rect); -} - -void SDLGraphics::calcTileCollection(ImageCollection *restrict const vertCol, - const Image *restrict const image, - int x, int y) restrict2 -{ - if (!vertCol) - return; - if (vertCol->currentImage != image) - { - ImageVertexes *const vert = new ImageVertexes; - vertCol->currentImage = image; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - calcTileSDL(vert, x, y); - } - else - { - calcTileSDL(vertCol->currentVert, x, y); - } -} - -void SDLGraphics::drawTileCollection(const ImageCollection - *restrict const vertCol) restrict2 -{ - const ImageVertexesVector &draws = vertCol->draws; - const ImageCollectionCIter it_end = draws.end(); - for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) - { - const ImageVertexes *const vert = *it; - const Image *const img = vert->image; - const DoubleRects *const rects = &vert->sdl; - DoubleRects::const_iterator it2 = rects->begin(); - const DoubleRects::const_iterator it2_end = rects->end(); - while (it2 != it2_end) - { - MSDL_RenderCopy(mRenderer, img->mTexture, - &(*it2)->src, &(*it2)->dst); - ++ it2; - } - } -} - -void SDLGraphics::drawTileVertexes(const ImageVertexes *restrict const vert) - restrict2 -{ - if (!vert) - return; - // vert and img must be != 0 - const Image *const img = vert->image; - const DoubleRects *const rects = &vert->sdl; - DoubleRects::const_iterator it = rects->begin(); - const DoubleRects::const_iterator it_end = rects->end(); - while (it != it_end) - { - MSDL_RenderCopy(mRenderer, img->mTexture, &(*it)->src, &(*it)->dst); - ++ it; - } -} - -void SDLGraphics::updateScreen() restrict2 -{ - BLOCK_START("Graphics::updateScreen") - SDL_RenderPresent(mRenderer); -// SDL_RenderClear(mRenderer); - BLOCK_END("Graphics::updateScreen") -} - -void SDLGraphics::calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) restrict2 -{ - ImageVertexes *vert = nullptr; - Image *const image = imgRect.grid[4]; - if (!image) - return; - if (vertCol->currentImage != image) - { - vert = new ImageVertexes; - vertCol->currentImage = image; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - calcImageRect(vert, x, y, w, h, imgRect); -} - -void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2 -{ - const ClipRect &top = mClipStack.top(); - const SDL_Rect rect = - { - CAST_S32(rectangle.x + top.xOffset), - CAST_S32(rectangle.y + top.yOffset), - CAST_S32(rectangle.width), - CAST_S32(rectangle.height) - }; - - setRenderDrawColor(mColor); - SDL_RenderFillRects(mRenderer, &rect, 1); -} - -void SDLGraphics::beginDraw() restrict2 -{ - pushClipArea(Rect(0, 0, mRect.w, mRect.h)); -} - -void SDLGraphics::endDraw() restrict2 -{ - popClipArea(); -} - -void SDLGraphics::pushClipArea(const Rect &restrict area) restrict2 -{ - Graphics::pushClipArea(area); - - const ClipRect &carea = mClipStack.top(); - defRectFromArea(rect, carea); - SDL_RenderSetClipRect(mRenderer, &rect); -} - -void SDLGraphics::popClipArea() restrict2 -{ - Graphics::popClipArea(); - - if (mClipStack.empty()) - return; - - const ClipRect &carea = mClipStack.top(); - defRectFromArea(rect, carea); - SDL_RenderSetClipRect(mRenderer, &rect); -} - -void SDLGraphics::drawPoint(int x, int y) restrict2 -{ - if (mClipStack.empty()) - return; - - const ClipRect &top = mClipStack.top(); - - x += top.xOffset; - y += top.yOffset; - - if (!top.isPointInRect(x, y)) - return; - - setRenderDrawColor(mColor); - const SDL_Point point = - { - x, - y - }; - - SDL_RenderDrawPoints(mRenderer, &point, 1); -} - - -void SDLGraphics::drawRectangle(const Rect &restrict rectangle) restrict2 -{ - const ClipRect &top = mClipStack.top(); - setRenderDrawColor(mColor); - - const int x1 = rectangle.x + top.xOffset; - const int y1 = rectangle.y + top.yOffset; - const int x2 = x1 + rectangle.width - 1; - const int y2 = y1 + rectangle.height - 1; - SDL_Point points[] = - { - {x1, y1}, - {x2, y1}, - {x2, y2}, - {x1, y2}, - {x1, y1} - }; - - SDL_RenderDrawLines(mRenderer, points, 5); -} - -void SDLGraphics::drawLine(int x1, int y1, - int x2, int y2) restrict2 -{ - const ClipRect &top = mClipStack.top(); - setRenderDrawColor(mColor); - - const int x0 = top.xOffset; - const int y0 = top.yOffset; - - SDL_Point points[] = - { - {x1 + x0, y1 + y0}, - {x2 + x0, y2 + y0} - }; - - SDL_RenderDrawLines(mRenderer, points, 2); -} - -bool SDLGraphics::setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - setMainFlags(w, h, - scale, - bpp, - fs, - hwaccel, - resize, - noFrame, - allowHighDPI); - - if (!(mWindow = graphicsManager.createWindow(w, h, bpp, - getSoftwareFlags()))) - { - mRect.w = 0; - mRect.h = 0; - return false; - } - - int w1 = 0; - int h1 = 0; - SDL_GetWindowSize(mWindow, &w1, &h1); - mRect.w = w1; - mRect.h = h1; - - mRenderer = graphicsManager.createRenderer(mWindow, mRendererFlags); - SDLImageHelper::setRenderer(mRenderer); - return videoInfo(); -} - -void SDLGraphics::drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) restrict2 -{ - #include "render/graphics_drawImageRect.hpp" -} - -void SDLGraphics::calcImageRect(ImageVertexes *restrict const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) restrict2 -{ - #include "render/graphics_calcImageRect.hpp" -} - -#endif // USE_SDL2 diff --git a/src/render/sdl2graphics.h b/src/render/sdl2graphics.h deleted file mode 100644 index 5db1cf179..000000000 --- a/src/render/sdl2graphics.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef RENDER_SDL2GRAPHICS_H -#define RENDER_SDL2GRAPHICS_H - -#ifdef USE_SDL2 - -#include "render/graphics.h" - -#include "localconsts.h" - -class Image; -class ImageCollection; -class ImageVertexes; -class MapLayer; - -struct SDL_Surface; - -/** - * A central point of control for graphics. - */ -class SDLGraphics final : public Graphics -{ - public: - /** - * Constructor. - */ - SDLGraphics(); - - A_DELETE_COPY(SDLGraphics) - - /** - * Destructor. - */ - ~SDLGraphics(); - - void setRendererFlags(const uint32_t flags) restrict noexcept2 override - { mRendererFlags = flags; } - - #include "render/graphicsdef.hpp" - RENDER_GRAPHICSDEF_HPP - - #include "render/softwaregraphicsdef.hpp" - RENDER_SOFTWAREGRAPHICSDEF_HPP - - protected: - uint32_t mRendererFlags; - uint32_t mOldPixel; - unsigned int mOldAlpha; -}; - -#endif // USE_SDL2 -#endif // RENDER_SDL2GRAPHICS_H diff --git a/src/render/sdl2softwaregraphics.cpp b/src/render/sdl2softwaregraphics.cpp deleted file mode 100644 index 808f7c601..000000000 --- a/src/render/sdl2softwaregraphics.cpp +++ /dev/null @@ -1,1530 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifdef USE_SDL2 - -#include "render/sdl2softwaregraphics.h" - -#include "graphicsmanager.h" - -#include "render/vertexes/imagecollection.h" - -#include "resources/imagerect.h" -#include "resources/sdl2softwareimagehelper.h" - -#include "resources/image/image.h" - -#include "utils/sdlcheckutils.h" - -#include "utils/sdlpixel.h" - -#include "debug.h" - -#ifndef SDL_BIG_ENDIAN -#error missing SDL_endian.h -#endif // SDL_BYTEORDER - -#if SDL_BYTEORDER == SDL_LIL_ENDIAN -static unsigned int *cR = nullptr; -static unsigned int *cG = nullptr; -static unsigned int *cB = nullptr; -#endif // SDL_BYTEORDER == SDL_LIL_ENDIAN - -#define defRectFromArea(rect, area) \ - const SDL_Rect rect = \ - { \ - CAST_S32(area.x), \ - CAST_S32(area.y), \ - CAST_S32(area.width), \ - CAST_S32(area.height) \ - } - -SDL2SoftwareGraphics::SDL2SoftwareGraphics() : - Graphics(), - mRendererFlags(SDL_RENDERER_SOFTWARE), - mSurface(nullptr), - mOldPixel(0), - mOldAlpha(0) -{ - mOpenGL = RENDER_SOFTWARE; - mName = "Software"; -} - -SDL2SoftwareGraphics::~SDL2SoftwareGraphics() -{ -} - -void SDL2SoftwareGraphics::drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - FUNC_BLOCK("Graphics::drawRescaledImage", 1) - // Check that preconditions for blitting are met. - if (!mSurface || !image || !image->mSDLSurface) - return; - - Image *const tmpImage = image->SDLgetScaledImage( - desiredWidth, desiredHeight); - - if (!tmpImage || !tmpImage->mSDLSurface) - return; - - const ClipRect &top = mClipStack.top(); - const SDL_Rect &bounds = image->mBounds; - - SDL_Rect srcRect = - { - CAST_S16(bounds.x), - CAST_S16(bounds.y), - CAST_U16(bounds.w), - CAST_U16(bounds.h) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX + top.xOffset), - CAST_S16(dstY + top.yOffset), - 0, - 0 - }; - - SDL_BlitSurface(tmpImage->mSDLSurface, &srcRect, mSurface, &dstRect); - delete tmpImage; -} - -void SDL2SoftwareGraphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void SDL2SoftwareGraphics::drawImageInline(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - // Check that preconditions for blitting are met. - if (!mSurface || !image || !image->mSDLSurface) - return; - - const ClipRect &top = mClipStack.top(); - const SDL_Rect &bounds = image->mBounds; - - SDL_Surface *const src = image->mSDLSurface; - - int srcX = bounds.x; - int srcY = bounds.y; - dstX += top.xOffset; - dstY += top.yOffset; - - int w = bounds.w; - int h = bounds.h; - if (srcX < 0) - { - w += srcX; - dstX -= CAST_S16(srcX); - srcX = 0; - } - const int maxw = src->w - srcX; - if (maxw < w) - w = maxw; - - if (srcY < 0) - { - h += srcY; - dstY -= CAST_S16(srcY); - srcY = 0; - } - const int maxh = src->h - srcY; - if (maxh < h) - h = maxh; - - const SDL_Rect *const clip = &mSurface->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - int dx = clipX - dstX; - if (dx > 0) - { - w -= dx; - dstX += CAST_S16(dx); - srcX += dx; - } - dx = dstX + w - clipX - clip->w; - if (dx > 0) - w -= dx; - - int dy = clipY - dstY; - if (dy > 0) - { - h -= dy; - dstY += CAST_S16(dy); - srcY += dy; - } - dy = dstY + h - clipY - clip->h; - if (dy > 0) - h -= dy; - - if (w > 0 && h > 0) - { - SDL_Rect srcRect = - { - CAST_S16(srcX), - CAST_S16(srcY), - CAST_U16(w), - CAST_U16(h) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX), - CAST_S16(dstY), - CAST_U16(w), - CAST_U16(h) - }; - - SDL_LowerBlit(src, &srcRect, mSurface, &dstRect); - } -} - -void SDL2SoftwareGraphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void SDL2SoftwareGraphics::drawImageCached(const Image *restrict const image, - int x, int y) restrict2 -{ - FUNC_BLOCK("Graphics::drawImageCached", 1) - // Check that preconditions for blitting are met. - if (!mSurface || !image || !image->mSDLSurface) - return; - - const ClipRect &top = mClipStack.top(); - const SDL_Rect &bounds = image->mBounds; - - SDL_Surface *const src = image->mSDLSurface; - - int srcX = bounds.x; - int srcY = bounds.y; - x += top.xOffset; - y += top.yOffset; - - int w = bounds.w; - int h = bounds.h; - if (srcX < 0) - { - w += srcX; - x -= CAST_S16(srcX); - srcX = 0; - } - const int maxw = src->w - srcX; - if (maxw < w) - w = maxw; - - if (srcY < 0) - { - h += srcY; - y -= CAST_S16(srcY); - srcY = 0; - } - const int maxh = src->h - srcY; - if (maxh < h) - h = maxh; - - const SDL_Rect *const clip = &mSurface->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - int dx = clipX - x; - if (dx > 0) - { - w -= dx; - x += CAST_S16(dx); - srcX += dx; - } - dx = x + w - clipX - clip->w; - if (dx > 0) - w -= dx; - - int dy = clipY - y; - if (dy > 0) - { - h -= dy; - y += CAST_S16(dy); - srcY += dy; - } - dy = y + h - clipY - clip->h; - if (dy > 0) - h -= dy; - - if (w > 0 && h > 0) - { - SDL_Rect srcRect = - { - CAST_S16(srcX), - CAST_S16(srcY), - CAST_U16(w), - CAST_U16(h) - }; - - SDL_Rect dstRect = - { - CAST_S16(x), - CAST_S16(y), - CAST_U16(w), - CAST_U16(h) - }; - - SDL_LowerBlit(src, &srcRect, mSurface, &dstRect); - } -} - -void SDL2SoftwareGraphics::drawPatternCached(const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPatternCached", 1) - // Check that preconditions for blitting are met. - if (!mSurface || !image) - return; - if (!image->mSDLSurface) - return; - - const SDL_Rect &bounds = image->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const ClipRect &top = mClipStack.top(); - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - const int srcX = bounds.x; - const int srcY = bounds.y; - SDL_Surface *const src = image->mSDLSurface; - const SDL_Rect *const clip = &mSurface->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - - for (int py = 0; py < h; py += ih) - { - const int dh = (py + ih >= h) ? h - py : ih; - int dstY = py + yOffset; - int y2 = srcY; - int h2 = dh; - if (y2 < 0) - { - h2 += y2; - dstY -= CAST_S16(y2); - y2 = 0; - } - const int maxh = src->h - y2; - if (maxh < h2) - h2 = maxh; - - int dy = clipY - dstY; - if (dy > 0) - { - h2 -= dy; - dstY += CAST_S16(dy); - y2 += dy; - } - dy = dstY + h2 - clipY - clip->h; - if (dy > 0) - h2 -= dy; - - if (h2 > 0) - { - for (int px = 0; px < w; px += iw) - { - const int dw = (px + iw >= w) ? w - px : iw; - int dstX = px + xOffset; - int x2 = srcX; - int w2 = dw; - if (x2 < 0) - { - w2 += x2; - dstX -= CAST_S16(x2); - x2 = 0; - } - const int maxw = src->w - x2; - if (maxw < w2) - w2 = maxw; - - int dx = clipX - dstX; - if (dx > 0) - { - w2 -= dx; - dstX += CAST_S16(dx); - x2 += dx; - } - dx = dstX + w2 - clipX - clip->w; - if (dx > 0) - w2 -= dx; - - if (w2 > 0) - { - SDL_Rect srcRect = - { - CAST_S16(x2), - CAST_S16(y2), - CAST_U16(w2), - CAST_U16(h2) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX), - CAST_S16(dstY), - CAST_U16(w2), - CAST_U16(h2) - }; - - SDL_LowerBlit(src, &srcRect, mSurface, &dstRect); - } - -// SDL_BlitSurface(image->mSDLSurface, &srcRect, mWindow, &dstRect); - } - } - } -} - -void SDL2SoftwareGraphics::completeCache() restrict2 -{ -} - -void SDL2SoftwareGraphics::drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - drawPatternInline(image, x, y, w, h); -} - -void SDL2SoftwareGraphics::drawPatternInline(const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPattern", 1) - // Check that preconditions for blitting are met. - if (!mSurface || !image) - return; - if (!image->mSDLSurface) - return; - - const SDL_Rect &bounds = image->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const ClipRect &top = mClipStack.top(); - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - const int srcX = bounds.x; - const int srcY = bounds.y; - SDL_Surface *const src = image->mSDLSurface; - const SDL_Rect *const clip = &mSurface->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - - for (int py = 0; py < h; py += ih) - { - const int dh = (py + ih >= h) ? h - py : ih; - int dstY = py + yOffset; - int y2 = srcY; - int h2 = dh; - if (y2 < 0) - { - h2 += y2; - dstY -= CAST_S16(y2); - y2 = 0; - } - const int maxh = src->h - y2; - if (maxh < h2) - h2 = maxh; - - int dy = clipY - dstY; - if (dy > 0) - { - h2 -= dy; - dstY += CAST_S16(dy); - y2 += dy; - } - dy = dstY + h2 - clipY - clip->h; - if (dy > 0) - h2 -= dy; - - if (h2 > 0) - { - for (int px = 0; px < w; px += iw) - { - const int dw = (px + iw >= w) ? w - px : iw; - int dstX = px + xOffset; - int x2 = srcX; - int w2 = dw; - if (x2 < 0) - { - w2 += x2; - dstX -= CAST_S16(x2); - x2 = 0; - } - const int maxw = src->w - x2; - if (maxw < w2) - w2 = maxw; - - int dx = clipX - dstX; - if (dx > 0) - { - w2 -= dx; - dstX += CAST_S16(dx); - x2 += dx; - } - dx = dstX + w2 - clipX - clip->w; - if (dx > 0) - w2 -= dx; - - if (w2 > 0) - { - SDL_Rect srcRect = - { - CAST_S16(x2), - CAST_S16(y2), - CAST_U16(w2), - CAST_U16(h2) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX), - CAST_S16(dstY), - CAST_U16(w2), - CAST_U16(h2) - }; - - SDL_LowerBlit(src, &srcRect, mSurface, &dstRect); - } - -// SDL_BlitSurface(image->mSDLSurface, &srcRect, mWindow, &dstRect); - } - } - } -} - -void SDL2SoftwareGraphics::drawRescaledPattern(const Image * - restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) - restrict2 -{ - // Check that preconditions for blitting are met. - if (!mSurface || !image) - return; - if (!image->mSDLSurface) - return; - - if (scaledHeight == 0 || scaledWidth == 0) - return; - - Image *const tmpImage = image->SDLgetScaledImage( - scaledWidth, scaledHeight); - if (!tmpImage) - return; - - const SDL_Rect &bounds = tmpImage->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const ClipRect &top = mClipStack.top(); - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - const int srcX = bounds.x; - const int srcY = bounds.y; - - for (int py = 0; py < h; py += ih) // Y position on pattern plane - { - const int dh = (py + ih >= h) ? h - py : ih; - const int dstY = py + yOffset; - - for (int px = 0; px < w; px += iw) // X position on pattern plane - { - const int dw = (px + iw >= w) ? w - px : iw; - const int dstX = px + xOffset; - - SDL_Rect srcRect = - { - CAST_S16(srcX), - CAST_S16(srcY), - CAST_U16(dw), - CAST_U16(dh) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX), - CAST_S16(dstY), - 0, - 0 - }; - - SDL_BlitSurface(tmpImage->mSDLSurface, &srcRect, - mSurface, &dstRect); - } - } - - delete tmpImage; -} - -void SDL2SoftwareGraphics::calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - calcPatternInline(vert, image, x, y, w, h); -} - -void SDL2SoftwareGraphics::calcPatternInline(ImageVertexes * - restrict const vert, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - // Check that preconditions for blitting are met. - if (!vert || !mSurface || !image || !image->mSDLSurface) - return; - - const SDL_Rect &bounds = image->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const ClipRect &top = mClipStack.top(); - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - const int srcX = bounds.x; - const int srcY = bounds.y; - - for (int py = 0; py < h; py += ih) // Y position on pattern plane - { - const int dh = (py + ih >= h) ? h - py : ih; - const int dstY = py + yOffset; - - for (int px = 0; px < w; px += iw) // X position on pattern plane - { - const int dw = (px + iw >= w) ? w - px : iw; - const int dstX = px + xOffset; - - DoubleRect *const r = new DoubleRect; - SDL_Rect &srcRect = r->src; - srcRect.x = CAST_S16(srcX); - srcRect.y = CAST_S16(srcY); - srcRect.w = CAST_U16(dw); - srcRect.h = CAST_U16(dh); - SDL_Rect &dstRect = r->dst; - dstRect.x = CAST_S16(dstX); - dstRect.y = CAST_S16(dstY); - - if (SDL_FakeUpperBlit(image->mSDLSurface, &srcRect, - mSurface, &dstRect) == 1) - { - vert->sdl.push_back(r); - } - else - { - delete r; - } - } - } -} - -void SDL2SoftwareGraphics::calcPattern(ImageCollection *restrict const vertCol, - const Image *restrict const image, - const int x, - const int y, - const int w, - const int h) const restrict2 -{ - ImageVertexes *vert = nullptr; - if (vertCol->currentImage != image) - { - vert = new ImageVertexes; - vertCol->currentImage = image; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - - calcPatternInline(vert, image, x, y, w, h); -} - -void SDL2SoftwareGraphics::calcTileVertexes(ImageVertexes *restrict const vert, - const Image *restrict const image, - int x, int y) const restrict2 -{ - vert->image = image; - calcTileSDL(vert, x, y); -} - -void SDL2SoftwareGraphics::calcTileVertexesInline(ImageVertexes * - restrict const vert, - const Image * - restrict const image, - int x, int y) const restrict2 -{ - vert->image = image; - calcTileSDL(vert, x, y); -} - -void SDL2SoftwareGraphics::calcTileSDL(ImageVertexes *restrict const vert, - int x, int y) const restrict2 -{ - // Check that preconditions for blitting are met. - if (!vert || !vert->image || !vert->image->mSDLSurface) - return; - - const Image *const image = vert->image; - const ClipRect &top = mClipStack.top(); - const SDL_Rect &bounds = image->mBounds; - - DoubleRect *rect = new DoubleRect; - rect->src.x = CAST_S16(bounds.x); - rect->src.y = CAST_S16(bounds.y); - rect->src.w = CAST_U16(bounds.w); - rect->src.h = CAST_U16(bounds.h); - rect->dst.x = CAST_S16(x + top.xOffset); - rect->dst.y = CAST_S16(y + top.yOffset); - if (SDL_FakeUpperBlit(image->mSDLSurface, &rect->src, - mSurface, &rect->dst) == 1) - { - vert->sdl.push_back(rect); - } - else - { - delete rect; - } -} - -void SDL2SoftwareGraphics::calcTileCollection(ImageCollection * - restrict const vertCol, - const Image * - restrict const image, - int x, int y) restrict2 -{ - if (!vertCol) - return; - if (vertCol->currentImage != image) - { - ImageVertexes *const vert = new ImageVertexes; - vertCol->currentImage = image; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - calcTileSDL(vert, x, y); - } - else - { - calcTileSDL(vertCol->currentVert, x, y); - } -} - -void SDL2SoftwareGraphics::drawTileCollection(const ImageCollection - *restrict const vertCol) - restrict2 -{ - const ImageVertexesVector &draws = vertCol->draws; - const ImageCollectionCIter it_end = draws.end(); - for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) - { - const ImageVertexes *const vert = *it; - const Image *const img = vert->image; - const DoubleRects *const rects = &vert->sdl; - DoubleRects::const_iterator it2 = rects->begin(); - const DoubleRects::const_iterator it2_end = rects->end(); - while (it2 != it2_end) - { - SDL_LowerBlit(img->mSDLSurface, &(*it2)->src, - mSurface, &(*it2)->dst); - ++ it2; - } - } -} - -void SDL2SoftwareGraphics::drawTileVertexes(const ImageVertexes * - restrict const vert) restrict2 -{ - if (!vert) - return; - // vert and img must be != 0 - const Image *const img = vert->image; - const DoubleRects *const rects = &vert->sdl; - DoubleRects::const_iterator it = rects->begin(); - const DoubleRects::const_iterator it_end = rects->end(); - while (it != it_end) - { - SDL_LowerBlit(img->mSDLSurface, &(*it)->src, mSurface, &(*it)->dst); - ++ it; - } -} - -void SDL2SoftwareGraphics::updateScreen() restrict2 -{ - BLOCK_START("Graphics::updateScreen") - SDL_UpdateWindowSurfaceRects(mWindow, &mRect, 1); - BLOCK_END("Graphics::updateScreen") -} - -void SDL2SoftwareGraphics::calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - ImageVertexes *vert = nullptr; - Image *const image = imgRect.grid[4]; - if (!image) - return; - if (vertCol->currentImage != image) - { - vert = new ImageVertexes; - vertCol->currentImage = image; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - calcImageRect(vert, x, y, w, h, imgRect); -} - -int SDL2SoftwareGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const - src, - SDL_Rect *restrict const srcrect, - const SDL_Surface *restrict const - dst, - SDL_Rect *restrict dstrect) - const restrict2 -{ - int srcx, srcy, w, h; - - // Make sure the surfaces aren't locked - if (!src || !dst) - return -1; - - if (!srcrect || !dstrect) - return -1; - - srcx = srcrect->x; - w = srcrect->w; - if (srcx < 0) - { - w += srcx; - dstrect->x -= CAST_S16(srcx); - srcx = 0; - } - int maxw = src->w - srcx; - if (maxw < w) - w = maxw; - - srcy = srcrect->y; - h = srcrect->h; - if (srcy < 0) - { - h += srcy; - dstrect->y -= CAST_S16(srcy); - srcy = 0; - } - int maxh = src->h - srcy; - if (maxh < h) - h = maxh; - - const SDL_Rect *const clip = &dst->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - int dx = clipX - dstrect->x; - if (dx > 0) - { - w -= dx; - dstrect->x += CAST_S16(dx); - srcx += dx; - } - dx = dstrect->x + w - clipX - clip->w; - if (dx > 0) - w -= dx; - - int dy = clipY - dstrect->y; - if (dy > 0) - { - h -= dy; - dstrect->y += CAST_S16(dy); - srcy += dy; - } - dy = dstrect->y + h - clipY - clip->h; - if (dy > 0) - h -= dy; - - if (w > 0 && h > 0) - { - if (srcrect) - { - srcrect->x = CAST_S16(srcx); - srcrect->y = CAST_S16(srcy); - srcrect->w = CAST_S16(w); - srcrect->h = CAST_S16(h); - } - dstrect->w = CAST_S16(w); - dstrect->h = CAST_S16(h); - - return 1; -// return SDL_LowerBlit(src, &sr, dst, dstrect); - } - dstrect->w = dstrect->h = 0; - return 0; -} - -void SDL2SoftwareGraphics::fillRectangle(const Rect &restrict rectangle) - restrict2 -{ - FUNC_BLOCK("Graphics::fillRectangle", 1) - if (mClipStack.empty()) - return; - - const ClipRect& top = mClipStack.top(); - - Rect area = rectangle; - area.x += top.xOffset; - area.y += top.yOffset; - - if (!area.isIntersecting(top)) - return; - - if (mAlpha) - { - const int x1 = area.x > top.x ? area.x : top.x; - const int y1 = area.y > top.y ? area.y : top.y; - const int x2 = area.x + area.width < top.x + top.width ? - area.x + area.width : top.x + top.width; - const int y2 = area.y + area.height < top.y + top.height ? - area.y + area.height : top.y + top.height; - int x, y; - - SDL_LockSurface(mSurface); - - const int bpp = mSurface->format->BytesPerPixel; - const uint32_t pixel = SDL_MapRGB(mSurface->format, - CAST_U8(mColor.r), CAST_U8(mColor.g), - CAST_U8(mColor.b)); - - switch (bpp) - { - case 1: - for (y = y1; y < y2; y++) - { - uint8_t *const p = static_cast(mSurface->pixels) - + y * mSurface->pitch; - for (x = x1; x < x2; x++) - *(p + x) = CAST_U8(pixel); - } - break; - case 2: - for (y = y1; y < y2; y++) - { - uint8_t *const p0 = static_cast( - mSurface->pixels) + y * mSurface->pitch; - for (x = x1; x < x2; x++) - { - uint8_t *const p = p0 + x * 2; - *reinterpret_cast(p) = SDLAlpha16( - CAST_U16(pixel), - *reinterpret_cast(p), - CAST_U8(mColor.a), mSurface->format); - } - } - break; - case 3: - { - const int ca = 255 - mColor.a; - const int cr = mColor.r * mColor.a; - const int cg = mColor.g * mColor.a; - const int cb = mColor.b * mColor.a; - - for (y = y1; y < y2; y++) - { - uint8_t *const p0 = static_cast( - mSurface->pixels) + y * mSurface->pitch; - for (x = x1; x < x2; x++) - { - uint8_t *const p = p0 + x * 3; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - p[2] = CAST_U8((p[2] * ca + cb) >> 8); - p[1] = CAST_U8((p[1] * ca + cg) >> 8); - p[0] = CAST_U8((p[0] * ca + cr) >> 8); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - p[0] = CAST_U8((p[0] * ca + cb) >> 8); - p[1] = CAST_U8((p[1] * ca + cg) >> 8); - p[2] = CAST_U8((p[2] * ca + cr) >> 8); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - } - } - break; - } - case 4: - { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned pb = (pixel & 0xff) * mColor.a; - const unsigned pg = (pixel & 0xff00) * mColor.a; - const unsigned pr = (pixel & 0xff0000) * mColor.a; - const unsigned a1 = (255 - mColor.a); - - for (y = y1; y < y2; y++) - { - uint8_t *const p0 = static_cast( - mSurface->pixels) + y * mSurface->pitch; - for (x = x1; x < x2; x++) - { - uint8_t *p = p0 + x * 4; - uint32_t dst = *reinterpret_cast(p); - const unsigned int b = (pb + (dst & 0xff) * a1) >> 8; - const unsigned int g = (pg + (dst & 0xff00) * a1) >> 8; - const unsigned int r = (pr - + (dst & 0xff0000) * a1) >> 8; - - *reinterpret_cast(p) = ((b & 0xff) - | (g & 0xff00) | (r & 0xff0000)); - } - } -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (!cR) - { - cR = new unsigned int[0x100]; - cG = new unsigned int[0x100]; - cB = new unsigned int[0x100]; - mOldPixel = 0; - mOldAlpha = mColor.a; - } - - const SDL_PixelFormat * const format = mSurface->format; - const unsigned rMask = format->Rmask; - const unsigned gMask = format->Gmask; - const unsigned bMask = format->Bmask; -// const unsigned aMask = format->Amask; - unsigned rShift = rMask / 0xff; - unsigned gShift = gMask / 0xff; - unsigned bShift = bMask / 0xff; - if (!rShift) - rShift = 1; - if (!gShift) - gShift = 1; - if (!bShift) - bShift = 1; - if (pixel != mOldPixel || mColor.a != mOldAlpha) - { - const unsigned pb = (pixel & bMask) * mColor.a; - const unsigned pg = (pixel & gMask) * mColor.a; - const unsigned pr = (pixel & rMask) * mColor.a; - const unsigned a0 = (255 - mColor.a); - - const unsigned int a1 = a0 * bShift; - const unsigned int a2 = a0 * gShift; - const unsigned int a3 = a0 * rShift; - - for (int f = 0; f <= 0xff; f ++) - { - cB[f] = ((pb + f * a1) >> 8) & bMask; - cG[f] = ((pg + f * a2) >> 8) & gMask; - cR[f] = ((pr + f * a3) >> 8) & rMask; - } - - mOldPixel = pixel; - mOldAlpha = mColor.a; - } - - for (y = y1; y < y2; y++) - { - uint32_t *const p0 = reinterpret_cast( - static_cast(mSurface->pixels) - + y * mSurface->pitch); - for (x = x1; x < x2; x++) - { - uint32_t *const p = p0 + x; - const uint32_t dst = *p; - *p = cB[dst & bMask / bShift] - | cG[(dst & gMask) / gShift] - | cR[(dst & rMask) / rShift]; - } - } -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - break; - } - default: - break; - } - - SDL_UnlockSurface(mSurface); - } - else - { - defRectFromArea(rect, area); - const uint32_t color = SDL_MapRGBA(mSurface->format, - CAST_S8(mColor.r), - CAST_S8(mColor.g), - CAST_S8(mColor.b), - CAST_S8(mColor.a)); - SDL_FillRect(mSurface, &rect, color); - } -} - -void SDL2SoftwareGraphics::beginDraw() restrict2 -{ - pushClipArea(Rect(0, 0, mRect.w, mRect.h)); -} - -void SDL2SoftwareGraphics::endDraw() restrict2 -{ - popClipArea(); -} - -void SDL2SoftwareGraphics::pushClipArea(const Rect &restrict area) restrict2 -{ - Graphics::pushClipArea(area); - - const ClipRect &carea = mClipStack.top(); - defRectFromArea(rect, carea); - SDL_SetClipRect(mSurface, &rect); -} - -void SDL2SoftwareGraphics::popClipArea() restrict2 -{ - Graphics::popClipArea(); - - if (mClipStack.empty()) - return; - - const ClipRect &carea = mClipStack.top(); - defRectFromArea(rect, carea); - SDL_SetClipRect(mSurface, &rect); -} - -void SDL2SoftwareGraphics::drawPoint(int x, int y) restrict2 -{ - if (mClipStack.empty()) - return; - - const ClipRect& top = mClipStack.top(); - - x += top.xOffset; - y += top.yOffset; - - if (!top.isPointInRect(x, y)) - return; - - if (mAlpha) - SDLputPixelAlpha(mSurface, x, y, mColor); - else - SDLputPixel(mSurface, x, y, mColor); -} - -void SDL2SoftwareGraphics::drawHLine(int x1, int y, int x2) restrict2 -{ - if (mClipStack.empty()) - return; - - const ClipRect& top = mClipStack.top(); - - const int xOffset = top.xOffset; - x1 += xOffset; - y += top.yOffset; - x2 += xOffset; - - const int topY = top.y; - if (y < topY || y >= topY + top.height) - return; - - if (x1 > x2) - { - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - } - - const int topX = top.x; - if (topX > x1) - { - if (topX > x2) - return; - - x1 = topX; - } - - const int sumX = topX + top.width; - if (sumX <= x2) - { - if (sumX <= x1) - return; - - x2 = sumX -1; - } - - const int bpp = mSurface->format->BytesPerPixel; - - SDL_LockSurface(mSurface); - - uint8_t *p = static_cast(mSurface->pixels) - + y * mSurface->pitch + x1 * bpp; - - const uint32_t pixel = SDL_MapRGB(mSurface->format, - CAST_U8(mColor.r), - CAST_U8(mColor.g), - CAST_U8(mColor.b)); - switch (bpp) - { - case 1: - for (; x1 <= x2; ++x1) - *(p++) = CAST_U8(pixel); - break; - - case 2: - { - uint16_t* q = reinterpret_cast(p); - const uint16_t pixel1 = CAST_U16(pixel); - for (; x1 <= x2; ++x1) - *(q++) = pixel1; - break; - } - - case 3: - { - const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff); - const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff); - const uint8_t b2 = CAST_U8(pixel & 0xff); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - for (; x1 <= x2; ++x1) - { - p[0] = b0; - p[1] = b1; - p[2] = b2; - p += 3; - } -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - for (; x1 <= x2; ++x1) - { - p[0] = b2; - p[1] = b1; - p[2] = b0; - p += 3; - } -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - break; - } - - case 4: - { - uint32_t *q = reinterpret_cast(p); - if (mAlpha) - { - unsigned char a = CAST_U8(mColor.a); - unsigned char a1 = CAST_U8(255U - a); - const int b0 = (pixel & 0xff) * a; - const int g0 = (pixel & 0xff00) * a; - const int r0 = (pixel & 0xff0000) * a; - for (; x1 <= x2; ++x1) - { - const unsigned int b = (b0 + (*q & 0xff) * a1) >> 8; - const unsigned int g = (g0 + (*q & 0xff00) * a1) >> 8; - const unsigned int r = (r0 + (*q & 0xff0000) * a1) >> 8; - *q = (b & 0xff) | (g & 0xff00) | (r & 0xff0000); - - q++; - } - } - else - { - for (; x1 <= x2; ++x1) - *(q++) = pixel; - } - break; - } - default: - break; - } // end switch - - SDL_UnlockSurface(mSurface); -} - -void SDL2SoftwareGraphics::drawVLine(int x, int y1, int y2) restrict2 -{ - if (mClipStack.empty()) - return; - - const ClipRect& top = mClipStack.top(); - - const int yOffset = top.yOffset; - x += top.xOffset; - y1 += yOffset; - y2 += yOffset; - - if (x < top.x || x >= top.x + top.width) - return; - - if (y1 > y2) - { - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - } - - if (top.y > y1) - { - if (top.y > y2) - return; - - y1 = top.y; - } - - const int sumY = top.y + top.height; - if (sumY <= y2) - { - if (sumY <= y1) - return; - - y2 = sumY - 1; - } - - const int bpp = mSurface->format->BytesPerPixel; - - SDL_LockSurface(mSurface); - - uint8_t *p = static_cast(mSurface->pixels) - + y1 * mSurface->pitch + x * bpp; - - const uint32_t pixel = SDL_MapRGB(mSurface->format, - CAST_U8(mColor.r), - CAST_U8(mColor.g), - CAST_U8(mColor.b)); - - const int pitch = mSurface->pitch; - switch (bpp) - { - case 1: - for (; y1 <= y2; ++y1) - { - *p = CAST_U8(pixel); - p += pitch; - } - break; - - case 2: - for (; y1 <= y2; ++ y1) - { - *reinterpret_cast(p) - = CAST_U16(pixel); - p += pitch; - } - break; - - case 3: - { - const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff); - const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff); - const uint8_t b2 = CAST_U8(pixel & 0xff); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - for (; y1 <= y2; ++y1) - { - p[0] = b0; - p[1] = b1; - p[2] = b2; - p += pitch; - } -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - for (; y1 <= y2; ++y1) - { - p[0] = b2; - p[1] = b1; - p[2] = b0; - p += pitch; - } -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - break; - } - - case 4: - { - if (mAlpha) - { - unsigned char a = CAST_U8(mColor.a); - unsigned char a1 = CAST_U8(255U - a); - const int b0 = (pixel & 0xff) * a; - const int g0 = (pixel & 0xff00) * a; - const int r0 = (pixel & 0xff0000) * a; - for (; y1 <= y2; ++y1) - { - const unsigned int dst = *reinterpret_cast(p); - const unsigned int b = (b0 + (dst & 0xff) * a1) >> 8; - const unsigned int g = (g0 + (dst & 0xff00) * a1) >> 8; - const unsigned int r = (r0 + (dst & 0xff0000) * a1) >> 8; - *reinterpret_cast(p) = - (b & 0xff) | (g & 0xff00) | (r & 0xff0000); - - p += pitch; - } - } - else - { - for (; y1 <= y2; ++y1) - { - *reinterpret_cast(p) = pixel; - p += pitch; - } - } - break; - } - - default: - break; - } // end switch - - SDL_UnlockSurface(mSurface); -} - -void SDL2SoftwareGraphics::drawRectangle(const Rect &restrict rectangle) - restrict2 -{ - const int x1 = rectangle.x; - const int x2 = x1 + rectangle.width - 1; - const int y1 = rectangle.y; - const int y2 = y1 + rectangle.height - 1; - - drawHLine(x1, y1, x2); - drawHLine(x1, y2, x2); - - drawVLine(x1, y1, y2); - drawVLine(x2, y1, y2); -} - -void SDL2SoftwareGraphics::drawLine(int x1, int y1, - int x2, int y2) restrict2 -{ - if (x1 == x2) - { - drawVLine(x1, y1, y2); - return; - } - if (y1 == y2) - { - drawHLine(x1, y1, x2); - return; - } -} - -bool SDL2SoftwareGraphics::setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - setMainFlags(w, h, - scale, - bpp, - fs, - hwaccel, - resize, - noFrame, - allowHighDPI); - - if (!(mWindow = graphicsManager.createWindow(w, h, bpp, - getSoftwareFlags()))) - { - mRect.w = 0; - mRect.h = 0; - mSurface = nullptr; - return false; - } - - mSurface = SDL_GetWindowSurface(mWindow); - ImageHelper::dumpSurfaceFormat(mSurface); - SDL2SoftwareImageHelper::setFormat(mSurface->format); - - int w1 = 0; - int h1 = 0; - SDL_GetWindowSize(mWindow, &w1, &h1); - mRect.w = w1; - mRect.h = h1; - - mRenderer = graphicsManager.createRenderer(mWindow, mRendererFlags); - return videoInfo(); -} - -bool SDL2SoftwareGraphics::resizeScreen(const int width, - const int height) restrict2 -{ - const bool ret = Graphics::resizeScreen(width, height); - - mSurface = SDL_GetWindowSurface(mWindow); - SDL2SoftwareImageHelper::setFormat(mSurface->format); - return ret; -} - -void SDL2SoftwareGraphics::drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_drawImageRect.hpp" -} - -void SDL2SoftwareGraphics::calcImageRect(ImageVertexes *restrict const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) - restrict2 -{ - #include "render/graphics_calcImageRect.hpp" -} - -#endif // USE_SDL2 diff --git a/src/render/sdl2softwaregraphics.h b/src/render/sdl2softwaregraphics.h deleted file mode 100644 index 438b02674..000000000 --- a/src/render/sdl2softwaregraphics.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_SDL2SOFTWAREGRAPHICS_H -#define RENDER_SDL2SOFTWAREGRAPHICS_H - -#ifdef USE_SDL2 - -#include "render/graphics.h" - -#include "localconsts.h" - -class Image; -class ImageCollection; -class ImageVertexes; -class MapLayer; - -struct SDL_Surface; - -/** - * A central point of control for graphics. - */ -class SDL2SoftwareGraphics final : public Graphics -{ - public: - friend class Sdl2SoftwareScreenshotHelper; - - /** - * Constructor. - */ - SDL2SoftwareGraphics(); - - A_DELETE_COPY(SDL2SoftwareGraphics) - - /** - * Destructor. - */ - ~SDL2SoftwareGraphics(); - - void setRendererFlags(const uint32_t flags) - restrict2 noexcept2 override final - { mRendererFlags = flags; } - - #include "render/graphicsdef.hpp" - RENDER_GRAPHICSDEF_HPP - - #include "render/softwaregraphicsdef.hpp" - RENDER_SOFTWAREGRAPHICSDEF_HPP - - bool resizeScreen(const int width, - const int height) restrict2 override final; - - protected: - int SDL_FakeUpperBlit(const SDL_Surface *restrict const src, - SDL_Rect *restrict const srcrect, - const SDL_Surface *restrict const dst, - SDL_Rect *restrict dstrect) const restrict2; - - void drawHLine(int x1, int y, int x2) restrict2; - - void drawVLine(int x, int y1, int y2) restrict2; - - uint32_t mRendererFlags; - SDL_Surface *mSurface; - uint32_t mOldPixel; - unsigned int mOldAlpha; -}; - -#endif // USE_SDL2 -#endif // RENDER_SDL2SOFTWAREGRAPHICS_H diff --git a/src/render/sdlgraphics.cpp b/src/render/sdlgraphics.cpp deleted file mode 100644 index b67e23d8e..000000000 --- a/src/render/sdlgraphics.cpp +++ /dev/null @@ -1,1518 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef USE_SDL2 - -#include "render/sdlgraphics.h" - -#include "graphicsmanager.h" - -#include "utils/sdlcheckutils.h" - -#include "utils/sdlpixel.h" - -#include "render/vertexes/imagecollection.h" - -#include "resources/imagerect.h" - -#include "resources/image/image.h" - -#include "debug.h" - -#ifndef SDL_BIG_ENDIAN -#error missing SDL_endian.h -#endif // SDL_BYTEORDER - -#if SDL_BYTEORDER == SDL_LIL_ENDIAN -static unsigned int *cR = nullptr; -static unsigned int *cG = nullptr; -static unsigned int *cB = nullptr; -#endif // SDL_BYTEORDER == SDL_LIL_ENDIAN - -SDLGraphics::SDLGraphics() : - Graphics(), - mOldPixel(0), - mOldAlpha(0) -{ - mOpenGL = RENDER_SOFTWARE; - mName = "Software"; -} - -SDLGraphics::~SDLGraphics() -{ -} - -void SDLGraphics::drawRescaledImage(const Image *restrict const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) restrict2 -{ - FUNC_BLOCK("Graphics::drawRescaledImage", 1) - // Check that preconditions for blitting are met. - if (mWindow == nullptr || - image == nullptr || - image->mSDLSurface == nullptr) - { - return; - } - - Image *const tmpImage = image->SDLgetScaledImage( - desiredWidth, desiredHeight); - - if ((tmpImage == nullptr) || (tmpImage->mSDLSurface == nullptr)) - return; - - const ClipRect &top = mClipStack.top(); - const SDL_Rect &bounds = image->mBounds; - - SDL_Rect srcRect = - { - CAST_S16(bounds.x), - CAST_S16(bounds.y), - CAST_U16(bounds.w), - CAST_U16(bounds.h) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX + top.xOffset), - CAST_S16(dstY + top.yOffset), - 0, - 0 - }; - - SDL_BlitSurface(tmpImage->mSDLSurface, &srcRect, mWindow, &dstRect); - delete tmpImage; -} - -void SDLGraphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void SDLGraphics::drawImageInline(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - // Check that preconditions for blitting are met. - if (mWindow == nullptr || - image == nullptr || - image->mSDLSurface == nullptr) - { - return; - } - - const ClipRect &top = mClipStack.top(); - const SDL_Rect &bounds = image->mBounds; - - SDL_Surface *const src = image->mSDLSurface; - - int srcX = bounds.x; - int srcY = bounds.y; - dstX += top.xOffset; - dstY += top.yOffset; - - int w = bounds.w; - int h = bounds.h; - if (srcX < 0) - { - w += srcX; - dstX -= CAST_S16(srcX); - srcX = 0; - } - const int maxw = src->w - srcX; - if (maxw < w) - w = maxw; - - if (srcY < 0) - { - h += srcY; - dstY -= CAST_S16(srcY); - srcY = 0; - } - const int maxh = src->h - srcY; - if (maxh < h) - h = maxh; - - const SDL_Rect *const clip = &mWindow->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - int dx = clipX - dstX; - if (dx > 0) - { - w -= dx; - dstX += CAST_S16(dx); - srcX += dx; - } - dx = dstX + w - clipX - clip->w; - if (dx > 0) - w -= dx; - - int dy = clipY - dstY; - if (dy > 0) - { - h -= dy; - dstY += CAST_S16(dy); - srcY += dy; - } - dy = dstY + h - clipY - clip->h; - if (dy > 0) - h -= dy; - - if (w > 0 && h > 0) - { - SDL_Rect srcRect = - { - CAST_S16(srcX), - CAST_S16(srcY), - CAST_U16(w), - CAST_U16(h) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX), - CAST_S16(dstY), - CAST_U16(w), - CAST_U16(h) - }; - - SDL_LowerBlit(src, &srcRect, mWindow, &dstRect); - } -} - -void SDLGraphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - drawImageInline(image, dstX, dstY); -} - -void SDLGraphics::drawImageCached(const Image *restrict const image, - int x, int y) restrict2 -{ - FUNC_BLOCK("Graphics::drawImageCached", 1) - // Check that preconditions for blitting are met. - if (mWindow == nullptr || - image == nullptr || - image->mSDLSurface == nullptr) - { - return; - } - - const ClipRect &top = mClipStack.top(); - const SDL_Rect &bounds = image->mBounds; - - SDL_Surface *const src = image->mSDLSurface; - - int srcX = bounds.x; - int srcY = bounds.y; - x += top.xOffset; - y += top.yOffset; - - int w = bounds.w; - int h = bounds.h; - if (srcX < 0) - { - w += srcX; - x -= CAST_S16(srcX); - srcX = 0; - } - const int maxw = src->w - srcX; - if (maxw < w) - w = maxw; - - if (srcY < 0) - { - h += srcY; - y -= CAST_S16(srcY); - srcY = 0; - } - const int maxh = src->h - srcY; - if (maxh < h) - h = maxh; - - const SDL_Rect *const clip = &mWindow->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - int dx = clipX - x; - if (dx > 0) - { - w -= dx; - x += CAST_S16(dx); - srcX += dx; - } - dx = x + w - clipX - clip->w; - if (dx > 0) - w -= dx; - - int dy = clipY - y; - if (dy > 0) - { - h -= dy; - y += CAST_S16(dy); - srcY += dy; - } - dy = y + h - clipY - clip->h; - if (dy > 0) - h -= dy; - - if (w > 0 && h > 0) - { - SDL_Rect srcRect = - { - CAST_S16(srcX), - CAST_S16(srcY), - CAST_U16(w), - CAST_U16(h) - }; - - SDL_Rect dstRect = - { - CAST_S16(x), - CAST_S16(y), - CAST_U16(w), - CAST_U16(h) - }; - - SDL_LowerBlit(src, &srcRect, mWindow, &dstRect); - } -} - -void SDLGraphics::drawPatternCached(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPatternCached", 1) - // Check that preconditions for blitting are met. - if ((mWindow == nullptr) || (image == nullptr)) - return; - if (image->mSDLSurface == nullptr) - return; - - const SDL_Rect &bounds = image->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const ClipRect &top = mClipStack.top(); - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - const int srcX = bounds.x; - const int srcY = bounds.y; - SDL_Surface *const src = image->mSDLSurface; - const SDL_Rect *const clip = &mWindow->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - - for (int py = 0; py < h; py += ih) - { - const int dh = (py + ih >= h) ? h - py : ih; - int dstY = py + yOffset; - int y2 = srcY; - int h2 = dh; - if (y2 < 0) - { - h2 += y2; - dstY -= CAST_S16(y2); - y2 = 0; - } - const int maxh = src->h - y2; - if (maxh < h2) - h2 = maxh; - - int dy = clipY - dstY; - if (dy > 0) - { - h2 -= dy; - dstY += CAST_S16(dy); - y2 += dy; - } - dy = dstY + h2 - clipY - clip->h; - if (dy > 0) - h2 -= dy; - - if (h2 > 0) - { - for (int px = 0; px < w; px += iw) - { - const int dw = (px + iw >= w) ? w - px : iw; - int dstX = px + xOffset; - int x2 = srcX; - int w2 = dw; - if (x2 < 0) - { - w2 += x2; - dstX -= CAST_S16(x2); - x2 = 0; - } - const int maxw = src->w - x2; - if (maxw < w2) - w2 = maxw; - - int dx = clipX - dstX; - if (dx > 0) - { - w2 -= dx; - dstX += CAST_S16(dx); - x2 += dx; - } - dx = dstX + w2 - clipX - clip->w; - if (dx > 0) - w2 -= dx; - - if (w2 > 0) - { - SDL_Rect srcRect = - { - CAST_S16(x2), - CAST_S16(y2), - CAST_U16(w2), - CAST_U16(h2) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX), - CAST_S16(dstY), - CAST_U16(w2), - CAST_U16(h2) - }; - - SDL_LowerBlit(src, &srcRect, mWindow, &dstRect); - } - -// SDL_BlitSurface(image->mSDLSurface, &srcRect, mWindow, &dstRect); - } - } - } -} - -void SDLGraphics::completeCache() restrict2 -{ -} - -void SDLGraphics::drawPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - drawPatternInline(image, x, y, w, h); -} - -void SDLGraphics::drawPatternInline(const Image *restrict const image, - const int x, const int y, - const int w, const int h) restrict2 -{ - FUNC_BLOCK("Graphics::drawPattern", 1) - // Check that preconditions for blitting are met. - if ((mWindow == nullptr) || (image == nullptr)) - return; - if (image->mSDLSurface == nullptr) - return; - - const SDL_Rect &bounds = image->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const ClipRect &top = mClipStack.top(); - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - const int srcX = bounds.x; - const int srcY = bounds.y; - SDL_Surface *const src = image->mSDLSurface; - const SDL_Rect *const clip = &mWindow->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - - for (int py = 0; py < h; py += ih) - { - const int dh = (py + ih >= h) ? h - py : ih; - int dstY = py + yOffset; - int y2 = srcY; - int h2 = dh; - if (y2 < 0) - { - h2 += y2; - dstY -= CAST_S16(y2); - y2 = 0; - } - const int maxh = src->h - y2; - if (maxh < h2) - h2 = maxh; - - int dy = clipY - dstY; - if (dy > 0) - { - h2 -= dy; - dstY += CAST_S16(dy); - y2 += dy; - } - dy = dstY + h2 - clipY - clip->h; - if (dy > 0) - h2 -= dy; - - if (h2 > 0) - { - for (int px = 0; px < w; px += iw) - { - const int dw = (px + iw >= w) ? w - px : iw; - int dstX = px + xOffset; - int x2 = srcX; - int w2 = dw; - if (x2 < 0) - { - w2 += x2; - dstX -= CAST_S16(x2); - x2 = 0; - } - const int maxw = src->w - x2; - if (maxw < w2) - w2 = maxw; - - int dx = clipX - dstX; - if (dx > 0) - { - w2 -= dx; - dstX += CAST_S16(dx); - x2 += dx; - } - dx = dstX + w2 - clipX - clip->w; - if (dx > 0) - w2 -= dx; - - if (w2 > 0) - { - SDL_Rect srcRect = - { - CAST_S16(x2), - CAST_S16(y2), - CAST_U16(w2), - CAST_U16(h2) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX), - CAST_S16(dstY), - CAST_U16(w2), - CAST_U16(h2) - }; - - SDL_LowerBlit(src, &srcRect, mWindow, &dstRect); - } - -// SDL_BlitSurface(image->mSDLSurface, &srcRect, mWindow, &dstRect); - } - } - } -} - -void SDLGraphics::drawRescaledPattern(const Image *restrict const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) restrict2 -{ - // Check that preconditions for blitting are met. - if ((mWindow == nullptr) || (image == nullptr)) - return; - if (image->mSDLSurface == nullptr) - return; - - if (scaledHeight == 0 || scaledWidth == 0) - return; - - Image *const tmpImage = image->SDLgetScaledImage( - scaledWidth, scaledHeight); - if (tmpImage == nullptr) - return; - - const SDL_Rect &bounds = tmpImage->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const ClipRect &top = mClipStack.top(); - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - const int srcX = bounds.x; - const int srcY = bounds.y; - - for (int py = 0; py < h; py += ih) // Y position on pattern plane - { - const int dh = (py + ih >= h) ? h - py : ih; - const int dstY = py + yOffset; - - for (int px = 0; px < w; px += iw) // X position on pattern plane - { - const int dw = (px + iw >= w) ? w - px : iw; - const int dstX = px + xOffset; - - SDL_Rect srcRect = - { - CAST_S16(srcX), - CAST_S16(srcY), - CAST_U16(dw), - CAST_U16(dh) - }; - - SDL_Rect dstRect = - { - CAST_S16(dstX), - CAST_S16(dstY), - 0, - 0 - }; - - SDL_BlitSurface(tmpImage->mSDLSurface, &srcRect, - mWindow, &dstRect); - } - } - - delete tmpImage; -} - -void SDLGraphics::calcPattern(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 -{ - calcPatternInline(vert, image, x, y, w, h); -} - -void SDLGraphics::calcPatternInline(ImageVertexes *restrict const vert, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 -{ - // Check that preconditions for blitting are met. - if (vert == nullptr || - mWindow == nullptr || - image == nullptr || - image->mSDLSurface == nullptr) - { - return; - } - - const SDL_Rect &bounds = image->mBounds; - const int iw = bounds.w; - const int ih = bounds.h; - if (iw == 0 || ih == 0) - return; - - const ClipRect &top = mClipStack.top(); - const int xOffset = top.xOffset + x; - const int yOffset = top.yOffset + y; - const int srcX = bounds.x; - const int srcY = bounds.y; - - for (int py = 0; py < h; py += ih) // Y position on pattern plane - { - const int dh = (py + ih >= h) ? h - py : ih; - const int dstY = py + yOffset; - - for (int px = 0; px < w; px += iw) // X position on pattern plane - { - const int dw = (px + iw >= w) ? w - px : iw; - const int dstX = px + xOffset; - - DoubleRect *const r = new DoubleRect; - SDL_Rect &srcRect = r->src; - srcRect.x = CAST_S16(srcX); - srcRect.y = CAST_S16(srcY); - srcRect.w = CAST_U16(dw); - srcRect.h = CAST_U16(dh); - SDL_Rect &dstRect = r->dst; - dstRect.x = CAST_S16(dstX); - dstRect.y = CAST_S16(dstY); - - if (SDL_FakeUpperBlit(image->mSDLSurface, &srcRect, - mWindow, &dstRect) == 1) - { - vert->sdl.push_back(r); - } - else - { - delete r; - } - } - } -} - -void SDLGraphics::calcPattern(ImageCollection *restrict const vertCol, - const Image *restrict const image, - const int x, const int y, - const int w, const int h) const restrict2 -{ - if (vertCol == nullptr || image == nullptr) - return; - - ImageVertexes *vert = nullptr; - if (vertCol->currentImage != image) - { - vert = new ImageVertexes; - vertCol->currentImage = image; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - - calcPatternInline(vert, image, x, y, w, h); -} - -void SDLGraphics::calcTileVertexes(ImageVertexes *restrict const vert, - const Image *restrict const image, - int x, int y) const restrict2 -{ - vert->image = image; - calcTileSDL(vert, x, y); -} - -void SDLGraphics::calcTileVertexesInline(ImageVertexes *restrict const vert, - const Image *restrict const image, - int x, int y) const restrict2 -{ - vert->image = image; - calcTileSDL(vert, x, y); -} - -void SDLGraphics::calcTileSDL(ImageVertexes *restrict const vert, - int x, int y) const restrict2 -{ - // Check that preconditions for blitting are met. - if (vert == nullptr || - vert->image == nullptr || - vert->image->mSDLSurface == nullptr) - { - return; - } - - const Image *const image = vert->image; - const ClipRect &top = mClipStack.top(); - const SDL_Rect &bounds = image->mBounds; - - DoubleRect *rect = new DoubleRect; - rect->src.x = CAST_S16(bounds.x); - rect->src.y = CAST_S16(bounds.y); - rect->src.w = CAST_U16(bounds.w); - rect->src.h = CAST_U16(bounds.h); - rect->dst.x = CAST_S16(x + top.xOffset); - rect->dst.y = CAST_S16(y + top.yOffset); - if (SDL_FakeUpperBlit(image->mSDLSurface, &rect->src, - mWindow, &rect->dst) == 1) - { - vert->sdl.push_back(rect); - } - else - { - delete rect; - } -} - -void SDLGraphics::calcTileCollection(ImageCollection *restrict const vertCol, - const Image *restrict const image, - int x, int y) restrict2 -{ - if (vertCol == nullptr) - return; - if (vertCol->currentImage != image) - { - ImageVertexes *const vert = new ImageVertexes; - vertCol->currentImage = image; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - calcTileSDL(vert, x, y); - } - else - { - calcTileSDL(vertCol->currentVert, x, y); - } -} - -void SDLGraphics::drawTileCollection(const ImageCollection - *restrict const vertCol) restrict2 -{ - const ImageVertexesVector &draws = vertCol->draws; - const ImageCollectionCIter it_end = draws.end(); - for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it) - { - const ImageVertexes *const vert = *it; - const Image *const img = vert->image; - const DoubleRects *const rects = &vert->sdl; - DoubleRects::const_iterator it2 = rects->begin(); - const DoubleRects::const_iterator it2_end = rects->end(); - while (it2 != it2_end) - { - SDL_LowerBlit(img->mSDLSurface, &(*it2)->src, - mWindow, &(*it2)->dst); - ++ it2; - } - } -} - -void SDLGraphics::drawTileVertexes(const ImageVertexes * - restrict const vert) restrict2 -{ - if (vert == nullptr) - return; - // vert and img must be != 0 - const Image *const img = vert->image; - const DoubleRects *const rects = &vert->sdl; - DoubleRects::const_iterator it = rects->begin(); - const DoubleRects::const_iterator it_end = rects->end(); - while (it != it_end) - { - SDL_LowerBlit(img->mSDLSurface, &(*it)->src, mWindow, &(*it)->dst); - ++ it; - } -} - -void SDLGraphics::updateScreen() restrict2 -{ - BLOCK_START("Graphics::updateScreen") - if (mDoubleBuffer) - { - SDL_Flip(mWindow); - } - else - { - SDL_UpdateRects(mWindow, 1, &mRect); -// SDL_UpdateRect(mWindow, 0, 0, 0, 0); - } - BLOCK_END("Graphics::updateScreen") -} - -void SDLGraphics::calcWindow(ImageCollection *restrict const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) restrict2 -{ - ImageVertexes *vert = nullptr; - Image *const image = imgRect.grid[4]; - if (image == nullptr) - return; - if (vertCol->currentImage != image) - { - vert = new ImageVertexes; - vertCol->currentImage = image; - vertCol->currentVert = vert; - vert->image = image; - vertCol->draws.push_back(vert); - } - else - { - vert = vertCol->currentVert; - } - calcImageRect(vert, x, y, w, h, imgRect); -} - -int SDLGraphics::SDL_FakeUpperBlit(const SDL_Surface *restrict const src, - SDL_Rect *restrict const srcrect, - const SDL_Surface *restrict const dst, - SDL_Rect *restrict dstrect) const restrict2 -{ - int srcx, srcy, w, h; - - // Make sure the surfaces aren't locked - if ((src == nullptr) || (dst == nullptr)) - return -1; - - if ((srcrect == nullptr) || (dstrect == nullptr)) - return -1; - - srcx = srcrect->x; - w = srcrect->w; - if (srcx < 0) - { - w += srcx; - dstrect->x -= CAST_S16(srcx); - srcx = 0; - } - int maxw = src->w - srcx; - if (maxw < w) - w = maxw; - - srcy = srcrect->y; - h = srcrect->h; - if (srcy < 0) - { - h += srcy; - dstrect->y -= CAST_S16(srcy); - srcy = 0; - } - int maxh = src->h - srcy; - if (maxh < h) - h = maxh; - - const SDL_Rect *const clip = &dst->clip_rect; - const int clipX = clip->x; - const int clipY = clip->y; - int dx = clipX - dstrect->x; - if (dx > 0) - { - w -= dx; - dstrect->x += CAST_S16(dx); - srcx += dx; - } - dx = dstrect->x + w - clipX - clip->w; - if (dx > 0) - w -= dx; - - int dy = clipY - dstrect->y; - if (dy > 0) - { - h -= dy; - dstrect->y += CAST_S16(dy); - srcy += dy; - } - dy = dstrect->y + h - clipY - clip->h; - if (dy > 0) - h -= dy; - - if (w > 0 && h > 0) - { - srcrect->x = CAST_S16(srcx); - srcrect->y = CAST_S16(srcy); - srcrect->w = CAST_S16(w); - srcrect->h = CAST_S16(h); - dstrect->w = CAST_S16(w); - dstrect->h = CAST_S16(h); - - return 1; -// return SDL_LowerBlit(src, &sr, dst, dstrect); - } - dstrect->w = dstrect->h = 0; - return 0; -} - -void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2 -{ - FUNC_BLOCK("Graphics::fillRectangle", 1) - if (mClipStack.empty()) - return; - - const ClipRect &restrict top = mClipStack.top(); - - Rect area = rectangle; - area.x += top.xOffset; - area.y += top.yOffset; - - if (!area.isIntersecting(top)) - return; - - if (mAlpha) - { - const int x1 = area.x > top.x ? area.x : top.x; - const int y1 = area.y > top.y ? area.y : top.y; - const int x2 = area.x + area.width < top.x + top.width ? - area.x + area.width : top.x + top.width; - const int y2 = area.y + area.height < top.y + top.height ? - area.y + area.height : top.y + top.height; - - SDL_LockSurface(mWindow); - - const int bpp = mWindow->format->BytesPerPixel; - const uint32_t pixel = SDL_MapRGB(mWindow->format, - CAST_U8(mColor.r), CAST_U8(mColor.g), - CAST_U8(mColor.b)); - - switch (bpp) - { - case 1: - cilk_for (int y = y1; y < y2; y++) - { - uint8_t *const p = static_cast(mWindow->pixels) - + CAST_SIZE(y * mWindow->pitch); - for (int x = x1; x < x2; x++) - { - *(p + CAST_SIZE(x)) - = CAST_U8(pixel); - } - } - break; - case 2: - cilk_for (int y = y1; y < y2; y++) - { - uint8_t *const p0 = static_cast(mWindow->pixels) - + CAST_SIZE(y * mWindow->pitch); - for (int x = x1; x < x2; x++) - { - uint8_t *const p = p0 + CAST_SIZE(x * 2); - *reinterpret_cast(p) = SDLAlpha16( - CAST_U16(pixel), - *reinterpret_cast(p), - CAST_U8(mColor.a), mWindow->format); - } - } - break; - case 3: - { - const int ca = 255 - mColor.a; - const int cr = mColor.r * mColor.a; - const int cg = mColor.g * mColor.a; - const int cb = mColor.b * mColor.a; - - cilk_for (int y = y1; y < y2; y++) - { - uint8_t *const p0 = static_cast(mWindow->pixels) - + CAST_SIZE(y * mWindow->pitch); - for (int x = x1; x < x2; x++) - { - uint8_t *const p = p0 + CAST_SIZE(x * 3); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - p[2] = CAST_U8((p[2] * ca + cb) >> 8); - p[1] = CAST_U8((p[1] * ca + cg) >> 8); - p[0] = CAST_U8((p[0] * ca + cr) >> 8); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - p[0] = CAST_U8((p[0] * ca + cb) >> 8); - p[1] = CAST_U8((p[1] * ca + cg) >> 8); - p[2] = CAST_U8((p[2] * ca + cr) >> 8); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - } - } - break; - } - case 4: - { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned pb = (pixel & 0xff) * mColor.a; - const unsigned pg = (pixel & 0xff00) * mColor.a; - const unsigned pr = (pixel & 0xff0000) * mColor.a; - const unsigned a1 = (255 - mColor.a); - - cilk_for (int y = y1; y < y2; y++) - { - uint8_t *const p0 = static_cast(mWindow->pixels) - + y * mWindow->pitch; - for (int x = x1; x < x2; x++) - { - uint8_t *p = p0 + x * 4; - uint32_t dst = *reinterpret_cast(p); - const unsigned int b = (pb + (dst & 0xff) * a1) >> 8; - const unsigned int g = (pg + (dst & 0xff00) * a1) >> 8; - const unsigned int r = (pr - + (dst & 0xff0000) * a1) >> 8; - - *reinterpret_cast(p) = ((b & 0xff) - | (g & 0xff00) | (r & 0xff0000)); - } - } -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - if (cR == nullptr) - { - cR = new unsigned int[0x100]; - cG = new unsigned int[0x100]; - cB = new unsigned int[0x100]; - mOldPixel = 0; - mOldAlpha = mColor.a; - } - - const SDL_PixelFormat * const format = mWindow->format; - const unsigned rMask = format->Rmask; - const unsigned gMask = format->Gmask; - const unsigned bMask = format->Bmask; -// const unsigned aMask = format->Amask; - unsigned rShift = rMask / 0xff; - unsigned gShift = gMask / 0xff; - unsigned bShift = bMask / 0xff; - if (rShift == 0u) - rShift = 1; - if (gShift == 0u) - gShift = 1; - if (bShift == 0u) - bShift = 1; - if (pixel != mOldPixel || mColor.a != mOldAlpha) - { - const unsigned pb = (pixel & bMask) * mColor.a; - const unsigned pg = (pixel & gMask) * mColor.a; - const unsigned pr = (pixel & rMask) * mColor.a; - const unsigned a0 = 255 - mColor.a; - - const unsigned int a1 = a0 * bShift; - const unsigned int a2 = a0 * gShift; - const unsigned int a3 = a0 * rShift; - - for (int f = 0; f <= 0xff; f ++) - { - cB[f] = ((pb + f * a1) >> 8) & bMask; - cG[f] = ((pg + f * a2) >> 8) & gMask; - cR[f] = ((pr + f * a3) >> 8) & rMask; - } - - mOldPixel = pixel; - mOldAlpha = mColor.a; - } - - cilk_for (int y = y1; y < y2; y++) - { - uint32_t *const p0 = reinterpret_cast( - static_cast(mWindow->pixels) - + CAST_SIZE(y * mWindow->pitch)); - for (int x = x1; x < x2; x++) - { - uint32_t *const p = p0 + CAST_SIZE(x); - const uint32_t dst = *p; - *p = cB[dst & bMask / bShift] - | cG[(dst & gMask) / gShift] - | cR[(dst & rMask) / rShift]; - } - } -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - break; - } - default: - break; - } - - SDL_UnlockSurface(mWindow); - } - else - { - SDL_Rect rect = - { - CAST_S16(area.x), - CAST_S16(area.y), - CAST_U16(area.width), - CAST_U16(area.height) - }; - - const uint32_t color = SDL_MapRGBA(mWindow->format, - CAST_S8(mColor.r), - CAST_S8(mColor.g), - CAST_S8(mColor.b), - CAST_S8(mColor.a)); - SDL_FillRect(mWindow, &rect, color); - } -} - -void SDLGraphics::beginDraw() restrict2 -{ - pushClipArea(Rect(0, 0, mRect.w, mRect.h)); -} - -void SDLGraphics::endDraw() restrict2 -{ - popClipArea(); -} - -void SDLGraphics::pushClipArea(const Rect &restrict area) restrict2 -{ - Graphics::pushClipArea(area); - const ClipRect &restrict carea = mClipStack.top(); - const SDL_Rect rect = - { - CAST_S16(carea.x), - CAST_S16(carea.y), - CAST_U16(carea.width), - CAST_U16(carea.height) - }; - SDL_SetClipRect(mWindow, &rect); -} - -void SDLGraphics::popClipArea() restrict2 -{ - Graphics::popClipArea(); - - if (mClipStack.empty()) - return; - - const ClipRect &restrict carea = mClipStack.top(); - const SDL_Rect rect = - { - CAST_S16(carea.x), - CAST_S16(carea.y), - CAST_U16(carea.width), - CAST_U16(carea.height) - }; - - SDL_SetClipRect(mWindow, &rect); -} - -void SDLGraphics::drawPoint(int x, int y) restrict2 -{ - if (mClipStack.empty()) - return; - - const ClipRect& top = mClipStack.top(); - - x += top.xOffset; - y += top.yOffset; - - if (!top.isPointInRect(x, y)) - return; - - if (mAlpha) - SDLputPixelAlpha(mWindow, x, y, mColor); - else - SDLputPixel(mWindow, x, y, mColor); -} - -void SDLGraphics::drawHLine(int x1, int y, int x2) restrict2 -{ - if (mClipStack.empty()) - return; - - const ClipRect& top = mClipStack.top(); - - const int xOffset = top.xOffset; - x1 += xOffset; - y += top.yOffset; - x2 += xOffset; - - const int topY = top.y; - if (y < topY || y >= topY + top.height) - return; - - if (x1 > x2) - { - x1 ^= x2; - x2 ^= x1; - x1 ^= x2; - } - - const int topX = top.x; - if (topX > x1) - { - if (topX > x2) - return; - - x1 = topX; - } - - const int sumX = topX + top.width; - if (sumX <= x2) - { - if (sumX <= x1) - return; - - x2 = sumX -1; - } - - const int bpp = mWindow->format->BytesPerPixel; - - SDL_LockSurface(mWindow); - - uint8_t *p = static_cast(mWindow->pixels) - + CAST_SIZE(y * mWindow->pitch + x1 * bpp); - - const uint32_t pixel = SDL_MapRGB(mWindow->format, - CAST_U8(mColor.r), - CAST_U8(mColor.g), - CAST_U8(mColor.b)); - switch (bpp) - { - case 1: - for (; x1 <= x2; ++x1) - *(p++) = CAST_U8(pixel); - break; - - case 2: - { - uint16_t* q = reinterpret_cast(p); - const uint16_t pixel1 = CAST_U16(pixel); - for (; x1 <= x2; ++x1) - *(q++) = pixel1; - break; - } - - case 3: - { - const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff); - const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff); - const uint8_t b2 = CAST_U8(pixel & 0xff); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - for (; x1 <= x2; ++x1) - { - p[0] = b0; - p[1] = b1; - p[2] = b2; - p += 3; - } -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - for (; x1 <= x2; ++x1) - { - p[0] = b2; - p[1] = b1; - p[2] = b0; - p += 3; - } -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - break; - } - - case 4: - { - uint32_t *q = reinterpret_cast(p); - if (mAlpha) - { - unsigned char a = CAST_U8(mColor.a); - unsigned char a1 = CAST_U8(255U - a); - const int b0 = (pixel & 0xff) * a; - const int g0 = (pixel & 0xff00) * a; - const int r0 = (pixel & 0xff0000) * a; - for (; x1 <= x2; ++x1) - { - const unsigned int b = (b0 + (*q & 0xff) * a1) >> 8; - const unsigned int g = (g0 + (*q & 0xff00) * a1) >> 8; - const unsigned int r = (r0 + (*q & 0xff0000) * a1) >> 8; - *q = (b & 0xff) | (g & 0xff00) | (r & 0xff0000); - - q++; - } - } - else - { - for (; x1 <= x2; ++x1) - *(q++) = pixel; - } - break; - } - default: - break; - } // end switch - - SDL_UnlockSurface(mWindow); -} - -void SDLGraphics::drawVLine(int x, int y1, int y2) restrict2 -{ - if (mClipStack.empty()) - return; - - const ClipRect &restrict top = mClipStack.top(); - - const int yOffset = top.yOffset; - x += top.xOffset; - y1 += yOffset; - y2 += yOffset; - - if (x < top.x || x >= top.x + top.width) - return; - - if (y1 > y2) - { - y1 ^= y2; - y2 ^= y1; - y1 ^= y2; - } - - if (top.y > y1) - { - if (top.y > y2) - return; - - y1 = top.y; - } - - const int sumY = top.y + top.height; - if (sumY <= y2) - { - if (sumY <= y1) - return; - - y2 = sumY - 1; - } - - const int bpp = mWindow->format->BytesPerPixel; - - SDL_LockSurface(mWindow); - - uint8_t *p = static_cast(mWindow->pixels) - + CAST_SIZE(y1 * mWindow->pitch + x * bpp); - - const uint32_t pixel = SDL_MapRGB(mWindow->format, - CAST_U8(mColor.r), - CAST_U8(mColor.g), - CAST_U8(mColor.b)); - - const int pitch = mWindow->pitch; - switch (bpp) - { - case 1: - for (; y1 <= y2; ++y1) - { - *p = CAST_U8(pixel); - p += pitch; - } - break; - - case 2: - for (; y1 <= y2; ++ y1) - { - *reinterpret_cast(p) - = CAST_U16(pixel); - p += pitch; - } - break; - - case 3: - { - const uint8_t b0 = CAST_U8((pixel >> 16) & 0xff); - const uint8_t b1 = CAST_U8((pixel >> 8) & 0xff); - const uint8_t b2 = CAST_U8(pixel & 0xff); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - for (; y1 <= y2; ++y1) - { - p[0] = b0; - p[1] = b1; - p[2] = b2; - p += pitch; - } -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - for (; y1 <= y2; ++y1) - { - p[0] = b2; - p[1] = b1; - p[2] = b0; - p += pitch; - } -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - break; - } - - case 4: - { - if (mAlpha) - { - unsigned char a = CAST_U8(mColor.a); - unsigned char a1 = CAST_U8(255U - a); - const int b0 = (pixel & 0xff) * a; - const int g0 = (pixel & 0xff00) * a; - const int r0 = (pixel & 0xff0000) * a; - for (; y1 <= y2; ++y1) - { - const unsigned int dst = *reinterpret_cast(p); - const unsigned int b = (b0 + (dst & 0xff) * a1) >> 8; - const unsigned int g = (g0 + (dst & 0xff00) * a1) >> 8; - const unsigned int r = (r0 + (dst & 0xff0000) * a1) >> 8; - *reinterpret_cast(p) = - (b & 0xff) | (g & 0xff00) | (r & 0xff0000); - - p += pitch; - } - } - else - { - for (; y1 <= y2; ++y1) - { - *reinterpret_cast(p) = pixel; - p += pitch; - } - } - break; - } - - default: - break; - } // end switch - - SDL_UnlockSurface(mWindow); -} - -void SDLGraphics::drawRectangle(const Rect &restrict rectangle) restrict2 -{ - const int x1 = rectangle.x; - const int x2 = x1 + rectangle.width - 1; - const int y1 = rectangle.y; - const int y2 = y1 + rectangle.height - 1; - - drawHLine(x1, y1, x2); - drawHLine(x1, y2, x2); - - drawVLine(x1, y1, y2); - drawVLine(x2, y1, y2); -} - -void SDLGraphics::drawLine(int x1, int y1, - int x2, int y2) restrict2 -{ - if (x1 == x2) - { - drawVLine(x1, y1, y2); - return; - } - if (y1 == y2) - { - drawHLine(x1, y1, x2); - return; - } - - // other cases not implemented -} - -bool SDLGraphics::setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame, - const bool allowHighDPI) restrict2 -{ - setMainFlags(w, h, - scale, - bpp, - fs, - hwaccel, - resize, - noFrame, - allowHighDPI); - - if ((mWindow = graphicsManager.createWindow(w, h, bpp, - getSoftwareFlags())) == nullptr) - { - mRect.w = 0; - mRect.h = 0; - return false; - } - - mRect.w = CAST_U16(mWindow->w); - mRect.h = CAST_U16(mWindow->h); - - return videoInfo(); -} - -void SDLGraphics::drawImageRect(const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) restrict2 -{ - #include "render/graphics_drawImageRect.hpp" -} - -void SDLGraphics::calcImageRect(ImageVertexes *restrict const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &restrict imgRect) restrict2 -{ - #include "render/graphics_calcImageRect.hpp" -} - -#endif // USE_SDL2 diff --git a/src/render/sdlgraphics.h b/src/render/sdlgraphics.h deleted file mode 100644 index e93c5df06..000000000 --- a/src/render/sdlgraphics.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_SDLGRAPHICS_H -#define RENDER_SDLGRAPHICS_H - -#ifdef USE_SDL2 -#include "render/sdl2graphics.h" -RENDER_SDL2GRAPHICS_H - -#else - -#include "render/graphics.h" - -#include "localconsts.h" - -/** - * A central point of control for graphics. - */ -class SDLGraphics final : public Graphics -{ - public: - /** - * Constructor. - */ - SDLGraphics(); - - A_DELETE_COPY(SDLGraphics) - - /** - * Destructor. - */ - ~SDLGraphics(); - - #include "render/graphicsdef.hpp" - RENDER_GRAPHICSDEF_HPP - - #include "render/softwaregraphicsdef.hpp" - RENDER_SOFTWAREGRAPHICSDEF_HPP - - protected: - int SDL_FakeUpperBlit(const SDL_Surface *restrict const src, - SDL_Rect *restrict const srcrect, - const SDL_Surface *restrict const dst, - SDL_Rect *restrict dstrect) const restrict2; - - void drawHLine(int x1, int y, int x2) restrict2; - - void drawVLine(int x, int y1, int y2) restrict2; - - uint32_t mOldPixel; - unsigned int mOldAlpha; -}; - -#endif // USE_SDL2 -#endif // RENDER_SDLGRAPHICS_H diff --git a/src/render/shaders/shader.cpp b/src/render/shaders/shader.cpp deleted file mode 100644 index f3cb54833..000000000 --- a/src/render/shaders/shader.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifdef USE_OPENGL - -#include "render/shaders/shader.h" - -#include "render/opengl/mgl.h" - -#include "debug.h" - -Shader::Shader(const unsigned int id) : - Resource(), - mShaderId(id) -{ -} - -Shader::~Shader() -{ - if (mShaderId != 0u) - mglDeleteShader(mShaderId); -} - -#endif // USE_OPENGL diff --git a/src/render/shaders/shader.h b/src/render/shaders/shader.h deleted file mode 100644 index f11d9d44e..000000000 --- a/src/render/shaders/shader.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_SHADERS_SHADER_H -#define RENDER_SHADERS_SHADER_H - -#ifdef USE_OPENGL - -#include "resources/resource.h" - -class Shader final : public Resource -{ - public: - explicit Shader(const unsigned int id); - - ~Shader(); - - A_DELETE_COPY(Shader) - - unsigned int getShaderId() const noexcept2 - { return mShaderId; } - - protected: - unsigned int mShaderId; -}; - -#endif // USE_OPENGL -#endif // RENDER_SHADERS_SHADER_H diff --git a/src/render/shaders/shaderprogram.cpp b/src/render/shaders/shaderprogram.cpp deleted file mode 100644 index 52cb025d7..000000000 --- a/src/render/shaders/shaderprogram.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifdef USE_OPENGL - -#include "render/shaders/shaderprogram.h" - -#include "render/opengl/mgl.h" -#ifdef __native_client__ -#include "render/opengl/naclglfunctions.h" -#endif // __native_client__ - -#include "render/shaders/shader.h" - -#include "debug.h" - -ShaderProgram::ShaderProgram(const unsigned int id, - Shader *const vertex, - Shader *const fragment) : - Resource(), - mProgramId(id), - mVertex(vertex), - mFragment(fragment) -{ -} - -ShaderProgram::~ShaderProgram() -{ - if (mProgramId != 0u) - mglDeleteProgram(mProgramId); - if (mVertex != nullptr) - mVertex->decRef(); - if (mFragment != nullptr) - mFragment->decRef(); -} - -#endif // USE_OPENGL diff --git a/src/render/shaders/shaderprogram.h b/src/render/shaders/shaderprogram.h deleted file mode 100644 index b8d8e4bc3..000000000 --- a/src/render/shaders/shaderprogram.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_SHADERS_SHADERPROGRAM_H -#define RENDER_SHADERS_SHADERPROGRAM_H - -#ifdef USE_OPENGL - -#include "resources/resource.h" - -class Shader; - -class ShaderProgram final : public Resource -{ - public: - ShaderProgram(const unsigned int id, - Shader *const vertex, - Shader *const fragment); - - ~ShaderProgram(); - - A_DELETE_COPY(ShaderProgram) - - unsigned int getProgramId() const noexcept2 - { return mProgramId; } - - protected: - unsigned int mProgramId; - Shader *mVertex; - Shader *mFragment; -}; - -#endif // USE_OPENGL -#endif // RENDER_SHADERS_SHADERPROGRAM_H diff --git a/src/render/shaders/shadersmanager.cpp b/src/render/shaders/shadersmanager.cpp deleted file mode 100644 index 8c4cd79e6..000000000 --- a/src/render/shaders/shadersmanager.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "render/shaders/shadersmanager.h" - -#ifdef USE_OPENGL - -#include "configuration.h" -#include "logger.h" - -#include "fs/virtfs/tools.h" - -#include "utils/cast.h" - -#include "render/opengl/mgl.h" -#ifdef __native_client__ -#include "render/opengl/naclglfunctions.h" -#endif // __native_client__ - -#include "render/shaders/shader.h" -#include "render/shaders/shaderprogram.h" - -#include "resources/loaders/shaderloader.h" - -#include "debug.h" - -ShadersManager shaders; - -Shader *ShadersManager::createShader(const unsigned int type, - const std::string &fileName) -{ - const std::string str = VirtFs::loadTextFileString(fileName); - const char *ptrStr = str.c_str(); - GLuint shaderId = mglCreateShader(type); - mglShaderSource(shaderId, 1, &ptrStr, nullptr); - mglCompileShader(shaderId); - - GLint isCompiled = 0; - mglGetShaderiv(shaderId, GL_COMPILE_STATUS, &isCompiled); - if (isCompiled == GL_TRUE) - return new Shader(shaderId); - GLint len = 0; - mglGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &len); - char *buf = new char[CAST_SIZE(len) + 1]; - mglGetShaderInfoLog(shaderId, len, &len, buf); - buf[len] = 0; - logger->log("Shader '%s' compilation error: %s", fileName.c_str(), buf); - delete [] buf; - mglDeleteShader(shaderId); - return nullptr; -} - -ShaderProgram *ShadersManager::createProgram(const std::string &vertex, - const std::string &fragment, - const bool isNewShader) -{ - Shader *const vertexShader = static_cast( - Loader::getShader(GL_VERTEX_SHADER, vertex)); - if (vertexShader == nullptr) - return nullptr; - - Shader *const fragmentShader = static_cast( - Loader::getShader(GL_FRAGMENT_SHADER, fragment)); - - if (fragmentShader == nullptr) - { - vertexShader->decRef(); - return nullptr; - } - - GLuint programId = mglCreateProgram(); - if (programId == 0u) - { - vertexShader->decRef(); - fragmentShader->decRef(); - return nullptr; - } - - mglAttachShader(programId, vertexShader->getShaderId()); - mglAttachShader(programId, fragmentShader->getShaderId()); - if (isNewShader) - mglBindFragDataLocation(programId, 0, "outColor"); - else - mglBindAttribLocation(programId, 0, "position"); - mglLinkProgram(programId); - GLint isLinked = 0; - mglGetProgramiv(programId, GL_LINK_STATUS, &isLinked); - if (isLinked == GL_TRUE) - { - mglValidateProgram(programId); - GLint isValidated = 0; - mglGetProgramiv(programId, GL_VALIDATE_STATUS, &isValidated); - if (isValidated == GL_TRUE) - return new ShaderProgram(programId, vertexShader, fragmentShader); - mglDeleteProgram(programId); - return nullptr; - } - - GLint len = 0; - mglGetProgramiv(programId, GL_INFO_LOG_LENGTH, &len); - char *buf = new char[CAST_SIZE(len) + 1]; - mglGetProgramInfoLog(programId, len, &len, buf); - buf[len] = 0; - logger->log("Program '%s, %s' compilation error: %s", - vertexShader->mIdPath.c_str(), - fragmentShader->mIdPath.c_str(), - buf); - delete [] buf; - mglDeleteProgram(programId); - return nullptr; -} - -ShaderProgram *ShadersManager::getSimpleProgram() -{ - const std::string dir = paths.getStringValue("shaders"); - return createProgram(dir + paths.getStringValue("simpleVertexShader"), - dir + paths.getStringValue("simpleFragmentShader"), - true); -} - -ShaderProgram *ShadersManager::getGles2Program() -{ - const std::string dir = paths.getStringValue("shaders"); - return createProgram(dir + paths.getStringValue("gles2VertexShader"), - dir + paths.getStringValue("gles2FragmentShader"), - false); -} - -#endif // USE_OPENGL diff --git a/src/render/shaders/shadersmanager.h b/src/render/shaders/shadersmanager.h deleted file mode 100644 index 8e45290c4..000000000 --- a/src/render/shaders/shadersmanager.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_SHADERS_SHADERSMANAGER_H -#define RENDER_SHADERS_SHADERSMANAGER_H - -#ifdef USE_OPENGL - -#include - -#include "localconsts.h" - -class Shader; -class ShaderProgram; - -class ShadersManager final -{ - public: - ShadersManager() - { } - - A_DELETE_COPY(ShadersManager) - - Shader *createShader(const unsigned int type, - const std::string &fileName) A_WARN_UNUSED; - - ShaderProgram *createProgram(const std::string &vertex, - const std::string &fragment, - const bool isNewShader) - A_WARN_UNUSED; - - ShaderProgram *getSimpleProgram(); - - ShaderProgram *getGles2Program(); -}; - -extern ShadersManager shaders; - -#endif // USE_OPENGL -#endif // RENDER_SHADERS_SHADERSMANAGER_H diff --git a/src/render/softwaregraphicsdef.hpp b/src/render/softwaregraphicsdef.hpp deleted file mode 100644 index b630a0657..000000000 --- a/src/render/softwaregraphicsdef.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define RENDER_SOFTWAREGRAPHICSDEF_HPP - -public: - void calcTileSDL(ImageVertexes *restrict const vert, - int x, int y) const restrict2 override final; diff --git a/src/render/surfacegraphics.cpp b/src/render/surfacegraphics.cpp deleted file mode 100644 index 52d0db57f..000000000 --- a/src/render/surfacegraphics.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "render/surfacegraphics.h" - -#ifndef USE_SDL2 -#include "resources/surfaceimagehelper.h" -#endif // USE_SDL2 - -#include "resources/image/image.h" - -#include "debug.h" - -SurfaceGraphics::SurfaceGraphics() : - Graphics(), - mBlitMode(BlitMode::BLIT_NORMAL), - mTarget(nullptr) -{ - mOpenGL = RENDER_SOFTWARE; - mName = "Surface"; -} - -SurfaceGraphics::~SurfaceGraphics() -{ -} - -void SurfaceGraphics::drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - // Check that preconditions for blitting are met. - if (mTarget == nullptr || - image == nullptr || - image->mSDLSurface == nullptr) - { - return; - } - - const SDL_Rect &imageRect = image->mBounds; - SDL_Rect dstRect; - SDL_Rect srcRect; - dstRect.x = CAST_S16(dstX); - dstRect.y = CAST_S16(dstY); - srcRect.x = CAST_S16(imageRect.x); - srcRect.y = CAST_S16(imageRect.y); - srcRect.w = CAST_U16(imageRect.w); - srcRect.h = CAST_U16(imageRect.h); - -#ifdef USE_SDL2 - SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect); -#else // USE_SDL2 - - if (mBlitMode == BlitMode::BLIT_NORMAL) - { - SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect); - } - else - { - SurfaceImageHelper::combineSurface(image->mSDLSurface, - &srcRect, mTarget, &dstRect); - } -#endif // USE_SDL2 -} - -void SurfaceGraphics::copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 -{ - FUNC_BLOCK("Graphics::drawImage", 1) - // Check that preconditions for blitting are met. - if (mTarget == nullptr || - image == nullptr || - image->mSDLSurface == nullptr) - { - return; - } - - const SDL_Rect &imageRect = image->mBounds; - SDL_Rect dstRect; - SDL_Rect srcRect; - dstRect.x = CAST_S16(dstX); - dstRect.y = CAST_S16(dstY); - srcRect.x = CAST_S16(imageRect.x); - srcRect.y = CAST_S16(imageRect.y); - srcRect.w = CAST_U16(imageRect.w); - srcRect.h = CAST_U16(imageRect.h); - -#ifdef USE_SDL2 - // probably need change some flags - SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect); -#else // USE_SDL2 - - SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect); -#endif // USE_SDL2 -} - -void SurfaceGraphics::drawImageCached(const Image *restrict const image, - int x, int y) restrict2 -{ - FUNC_BLOCK("Graphics::drawImageCached", 1) - // Check that preconditions for blitting are met. - if (mTarget == nullptr || - image == nullptr || - image->mSDLSurface == nullptr) - { - return; - } - - const SDL_Rect &rect = image->mBounds; - - SDL_Rect dstRect; - SDL_Rect srcRect; - dstRect.x = CAST_S16(x); - dstRect.y = CAST_S16(y); - srcRect.x = CAST_S16(rect.x); - srcRect.y = CAST_S16(rect.y); - srcRect.w = CAST_U16(rect.w); - srcRect.h = CAST_U16(rect.h); - -#ifdef USE_SDL2 - SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect); -#else // USE_SDL2 - - if (mBlitMode == BlitMode::BLIT_NORMAL) - { - SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect); - } - else - { - SurfaceImageHelper::combineSurface(image->mSDLSurface, &srcRect, - mTarget, &dstRect); - } -#endif // USE_SDL2 -} - -void SurfaceGraphics::completeCache() restrict2 -{ -} diff --git a/src/render/surfacegraphics.h b/src/render/surfacegraphics.h deleted file mode 100644 index 2e46c9f1e..000000000 --- a/src/render/surfacegraphics.h +++ /dev/null @@ -1,218 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_SURFACEGRAPHICS_H -#define RENDER_SURFACEGRAPHICS_H - -#include "enums/render/blitmode.h" - -#include "render/graphics.h" - -#include "localconsts.h" - -class Image; -class ImageCollection; -class ImageVertexes; - -/** - * A central point of control for graphics. - */ -class SurfaceGraphics final : public Graphics -{ - public: - SurfaceGraphics(); - - A_DELETE_COPY(SurfaceGraphics) - - ~SurfaceGraphics(); - - void setTarget(SDL_Surface *restrict const target) restrict2 noexcept2 - { mTarget = target; } - - SDL_Surface *getTarget() const restrict2 noexcept2 - { return mTarget; } - - void beginDraw() restrict2 override final - { } - - void endDraw() restrict2 override final - { } - - void pushClipArea(const Rect &restrict rect A_UNUSED) - restrict2 override final - { } - - void popClipArea() restrict2 override final - { } - - void drawRescaledImage(const Image *restrict const image A_UNUSED, - int dstX A_UNUSED, int dstY A_UNUSED, - const int desiredWidth A_UNUSED, - const int desiredHeight A_UNUSED) - restrict2 override final - { } - - void drawPattern(const Image *restrict const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) restrict2 override final - { } - - void drawRescaledPattern(const Image *const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED, - const int scaledWidth A_UNUSED, - const int scaledHeight A_UNUSED) - override final - { } - - void calcPattern(ImageVertexes *restrict const vert A_UNUSED, - const Image *restrict const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) const restrict2 override final - { } - - void calcPattern(ImageCollection *restrict const vert A_UNUSED, - const Image *restrict const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) const restrict2 override final - { } - - void calcTileVertexes(ImageVertexes *restrict const vert A_UNUSED, - const Image *restrict const image A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) const restrict2 override final - A_NONNULL(2, 3) - { } - - void calcTileSDL(ImageVertexes *restrict const vert A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) const restrict2 override final - { } - - void calcTileCollection(ImageCollection *restrict const - vertCol A_UNUSED, - const Image *restrict const image A_UNUSED, - int x A_UNUSED, - int y A_UNUSED) restrict2 override final - { } - - void drawTileVertexes(const ImageVertexes *restrict const - vert A_UNUSED) restrict2 override final - { } - - void drawTileCollection(const ImageCollection *restrict const - vertCol A_UNUSED) - restrict2 override final A_NONNULL(2) - { } - - void updateScreen() override final - { } - - void drawNet(const int x1 A_UNUSED, - const int y1 A_UNUSED, - const int x2 A_UNUSED, - const int y2 A_UNUSED, - const int width A_UNUSED, - const int height A_UNUSED) restrict2 override final - { } - - void calcWindow(ImageCollection *restrict const vertCol A_UNUSED, - const int x A_UNUSED, const int y A_UNUSED, - const int w A_UNUSED, const int h A_UNUSED, - const ImageRect &restrict imgRect A_UNUSED) - restrict2 override final A_NONNULL(2) - { } - - void setBlitMode(const BlitModeT mode) restrict2 noexcept2 - { mBlitMode = mode; } - - BlitModeT getBlitMode() const restrict2 noexcept2 A_WARN_UNUSED - { return mBlitMode; } - - void fillRectangle(const Rect &restrict rect A_UNUSED) - restrict2 override final - { } - - void drawRectangle(const Rect &restrict rect A_UNUSED) - restrict2 override final - { } - - void drawPoint(int x A_UNUSED, int y A_UNUSED) restrict2 override final - { } - - void drawLine(int x1 A_UNUSED, int y1 A_UNUSED, - int x2 A_UNUSED, int y2 A_UNUSED) - restrict2 override final - { } - - bool setVideoMode(const int w A_UNUSED, const int h A_UNUSED, - const int scale A_UNUSED, - const int bpp A_UNUSED, - const bool fs A_UNUSED, const bool hwaccel A_UNUSED, - const bool resize A_UNUSED, - const bool noFrame A_UNUSED, - const bool allowHighDPI A_UNUSED) - restrict2 override final - { return false; } - - void drawImage(const Image *restrict const image, - int dstX, int dstY) restrict2 override final; - - void copyImage(const Image *restrict const image, - int dstX, int dstY) restrict2 override final; - - void drawImageCached(const Image *restrict const image, - int x, int y) restrict2 override final; - - void drawPatternCached(const Image *restrict const image A_UNUSED, - const int x A_UNUSED, - const int y A_UNUSED, - const int w A_UNUSED, - const int h A_UNUSED) restrict2 override final - { } - - void completeCache() restrict2 override final; - - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(const int x A_UNUSED, const int y A_UNUSED, - const int w A_UNUSED, const int h A_UNUSED, - const ImageRect &restrict imgRect A_UNUSED) - restrict2 override final - { } - - protected: - BlitModeT mBlitMode; - SDL_Surface *mTarget; -}; - -#endif // RENDER_SURFACEGRAPHICS_H diff --git a/src/render/vertexes/imagecollection.cpp b/src/render/vertexes/imagecollection.cpp deleted file mode 100644 index 2c626e03d..000000000 --- a/src/render/vertexes/imagecollection.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "render/vertexes/imagecollection.h" - -#include "utils/dtor.h" - -#include "debug.h" - -ImageCollection::ImageCollection() : -#ifdef USE_OPENGL - currentGLImage(0), -#endif // USE_OPENGL - currentImage(nullptr), - currentVert(nullptr), - draws() -{ -} - -ImageCollection::~ImageCollection() -{ - clear(); -} - -void ImageCollection::clear() restrict2 -{ -#ifdef USE_OPENGL - currentGLImage = 0; -#endif // USE_OPENGL - currentImage = nullptr; - currentVert = nullptr; - - delete_all(draws); - draws.clear(); -} diff --git a/src/render/vertexes/imagecollection.h b/src/render/vertexes/imagecollection.h deleted file mode 100644 index c5b9dfe55..000000000 --- a/src/render/vertexes/imagecollection.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_VERTEXES_IMAGECOLLECTION_H -#define RENDER_VERTEXES_IMAGECOLLECTION_H - -#include "render/vertexes/imagevertexes.h" - -#include "localconsts.h" - -class Image; - -class ImageCollection final -{ - public: - ImageCollection(); - - A_DELETE_COPY(ImageCollection) - - ~ImageCollection(); - - void clear() restrict2; - -#ifdef USE_OPENGL - GLuint currentGLImage; -#endif // USE_OPENGL - - const Image *restrict currentImage; - - ImageVertexes *restrict currentVert; - - ImageVertexesVector draws; -}; - -#endif // RENDER_VERTEXES_IMAGECOLLECTION_H diff --git a/src/render/vertexes/imagevertexes.cpp b/src/render/vertexes/imagevertexes.cpp deleted file mode 100644 index 3aff57636..000000000 --- a/src/render/vertexes/imagevertexes.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "render/vertexes/imagevertexes.h" - -#include "utils/dtor.h" - -#include "debug.h" - -ImageVertexes::ImageVertexes() : - image(nullptr), -#ifdef USE_OPENGL - ogl(), -#endif // USE_OPENGL - sdl() -{ - sdl.reserve(30); -} - -ImageVertexes::~ImageVertexes() -{ - delete_all(sdl); - sdl.clear(); -} diff --git a/src/render/vertexes/imagevertexes.h b/src/render/vertexes/imagevertexes.h deleted file mode 100644 index 01390c450..000000000 --- a/src/render/vertexes/imagevertexes.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_VERTEXES_IMAGEVERTEXES_H -#define RENDER_VERTEXES_IMAGEVERTEXES_H - -#include "resources/rect/doublerect.h" - -#ifdef USE_OPENGL -#include "render/vertexes/openglgraphicsvertexes.h" -#else // USE_OPENGL -#include "utils/vector.h" -#endif // USE_OPENGL - -#include "localconsts.h" - -class Image; - -typedef STD_VECTOR DoubleRects; - -class ImageVertexes final -{ - public: - ImageVertexes(); - - A_DELETE_COPY(ImageVertexes) - - ~ImageVertexes(); - - const Image *restrict image; -#ifdef USE_OPENGL - OpenGLGraphicsVertexes ogl; -#endif // USE_OPENGL - - DoubleRects sdl; -}; - -typedef STD_VECTOR ImageVertexesVector; -typedef ImageVertexesVector::iterator ImageCollectionIter; -typedef ImageVertexesVector::const_iterator ImageCollectionCIter; - -#endif // RENDER_VERTEXES_IMAGEVERTEXES_H diff --git a/src/render/vertexes/openglgraphicsvertexes.cpp b/src/render/vertexes/openglgraphicsvertexes.cpp deleted file mode 100644 index a65f0e2b9..000000000 --- a/src/render/vertexes/openglgraphicsvertexes.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifdef USE_OPENGL - -#include "render/vertexes/openglgraphicsvertexes.h" - -#include "render/graphics.h" - -#include "debug.h" - -unsigned int vertexBufSize = 500; - -OpenGLGraphicsVertexes::OpenGLGraphicsVertexes() : - ptr(0), - mFloatTexArray(nullptr), - mIntTexArray(nullptr), - mIntVertArray(nullptr), - mShortVertArray(nullptr), - mVp(), - mFloatTexPool(), - mIntVertPool(), - mShortVertPool(), - mIntTexPool(), - mVbo() -{ - mFloatTexPool.reserve(30); - mIntVertPool.reserve(30); - mShortVertPool.reserve(30); - mIntTexPool.reserve(30); - mVp.reserve(30); - mVbo.reserve(30); -} - -OpenGLGraphicsVertexes::~OpenGLGraphicsVertexes() -{ - clear(); -} - -void OpenGLGraphicsVertexes::clear() restrict2 -{ - for (STD_VECTOR::iterator it = mFloatTexPool.begin(); - it != mFloatTexPool.end(); ++ it) - { - delete [] (*it); - } - mFloatTexPool.clear(); - - for (STD_VECTOR::iterator it = mIntVertPool.begin(); - it != mIntVertPool.end(); ++ it) - { - delete [] (*it); - } - mIntVertPool.clear(); - - for (STD_VECTOR::iterator it = mShortVertPool.begin(); - it != mShortVertPool.end(); ++ it) - { - delete [] (*it); - } - mShortVertPool.clear(); - - for (STD_VECTOR::iterator it = mIntTexPool.begin(); - it != mIntTexPool.end(); ++ it) - { - delete [] (*it); - } - mIntTexPool.clear(); - - const int sz = CAST_S32(mVbo.size()); - if (sz > 0) - { - mainGraphics->removeArray(sz, &mVbo[0]); - mVbo.clear(); - } - - mVp.clear(); - if (ptr != 0) - { - ptr = 0; - delete []mFloatTexArray; - mFloatTexArray = nullptr; - delete []mIntTexArray; - mIntTexArray = nullptr; - delete []mIntVertArray; - mIntVertArray = nullptr; - delete []mShortVertArray; - mShortVertArray = nullptr; - } -} - -void OpenGLGraphicsVertexes::init() restrict2 -{ - clear(); -} - -GLfloat *OpenGLGraphicsVertexes::switchFloatTexArray() restrict2 -{ - mFloatTexArray = new GLfloat[CAST_SIZE(vertexBufSize * 4 + 30)]; - mFloatTexPool.push_back(mFloatTexArray); - return mFloatTexArray; -} - -GLint *OpenGLGraphicsVertexes::switchIntVertArray() restrict2 -{ - mIntVertArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)]; - mIntVertPool.push_back(mIntVertArray); - return mIntVertArray; -} - -GLshort *OpenGLGraphicsVertexes::switchShortVertArray() restrict2 -{ - mShortVertArray = new GLshort[CAST_SIZE(vertexBufSize * 4 + 30)]; - mShortVertPool.push_back(mShortVertArray); - return mShortVertArray; -} - -GLint *OpenGLGraphicsVertexes::switchIntTexArray() restrict2 -{ - mIntTexArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)]; - mIntTexPool.push_back(mIntTexArray); - return mIntTexArray; -} - -void OpenGLGraphicsVertexes::switchVp(const int n) restrict2 -{ - mVp.push_back(n); -} - -int OpenGLGraphicsVertexes::continueVp() restrict2 -{ - if (mVp.empty()) - { - return 0; - } - else - { - const int val = mVp.back(); - mVp.pop_back(); - return val; - } -} - -void OpenGLGraphicsVertexes::updateVp(const int n) restrict2 -{ - if (!mVp.empty()) - mVp.pop_back(); - mVp.push_back(n); -} - -GLfloat *OpenGLGraphicsVertexes::continueFloatTexArray() restrict2 -{ - if (mFloatTexPool.empty()) - { - mFloatTexArray = new GLfloat[CAST_SIZE( - vertexBufSize * 4 + 30)]; - mFloatTexPool.push_back(mFloatTexArray); - } - else - { - mFloatTexArray = mFloatTexPool.back(); - } - return mFloatTexArray; -} - -GLint *OpenGLGraphicsVertexes::continueIntVertArray() restrict2 -{ - if (mIntVertPool.empty()) - { - mIntVertArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)]; - mIntVertPool.push_back(mIntVertArray); - } - else - { - mIntVertArray = mIntVertPool.back(); - } - return mIntVertArray; -} - -GLshort *OpenGLGraphicsVertexes::continueShortVertArray() restrict2 -{ - if (mShortVertPool.empty()) - { - mShortVertArray = new GLshort[CAST_SIZE( - vertexBufSize * 4 + 30)]; - mShortVertPool.push_back(mShortVertArray); - } - else - { - mShortVertArray = mShortVertPool.back(); - } - return mShortVertArray; -} - -GLint *OpenGLGraphicsVertexes::continueIntTexArray() restrict2 -{ - if (mIntTexPool.empty()) - { - mIntTexArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)]; - mIntTexPool.push_back(mIntTexArray); - } - else - { - mIntTexArray = mIntTexPool.back(); - } - return mIntTexArray; -} -#endif // USE_OPENGL diff --git a/src/render/vertexes/openglgraphicsvertexes.h b/src/render/vertexes/openglgraphicsvertexes.h deleted file mode 100644 index 023abf139..000000000 --- a/src/render/vertexes/openglgraphicsvertexes.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RENDER_VERTEXES_OPENGLGRAPHICSVERTEXES_H -#define RENDER_VERTEXES_OPENGLGRAPHICSVERTEXES_H - -#ifdef USE_OPENGL - -#include "localconsts.h" - -#ifdef ANDROID -#include -#else // ANDROID -#ifndef USE_SDL2 -#define GL_GLEXT_PROTOTYPES 1 -#endif // USE_SDL2 -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#include -PRAGMA48(GCC diagnostic pop) -#endif // ANDROID - -#include "utils/vector.h" - -class OpenGLGraphicsVertexes final -{ - public: - OpenGLGraphicsVertexes(); - - A_DELETE_COPY(OpenGLGraphicsVertexes) - - ~OpenGLGraphicsVertexes(); - - GLfloat *switchFloatTexArray() restrict2; - - GLint *switchIntVertArray() restrict2; - - GLint *switchIntTexArray() restrict2; - - GLshort *switchShortVertArray() restrict2; - - STD_VECTOR *getFloatTexPool() restrict2 A_WARN_UNUSED - { return &mFloatTexPool; } - - STD_VECTOR *getIntVertPool() restrict2 A_WARN_UNUSED - { return &mIntVertPool; } - - STD_VECTOR *getShortVertPool() restrict2 A_WARN_UNUSED - { return &mShortVertPool; } - - STD_VECTOR *getIntTexPool() restrict2 A_WARN_UNUSED - { return &mIntTexPool; } - - void switchVp(const int n) restrict2; - - GLfloat *continueFloatTexArray() restrict2 RETURNS_NONNULL; - - GLint *continueIntVertArray() restrict2 RETURNS_NONNULL; - - GLshort *continueShortVertArray() restrict2 RETURNS_NONNULL; - - GLint *continueIntTexArray() restrict2 RETURNS_NONNULL; - - int continueVp() restrict2; - - void updateVp(const int n) restrict2; - - STD_VECTOR *getVp() restrict2 A_WARN_UNUSED - { return &mVp; } - - void init() restrict2; - - void clear() restrict2; - - int ptr; - - GLfloat *mFloatTexArray; - GLint *mIntTexArray; - GLint *mIntVertArray; - GLshort *mShortVertArray; - STD_VECTOR mVp; - STD_VECTOR mFloatTexPool; - STD_VECTOR mIntVertPool; - STD_VECTOR mShortVertPool; - STD_VECTOR mIntTexPool; - STD_VECTOR mVbo; -}; - -extern unsigned int vertexBufSize; -#endif // USE_OPENGL - -#endif // RENDER_VERTEXES_OPENGLGRAPHICSVERTEXES_H -- cgit v1.2.3-60-g2f50