Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merging branch GML to trunk

git-svn-id: https://spring.clan-sy.com/svn/spring/trunk@6045 37977431-3df6-0310-b722-df95706aa16b
  • Loading branch information...
commit 48b69c7d4e6e4340c1d0ded02f76ea28e0c3e2c6 1 parent 58868ea
zerver authored
Showing with 10,324 additions and 418 deletions.
  1. +49 −7 rts/Game/Game.cpp
  2. +8 −0 rts/Game/Game.h
  3. +9 −2 rts/Game/GameController.cpp
  4. +4 −1 rts/Game/GameServer.cpp
  5. +0 −1  rts/Game/PlayerRoster.cpp
  6. +1 −1  rts/Game/UI/HwMouseCursor.cpp
  7. +2 −2 rts/Lua/LuaMaterial.h
  8. +2 −0  rts/Lua/LuaOpenGL.cpp
  9. +1 −0  rts/Lua/LuaParser.cpp
  10. +1 −0  rts/Lua/LuaVFS.cpp
  11. +1 −2  rts/Map/ReadMap.h
  12. +2 −3 rts/Map/SM3/Frustum.cpp
  13. +1 −2  rts/Map/SM3/Sm3GroundDrawer.cpp
  14. +1 −2  rts/Map/SM3/Sm3Map.cpp
  15. +1 −2  rts/Map/SM3/terrain/QuadRenderData.cpp
  16. +1 −2  rts/Map/SM3/terrain/Terrain.cpp
  17. +1 −2  rts/Map/SM3/terrain/TerrainBase.h
  18. +795 −2 rts/Map/SMF/BFGroundDrawer.cpp
  19. +11 −0 rts/Map/SMF/BFGroundDrawer.h
  20. +1 −2  rts/Map/SMF/BFGroundTextures.h
  21. +12 −8 rts/Map/SMF/SmfReadMap.cpp
  22. +29 −28 rts/Rendering/Env/AdvTreeDrawer.cpp
  23. +0 −1  rts/Rendering/Env/GrassDrawer.cpp
  24. +95 −112 rts/Rendering/GL/VertexArray.cpp
  25. +71 −69 rts/Rendering/GL/VertexArray.h
  26. +20 −53 rts/Rendering/GL/VertexArrayRange.cpp
  27. +18 −1 rts/Rendering/GL/myGL.cpp
  28. +4 −0 rts/Rendering/GL/myGL.h
  29. +2 −1  rts/Rendering/GroundDecalHandler.cpp
  30. +1 −1  rts/Rendering/Textures/nv_dds.h
  31. +1 −1  rts/Rendering/UnitModels/3DOParser.cpp
  32. +171 −15 rts/Rendering/UnitModels/UnitDrawer.cpp
  33. +18 −4 rts/Rendering/UnitModels/UnitDrawer.h
  34. +0 −1  rts/Sim/Features/FeatureHandler.cpp
  35. +7 −7 rts/Sim/Path/PathEstimator.cpp
  36. +1 −1  rts/Sim/Projectiles/Projectile.cpp
  37. +2 −2 rts/Sim/Projectiles/ProjectileHandler.cpp
  38. +1 −1  rts/Sim/Units/UnitHandler.cpp
  39. +2 −0  rts/System/BaseNetProtocol.cpp
  40. +1 −1  rts/System/FileSystem/FileFilter.cpp
  41. +1 −0  rts/System/FileSystem/FileHandler.cpp
  42. +1 −0  rts/System/Platform/FileSystem.cpp
  43. +1 −1  rts/System/Platform/Win/AVIGenerator.cpp
  44. +0 −4 rts/System/Platform/Win/DxSound.h
  45. +1 −0  rts/System/Platform/Win/WinFileSystemHandler.cpp
  46. +3 −0  rts/System/Platform/Win/win32.h
  47. +4 −0 rts/System/StdAfx.h
  48. +0 −1  rts/System/Sync/SyncedPrimitive.h
  49. +5 −2 rts/build/vstudio8/rts.sln
  50. +1,818 −69 rts/build/vstudio8/rts.vcproj
  51. +973 −0 rts/lib/gml/gml.cpp
  52. +135 −0 rts/lib/gml/gml.h
  53. +889 −0 rts/lib/gml/gmlcls.h
  54. +528 −0 rts/lib/gml/gmldef.h
  55. +1,228 −0 rts/lib/gml/gmlfun.h
  56. +3,122 −0 rts/lib/gml/gmlimp.h
  57. +263 −0 rts/lib/gml/gmlsrv.h
  58. +4 −1 rts/lib/luabind/luabind/lua_include.hpp
  59. BIN  rts/spring.ico
  60. BIN  rts/spring.new.ico
