From 1fdfce5957e358004d5acb267fb1eb09579fe0ed Mon Sep 17 00:00:00 2001 From: David Athay Date: Sat, 17 Jul 2010 20:59:39 -0500 Subject: Fixed config directory, updated project file. --- src/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index ac10112e..b63550e6 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1035,13 +1035,13 @@ void Client::initHomeDir() if (mConfigDir.empty()){ #ifdef __APPLE__ - mConfigDir = mLocalDataDir; + mConfigDir = mLocalDataDir + "/" + branding.getValue("appShort", "mana"); #elif defined WIN32 mConfigDir = getSpecialFolderLocation(CSIDL_APPDATA); if (mConfigDir.empty()) mConfigDir = mLocalDataDir; else - mConfigDir += "/mana/" + branding.getValue("appName", "Mana"); + mConfigDir += "/mana/" + branding.getValue("appShort", "Mana"); #else mConfigDir = std::string(PHYSFS_getUserDir()) + "/.config/mana/" + branding.getValue("appShort", "mana"); -- cgit v1.2.3-70-g09d2 From 54bedfb27c92f8aba1f5721343cb3ee7cbfd5053 Mon Sep 17 00:00:00 2001 From: koom Date: Mon, 12 Jul 2010 23:40:32 +0200 Subject: added xmessage for linux case of error Reviewed-by: Bertram. --- src/log.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/log.cpp b/src/log.cpp index ba1610fd..d5a30bb4 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -123,6 +123,10 @@ void Logger::error(const std::string &error_text) StandardAlert(kAlertStopAlert, "\pError", (ConstStr255Param) msg, NULL, NULL); +#elif defined __linux__ + std::cerr << "Error: " << error_text << std::endl; + std::string msg="xmessage \"" + error_text + "\""; + system(msg.c_str()); #else std::cerr << "Error: " << error_text << std::endl; #endif -- cgit v1.2.3-70-g09d2 From d1d730b3e64cd7d0e064b8f3138604df2ad121c4 Mon Sep 17 00:00:00 2001 From: kook Date: Mon, 19 Jul 2010 21:00:04 +0200 Subject: Finished to add the xmessage support thanks to Kook. Reviewed-by: Bertram --- src/log.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/log.cpp b/src/log.cpp index d5a30bb4..435b2da0 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -30,6 +30,8 @@ #include #elif __APPLE__ #include +#elif __linux__ || __linux +#include #endif #include @@ -123,7 +125,7 @@ void Logger::error(const std::string &error_text) StandardAlert(kAlertStopAlert, "\pError", (ConstStr255Param) msg, NULL, NULL); -#elif defined __linux__ +#elif defined __linux__ || __linux std::cerr << "Error: " << error_text << std::endl; std::string msg="xmessage \"" + error_text + "\""; system(msg.c_str()); -- cgit v1.2.3-70-g09d2 From 94067246b02a981e3e3b058120551beb8a830c7e Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Thu, 22 Jul 2010 22:42:54 +0200 Subject: Fixing compatibility with cmake 2.6.0 The syntax IF ((condition) OR (condition)) is not accepted by cmake prior to 2.6.4. The syntax IF (NOT (condition OR condition)) is also not accepted. The patch should address this without affecting newer versions. A newline character was also automatically added to the end of the file. --- CMakeLists.txt | 4 ++-- src/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 15a55d91..b396b8e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ ENDIF() STRING(REPLACE "." " " _VERSION ${VERSION}) SEPARATE_ARGUMENTS(_VERSION) LIST(LENGTH _VERSION _LEN) -IF(NOT (_LEN EQUAL 4 OR _LEN EQUAL 3)) +IF(NOT _LEN EQUAL 4 AND NOT _LEN EQUAL 3) MESSAGE(FATAL_ERROR "Version needs to be in the form MAJOR.MINOR.RELEASE[.BUILD]") ENDIF() @@ -70,4 +70,4 @@ IF(WIN32) SET(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/packaging/windows/setup_welcome.bmp") SET(CPACK_NSIS_URL_INFO_ABOUT "http://www.manasource.org") ENDIF() -INCLUDE(CPack) \ No newline at end of file +INCLUDE(CPack) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b15948d3..9b38b496 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,8 +32,8 @@ ENDIF() IF (CMAKE_BUILD_TYPE) STRING(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER) - IF((CMAKE_BUILD_TYPE_TOLOWER MATCHES debug) OR - (CMAKE_BUILD_TYPE_TOLOWER MATCHES relwithdebinfo)) + IF(CMAKE_BUILD_TYPE_TOLOWER MATCHES debug OR + CMAKE_BUILD_TYPE_TOLOWER MATCHES relwithdebinfo) SET(FLAGS "${FLAGS} -DDEBUG") ENDIF() ENDIF() -- cgit v1.2.3-70-g09d2 From 59143e174f946c66e2e437e32b6f6b28c506115a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 2 Aug 2010 03:13:49 +0300 Subject: Fix chat spoofing. Remove colors from nicks in public chat. Signed-off-by: Chuck Miller --- src/net/tmwa/chathandler.cpp | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 640d04c1..00d29662 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -110,7 +110,8 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) break; // Received speech from being - case SMSG_BEING_CHAT: { + case SMSG_BEING_CHAT: + { chatMsgLength = msg.readInt16() - 8; being = beingManager->findBeing(msg.readInt32()); @@ -121,24 +122,42 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) std::string::size_type pos = chatMsg.find(" : ", 0); std::string sender_name = ((pos == std::string::npos) - ? "" - : chatMsg.substr(0, pos)); + ? "" : chatMsg.substr(0, pos)); - // We use getIgnorePlayer instead of ignoringPlayer here because ignorePlayer' side - // effects are triggered right below for Being::IGNORE_SPEECH_FLOAT. - if (player_relations.checkPermissionSilently(sender_name, PlayerRelation::SPEECH_LOG)) - localChatTab->chatLog(chatMsg, BY_OTHER); + if (sender_name != being->getName() + && being->getType() == Being::PLAYER) + { + if (!being->getName().empty()) + sender_name = being->getName(); + } + else + { + chatMsg.erase(0, pos + 3); + } - chatMsg.erase(0, pos + 3); trim(chatMsg); - if (player_relations.hasPermission(sender_name, PlayerRelation::SPEECH_FLOAT)) + // We use getIgnorePlayer instead of ignoringPlayer here + // because ignorePlayer' side effects are triggered + // right below for Being::IGNORE_SPEECH_FLOAT. + if (player_relations.checkPermissionSilently(sender_name, + PlayerRelation::SPEECH_LOG) && chatWindow) + { + localChatTab->chatLog(removeColors(sender_name) + " : " + + chatMsg, BY_OTHER); + } + + if (player_relations.hasPermission(sender_name, + PlayerRelation::SPEECH_FLOAT)) + { being->setSpeech(chatMsg, SPEECH_TIME); + } break; } case SMSG_PLAYER_CHAT: - case SMSG_GM_CHAT: { + case SMSG_GM_CHAT: + { chatMsgLength = msg.readInt16() - 4; if (chatMsgLength <= 0) -- cgit v1.2.3-70-g09d2 From 4c27bfbf6ca84546e5b914b7909df14dd2966081 Mon Sep 17 00:00:00 2001 From: dweems Date: Tue, 3 Aug 2010 12:19:59 -0500 Subject: Added double click to equip unequip and use items -Double-click items in invetory to equip/unequip -Double-click items in inventory to use Signed-off-by: Jared Adams --- src/gui/widgets/itemcontainer.cpp | 40 +++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 5163fc45..7648eb24 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -255,14 +255,46 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) if (mSelectedIndex == index) { - mSelectionStatus = SEL_DESELECTING; + if(event.getClickCount() == 2) + { + if (item->isEquipment()) + { + if (item->isEquipped()) + Net::getInventoryHandler()->unequipItem(item); + else + Net::getInventoryHandler()->equipItem(item); + } + else + Net::getInventoryHandler()->useItem(item); + + } + else + { + mSelectionStatus = SEL_DESELECTING; + } } else if (item && item->getId()) { - setSelectedIndex(index); - mSelectionStatus = SEL_SELECTING; + if(event.getClickCount() == 2) + { + if (item->isEquipment()) + { + if (item->isEquipped()) + Net::getInventoryHandler()->unequipItem(item); + else + Net::getInventoryHandler()->equipItem(item); + } + else + Net::getInventoryHandler()->useItem(item); - itemShortcut->setItemSelected(item->getId()); + } + else + { + setSelectedIndex(index); + mSelectionStatus = SEL_SELECTING; + + itemShortcut->setItemSelected(item->getId()); + } if (item->isEquipment()) outfitWindow->setItemSelected(item->getId()); } -- cgit v1.2.3-70-g09d2 From 12b0ff6204dd64627a3824ba624000424551f054 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 2 Aug 2010 20:49:37 -0600 Subject: Fix enet version check Tested-by: BaseBallBoy --- src/net/manaserv/connection.cpp | 4 ++++ src/net/manaserv/network.cpp | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/net/manaserv/connection.cpp b/src/net/manaserv/connection.cpp index 98076c8a..fbd2ed22 100644 --- a/src/net/manaserv/connection.cpp +++ b/src/net/manaserv/connection.cpp @@ -60,7 +60,11 @@ bool Connection::connect(const std::string &address, short port) enetAddress.port = port; // Initiate the connection, allocating channel 0. +#ifdef ENET_VERSION_MAJOR + mConnection = enet_host_connect(mClient, &enetAddress, 1, 0); +#else mConnection = enet_host_connect(mClient, &enetAddress, 1); +#endif if (!mConnection) { diff --git a/src/net/manaserv/network.cpp b/src/net/manaserv/network.cpp index f97a54d2..4b9751d7 100644 --- a/src/net/manaserv/network.cpp +++ b/src/net/manaserv/network.cpp @@ -53,7 +53,11 @@ void initialize() logger->error("Failed to initialize ENet."); } +#ifdef ENET_VERSION_MAJOR + client = enet_host_create(NULL, 3, 0, 0, 0); +#else client = enet_host_create(NULL, 3, 0, 0); +#endif if (!client) { -- cgit v1.2.3-70-g09d2 From 98abc793f8fb45d647e1e8c51cf5f38170c6b703 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 28 Jul 2010 00:06:08 +0300 Subject: Improve OpenGL speed. Use batch commands and not selecting already selected texture. Signed-off-by: Jared Adams --- src/openglgraphics.cpp | 502 +++++++++++++++++++++++++++++++++++++----------- src/openglgraphics.h | 23 ++- src/resources/image.cpp | 7 +- 3 files changed, 422 insertions(+), 110 deletions(-) (limited to 'src') diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 01ef9b91..7818e9d2 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -19,11 +19,14 @@ * along with this program. If not, see . */ -#include "log.h" #include "openglgraphics.h" +#include "log.h" + #include "resources/image.h" +#include "utils/stringutils.h" + #ifdef USE_OPENGL #ifdef __APPLE__ @@ -37,14 +40,24 @@ #define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 #endif +const unsigned int vertexBufSize = 500; + +GLuint OpenGLGraphics::mLastImage = 0; + OpenGLGraphics::OpenGLGraphics(): mAlpha(false), mTexture(false), mColorAlpha(false), mSync(false) { + mFloatTexArray = new GLfloat[vertexBufSize * 4]; + mIntTexArray = new GLint[vertexBufSize * 4]; + mIntVertArray = new GLint[vertexBufSize * 4]; } OpenGLGraphics::~OpenGLGraphics() { + delete[] mFloatTexArray; + delete[] mIntTexArray; + delete[] mIntVertArray; } void OpenGLGraphics::setSync(bool sync) @@ -87,7 +100,7 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) int gotDoubleBuffer; SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer); logger->log("Using OpenGL %s double buffering.", - (gotDoubleBuffer ? "with" : "without")); + (gotDoubleBuffer ? "with" : "without")); char const *glExtensions = (char const *)glGetString(GL_EXTENSIONS); GLint texSize; @@ -116,65 +129,119 @@ static inline void drawQuad(Image *image, if (image->getTextureType() == GL_TEXTURE_2D) { // Find OpenGL normalized texture coordinates. - float texX1 = srcX / (float) image->getTextureWidth(); - float texY1 = srcY / (float) image->getTextureHeight(); - float texX2 = (srcX + width) / (float) image->getTextureWidth(); - float texY2 = (srcY + height) / (float) image->getTextureHeight(); - - 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); + const float texX1 = static_cast(srcX) / + static_cast(image->getTextureWidth()); + const float texY1 = static_cast(srcY) / + static_cast(image->getTextureHeight()); + const float texX2 = static_cast(srcX + width) / + static_cast(image->getTextureWidth()); + const float texY2 = static_cast(srcY + height) / + static_cast(image->getTextureHeight()); + + GLfloat tex[] = + { + texX1, texY1, + texX2, texY1, + texX2, texY2, + texX1, texY2 + }; + + GLint vert[] = + { + dstX, dstY, + dstX + width, dstY, + dstX + width, dstY + height, + dstX, dstY + height + }; + + glVertexPointer(2, GL_FLOAT, 0, &vert); + glTexCoordPointer(2, GL_INT, 0, &tex); + + glDrawArrays(GL_QUADS, 0, 4); } 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); + 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 + }; + + glVertexPointer(2, GL_INT, 0, &vert); + glTexCoordPointer(2, GL_INT, 0, &tex); + + glDrawArrays(GL_QUADS, 0, 4); } } static inline void drawRescaledQuad(Image *image, - int srcX, int srcY, int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight) + int srcX, int srcY, int dstX, int dstY, + int width, int height, + int desiredWidth, int desiredHeight) { if (image->getTextureType() == GL_TEXTURE_2D) { // Find OpenGL normalized texture coordinates. - float texX1 = srcX / (float) image->getTextureWidth(); - float texY1 = srcY / (float) image->getTextureHeight(); - float texX2 = (srcX + width) / (float) image->getTextureWidth(); - float texY2 = (srcY + height) / (float) image->getTextureHeight(); - - 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); + const float texX1 = static_cast(srcX) / + static_cast(image->getTextureWidth()); + const float texY1 = static_cast(srcY) / + static_cast(image->getTextureHeight()); + const float texX2 = static_cast(srcX + width) / + static_cast(image->getTextureWidth()); + const float texY2 = static_cast(srcY + height) / + static_cast(image->getTextureHeight()); + + GLfloat tex[] = + { + texX1, texY1, + texX2, texY1, + texX2, texY2, + texX1, texY2 + }; + + GLint vert[] = + { + dstX, dstY, + dstX + desiredWidth, dstY, + dstX + desiredWidth, dstY + desiredHeight, + dstX, dstY + desiredHeight + }; + + glVertexPointer(2, GL_FLOAT, 0, &vert); + glTexCoordPointer(2, GL_INT, 0, &tex); + + glDrawArrays(GL_QUADS, 0, 4); } 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); + 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 + }; + + glVertexPointer(2, GL_INT, 0, &vert); + glTexCoordPointer(2, GL_INT, 0, &tex); + + glDrawArrays(GL_QUADS, 0, 4); } } @@ -192,26 +259,28 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, if (!useColor) glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha); - glBindTexture(Image::mTextureType, image->mGLImage); + bindTexture(Image::mTextureType, image->mGLImage); setTexturingAndBlending(true); - // Draw a textured quad. - glBegin(GL_QUADS); drawQuad(image, srcX, srcY, dstX, dstY, width, height); - glEnd(); if (!useColor) - glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); + { + glColor4ub(static_cast(mColor.r), + static_cast(mColor.g), + static_cast(mColor.b), + static_cast(mColor.a)); + } return true; } bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, - int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor) + int dstX, int dstY, + int width, int height, + int desiredWidth, int desiredHeight, + bool useColor) { return drawRescaledImage(image, srcX, srcY, dstX, dstY, @@ -221,17 +290,20 @@ bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, } bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, - int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor, bool smooth) + int dstX, int dstY, + int width, int height, + int desiredWidth, int desiredHeight, + bool useColor, bool smooth) { if (!image) return false; // Just draw the image normally when no resizing is necessary, if (width == desiredWidth && height == desiredHeight) - return drawImage(image, srcX, srcY, dstX, dstY, width, height, useColor); + { + return drawImage(image, srcX, srcY, dstX, dstY, + width, height, useColor); + } // When the desired image is smaller than the current one, // disable smooth effect. @@ -244,12 +316,11 @@ bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, if (!useColor) glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha); - glBindTexture(Image::mTextureType, image->mGLImage); + bindTexture(Image::mTextureType, image->mGLImage); setTexturingAndBlending(true); // Draw a textured quad. - glBegin(GL_QUADS); drawRescaledQuad(image, srcX, srcY, dstX, dstY, width, height, desiredWidth, desiredHeight); @@ -257,26 +328,27 @@ bool OpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, { glColor4f(1.0f, 1.0f, 1.0f, 0.2f); drawRescaledQuad(image, srcX, srcY, dstX - 1, dstY - 1, width, height, - desiredWidth + 1, desiredHeight + 1); + desiredWidth + 1, desiredHeight + 1); drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY + 1, width, height, - desiredWidth - 1, desiredHeight - 1); + desiredWidth - 1, desiredHeight - 1); drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY, width, height, - desiredWidth - 1, desiredHeight); + desiredWidth - 1, desiredHeight); drawRescaledQuad(image, srcX, srcY, dstX, dstY + 1, width, height, - desiredWidth, desiredHeight - 1); + desiredWidth, desiredHeight - 1); } - glEnd(); - if (!useColor) - glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); + { + glColor4ub(static_cast(mColor.r), + static_cast(mColor.g), + static_cast(mColor.b), + static_cast(mColor.a)); + } return true; } -/* Optimising the functions that Graphics::drawImagePattern would call, - * so that glBegin...glEnd are outside the main loop. */ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) { if (!image) @@ -287,39 +359,130 @@ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) const int iw = image->getWidth(); const int ih = image->getHeight(); + if (iw == 0 || ih == 0) return; + const float tw = static_cast(image->getTextureWidth()); + const float th = static_cast(image->getTextureHeight()); + glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha); - glBindTexture(Image::mTextureType, image->mGLImage); + bindTexture(Image::mTextureType, image->mGLImage); setTexturingAndBlending(true); + unsigned int vp = 0; + const unsigned int vLimit = vertexBufSize * 4; // Draw a set of textured rectangles - glBegin(GL_QUADS); - - for (int py = 0; py < h; py += ih) + if (image->getTextureType() == GL_TEXTURE_2D) { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) + float texX1 = static_cast(srcX) / tw; + float texY1 = static_cast(srcY) / th; + + for (int py = 0; py < h; py += ih) { - int width = (px + iw >= w) ? w - px : iw; - int dstX = x + px; + 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; + + float texX2 = static_cast(srcX + width) / tw; + float texY2 = static_cast(srcY + height) / th; + + mFloatTexArray[vp + 0] = texX1; + mFloatTexArray[vp + 1] = texY1; - drawQuad(image, srcX, srcY, dstX, dstY, width, height); + 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) + { + int width = (px + iw >= w) ? w - px : iw; + int dstX = x + px; - glEnd(); + mIntTexArray[vp + 0] = srcX; + mIntTexArray[vp + 1] = srcY; - glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); + 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); + } + + glColor4ub(static_cast(mColor.r), + static_cast(mColor.g), + static_cast(mColor.b), + static_cast(mColor.a)); } void OpenGLGraphics::drawRescaledImagePattern(Image *image, int x, int y, - int w, int h, - int scaledWidth, int scaledHeight) + int w, int h, int scaledWidth, + int scaledHeight) { if (!image) return; @@ -332,30 +495,117 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, int x, int y, if (iw == 0 || ih == 0) return; + const float tw = static_cast(image->getTextureWidth()); + const float th = static_cast(image->getTextureHeight()); + glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha); - glBindTexture(Image::mTextureType, image->mGLImage); + bindTexture(Image::mTextureType, image->mGLImage); setTexturingAndBlending(true); - // Draw a set of textured rectangles - glBegin(GL_QUADS); + unsigned int vp = 0; + const unsigned int vLimit = vertexBufSize * 4; - for (int py = 0; py < h; py += ih) + float texX1 = static_cast(srcX) / tw; + float texY1 = static_cast(srcY) / th; + + // Draw a set of textured rectangles + if (image->getTextureType() == GL_TEXTURE_2D) { - const int height = (py + ih >= h) ? h - py : ih; - const int dstY = y + py; - for (int px = 0; px < w; px += iw) + for (int py = 0; py < h; py += ih) { - int width = (px + iw >= w) ? w - px : iw; - int dstX = x + px; + 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; + + float texX2 = static_cast(srcX + width) / tw; + float texY2 = static_cast(srcY + height) / th; + + mFloatTexArray[vp + 0] = texX1; + mFloatTexArray[vp + 1] = texY1; - drawRescaledQuad(image, srcX, srcY, dstX, dstY, - width, height, scaledWidth, scaledHeight); + 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 + scaledWidth; + mIntVertArray[vp + 3] = dstY; + + mIntVertArray[vp + 4] = dstX + scaledWidth; + mIntVertArray[vp + 5] = dstY + scaledHeight; + + mIntVertArray[vp + 6] = dstX; + mIntVertArray[vp + 7] = dstY + scaledHeight; + + 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) + { + int width = (px + iw >= w) ? w - px : iw; + int dstX = x + px; - glEnd(); + 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 + scaledWidth; + mIntVertArray[vp + 3] = dstY; + + mIntVertArray[vp + 4] = dstX + scaledWidth; + mIntVertArray[vp + 5] = dstY + scaledHeight; + + mIntVertArray[vp + 6] = dstX; + mIntVertArray[vp + 7] = dstY + scaledHeight; + + vp += 8; + if (vp >= vLimit) + { + drawQuadArrayii(vp); + vp = 0; + } + } + } + if (vp > 0) + drawQuadArrayii(vp); + } glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); } @@ -381,9 +631,13 @@ void OpenGLGraphics::_beginDraw() glLoadIdentity(); glEnable(GL_SCISSOR_TEST); + glEnableClientState(GL_VERTEX_ARRAY); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + pushClipArea(gcn::Rectangle(0, 0, mTarget->w, mTarget->h)); } @@ -449,9 +703,9 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) glPushMatrix(); glTranslatef(transX, transY, 0); glScissor(mClipStack.top().x, - mTarget->h - mClipStack.top().y - mClipStack.top().height, - mClipStack.top().width, - mClipStack.top().height); + mTarget->h - mClipStack.top().y - mClipStack.top().height, + mClipStack.top().width, + mClipStack.top().height); return result; } @@ -533,6 +787,7 @@ void OpenGLGraphics::setTexturingAndBlending(bool enable) } else { + mLastImage = 0; if (mAlpha && !mColorAlpha) { glDisable(GL_BLEND); @@ -558,12 +813,45 @@ void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled) setTexturingAndBlending(false); - glBegin(filled ? GL_QUADS : GL_LINE_LOOP); - glVertex2f(rect.x + offset, rect.y + offset); - glVertex2f(rect.x + rect.width - offset, rect.y + offset); - glVertex2f(rect.x + rect.width - offset, rect.y + rect.height - offset); - glVertex2f(rect.x + offset, rect.y + rect.height - offset); - glEnd(); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + GLfloat vert[] = + { + rect.x + offset, rect.y + offset, + rect.x + rect.width - offset, rect.y + offset, + rect.x + rect.width - offset, rect.y + rect.height - offset, + rect.x + offset, rect.y + rect.height - offset + }; + + glVertexPointer(2, GL_FLOAT, 0, &vert); + glDrawArrays(filled ? GL_QUADS : GL_LINE_LOOP, 0, 4); + + glEnableClientState(GL_TEXTURE_COORD_ARRAY); +} + +void OpenGLGraphics::bindTexture(GLenum target, GLuint texture) +{ + if (mLastImage != texture) + { + mLastImage = texture; + glBindTexture(target, texture); + } +} + +inline void OpenGLGraphics::drawQuadArrayfi(int size) +{ + glVertexPointer(2, GL_INT, 0, mIntVertArray); + glTexCoordPointer(2, GL_FLOAT, 0, mFloatTexArray); + + glDrawArrays(GL_QUADS, 0, size / 2); +} + +inline void OpenGLGraphics::drawQuadArrayii(int size) +{ + glVertexPointer(2, GL_INT, 0, mIntVertArray); + glTexCoordPointer(2, GL_INT, 0, mIntTexArray); + + glDrawArrays(GL_QUADS, 0, size / 2); } #endif // USE_OPENGL diff --git a/src/openglgraphics.h b/src/openglgraphics.h index 03738bfb..ee96e19c 100644 --- a/src/openglgraphics.h +++ b/src/openglgraphics.h @@ -22,8 +22,16 @@ #ifndef OPENGLGRAPHICS_H #define OPENGLGRAPHICS_H +#include "main.h" + #include "graphics.h" +#ifdef USE_OPENGL +#define NO_SDL_GLEXT + +#include +#endif + class OpenGLGraphics : public Graphics { public: @@ -72,8 +80,8 @@ class OpenGLGraphics : public Graphics * Draw a pattern based on a rescaled version of the given image... */ void drawRescaledImagePattern(Image *image, - int x, int y, int w, int h, - int scaledWidth, int scaledHeight); + int x, int y, int w, int h, + int scaledWidth, int scaledHeight); void updateScreen(); @@ -97,15 +105,26 @@ class OpenGLGraphics : public Graphics void setTargetPlane(int width, int height); + void drawQuadArrayfi(int size); + + void drawQuadArrayii(int size); + /** * Takes a screenshot and returns it as SDL surface. */ SDL_Surface *getScreenshot(); + static void bindTexture(GLenum target, GLuint texture); + + static GLuint mLastImage; + protected: void setTexturingAndBlending(bool enable); private: + GLfloat *mFloatTexArray; + GLint *mIntTexArray; + GLint *mIntVertArray; bool mAlpha, mTexture; bool mColorAlpha; bool mSync; diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 0e7dc897..82799bce 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -22,6 +22,11 @@ #include "resources/image.h" #include "resources/dye.h" + +#ifdef USE_OPENGL +#include "openglgraphics.h" +#endif + #include "log.h" #include @@ -467,7 +472,7 @@ Image *Image::_GLload(SDL_Surface *tmpImage) GLuint texture; glGenTextures(1, &texture); - glBindTexture(mTextureType, texture); + OpenGLGraphics::bindTexture(mTextureType, texture); if (SDL_MUSTLOCK(tmpImage)) SDL_LockSurface(tmpImage); -- cgit v1.2.3-70-g09d2