56 rts/Game/Game.cpp
View
@@ -11,7 +11,6 @@
#include <sstream>
#include "Rendering/GL/myGL.h"
-#include <GL/glu.h>
#include <SDL_keyboard.h>
#include <SDL_keysym.h>
#include <SDL_mouse.h>
@@ -150,13 +149,16 @@
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
+#include <boost/thread/barrier.hpp>
+
+#include "lib/gml/gmlsrv.h"
+gmlClientServer<void, int,CUnit*> gmlProcessor;
extern Uint8 *keys;
extern bool globalQuit;
extern bool fullscreen;
extern string stupidGlobalMapname;
-
CGame* game = NULL;
@@ -2449,6 +2451,7 @@ bool CGame::DrawWorld()
//transparent stuff
glEnable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
+
if (drawGround) {
if (treeDrawer->drawTrees) {
treeDrawer->DrawGrass();
@@ -2540,9 +2543,22 @@ bool CGame::DrawWorld()
return true;
}
+#if GML_ENABLE_DRAWALL
+bool CGame::Draw() {
+#else
+bool CGame::DrawMT() {
+#endif
+ gmlProcessor.Work(&CGame::DrawMTcb,NULL,NULL,this,gmlThreadCount,TRUE,NULL,1,2,2,FALSE);
+ return TRUE;
+}
+
+
+#if GML_ENABLE_DRAWALL
+bool CGame::DrawMT() {
+#else
+bool CGame::Draw() {
+#endif
-bool CGame::Draw()
-{
ASSERT_UNSYNCED_MODE;
SetDrawMode(normalDraw);
@@ -2943,8 +2959,29 @@ void CGame::StartPlaying()
}
-void CGame::SimFrame()
-{
+
+// This will be run by a separate thread in parallel with the Sim
+// ONLY 100% THREAD SAFE UNSYNCED STUFF HERE PLEASE
+void CGame::UnsyncedStuff() {
+ if(!skipping) {
+ infoConsole->Update();
+ }
+}
+
+
+#if GML_ENABLE_SIM
+void CGame::SimFrame() {
+#else
+void CGame::SimFrameMT() {
+#endif
+ gmlProcessor.Work(&CGame::SimFrameMTcb,NULL,NULL,this,2,FALSE,NULL,1,2,2,FALSE,&CGame::UnsyncedStuffcb);
+}
+
+#if GML_ENABLE_SIM
+void CGame::SimFrameMT() {
+#else
+void CGame::SimFrame() {
+#endif
good_fpu_control_registers("CGame::SimFrame");
lastFrameTime = SDL_GetTicks();
ASSERT_SYNCED_MODE;
@@ -2970,7 +3007,10 @@ void CGame::SimFrame()
ENTER_UNSYNCED;
if (!skipping) {
- infoConsole->Update();
+#if !GML_ENABLE_SIM
+ UnsyncedStuff();
+#endif
+// infoConsole->Update();
waitCommandsAI.Update();
geometricObjects->Update();
if(!(gs->frameNum & 7))
@@ -3717,6 +3757,8 @@ void CGame::ClientReadNet()
gu->spectating = false;
gu->spectatingFullView = false;
gu->spectatingFullSelect = false;
+ gu->spectatingFullView = false;
+ gu->spectatingFullSelect = false;
selectedUnits.ClearSelected();
unitTracker.Disable();
CLuaUI::UpdateTeams();
8 rts/Game/Game.h
View
@@ -31,7 +31,15 @@ class CGame : public CGameController
CR_DECLARE(CGame); //Don't use CGame pointer in CR_MEMBER()!!!
void PostLoad();
+ void SimFrameMT();
+ static void SimFrameMTcb(void *c) {((CGame *)c)->SimFrameMT();}
+
bool Draw();
+ bool DrawMT();
+
+ static void DrawMTcb(void *c) {((CGame *)c)->DrawMT();}
+ void UnsyncedStuff();
+ static void UnsyncedStuffcb(void *c) {((CGame *)c)->UnsyncedStuff();}
bool Update();
int KeyReleased(unsigned short k);
int KeyPressed(unsigned short k,bool isRepeat);
11 rts/Game/GameController.cpp
View
@@ -30,8 +30,15 @@ bool CGameController::Draw(void)
{
return true;
}
-
-
+/*
+bool CGameController::Draw2(void)
+{
+ return true;
+}*/
+/*bool CGameController::DrawMT(void)
+{
+ return true;
+}*/
bool CGameController::Update(void)
{
5 rts/Game/GameServer.cpp
View
@@ -1,3 +1,4 @@
+#include "StdAfx.h"
#include "GameServer.h"
#include <stdarg.h>
@@ -37,6 +38,7 @@ namespace std { using ::ceil; }
#endif
using netcode::RawPacket;
+
/// frames until a syncchech will time out and a warning is given out
const int SYNCCHECK_TIMEOUT = 300;
@@ -1240,7 +1242,7 @@ void CGameServer::CheckForGameEnd()
void CGameServer::CreateNewFrame(bool fromServerThread, bool fixedFrameTime)
{
-#if BOOST_VERSION >= 103500
+#if (BOOST_VERSION >= 103500)
if (!fromServerThread)
boost::recursive_mutex::scoped_lock scoped_lock(gameServerMutex, boost::defer_lock);
else
@@ -1426,3 +1428,4 @@ void CGameServer::RestrictedAction(const std::string& action)
commandBlacklist.insert(action);
}
+
1  rts/Game/PlayerRoster.cpp
View
@@ -7,7 +7,6 @@
#include "Player.h"
#include "Team.h"
-
static int CompareAllies (const void* a, const void* b);
static int CompareTeamIDs (const void* a, const void* b);
static int ComparePlayerNames(const void* a, const void* b);
2  rts/Game/UI/HwMouseCursor.cpp
View
@@ -13,7 +13,7 @@
#include <SDL_syswm.h>
#ifdef WIN32
- #include "windows.h"
+ #include "windows.h"
#include "MouseInput.h"
#elif defined(__APPLE__)
/*do nothing (duno how to create cursors on runtime on macs)*/
4 rts/Lua/LuaMaterial.h
View
@@ -202,7 +202,7 @@ class LuaMatBin : public LuaMaterial {
public:
void Clear() { units.clear(); }
- const vector<CUnit*>& GetUnits() const { return units; }
+ const GML_VECTOR<CUnit*>& GetUnits() const { return units; }
void Ref();
void UnRef();
@@ -218,7 +218,7 @@ class LuaMatBin : public LuaMaterial {
private:
int refCount;
- vector<CUnit*> units;
+ GML_VECTOR<CUnit*> units;
};
2  rts/Lua/LuaOpenGL.cpp
View
@@ -65,6 +65,8 @@ using std::string;
using std::vector;
using std::set;
+#undef far // avoid collision with windef.h
+#undef near
static const int MAX_TEXTURE_UNITS = 32;
1  rts/Lua/LuaParser.cpp
View
@@ -6,6 +6,7 @@
#include "LuaParser.h"
#include <algorithm>
+#include <limits.h>
#include <boost/regex.hpp>
#include <SDL_timer.h>
1  rts/Lua/LuaVFS.cpp
View
@@ -7,6 +7,7 @@
#include <set>
#include <list>
#include <cctype>
+#include <limits.h>
#include <boost/regex.hpp>
using namespace std;
3  rts/Map/ReadMap.h
View
@@ -4,8 +4,7 @@
//
//////////////////////////////////////////////////////////////////////
-#define GLEW_STATIC
-#include <GL/glew.h>
+#include "Rendering/GL/myGL.h"
#include "creg/creg.h"
#include "float3.h"
5 rts/Map/SM3/Frustum.cpp
View
@@ -9,9 +9,8 @@
#include "Frustum.h"
-#define GLEW_STATIC
-#include <GL/glew.h>
-
+#include "Rendering/GL/myGL.h"
+#undef far // avoid collision with windef.h
void Frustum::InversePlanes ()
{
3  rts/Map/SM3/Sm3GroundDrawer.cpp
View
@@ -8,9 +8,8 @@
#include "Rendering/ShadowHandler.h"
#include "Sim/Projectiles/ProjectileHandler.h"
#include "Rendering/GroundDecalHandler.h"
+#include "Rendering/GL/myGL.h"
#include "Map/MapInfo.h"
-#define GLEW_STATIC
-#include <GL/glew.h>
#include "Platform/ConfigHandler.h"
#include <SDL_keysym.h>
3  rts/Map/SM3/Sm3Map.cpp
View
@@ -4,8 +4,7 @@
#include "Sm3GroundDrawer.h"
#include "LogOutput.h"
-#define GLEW_STATIC
-#include <GL/glew.h>
+#include "Rendering/GL/myGL.h"
#include <IL/il.h>
#include <SDL_types.h>
#include "Map/MapInfo.h"
3  rts/Map/SM3/terrain/QuadRenderData.cpp
View
@@ -28,8 +28,7 @@
*/
#include "StdAfx.h"
-#define GLEW_STATIC
-#include <GL/glew.h>
+#include "Rendering/GL/myGL.h"
#include "TerrainBase.h"
#include "TerrainNode.h"
3  rts/Map/SM3/terrain/Terrain.cpp
View
@@ -28,8 +28,7 @@
*/
#include "StdAfx.h"
-#define GLEW_STATIC
-#include <GL/glew.h>
+#include "Rendering/GL/myGL.h"
#include "TerrainBase.h"
#include "Terrain.h"
3  rts/Map/SM3/terrain/TerrainBase.h
View
@@ -29,8 +29,7 @@
#ifndef TERRAIN_BASE_H
#define TERRAIN_BASE_H
-#define GLEW_STATIC
-#include <GL/glew.h>
+#include "Rendering/GL/myGL.h"
#include "../Frustum.h"
#include "Matrix44f.h"
797 rts/Map/SMF/BFGroundDrawer.cpp
View
@@ -14,6 +14,9 @@
#include "Platform/ConfigHandler.h"
#include "mmgr.h"
+#include "lib/gml/gmlsrv.h"
+extern gmlClientServer<void, int,CUnit*> gmlProcessor;
+
using std::min;
using std::max;
@@ -86,6 +89,28 @@ inline void CBFGroundDrawer::EndStrip()
}
+inline void CBFGroundDrawer::DrawVertexAMT(CVertexArray *ma, int x, int y)
+{
+ float height = heightData[y * heightDataX + x];
+ if (waterDrawn && height < 0) {
+ height *= 2;
+ }
+
+ ma->AddVertexQ0(x * SQUARE_SIZE, height, y * SQUARE_SIZE);
+}
+
+inline void CBFGroundDrawer::DrawVertexAMT(CVertexArray *ma, int x, int y, float height)
+{
+ if (waterDrawn && height < 0) {
+ height *= 2;
+ }
+ ma->AddVertexQ0(x * SQUARE_SIZE, height, y * SQUARE_SIZE);
+}
+
+inline void CBFGroundDrawer::EndStripMT(CVertexArray *ma)
+{
+ ma->EndStripQ();
+}
inline bool CBFGroundDrawer::BigTexSquareRowVisible(int bty) {
static int mapWidth = (gs->mapx << 3);
@@ -138,6 +163,485 @@ inline void CBFGroundDrawer::DrawGroundVertexArray()
}
+inline void CBFGroundDrawer::DrawGroundVertexArrayMT(CVertexArray * &ma)
+{
+ ma->DrawArray0(GL_TRIANGLE_STRIP);
+ ma = GetVertexArray();
+ ma->Initialize();
+}
+
+int neededLod=0;
+int maxIdx=0;
+
+bool CBFGroundDrawer::DrawMT(int bty) {
+ unsigned int overrideVP=mt_overrideVP;
+#define CLAMP(i) std::max(0, std::min((i), maxIdx))
+ if (!BigTexSquareRowVisible(bty)) {
+ // skip this entire row of squares if we can't see it
+ return true;
+ }
+
+ CVertexArray *ma = GetVertexArray();
+ ma->Initialize();
+
+ bool inStrip = false;
+ int x,y;
+ // only process the necessary big squares in the x direction
+ int sx = 0;
+ int ex = numBigTexX;
+ float x0, x1;
+ std::vector<fline>::iterator fli;
+
+
+ for (fli = left.begin(); fli != left.end(); fli++) {
+ x0 = ((fli->base / SQUARE_SIZE + fli->dir * (bty * bigSquareSize) ));
+ x1 = ((fli->base / SQUARE_SIZE + fli->dir * ((bty * bigSquareSize) + bigSquareSize)));
+
+ if (x0 > x1)
+ x0 = x1;
+
+ x0 /= bigSquareSize;
+
+ if (x0 > sx)
+ sx = (int) x0;
+ }
+ for (fli = right.begin(); fli != right.end(); fli++) {
+ x0 = ((fli->base / SQUARE_SIZE + fli->dir * (bty * bigSquareSize) )) + bigSquareSize;
+ x1 = ((fli->base / SQUARE_SIZE + fli->dir * ((bty * bigSquareSize) + bigSquareSize))) + bigSquareSize;
+
+ if (x0 < x1)
+ x0 = x1;
+
+ x0 /= bigSquareSize;
+
+ if (x0 < ex)
+ ex = (int) x0;
+ }
+
+
+ for (int btx = sx; btx < ex; ++btx) {
+ // must be in drawLos mode or shadows must be off
+ if (DrawExtraTex() || !shadowHandler->drawShadows) {
+ textures->SetTexture(btx, bty);
+ SetTexGen(1.0f / 1024, 1.0f / 1024, -btx, -bty);
+
+ if (overrideVP) {
+ glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 11, -btx, -bty, 0, 0);
+ }
+ } else {
+ textures->SetTexture(btx, bty);
+ glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 11, -btx, -bty, 0, 0);
+ }
+
+ for (int lod = 1; lod < neededLod; lod <<= 1) {
+ float cx2 = (cam2->pos.x / (SQUARE_SIZE));
+ float cy2 = (cam2->pos.z / (SQUARE_SIZE));
+
+ float oldcamxpart = 0.0f;
+ float oldcamypart = 0.0f;
+
+ int hlod = lod >> 1;
+ int dlod = lod << 1;
+
+ int cx = (int)cx2;
+ int cy = (int)cy2;
+
+ if(lod>1) {
+ int cxo = (cx / hlod) * hlod;
+ int cyo = (cy / hlod) * hlod;
+ float cx2o = (cxo / lod) * lod;
+ float cy2o = (cyo / lod) * lod;
+ oldcamxpart = (cx2 - cx2o) / (lod);
+ oldcamypart = (cy2 - cy2o) / (lod);
+ }
+
+ cx = (cx / lod) * lod;
+ cy = (cy / lod) * lod;
+ int ysquaremod = ((cy) % (dlod)) / lod;
+ int xsquaremod = ((cx) % (dlod)) / lod;
+
+ float camxpart = (cx2 - ((cx / (dlod)) * dlod)) / (dlod);
+ float camypart = (cy2 - ((cy / (dlod)) * dlod)) / (dlod);
+
+ int minty = bty * bigSquareSize;
+ int maxty = (bty + 1) * bigSquareSize;
+ int mintx = btx * bigSquareSize;
+ int maxtx = (btx + 1) * bigSquareSize;
+
+ int minly = cy + (-viewRadius + 3 - ysquaremod) * lod;
+ int maxly = cy + ( viewRadius - 1 - ysquaremod) * lod;
+ int minlx = cx + (-viewRadius + 3 - xsquaremod) * lod;
+ int maxlx = cx + ( viewRadius - 1 - xsquaremod) * lod;
+
+ int xstart = max(minlx, mintx);
+ int xend = min(maxlx, maxtx);
+ int ystart = max(minly, minty);
+ int yend = min(maxly, maxty);
+
+ for (y = ystart; y < yend; y += lod) {
+ int xs = xstart;
+ int xe = xend;
+ int xt0, xt1;
+ std::vector<fline>::iterator fli;
+
+
+ for (fli = left.begin(); fli != left.end(); fli++) {
+ xt0 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * y )) / lod * lod - lod;
+ xt1 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * (y + lod))) / lod * lod - lod;
+
+ if (xt0 > xt1) xt0 = xt1;
+ if (xt0 > xs) xs = xt0;
+ }
+ for (fli = right.begin(); fli != right.end(); fli++) {
+ xt0 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * y )) / lod * lod + lod;
+ xt1 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * (y + lod))) / lod * lod + lod;
+
+ if (xt0 < xt1) xt0 = xt1;
+ if (xt0 < xe) xe = xt0;
+ }
+
+ int nloop=(xe-xs)/lod+1;
+ ma->EnlargeArrays(52*nloop, 14*nloop+1); // includes one extra for final endstrip
+
+ for (x = xs; x < xe; x += lod) {
+ if ((lod == 1) ||
+ (x > (cx) + viewRadius * hlod) || (x < (cx) - viewRadius * hlod) ||
+ (y > (cy) + viewRadius * hlod) || (y < (cy) - viewRadius * hlod)) {
+ // normal terrain
+ if (!inStrip) {
+ DrawVertexAMT(ma, x, y );
+ DrawVertexAMT(ma, x, y + lod);
+ inStrip = true;
+ }
+
+ DrawVertexAMT(ma, x + lod, y );
+ DrawVertexAMT(ma, x + lod, y + lod);
+ } else {
+ // inre begr�sning mot f�eg�nde lod
+ if ((x >= (cx) + viewRadius * hlod)) {
+ int idx1 = CLAMP((y ) * heightDataX + x), idx1LOD = CLAMP(idx1 + lod), idx1HLOD = CLAMP(idx1 + hlod);
+ int idx2 = CLAMP((y + lod) * heightDataX + x), idx2LOD = CLAMP(idx2 + lod), idx2HLOD = CLAMP(idx2 + hlod);
+ int idx3 = CLAMP((y + hlod) * heightDataX + x), idx3HLOD = CLAMP(idx3 + hlod);
+ float h1 = (heightData[idx1] + heightData[idx2 ]) * 0.5f * (1 - oldcamxpart) + heightData[idx3 ] * (oldcamxpart);
+ float h2 = (heightData[idx1] + heightData[idx1LOD]) * 0.5f * (1 - oldcamxpart) + heightData[idx1HLOD] * (oldcamxpart);
+ float h3 = (heightData[idx2] + heightData[idx1LOD]) * 0.5f * (1 - oldcamxpart) + heightData[idx3HLOD] * (oldcamxpart);
+ float h4 = (heightData[idx2] + heightData[idx2LOD]) * 0.5f * (1 - oldcamxpart) + heightData[idx2HLOD] * (oldcamxpart);
+
+ if (inStrip) {
+ EndStripMT(ma);
+ inStrip = false;
+ }
+
+ DrawVertexAMT(ma, x, y );
+ DrawVertexAMT(ma, x, y + hlod, h1);
+ DrawVertexAMT(ma, x + hlod, y, h2);
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x, y + hlod, h1);
+ DrawVertexAMT(ma, x, y + lod );
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ DrawVertexAMT(ma, x + hlod, y + lod, h4);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x + hlod, y + lod, h4);
+ DrawVertexAMT(ma, x + lod, y + lod );
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ DrawVertexAMT(ma, x + lod, y );
+ DrawVertexAMT(ma, x + hlod, y, h2);
+ EndStripMT(ma);
+ }
+ if ((x <= (cx) - viewRadius * hlod)) {
+ int idx1 = CLAMP((y ) * heightDataX + x), idx1LOD = CLAMP(idx1 + lod), idx1HLOD = CLAMP(idx1 + hlod);
+ int idx2 = CLAMP((y + lod) * heightDataX + x), idx2LOD = CLAMP(idx2 + lod), idx2HLOD = CLAMP(idx2 + hlod);
+ int idx3 = CLAMP((y + hlod) * heightDataX + x), idx3LOD = CLAMP(idx3 + lod), idx3HLOD = CLAMP(idx3 + hlod);
+ float h1 = (heightData[idx1LOD] + heightData[idx2LOD]) * 0.5f * (oldcamxpart) + heightData[idx3LOD ] * (1 - oldcamxpart);
+ float h2 = (heightData[idx1 ] + heightData[idx1LOD]) * 0.5f * (oldcamxpart) + heightData[idx1HLOD] * (1 - oldcamxpart);
+ float h3 = (heightData[idx2 ] + heightData[idx1LOD]) * 0.5f * (oldcamxpart) + heightData[idx3HLOD] * (1 - oldcamxpart);
+ float h4 = (heightData[idx2 ] + heightData[idx2LOD]) * 0.5f * (oldcamxpart) + heightData[idx2HLOD] * (1 - oldcamxpart);
+
+ if (inStrip) {
+ EndStripMT(ma);
+ inStrip = false;
+ }
+
+ DrawVertexAMT(ma, x + lod, y + hlod, h1);
+ DrawVertexAMT(ma, x + lod, y );
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ DrawVertexAMT(ma, x + hlod, y, h2);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x + lod, y + lod );
+ DrawVertexAMT(ma, x + lod, y + hlod, h1);
+ DrawVertexAMT(ma, x + hlod, y + lod, h4);
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x + hlod, y, h2);
+ DrawVertexAMT(ma, x, y );
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ DrawVertexAMT(ma, x, y + lod );
+ DrawVertexAMT(ma, x + hlod, y + lod, h4);
+ EndStripMT(ma);
+ }
+ if ((y >= (cy) + viewRadius * hlod)) {
+ int idx1 = (y ) * heightDataX + x, idx1LOD = CLAMP(idx1 + lod), idx1HLOD = CLAMP(idx1 + hlod);
+ int idx2 = (y + lod) * heightDataX + x, idx2LOD = CLAMP(idx2 + lod);
+ int idx3 = (y + hlod) * heightDataX + x, idx3LOD = CLAMP(idx3 + lod), idx3HLOD = CLAMP(idx3 + hlod);
+ float h1 = (heightData[idx1 ] + heightData[idx1LOD]) * 0.5f * (1 - oldcamypart) + heightData[idx1HLOD] * (oldcamypart);
+ float h2 = (heightData[idx1 ] + heightData[idx2 ]) * 0.5f * (1 - oldcamypart) + heightData[idx3 ] * (oldcamypart);
+ float h3 = (heightData[idx2 ] + heightData[idx1LOD]) * 0.5f * (1 - oldcamypart) + heightData[idx3HLOD] * (oldcamypart);
+ float h4 = (heightData[idx2LOD] + heightData[idx1LOD]) * 0.5f * (1 - oldcamypart) + heightData[idx3LOD ] * (oldcamypart);
+
+ if (inStrip) {
+ EndStripMT(ma);
+ inStrip = false;
+ }
+
+ DrawVertexAMT(ma, x, y );
+ DrawVertexAMT(ma, x, y + hlod, h2);
+ DrawVertexAMT(ma, x + hlod, y, h1);
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ DrawVertexAMT(ma, x + lod, y );
+ DrawVertexAMT(ma, x + lod, y + hlod, h4);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x, y + hlod, h2);
+ DrawVertexAMT(ma, x, y + lod );
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ DrawVertexAMT(ma, x + lod, y + lod );
+ DrawVertexAMT(ma, x + lod, y + hlod, h4);
+ EndStripMT(ma);
+ }
+ if ((y <= (cy) - viewRadius * hlod)) {
+ int idx1 = CLAMP((y ) * heightDataX + x), idx1LOD = CLAMP(idx1 + lod);
+ int idx2 = CLAMP((y + lod) * heightDataX + x), idx2LOD = CLAMP(idx2 + lod), idx2HLOD = CLAMP(idx2 + hlod);
+ int idx3 = CLAMP((y + hlod) * heightDataX + x), idx3LOD = CLAMP(idx3 + lod), idx3HLOD = CLAMP(idx3 + hlod);
+ float h1 = (heightData[idx2 ] + heightData[idx2LOD]) * 0.5f * (oldcamypart) + heightData[idx2HLOD] * (1 - oldcamypart);
+ float h2 = (heightData[idx1 ] + heightData[idx2 ]) * 0.5f * (oldcamypart) + heightData[idx3 ] * (1 - oldcamypart);
+ float h3 = (heightData[idx2 ] + heightData[idx1LOD]) * 0.5f * (oldcamypart) + heightData[idx3HLOD] * (1 - oldcamypart);
+ float h4 = (heightData[idx2LOD] + heightData[idx1LOD]) * 0.5f * (oldcamypart) + heightData[idx3LOD ] * (1 - oldcamypart);
+
+ if (inStrip) {
+ EndStripMT(ma);
+ inStrip = false;
+ }
+
+ DrawVertexAMT(ma, x, y + hlod, h2);
+ DrawVertexAMT(ma, x, y + lod );
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ DrawVertexAMT(ma, x + hlod, y + lod, h1);
+ DrawVertexAMT(ma, x + lod, y + hlod, h4);
+ DrawVertexAMT(ma, x + lod, y + lod );
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x + lod, y + hlod, h4);
+ DrawVertexAMT(ma, x + lod, y );
+ DrawVertexAMT(ma, x + hlod, y + hlod, h3);
+ DrawVertexAMT(ma, x, y );
+ DrawVertexAMT(ma, x, y + hlod, h2);
+ EndStripMT(ma);
+ }
+ }
+ }
+
+ if (inStrip) {
+ EndStripMT(ma);
+ inStrip = false;
+ }
+ }
+
+ int yst=max(ystart - lod, minty);
+ int yed=min(yend + lod, maxty);
+ int nloop=(yed-yst)/lod+1;
+ ma->EnlargeArrays(8*nloop, 2*nloop);
+
+ // rita yttre begr�snings yta mot n�ta lod
+ if (maxlx < maxtx && maxlx >= mintx) {
+ x = maxlx;
+ for (y = yst; y < yed; y += lod) {
+ DrawVertexAMT(ma, x, y );
+ DrawVertexAMT(ma, x, y + lod);
+
+ if (y % (dlod)) {
+ int idx1 = CLAMP((y ) * heightDataX + x), idx1LOD = CLAMP(idx1 + lod);
+ int idx2 = CLAMP((y + lod) * heightDataX + x), idx2LOD = CLAMP(idx2 + lod);
+ int idx3 = CLAMP((y - lod) * heightDataX + x), idx3LOD = CLAMP(idx3 + lod);
+ float h = ((heightData[idx3LOD] +
+ heightData[idx2LOD]) * 0.5f) * (1 - camxpart) +
+ heightData[idx1LOD] * (camxpart);
+
+ DrawVertexAMT(ma, x + lod, y, h);
+ DrawVertexAMT(ma, x + lod, y + lod );
+ } else {
+ int idx1 = CLAMP((y ) * heightDataX + x), idx1LOD = CLAMP(idx1 + lod);
+ int idx2 = CLAMP((y + lod) * heightDataX + x), idx2LOD = CLAMP(idx2 + lod);
+ int idx3 = CLAMP((y + dlod) * heightDataX + x), idx3LOD = CLAMP(idx3 + lod);
+ float h = (heightData[idx1LOD] +
+ heightData[idx3LOD]) * 0.5f * (1 - camxpart) +
+ heightData[idx2LOD] * (camxpart);
+
+ DrawVertexAMT(ma, x + lod, y);
+ DrawVertexAMT(ma, x + lod, y + lod, h);
+ }
+ EndStripMT(ma);
+ }
+ }
+
+ if (minlx > mintx && minlx < maxtx) {
+ x = minlx - lod;
+ for (y = yst; y < yed; y += lod) {
+ if (y % (dlod)) {
+ int idx1 = CLAMP((y ) * heightDataX + x);
+ int idx2 = CLAMP((y + lod) * heightDataX + x);
+ int idx3 = CLAMP((y - lod) * heightDataX + x);
+ float h = ((heightData[idx3] +
+ heightData[idx2]) * 0.5f) * (camxpart) +
+ heightData[idx1] * (1 - camxpart);
+
+ DrawVertexAMT(ma, x, y, h);
+ DrawVertexAMT(ma, x, y + lod );
+ } else {
+ int idx1 = CLAMP((y ) * heightDataX + x);
+ int idx2 = CLAMP((y + lod) * heightDataX + x);
+ int idx3 = CLAMP((y + dlod) * heightDataX + x);
+ float h = (heightData[idx1] +
+ heightData[idx3]) * 0.5f * (camxpart) +
+ heightData[idx2] * (1 - camxpart);
+
+ DrawVertexAMT(ma, x, y);
+ DrawVertexAMT(ma, x, y + lod, h);
+ }
+ DrawVertexAMT(ma, x + lod, y );
+ DrawVertexAMT(ma, x + lod, y + lod);
+ EndStripMT(ma);
+ }
+ }
+
+ if (maxly < maxty && maxly > minty) {
+ y = maxly;
+ int xs = max(xstart - lod, mintx);
+ int xe = min(xend + lod, maxtx);
+ int xt0, xt1;
+ std::vector<fline>::iterator fli;
+
+
+ for (fli = left.begin(); fli != left.end(); fli++) {
+ xt0 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * y )) / lod * lod - lod;
+ xt1 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * (y + lod))) / lod * lod - lod;
+
+ if (xt0 > xt1) xt0 = xt1;
+ if (xt0 > xs) xs = xt0;
+ }
+ for (fli = right.begin(); fli != right.end(); fli++) {
+ xt0 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * y )) / lod * lod + lod;
+ xt1 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * (y + lod))) / lod * lod + lod;
+
+ if (xt0 < xt1) xt0 = xt1;
+ if (xt0 < xe) xe = xt0;
+ }
+
+
+ if (xs < xe) {
+ x = xs;
+ int nloop=(xe-xs)/lod+2; // one extra for if statment
+ ma->EnlargeArrays(2*nloop, 1);
+ if (x % (dlod)) {
+ int idx2 = CLAMP((y + lod) * heightDataX + x),
+ idx2PLOD = CLAMP(idx2 + lod),
+ idx2MLOD = CLAMP(idx2 - lod);
+ float h = ((heightData[idx2MLOD] +
+ heightData[idx2PLOD]) * 0.5f) * (1 - camypart) +
+ heightData[idx2 ] * (camypart);
+
+ DrawVertexAMT(ma, x, y);
+ DrawVertexAMT(ma, x, y + lod, h);
+ } else {
+ DrawVertexAMT(ma, x, y );
+ DrawVertexAMT(ma, x, y + lod);
+ }
+ for (x = xs; x < xe; x += lod) {
+ if (x % (dlod)) {
+ DrawVertexAMT(ma, x + lod, y );
+ DrawVertexAMT(ma, x + lod, y + lod);
+ } else {
+ int idx2 = CLAMP((y + lod) * heightDataX + x),
+ idx2PLOD = CLAMP(idx2 + lod),
+ idx2PLOD2 = CLAMP(idx2 + dlod);
+ float h = (heightData[idx2PLOD2] +
+ heightData[idx2 ]) * 0.5f * (1 - camypart) +
+ heightData[idx2PLOD ] * (camypart);
+
+ DrawVertexAMT(ma, x + lod, y);
+ DrawVertexAMT(ma, x + lod, y + lod, h);
+ }
+ }
+ EndStripMT(ma);
+ }
+ }
+
+ if (minly > minty && minly < maxty) {
+ y = minly - lod;
+ int xs = max(xstart - lod, mintx);
+ int xe = min(xend + lod, maxtx);
+ int xt0, xt1;
+ std::vector<fline>::iterator fli;
+
+
+ for (fli = left.begin(); fli != left.end(); fli++) {
+ xt0 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * y )) / lod * lod - lod;
+ xt1 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * (y + lod))) / lod * lod - lod;
+
+ if (xt0 > xt1) xt0 = xt1;
+ if (xt0 > xs) xs = xt0;
+ }
+ for (fli = right.begin(); fli != right.end(); fli++) {
+ xt0 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * y )) / lod * lod + lod;
+ xt1 = ((int) (fli->base / (SQUARE_SIZE) + fli->dir * (y + lod))) / lod * lod + lod;
+
+ if (xt0 < xt1) xt0 = xt1;
+ if (xt0 < xe) xe = xt0;
+ }
+
+
+ if (xs < xe) {
+ x = xs;
+ int nloop=(xe-xs)/lod+2; // one extra for if statment
+ ma->EnlargeArrays(2*nloop, 1);
+ if (x % (dlod)) {
+ int idx1 = CLAMP((y) * heightDataX + x),
+ idx1PLOD = CLAMP(idx1 + lod),
+ idx1MLOD = CLAMP(idx1 - lod);
+ float h = ((heightData[idx1MLOD] +
+ heightData[idx1PLOD]) * 0.5f) * (camypart) +
+ heightData[idx1 ] * (1 - camypart);
+
+ DrawVertexAMT(ma, x, y, h);
+ DrawVertexAMT(ma, x, y + lod );
+ } else {
+ DrawVertexAMT(ma, x, y );
+ DrawVertexAMT(ma, x, y + lod);
+ }
+
+ for (x = xs; x < xe; x+= lod) {
+ if (x % (dlod)) {
+ DrawVertexAMT(ma, x + lod, y );
+ DrawVertexAMT(ma, x + lod, y + lod);
+ } else {
+ int idx1 = CLAMP((y) * heightDataX + x),
+ idx1PLOD = CLAMP(idx1 + lod),
+ idx1PLOD2 = CLAMP(idx1 + dlod);
+ float h = (heightData[idx1PLOD2] +
+ heightData[idx1 ]) * 0.5f * (camypart) +
+ heightData[idx1PLOD ] * (1 - camypart);
+
+ DrawVertexAMT(ma, x + lod, y, h);
+ DrawVertexAMT(ma, x + lod, y + lod );
+ }
+ }
+ EndStripMT(ma);
+ }
+ }
+ }
+ DrawGroundVertexArrayMT(ma);
+ }
+ return true;
+}
+
void CBFGroundDrawer::Draw(bool drawWaterReflection, bool drawUnitReflection, unsigned int overrideVP)
{
@@ -161,8 +665,8 @@ void CBFGroundDrawer::Draw(bool drawWaterReflection, bool drawUnitReflection, un
textures->DrawUpdate();
int x, y;
- const int neededLod = int((gu->viewRange * 0.125f) / viewRadius) << 1;
- const int maxIdx = ((gs->mapx + 1) * (gs->mapy + 1)) - 1;
+ neededLod = int((gu->viewRange * 0.125f) / viewRadius) << 1;
+ maxIdx = ((gs->mapx + 1) * (gs->mapy + 1)) - 1;
#define CLAMP(i) std::max(0, std::min((i), maxIdx))
UpdateCamRestraints();
@@ -186,6 +690,10 @@ void CBFGroundDrawer::Draw(bool drawWaterReflection, bool drawUnitReflection, un
float camxpart = 0.0f, oldcamxpart;
float camypart = 0.0f, oldcamypart;
+#if GML_ENABLE_DRAWGROUND
+ mt_overrideVP=overrideVP;
+ gmlProcessor.Work(NULL,&CBFGroundDrawer::DrawMTcb,NULL,this,gmlThreadCount,FALSE,NULL,numBigTexY,50,100,TRUE,NULL);
+#else
for (int bty = 0; bty < numBigTexY; ++bty) {
if (!BigTexSquareRowVisible(bty)) {
// skip this entire row of squares if we can't see it
@@ -625,6 +1133,7 @@ void CBFGroundDrawer::Draw(bool drawWaterReflection, bool drawUnitReflection, un
DrawGroundVertexArray();
}
}
+#endif
ResetTextureUnits(drawWaterReflection, overrideVP);
glDisable(GL_CULL_FACE);
@@ -694,6 +1203,286 @@ void CBFGroundDrawer::Draw(bool drawWaterReflection, bool drawUnitReflection, un
}
+bool CBFGroundDrawer::DrawShadowPassMT(int nlod) {
+ CVertexArray *ma = GetVertexArray();
+ ma->Initialize();
+
+ bool inStrip=false;
+ int x,y;
+ int lod=1<<nlod;
+
+ float cx2 = (camera->pos.x / (SQUARE_SIZE));
+ float cy2 = (camera->pos.z / (SQUARE_SIZE));
+
+ float oldcamxpart = 0.0f;
+ float oldcamypart = 0.0f;
+
+ int hlod = lod >> 1;
+ int dlod = lod << 1;
+
+ int cx = (int)cx2;
+ int cy = (int)cy2;
+ if(lod>1) {
+ int cxo = (cx / hlod) * hlod;
+ int cyo = (cy / hlod) * hlod;
+ float cx2o = (cxo / lod) * lod;
+ float cy2o = (cyo / lod) * lod;
+ oldcamxpart = (cx2 - cx2o) / (lod);
+ oldcamypart = (cy2 - cy2o) / (lod);
+ }
+
+ cx = (cx / lod) * lod;
+ cy = (cy / lod) * lod;
+ int ysquaremod = ((cy) % (dlod)) / lod;
+ int xsquaremod = ((cx) % (dlod)) / lod;
+
+ float camxpart = (cx2 - ((cx / (dlod)) * dlod)) / (dlod);
+ float camypart = (cy2 - ((cy / (dlod)) * dlod)) / (dlod);
+
+ int minty = 0;
+ int maxty = gs->mapy;
+ int mintx = 0;
+ int maxtx = gs->mapx;
+
+ int minly = cy + (-viewRadius + 3 - ysquaremod) * lod;
+ int maxly = cy + ( viewRadius - 1 - ysquaremod) * lod;
+ int minlx = cx + (-viewRadius + 3 - xsquaremod) * lod;
+ int maxlx = cx + ( viewRadius - 1 - xsquaremod) * lod;
+
+ int xstart = max(minlx, mintx);
+ int xend = min(maxlx, maxtx);
+ int ystart = max(minly, minty);
+ int yend = min(maxly, maxty);
+
+ for (y = ystart; y < yend; y += lod) {
+ int xs = xstart;
+ int xe = xend;
+
+ int nloop=(xe-xs)/lod+1;
+ ma->EnlargeArrays(52*nloop, 14*nloop+1); // includes one extra for final endstrip
+ for (x = xs; x < xe; x += lod) {
+ if ((lod == 1) ||
+ (x > (cx) + viewRadius * hlod) || (x < (cx) - viewRadius * hlod) ||
+ (y > (cy) + viewRadius * hlod) || (y < (cy) - viewRadius * hlod)) {
+ if (!inStrip) {
+ DrawVertexAMT(ma, x, y );
+ DrawVertexAMT(ma, x, y + lod);
+ inStrip = true;
+ }
+ DrawVertexAMT(ma, x + lod, y );
+ DrawVertexAMT(ma, x + lod, y + lod);
+ } else { //inre begr�sning mot f�eg�nde lod
+ if((x>=(cx)+viewRadius*hlod)){
+ float h1=(heightData[(y)*heightDataX+x]+heightData[(y+lod)*heightDataX+x])*0.5f*(1-oldcamxpart)+heightData[(y+hlod)*heightDataX+x]*(oldcamxpart);
+ float h2=(heightData[(y)*heightDataX+x]+heightData[(y)*heightDataX+x+lod])*0.5f*(1-oldcamxpart)+heightData[(y)*heightDataX+x+hlod]*(oldcamxpart);
+ float h3=(heightData[(y+lod)*heightDataX+x]+heightData[(y)*heightDataX+x+lod])*0.5f*(1-oldcamxpart)+heightData[(y+hlod)*heightDataX+x+hlod]*(oldcamxpart);
+ float h4=(heightData[(y+lod)*heightDataX+x]+heightData[(y+lod)*heightDataX+x+lod])*0.5f*(1-oldcamxpart)+heightData[(y+lod)*heightDataX+x+hlod]*(oldcamxpart);
+
+ if(inStrip){
+ EndStripMT(ma);
+ inStrip=false;
+ }
+ DrawVertexAMT(ma, x,y);
+ DrawVertexAMT(ma, x,y+hlod,h1);
+ DrawVertexAMT(ma, x+hlod,y,h2);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x,y+hlod,h1);
+ DrawVertexAMT(ma, x,y+lod);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ DrawVertexAMT(ma, x+hlod,y+lod,h4);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x+hlod,y+lod,h4);
+ DrawVertexAMT(ma, x+lod,y+lod);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ DrawVertexAMT(ma, x+lod,y);
+ DrawVertexAMT(ma, x+hlod,y,h2);
+ EndStripMT(ma);
+ }
+ if((x<=(cx)-viewRadius*hlod)){
+ float h1=(heightData[(y)*heightDataX+x+lod]+heightData[(y+lod)*heightDataX+x+lod])*0.5f*(oldcamxpart)+heightData[(y+hlod)*heightDataX+x+lod]*(1-oldcamxpart);
+ float h2=(heightData[(y)*heightDataX+x]+heightData[(y)*heightDataX+x+lod])*0.5f*(oldcamxpart)+heightData[(y)*heightDataX+x+hlod]*(1-oldcamxpart);
+ float h3=(heightData[(y+lod)*heightDataX+x]+heightData[(y)*heightDataX+x+lod])*0.5f*(oldcamxpart)+heightData[(y+hlod)*heightDataX+x+hlod]*(1-oldcamxpart);
+ float h4=(heightData[(y+lod)*heightDataX+x]+heightData[(y+lod)*heightDataX+x+lod])*0.5f*(oldcamxpart)+heightData[(y+lod)*heightDataX+x+hlod]*(1-oldcamxpart);
+
+ if(inStrip){
+ EndStripMT(ma);
+ inStrip=false;
+ }
+ DrawVertexAMT(ma, x+lod,y+hlod,h1);
+ DrawVertexAMT(ma, x+lod,y);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ DrawVertexAMT(ma, x+hlod,y,h2);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x+lod,y+lod);
+ DrawVertexAMT(ma, x+lod,y+hlod,h1);
+ DrawVertexAMT(ma, x+hlod,y+lod,h4);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x+hlod,y,h2);
+ DrawVertexAMT(ma, x,y);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ DrawVertexAMT(ma, x,y+lod);
+ DrawVertexAMT(ma, x+hlod,y+lod,h4);
+ EndStripMT(ma);
+ }
+ if((y>=(cy)+viewRadius*hlod)){
+ float h1=(heightData[(y)*heightDataX+x]+heightData[(y)*heightDataX+x+lod])*0.5f*(1-oldcamypart)+heightData[(y)*heightDataX+x+hlod]*(oldcamypart);
+ float h2=(heightData[(y)*heightDataX+x]+heightData[(y+lod)*heightDataX+x])*0.5f*(1-oldcamypart)+heightData[(y+hlod)*heightDataX+x]*(oldcamypart);
+ float h3=(heightData[(y+lod)*heightDataX+x]+heightData[(y)*heightDataX+x+lod])*0.5f*(1-oldcamypart)+heightData[(y+hlod)*heightDataX+x+hlod]*(oldcamypart);
+ float h4=(heightData[(y+lod)*heightDataX+x+lod]+heightData[(y)*heightDataX+x+lod])*0.5f*(1-oldcamypart)+heightData[(y+hlod)*heightDataX+x+lod]*(oldcamypart);
+
+ if(inStrip){
+ EndStripMT(ma);
+ inStrip=false;
+ }
+ DrawVertexAMT(ma, x,y);
+ DrawVertexAMT(ma, x,y+hlod,h2);
+ DrawVertexAMT(ma, x+hlod,y,h1);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ DrawVertexAMT(ma, x+lod,y);
+ DrawVertexAMT(ma, x+lod,y+hlod,h4);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x,y+hlod,h2);
+ DrawVertexAMT(ma, x,y+lod);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ DrawVertexAMT(ma, x+lod,y+lod);
+ DrawVertexAMT(ma, x+lod,y+hlod,h4);
+ EndStripMT(ma);
+ }
+ if((y<=(cy)-viewRadius*hlod)){
+ float h1=(heightData[(y+lod)*heightDataX+x]+heightData[(y+lod)*heightDataX+x+lod])*0.5f*(oldcamypart)+heightData[(y+lod)*heightDataX+x+hlod]*(1-oldcamypart);
+ float h2=(heightData[(y)*heightDataX+x]+heightData[(y+lod)*heightDataX+x])*0.5f*(oldcamypart)+heightData[(y+hlod)*heightDataX+x]*(1-oldcamypart);
+ float h3=(heightData[(y+lod)*heightDataX+x]+heightData[(y)*heightDataX+x+lod])*0.5f*(oldcamypart)+heightData[(y+hlod)*heightDataX+x+hlod]*(1-oldcamypart);
+ float h4=(heightData[(y+lod)*heightDataX+x+lod]+heightData[(y)*heightDataX+x+lod])*0.5f*(oldcamypart)+heightData[(y+hlod)*heightDataX+x+lod]*(1-oldcamypart);
+
+ if(inStrip){
+ EndStripMT(ma);
+ inStrip=false;
+ }
+ DrawVertexAMT(ma, x,y+hlod,h2);
+ DrawVertexAMT(ma, x,y+lod);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ DrawVertexAMT(ma, x+hlod,y+lod,h1);
+ DrawVertexAMT(ma, x+lod,y+hlod,h4);
+ DrawVertexAMT(ma, x+lod,y+lod);
+ EndStripMT(ma);
+ DrawVertexAMT(ma, x+lod,y+hlod,h4);
+ DrawVertexAMT(ma, x+lod,y);
+ DrawVertexAMT(ma, x+hlod,y+hlod,h3);
+ DrawVertexAMT(ma, x,y);
+ DrawVertexAMT(ma, x,y+hlod,h2);
+ EndStripMT(ma);
+ }
+ }
+ }
+ if(inStrip){
+ EndStripMT(ma);
+ inStrip=false;
+ }
+ }
+
+ int yst=max(ystart - lod, minty);
+ int yed=min(yend + lod, maxty);
+ int nloop=(yed-yst)/lod+1;
+ ma->EnlargeArrays(8*nloop, 2*nloop);
+ //rita yttre begr�snings yta mot n�ta lod
+ if(maxlx<maxtx && maxlx>=mintx){
+ x=maxlx;
+ for(y=yst;y<yed;y+=lod){
+ DrawVertexAMT(ma, x,y);
+ DrawVertexAMT(ma, x,y+lod);
+ if(y%(lod*2)){
+ float h=((heightData[(y-lod)*heightDataX+x+lod]+heightData[(y+lod)*heightDataX+x+lod])*0.5f)*(1-camxpart)+heightData[(y)*heightDataX+x+lod]*(camxpart);
+ DrawVertexAMT(ma, x+lod,y,h);
+ DrawVertexAMT(ma, x+lod,y+lod);
+ } else {
+ DrawVertexAMT(ma, x+lod,y);
+ float h=(heightData[(y)*heightDataX+x+lod]+heightData[(y+lod*2)*heightDataX+x+lod])*0.5f*(1-camxpart)+heightData[(y+lod)*heightDataX+x+lod]*(camxpart);
+ DrawVertexAMT(ma, x+lod,y+lod,h);
+ }
+ EndStripMT(ma);
+ }
+ }
+ if(minlx>mintx && minlx<maxtx){
+ x=minlx-lod;
+ for(y=yst;y<yed;y+=lod){
+ if(y%(lod*2)){
+ float h=((heightData[(y-lod)*heightDataX+x]+heightData[(y+lod)*heightDataX+x])*0.5f)*(camxpart)+heightData[(y)*heightDataX+x]*(1-camxpart);
+ DrawVertexAMT(ma, x,y,h);
+ DrawVertexAMT(ma, x,y+lod);
+ } else {
+ DrawVertexAMT(ma, x,y);
+ float h=(heightData[(y)*heightDataX+x]+heightData[(y+lod*2)*heightDataX+x])*0.5f*(camxpart)+heightData[(y+lod)*heightDataX+x]*(1-camxpart);
+ DrawVertexAMT(ma, x,y+lod,h);
+ }
+ DrawVertexAMT(ma, x+lod,y);
+ DrawVertexAMT(ma, x+lod,y+lod);
+ EndStripMT(ma);
+ }
+ }
+ if(maxly<maxty && maxly>minty){
+ y=maxly;
+ int xs=max(xstart-lod,mintx);
+ int xe=min(xend+lod,maxtx);
+ if(xs<xe){
+ x=xs;
+ int nloop=(xe-xs)/lod+2; // one extra for if statment
+ ma->EnlargeArrays(2*nloop, 1);
+ if(x%(lod*2)){
+ DrawVertexAMT(ma, x,y);
+ float h=((heightData[(y+lod)*heightDataX+x-lod]+heightData[(y+lod)*heightDataX+x+lod])*0.5f)*(1-camypart)+heightData[(y+lod)*heightDataX+x]*(camypart);
+ DrawVertexAMT(ma, x,y+lod,h);
+ } else {
+ DrawVertexAMT(ma, x,y);
+ DrawVertexAMT(ma, x,y+lod);
+ }
+ for(x=xs;x<xe;x+=lod){
+ if(x%(lod*2)){
+ DrawVertexAMT(ma, x+lod,y);
+ DrawVertexAMT(ma, x+lod,y+lod);
+ } else {
+ DrawVertexAMT(ma, x+lod,y);
+ float h=(heightData[(y+lod)*heightDataX+x+2*lod]+heightData[(y+lod)*heightDataX+x])*0.5f*(1-camypart)+heightData[(y+lod)*heightDataX+x+lod]*(camypart);
+ DrawVertexAMT(ma, x+lod,y+lod,h);
+ }
+ }
+ EndStripMT(ma);
+ }
+ }
+ if(minly>minty && minly<maxty){
+ y=minly-lod;
+ int xs=max(xstart-lod,mintx);
+ int xe=min(xend+lod,maxtx);
+ if(xs<xe){
+ x=xs;
+ int nloop=(xe-xs)/lod+2; // one extra for if statment
+ ma->EnlargeArrays(2*nloop, 1);
+ if(x%(lod*2)){
+ float h=((heightData[(y)*heightDataX+x-lod]+heightData[(y)*heightDataX+x+lod])*0.5f)*(camypart)+heightData[(y)*heightDataX+x]*(1-camypart);
+ DrawVertexAMT(ma, x,y,h);
+ DrawVertexAMT(ma, x,y+lod);
+ } else {
+ DrawVertexAMT(ma, x,y);
+ DrawVertexAMT(ma, x,y+lod);
+ }
+ for(x=xs;x<xe;x+=lod){
+ if(x%(lod*2)){
+ DrawVertexAMT(ma, x+lod,y);
+ DrawVertexAMT(ma, x+lod,y+lod);
+ } else {
+ float h=(heightData[(y)*heightDataX+x+2*lod]+heightData[(y)*heightDataX+x])*0.5f*(camypart)+heightData[(y)*heightDataX+x+lod]*(1-camypart);
+ DrawVertexAMT(ma, x+lod,y,h);
+ DrawVertexAMT(ma, x+lod,y+lod);
+ }
+ }
+ EndStripMT(ma);
+ }
+ }
+
+ DrawGroundVertexArrayMT(ma);
+ return true;
+}
void CBFGroundDrawer::DrawShadowPass(void)
@@ -715,6 +1504,9 @@ void CBFGroundDrawer::DrawShadowPass(void)
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, groundShadowVP);
glEnable(GL_VERTEX_PROGRAM_ARB);
+#if GML_ENABLE_DRAWGROUNDSHADOW
+ gmlProcessor.Work(NULL,&CBFGroundDrawer::DrawShadowPassMTcb,NULL,this,gmlThreadCount,FALSE,NULL,NUM_LODS+1,50,100,TRUE,NULL);
+#else
for (int lod = 1; lod < (2 << NUM_LODS); lod *= 2) {
int cx = (((int) (camera->pos.x / SQUARE_SIZE)) / lod) * lod;
int cy = (((int) (camera->pos.z / SQUARE_SIZE)) / lod) * lod;
@@ -964,6 +1756,7 @@ void CBFGroundDrawer::DrawShadowPass(void)
DrawGroundVertexArray();
}
+#endif
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_CULL_FACE);
11 rts/Map/SMF/BFGroundDrawer.h
View
@@ -52,6 +52,17 @@ class CBFGroundDrawer :
unsigned int groundFPShadow;
bool waterDrawn;
+ volatile unsigned int mt_overrideVP;
+
+ bool DrawMT(int bty);
+ static void DrawMTcb(void *c,int bty) {((CBFGroundDrawer *)c)->DrawMT(bty);}
+ void DrawVertexAMT(CVertexArray *ma, int x, int y);
+ void DrawVertexAMT(CVertexArray *ma, int x, int y, float height);
+ void EndStripMT(CVertexArray *ma);
+ void DrawGroundVertexArrayMT(CVertexArray * &ma);
+ bool DrawShadowPassMT(int nlod);
+ static void DrawShadowPassMTcb(void *c,int nlod) {((CBFGroundDrawer *)c)->DrawShadowPassMT(nlod);}
+
inline void DrawVertexA(int x, int y);
inline void DrawVertexA(int x, int y, float height);
inline void EndStrip();
3  rts/Map/SMF/BFGroundTextures.h
View
@@ -4,8 +4,7 @@
#ifndef __BF_GROUND_TEXTURES_H__
#define __BF_GROUND_TEXTURES_H__
-#define GLEW_STATIC
-#include <GL/glew.h>
+#include "Rendering/GL/myGL.h"
class CFileHandler;
class CSmfReadMap;
20 rts/Map/SMF/SmfReadMap.cpp
View
@@ -16,6 +16,9 @@
#include "bitops.h"
#include "mmgr.h"
+#include "lib/gml/gmlsrv.h"
+extern gmlClientServer<void, int,CUnit*> gmlProcessor;
+
using namespace std;
CR_BIND_DERIVED(CSmfReadMap, CReadMap, (""))
@@ -302,7 +305,6 @@ void CSmfReadMap::DrawMinimap ()
glActiveTextureARB(GL_TEXTURE0_ARB);
}
-
void CSmfReadMap::GridVisibility (CCamera *cam, int quadSize, float maxdist, CReadMap::IQuadDrawer *qd, int extraSize)
{
int cx=(int)(cam->pos.x/(SQUARE_SIZE*quadSize));
@@ -319,15 +321,17 @@ void CSmfReadMap::GridVisibility (CCamera *cam, int quadSize, float maxdist, CRe
if(ey>=header.mapy/quadSize)
ey=header.mapy/quadSize-1;
+ int sxi=cx-drawSquare;
+ if(sxi<0)
+ sxi=0;
+ int exi=cx+drawSquare;
+ if(exi>drawQuadsX-1)
+ exi=drawQuadsX-1;
+
for(int y=sy;y<=ey;y++){
- int sx=cx-drawSquare;
- if(sx<0)
- sx=0;
- int ex=cx+drawSquare;
- if(ex>drawQuadsX-1)
- ex=drawQuadsX-1;
+ int sx=sxi;
+ int ex=exi;
float xtest,xtest2;
-
std::vector<CBFGroundDrawer::fline>::iterator fli;
for(fli=groundDrawer->left.begin();fli!=groundDrawer->left.end();fli++){
xtest=((fli->base/SQUARE_SIZE+fli->dir*(y*quadSize)));
57 rts/Rendering/Env/AdvTreeDrawer.cpp
View
@@ -393,38 +393,39 @@ void CAdvTreeDrawer::Draw(float treeDistance,bool drawReflection)
}
}
}
- //draw trees that has been marked as falling
- glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,10,0,0,0,0);
- glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,13, camera->right.x,camera->right.y,camera->right.z,0);
- glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,9, camera->up.x,camera->up.y,camera->up.z,0);
- for(std::list<FallingTree>::iterator fti=fallingTrees.begin();fti!=fallingTrees.end();){
- float3 pos=fti->pos-UpVector*(fti->fallPos*20);
- if(camera->InView(pos+float3(0,MAX_TREE_HEIGHT/2,0),MAX_TREE_HEIGHT/2)){
- float ang=fti->fallPos*PI;
- float3 up(fti->dir.x*sin(ang),cos(ang),fti->dir.z*sin(ang));
- float3 z(up.cross(float3(-1,0,0)));
- z.Normalize();
- float3 x(up.cross(z));
- CMatrix44f transMatrix(pos,x,up,z);
-
- glPushMatrix();
- glMultMatrixf(&transMatrix[0]);
-
- int type=fti->type;
- int displist;
- if(type<8){
- displist=treeGen->pineDL+type;
- } else {
- type-=8;
- displist=treeGen->leafDL+type;
- }
- glCallList(displist);
+ }
+ //draw trees that has been marked as falling
+ glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,10,0,0,0,0);
+ glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,13, camera->right.x,camera->right.y,camera->right.z,0);
+ glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,9, camera->up.x,camera->up.y,camera->up.z,0);
+ for(std::list<FallingTree>::iterator fti=fallingTrees.begin();fti!=fallingTrees.end();){
+ float3 pos=fti->pos-UpVector*(fti->fallPos*20);
+ if(camera->InView(pos+float3(0,MAX_TREE_HEIGHT/2,0),MAX_TREE_HEIGHT/2)){
+ float ang=fti->fallPos*PI;
+ float3 up(fti->dir.x*sin(ang),cos(ang),fti->dir.z*sin(ang));
+ float3 z(up.cross(float3(-1,0,0)));
+ z.Normalize();
+ float3 x(up.cross(z));
+ CMatrix44f transMatrix(pos,x,up,z);
+
+ glPushMatrix();
+ glMultMatrixf(&transMatrix[0]);
- glPopMatrix();
+ int type=fti->type;
+ int displist;
+ if(type<8){
+ displist=treeGen->pineDL+type;
+ } else {
+ type-=8;
+ displist=treeGen->leafDL+type;
}
- ++fti;
+ glCallList(displist);
+
+ glPopMatrix();
}
+ ++fti;
}
+
glDisable( GL_VERTEX_PROGRAM_ARB );
if(shadowHandler->drawShadows && !gd->DrawExtraTex()){
1  rts/Rendering/Env/GrassDrawer.cpp
View
@@ -6,7 +6,6 @@
#include "Map/ReadMap.h"
#include "Map/BaseGroundDrawer.h"
#include "Rendering/GL/myGL.h"
-#include <GL/glu.h>
#include "AdvTreeDrawer.h"
#include "Rendering/Textures/Bitmap.h"
#include "LogOutput.h"
207 rts/Rendering/GL/VertexArray.cpp
View
@@ -6,184 +6,167 @@
#include "VertexArray.h"
#include "myGL.h"
#include "mmgr.h"
-#include <GL/glew.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-CVertexArray::CVertexArray()
-{
+CVertexArray::CVertexArray() {
drawArray=SAFE_NEW float[1000];
stripArray=SAFE_NEW int[100];
+ Initialize();
+ drawArraySize=drawArray+1000;
+ stripArraySize=stripArray+100;
+}
- drawArraySize=1000;
- stripArraySize=100;
+CVertexArray::~CVertexArray() {
+ delete [] drawArray;
+ delete [] stripArray;
}
-CVertexArray::~CVertexArray()
-{
- delete[] drawArray;
- delete[] stripArray;
+void CVertexArray::Initialize() {
+ drawArrayPos=drawArray;
+ stripArrayPos=stripArray;
}
-void CVertexArray::Initialize()
-{
- stripIndex=0;
- drawIndex=0;
+int CVertexArray::drawIndex() {
+ return drawArrayPos-drawArray;
}
-bool CVertexArray::IsReady()
-{
+bool CVertexArray::IsReady() {
return true;
}
-void CVertexArray::EndStrip()
-{
- if(stripIndex>stripArraySize-4)
+void CVertexArray::EndStrip() {
+ if((char *)stripArrayPos>(char *)stripArraySize-4*sizeof(int))
EnlargeStripArray();
- stripArray[stripIndex++]=drawIndex;
+ *stripArrayPos++=((char *)drawArrayPos-(char *)drawArray);
}
-void CVertexArray::DrawArray0(int drawType,int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
+void CVertexArray::EnlargeArrays(int vertexes, int strips, int stripsize) {
+ while((char *)drawArrayPos>(char *)drawArraySize-stripsize*sizeof(float)*vertexes)
+ EnlargeDrawArray();
- glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
- glEnableClientState(GL_VERTEX_ARRAY);
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
+ while((char *)stripArrayPos>(char *)stripArraySize-sizeof(int)*strips)
+ EnlargeStripArray();
+}
+
+void CVertexArray::EndStripQ() {
+ *stripArrayPos++=((char *)drawArrayPos-(char *)drawArray);
+}
+
+void CVertexArray::DrawArrays(int drawType, int stride) {
+ int newIndex,oldIndex=0;
+ int *stripArrayPtr=stripArray;
+ while(stripArrayPtr<stripArrayPos) {
+ newIndex=(*stripArrayPtr++)/stride;
+ glDrawArrays(drawType,oldIndex,newIndex-oldIndex);
+ oldIndex=newIndex;
}
- glDisableClientState(GL_VERTEX_ARRAY);
}
-void CVertexArray::DrawArrayC(int drawType,int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
+void CVertexArray::DrawArray0(int drawType,int stride) {
+ CheckEndStrip();
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(3,GL_FLOAT,stride,drawArray);
+ DrawArrays(drawType, stride);
+ glDisableClientState(GL_VERTEX_ARRAY);
+}
+void CVertexArray::DrawArrayC(int drawType,int stride) {
+ CheckEndStrip();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
- glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
- glColorPointer(4,GL_UNSIGNED_BYTE,stride,&drawArray[3]);
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
- }
- glDisableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(3,GL_FLOAT,stride,drawArray);
+ glColorPointer(4,GL_UNSIGNED_BYTE,stride,drawArray+3);
+ DrawArrays(drawType, stride);
+ glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
-void CVertexArray::DrawArrayT(int drawType,int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
-
+void CVertexArray::DrawArrayT(int drawType,int stride) {
+ CheckEndStrip();
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
- glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[3]);
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
- }
+ glVertexPointer(3,GL_FLOAT,stride,drawArray);
+ glTexCoordPointer(2,GL_FLOAT,stride,drawArray+3);
+ DrawArrays(drawType, stride);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
-void CVertexArray::DrawArrayT2(int drawType,int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
-
+void CVertexArray::DrawArrayT2(int drawType,int stride) {
+ CheckEndStrip();
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
- glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[3]);
+ glVertexPointer(3,GL_FLOAT,stride,drawArray);
+ glTexCoordPointer(2,GL_FLOAT,stride,drawArray+3);
+
glClientActiveTextureARB(GL_TEXTURE1_ARB);
- glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[5]);
+ glTexCoordPointer(2,GL_FLOAT,stride,drawArray+5);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
-
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
- }
+ DrawArrays(drawType, stride);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
}
-void CVertexArray::DrawArrayTN(int drawType, int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
-
+void CVertexArray::DrawArrayTN(int drawType, int stride) {
+ CheckEndStrip();
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
- glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
- glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[3]);
- glNormalPointer(GL_FLOAT,stride,&drawArray[5]);
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
- }
+ glVertexPointer(3,GL_FLOAT,stride,drawArray);
+ glTexCoordPointer(2,GL_FLOAT,stride,drawArray+3);
+ glNormalPointer(GL_FLOAT,stride,drawArray+5);
+ DrawArrays(drawType, stride);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
-void CVertexArray::DrawArrayTC(int drawType, int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
-
+void CVertexArray::DrawArrayTC(int drawType, int stride) {
+ CheckEndStrip();
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
- glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
- glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[3]);
- glColorPointer(4,GL_UNSIGNED_BYTE,stride,&drawArray[5]);
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
- }
+ glVertexPointer(3,GL_FLOAT,stride,drawArray);
+ glTexCoordPointer(2,GL_FLOAT,stride,drawArray+3);
+ glColorPointer(4,GL_UNSIGNED_BYTE,stride,drawArray+5);
+ DrawArrays(drawType, stride);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
-void CVertexArray::EnlargeDrawArray()
-{
- float* tempArray=SAFE_NEW float[drawArraySize*2];
- for(int a=0;a<drawIndex;++a)
- tempArray[a]=drawArray[a];
+void CVertexArray::EnlargeDrawArray() {
+ int pos=drawArrayPos-drawArray;
+ int oldsize=drawArraySize-drawArray;
+ int newsize=oldsize*2;
+ float* tempArray=SAFE_NEW float[newsize];
+ memcpy(tempArray,drawArray,oldsize*sizeof(float));
- drawArraySize*=2;
- delete[] drawArray;
+ delete [] drawArray;
drawArray=tempArray;
+ drawArraySize=drawArray+newsize;
+ drawArrayPos=drawArray+pos;
}
-void CVertexArray::EnlargeStripArray()
-{
- int* tempArray=SAFE_NEW int[stripArraySize*2];
- for(int a=0;a<stripIndex;++a)
- tempArray[a]=stripArray[a];
+void CVertexArray::EnlargeStripArray() {
+ int pos=stripArrayPos-stripArray;
+ int oldsize=stripArraySize-stripArray;
+ int newsize=oldsize*2;
+
+ int* tempArray=SAFE_NEW int[newsize];
+ memcpy(tempArray,stripArray,oldsize*sizeof(int));
- stripArraySize*=2;
- delete[] stripArray;
+ delete [] stripArray;
stripArray=tempArray;
+ stripArraySize=stripArray+newsize;
+ stripArrayPos=stripArray+pos;
}
140 rts/Rendering/GL/VertexArray.h
View
@@ -4,15 +4,12 @@
//
//////////////////////////////////////////////////////////////////////
-#include "myGL.h"
-
-class CVertexArray
+class CVertexArray
{
public:
CVertexArray();
~CVertexArray();
void Initialize();
- bool IsReady();
inline void AddVertexTC(const float3 &pos,float tx,float ty,unsigned char* color);
void DrawArrayTC(int drawType,int stride=24);
@@ -26,97 +23,102 @@ class CVertexArray
void DrawArray0(int drawType,int stride=12);
inline void AddVertexC(const float3& pos,unsigned char* color);
void DrawArrayC(int drawType,int stride=16);
-
void EnlargeStripArray();
void EnlargeDrawArray();
void EndStrip();
+ bool IsReady();
+ inline void CheckEnlargeDrawArray();
+ void CheckEndStrip();
+ void DrawArrays(int drawType, int stride);
+ void EnlargeArrays(int vertexes, int strips, int stripsize=3);
+ void EndStripQ();
+ inline void AddVertexQ0(float x, float y, float z);
+
+ int drawIndex();
float* drawArray;
- int drawArraySize;
- int drawIndex;
+ float* drawArrayPos;
+ float* drawArraySize;
int* stripArray;
- int stripArraySize;
- int stripIndex;
+ int* stripArrayPos;
+ int* stripArraySize;
};
-/***************************************************************************************************/
-/***************************************************************************************************/
-
-inline void CVertexArray::AddVertexTC(const float3 &pos,float tx,float ty,unsigned char* color)
-{
- if(drawIndex>drawArraySize-10)
+inline void CVertexArray::CheckEnlargeDrawArray() {
+ if((char *)drawArrayPos>(char *)drawArraySize-10*sizeof(float))
EnlargeDrawArray();
+}
- drawArray[drawIndex++]=pos.x;
- drawArray[drawIndex++]=pos.y;
- drawArray[drawIndex++]=pos.z;
- drawArray[drawIndex++]=tx;
- drawArray[drawIndex++]=ty;
- drawArray[drawIndex++]=*((float*)(color));
+inline void CVertexArray::AddVertexQ0(float x, float y, float z) {
+ *drawArrayPos++=x;
+ *drawArrayPos++=y;
+ *drawArrayPos++=z;
}
-inline void CVertexArray::AddVertexTN(const float3 &pos,float tx,float ty,const float3& norm)
-{
- if(drawIndex>drawArraySize-10)
+inline void CVertexArray::AddVertex0(const float3& pos) {
+ if(drawArrayPos>drawArraySize-10)
EnlargeDrawArray();
- drawArray[drawIndex++]=pos.x;
- drawArray[drawIndex++]=pos.y;
- drawArray[drawIndex++]=pos.z;
- drawArray[drawIndex++]=tx;
- drawArray[drawIndex++]=ty;
- drawArray[drawIndex++]=norm.x;
- drawArray[drawIndex++]=norm.y;
- drawArray[drawIndex++]=norm.z;
+ *drawArrayPos++=pos.x;
+ *drawArrayPos++=pos.y;
+ *drawArrayPos++=pos.z;
}
-inline void CVertexArray::AddVertexT2(const float3& pos,float t1x,float t1y,float t2x,float t2y)
-{
- if(drawIndex>drawArraySize-10)
- EnlargeDrawArray();
-
- drawArray[drawIndex++]=pos.x;
- drawArray[drawIndex++]=pos.y;
- drawArray[drawIndex++]=pos.z;
- drawArray[drawIndex++]=t1x;
- drawArray[drawIndex++]=t1y;
- drawArray[drawIndex++]=t2x;
- drawArray[drawIndex++]=t2y;
+inline void CVertexArray::AddVertexC(const float3& pos,unsigned char* color) {
+ CheckEnlargeDrawArray();
+ *drawArrayPos++=pos.x;
+ *drawArrayPos++=pos.y;
+ *drawArrayPos++=pos.z;
+ *drawArrayPos++=*((float*)(color));
}
-inline void CVertexArray::AddVertexT(const float3& pos,float tx,float ty)
-{
- if(drawIndex>drawArraySize-10)
- EnlargeDrawArray();
+inline void CVertexArray::AddVertexT(const float3& pos,float tx,float ty) {
+ CheckEnlargeDrawArray();
+ *drawArrayPos++=pos.x;
+ *drawArrayPos++=pos.y;
+ *drawArrayPos++=pos.z;
+ *drawArrayPos++=tx;
+ *drawArrayPos++=ty;
+}
- drawArray[drawIndex++]=pos.x;
- drawArray[drawIndex++]=pos.y;
- drawArray[drawIndex++]=pos.z;
- drawArray[drawIndex++]=tx;
- drawArray[drawIndex++]=ty;
+inline void CVertexArray::AddVertexT2(const float3& pos,float tx,float ty,float t2x,float t2y) {
+ CheckEnlargeDrawArray();
+ *drawArrayPos++=pos.x;
+ *drawArrayPos++=pos.y;
+ *drawArrayPos++=pos.z;
+ *drawArrayPos++=tx;
+ *drawArrayPos++=ty;
+ *drawArrayPos++=t2x;
+ *drawArrayPos++=t2y;
}
-inline void CVertexArray::AddVertex0(const float3& pos)
-{
- if(drawIndex>drawArraySize-10)
- EnlargeDrawArray();
+inline void CVertexArray::AddVertexTN(const float3& pos,float tx,float ty,const float3& norm) {
+ CheckEnlargeDrawArray();
+ *drawArrayPos++=pos.x;
+ *drawArrayPos++=pos.y;
+ *drawArrayPos++=pos.z;
+ *drawArrayPos++=tx;
+ *drawArrayPos++=ty;
+ *drawArrayPos++=norm.x;
+ *drawArrayPos++=norm.y;
+ *drawArrayPos++=norm.z;
+}
- drawArray[drawIndex++]=pos.x;
- drawArray[drawIndex++]=pos.y;
- drawArray[drawIndex++]=pos.z;
+inline void CVertexArray::AddVertexTC(const float3& pos,float tx,float ty,unsigned char* col) {
+ CheckEnlargeDrawArray();
+ *drawArrayPos++=pos.x;
+ *drawArrayPos++=pos.y;
+ *drawArrayPos++=pos.z;
+ *drawArrayPos++=tx;
+ *drawArrayPos++=ty;
+ *drawArrayPos++=*((float*)(col));
}
-inline void CVertexArray::AddVertexC(const float3& pos,unsigned char* color)
-{
- if(drawIndex>drawArraySize-10)
- EnlargeDrawArray();
- drawArray[drawIndex++]=pos.x;
- drawArray[drawIndex++]=pos.y;
- drawArray[drawIndex++]=pos.z;
- drawArray[drawIndex++]=*((float*)(color));
+inline void CVertexArray::CheckEndStrip() {
+ if(stripArrayPos==stripArray || *(stripArrayPos-1)!=((char *)drawArrayPos-(char *)drawArray))
+ EndStrip();
}
-
#endif /* VERTEXARRAY_H */
73 rts/Rendering/GL/VertexArrayRange.cpp
View
@@ -10,57 +10,44 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-CVertexArrayRange::CVertexArrayRange(float* mem,int size)
-{
+CVertexArrayRange::CVertexArrayRange(float* mem,int size) {
delete[] drawArray;
drawArray=mem;
- drawArraySize=size;
+ drawArraySize=mem+size;
glGenFencesNV(1, &fence);
glEnableClientState(GL_VERTEX_ARRAY_RANGE_NV);
}
-CVertexArrayRange::~CVertexArrayRange()
-{
+CVertexArrayRange::~CVertexArrayRange() {
glDeleteFencesNV(1,&fence);
}
-void CVertexArrayRange::Initialize()
-{
- stripIndex=0;
- drawIndex=0;
+void CVertexArrayRange::Initialize() {
+ CVertexArray::Initialize();
glFinishFenceNV(fence);
}
-bool CVertexArrayRange::IsReady()
-{
+bool CVertexArrayRange::IsReady() {
return !!glTestFenceNV(fence);
}
-void CVertexArrayRange::DrawArrayT(int drawType,int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
+void CVertexArrayRange::DrawArrayT(int drawType,int stride) {
+ CheckEndStrip();
glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[3]);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
- }
+ DrawArrays(drawType, stride);
glSetFenceNV(fence, GL_ALL_COMPLETED_NV);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
-void CVertexArrayRange::DrawArrayT2(int drawType,int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
+void CVertexArrayRange::DrawArrayT2(int drawType,int stride) {
+ CheckEndStrip();
glEnableClientState(GL_VERTEX_ARRAY_RANGE_NV);
glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[3]);
@@ -71,12 +58,7 @@ void CVertexArrayRange::DrawArrayT2(int drawType,int stride)
glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[5]);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
-
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
- }
+ DrawArrays(drawType, stride);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
@@ -87,10 +69,8 @@ void CVertexArrayRange::DrawArrayT2(int drawType,int stride)
glDisableClientState(GL_VERTEX_ARRAY_RANGE_NV);
}
-void CVertexArrayRange::DrawArrayTN(int drawType, int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
+void CVertexArrayRange::DrawArrayTN(int drawType, int stride) {
+ CheckEndStrip();
// glEnableClientState(GL_VERTEX_ARRAY_RANGE_NV);
glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[3]);
@@ -98,12 +78,7 @@ void CVertexArrayRange::DrawArrayTN(int drawType, int stride)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
-
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
- }
+ DrawArrays(drawType, stride);
glSetFenceNV(fence, GL_ALL_COMPLETED_NV);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
@@ -111,10 +86,8 @@ void CVertexArrayRange::DrawArrayTN(int drawType, int stride)
// glDisableClientState(GL_VERTEX_ARRAY_RANGE_NV);
}
-void CVertexArrayRange::DrawArrayTC(int drawType, int stride)
-{
- if(stripIndex==0 || stripArray[stripIndex-1]!=drawIndex)
- EndStrip();
+void CVertexArrayRange::DrawArrayTC(int drawType, int stride) {
+ CheckEndStrip();
// glDisableClientState(GL_VERTEX_ARRAY_RANGE_NV);
glVertexPointer(3,GL_FLOAT,stride,&drawArray[0]);
glTexCoordPointer(2,GL_FLOAT,stride,&drawArray[3]);
@@ -122,12 +95,7 @@ void CVertexArrayRange::DrawArrayTC(int drawType, int stride)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
-
- int oldIndex=0;
- for(int a=0;a<stripIndex;a++){
- glDrawArrays(drawType,oldIndex*4/stride,stripArray[a]*4/stride-oldIndex*4/stride);
- oldIndex=stripArray[a];
- }
+ DrawArrays(drawType, stride);
glSetFenceNV(fence, GL_ALL_COMPLETED_NV);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
@@ -135,7 +103,6 @@ void CVertexArrayRange::DrawArrayTC(int drawType, int stride)
// glDisableClientState(GL_VERTEX_ARRAY_RANGE_NV);
}
-void CVertexArrayRange::EnlargeDrawArray()
-{
- drawIndex-=40;
+void CVertexArrayRange::EnlargeDrawArray() {
+ drawArrayPos-=40;
}
19 rts/Rendering/GL/myGL.cpp
View
@@ -26,18 +26,35 @@ static CVertexArray* currentVertexArray = NULL;
static GLuint startupTexture = 0;
-
+#if GML_ENABLE
+static CVertexArray vertexArrays1[GML_MAX_NUM_THREADS];
+static CVertexArray vertexArrays2[GML_MAX_NUM_THREADS];
+static CVertexArray* currentVertexArrays[GML_MAX_NUM_THREADS];
+#endif
+//BOOL gmlVertexArrayEnable=0;
/******************************************************************************/
/******************************************************************************/
CVertexArray* GetVertexArray()
{
+#if GML_ENABLE // each thread gets its own array to avoid conflicts
+// if(gmlVertexArrayEnable) {
+ int thread=gmlThreadNumber;
+ if(currentVertexArrays[thread]==&vertexArrays1[thread]){
+ currentVertexArrays[thread]=&vertexArrays2[thread];
+ } else {
+ currentVertexArrays[thread]=&vertexArrays1[thread];
+ }
+ return currentVertexArrays[thread];
+// }
+#else
if(currentVertexArray==vertexArray1){
currentVertexArray=vertexArray2;
} else {
currentVertexArray=vertexArray1;
}
return currentVertexArray;
+#endif
}
4 rts/Rendering/GL/myGL.h
View
@@ -2,9 +2,13 @@
#define MYGL_H
#define GLEW_STATIC
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
#include <string>
#include <GL/glew.h>
+#include "lib/gml/gml.h"
#include "float3.h"
inline void glVertexf3(const float3 &v)
3  rts/Rendering/GroundDecalHandler.cpp
View
@@ -434,7 +434,8 @@ void CGroundDecalHandler::Draw(void)
const int start = 5;
const int stride = 6;
- for (int i = start; i < scar->scarQuads->drawIndex; i += stride) {
+ int sdi=scar->scarQuads->drawIndex();
+ for (int i = start; i < sdi; i += stride) {
scar->scarQuads->drawArray[i] = c;
}
}
2  rts/Rendering/Textures/nv_dds.h
View
@@ -14,7 +14,7 @@
#include "Rendering/GL/myGL.h"
#if defined(__APPLE__)
-#include <OpenGL/gl.h>
+//#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#endif
2  rts/Rendering/UnitModels/3DOParser.cpp
View
@@ -498,7 +498,7 @@ void C3DOParser::DrawSub(S3DO* o)
}
}
va->DrawArrayTN(GL_QUADS);
- if(va2->drawIndex!=0)
+ if(va2->drawIndex()!=0)
va2->DrawArrayTN(GL_TRIANGLES);
}
186 rts/Rendering/UnitModels/UnitDrawer.cpp
View
@@ -42,6 +42,8 @@
#include "Sim/Weapons/Weapon.h"
#include "mmgr.h"
+#include "lib/gml/gmlsrv.h"
+extern gmlClientServer<void, int,CUnit*> gmlProcessor;
CUnitDrawer* unitDrawer;
static bool luaDrawing = false; // FIXME
@@ -277,20 +279,114 @@ inline void CUnitDrawer::DrawUnit(CUnit* unit)
}
+bool CUnitDrawer::DrawUnitMT(CUnit *unit) {
+ bool drawReflection=mt_drawReflection;
+ bool drawRefraction=mt_drawRefraction;
+ CUnit *excludeUnit=mt_excludeUnit;
+#ifdef DIRECT_CONTROL_ALLOWED
+ if (unit == excludeUnit) {
+ return false;
+ }
+#endif
+ if (unit->noDraw) {
+ return false;
+ }
+ if (camera->InView(unit->midPos, unit->radius + 30)) {
+ const unsigned short losStatus = unit->losStatus[gu->myAllyTeam];
+ if ((losStatus & LOS_INLOS) || gu->spectatingFullView) {
+
+ if (drawReflection) {
+ float3 zeroPos;
+ if (unit->midPos.y < 0.0f) {
+ zeroPos = unit->midPos;
+ } else {
+ const float dif = unit->midPos.y - camera->pos.y;
+ zeroPos = camera->pos * (unit->midPos.y / dif) +
+ unit->midPos * (-camera->pos.y / dif);
+ }
+ if (ground->GetApproximateHeight(zeroPos.x, zeroPos.z) > unit->radius) {
+ return false;
+ }
+ }
+
+ if (drawRefraction) {
+ if (unit->pos.y > 0.0f) {
+ return false;
+ }
+ }
+
+ float sqDist = (unit->pos-camera->pos).SqLength();
+ float iconDistMult = unit->unitDef->iconType->GetDistance();
+ float realIconLength = iconLength * (iconDistMult * iconDistMult);
+ if (sqDist>realIconLength) {
+ drawIcon.push_back(unit);
+ unit->isIcon = true;
+ }
+ else {
+ unit->isIcon = false;
+
+ float farLength = unit->sqRadius * unitDrawDistSqr;
+ if (sqDist > farLength) {
+ drawFar.push_back(unit);
+ } else {
+ DrawUnit(unit);
+ }
+
+ if (showHealthBars && (sqDist < (unitDrawDistSqr * 500))) {
+ drawStat.push_back(unit);
+ }
+ }
+ }
+ else if (losStatus & LOS_PREVLOS) {
+ unit->isIcon = true;
+
+ if ((!gameSetup || gameSetup->ghostedBuildings) && !(unit->mobility)) {
+ // it's a building we've had LOS on once,
+ // add it to the vector of cloaked units
+ float sqDist = (unit->pos-camera->pos).SqLength();
+ float iconDistMult = unit->unitDef->iconType->GetDistance();
+ float realIconLength = iconLength * (iconDistMult * iconDistMult);
+
+ if (sqDist < realIconLength) {
+ if (unit->model->textureType) {
+ drawCloakedS3O.push_back(unit);
+ } else {
+ drawCloaked.push_back(unit);
+ }
+ unit->isIcon = false;
+ }
+ }
+ if (losStatus & LOS_INRADAR) {
+ if (!(losStatus & LOS_CONTRADAR)) {
+ drawRadarIcon.push_back(unit);
+ } else if (unit->isIcon) {
+ // this prevents us from drawing icons on top of ghosted buildings
+ drawIcon.push_back(unit);
+ }
+ }
+ } else if (losStatus & LOS_INRADAR) {
+ drawRadarIcon.push_back(unit);
+ }
+ }
+ return true;
+}
+
+
void CUnitDrawer::Draw(bool drawReflection, bool drawRefraction)
{
ASSERT_UNSYNCED_MODE;
- vector<CUnit*> drawFar;
- vector<CUnit*> drawStat;
+ drawFar.clear();
+ drawStat.clear();
+
drawCloaked.clear();
drawCloakedS3O.clear();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glFogfv(GL_FOG_COLOR, mapInfo->atmosphere.fogColor);
- vector<CUnit*> drawIcon;
- vector<CUnit*> drawRadarIcon;
+ drawIcon.clear();
+ drawRadarIcon.clear();
if (drawReflection) {
CUnit::SetLODFactor(LODScale * LODScaleReflection);
@@ -306,9 +402,14 @@ void CUnitDrawer::Draw(bool drawReflection, bool drawRefraction)
CUnit* excludeUnit = drawReflection ? NULL : gu->directControl;
#endif
+#if GML_ENABLE_DRAWUNIT
+ mt_drawReflection=drawReflection;
+ mt_drawRefraction=drawRefraction;
+ mt_excludeUnit=excludeUnit;
+ gmlProcessor.Work(NULL,NULL,&CUnitDrawer::DrawUnitMTcb,this,gmlThreadCount,FALSE,&uh->activeUnits,uh->activeUnits.size(),50,100,TRUE);
+#else
for (std::list<CUnit*>::iterator usi = uh->activeUnits.begin(); usi != uh->activeUnits.end(); ++usi) {
CUnit* unit = *usi;
-
#ifdef DIRECT_CONTROL_ALLOWED
if (unit == excludeUnit) {
continue;
@@ -395,6 +496,7 @@ void CUnitDrawer::Draw(bool drawReflection, bool drawRefraction)
}
}
}
+#endif
std::multimap<int, TempDrawUnit>::iterator ti;
for (ti = tempDrawUnits.begin(); ti != tempDrawUnits.end(); ++ti) {
@@ -423,7 +525,7 @@ void CUnitDrawer::Draw(bool drawReflection, bool drawRefraction)
glEnable(GL_FOG);
glFogfv(GL_FOG_COLOR, mapInfo->atmosphere.fogColor);
- for (vector<CUnit*>::iterator usi = drawFar.begin(); usi != drawFar.end(); usi++) {
+ for (GML_VECTOR<CUnit*>::iterator usi = drawFar.begin(); usi != drawFar.end(); usi++) {
DrawFar(*usi);
}
@@ -432,7 +534,7 @@ void CUnitDrawer::Draw(bool drawReflection, bool drawRefraction)
if (!drawReflection) {
// Draw unit icons and radar blips.
glAlphaFunc(GL_GREATER, 0.5f);
- vector<CUnit*>::iterator ui;
+ GML_VECTOR<CUnit*>::iterator ui;
for (ui = drawIcon.begin(); ui != drawIcon.end(); ++ui) {
DrawIcon(*ui, false);
}
@@ -470,7 +572,7 @@ static void DrawBins(LuaMatType type)
bin->Execute(*currMat);
currMat = (LuaMaterial*)bin;
- const vector<CUnit*>& units = bin->GetUnits();
+ const GML_VECTOR<CUnit*>& units = bin->GetUnits();
const int count = (int)units.size();
for (int i = 0; i < count; i++) {
CUnit* unit = units[i];
@@ -584,6 +686,41 @@ void CUnitDrawer::DrawShadowShaderUnits()
/******************************************************************************/
/******************************************************************************/
+
+bool CUnitDrawer::DrawUnitShadowMT(CUnit *unit) {
+ const unsigned short losStatus = unit->losStatus[gu->myAllyTeam];
+ if (((losStatus & LOS_INLOS) || gu->spectatingFullView) && camera->InView(unit->midPos, unit->radius + 700)) {
+ // FIXME: test against the shadow projection intersection
+ float sqDist = (unit->pos-camera->pos).SqLength();
+ float farLength = unit->sqRadius * unitDrawDistSqr;
+
+ if (sqDist < farLength) {
+ float iconDistMult = unit->unitDef->iconType->GetDistance();
+ float realIconLength = iconLength * (iconDistMult * iconDistMult);
+
+ if (sqDist < realIconLength) {
+ if (!unit->isCloaked) {
+ if (unit->lodCount <= 0) {
+ DrawUnitNow(unit);
+ } else {
+ LuaUnitMaterial& unitMat = unit->luaMats[LUAMAT_SHADOW];
+ const unsigned lod = unit->CalcLOD(unitMat.GetLastLOD());
+ unit->currentLOD = lod;
+ LuaUnitLODMaterial* lodMat = unitMat.GetMaterial(lod);
+
+ if ((lodMat != NULL) && lodMat->IsActive()) {
+ lodMat->AddUnit(unit);
+ } else {
+ DrawUnitNow(unit);
+ }
+ }
+ }
+ }
+ }
+ }
+ return true;
+}
+
void CUnitDrawer::DrawShadowPass(void)
{
ASSERT_UNSYNCED_MODE;
@@ -598,6 +735,9 @@ void CUnitDrawer::DrawShadowPass(void)
CUnit::SetLODFactor(LODScale * LODScaleShadow);
+#if GML_ENABLE_DRAWUNITSHADOW
+ gmlProcessor.Work(NULL,NULL,&CUnitDrawer::DrawUnitShadowMTcb,this,gmlThreadCount,FALSE,&uh->activeUnits,uh->activeUnits.size(),50,100,TRUE);
+#else
std::list<CUnit*>::iterator usi;
for (usi = uh->activeUnits.begin(); usi != uh->activeUnits.end(); ++usi) {
CUnit* unit = *usi;
@@ -635,6 +775,7 @@ void CUnitDrawer::DrawShadowPass(void)
}
}
}
+#endif
glDisable(GL_VERTEX_PROGRAM_ARB);
@@ -839,10 +980,10 @@ void CUnitDrawer::DrawCloakedUnits(void)
}
-void CUnitDrawer::DrawCloakedUnitsHelper(std::vector<CUnit*>& dC, std::list<GhostBuilding*>& gB, bool is_s3o)
+void CUnitDrawer::DrawCloakedUnitsHelper(GML_VECTOR<CUnit*>& dC, std::list<GhostBuilding*>& gB, bool is_s3o)
{
// cloaked units and living ghosted buildings (stored in same vector)
- for (vector<CUnit*>::iterator ui = dC.begin(); ui != dC.end(); ++ui) {
+ for (GML_VECTOR<CUnit*>::iterator ui = dC.begin(); ui != dC.end(); ++ui) {
CUnit* unit = *ui;
const unsigned short losStatus = unit->losStatus[gu->myAllyTeam];
if ((losStatus & LOS_INLOS) || gu->spectatingFullView) {
@@ -1473,26 +1614,29 @@ void CUnitDrawer::CreateReflectionFace(unsigned int gltype, float3 camdir)
camera = realCam;
}
-
void CUnitDrawer::QueS3ODraw(CWorldObject* object, int textureType)
{
+#if GML_ENABLE
+ quedS3Os.acquire(textureType).push_back(object);
+ quedS3Os.release();
+#else
while (quedS3Os.size() <= textureType)
- quedS3Os.push_back(std::vector<CWorldObject*>());
-
+ quedS3Os.push_back(GML_VECTOR<CWorldObject*>());
quedS3Os[textureType].push_back(object);
usedS3OTextures.insert(textureType);
+#endif