Remove Handle::operator T*()
, discouraging conversion to raw pointers
It was replaced by `Handle::GetPointerOrNull()`. Every use of `GetPointerOrNull` should be reviewed. Some of them were already removed.
This commit is contained in:
parent
6517338dab
commit
60fd3191c5
@ -86,7 +86,7 @@ namespace spades {
|
||||
fade = 1.f;
|
||||
|
||||
float y = 100.f + 32.f * (float)ent.line;
|
||||
float x = (renderer->ScreenWidth() - size.x) * .5f;
|
||||
float x = (renderer.ScreenWidth() - size.x) * .5f;
|
||||
|
||||
Vector4 shadow = {0, 0, 0, fade * 0.5f};
|
||||
Vector4 color = {1, 1, 1, fade};
|
||||
|
@ -38,7 +38,7 @@ namespace spades {
|
||||
};
|
||||
|
||||
Client *client;
|
||||
IRenderer *renderer;
|
||||
IRenderer &renderer;
|
||||
IFont *font;
|
||||
std::vector<bool> lineUsing;
|
||||
std::list<Entry> entries;
|
||||
@ -54,4 +54,4 @@ namespace spades {
|
||||
void Draw();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,19 +111,22 @@ namespace spades {
|
||||
renderer->SetFogDistance(128.f);
|
||||
renderer->SetFogColor(MakeVector3(.8f, 1.f, 1.f));
|
||||
|
||||
chatWindow.reset(new ChatWindow(this, GetRenderer(), fontManager->GetGuiFont(), false));
|
||||
chatWindow.reset(
|
||||
new ChatWindow(this, &GetRenderer(), &fontManager->GetGuiFont(), false));
|
||||
killfeedWindow.reset(
|
||||
new ChatWindow(this, GetRenderer(), fontManager->GetGuiFont(), true));
|
||||
new ChatWindow(this, &GetRenderer(), &fontManager->GetGuiFont(), true));
|
||||
|
||||
hurtRingView.reset(new HurtRingView(this));
|
||||
centerMessageView.reset(new CenterMessageView(this, fontManager->GetLargeFont()));
|
||||
centerMessageView.reset(new CenterMessageView(this, &fontManager->GetLargeFont()));
|
||||
mapView.reset(new MapView(this, false));
|
||||
largeMapView.reset(new MapView(this, true));
|
||||
scoreboard.reset(new ScoreboardView(this));
|
||||
limbo.reset(new LimboView(this));
|
||||
paletteView.reset(new PaletteView(this));
|
||||
tcView.reset(new TCProgressView(this));
|
||||
scriptedUI.Set(new ClientUI(renderer, audioDev, fontManager, this), false);
|
||||
scriptedUI.Set(new ClientUI(renderer.GetPointerOrNull(), audioDev.GetPointerOrNull(),
|
||||
fontManager.GetPointerOrNull(), this),
|
||||
false);
|
||||
|
||||
renderer->SetGameMap(nullptr);
|
||||
}
|
||||
@ -173,7 +176,7 @@ namespace spades {
|
||||
world->SetListener(this);
|
||||
map = world->GetMap();
|
||||
renderer->SetGameMap(map);
|
||||
audioDevice->SetGameMap(map);
|
||||
audioDevice->SetGameMap(map.GetPointerOrNull());
|
||||
NetLog("------ World Loaded ------");
|
||||
} else {
|
||||
|
||||
@ -234,7 +237,7 @@ namespace spades {
|
||||
/** Initiate an initialization which likely to take some time */
|
||||
void Client::DoInit() {
|
||||
renderer->Init();
|
||||
SmokeSpriteEntity::Preload(renderer);
|
||||
SmokeSpriteEntity::Preload(renderer.GetPointerOrNull());
|
||||
|
||||
renderer->RegisterImage("Textures/Fluid.png");
|
||||
renderer->RegisterImage("Textures/WaterExpl.png");
|
||||
@ -533,7 +536,7 @@ namespace spades {
|
||||
|
||||
void Client::PlayAlertSound() {
|
||||
Handle<IAudioChunk> chunk = audioDevice->RegisterSound("Sounds/Feedback/Alert.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
}
|
||||
|
||||
/** Records chat message/game events to the log file. */
|
||||
@ -665,7 +668,7 @@ namespace spades {
|
||||
|
||||
if ((!IsMuted()) && (int)cg_chatBeep) {
|
||||
Handle<IAudioChunk> chunk = audioDevice->RegisterSound("Sounds/Feedback/Chat.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -423,9 +423,9 @@ namespace spades {
|
||||
|
||||
void MarkWorldUpdate();
|
||||
|
||||
IRenderer *GetRenderer() { return renderer; }
|
||||
IRenderer &GetRenderer() { return *renderer; }
|
||||
SceneDefinition GetLastSceneDef() { return lastSceneDef; }
|
||||
IAudioDevice *GetAudioDevice() { return audioDevice; }
|
||||
IAudioDevice &GetAudioDevice() { return *audioDevice; }
|
||||
|
||||
bool WantsToBeClosed() override;
|
||||
bool IsMuted();
|
||||
|
@ -80,7 +80,7 @@ namespace spades {
|
||||
~SandboxedRenderer() {}
|
||||
|
||||
public:
|
||||
SandboxedRenderer(IRenderer *base) : base(base) {}
|
||||
SandboxedRenderer(Handle<IRenderer> base) : base(std::move(base)) {}
|
||||
|
||||
void SetClipBox(const AABB3 &b) { clipBox = b; }
|
||||
void SetAllowDepthHack(bool h) { allowDepthHack = h; }
|
||||
@ -88,8 +88,12 @@ namespace spades {
|
||||
void Init() { OnProhibitedAction(); }
|
||||
void Shutdown() { OnProhibitedAction(); }
|
||||
|
||||
Handle<IImage> RegisterImage(const char *filename) { return base->RegisterImage(filename); }
|
||||
Handle<IModel> RegisterModel(const char *filename) { return base->RegisterModel(filename); }
|
||||
Handle<IImage> RegisterImage(const char *filename) {
|
||||
return base->RegisterImage(filename);
|
||||
}
|
||||
Handle<IModel> RegisterModel(const char *filename) {
|
||||
return base->RegisterModel(filename);
|
||||
}
|
||||
|
||||
Handle<IImage> CreateImage(Bitmap &bmp) { return base->CreateImage(bmp); }
|
||||
Handle<IModel> CreateModel(VoxelModel &m) { return base->CreateModel(m); }
|
||||
@ -176,20 +180,23 @@ namespace spades {
|
||||
else
|
||||
OnProhibitedAction();
|
||||
}
|
||||
void DrawImage(stmp::optional<IImage &> img, const Vector2 &outTopLeft, const AABB2 &inRect) {
|
||||
void DrawImage(stmp::optional<IImage &> img, const Vector2 &outTopLeft,
|
||||
const AABB2 &inRect) {
|
||||
if (allowDepthHack)
|
||||
base->DrawImage(img, outTopLeft, inRect);
|
||||
else
|
||||
OnProhibitedAction();
|
||||
}
|
||||
void DrawImage(stmp::optional<IImage &> img, const AABB2 &outRect, const AABB2 &inRect) {
|
||||
void DrawImage(stmp::optional<IImage &> img, const AABB2 &outRect,
|
||||
const AABB2 &inRect) {
|
||||
if (allowDepthHack)
|
||||
base->DrawImage(img, outRect, inRect);
|
||||
else
|
||||
OnProhibitedAction();
|
||||
}
|
||||
void DrawImage(stmp::optional<IImage &> img, const Vector2 &outTopLeft, const Vector2 &outTopRight,
|
||||
const Vector2 &outBottomLeft, const AABB2 &inRect) {
|
||||
void DrawImage(stmp::optional<IImage &> img, const Vector2 &outTopLeft,
|
||||
const Vector2 &outTopRight, const Vector2 &outBottomLeft,
|
||||
const AABB2 &inRect) {
|
||||
if (allowDepthHack)
|
||||
base->DrawImage(img, outTopLeft, outTopRight, outBottomLeft, inRect);
|
||||
else
|
||||
@ -228,11 +235,10 @@ namespace spades {
|
||||
flashlightOrientation = p.GetFront();
|
||||
|
||||
ScriptContextHandle ctx;
|
||||
IRenderer *renderer = client.GetRenderer();
|
||||
IAudioDevice *audio = client.GetAudioDevice();
|
||||
IAudioDevice &audio = client.GetAudioDevice();
|
||||
|
||||
sandboxedRenderer.Set(new SandboxedRenderer(renderer), false);
|
||||
renderer = sandboxedRenderer;
|
||||
sandboxedRenderer.Set(new SandboxedRenderer(client.GetRenderer()), false);
|
||||
IRenderer &renderer = *sandboxedRenderer;
|
||||
|
||||
static ScriptFunction spadeFactory(
|
||||
"ISpadeSkin@ CreateThirdPersonSpadeSkin(Renderer@, AudioDevice@)");
|
||||
@ -299,10 +305,10 @@ namespace spades {
|
||||
}
|
||||
|
||||
asIScriptObject *ClientPlayer::initScriptFactory(ScriptFunction &creator,
|
||||
IRenderer *renderer, IAudioDevice *audio) {
|
||||
IRenderer &renderer, IAudioDevice &audio) {
|
||||
ScriptContextHandle ctx = creator.Prepare();
|
||||
ctx->SetArgObject(0, reinterpret_cast<void *>(renderer));
|
||||
ctx->SetArgObject(1, reinterpret_cast<void *>(audio));
|
||||
ctx->SetArgObject(0, reinterpret_cast<void *>(&renderer));
|
||||
ctx->SetArgObject(1, reinterpret_cast<void *>(&audio));
|
||||
ctx.ExecuteChecked();
|
||||
asIScriptObject *result = reinterpret_cast<asIScriptObject *>(ctx->GetReturnObject());
|
||||
result->AddRef();
|
||||
@ -372,40 +378,41 @@ namespace spades {
|
||||
|
||||
// play tool change sound
|
||||
if (player.IsLocalPlayer()) {
|
||||
auto *audioDevice = client.GetAudioDevice();
|
||||
IAudioDevice &audioDevice = client.GetAudioDevice();
|
||||
Handle<IAudioChunk> c;
|
||||
switch (player.GetTool()) {
|
||||
case Player::ToolSpade:
|
||||
c = audioDevice->RegisterSound(
|
||||
"Sounds/Weapons/Spade/RaiseLocal.opus");
|
||||
c =
|
||||
audioDevice.RegisterSound("Sounds/Weapons/Spade/RaiseLocal.opus");
|
||||
break;
|
||||
case Player::ToolBlock:
|
||||
c = audioDevice->RegisterSound(
|
||||
"Sounds/Weapons/Block/RaiseLocal.opus");
|
||||
c =
|
||||
audioDevice.RegisterSound("Sounds/Weapons/Block/RaiseLocal.opus");
|
||||
break;
|
||||
case Player::ToolWeapon:
|
||||
switch (player.GetWeapon().GetWeaponType()) {
|
||||
case RIFLE_WEAPON:
|
||||
c = audioDevice->RegisterSound(
|
||||
c = audioDevice.RegisterSound(
|
||||
"Sounds/Weapons/Rifle/RaiseLocal.opus");
|
||||
break;
|
||||
case SMG_WEAPON:
|
||||
c = audioDevice->RegisterSound(
|
||||
c = audioDevice.RegisterSound(
|
||||
"Sounds/Weapons/SMG/RaiseLocal.opus");
|
||||
break;
|
||||
case SHOTGUN_WEAPON:
|
||||
c = audioDevice->RegisterSound(
|
||||
c = audioDevice.RegisterSound(
|
||||
"Sounds/Weapons/Shotgun/RaiseLocal.opus");
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case Player::ToolGrenade:
|
||||
c = audioDevice->RegisterSound(
|
||||
c = audioDevice.RegisterSound(
|
||||
"Sounds/Weapons/Grenade/RaiseLocal.opus");
|
||||
break;
|
||||
}
|
||||
audioDevice->PlayLocal(c, MakeVector3(.4f, -.3f, .5f), AudioParam());
|
||||
audioDevice.PlayLocal(c.GetPointerOrNull(), MakeVector3(.4f, -.3f, .5f),
|
||||
AudioParam());
|
||||
}
|
||||
} else if (toolRaiseState > 1.f) {
|
||||
toolRaiseState = 1.f;
|
||||
@ -640,7 +647,7 @@ namespace spades {
|
||||
|
||||
void ClientPlayer::AddToSceneFirstPersonView() {
|
||||
Player &p = player;
|
||||
IRenderer *renderer = client.GetRenderer();
|
||||
IRenderer &renderer = client.GetRenderer();
|
||||
World *world = client.GetWorld();
|
||||
Matrix4 eyeMatrix = GetEyeMatrix();
|
||||
|
||||
@ -656,26 +663,26 @@ namespace spades {
|
||||
|
||||
// add flash light
|
||||
DynamicLightParam light;
|
||||
Handle<IImage> image = renderer.RegisterImage("Gfx/Spotlight.png");
|
||||
light.origin = (eyeMatrix * MakeVector3(0, -0.05f, -0.1f)).GetXYZ();
|
||||
light.color = MakeVector3(1, .7f, .5f) * 1.5f * brightness;
|
||||
light.radius = 40.f;
|
||||
light.type = DynamicLightTypeSpotlight;
|
||||
light.spotAngle = 30.f * M_PI / 180.f;
|
||||
light.spotAxis = GetFlashlightAxes();
|
||||
light.image = renderer->RegisterImage("Gfx/Spotlight.png");
|
||||
renderer->AddLight(light);
|
||||
light.image = image.GetPointerOrNull();
|
||||
renderer.AddLight(light);
|
||||
|
||||
light.color *= .3f;
|
||||
light.radius = 10.f;
|
||||
light.type = DynamicLightTypePoint;
|
||||
light.image = NULL;
|
||||
renderer->AddLight(light);
|
||||
renderer.AddLight(light);
|
||||
|
||||
// add glare
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(1, .7f, .5f, 0) * brightness *
|
||||
.3f);
|
||||
renderer->AddSprite(*renderer->RegisterImage("Gfx/Glare.png"),
|
||||
(eyeMatrix * MakeVector3(0, 0.3f, -0.3f)).GetXYZ(), .8f, 0.f);
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(1, .7f, .5f, 0) * brightness * .3f);
|
||||
renderer.AddSprite(*renderer.RegisterImage("Gfx/Glare.png"),
|
||||
(eyeMatrix * MakeVector3(0, 0.3f, -0.3f)).GetXYZ(), .8f, 0.f);
|
||||
}
|
||||
|
||||
Vector3 leftHand, rightHand;
|
||||
@ -751,8 +758,8 @@ namespace spades {
|
||||
ModelRenderParam param;
|
||||
param.depthHack = true;
|
||||
|
||||
Handle<IModel> model = renderer->RegisterModel("Models/Player/Arm.kv6");
|
||||
Handle<IModel> model2 = renderer->RegisterModel("Models/Player/UpperArm.kv6");
|
||||
Handle<IModel> model = renderer.RegisterModel("Models/Player/Arm.kv6");
|
||||
Handle<IModel> model2 = renderer.RegisterModel("Models/Player/UpperArm.kv6");
|
||||
|
||||
IntVector3 col = p.GetColor();
|
||||
param.customColor = MakeVector3(col.x / 255.f, col.y / 255.f, col.z / 255.f);
|
||||
@ -792,7 +799,7 @@ namespace spades {
|
||||
mat = eyeMatrix * mat;
|
||||
|
||||
param.matrix = mat;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
}
|
||||
|
||||
{
|
||||
@ -807,7 +814,7 @@ namespace spades {
|
||||
mat = eyeMatrix * mat;
|
||||
|
||||
param.matrix = mat;
|
||||
renderer->RenderModel(*model2, param);
|
||||
renderer.RenderModel(*model2, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -817,7 +824,7 @@ namespace spades {
|
||||
|
||||
void ClientPlayer::AddToSceneThirdPersonView() {
|
||||
Player &p = player;
|
||||
IRenderer *renderer = client.GetRenderer();
|
||||
IRenderer &renderer = client.GetRenderer();
|
||||
World *world = client.GetWorld();
|
||||
|
||||
if (!p.IsAlive()) {
|
||||
@ -828,8 +835,8 @@ namespace spades {
|
||||
IntVector3 col = p.GetColor();
|
||||
param.customColor = MakeVector3(col.x / 255.f, col.y / 255.f, col.z / 255.f);
|
||||
|
||||
Handle<IModel> model = renderer->RegisterModel("Models/Player/Dead.kv6");
|
||||
renderer->RenderModel(*model, param);
|
||||
Handle<IModel> model = renderer.RegisterModel("Models/Player/Dead.kv6");
|
||||
renderer.RenderModel(*model, param);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -900,18 +907,18 @@ namespace spades {
|
||||
leg1 = lower * leg1;
|
||||
leg2 = lower * leg2;
|
||||
|
||||
model = renderer->RegisterModel("Models/Player/LegCrouch.kv6");
|
||||
model = renderer.RegisterModel("Models/Player/LegCrouch.kv6");
|
||||
param.matrix = leg1 * scaler;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
param.matrix = leg2 * scaler;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
|
||||
torso = Matrix4::Translate(0.f, 0.f, -0.55f);
|
||||
torso = lower * torso;
|
||||
|
||||
model = renderer->RegisterModel("Models/Player/TorsoCrouch.kv6");
|
||||
model = renderer.RegisterModel("Models/Player/TorsoCrouch.kv6");
|
||||
param.matrix = torso * scaler;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
|
||||
head = Matrix4::Translate(0.f, 0.f, -0.0f);
|
||||
head = torso * head;
|
||||
@ -934,18 +941,18 @@ namespace spades {
|
||||
leg1 = lower * leg1;
|
||||
leg2 = lower * leg2;
|
||||
|
||||
model = renderer->RegisterModel("Models/Player/Leg.kv6");
|
||||
model = renderer.RegisterModel("Models/Player/Leg.kv6");
|
||||
param.matrix = leg1 * scaler;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
param.matrix = leg2 * scaler;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
|
||||
torso = Matrix4::Translate(0.f, 0.f, -1.0f);
|
||||
torso = lower * torso;
|
||||
|
||||
model = renderer->RegisterModel("Models/Player/Torso.kv6");
|
||||
model = renderer.RegisterModel("Models/Player/Torso.kv6");
|
||||
param.matrix = torso * scaler;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
|
||||
head = Matrix4::Translate(0.f, 0.f, -0.0f);
|
||||
head = torso * head;
|
||||
@ -966,15 +973,15 @@ namespace spades {
|
||||
|
||||
arms = arms * Matrix4::Rotate(MakeVector3(1, 0, 0), armPitch);
|
||||
|
||||
model = renderer->RegisterModel("Models/Player/Arms.kv6");
|
||||
model = renderer.RegisterModel("Models/Player/Arms.kv6");
|
||||
param.matrix = arms * scaler;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
|
||||
head = head * Matrix4::Rotate(MakeVector3(1, 0, 0), pitch);
|
||||
|
||||
model = renderer->RegisterModel("Models/Player/Head.kv6");
|
||||
model = renderer.RegisterModel("Models/Player/Head.kv6");
|
||||
param.matrix = head * scaler;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
|
||||
// draw tool
|
||||
{
|
||||
@ -1002,9 +1009,9 @@ namespace spades {
|
||||
MakeVector3(col2.x / 255.f, col2.y / 255.f, col2.z / 255.f);
|
||||
Matrix4 mIntel = torso * Matrix4::Translate(0, 0.6f, 0.5f);
|
||||
|
||||
model = renderer->RegisterModel("Models/MapObjects/Intel.kv6");
|
||||
model = renderer.RegisterModel("Models/MapObjects/Intel.kv6");
|
||||
param.matrix = mIntel * scaler;
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
|
||||
param.customColor =
|
||||
MakeVector3(col.x / 255.f, col.y / 255.f, col.z / 255.f);
|
||||
@ -1094,8 +1101,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
float maxDistance = 40.f;
|
||||
GameMap *map = client.map;
|
||||
SPAssert(map);
|
||||
GameMap &map = *client.map;
|
||||
|
||||
Vector3 rayFrom = player.GetEye();
|
||||
// uniformly distributed random unit vectors
|
||||
@ -1136,7 +1142,7 @@ namespace spades {
|
||||
const Vector3 &rayTo = directions[i];
|
||||
|
||||
IntVector3 hitPos;
|
||||
bool hit = map->CastRay(rayFrom, rayTo, maxDistance, hitPos);
|
||||
bool hit = map.CastRay(rayFrom, rayTo, maxDistance, hitPos);
|
||||
if (hit) {
|
||||
Vector3 hitPosf = {(float)hitPos.x, (float)hitPos.y, (float)hitPos.z};
|
||||
distance = (hitPosf - rayFrom).GetLength();
|
||||
@ -1145,7 +1151,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
if (hit) {
|
||||
bool hit2 = map->CastRay(rayFrom, -rayTo, maxDistance, hitPos);
|
||||
bool hit2 = map.CastRay(rayFrom, -rayTo, maxDistance, hitPos);
|
||||
if (hit2)
|
||||
feedbackness = 1.f;
|
||||
else
|
||||
@ -1194,8 +1200,8 @@ namespace spades {
|
||||
World &world = player.GetWorld();
|
||||
Vector3 muzzle;
|
||||
const SceneDefinition &lastSceneDef = client.GetLastSceneDef();
|
||||
IRenderer *renderer = client.GetRenderer();
|
||||
IAudioDevice *audioDevice = client.GetAudioDevice();
|
||||
IRenderer &renderer = client.GetRenderer();
|
||||
IAudioDevice &audioDevice = client.GetAudioDevice();
|
||||
Player &p = player;
|
||||
|
||||
// make dlight
|
||||
@ -1219,27 +1225,26 @@ namespace spades {
|
||||
Handle<IAudioChunk> snd2 = NULL;
|
||||
switch (player.GetWeapon().GetWeaponType()) {
|
||||
case RIFLE_WEAPON:
|
||||
model = renderer->RegisterModel("Models/Weapons/Rifle/Casing.kv6");
|
||||
model = renderer.RegisterModel("Models/Weapons/Rifle/Casing.kv6");
|
||||
snd =
|
||||
SampleRandomBool()
|
||||
? audioDevice->RegisterSound("Sounds/Weapons/Rifle/ShellDrop1.opus")
|
||||
: audioDevice->RegisterSound(
|
||||
"Sounds/Weapons/Rifle/ShellDrop2.opus");
|
||||
? audioDevice.RegisterSound("Sounds/Weapons/Rifle/ShellDrop1.opus")
|
||||
: audioDevice.RegisterSound("Sounds/Weapons/Rifle/ShellDrop2.opus");
|
||||
snd2 =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Rifle/ShellWater.opus");
|
||||
audioDevice.RegisterSound("Sounds/Weapons/Rifle/ShellWater.opus");
|
||||
break;
|
||||
case SHOTGUN_WEAPON:
|
||||
// FIXME: don't want to show shotgun't casing
|
||||
// because it isn't ejected when firing
|
||||
// model = renderer->RegisterModel("Models/Weapons/Shotgun/Casing.kv6");
|
||||
// model = renderer.RegisterModel("Models/Weapons/Shotgun/Casing.kv6");
|
||||
break;
|
||||
case SMG_WEAPON:
|
||||
model = renderer->RegisterModel("Models/Weapons/SMG/Casing.kv6");
|
||||
model = renderer.RegisterModel("Models/Weapons/SMG/Casing.kv6");
|
||||
snd =
|
||||
SampleRandomBool()
|
||||
? audioDevice->RegisterSound("Sounds/Weapons/SMG/ShellDrop1.opus")
|
||||
: audioDevice->RegisterSound("Sounds/Weapons/SMG/ShellDrop2.opus");
|
||||
snd2 = audioDevice->RegisterSound("Sounds/Weapons/SMG/ShellWater.opus");
|
||||
? audioDevice.RegisterSound("Sounds/Weapons/SMG/ShellDrop1.opus")
|
||||
: audioDevice.RegisterSound("Sounds/Weapons/SMG/ShellDrop2.opus");
|
||||
snd2 = audioDevice.RegisterSound("Sounds/Weapons/SMG/ShellWater.opus");
|
||||
break;
|
||||
}
|
||||
if (model) {
|
||||
@ -1255,7 +1260,9 @@ namespace spades {
|
||||
}
|
||||
|
||||
ILocalEntity *ent;
|
||||
ent = new GunCasing(&client, model, snd, snd2, origin, p.GetFront(), vel);
|
||||
ent =
|
||||
new GunCasing(&client, model.GetPointerOrNull(), snd.GetPointerOrNull(),
|
||||
snd2.GetPointerOrNull(), origin, p.GetFront(), vel);
|
||||
client.AddLocalEntity(ent);
|
||||
}
|
||||
}
|
||||
|
@ -90,8 +90,9 @@ namespace spades {
|
||||
|
||||
bool ShouldRenderInThirdPersonView();
|
||||
|
||||
asIScriptObject *initScriptFactory(ScriptFunction &creator, IRenderer *renderer,
|
||||
IAudioDevice *audio);
|
||||
// TODO: Naming convention violation
|
||||
asIScriptObject *initScriptFactory(ScriptFunction &creator, IRenderer &renderer,
|
||||
IAudioDevice &audio);
|
||||
|
||||
protected:
|
||||
~ClientPlayer();
|
||||
|
@ -35,10 +35,10 @@ namespace spades {
|
||||
ClientUI::ClientUI(IRenderer *r, IAudioDevice *a, FontManager *fontManager, Client *client)
|
||||
: renderer(r), audioDevice(a), fontManager(fontManager), client(client) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
if (r == NULL)
|
||||
SPInvalidArgument("r");
|
||||
if (a == NULL)
|
||||
SPInvalidArgument("a");
|
||||
if (!renderer)
|
||||
SPInvalidArgument("renderer");
|
||||
if (!audioDevice)
|
||||
SPInvalidArgument("audioDevice");
|
||||
|
||||
helper.Set(new ClientUIHelper(this), false);
|
||||
|
||||
@ -47,8 +47,8 @@ namespace spades {
|
||||
"ClientUI@ CreateClientUI(Renderer@, AudioDevice@, FontManager@, ClientUIHelper@)");
|
||||
{
|
||||
ScriptContextHandle ctx = uiFactory.Prepare();
|
||||
ctx->SetArgObject(0, renderer);
|
||||
ctx->SetArgObject(1, audioDevice);
|
||||
ctx->SetArgObject(0, renderer.GetPointerOrNull());
|
||||
ctx->SetArgObject(1, audioDevice.GetPointerOrNull());
|
||||
ctx->SetArgObject(2, fontManager);
|
||||
ctx->SetArgObject(3, &*helper);
|
||||
|
||||
|
@ -120,9 +120,9 @@ namespace spades {
|
||||
// Well done!
|
||||
renderer->FrameDone();
|
||||
|
||||
Handle<Bitmap> bmp(renderer->ReadBitmap(), false);
|
||||
// force 100% opacity
|
||||
Handle<Bitmap> bmp = renderer->ReadBitmap();
|
||||
|
||||
// force 100% opacity
|
||||
uint32_t *pixels = bmp->GetPixels();
|
||||
for (size_t i = bmp->GetWidth() * bmp->GetHeight(); i > 0; i--) {
|
||||
*(pixels++) |= 0xff000000UL;
|
||||
@ -212,12 +212,12 @@ namespace spades {
|
||||
|
||||
DrawSplash();
|
||||
|
||||
IFont *font = fontManager->GetGuiFont();
|
||||
IFont &font = fontManager->GetGuiFont();
|
||||
std::string str = _Tr("Client", "NOW LOADING");
|
||||
Vector2 size = font->Measure(str);
|
||||
Vector2 size = font.Measure(str);
|
||||
Vector2 pos = MakeVector2(scrSize.x - 16.f, scrSize.y - 16.f);
|
||||
pos -= size;
|
||||
font->DrawShadow(str, pos, 1.f, MakeVector4(1, 1, 1, 1), MakeVector4(0, 0, 0, 0.5));
|
||||
font.DrawShadow(str, pos, 1.f, MakeVector4(1, 1, 1, 1), MakeVector4(0, 0, 0, 0.5));
|
||||
|
||||
renderer->FrameDone();
|
||||
renderer->Flip();
|
||||
@ -311,11 +311,11 @@ namespace spades {
|
||||
pos.y += (int)cg_playerNameY;
|
||||
pos.x += (int)cg_playerNameX;
|
||||
|
||||
IFont *font = fontManager->GetGuiFont();
|
||||
Vector2 size = font->Measure(buf);
|
||||
IFont &font = fontManager->GetGuiFont();
|
||||
Vector2 size = font.Measure(buf);
|
||||
pos.x -= size.x * .5f;
|
||||
pos.y -= size.y;
|
||||
font->DrawShadow(buf, pos, 1.f, MakeVector4(1, 1, 1, 1), MakeVector4(0, 0, 0, 0.5));
|
||||
font.DrawShadow(buf, pos, 1.f, MakeVector4(1, 1, 1, 1), MakeVector4(0, 0, 0, 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
@ -403,7 +403,7 @@ namespace spades {
|
||||
clientPlayers[playerId]->Draw2D();
|
||||
|
||||
if (cg_hitIndicator && hitFeedbackIconState > 0.f && !cg_hideHud) {
|
||||
Handle<IImage> img(renderer->RegisterImage("Gfx/HitFeedback.png"), false);
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/HitFeedback.png");
|
||||
Vector2 pos = {scrWidth * .5f, scrHeight * .5f};
|
||||
pos.x -= img->GetWidth() * .5f;
|
||||
pos.y -= img->GetHeight() * .5f;
|
||||
@ -427,7 +427,7 @@ namespace spades {
|
||||
if (mode.ModeType() == IGameMode::m_CTF) {
|
||||
auto &ctfMode = static_cast<CTFGameMode &>(mode);
|
||||
if (ctfMode.PlayerHasIntel(*world, player)) {
|
||||
Handle<IImage> img(renderer->RegisterImage("Gfx/Intel.png"), false);
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/Intel.png");
|
||||
|
||||
// Strobe
|
||||
Vector4 color{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
@ -450,7 +450,6 @@ namespace spades {
|
||||
float scrWidth = renderer->ScreenWidth();
|
||||
float scrHeight = renderer->ScreenHeight();
|
||||
Player &p = GetWorld()->GetLocalPlayer().value();
|
||||
IFont *font;
|
||||
|
||||
// Draw damage rings
|
||||
if (!cg_hideHud)
|
||||
@ -531,12 +530,12 @@ namespace spades {
|
||||
|
||||
char buf[64];
|
||||
sprintf(buf, "%d", stockNum);
|
||||
font = fontManager->GetSquareDesignFont();
|
||||
IFont &font = fontManager->GetSquareDesignFont();
|
||||
std::string stockStr = buf;
|
||||
Vector2 size = font->Measure(stockStr);
|
||||
Vector2 size = font.Measure(stockStr);
|
||||
Vector2 pos = MakeVector2(scrWidth - 16.f, scrHeight - 16.f - iconHeight);
|
||||
pos -= size;
|
||||
font->DrawShadow(stockStr, pos, 1.f, numberColor, MakeVector4(0, 0, 0, 0.5));
|
||||
font.DrawShadow(stockStr, pos, 1.f, numberColor, MakeVector4(0, 0, 0, 0.5));
|
||||
|
||||
// draw "press ... to reload"
|
||||
{
|
||||
@ -570,11 +569,11 @@ namespace spades {
|
||||
}
|
||||
|
||||
if (!msg.empty()) {
|
||||
font = fontManager->GetGuiFont();
|
||||
Vector2 size = font->Measure(msg);
|
||||
IFont &font = fontManager->GetGuiFont();
|
||||
Vector2 size = font.Measure(msg);
|
||||
Vector2 pos = MakeVector2((scrWidth - size.x) * .5f, scrHeight * 2.f / 3.f);
|
||||
font->DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.5));
|
||||
font.DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
@ -610,12 +609,12 @@ namespace spades {
|
||||
msg = _Tr("Client", "Waiting for respawn");
|
||||
|
||||
if (!msg.empty()) {
|
||||
font = fontManager->GetGuiFont();
|
||||
Vector2 size = font->Measure(msg);
|
||||
IFont &font = fontManager->GetGuiFont();
|
||||
Vector2 size = font.Measure(msg);
|
||||
Vector2 pos = MakeVector2((scrWidth - size.x) * .5f, scrHeight / 3.f);
|
||||
|
||||
font->DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.5));
|
||||
font.DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.5));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -628,7 +627,7 @@ namespace spades {
|
||||
return;
|
||||
}
|
||||
|
||||
IFont &font = *fontManager->GetGuiFont();
|
||||
IFont &font = fontManager->GetGuiFont();
|
||||
float scrWidth = renderer->ScreenWidth();
|
||||
|
||||
float textX = scrWidth - 8.0f;
|
||||
@ -676,7 +675,7 @@ namespace spades {
|
||||
void Client::DrawAlert() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IFont *font = fontManager->GetGuiFont();
|
||||
IFont &font = fontManager->GetGuiFont();
|
||||
float scrWidth = renderer->ScreenWidth();
|
||||
float scrHeight = renderer->ScreenHeight();
|
||||
auto &r = renderer;
|
||||
@ -693,9 +692,9 @@ namespace spades {
|
||||
borderFade = std::max(std::min(borderFade, 1.f), 0.f);
|
||||
borderFade *= fade;
|
||||
|
||||
Handle<IImage> alertIcon(renderer->RegisterImage("Gfx/AlertIcon.png"), false);
|
||||
Handle<IImage> alertIcon = renderer->RegisterImage("Gfx/AlertIcon.png");
|
||||
|
||||
Vector2 textSize = font->Measure(alertContents);
|
||||
Vector2 textSize = font.Measure(alertContents);
|
||||
Vector2 contentsSize = textSize;
|
||||
contentsSize.y = std::max(contentsSize.y, 16.f);
|
||||
if (alertType != AlertType::Notice) {
|
||||
@ -757,17 +756,16 @@ namespace spades {
|
||||
color = Vector4(1.f, 1.f, 1.f, 1.f);
|
||||
color *= fade;
|
||||
|
||||
font->DrawShadow(alertContents,
|
||||
Vector2(pos.x + contentsSize.x - textSize.x - margin,
|
||||
pos.y + (contentsSize.y - textSize.y) * 0.5f),
|
||||
1.f, color, Vector4(0.f, 0.f, 0.f, fade * 0.5f));
|
||||
font.DrawShadow(alertContents,
|
||||
Vector2(pos.x + contentsSize.x - textSize.x - margin,
|
||||
pos.y + (contentsSize.y - textSize.y) * 0.5f),
|
||||
1.f, color, Vector4(0.f, 0.f, 0.f, fade * 0.5f));
|
||||
}
|
||||
|
||||
void Client::DrawHealth() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
Player &p = GetWorld()->GetLocalPlayer().value();
|
||||
IFont *font;
|
||||
// float scrWidth = renderer->ScreenWidth();
|
||||
float scrHeight = renderer->ScreenHeight();
|
||||
|
||||
@ -782,11 +780,11 @@ namespace spades {
|
||||
numberColor.z = 0.3f;
|
||||
}
|
||||
|
||||
font = fontManager->GetSquareDesignFont();
|
||||
Vector2 size = font->Measure(str);
|
||||
IFont &font = fontManager->GetSquareDesignFont();
|
||||
Vector2 size = font.Measure(str);
|
||||
Vector2 pos = MakeVector2(16.f, scrHeight - 16.f);
|
||||
pos.y -= size.y;
|
||||
font->DrawShadow(str, pos, 1.f, numberColor, MakeVector4(0, 0, 0, 0.5));
|
||||
font.DrawShadow(str, pos, 1.f, numberColor, MakeVector4(0, 0, 0, 0.5));
|
||||
}
|
||||
|
||||
void Client::Draw2DWithWorld() {
|
||||
@ -856,17 +854,16 @@ namespace spades {
|
||||
// no world; loading?
|
||||
float scrWidth = renderer->ScreenWidth();
|
||||
float scrHeight = renderer->ScreenHeight();
|
||||
IFont *font;
|
||||
|
||||
DrawSplash();
|
||||
|
||||
Handle<IImage> img;
|
||||
|
||||
std::string msg = net->GetStatusString();
|
||||
font = fontManager->GetGuiFont();
|
||||
Vector2 textSize = font->Measure(msg);
|
||||
font->Draw(msg, MakeVector2(scrWidth - 16.f, scrHeight - 24.f) - textSize, 1.f,
|
||||
MakeVector4(1, 1, 1, 0.95f));
|
||||
IFont &font = fontManager->GetGuiFont();
|
||||
Vector2 textSize = font.Measure(msg);
|
||||
font.Draw(msg, MakeVector2(scrWidth - 16.f, scrHeight - 24.f) - textSize, 1.f,
|
||||
MakeVector4(1, 1, 1, 0.95f));
|
||||
|
||||
img = renderer->RegisterImage("Gfx/White.tga");
|
||||
|
||||
@ -942,19 +939,18 @@ namespace spades {
|
||||
|
||||
float scrWidth = renderer->ScreenWidth();
|
||||
float scrHeight = renderer->ScreenHeight();
|
||||
IFont *font = fontManager->GetGuiFont();
|
||||
IFont &font = fontManager->GetGuiFont();
|
||||
float margin = 5.f;
|
||||
|
||||
IRenderer *r = renderer;
|
||||
auto size = font->Measure(str);
|
||||
auto size = font.Measure(str);
|
||||
size += Vector2(margin * 2.f, margin * 2.f);
|
||||
|
||||
auto pos = (Vector2(scrWidth, scrHeight) - size) * Vector2(0.5f, 1.f);
|
||||
|
||||
r->SetColorAlphaPremultiplied(Vector4(0.f, 0.f, 0.f, 0.5f));
|
||||
r->DrawImage(nullptr, AABB2(pos.x, pos.y, size.x, size.y));
|
||||
font->DrawShadow(str, pos + Vector2(margin, margin), 1.f, Vector4(1.f, 1.f, 1.f, 1.f),
|
||||
Vector4(0.f, 0.f, 0.f, 0.5f));
|
||||
renderer->SetColorAlphaPremultiplied(Vector4(0.f, 0.f, 0.f, 0.5f));
|
||||
renderer->DrawImage(nullptr, AABB2(pos.x, pos.y, size.x, size.y));
|
||||
font.DrawShadow(str, pos + Vector2(margin, margin), 1.f, Vector4(1.f, 1.f, 1.f, 1.f),
|
||||
Vector4(0.f, 0.f, 0.f, 0.5f));
|
||||
}
|
||||
|
||||
void Client::Draw2D() {
|
||||
|
@ -446,7 +446,7 @@ namespace spades {
|
||||
params.volume = 0.08f;
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/AimDownSightLocal.opus");
|
||||
audioDevice->PlayLocal(chunk, MakeVector3(.4f, -.3f, .5f), params);
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), MakeVector3(.4f, -.3f, .5f), params);
|
||||
}
|
||||
} else if (CheckKey(cg_keyReloadWeapon, name) && down) {
|
||||
Weapon &w = world->GetLocalPlayer()->GetWeapon();
|
||||
@ -536,16 +536,16 @@ namespace spades {
|
||||
mapView->SwitchScale();
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Misc/SwitchMapZoom.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
} else if (CheckKey(cg_keyToggleMapZoom, name) && down) {
|
||||
if (largeMapView->ToggleZoom()) {
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Misc/OpenMap.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
} else {
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Misc/CloseMap.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
}
|
||||
} else if (CheckKey(cg_keyScoreboard, name)) {
|
||||
scoreboardVisible = down;
|
||||
@ -569,7 +569,7 @@ namespace spades {
|
||||
flashlightOnTime = time;
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Player/Flashlight.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
} else if (CheckKey(cg_keyAutoFocus, name) && down && (int)cg_manualFocus) {
|
||||
autoFocusEnabled = true;
|
||||
} else if (down) {
|
||||
|
@ -159,7 +159,8 @@ namespace spades {
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Vector4 color = {0.5f, 0.02f, 0.04f, 1.f};
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
ent->SetTrajectory(v,
|
||||
MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
@ -224,7 +225,8 @@ namespace spades {
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Vector4 color = {c.x / 255.f, c.y / 255.f, c.z / 255.f, 1.f};
|
||||
for (int i = 0; i < 7; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
ent->SetTrajectory(origin,
|
||||
MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
@ -244,7 +246,8 @@ namespace spades {
|
||||
|
||||
if (distPowered < 32.f * 32.f) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
ent->SetTrajectory(origin,
|
||||
MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
@ -293,7 +296,8 @@ namespace spades {
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Vector4 color = {c.x / 255.f, c.y / 255.f, c.z / 255.f, 1.f};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
ent->SetTrajectory(origin,
|
||||
MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
@ -433,7 +437,8 @@ namespace spades {
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
color = MakeVector4(0.01, 0.03, 0, 1.f);
|
||||
for (int i = 0; i < 42; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
Vector3 dir = MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat());
|
||||
@ -486,7 +491,8 @@ namespace spades {
|
||||
if ((int)cg_particles < 2)
|
||||
color.w = .3f;
|
||||
for (int i = 0; i < 7; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
ent->SetTrajectory(origin,
|
||||
(MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
@ -506,7 +512,8 @@ namespace spades {
|
||||
if ((int)cg_particles < 2)
|
||||
color.w = .4f;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
ent->SetTrajectory(origin,
|
||||
(MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
@ -549,7 +556,8 @@ namespace spades {
|
||||
img = renderer->RegisterImage("Gfx/White.tga");
|
||||
color = MakeVector4(1, 1, 1, 0.7f);
|
||||
for (int i = 0; i < 42; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
Vector3 dir = MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
-SampleRandomFloat() * 3.f);
|
||||
@ -584,7 +592,8 @@ namespace spades {
|
||||
if ((int)cg_particles < 2)
|
||||
color.w = .2f;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
ent->SetTrajectory(origin,
|
||||
(MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
@ -604,7 +613,8 @@ namespace spades {
|
||||
if ((int)cg_particles < 2)
|
||||
color.w = .4f;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
ent->SetTrajectory(origin,
|
||||
(MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
@ -623,7 +633,8 @@ namespace spades {
|
||||
img = renderer->RegisterImage("Gfx/White.tga");
|
||||
color = MakeVector4(1, 1, 1, 0.7f);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(this, img, color);
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(this, img.GetPointerOrNull(), color);
|
||||
Vector3 dir = MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
SampleRandomFloat() - SampleRandomFloat(),
|
||||
-SampleRandomFloat() * 3.f);
|
||||
|
@ -73,7 +73,7 @@ namespace spades {
|
||||
if (!IsMuted()) {
|
||||
Handle<IAudioChunk> c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Block/Build.opus");
|
||||
audioDevice->Play(c, p.GetEye() + p.GetFront(), AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), p.GetEye() + p.GetFront(), AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,11 +108,11 @@ namespace spades {
|
||||
if (teamId == world->GetLocalPlayer()->GetTeamId()) {
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Feedback/TC/YourTeamCaptured.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
} else {
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Feedback/TC/EnemyCaptured.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,11 +140,11 @@ namespace spades {
|
||||
if (p.GetTeamId() == world->GetLocalPlayer()->GetTeamId()) {
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Feedback/CTF/YourTeamCaptured.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
} else {
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Feedback/CTF/EnemyCaptured.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -170,7 +170,7 @@ namespace spades {
|
||||
if (!IsMuted()) {
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Feedback/CTF/PickedUp.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ namespace spades {
|
||||
|
||||
Handle<IAudioChunk> c = audioDevice->RegisterSound("Sounds/Misc/BlockDestroy.opus");
|
||||
if (!IsMuted()) {
|
||||
audioDevice->Play(c, origin, AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), origin, AudioParam());
|
||||
}
|
||||
|
||||
uint32_t col = map->GetColor(blk.x, blk.y, blk.z);
|
||||
@ -218,7 +218,7 @@ namespace spades {
|
||||
|
||||
Handle<IAudioChunk> c = audioDevice->RegisterSound("Sounds/Misc/BlockDestroy.opus");
|
||||
if (!IsMuted()) {
|
||||
audioDevice->Play(c, origin, AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), origin, AudioParam());
|
||||
}
|
||||
|
||||
SPAssert(map);
|
||||
@ -333,11 +333,11 @@ namespace spades {
|
||||
if (teamId == world->GetLocalPlayer()->GetTeamId()) {
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Feedback/Win.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
} else {
|
||||
Handle<IAudioChunk> chunk =
|
||||
audioDevice->RegisterSound("Sounds/Feedback/Lose.opus");
|
||||
audioDevice->PlayLocal(chunk, AudioParam());
|
||||
audioDevice->PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,8 +121,7 @@ namespace spades {
|
||||
return 1.f;
|
||||
}
|
||||
|
||||
ClientPlayer *clientPlayer = clientPlayers[player.GetId()];
|
||||
SPAssert(clientPlayer);
|
||||
ClientPlayer &clientPlayer = *clientPlayers[player.GetId()];
|
||||
|
||||
float delta = .8f;
|
||||
switch (player.GetWeapon().GetWeaponType()) {
|
||||
@ -131,7 +130,7 @@ namespace spades {
|
||||
case SHOTGUN_WEAPON: delta = .4f; break;
|
||||
}
|
||||
|
||||
float aimDownState = clientPlayer->GetAimDownState();
|
||||
float aimDownState = clientPlayer.GetAimDownState();
|
||||
|
||||
return 1.f + (3.f - 2.f * powf(aimDownState, 1.5f)) * powf(aimDownState, 3.f) * delta;
|
||||
}
|
||||
|
@ -109,9 +109,7 @@ namespace spades {
|
||||
if (!world || !world->GetLocalPlayerIndex()) {
|
||||
return {};
|
||||
}
|
||||
return clientPlayers.at(static_cast<std::size_t>(*world->GetLocalPlayerIndex()))
|
||||
.
|
||||
operator ClientPlayer *();
|
||||
return clientPlayers.at(static_cast<std::size_t>(*world->GetLocalPlayerIndex()));
|
||||
}
|
||||
|
||||
#pragma mark - World Actions
|
||||
@ -156,7 +154,8 @@ namespace spades {
|
||||
if (!quiet) {
|
||||
Handle<IAudioChunk> c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/SwitchLocal.opus");
|
||||
audioDevice->PlayLocal(c, MakeVector3(.4f, -.3f, .5f), AudioParam());
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), MakeVector3(.4f, -.3f, .5f),
|
||||
AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -537,7 +536,7 @@ namespace spades {
|
||||
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/FleshLocal4.opus");
|
||||
break;
|
||||
}
|
||||
audioDevice->PlayLocal(c, AudioParam());
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), AudioParam());
|
||||
|
||||
float hpper = player.GetHealth() / 100.f;
|
||||
int cnt = 18 - (int)(player.GetHealth() / 100.f * 8.f);
|
||||
@ -581,7 +580,7 @@ namespace spades {
|
||||
Handle<IAudioChunk> c =
|
||||
p.GetWade() ? audioDevice->RegisterSound("Sounds/Player/WaterJump.opus")
|
||||
: audioDevice->RegisterSound("Sounds/Player/Jump.opus");
|
||||
audioDevice->Play(c, p.GetOrigin(), AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), p.GetOrigin(), AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -596,7 +595,7 @@ namespace spades {
|
||||
c = audioDevice->RegisterSound("Sounds/Player/WaterLand.opus");
|
||||
else
|
||||
c = audioDevice->RegisterSound("Sounds/Player/Land.opus");
|
||||
audioDevice->Play(c, p.GetOrigin(), AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), p.GetOrigin(), AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -628,12 +627,12 @@ namespace spades {
|
||||
Handle<IAudioChunk> c = p.GetWade()
|
||||
? audioDevice->RegisterSound(SampleRandomElement(wsnds))
|
||||
: audioDevice->RegisterSound(SampleRandomElement(snds));
|
||||
audioDevice->Play(c, p.GetOrigin(), AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), p.GetOrigin(), AudioParam());
|
||||
if (sprinting && !p.GetWade()) {
|
||||
AudioParam param;
|
||||
param.volume *= clientPlayers[p.GetId()]->GetSprintState();
|
||||
c = audioDevice->RegisterSound(SampleRandomElement(rsnds));
|
||||
audioDevice->Play(c, p.GetOrigin(), param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), p.GetOrigin(), param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -654,11 +653,13 @@ namespace spades {
|
||||
bool isLocal = &p == world->GetLocalPlayer();
|
||||
Handle<IAudioChunk> c = audioDevice->RegisterSound("Sounds/Weapons/DryFire.opus");
|
||||
if (isLocal)
|
||||
audioDevice->PlayLocal(c, MakeVector3(.4f, -.3f, .5f), AudioParam());
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), MakeVector3(.4f, -.3f, .5f),
|
||||
AudioParam());
|
||||
else
|
||||
audioDevice->Play(
|
||||
c, p.GetEye() + p.GetFront() * 0.5f - p.GetUp() * .3f + p.GetRight() * .4f,
|
||||
AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(),
|
||||
p.GetEye() + p.GetFront() * 0.5f - p.GetUp() * .3f +
|
||||
p.GetRight() * .4f,
|
||||
AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -687,11 +688,13 @@ namespace spades {
|
||||
c = audioDevice->RegisterSound("Sounds/Weapons/Switch.opus");
|
||||
}
|
||||
if (isLocal)
|
||||
audioDevice->PlayLocal(c, MakeVector3(.4f, -.3f, .5f), AudioParam());
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), MakeVector3(.4f, -.3f, .5f),
|
||||
AudioParam());
|
||||
else
|
||||
audioDevice->Play(
|
||||
c, p.GetEye() + p.GetFront() * 0.5f - p.GetUp() * .3f + p.GetRight() * .4f,
|
||||
AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(),
|
||||
p.GetEye() + p.GetFront() * 0.5f - p.GetUp() * .3f +
|
||||
p.GetRight() * .4f,
|
||||
AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -702,11 +705,13 @@ namespace spades {
|
||||
isLocal ? audioDevice->RegisterSound("Sounds/Weapons/RestockLocal.opus")
|
||||
: audioDevice->RegisterSound("Sounds/Weapons/Restock.opus");
|
||||
if (isLocal)
|
||||
audioDevice->PlayLocal(c, MakeVector3(.4f, -.3f, .5f), AudioParam());
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), MakeVector3(.4f, -.3f, .5f),
|
||||
AudioParam());
|
||||
else
|
||||
audioDevice->Play(
|
||||
c, p.GetEye() + p.GetFront() * 0.5f - p.GetUp() * .3f + p.GetRight() * .4f,
|
||||
AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(),
|
||||
p.GetEye() + p.GetFront() * 0.5f - p.GetUp() * .3f +
|
||||
p.GetRight() * .4f,
|
||||
AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -724,11 +729,13 @@ namespace spades {
|
||||
}
|
||||
|
||||
if (isLocal)
|
||||
audioDevice->PlayLocal(c, MakeVector3(.4f, 0.1f, .3f), AudioParam());
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), MakeVector3(.4f, 0.1f, .3f),
|
||||
AudioParam());
|
||||
else
|
||||
audioDevice->Play(
|
||||
c, p.GetEye() + p.GetFront() * 0.5f - p.GetUp() * .2f + p.GetRight() * .3f,
|
||||
AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(),
|
||||
p.GetEye() + p.GetFront() * 0.5f - p.GetUp() * .2f +
|
||||
p.GetRight() * .3f,
|
||||
AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -740,9 +747,11 @@ namespace spades {
|
||||
Handle<IAudioChunk> c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Spade/Miss.opus");
|
||||
if (isLocal)
|
||||
audioDevice->PlayLocal(c, MakeVector3(.2f, -.1f, 0.7f), AudioParam());
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), MakeVector3(.2f, -.1f, 0.7f),
|
||||
AudioParam());
|
||||
else
|
||||
audioDevice->Play(c, p.GetOrigin() + p.GetFront() * 0.8f - p.GetUp() * .2f,
|
||||
audioDevice->Play(c.GetPointerOrNull(),
|
||||
p.GetOrigin() + p.GetFront() * 0.8f - p.GetUp() * .2f,
|
||||
AudioParam());
|
||||
}
|
||||
}
|
||||
@ -769,9 +778,11 @@ namespace spades {
|
||||
Handle<IAudioChunk> c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Spade/HitBlock.opus");
|
||||
if (isLocal)
|
||||
audioDevice->PlayLocal(c, MakeVector3(.1f, -.1f, 1.2f), AudioParam());
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), MakeVector3(.1f, -.1f, 1.2f),
|
||||
AudioParam());
|
||||
else
|
||||
audioDevice->Play(c, p.GetOrigin() + p.GetFront() * 0.5f - p.GetUp() * .2f,
|
||||
audioDevice->Play(c.GetPointerOrNull(),
|
||||
p.GetOrigin() + p.GetFront() * 0.5f - p.GetUp() * .2f,
|
||||
AudioParam());
|
||||
}
|
||||
}
|
||||
@ -800,7 +811,7 @@ namespace spades {
|
||||
}
|
||||
AudioParam param;
|
||||
param.volume = 4.f;
|
||||
audioDevice->Play(c, victim.GetEye(), param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), victim.GetEye(), param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -966,7 +977,7 @@ namespace spades {
|
||||
if (type == HitTypeMelee) {
|
||||
Handle<IAudioChunk> c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Spade/HitPlayer.opus");
|
||||
audioDevice->Play(c, hitPos, AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), hitPos, AudioParam());
|
||||
} else {
|
||||
Handle<IAudioChunk> c;
|
||||
switch (SampleRandomInt(0, 2)) {
|
||||
@ -982,7 +993,7 @@ namespace spades {
|
||||
}
|
||||
AudioParam param;
|
||||
param.volume = 4.f;
|
||||
audioDevice->Play(c, hitPos, param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), hitPos, param);
|
||||
}
|
||||
}
|
||||
|
||||
@ -994,7 +1005,7 @@ namespace spades {
|
||||
audioDevice->RegisterSound("Sounds/Feedback/HeadshotFeedback.opus");
|
||||
AudioParam param;
|
||||
param.volume = cg_hitFeedbackSoundGain;
|
||||
audioDevice->PlayLocal(c, param);
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), param);
|
||||
}
|
||||
|
||||
hitFeedbackIconState = 1.f;
|
||||
@ -1039,7 +1050,7 @@ namespace spades {
|
||||
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/Water4.opus");
|
||||
break;
|
||||
}
|
||||
audioDevice->Play(c, shiftedHitPos, param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), shiftedHitPos, param);
|
||||
}
|
||||
} else {
|
||||
EmitBlockFragments(shiftedHitPos, colV);
|
||||
@ -1050,7 +1061,7 @@ namespace spades {
|
||||
|
||||
Handle<IAudioChunk> c;
|
||||
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/Block.opus");
|
||||
audioDevice->Play(c, shiftedHitPos, param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), shiftedHitPos, param);
|
||||
|
||||
param.pitch = .9f + SampleRandomFloat() * 0.2f;
|
||||
param.volume = 2.f;
|
||||
@ -1068,7 +1079,7 @@ namespace spades {
|
||||
c = audioDevice->RegisterSound("Sounds/Weapons/Impacts/Ricochet4.opus");
|
||||
break;
|
||||
}
|
||||
audioDevice->Play(c, shiftedHitPos, param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), shiftedHitPos, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1110,7 +1121,7 @@ namespace spades {
|
||||
o += .5f;
|
||||
|
||||
Handle<IAudioChunk> c = audioDevice->RegisterSound("Sounds/Misc/BlockFall.opus");
|
||||
audioDevice->Play(c, o, AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), o, AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1121,7 +1132,7 @@ namespace spades {
|
||||
if (!IsMuted()) {
|
||||
Handle<IAudioChunk> c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Grenade/Bounce.opus");
|
||||
audioDevice->Play(c, g.GetPosition(), AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), g.GetPosition(), AudioParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1132,7 +1143,7 @@ namespace spades {
|
||||
if (!IsMuted()) {
|
||||
Handle<IAudioChunk> c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Grenade/DropWater.opus");
|
||||
audioDevice->Play(c, g.GetPosition(), AudioParam());
|
||||
audioDevice->Play(c.GetPointerOrNull(), g.GetPosition(), AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1147,17 +1158,17 @@ namespace spades {
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Grenade/WaterExplode.opus");
|
||||
AudioParam param;
|
||||
param.volume = 10.f;
|
||||
audioDevice->Play(c, g.GetPosition(), param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), g.GetPosition(), param);
|
||||
|
||||
c = audioDevice->RegisterSound("Sounds/Weapons/Grenade/WaterExplodeFar.opus");
|
||||
param.volume = 6.f;
|
||||
param.referenceDistance = 10.f;
|
||||
audioDevice->Play(c, g.GetPosition(), param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), g.GetPosition(), param);
|
||||
|
||||
c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Grenade/WaterExplodeStereo.opus");
|
||||
param.volume = 2.f;
|
||||
audioDevice->Play(c, g.GetPosition(), param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), g.GetPosition(), param);
|
||||
}
|
||||
|
||||
GrenadeExplosionUnderwater(g.GetPosition());
|
||||
@ -1184,19 +1195,19 @@ namespace spades {
|
||||
AudioParam param;
|
||||
param.volume = 30.f;
|
||||
param.referenceDistance = 5.f;
|
||||
audioDevice->Play(c, g.GetPosition(), param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), g.GetPosition(), param);
|
||||
|
||||
param.referenceDistance = 1.f;
|
||||
audioDevice->Play(cs, g.GetPosition(), param);
|
||||
audioDevice->Play(cs.GetPointerOrNull(), g.GetPosition(), param);
|
||||
|
||||
c = audioDevice->RegisterSound("Sounds/Weapons/Grenade/ExplodeFar.opus");
|
||||
param.volume = 6.f;
|
||||
param.referenceDistance = 40.f;
|
||||
audioDevice->Play(c, g.GetPosition(), param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), g.GetPosition(), param);
|
||||
|
||||
c = audioDevice->RegisterSound("Sounds/Weapons/Grenade/ExplodeFarStereo.opus");
|
||||
param.referenceDistance = 10.f;
|
||||
audioDevice->Play(c, g.GetPosition(), param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), g.GetPosition(), param);
|
||||
|
||||
// debri sound
|
||||
c = audioDevice->RegisterSound("Sounds/Weapons/Grenade/Debris.opus");
|
||||
@ -1207,7 +1218,7 @@ namespace spades {
|
||||
if (world->GetMap()->CastRay(soundPos, MakeVector3(0, 0, 1), 8.f, outPos)) {
|
||||
soundPos.z = (float)outPos.z - .2f;
|
||||
}
|
||||
audioDevice->Play(c, soundPos, param);
|
||||
audioDevice->Play(c.GetPointerOrNull(), soundPos, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1218,7 +1229,8 @@ namespace spades {
|
||||
if (!IsMuted()) {
|
||||
Handle<IAudioChunk> c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Grenade/Fire.opus");
|
||||
audioDevice->PlayLocal(c, MakeVector3(.4f, -.3f, .5f), AudioParam());
|
||||
audioDevice->PlayLocal(c.GetPointerOrNull(), MakeVector3(.4f, -.3f, .5f),
|
||||
AudioParam());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ namespace spades {
|
||||
matrix = Matrix4::Translate(matTrans);
|
||||
|
||||
// build renderer model
|
||||
model = client->GetRenderer()->CreateModel(*vmodel).Unmanage();
|
||||
model = client->GetRenderer().CreateModel(*vmodel).Unmanage();
|
||||
|
||||
time = 0.f;
|
||||
}
|
||||
@ -122,7 +122,7 @@ namespace spades {
|
||||
Vector3 vmAxis2 = vmat.GetAxis(1);
|
||||
Vector3 vmAxis3 = vmat.GetAxis(2);
|
||||
|
||||
Handle<IImage> img = client->GetRenderer()->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> img = client->GetRenderer().RegisterImage("Gfx/White.tga");
|
||||
|
||||
bool usePrecisePhysics = false;
|
||||
float dist =
|
||||
@ -187,7 +187,7 @@ namespace spades {
|
||||
col.w = 1.f;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
ParticleSpriteEntity *ent =
|
||||
new ParticleSpriteEntity(client, img, col);
|
||||
new ParticleSpriteEntity(client, img.GetPointerOrNull(), col);
|
||||
ent->SetTrajectory(p3,
|
||||
MakeVector3(getRandom() - getRandom(),
|
||||
getRandom() - getRandom(),
|
||||
@ -223,7 +223,7 @@ namespace spades {
|
||||
void FallingBlock::Render3D() {
|
||||
ModelRenderParam param;
|
||||
param.matrix = matrix;
|
||||
client->GetRenderer()->RenderModel(*model, param);
|
||||
client->GetRenderer().RenderModel(*model, param);
|
||||
}
|
||||
} // namespace client
|
||||
} // namespace spades
|
||||
|
@ -65,31 +65,36 @@ namespace spades {
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
FontManager::FontManager(IRenderer *renderer) {
|
||||
{
|
||||
auto *font =
|
||||
new Quake3Font(renderer, renderer->RegisterImage("Gfx/Fonts/SquareFontBig.png"),
|
||||
(const int *)SquareFontBigMap, 48, 8, true);
|
||||
auto font = Handle<Quake3Font>::New(
|
||||
renderer,
|
||||
renderer->RegisterImage("Gfx/Fonts/SquareFontBig.png").GetPointerOrNull(),
|
||||
(const int *)SquareFontBigMap, 48, 8.f, true);
|
||||
font->SetGlyphYRange(11.f, 37.f);
|
||||
SPLog("Font 'SquareFont (Large)' Loaded");
|
||||
squareDesignFont.Set(font, false);
|
||||
squareDesignFont = std::move(font).Cast<IFont>();
|
||||
}
|
||||
largeFont.Set(
|
||||
new ngclient::FTFont(renderer, GlobalFontInfo::GetInstance().guiFontSet, 34.f, 48.f),
|
||||
false);
|
||||
mediumFont.Set(
|
||||
new ngclient::FTFont(renderer, GlobalFontInfo::GetInstance().guiFontSet, 24.f, 32.f),
|
||||
false);
|
||||
headingFont.Set(
|
||||
new ngclient::FTFont(renderer, GlobalFontInfo::GetInstance().guiFontSet, 20.f, 26.f),
|
||||
false);
|
||||
guiFont.Set(
|
||||
new ngclient::FTFont(renderer, GlobalFontInfo::GetInstance().guiFontSet, 16.f, 20.f),
|
||||
false);
|
||||
largeFont =
|
||||
Handle<ngclient::FTFont>::New(
|
||||
renderer, GlobalFontInfo::GetInstance().guiFontSet.GetPointerOrNull(), 34.f, 48.f)
|
||||
.Cast<IFont>();
|
||||
mediumFont =
|
||||
Handle<ngclient::FTFont>::New(
|
||||
renderer, GlobalFontInfo::GetInstance().guiFontSet.GetPointerOrNull(), 24.f, 32.f)
|
||||
.Cast<IFont>();
|
||||
headingFont =
|
||||
Handle<ngclient::FTFont>::New(
|
||||
renderer, GlobalFontInfo::GetInstance().guiFontSet.GetPointerOrNull(), 20.f, 26.f)
|
||||
.Cast<IFont>();
|
||||
guiFont =
|
||||
Handle<ngclient::FTFont>::New(
|
||||
renderer, GlobalFontInfo::GetInstance().guiFontSet.GetPointerOrNull(), 16.f, 20.f)
|
||||
.Cast<IFont>();
|
||||
}
|
||||
|
||||
FontManager::~FontManager() {}
|
||||
}
|
||||
}
|
||||
} // namespace client
|
||||
} // namespace spades
|
||||
|
@ -29,11 +29,11 @@ namespace spades {
|
||||
public:
|
||||
FontManager(IRenderer *);
|
||||
|
||||
IFont *GetSquareDesignFont() { return squareDesignFont; }
|
||||
IFont *GetLargeFont() { return largeFont; }
|
||||
IFont *GetMediumFont() { return mediumFont; }
|
||||
IFont *GetHeadingFont() { return headingFont; }
|
||||
IFont *GetGuiFont() { return guiFont; }
|
||||
IFont &GetSquareDesignFont() { return *squareDesignFont; }
|
||||
IFont &GetLargeFont() { return *largeFont; }
|
||||
IFont &GetMediumFont() { return *mediumFont; }
|
||||
IFont &GetHeadingFont() { return *headingFont; }
|
||||
IFont &GetGuiFont() { return *guiFont; }
|
||||
|
||||
protected:
|
||||
~FontManager() override;
|
||||
|
@ -97,12 +97,12 @@ namespace spades {
|
||||
|
||||
if (waterSound) {
|
||||
if (dist < 40.f * 40.f && !client->IsMuted()) {
|
||||
IAudioDevice *dev = client->GetAudioDevice();
|
||||
IAudioDevice &dev = client->GetAudioDevice();
|
||||
AudioParam param;
|
||||
param.referenceDistance = .6f;
|
||||
param.pitch = .9f + SampleRandomFloat() * .2f;
|
||||
|
||||
dev->Play(waterSound, lastMat.GetOrigin(), param);
|
||||
dev.Play(waterSound, lastMat.GetOrigin(), param);
|
||||
}
|
||||
waterSound = NULL;
|
||||
}
|
||||
@ -110,13 +110,13 @@ namespace spades {
|
||||
if (dist < 40.f * 40.f) {
|
||||
int splats = SampleRandomInt(0, 2);
|
||||
|
||||
Handle<IImage> img = client->GetRenderer()->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> img = client->GetRenderer().RegisterImage("Gfx/White.tga");
|
||||
|
||||
Vector4 col = {1, 1, 1, 0.8f};
|
||||
Vector3 pt = matrix.GetOrigin();
|
||||
pt.z = 62.99f;
|
||||
for (int i = 0; i < splats; i++) {
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(client, img, col);
|
||||
ParticleSpriteEntity *ent = new ParticleSpriteEntity(client, img.GetPointerOrNull(), col);
|
||||
ent->SetTrajectory(
|
||||
pt,
|
||||
MakeVector3(SampleRandomFloat() - SampleRandomFloat(),
|
||||
@ -172,11 +172,11 @@ namespace spades {
|
||||
(client->GetLastSceneDef().viewOrigin - matrix.GetOrigin())
|
||||
.GetPoweredLength();
|
||||
if (dist < 40.f * 40.f && !client->IsMuted()) {
|
||||
IAudioDevice *dev = client->GetAudioDevice();
|
||||
IAudioDevice &dev = client->GetAudioDevice();
|
||||
AudioParam param;
|
||||
param.referenceDistance = .6f;
|
||||
|
||||
dev->Play(dropSound, lastMat.GetOrigin(), param);
|
||||
dev.Play(dropSound, lastMat.GetOrigin(), param);
|
||||
}
|
||||
dropSound = NULL;
|
||||
}
|
||||
@ -217,7 +217,7 @@ namespace spades {
|
||||
float move = (groundTime - 1.f) * .2f;
|
||||
param.matrix = Matrix4::Translate(0, 0, move) * param.matrix;
|
||||
}
|
||||
renderer->RenderModel(*model, param);
|
||||
renderer.RenderModel(*model, param);
|
||||
}
|
||||
} // namespace client
|
||||
} // namespace spades
|
||||
|
@ -31,7 +31,7 @@ namespace spades {
|
||||
class IAudioChunk;
|
||||
class GunCasing : public ILocalEntity {
|
||||
Client *client;
|
||||
IRenderer *renderer;
|
||||
IRenderer &renderer;
|
||||
IModel *model;
|
||||
Matrix4 matrix;
|
||||
Vector3 rotAxis;
|
||||
|
@ -45,7 +45,7 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
bmp.Set(new Bitmap(512, 512), false);
|
||||
}
|
||||
Bitmap *GetFramebuffer() override { return bmp; }
|
||||
Bitmap &GetFramebuffer() override { return *bmp; }
|
||||
void Swap() override {
|
||||
// nothing to do here
|
||||
}
|
||||
@ -54,7 +54,7 @@ namespace spades {
|
||||
HitTestDebugger::HitTestDebugger(World *world) : world(world) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
port.Set(new Port(), false);
|
||||
renderer.Set(new draw::SWRenderer(port), false);
|
||||
renderer.Set(new draw::SWRenderer(port.Cast<draw::SWPort>()), false);
|
||||
renderer->Init();
|
||||
}
|
||||
|
||||
@ -233,12 +233,12 @@ namespace spades {
|
||||
renderer->EndScene();
|
||||
|
||||
// draw crosshair
|
||||
IImage *img = renderer->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/White.tga");
|
||||
float size = renderer->ScreenWidth();
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(Vector4(1.f, 0.f, 0.f, 0.9f));
|
||||
renderer->DrawImage(img, AABB2(size * 0.5f - 1.f, 0.f, 2.f, size));
|
||||
renderer->DrawImage(img, AABB2(0.f, size * 0.5f - 1.f, size, 2.f));
|
||||
renderer->DrawImage(*img, AABB2(size * 0.5f - 1.f, 0.f, 2.f, size));
|
||||
renderer->DrawImage(*img, AABB2(0.f, size * 0.5f - 1.f, size, 2.f));
|
||||
|
||||
// draw bullet vectors
|
||||
float fov = tanf(def.fovY * .5f);
|
||||
@ -250,9 +250,9 @@ namespace spades {
|
||||
x = floorf(x);
|
||||
y = floorf(y);
|
||||
renderer->SetColorAlphaPremultiplied(Vector4(1.f, 0.f, 0.f, 0.9f));
|
||||
renderer->DrawImage(img, AABB2(x - 1.f, y - 1.f, 3.f, 3.f));
|
||||
renderer->DrawImage(*img, AABB2(x - 1.f, y - 1.f, 3.f, 3.f));
|
||||
renderer->SetColorAlphaPremultiplied(Vector4(1.f, 1.f, 0.f, 0.9f));
|
||||
renderer->DrawImage(img, AABB2(x, y, 1.f, 1.f));
|
||||
renderer->DrawImage(*img, AABB2(x, y, 1.f, 1.f));
|
||||
}
|
||||
|
||||
renderer->FrameDone();
|
||||
@ -297,7 +297,7 @@ namespace spades {
|
||||
|
||||
// save image
|
||||
try {
|
||||
Handle<Bitmap> b(renderer->ReadBitmap(), false);
|
||||
Handle<Bitmap> b = renderer->ReadBitmap();
|
||||
b->Save(fileName);
|
||||
SPLog("HitTestDebugger: saved to '%s'", fileName.c_str());
|
||||
} catch (const std::exception &ex) {
|
||||
|
@ -32,7 +32,7 @@ namespace spades {
|
||||
HurtRingView::HurtRingView(Client *cli) : client(cli), renderer(cli->GetRenderer()) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
image = renderer->RegisterImage("Gfx/HurtRing2.png");
|
||||
image = renderer.RegisterImage("Gfx/HurtRing2.png");
|
||||
}
|
||||
|
||||
HurtRingView::~HurtRingView() {}
|
||||
@ -82,9 +82,9 @@ namespace spades {
|
||||
|
||||
playerFront = p->GetFront2D();
|
||||
|
||||
float hurtRingSize = renderer->ScreenHeight() * .3f;
|
||||
float cx = renderer->ScreenWidth() * .5f;
|
||||
float cy = renderer->ScreenHeight() * .5f;
|
||||
float hurtRingSize = renderer.ScreenHeight() * .3f;
|
||||
float cx = renderer.ScreenWidth() * .5f;
|
||||
float cy = renderer.ScreenHeight() * .5f;
|
||||
static const float coords[][2] = {{-1, 1}, {1, 1}, {-1, 0}};
|
||||
|
||||
std::list<Item>::iterator it;
|
||||
@ -95,7 +95,7 @@ namespace spades {
|
||||
if (fade > 1.f)
|
||||
fade = 1.f;
|
||||
Vector4 color = {fade, fade, fade, 0};
|
||||
renderer->SetColorAlphaPremultiplied(color);
|
||||
renderer.SetColorAlphaPremultiplied(color);
|
||||
|
||||
Vector3 dir = -item.dir;
|
||||
float c = dir.x * playerFront.x + dir.y * playerFront.y;
|
||||
@ -108,8 +108,8 @@ namespace spades {
|
||||
verts[i] = verts[i] * hurtRingSize + MakeVector2(cx, cy);
|
||||
}
|
||||
|
||||
renderer->DrawImage(image, verts[0], verts[1], verts[2],
|
||||
AABB2(0, 0, image->GetWidth(), image->GetHeight()));
|
||||
renderer.DrawImage(image, verts[0], verts[1], verts[2],
|
||||
AABB2(0, 0, image->GetWidth(), image->GetHeight()));
|
||||
}
|
||||
}
|
||||
} // namespace client
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <list>
|
||||
|
||||
#include <Core/Math.h>
|
||||
#include <Core/RefCountedObject.h>
|
||||
|
||||
namespace spades {
|
||||
namespace client {
|
||||
@ -32,8 +33,8 @@ namespace spades {
|
||||
|
||||
class HurtRingView {
|
||||
Client *client;
|
||||
IRenderer *renderer;
|
||||
IImage *image;
|
||||
IRenderer &renderer;
|
||||
Handle<IImage> image;
|
||||
|
||||
struct Item {
|
||||
Vector3 dir;
|
||||
|
@ -226,11 +226,11 @@ namespace spades {
|
||||
auto glyph = FindGlyph(unicode);
|
||||
if (glyph.img == nullptr) {
|
||||
// no glyph found! draw box in the last resort
|
||||
IImage *img = whiteImage;
|
||||
renderer->DrawImage(img, AABB2(x, y, size, 1.f));
|
||||
renderer->DrawImage(img, AABB2(x, y + size - 1.f, size, 1.f));
|
||||
renderer->DrawImage(img, AABB2(x, y + 1.f, 1.f, size - 2.f));
|
||||
renderer->DrawImage(img, AABB2(x + size - 1.f, y + 1.f, 1.f, size - 2.f));
|
||||
const Handle<IImage> &img = whiteImage;
|
||||
renderer->DrawImage(*img, AABB2(x, y, size, 1.f));
|
||||
renderer->DrawImage(*img, AABB2(x, y + size - 1.f, size, 1.f));
|
||||
renderer->DrawImage(*img, AABB2(x, y + 1.f, 1.f, size - 2.f));
|
||||
renderer->DrawImage(*img, AABB2(x + size - 1.f, y + 1.f, 1.f, size - 2.f));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ namespace spades {
|
||||
* See the existing code for usage. */
|
||||
std::array<Vector3, 3> spotAxis;
|
||||
/** The projected image for a spotlight. */
|
||||
IImage *image = nullptr;
|
||||
IImage *image = nullptr; // TODO: Replace this raw pointer with something
|
||||
float spotAngle = 0.0f;
|
||||
|
||||
/** When set to `true`, the lens flare post-effect is enabled for
|
||||
|
@ -45,8 +45,8 @@ namespace spades {
|
||||
float menuHeight = menuWidth / 8.f;
|
||||
float rowHeight = menuHeight + 3.f;
|
||||
|
||||
float left = (renderer->ScreenWidth() - contentsWidth) * .5f;
|
||||
float top = renderer->ScreenHeight() - 150.f;
|
||||
float left = (renderer.ScreenWidth() - contentsWidth) * .5f;
|
||||
float top = renderer.ScreenHeight() - 150.f;
|
||||
|
||||
float teamX = left + 10.f;
|
||||
float firstY = top + 35.f;
|
||||
@ -78,7 +78,7 @@ namespace spades {
|
||||
AABB2(left + contentsWidth - 266.f, firstY + 4.f, 256.f, 64.f),
|
||||
_Tr("Client", "Spawn")));
|
||||
|
||||
cursorPos = MakeVector2(renderer->ScreenWidth() * .5f, renderer->ScreenHeight() * .5f);
|
||||
cursorPos = MakeVector2(renderer.ScreenWidth() * .5f, renderer.ScreenHeight() * .5f);
|
||||
|
||||
selectedTeam = 2;
|
||||
selectedWeapon = RIFLE_WEAPON;
|
||||
@ -90,8 +90,8 @@ namespace spades {
|
||||
cursorPos.y = y;
|
||||
|
||||
// clip
|
||||
float w = renderer->ScreenWidth();
|
||||
float h = renderer->ScreenHeight();
|
||||
float w = renderer.ScreenWidth();
|
||||
float h = renderer.ScreenHeight();
|
||||
|
||||
cursorPos.x = std::max(cursorPos.x, 0.f);
|
||||
cursorPos.y = std::max(cursorPos.y, 0.f);
|
||||
@ -104,10 +104,10 @@ namespace spades {
|
||||
for (size_t i = 0; i < items.size(); i++) {
|
||||
MenuItem &item = items[i];
|
||||
if (item.hover) {
|
||||
IAudioDevice *dev = client->audioDevice;
|
||||
IAudioDevice &dev = *client->audioDevice;
|
||||
Handle<IAudioChunk> chunk =
|
||||
dev->RegisterSound("Sounds/Feedback/Limbo/Select.opus");
|
||||
dev->PlayLocal(chunk, AudioParam());
|
||||
dev.RegisterSound("Sounds/Feedback/Limbo/Select.opus");
|
||||
dev.PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
switch (item.type) {
|
||||
case MenuTeam1: selectedTeam = 0; break;
|
||||
case MenuTeam2: selectedTeam = 1; break;
|
||||
@ -163,37 +163,35 @@ namespace spades {
|
||||
if (!item.visible)
|
||||
newHover = false;
|
||||
if (newHover && !item.hover) {
|
||||
IAudioDevice *dev = client->audioDevice;
|
||||
IAudioDevice &dev = *client->audioDevice;
|
||||
Handle<IAudioChunk> chunk =
|
||||
dev->RegisterSound("Sounds/Feedback/Limbo/Hover.opus");
|
||||
dev->PlayLocal(chunk, AudioParam());
|
||||
dev.RegisterSound("Sounds/Feedback/Limbo/Hover.opus");
|
||||
dev.PlayLocal(chunk.GetPointerOrNull(), AudioParam());
|
||||
}
|
||||
item.hover = newHover;
|
||||
}
|
||||
}
|
||||
|
||||
void LimboView::Draw() {
|
||||
Handle<IImage> menuItemImage = renderer->RegisterImage("Gfx/Limbo/MenuItem.png");
|
||||
Handle<IImage> menuItemBigImage = renderer->RegisterImage("Gfx/Limbo/BigMenuItem.png");
|
||||
IFont *font = client->fontManager->GetGuiFont();
|
||||
Handle<IImage> menuItemImage = renderer.RegisterImage("Gfx/Limbo/MenuItem.png");
|
||||
Handle<IImage> menuItemBigImage = renderer.RegisterImage("Gfx/Limbo/BigMenuItem.png");
|
||||
IFont &font = client->fontManager->GetGuiFont();
|
||||
|
||||
float left = (renderer->ScreenWidth() - contentsWidth) * .5f;
|
||||
float top = renderer->ScreenHeight() - 150.f;
|
||||
float left = (renderer.ScreenWidth() - contentsWidth) * .5f;
|
||||
float top = renderer.ScreenHeight() - 150.f;
|
||||
{
|
||||
std::string msg = _Tr("Client", "Select Team:");
|
||||
Vector2 pos;
|
||||
pos.x = left + 10.f;
|
||||
pos.y = top + 10.f;
|
||||
font->DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.4f));
|
||||
font.DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1), MakeVector4(0, 0, 0, 0.4f));
|
||||
}
|
||||
if (selectedTeam != 2) {
|
||||
std::string msg = _Tr("Client", "Select Weapon:");
|
||||
Vector2 pos;
|
||||
pos.x = left + 260.f;
|
||||
pos.y = top + 10.f;
|
||||
font->DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.4f));
|
||||
font.DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1), MakeVector4(0, 0, 0, 0.4f));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < items.size(); i++) {
|
||||
@ -230,47 +228,47 @@ namespace spades {
|
||||
fillColor = MakeVector4(.7f, .7f, .7f, 1.f) * .9f;
|
||||
}
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(fillColor);
|
||||
renderer.SetColorAlphaPremultiplied(fillColor);
|
||||
if (item.type == MenuSpawn) {
|
||||
renderer->DrawImage(menuItemBigImage, item.rect);
|
||||
renderer.DrawImage(menuItemBigImage, item.rect);
|
||||
|
||||
std::string msg = item.text;
|
||||
IFont *bFont = client->fontManager->GetGuiFont();
|
||||
Vector2 size = bFont->Measure(msg);
|
||||
IFont &bFont = client->fontManager->GetGuiFont();
|
||||
Vector2 size = bFont.Measure(msg);
|
||||
Vector2 pos;
|
||||
pos.x = item.rect.GetMinX() + (item.rect.GetWidth() - size.x) / 2.f + 2.f;
|
||||
pos.y = item.rect.GetMinY() + (item.rect.GetHeight() - size.y) / 2.f;
|
||||
bFont->DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.4f));
|
||||
bFont.DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.4f));
|
||||
} else {
|
||||
renderer->DrawImage(menuItemImage, item.rect);
|
||||
renderer.DrawImage(menuItemImage, item.rect);
|
||||
|
||||
std::string msg = item.text;
|
||||
if (item.type == MenuTeam1)
|
||||
msg = client->GetWorld()->GetTeam(0).name;
|
||||
if (item.type == MenuTeam2)
|
||||
msg = client->GetWorld()->GetTeam(1).name;
|
||||
Vector2 size = font->Measure(msg);
|
||||
Vector2 size = font.Measure(msg);
|
||||
Vector2 pos;
|
||||
pos.x = item.rect.GetMinX() + 5.f;
|
||||
pos.y = item.rect.GetMinY() + (item.rect.GetHeight() - size.y) / 2.f;
|
||||
font->DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.4f));
|
||||
font.DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.4f));
|
||||
if (index > 0) {
|
||||
std::stringstream ss;
|
||||
ss << index;
|
||||
msg = ss.str();
|
||||
pos.x = item.rect.GetMaxX() - 5.f - font->Measure(msg).x;
|
||||
font->DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.4f));
|
||||
pos.x = item.rect.GetMaxX() - 5.f - font.Measure(msg).x;
|
||||
font.DrawShadow(msg, pos, 1.f, MakeVector4(1, 1, 1, 1),
|
||||
MakeVector4(0, 0, 0, 0.4f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Handle<IImage> cursor = renderer->RegisterImage("Gfx/Limbo/Cursor.png");
|
||||
Handle<IImage> cursor = renderer.RegisterImage("Gfx/Limbo/Cursor.png");
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1));
|
||||
renderer->DrawImage(cursor, AABB2(cursorPos.x - 8, cursorPos.y - 8, 32, 32));
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1));
|
||||
renderer.DrawImage(cursor, AABB2(cursorPos.x - 8, cursorPos.y - 8, 32, 32));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace client
|
||||
} // namespace spades
|
||||
|
@ -52,7 +52,7 @@ namespace spades {
|
||||
: type(type), rect(rt), text(txt), hover(false) {}
|
||||
};
|
||||
Client *client;
|
||||
IRenderer *renderer;
|
||||
IRenderer &renderer;
|
||||
|
||||
std::vector<MenuItem> items;
|
||||
|
||||
|
@ -142,7 +142,7 @@ namespace spades {
|
||||
return scrPos;
|
||||
}
|
||||
|
||||
void MapView::DrawIcon(spades::Vector3 pos, spades::client::IImage *img, float rotation) {
|
||||
void MapView::DrawIcon(spades::Vector3 pos, IImage &img, float rotation) {
|
||||
if (pos.x < inRect.GetMinX() || pos.x > inRect.GetMaxX() || pos.y < inRect.GetMinY() ||
|
||||
pos.y > inRect.GetMaxY())
|
||||
return;
|
||||
@ -155,8 +155,8 @@ namespace spades {
|
||||
float c = rotation != 0.f ? cosf(rotation) : 1.f;
|
||||
float s = rotation != 0.f ? sinf(rotation) : 0.f;
|
||||
static const float coords[][2] = {{-1, -1}, {1, -1}, {-1, 1}};
|
||||
Vector2 u = MakeVector2(img->GetWidth() * .5f, 0.f);
|
||||
Vector2 v = MakeVector2(0.f, img->GetHeight() * .5f);
|
||||
Vector2 u = MakeVector2(img.GetWidth() * .5f, 0.f);
|
||||
Vector2 v = MakeVector2(0.f, img.GetHeight() * .5f);
|
||||
|
||||
Vector2 vt[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@ -165,8 +165,8 @@ namespace spades {
|
||||
vt[i].y = scrPos.y + ss.x * s + ss.y * c;
|
||||
}
|
||||
|
||||
renderer->DrawImage(img, vt[0], vt[1], vt[2],
|
||||
AABB2(0, 0, img->GetWidth(), img->GetHeight()));
|
||||
renderer.DrawImage(img, vt[0], vt[1], vt[2],
|
||||
AABB2(0, 0, img.GetWidth(), img.GetHeight()));
|
||||
}
|
||||
|
||||
void MapView::SwitchScale() {
|
||||
@ -291,7 +291,7 @@ namespace spades {
|
||||
center = Mix(center, mapSize * .5f, zoomState);
|
||||
|
||||
Vector2 zoomedSize = {512, 512};
|
||||
if (renderer->ScreenWidth() < 512.f || renderer->ScreenHeight() < 512.f)
|
||||
if (renderer.ScreenWidth() < 512.f || renderer.ScreenHeight() < 512.f)
|
||||
zoomedSize = MakeVector2(256, 256);
|
||||
if (largeMap) {
|
||||
float per = zoomState;
|
||||
@ -319,13 +319,13 @@ namespace spades {
|
||||
inRect = inRect.Translated(0, mapSize.y - inRect.GetMaxY());
|
||||
}
|
||||
|
||||
AABB2 outRect(renderer->ScreenWidth() - mapWndSize.x - 16.f, 16.f, mapWndSize.x,
|
||||
AABB2 outRect(renderer.ScreenWidth() - mapWndSize.x - 16.f, 16.f, mapWndSize.x,
|
||||
mapWndSize.y);
|
||||
if (largeMap) {
|
||||
outRect.min = MakeVector2((renderer->ScreenWidth() - zoomedSize.x) * .5f,
|
||||
(renderer->ScreenHeight() - zoomedSize.y) * .5f);
|
||||
outRect.max = MakeVector2((renderer->ScreenWidth() + zoomedSize.x) * .5f,
|
||||
(renderer->ScreenHeight() + zoomedSize.y) * .5f);
|
||||
outRect.min = MakeVector2((renderer.ScreenWidth() - zoomedSize.x) * .5f,
|
||||
(renderer.ScreenHeight() - zoomedSize.y) * .5f);
|
||||
outRect.max = MakeVector2((renderer.ScreenWidth() + zoomedSize.x) * .5f,
|
||||
(renderer.ScreenHeight() + zoomedSize.y) * .5f);
|
||||
}
|
||||
|
||||
float alpha = 1.f;
|
||||
@ -335,11 +335,11 @@ namespace spades {
|
||||
|
||||
// fades bg
|
||||
if (largeMap) {
|
||||
Handle<IImage> bg = renderer->RegisterImage("Gfx/MapBg.png");
|
||||
Vector2 scrSize = {renderer->ScreenWidth(), renderer->ScreenHeight()};
|
||||
Handle<IImage> bg = renderer.RegisterImage("Gfx/MapBg.png");
|
||||
Vector2 scrSize = {renderer.ScreenWidth(), renderer.ScreenHeight()};
|
||||
float size = std::max(scrSize.x, scrSize.y);
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, alpha * .5f));
|
||||
renderer->DrawImage(
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, alpha * .5f));
|
||||
renderer.DrawImage(
|
||||
bg, AABB2((scrSize.x - size) * .5f, (scrSize.y - size) * .5f, size, size));
|
||||
}
|
||||
|
||||
@ -348,60 +348,60 @@ namespace spades {
|
||||
float borderWidth;
|
||||
AABB2 borderRect = outRect;
|
||||
if (largeMap) {
|
||||
border = renderer->RegisterImage("Gfx/MapBorder.png");
|
||||
border = renderer.RegisterImage("Gfx/MapBorder.png");
|
||||
borderWidth = 3.f * outRect.GetHeight() / zoomedSize.y;
|
||||
} else {
|
||||
border = renderer->RegisterImage("Gfx/MinimapBorder.png");
|
||||
border = renderer.RegisterImage("Gfx/MinimapBorder.png");
|
||||
borderWidth = 2.f;
|
||||
}
|
||||
borderRect = borderRect.Inflate(borderWidth - 8.f);
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(alpha, alpha, alpha, alpha));
|
||||
renderer->DrawImage(border,
|
||||
AABB2(borderRect.GetMinX() - 16, borderRect.GetMinY() - 16, 16, 16),
|
||||
AABB2(0, 0, 16, 16));
|
||||
renderer->DrawImage(border,
|
||||
AABB2(borderRect.GetMaxX(), borderRect.GetMinY() - 16, 16, 16),
|
||||
AABB2(16, 0, 16, 16));
|
||||
renderer->DrawImage(border,
|
||||
AABB2(borderRect.GetMinX() - 16, borderRect.GetMaxY(), 16, 16),
|
||||
AABB2(0, 16, 16, 16));
|
||||
renderer->DrawImage(border, AABB2(borderRect.GetMaxX(), borderRect.GetMaxY(), 16, 16),
|
||||
AABB2(16, 16, 16, 16));
|
||||
renderer->DrawImage(
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(alpha, alpha, alpha, alpha));
|
||||
renderer.DrawImage(border,
|
||||
AABB2(borderRect.GetMinX() - 16, borderRect.GetMinY() - 16, 16, 16),
|
||||
AABB2(0, 0, 16, 16));
|
||||
renderer.DrawImage(border,
|
||||
AABB2(borderRect.GetMaxX(), borderRect.GetMinY() - 16, 16, 16),
|
||||
AABB2(16, 0, 16, 16));
|
||||
renderer.DrawImage(border,
|
||||
AABB2(borderRect.GetMinX() - 16, borderRect.GetMaxY(), 16, 16),
|
||||
AABB2(0, 16, 16, 16));
|
||||
renderer.DrawImage(border, AABB2(borderRect.GetMaxX(), borderRect.GetMaxY(), 16, 16),
|
||||
AABB2(16, 16, 16, 16));
|
||||
renderer.DrawImage(
|
||||
border,
|
||||
AABB2(borderRect.GetMinX(), borderRect.GetMinY() - 16, borderRect.GetWidth(), 16),
|
||||
AABB2(16, 0, 0, 16));
|
||||
renderer->DrawImage(
|
||||
renderer.DrawImage(
|
||||
border, AABB2(borderRect.GetMinX(), borderRect.GetMaxY(), borderRect.GetWidth(), 16),
|
||||
AABB2(16, 16, 0, 16));
|
||||
renderer->DrawImage(
|
||||
renderer.DrawImage(
|
||||
border,
|
||||
AABB2(borderRect.GetMinX() - 16, borderRect.GetMinY(), 16, borderRect.GetHeight()),
|
||||
AABB2(0, 16, 16, 0));
|
||||
renderer->DrawImage(
|
||||
renderer.DrawImage(
|
||||
border, AABB2(borderRect.GetMaxX(), borderRect.GetMinY(), 16, borderRect.GetHeight()),
|
||||
AABB2(16, 16, 16, 0));
|
||||
|
||||
// draw map
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(alpha, alpha, alpha, alpha));
|
||||
renderer->DrawFlatGameMap(outRect, inRect);
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(alpha, alpha, alpha, alpha));
|
||||
renderer.DrawFlatGameMap(outRect, inRect);
|
||||
|
||||
this->inRect = inRect;
|
||||
this->outRect = outRect;
|
||||
|
||||
// draw grid
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, 0.8f * alpha));
|
||||
Handle<IImage> dashLine = renderer->RegisterImage("Gfx/DashLine.tga");
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, 0.8f * alpha));
|
||||
Handle<IImage> dashLine = renderer.RegisterImage("Gfx/DashLine.tga");
|
||||
for (float x = 64.f; x < map->Width(); x += 64.f) {
|
||||
float wx = (x - inRect.GetMinX()) / inRect.GetWidth();
|
||||
if (wx < 0.f || wx >= 1.f)
|
||||
continue;
|
||||
wx = (wx * outRect.GetWidth()) + outRect.GetMinX();
|
||||
wx = roundf(wx);
|
||||
renderer->DrawImage(dashLine, MakeVector2(wx, outRect.GetMinY()),
|
||||
AABB2(0, 0, 1.f, outRect.GetHeight()));
|
||||
renderer.DrawImage(dashLine, MakeVector2(wx, outRect.GetMinY()),
|
||||
AABB2(0, 0, 1.f, outRect.GetHeight()));
|
||||
}
|
||||
for (float y = 64.f; y < map->Height(); y += 64.f) {
|
||||
float wy = (y - inRect.GetMinY()) / inRect.GetHeight();
|
||||
@ -409,13 +409,13 @@ namespace spades {
|
||||
continue;
|
||||
wy = (wy * outRect.GetHeight()) + outRect.GetMinY();
|
||||
wy = roundf(wy);
|
||||
renderer->DrawImage(dashLine, MakeVector2(outRect.GetMinX(), wy),
|
||||
AABB2(0, 0, outRect.GetWidth(), 1.f));
|
||||
renderer.DrawImage(dashLine, MakeVector2(outRect.GetMinX(), wy),
|
||||
AABB2(0, 0, outRect.GetWidth(), 1.f));
|
||||
}
|
||||
|
||||
// draw grid label
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1) * (0.8f * alpha));
|
||||
Handle<IImage> mapFont = renderer->RegisterImage("Gfx/Fonts/MapFont.tga");
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1) * (0.8f * alpha));
|
||||
Handle<IImage> mapFont = renderer.RegisterImage("Gfx/Fonts/MapFont.tga");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
float startX = (float)i * 64.f;
|
||||
float endX = startX + 64.f;
|
||||
@ -425,8 +425,7 @@ namespace spades {
|
||||
std::min((std::min(endX, inRect.GetMaxX()) - std::max(startX, inRect.GetMinX())) /
|
||||
(endX - startX) * 2.f,
|
||||
1.f);
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1) *
|
||||
(fade * .8f * alpha));
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1) * (fade * .8f * alpha));
|
||||
|
||||
float center = std::max(startX, inRect.GetMinX());
|
||||
center = .5f * (center + std::min(endX, inRect.GetMaxX()));
|
||||
@ -437,8 +436,8 @@ namespace spades {
|
||||
|
||||
float fntX = static_cast<float>((i & 3) * 8);
|
||||
float fntY = static_cast<float>((i >> 2) * 8);
|
||||
renderer->DrawImage(mapFont, MakeVector2(wx - 4.f, outRect.GetMinY() + 4),
|
||||
AABB2(fntX, fntY, 8, 8));
|
||||
renderer.DrawImage(mapFont, MakeVector2(wx - 4.f, outRect.GetMinY() + 4),
|
||||
AABB2(fntX, fntY, 8, 8));
|
||||
}
|
||||
for (int i = 0; i < 8; i++) {
|
||||
float startY = (float)i * 64.f;
|
||||
@ -449,8 +448,7 @@ namespace spades {
|
||||
std::min((std::min(endY, inRect.GetMaxY()) - std::max(startY, inRect.GetMinY())) /
|
||||
(endY - startY) * 2.f,
|
||||
1.f);
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1) *
|
||||
(fade * .8f * alpha));
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1) * (fade * .8f * alpha));
|
||||
|
||||
float center = std::max(startY, inRect.GetMinY());
|
||||
center = .5f * (center + std::min(endY, inRect.GetMaxY()));
|
||||
@ -461,19 +459,19 @@ namespace spades {
|
||||
|
||||
int fntX = (i & 3) * 8;
|
||||
int fntY = (i >> 2) * 8 + 16;
|
||||
renderer->DrawImage(mapFont, MakeVector2(outRect.GetMinX() + 4, wy - 4.f),
|
||||
AABB2(fntX, fntY, 8, 8));
|
||||
renderer.DrawImage(mapFont, MakeVector2(outRect.GetMinX() + 4, wy - 4.f),
|
||||
AABB2(fntX, fntY, 8, 8));
|
||||
}
|
||||
// draw objects
|
||||
|
||||
const int iconMode = cg_minimapPlayerIcon;
|
||||
const int colorMode = cg_minimapPlayerColor;
|
||||
|
||||
Handle<IImage> playerSMG = renderer->RegisterImage("Gfx/Map/SMG.png");
|
||||
Handle<IImage> playerRifle = renderer->RegisterImage("Gfx/Map/Rifle.png");
|
||||
Handle<IImage> playerShotgun = renderer->RegisterImage("Gfx/Map/Shotgun.png");
|
||||
Handle<IImage> playerIcon = renderer->RegisterImage("Gfx/Map/Player.png");
|
||||
Handle<IImage> viewIcon = renderer->RegisterImage("Gfx/Map/View.png");
|
||||
Handle<IImage> playerSMG = renderer.RegisterImage("Gfx/Map/SMG.png");
|
||||
Handle<IImage> playerRifle = renderer.RegisterImage("Gfx/Map/Rifle.png");
|
||||
Handle<IImage> playerShotgun = renderer.RegisterImage("Gfx/Map/Shotgun.png");
|
||||
Handle<IImage> playerIcon = renderer.RegisterImage("Gfx/Map/Player.png");
|
||||
Handle<IImage> viewIcon = renderer.RegisterImage("Gfx/Map/View.png");
|
||||
|
||||
// draw player's icon
|
||||
for (int i = 0; i < world->GetNumPlayerSlots(); i++) {
|
||||
@ -518,34 +516,34 @@ namespace spades {
|
||||
|
||||
// Draw the focused player's view
|
||||
if (&p == &focusPlayer) {
|
||||
renderer->SetColorAlphaPremultiplied(iconColorF * 0.9f);
|
||||
renderer.SetColorAlphaPremultiplied(iconColorF * 0.9f);
|
||||
DrawIcon(p.IsSpectator() ? client->freeCameraState.position : p.GetPosition(),
|
||||
viewIcon, ang);
|
||||
*viewIcon, ang);
|
||||
}
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(iconColorF);
|
||||
renderer.SetColorAlphaPremultiplied(iconColorF);
|
||||
// use a different icon in minimap according to weapon of player
|
||||
if (iconMode) {
|
||||
WeaponType weapon = world->GetPlayer(i)->GetWeaponType();
|
||||
if (weapon == WeaponType::SMG_WEAPON) {
|
||||
DrawIcon(p.IsSpectator() ? client->freeCameraState.position
|
||||
: p.GetPosition(),
|
||||
playerSMG, ang);
|
||||
*playerSMG, ang);
|
||||
}
|
||||
|
||||
else if (weapon == WeaponType::RIFLE_WEAPON) {
|
||||
DrawIcon(p.IsSpectator() ? client->freeCameraState.position
|
||||
: p.GetPosition(),
|
||||
playerRifle, ang);
|
||||
*playerRifle, ang);
|
||||
}
|
||||
|
||||
else if (weapon == WeaponType::SHOTGUN_WEAPON) {
|
||||
DrawIcon(p.IsSpectator() ? client->freeCameraState.position
|
||||
: p.GetPosition(),
|
||||
playerShotgun, ang);
|
||||
*playerShotgun, ang);
|
||||
}
|
||||
} else { // draw normal color
|
||||
DrawIcon(&p == &focusPlayer ? focusPlayerPos : p.GetPosition(), playerIcon,
|
||||
DrawIcon(&p == &focusPlayer ? focusPlayerPos : p.GetPosition(), *playerIcon,
|
||||
ang);
|
||||
}
|
||||
}
|
||||
@ -553,8 +551,8 @@ namespace spades {
|
||||
stmp::optional<IGameMode &> mode = world->GetMode();
|
||||
if (mode && IGameMode::m_CTF == mode->ModeType()) {
|
||||
CTFGameMode &ctf = dynamic_cast<CTFGameMode &>(*mode);
|
||||
Handle<IImage> intelIcon = renderer->RegisterImage("Gfx/Map/Intel.png");
|
||||
Handle<IImage> baseIcon = renderer->RegisterImage("Gfx/Map/CommandPost.png");
|
||||
Handle<IImage> intelIcon = renderer.RegisterImage("Gfx/Map/Intel.png");
|
||||
Handle<IImage> baseIcon = renderer.RegisterImage("Gfx/Map/CommandPost.png");
|
||||
for (int tId = 0; tId < 2; tId++) {
|
||||
CTFGameMode::Team &team = ctf.GetTeam(tId);
|
||||
IntVector3 teamColor = world->GetTeam(tId).color;
|
||||
@ -562,13 +560,13 @@ namespace spades {
|
||||
teamColorF *= alpha;
|
||||
|
||||
// draw base
|
||||
renderer->SetColorAlphaPremultiplied(teamColorF);
|
||||
DrawIcon(team.basePos, baseIcon, 0.f);
|
||||
renderer.SetColorAlphaPremultiplied(teamColorF);
|
||||
DrawIcon(team.basePos, *baseIcon, 0.f);
|
||||
|
||||
// draw flag
|
||||
if (!ctf.GetTeam(1 - tId).hasIntel) {
|
||||
renderer->SetColorAlphaPremultiplied(teamColorF);
|
||||
DrawIcon(team.flagPos, intelIcon, 0.f);
|
||||
renderer.SetColorAlphaPremultiplied(teamColorF);
|
||||
DrawIcon(team.flagPos, *intelIcon, 0.f);
|
||||
} else if (world->GetLocalPlayer()->GetTeamId() == 1 - tId) {
|
||||
// local player's team is carrying
|
||||
int cId = ctf.GetTeam(1 - tId).carrier;
|
||||
@ -581,15 +579,15 @@ namespace spades {
|
||||
|
||||
Vector4 col = teamColorF;
|
||||
col *= fabsf(sinf(world->GetTime() * 4.f));
|
||||
renderer->SetColorAlphaPremultiplied(col);
|
||||
DrawIcon(carrier->GetPosition(), intelIcon, 0.f);
|
||||
renderer.SetColorAlphaPremultiplied(col);
|
||||
DrawIcon(carrier->GetPosition(), *intelIcon, 0.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (mode && IGameMode::m_TC == mode->ModeType()) {
|
||||
TCGameMode &tc = dynamic_cast<TCGameMode &>(*mode);
|
||||
Handle<IImage> icon = renderer->RegisterImage("Gfx/Map/CommandPost.png");
|
||||
Handle<IImage> icon = renderer.RegisterImage("Gfx/Map/CommandPost.png");
|
||||
int cnt = tc.GetNumTerritories();
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
TCGameMode::Territory &t = tc.GetTerritory(i);
|
||||
@ -601,13 +599,13 @@ namespace spades {
|
||||
teamColorF *= alpha;
|
||||
|
||||
// draw base
|
||||
renderer->SetColorAlphaPremultiplied(teamColorF);
|
||||
DrawIcon(t.pos, icon, 0.f);
|
||||
renderer.SetColorAlphaPremultiplied(teamColorF);
|
||||
DrawIcon(t.pos, *icon, 0.f);
|
||||
}
|
||||
}
|
||||
|
||||
// draw tracers
|
||||
Handle<IImage> tracerImage = renderer->RegisterImage("Gfx/Ball.png");
|
||||
Handle<IImage> tracerImage = renderer.RegisterImage("Gfx/Ball.png");
|
||||
const float tracerWidth = 2.0f;
|
||||
const AABB2 tracerInRect{0.0f, 0.0f, tracerImage->GetWidth(), tracerImage->GetHeight()};
|
||||
|
||||
@ -646,9 +644,9 @@ namespace spades {
|
||||
line3.first + normal * tracerWidth,
|
||||
line3.second - normal * tracerWidth};
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(Vector4{1.0f, 0.8f, 0.6f, 1.0f} * alpha);
|
||||
renderer->DrawImage(tracerImage, vertices[0], vertices[1], vertices[2],
|
||||
tracerInRect);
|
||||
renderer.SetColorAlphaPremultiplied(Vector4{1.0f, 0.8f, 0.6f, 1.0f} * alpha);
|
||||
renderer.DrawImage(tracerImage, vertices[0], vertices[1], vertices[2],
|
||||
tracerInRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace spades {
|
||||
class IImage;
|
||||
class MapView {
|
||||
Client *client;
|
||||
IRenderer *renderer;
|
||||
IRenderer &renderer;
|
||||
|
||||
int scaleMode;
|
||||
float actualScale;
|
||||
@ -50,7 +50,7 @@ namespace spades {
|
||||
|
||||
Vector2 Project(const Vector2 &) const;
|
||||
|
||||
void DrawIcon(Vector3 pos, IImage *img, float rotation);
|
||||
void DrawIcon(Vector3 pos, IImage &img, float rotation);
|
||||
|
||||
public:
|
||||
MapView(Client *, bool largeMap);
|
||||
|
@ -151,12 +151,12 @@ namespace spades {
|
||||
void PaletteView::Update() {}
|
||||
|
||||
void PaletteView::Draw() {
|
||||
Handle<IImage> img = renderer->RegisterImage("Gfx/Palette.png");
|
||||
Handle<IImage> img = renderer.RegisterImage("Gfx/Palette.png");
|
||||
|
||||
int sel = GetSelectedIndex();
|
||||
|
||||
float scrW = renderer->ScreenWidth();
|
||||
float scrH = renderer->ScreenHeight();
|
||||
float scrW = renderer.ScreenWidth();
|
||||
float scrH = renderer.ScreenHeight();
|
||||
|
||||
for (size_t phase = 0; phase < 2; phase++) {
|
||||
for (size_t i = 0; i < colors.size(); i++) {
|
||||
@ -179,18 +179,18 @@ namespace spades {
|
||||
float x = scrW - 100.f + 10.f * col;
|
||||
float y = scrH - 106.f + 10.f * row - 40.f;
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(cl);
|
||||
renderer.SetColorAlphaPremultiplied(cl);
|
||||
if (selected) {
|
||||
renderer->DrawImage(img, MakeVector2(x, y), AABB2(0, 16, 16, 16));
|
||||
renderer.DrawImage(img, MakeVector2(x, y), AABB2(0, 16, 16, 16));
|
||||
} else {
|
||||
renderer->DrawImage(img, MakeVector2(x, y), AABB2(0, 0, 16, 16));
|
||||
renderer.DrawImage(img, MakeVector2(x, y), AABB2(0, 0, 16, 16));
|
||||
}
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1));
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1));
|
||||
if (selected) {
|
||||
renderer->DrawImage(img, MakeVector2(x, y), AABB2(16, 16, 16, 16));
|
||||
renderer.DrawImage(img, MakeVector2(x, y), AABB2(16, 16, 16, 16));
|
||||
} else {
|
||||
renderer->DrawImage(img, MakeVector2(x, y), AABB2(16, 0, 16, 16));
|
||||
renderer.DrawImage(img, MakeVector2(x, y), AABB2(16, 0, 16, 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace spades {
|
||||
class IRenderer;
|
||||
class PaletteView {
|
||||
Client *client;
|
||||
IRenderer *renderer;
|
||||
IRenderer &renderer;
|
||||
|
||||
int defaultColor;
|
||||
std::vector<IntVector3> colors;
|
||||
|
@ -26,7 +26,7 @@
|
||||
namespace spades {
|
||||
namespace client {
|
||||
ParticleSpriteEntity::ParticleSpriteEntity(Client *cli, IImage *image, Vector4 color)
|
||||
: image(image), color(color) {
|
||||
: renderer(cli->GetRenderer()), image(image), color(color) {
|
||||
position = MakeVector3(0, 0, 0);
|
||||
velocity = MakeVector3(0, 0, 0);
|
||||
radius = 1.f;
|
||||
@ -46,7 +46,6 @@ namespace spades {
|
||||
if (image != NULL)
|
||||
image->AddRef();
|
||||
|
||||
renderer = cli->GetRenderer();
|
||||
if (cli->GetWorld())
|
||||
map = cli->GetWorld()->GetMap();
|
||||
else
|
||||
@ -155,8 +154,8 @@ namespace spades {
|
||||
if (additive)
|
||||
col.w = 0.f;
|
||||
|
||||
renderer->SetColorAlphaPremultiplied(col);
|
||||
renderer->AddSprite(*image, position, radius, angle);
|
||||
renderer.SetColorAlphaPremultiplied(col);
|
||||
renderer.AddSprite(*image, position, radius, angle);
|
||||
}
|
||||
void ParticleSpriteEntity::SetImage(IImage *img) {
|
||||
if (img == image)
|
||||
|
@ -33,7 +33,7 @@ namespace spades {
|
||||
enum BlockHitAction { Delete, Ignore, BounceWeak };
|
||||
|
||||
private:
|
||||
IRenderer *renderer;
|
||||
IRenderer &renderer;
|
||||
Handle<GameMap> map;
|
||||
|
||||
IImage *image;
|
||||
@ -77,7 +77,7 @@ namespace spades {
|
||||
void SetImage(IImage *img);
|
||||
void SetColor(Vector4 col) { color = col; }
|
||||
|
||||
IRenderer *GetRenderer() { return renderer; }
|
||||
IRenderer &GetRenderer() { return renderer; }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,13 +138,13 @@ namespace spades {
|
||||
: NULL;
|
||||
|
||||
Handle<IImage> image;
|
||||
IFont *font;
|
||||
IFont &font = client->fontManager->GetSquareDesignFont();
|
||||
Vector2 pos, size;
|
||||
std::string str;
|
||||
float scrWidth = renderer->ScreenWidth();
|
||||
// float scrHeight = renderer->ScreenHeight();
|
||||
float scrWidth = renderer.ScreenWidth();
|
||||
// float scrHeight = renderer.ScreenHeight();
|
||||
const Vector4 whiteColor = {1, 1, 1, 1};
|
||||
Handle<IImage> whiteImage = renderer->RegisterImage("Gfx/White.tga");
|
||||
Handle<IImage> whiteImage = renderer.RegisterImage("Gfx/White.tga");
|
||||
|
||||
float teamBarTop = 120.f;
|
||||
float teamBarHeight = 60.f;
|
||||
@ -156,42 +156,41 @@ namespace spades {
|
||||
float playersBottom = playersTop + playersHeight;
|
||||
|
||||
// draw shadow
|
||||
image = renderer->RegisterImage("Gfx/Scoreboard/TopShadow.tga");
|
||||
image = renderer.RegisterImage("Gfx/Scoreboard/TopShadow.tga");
|
||||
size.y = 32.f;
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, 0.2f));
|
||||
renderer->DrawImage(image, AABB2(0, teamBarTop - size.y, scrWidth, size.y));
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, 0.2f));
|
||||
renderer->DrawImage(image, AABB2(0, playersBottom + size.y, scrWidth, -size.y));
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, 0.2f));
|
||||
renderer.DrawImage(image, AABB2(0, teamBarTop - size.y, scrWidth, size.y));
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, 0.2f));
|
||||
renderer.DrawImage(image, AABB2(0, playersBottom + size.y, scrWidth, -size.y));
|
||||
|
||||
// draw team bar
|
||||
image = whiteImage;
|
||||
renderer->SetColorAlphaPremultiplied(AdjustColor(GetTeamColor(0), 0.8f, 0.3f));
|
||||
renderer->DrawImage(image, AABB2(0, teamBarTop, scrWidth * .5f, teamBarHeight));
|
||||
renderer->SetColorAlphaPremultiplied(AdjustColor(GetTeamColor(1), 0.8f, 0.3f));
|
||||
renderer->DrawImage(image,
|
||||
AABB2(scrWidth * .5f, teamBarTop, scrWidth * .5f, teamBarHeight));
|
||||
renderer.SetColorAlphaPremultiplied(AdjustColor(GetTeamColor(0), 0.8f, 0.3f));
|
||||
renderer.DrawImage(image, AABB2(0, teamBarTop, scrWidth * .5f, teamBarHeight));
|
||||
renderer.SetColorAlphaPremultiplied(AdjustColor(GetTeamColor(1), 0.8f, 0.3f));
|
||||
renderer.DrawImage(image,
|
||||
AABB2(scrWidth * .5f, teamBarTop, scrWidth * .5f, teamBarHeight));
|
||||
|
||||
image = renderer->RegisterImage("Gfx/Scoreboard/Grunt.png");
|
||||
image = renderer.RegisterImage("Gfx/Scoreboard/Grunt.png");
|
||||
size.x = 120.f;
|
||||
size.y = 60.f;
|
||||
renderer->DrawImage(
|
||||
renderer.DrawImage(
|
||||
image, AABB2(contentsLeft, teamBarTop + teamBarHeight - size.y, size.x, size.y));
|
||||
renderer->DrawImage(
|
||||
renderer.DrawImage(
|
||||
image, AABB2(contentsRight, teamBarTop + teamBarHeight - size.y, -size.x, size.y));
|
||||
|
||||
font = client->fontManager->GetSquareDesignFont();
|
||||
str = world->GetTeam(0).name;
|
||||
pos.x = contentsLeft + 110.f;
|
||||
pos.y = teamBarTop + 5.f;
|
||||
font->Draw(str, pos + MakeVector2(0, 2), 1.f, MakeVector4(0, 0, 0, 0.5));
|
||||
font->Draw(str, pos, 1.f, whiteColor);
|
||||
font.Draw(str, pos + MakeVector2(0, 2), 1.f, MakeVector4(0, 0, 0, 0.5));
|
||||
font.Draw(str, pos, 1.f, whiteColor);
|
||||
|
||||
str = world->GetTeam(1).name;
|
||||
size = font->Measure(str);
|
||||
size = font.Measure(str);
|
||||
pos.x = contentsRight - 110.f - size.x;
|
||||
pos.y = teamBarTop + 5.f;
|
||||
font->Draw(str, pos + MakeVector2(0, 2), 1.f, MakeVector4(0, 0, 0, 0.5));
|
||||
font->Draw(str, pos, 1.f, whiteColor);
|
||||
font.Draw(str, pos + MakeVector2(0, 2), 1.f, MakeVector4(0, 0, 0, 0.5));
|
||||
font.Draw(str, pos, 1.f, whiteColor);
|
||||
|
||||
// draw scores
|
||||
int capLimit;
|
||||
@ -204,23 +203,23 @@ namespace spades {
|
||||
}
|
||||
if (capLimit != -1) {
|
||||
str = Format("{0}-{1}", GetTeamScore(0), capLimit);
|
||||
pos.x = scrWidth * .5f - font->Measure(str).x - 15.f;
|
||||
pos.x = scrWidth * .5f - font.Measure(str).x - 15.f;
|
||||
pos.y = teamBarTop + 5.f;
|
||||
font->Draw(str, pos, 1.f, Vector4(1.f, 1.f, 1.f, 0.5f));
|
||||
font.Draw(str, pos, 1.f, Vector4(1.f, 1.f, 1.f, 0.5f));
|
||||
|
||||
str = Format("{0}-{1}", GetTeamScore(1), capLimit);
|
||||
pos.x = scrWidth * .5f + 15.f;
|
||||
pos.y = teamBarTop + 5.f;
|
||||
font->Draw(str, pos, 1.f, Vector4(1.f, 1.f, 1.f, 0.5f));
|
||||
font.Draw(str, pos, 1.f, Vector4(1.f, 1.f, 1.f, 0.5f));
|
||||
}
|
||||
|
||||
// players background
|
||||
auto areSpectatorsPr = areSpectatorsPresent();
|
||||
image = renderer->RegisterImage("Gfx/Scoreboard/PlayersBg.png");
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, 1.f));
|
||||
renderer->DrawImage(image,
|
||||
AABB2(0, playersTop, scrWidth,
|
||||
playersHeight + (areSpectatorsPr ? spectatorsHeight : 0)));
|
||||
image = renderer.RegisterImage("Gfx/Scoreboard/PlayersBg.png");
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(0, 0, 0, 1.f));
|
||||
renderer.DrawImage(image,
|
||||
AABB2(0, playersTop, scrWidth,
|
||||
playersHeight + (areSpectatorsPr ? spectatorsHeight : 0)));
|
||||
|
||||
// draw players
|
||||
DrawPlayers(0, contentsLeft, playersTop, (contentsRight - contentsLeft) * .5f,
|
||||
@ -241,7 +240,7 @@ namespace spades {
|
||||
|
||||
void ScoreboardView::DrawPlayers(int team, float left, float top, float width,
|
||||
float height) {
|
||||
IFont *font = client->fontManager->GetGuiFont();
|
||||
IFont &font = client->fontManager->GetGuiFont();
|
||||
float rowHeight = 24.f;
|
||||
char buf[256];
|
||||
Vector2 size;
|
||||
@ -289,29 +288,29 @@ namespace spades {
|
||||
Vector4 color = white;
|
||||
|
||||
sprintf(buf, "#%d", ent.id); // FIXME: 1-base?
|
||||
size = font->Measure(buf);
|
||||
size = font.Measure(buf);
|
||||
|
||||
if (colormode == "1") {
|
||||
IntVector3 Colorplayer =
|
||||
IntVector3::Make(palette[ent.id][0], palette[ent.id][1], palette[ent.id][2]);
|
||||
Vector4 ColorplayerF = ModifyColor(Colorplayer);
|
||||
ColorplayerF *= 1.0f;
|
||||
font->Draw(buf, MakeVector2(colX + 35.f - size.x, rowY), 1.f, ColorplayerF);
|
||||
font.Draw(buf, MakeVector2(colX + 35.f - size.x, rowY), 1.f, ColorplayerF);
|
||||
} else {
|
||||
font->Draw(buf, MakeVector2(colX + 35.f - size.x, rowY), 1.f, white);
|
||||
font.Draw(buf, MakeVector2(colX + 35.f - size.x, rowY), 1.f, white);
|
||||
}
|
||||
|
||||
color = ent.alive ? white : gray;
|
||||
if (stmp::make_optional(ent.id) == world->GetLocalPlayerIndex())
|
||||
color = GetTeamColor(team);
|
||||
|
||||
font->Draw(ent.name, MakeVector2(colX + 45.f, rowY), 1.f, color);
|
||||
font.Draw(ent.name, MakeVector2(colX + 45.f, rowY), 1.f, color);
|
||||
|
||||
color = white;
|
||||
|
||||
sprintf(buf, "%d", ent.score);
|
||||
size = font->Measure(buf);
|
||||
font->Draw(buf, MakeVector2(colX + colWidth - 10.f - size.x, rowY), 1.f, color);
|
||||
size = font.Measure(buf);
|
||||
font.Draw(buf, MakeVector2(colX + colWidth - 10.f - size.x, rowY), 1.f, color);
|
||||
|
||||
row++;
|
||||
if (row >= maxRows) {
|
||||
@ -322,7 +321,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
void ScoreboardView::DrawSpectators(float top, float centerX) const {
|
||||
IFont *font = client->fontManager->GetGuiFont();
|
||||
IFont &font = client->fontManager->GetGuiFont();
|
||||
char buf[256];
|
||||
std::vector<ScoreboardEntry> entries;
|
||||
|
||||
@ -349,7 +348,7 @@ namespace spades {
|
||||
// Measure total width in pixels so that we can center align all the spectators
|
||||
sprintf(buf, "#%d", ent.id);
|
||||
totalPixelWidth +=
|
||||
font->Measure(buf).x + font->Measure(ent.name).x + xPixelSpectatorOffset;
|
||||
font.Measure(buf).x + font.Measure(ent.name).x + xPixelSpectatorOffset;
|
||||
}
|
||||
if (numSpectators == 0) {
|
||||
return;
|
||||
@ -358,7 +357,7 @@ namespace spades {
|
||||
strcpy(buf,
|
||||
_TrN("Client", "Spectator{1}", "Spectators{1}", numSpectators, ":").c_str());
|
||||
|
||||
auto isSquareFont = spectatorFont == client->fontManager->GetSquareDesignFont();
|
||||
auto isSquareFont = spectatorFont == &client->fontManager->GetSquareDesignFont();
|
||||
auto sizeSpecString = spectatorFont->Measure(buf);
|
||||
spectatorFont->Draw(
|
||||
buf, MakeVector2(centerX - sizeSpecString.x / 2, top + (isSquareFont ? 0 : 10)), 1.f,
|
||||
@ -372,12 +371,12 @@ namespace spades {
|
||||
ScoreboardEntry &ent = entries[i];
|
||||
|
||||
sprintf(buf, "#%d", ent.id);
|
||||
font->Draw(buf, MakeVector2(currentXoffset, yOffset), 1.f, spectatorIdColor);
|
||||
font.Draw(buf, MakeVector2(currentXoffset, yOffset), 1.f, spectatorIdColor);
|
||||
|
||||
auto sizeName = font->Measure(ent.name);
|
||||
auto sizeID = font->Measure(buf);
|
||||
font->Draw(ent.name, MakeVector2(currentXoffset + sizeID.x + 5.f, yOffset), 1.f,
|
||||
white);
|
||||
auto sizeName = font.Measure(ent.name);
|
||||
auto sizeID = font.Measure(buf);
|
||||
font.Draw(ent.name, MakeVector2(currentXoffset + sizeID.x + 5.f, yOffset), 1.f,
|
||||
white);
|
||||
|
||||
currentXoffset += sizeID.x + sizeName.x + xPixelSpectatorOffset;
|
||||
}
|
||||
|
@ -33,29 +33,26 @@ namespace spades {
|
||||
class IFont;
|
||||
class ScoreboardView {
|
||||
Client *client;
|
||||
IRenderer *renderer;
|
||||
IRenderer &renderer;
|
||||
IImage *image;
|
||||
|
||||
World *world;
|
||||
CTFGameMode *ctf;
|
||||
TCGameMode *tc;
|
||||
IFont *spectatorFont;
|
||||
Handle<IFont> spectatorFont;
|
||||
|
||||
int GetTeamScore(int) const;
|
||||
Vector4 GetTeamColor(int);
|
||||
Vector4 AdjustColor(Vector4 col,
|
||||
float bright,
|
||||
float saturation) const;
|
||||
void DrawPlayers(int team,
|
||||
float left, float top,
|
||||
float width, float height);
|
||||
Vector4 AdjustColor(Vector4 col, float bright, float saturation) const;
|
||||
void DrawPlayers(int team, float left, float top, float width, float height);
|
||||
void DrawSpectators(float top, float width) const;
|
||||
bool areSpectatorsPresent() const;
|
||||
|
||||
public:
|
||||
ScoreboardView(Client *);
|
||||
~ScoreboardView();
|
||||
|
||||
void Draw();
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace client
|
||||
} // namespace spades
|
||||
|
@ -28,11 +28,12 @@
|
||||
namespace spades {
|
||||
namespace client {
|
||||
static IRenderer *lastRenderer = NULL;
|
||||
static IImage *lastSeq[180];
|
||||
static IImage *lastSeq2[48];
|
||||
static Handle<IImage> lastSeq[180];
|
||||
static Handle<IImage> lastSeq2[48];
|
||||
|
||||
// FIXME: add "image manager"?
|
||||
static void Load(IRenderer *r) {
|
||||
// FIXME: Pointers are not unique identifiers since the same value could be reused
|
||||
if (r == lastRenderer)
|
||||
return;
|
||||
|
||||
@ -50,19 +51,19 @@ namespace spades {
|
||||
lastRenderer = r;
|
||||
}
|
||||
|
||||
IImage *SmokeSpriteEntity::GetSequence(int i, IRenderer *r, Type type) {
|
||||
IImage &SmokeSpriteEntity::GetSequence(int i, IRenderer *r, Type type) {
|
||||
Load(r);
|
||||
if (type == Type::Steady) {
|
||||
SPAssert(i >= 0 && i < 180);
|
||||
return lastSeq[i];
|
||||
return *lastSeq[i];
|
||||
} else {
|
||||
SPAssert(i >= 0 && i < 48);
|
||||
return lastSeq2[i];
|
||||
return *lastSeq2[i];
|
||||
}
|
||||
}
|
||||
|
||||
SmokeSpriteEntity::SmokeSpriteEntity(Client *c, Vector4 color, float fps, Type type)
|
||||
: ParticleSpriteEntity(c, GetSequence(0, c->GetRenderer(), type), color),
|
||||
: ParticleSpriteEntity(c, &GetSequence(0, &c->GetRenderer(), type), color),
|
||||
fps(fps),
|
||||
type(type) {
|
||||
frame = 0.f;
|
||||
@ -82,7 +83,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
int fId = (int)floorf(frame);
|
||||
SetImage(GetSequence(fId, GetRenderer(), type));
|
||||
SetImage(&GetSequence(fId, &GetRenderer(), type));
|
||||
|
||||
return ParticleSpriteEntity::Update(dt);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace spades {
|
||||
float frame;
|
||||
float fps;
|
||||
Type type;
|
||||
static IImage *GetSequence(int i, IRenderer *r, Type);
|
||||
static IImage &GetSequence(int i, IRenderer *r, Type);
|
||||
|
||||
public:
|
||||
SmokeSpriteEntity(Client *cli, Vector4 color, float fps, Type type = Type::Steady);
|
||||
@ -44,4 +44,4 @@ namespace spades {
|
||||
bool Update(float dt) override;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,11 +72,11 @@ namespace spades {
|
||||
}
|
||||
TCGameMode &tc = dynamic_cast<TCGameMode &>(mode.value());
|
||||
|
||||
float scrW = renderer->ScreenWidth();
|
||||
float scrH = renderer->ScreenHeight();
|
||||
float scrW = renderer.ScreenWidth();
|
||||
float scrH = renderer.ScreenHeight();
|
||||
|
||||
Handle<IImage> prgBg = renderer->RegisterImage("Gfx/TC/ProgressBg.png");
|
||||
Handle<IImage> prgBar = renderer->RegisterImage("Gfx/TC/ProgressBar.png");
|
||||
Handle<IImage> prgBg = renderer.RegisterImage("Gfx/TC/ProgressBg.png");
|
||||
Handle<IImage> prgBar = renderer.RegisterImage("Gfx/TC/ProgressBar.png");
|
||||
|
||||
stmp::optional<Player &> maybePlayer = w->GetLocalPlayer();
|
||||
if (maybePlayer && maybePlayer.value().GetTeamId() < 2 &&
|
||||
@ -119,35 +119,35 @@ namespace spades {
|
||||
float y = scrH * 0.7f;
|
||||
|
||||
if (nearTerritory->ownerTeamId == 2) {
|
||||
renderer->SetColorAlphaPremultiplied(MakeVector4(fade, fade, fade, fade));
|
||||
renderer.SetColorAlphaPremultiplied(MakeVector4(fade, fade, fade, fade));
|
||||
} else {
|
||||
IntVector3 c = w->GetTeam(nearTerritory->ownerTeamId).color;
|
||||
renderer->SetColorAlphaPremultiplied(
|
||||
renderer.SetColorAlphaPremultiplied(
|
||||
MakeVector4(c.x / 255.f, c.y / 255.f, c.z / 255.f, 1) * fade);
|
||||
}
|
||||
renderer->DrawImage(prgBg, MakeVector2(x, y));
|
||||
renderer.DrawImage(prgBg, MakeVector2(x, y));
|
||||
|
||||
// get away from border
|
||||
state.progress += (.5f - state.progress) * 12.f / 256.f;
|
||||
|
||||
if (state.team1 != 2) {
|
||||
IntVector3 c = w->GetTeam(state.team1).color;
|
||||
renderer->SetColorAlphaPremultiplied(
|
||||
renderer.SetColorAlphaPremultiplied(
|
||||
MakeVector4(c.x / 255.f, c.y / 255.f, c.z / 255.f, 1) * (fade * 0.8f));
|
||||
renderer->DrawImage(prgBar, MakeVector2(x, y),
|
||||
AABB2(0, 0, (1.f - state.progress) * 256.f, 32));
|
||||
renderer.DrawImage(prgBar, MakeVector2(x, y),
|
||||
AABB2(0, 0, (1.f - state.progress) * 256.f, 32));
|
||||
}
|
||||
|
||||
if (state.team2 != 2) {
|
||||
IntVector3 c = w->GetTeam(state.team2).color;
|
||||
renderer->SetColorAlphaPremultiplied(
|
||||
renderer.SetColorAlphaPremultiplied(
|
||||
MakeVector4(c.x / 255.f, c.y / 255.f, c.z / 255.f, 1) * (fade * 0.8f));
|
||||
renderer->DrawImage(
|
||||
renderer.DrawImage(
|
||||
prgBar, MakeVector2(x + (1.f - state.progress) * 256.f, y),
|
||||
AABB2((1.f - state.progress) * 256.f, 0, state.progress * 256.f, 32));
|
||||
}
|
||||
|
||||
IFont *font = client->fontManager->GetGuiFont();
|
||||
IFont &font = client->fontManager->GetGuiFont();
|
||||
std::string str;
|
||||
|
||||
if (nearTerritory->ownerTeamId == 2) {
|
||||
@ -157,11 +157,11 @@ namespace spades {
|
||||
str = _Tr("Client", "{0}'s Territory", str);
|
||||
}
|
||||
|
||||
Vector2 size = font->Measure(str);
|
||||
Vector2 size = font.Measure(str);
|
||||
x = (scrW - size.x) * .5f;
|
||||
y += 35.f;
|
||||
|
||||
font->DrawShadow(str, MakeVector2(x, y), 1.f, MakeVector4(1.f, 1.f, 1.f, fade),
|
||||
font.DrawShadow(str, MakeVector2(x, y), 1.f, MakeVector4(1.f, 1.f, 1.f, fade),
|
||||
MakeVector4(0, 0, 0, 0.5f * fade));
|
||||
}
|
||||
} else {
|
||||
|
@ -26,7 +26,7 @@ namespace spades {
|
||||
class IRenderer;
|
||||
class TCProgressView {
|
||||
Client *client;
|
||||
IRenderer *renderer;
|
||||
IRenderer &renderer;
|
||||
|
||||
int lastTerritoryId;
|
||||
float lastTerritoryTime;
|
||||
@ -38,4 +38,4 @@ namespace spades {
|
||||
void Draw();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace spades {
|
||||
|
||||
firstUpdate = true;
|
||||
|
||||
image = cli->GetRenderer()->RegisterImage("Gfx/Ball.png");
|
||||
image = cli->GetRenderer().RegisterImage("Gfx/Ball.png");
|
||||
}
|
||||
|
||||
bool Tracer::Update(float dt) {
|
||||
@ -44,8 +44,8 @@ namespace spades {
|
||||
}
|
||||
|
||||
void Tracer::Render3D() {
|
||||
IRenderer *r = client->GetRenderer();
|
||||
if (dynamic_cast<draw::SWRenderer *>(r)) {
|
||||
IRenderer &r = client->GetRenderer();
|
||||
if (dynamic_cast<draw::SWRenderer *>(&r)) {
|
||||
// SWRenderer doesn't support long sprites (yet)
|
||||
float startDist = curDistance;
|
||||
float endDist = curDistance + visibleLength;
|
||||
@ -59,7 +59,7 @@ namespace spades {
|
||||
Vector3 pos1 = startPos + dir * startDist;
|
||||
Vector3 pos2 = startPos + dir * endDist;
|
||||
Vector4 col = {1.f, .6f, .2f, 0.f};
|
||||
r->AddDebugLine(pos1, pos2, Vector4{1.0f, 0.6f, 0.2f, 1.0f});
|
||||
r.AddDebugLine(pos1, pos2, Vector4{1.0f, 0.6f, 0.2f, 1.0f});
|
||||
} else {
|
||||
for (float step = 0.0f; step <= 1.0f; step += 0.1f) {
|
||||
float startDist = curDistance;
|
||||
@ -78,8 +78,8 @@ namespace spades {
|
||||
Vector3 pos1 = startPos + dir * startDist;
|
||||
Vector3 pos2 = startPos + dir * endDist;
|
||||
Vector4 col = {1.f, .6f, .2f, 0.f};
|
||||
r->SetColorAlphaPremultiplied(col * 0.4f);
|
||||
r->AddLongSprite(*image, pos1, pos2, .05f);
|
||||
r.SetColorAlphaPremultiplied(col * 0.4f);
|
||||
r.AddLongSprite(*image, pos1, pos2, .05f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,10 +115,12 @@ namespace spades {
|
||||
}
|
||||
|
||||
T *operator->() const {
|
||||
// TODO: Do not skip null check in release builds
|
||||
SPAssert(ptr != NULL);
|
||||
return ptr;
|
||||
}
|
||||
T &operator*() const {
|
||||
// TODO: Do not skip null check in release builds
|
||||
SPAssert(ptr != NULL);
|
||||
return *ptr;
|
||||
}
|
||||
@ -137,14 +139,34 @@ namespace spades {
|
||||
}
|
||||
void operator=(T *p) { Set(p); }
|
||||
void operator=(const Handle<T> &h) { Set(h.ptr, true); }
|
||||
operator T *() const { return ptr; }
|
||||
|
||||
operator stmp::optional<T &>() const { return ptr; }
|
||||
|
||||
/**
|
||||
* Get a nullable raw pointer. After the operation, the original `Handle`
|
||||
* still owns a reference to the referent (if any).
|
||||
*
|
||||
* This conversion have a danger of causing a pointer use-after-free if
|
||||
* used incorrectly. For example, `IImage *image = CreateImage().GetPointer();`
|
||||
* creates a dangling pointer because the temporary value `CreateImage()`
|
||||
* is destroyed right after initializing the variable, invalidating the
|
||||
* pointer returned by `GetPointer()`. This is why this conversion is
|
||||
* no longer supported as implicit casting.
|
||||
*/
|
||||
T *GetPointerOrNull() const { return ptr; }
|
||||
/**
|
||||
* Convert a `Handle` to a raw pointer, transfering the ownership.
|
||||
* Throws an exception if the `Handle` is null.
|
||||
*/
|
||||
T *Unmanage() {
|
||||
SPAssert(ptr != NULL);
|
||||
T *p = ptr;
|
||||
ptr = NULL;
|
||||
return p;
|
||||
}
|
||||
/**
|
||||
* Convert a `Handle` to a raw pointer, transfering the ownership.
|
||||
*/
|
||||
T *MaybeUnmanage() {
|
||||
T *p = ptr;
|
||||
ptr = NULL;
|
||||
|
@ -21,10 +21,10 @@
|
||||
#include <atomic>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <Client/GameMap.h>
|
||||
#include "GLAmbientShadowRenderer.h"
|
||||
#include "GLProfiler.h"
|
||||
#include "GLRenderer.h"
|
||||
#include <Client/GameMap.h>
|
||||
|
||||
#include <Core/ConcurrentDispatch.h>
|
||||
|
||||
@ -34,8 +34,8 @@ namespace spades {
|
||||
GLAmbientShadowRenderer *renderer;
|
||||
|
||||
public:
|
||||
std::atomic<bool> done {false};
|
||||
UpdateDispatch(GLAmbientShadowRenderer *r) : renderer(r) { }
|
||||
std::atomic<bool> done{false};
|
||||
UpdateDispatch(GLAmbientShadowRenderer *r) : renderer(r) {}
|
||||
void Run() override {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
@ -50,7 +50,8 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
for (int i = 0; i < NumRays; i++) {
|
||||
Vector3 dir = MakeVector3(SampleRandomFloat(), SampleRandomFloat(), SampleRandomFloat());
|
||||
Vector3 dir =
|
||||
MakeVector3(SampleRandomFloat(), SampleRandomFloat(), SampleRandomFloat());
|
||||
dir = dir.Normalize();
|
||||
dir += 0.01f;
|
||||
rays[i] = dir;
|
||||
@ -81,21 +82,22 @@ namespace spades {
|
||||
c.cz = z;
|
||||
}
|
||||
|
||||
SPLog("Chunk buffer allocated (%d bytes)", (int) sizeof(Chunk) * chunkW * chunkH * chunkD);
|
||||
SPLog("Chunk buffer allocated (%d bytes)",
|
||||
(int)sizeof(Chunk) * chunkW * chunkH * chunkD);
|
||||
|
||||
// make texture
|
||||
texture = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture3D, texture);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapR,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexImage3D(IGLDevice::Texture3D, 0, IGLDevice::Red, w, h, d + 1, 0,
|
||||
IGLDevice::Red, IGLDevice::FloatType, NULL);
|
||||
texture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture3D, texture);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapR,
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexImage3D(IGLDevice::Texture3D, 0, IGLDevice::Red, w, h, d + 1, 0,
|
||||
IGLDevice::Red, IGLDevice::FloatType, NULL);
|
||||
|
||||
SPLog("Chunk texture allocated");
|
||||
|
||||
@ -103,8 +105,8 @@ namespace spades {
|
||||
v.resize(w * h);
|
||||
std::fill(v.begin(), v.end(), 1.f);
|
||||
for (int i = 0; i < d + 1; i++) {
|
||||
device->TexSubImage3D(IGLDevice::Texture3D, 0, 0, 0, i, w, h, 1, IGLDevice::Red,
|
||||
IGLDevice::FloatType, v.data());
|
||||
device.TexSubImage3D(IGLDevice::Texture3D, 0, 0, 0, i, w, h, 1, IGLDevice::Red,
|
||||
IGLDevice::FloatType, v.data());
|
||||
}
|
||||
|
||||
SPLog("Chunk texture initialized");
|
||||
@ -118,7 +120,7 @@ namespace spades {
|
||||
dispatch->Join();
|
||||
delete dispatch;
|
||||
}
|
||||
device->DeleteTexture(texture);
|
||||
device.DeleteTexture(texture);
|
||||
}
|
||||
|
||||
float GLAmbientShadowRenderer::Evaluate(IntVector3 ipos) {
|
||||
@ -281,16 +283,17 @@ namespace spades {
|
||||
if (!chunks[i].transferDone.load())
|
||||
cnt++;
|
||||
}
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Large Ambient Occlusion [>= %d chunk(s)]", cnt);
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(),
|
||||
"Large Ambient Occlusion [>= %d chunk(s)]", cnt);
|
||||
|
||||
device->BindTexture(IGLDevice::Texture3D, texture);
|
||||
device.BindTexture(IGLDevice::Texture3D, texture);
|
||||
for (size_t i = 0; i < chunks.size(); i++) {
|
||||
Chunk &c = chunks[i];
|
||||
if (!c.transferDone.exchange(true)) {
|
||||
device->TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize + 1, ChunkSize,
|
||||
ChunkSize, ChunkSize, IGLDevice::Red,
|
||||
IGLDevice::FloatType, c.data);
|
||||
device.TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize + 1, ChunkSize,
|
||||
ChunkSize, ChunkSize, IGLDevice::Red, IGLDevice::FloatType,
|
||||
c.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -341,7 +344,7 @@ namespace spades {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (numDirtyChunks <= 0)
|
||||
break;
|
||||
int idx = SampleRandomInt(0, numDirtyChunks - 1);
|
||||
int idx = SampleRandomInt(0, numDirtyChunks - 1);
|
||||
Chunk &c = chunks[dirtyChunkIds[idx]];
|
||||
|
||||
// remove from list (fast)
|
||||
@ -380,5 +383,5 @@ namespace spades {
|
||||
c.dirty = false;
|
||||
c.transferDone = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -39,7 +39,7 @@ namespace spades {
|
||||
class UpdateDispatch;
|
||||
enum { NumRays = 16, ChunkSize = 16, ChunkSizeBits = 4 };
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
client::GameMap *map;
|
||||
Vector3 rays[NumRays];
|
||||
|
||||
|
@ -20,16 +20,16 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include "GLAutoExposureFilter.h"
|
||||
#include "GLProgram.h"
|
||||
#include "GLProgramAttribute.h"
|
||||
#include "GLProgramUniform.h"
|
||||
#include "GLQuadRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include "GLSettings.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -39,43 +39,39 @@ namespace spades {
|
||||
renderer->RegisterProgram("Shaders/PostFilters/AutoExposurePreprocess.program");
|
||||
computeGain = renderer->RegisterProgram("Shaders/PostFilters/AutoExposure.program");
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
|
||||
exposureTexture = dev->GenTexture();
|
||||
exposureTexture = dev.GenTexture();
|
||||
|
||||
dev->BindTexture(IGLDevice::Texture2D, exposureTexture);
|
||||
dev.BindTexture(IGLDevice::Texture2D, exposureTexture);
|
||||
|
||||
dev->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA16F, 1, 1, 0, IGLDevice::RGBA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
dev.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA16F, 1, 1, 0, IGLDevice::RGBA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
SPLog("Brightness Texture Allocated");
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter, IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter, IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::ClampToEdge);
|
||||
|
||||
exposureFramebuffer = dev->GenFramebuffer();
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, exposureFramebuffer);
|
||||
exposureFramebuffer = dev.GenFramebuffer();
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, exposureFramebuffer);
|
||||
|
||||
dev->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, exposureTexture, 0);
|
||||
dev->Viewport(0, 0, 1, 1);
|
||||
dev->ClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
dev->Clear(IGLDevice::ColorBufferBit);
|
||||
dev.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, exposureTexture, 0);
|
||||
dev.Viewport(0, 0, 1, 1);
|
||||
dev.ClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
dev.Clear(IGLDevice::ColorBufferBit);
|
||||
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
SPLog("Brightness Framebuffer Allocated");
|
||||
}
|
||||
|
||||
GLAutoExposureFilter::~GLAutoExposureFilter() {
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
dev->DeleteTexture(exposureTexture);
|
||||
dev->DeleteFramebuffer(exposureFramebuffer);
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
dev.DeleteTexture(exposureTexture);
|
||||
dev.DeleteFramebuffer(exposureFramebuffer);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@ -83,14 +79,14 @@ namespace spades {
|
||||
int w, h;
|
||||
GLColorBuffer buffer;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
GLColorBuffer GLAutoExposureFilter::Filter(GLColorBuffer input, float dt) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
std::vector<Level> levels;
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
GLSettings &settings = renderer->GetSettings();
|
||||
@ -139,8 +135,8 @@ namespace spades {
|
||||
thruTexture.SetValue(0);
|
||||
thruTexCoordRange.SetValue(0.f, 0.f, 1.f, 1.f);
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev->ActiveTexture(0);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
dev.ActiveTexture(0);
|
||||
|
||||
// downsample until it becomes 1x1x
|
||||
GLColorBuffer buffer = input;
|
||||
@ -153,8 +149,8 @@ namespace spades {
|
||||
int newH = (prevH + 1) / 2;
|
||||
GLColorBuffer newLevel = input.GetManager()->CreateBufferHandle(newW, newH);
|
||||
|
||||
dev->BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, newLevel.GetFramebuffer());
|
||||
dev.BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, newLevel.GetFramebuffer());
|
||||
if (firstLevel) {
|
||||
preprocess->Use();
|
||||
qr.SetCoordAttributeIndex(preprocessPosition());
|
||||
@ -163,18 +159,18 @@ namespace spades {
|
||||
thru->Use();
|
||||
qr.SetCoordAttributeIndex(thruPosition());
|
||||
}
|
||||
dev->Viewport(0, 0, newLevel.GetWidth(), newLevel.GetHeight());
|
||||
dev->ClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
dev->Clear(IGLDevice::ColorBufferBit);
|
||||
dev.Viewport(0, 0, newLevel.GetWidth(), newLevel.GetHeight());
|
||||
dev.ClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
dev.Clear(IGLDevice::ColorBufferBit);
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
buffer = newLevel;
|
||||
}
|
||||
|
||||
// compute estimated brightness on GPU
|
||||
dev->Enable(IGLDevice::Blend, true);
|
||||
dev->BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
dev.Enable(IGLDevice::Blend, true);
|
||||
dev.BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
|
||||
float minExposure = settings.r_hdrAutoExposureMin;
|
||||
float maxExposure = settings.r_hdrAutoExposureMax;
|
||||
@ -196,30 +192,30 @@ namespace spades {
|
||||
computeGainMinGain.SetValue(std::pow(2.0f, minExposure));
|
||||
computeGainMaxGain.SetValue(std::pow(2.0f, maxExposure));
|
||||
qr.SetCoordAttributeIndex(computeGainPosition());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, exposureFramebuffer);
|
||||
dev->BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
dev->Viewport(0, 0, 1, 1);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, exposureFramebuffer);
|
||||
dev.BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
dev.Viewport(0, 0, 1, 1);
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
// apply exposure adjustment
|
||||
thru->Use();
|
||||
thruColor.SetValue(1.f, 1.f, 1.f, 1.f);
|
||||
thruTexCoordRange.SetValue(0.f, 0.f, 1.f, 1.f);
|
||||
thruTexture.SetValue(0);
|
||||
dev->Enable(IGLDevice::Blend, true);
|
||||
dev->BlendFunc(IGLDevice::DestColor, IGLDevice::Zero); // multiply
|
||||
dev.Enable(IGLDevice::Blend, true);
|
||||
dev.BlendFunc(IGLDevice::DestColor, IGLDevice::Zero); // multiply
|
||||
qr.SetCoordAttributeIndex(thruPosition());
|
||||
dev->BindTexture(IGLDevice::Texture2D, exposureTexture);
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, input.GetFramebuffer());
|
||||
dev->Viewport(0, 0, input.GetWidth(), input.GetHeight());
|
||||
dev.BindTexture(IGLDevice::Texture2D, exposureTexture);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, input.GetFramebuffer());
|
||||
dev.Viewport(0, 0, input.GetWidth(), input.GetHeight());
|
||||
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
dev->BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
dev.BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -19,64 +19,62 @@
|
||||
*/
|
||||
|
||||
#include "GLBasicShadowMapRenderer.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
#include <Core/Settings.h>
|
||||
#include "GLProfiler.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
#include <Core/Settings.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
|
||||
GLBasicShadowMapRenderer::GLBasicShadowMapRenderer(GLRenderer *r)
|
||||
: IGLShadowMapRenderer(r) {
|
||||
: IGLShadowMapRenderer(r), device(r->GetGLDevice()) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device = r->GetGLDevice();
|
||||
|
||||
textureSize = r->GetSettings().r_shadowMapSize;
|
||||
if ((int)textureSize > 4096) {
|
||||
SPLog("r_shadowMapSize is too large; changed to 4096");
|
||||
r->GetSettings().r_shadowMapSize = textureSize = 4096;
|
||||
}
|
||||
|
||||
colorTexture = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture2D, colorTexture);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGB, textureSize, textureSize, 0,
|
||||
IGLDevice::RGB, IGLDevice::UnsignedByte, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
colorTexture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, colorTexture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGB, textureSize, textureSize, 0,
|
||||
IGLDevice::RGB, IGLDevice::UnsignedByte, NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
for (int i = 0; i < NumSlices; i++) {
|
||||
texture[i] = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture2D, texture[i]);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24,
|
||||
textureSize, textureSize, 0, IGLDevice::DepthComponent,
|
||||
IGLDevice::UnsignedInt, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
texture[i] = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, texture[i]);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24, textureSize,
|
||||
textureSize, 0, IGLDevice::DepthComponent, IGLDevice::UnsignedInt,
|
||||
NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
framebuffer[i] = device->GenFramebuffer();
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, framebuffer[i]);
|
||||
device->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, colorTexture, 0);
|
||||
device->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, texture[i], 0);
|
||||
framebuffer[i] = device.GenFramebuffer();
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, framebuffer[i]);
|
||||
device.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, colorTexture, 0);
|
||||
device.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, texture[i], 0);
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,10 +82,10 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
for (int i = 0; i < NumSlices; i++) {
|
||||
device->DeleteTexture(texture[i]);
|
||||
device->DeleteFramebuffer(framebuffer[i]);
|
||||
device.DeleteTexture(texture[i]);
|
||||
device.DeleteFramebuffer(framebuffer[i]);
|
||||
}
|
||||
device->DeleteTexture(colorTexture);
|
||||
device.DeleteTexture(colorTexture);
|
||||
}
|
||||
|
||||
#define Segment GLBSMRSegment
|
||||
@ -224,7 +222,7 @@ namespace spades {
|
||||
void GLBasicShadowMapRenderer::Render() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice::Integer lastFb = device->GetInteger(IGLDevice::FramebufferBinding);
|
||||
IGLDevice::Integer lastFb = device.GetInteger(IGLDevice::FramebufferBinding);
|
||||
|
||||
// client::SceneDefinition def = GetRenderer()->GetSceneDef();
|
||||
|
||||
@ -232,7 +230,8 @@ namespace spades {
|
||||
|
||||
for (int i = 0; i < NumSlices; i++) {
|
||||
|
||||
GLProfiler::Context profiler(GetRenderer()->GetGLProfiler(), "Slice %d / %d", i + 1, (int)NumSlices);
|
||||
GLProfiler::Context profiler(GetRenderer()->GetGLProfiler(), "Slice %d / %d", i + 1,
|
||||
(int)NumSlices);
|
||||
|
||||
float farDist = 0.0;
|
||||
// TODO: variable far distance according to the scene definition
|
||||
@ -258,19 +257,19 @@ namespace spades {
|
||||
matrix = matrix * Matrix4::Translate(-def.viewOrigin);
|
||||
matrix = Matrix4::Scale(1,1,16.f / 70.f) * matrix;*/
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, framebuffer[i]);
|
||||
device->Viewport(0, 0, textureSize, textureSize);
|
||||
device->ClearDepth(1.f);
|
||||
device->Clear(IGLDevice::DepthBufferBit);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, framebuffer[i]);
|
||||
device.Viewport(0, 0, textureSize, textureSize);
|
||||
device.ClearDepth(1.f);
|
||||
device.Clear(IGLDevice::DepthBufferBit);
|
||||
|
||||
RenderShadowMapPass();
|
||||
|
||||
nearDist = farDist;
|
||||
}
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
|
||||
device->Viewport(0, 0, device->ScreenWidth(), device->ScreenHeight());
|
||||
device.Viewport(0, 0, device.ScreenWidth(), device.ScreenHeight());
|
||||
}
|
||||
|
||||
bool GLBasicShadowMapRenderer::Cull(const spades::AABB3 &) {
|
||||
@ -292,5 +291,5 @@ namespace spades {
|
||||
// return true;
|
||||
// return obb.GetDistanceTo(center) < rad;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -31,7 +31,7 @@ namespace spades {
|
||||
|
||||
enum { NumSlices = 3 };
|
||||
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
|
||||
int textureSize;
|
||||
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include "GLBloomFilter.h"
|
||||
#include "GLProgram.h"
|
||||
#include "GLProgramAttribute.h"
|
||||
@ -29,6 +27,8 @@
|
||||
#include "GLQuadRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -48,7 +48,7 @@ namespace spades {
|
||||
|
||||
std::vector<Level> levels;
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
static GLProgramAttribute thruPosition("positionAttribute");
|
||||
@ -77,7 +77,7 @@ namespace spades {
|
||||
thru->Use();
|
||||
thruColor.SetValue(1.f, 1.f, 1.f, 1.f);
|
||||
thruTexture.SetValue(0);
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
// create downsample levels
|
||||
for (int i = 0; i < 6; i++) {
|
||||
@ -96,14 +96,14 @@ namespace spades {
|
||||
|
||||
thru->Use();
|
||||
qr.SetCoordAttributeIndex(thruPosition());
|
||||
dev->BindTexture(IGLDevice::Texture2D, prevLevel.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, newLevel.GetFramebuffer());
|
||||
dev->Viewport(0, 0, newLevel.GetWidth(), newLevel.GetHeight());
|
||||
dev.BindTexture(IGLDevice::Texture2D, prevLevel.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, newLevel.GetFramebuffer());
|
||||
dev.Viewport(0, 0, newLevel.GetWidth(), newLevel.GetHeight());
|
||||
thruTexCoordRange.SetValue(0.f, 0.f,
|
||||
(float)newLevel.GetWidth() * 2.f / (float)prevW,
|
||||
(float)newLevel.GetHeight() * 2.f / (float)prevH);
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
Level lv;
|
||||
lv.w = newW;
|
||||
@ -112,8 +112,8 @@ namespace spades {
|
||||
levels.push_back(lv);
|
||||
}
|
||||
|
||||
dev->Enable(IGLDevice::Blend, true);
|
||||
dev->BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
dev.Enable(IGLDevice::Blend, true);
|
||||
dev.BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
|
||||
// composite levels in the opposite direction
|
||||
thruTexCoordRange.SetValue(0.f, 0.f, 1.f, 1.f);
|
||||
@ -126,12 +126,12 @@ namespace spades {
|
||||
|
||||
thru->Use();
|
||||
qr.SetCoordAttributeIndex(thruPosition());
|
||||
dev->BindTexture(IGLDevice::Texture2D, curLevel.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, targLevel.GetFramebuffer());
|
||||
dev->Viewport(0, 0, targLevel.GetWidth(), targLevel.GetHeight());
|
||||
dev.BindTexture(IGLDevice::Texture2D, curLevel.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, targLevel.GetFramebuffer());
|
||||
dev.Viewport(0, 0, targLevel.GetWidth(), targLevel.GetHeight());
|
||||
thruColor.SetValue(1.f, 1.f, 1.f, alpha);
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
// composite to the final image
|
||||
@ -140,22 +140,22 @@ namespace spades {
|
||||
|
||||
gammaMix->Use();
|
||||
qr.SetCoordAttributeIndex(gammaMixPosition());
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, topLevel.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D, topLevel.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev.Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
gammaMixTexture1.SetValue(0);
|
||||
gammaMixTexture2.SetValue(1);
|
||||
gammaMixMix1.SetValue(.8f, .8f, .8f);
|
||||
gammaMixMix2.SetValue(.2f, .2f, .2f);
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
dev->ActiveTexture(0);
|
||||
dev.ActiveTexture(0);
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include "GLCameraBlurFilter.h"
|
||||
#include "GLProfiler.h"
|
||||
#include "GLProgram.h"
|
||||
@ -30,6 +28,8 @@
|
||||
#include "GLQuadRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -66,10 +66,10 @@ namespace spades {
|
||||
|
||||
bool hasRadialBlur = radialBlur < .9999f;
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
static GLProgramAttribute programPosition("positionAttribute");
|
||||
static GLProgramUniform programTexture("mainTexture");
|
||||
@ -118,10 +118,10 @@ namespace spades {
|
||||
movePixels = std::max(movePixels, MyACos(diffMatrix.m[5]));
|
||||
movePixels = std::max(movePixels, MyACos(diffMatrix.m[10]));
|
||||
movePixels = tanf(movePixels) / tanf(def.fovX * .5f);
|
||||
movePixels *= (float)dev->ScreenWidth() * .5f;
|
||||
movePixels *= (float)dev.ScreenWidth() * .5f;
|
||||
movePixels *= shutterTimeScale;
|
||||
|
||||
movePixels = std::max(movePixels, (1.f - radialBlur) * dev->ScreenWidth() * 0.5f);
|
||||
movePixels = std::max(movePixels, (1.f - radialBlur) * dev.ScreenWidth() * 0.5f);
|
||||
|
||||
if (movePixels < 1.f) {
|
||||
// too less change, skip camera blur
|
||||
@ -146,28 +146,28 @@ namespace spades {
|
||||
GLColorBuffer buf = input;
|
||||
|
||||
qr.SetCoordAttributeIndex(programPosition());
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
dev->ActiveTexture(0);
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
dev.ActiveTexture(0);
|
||||
|
||||
for (int i = 0; i < levels; i++) {
|
||||
GLColorBuffer output = input.GetManager()->CreateBufferHandle();
|
||||
programShutterTimeScale.SetValue(shutterTimeScale);
|
||||
dev->BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
dev.BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev.Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
shutterTimeScale /= 5.f;
|
||||
buf = output;
|
||||
}
|
||||
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev->ActiveTexture(0);
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.ActiveTexture(0);
|
||||
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include "GLColorCorrectionFilter.h"
|
||||
#include "GLProgram.h"
|
||||
#include "GLProgramAttribute.h"
|
||||
@ -29,6 +27,8 @@
|
||||
#include "GLQuadRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include <Core/Settings.h>
|
||||
|
||||
namespace spades {
|
||||
@ -40,7 +40,7 @@ namespace spades {
|
||||
GLColorBuffer GLColorCorrectionFilter::Filter(GLColorBuffer input, Vector3 tintVal) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
static GLProgramAttribute lensPosition("positionAttribute");
|
||||
@ -54,7 +54,7 @@ namespace spades {
|
||||
enhancement(lens);
|
||||
tint(lens);
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
lensPosition(lens);
|
||||
lensTexture(lens);
|
||||
@ -92,13 +92,13 @@ namespace spades {
|
||||
GLColorBuffer output = input.GetManager()->CreateBufferHandle();
|
||||
|
||||
qr.SetCoordAttributeIndex(lensPosition());
|
||||
dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
dev.BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev.Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include "GLDepthOfFieldFilter.h"
|
||||
#include "GLProfiler.h"
|
||||
#include "GLProgram.h"
|
||||
@ -30,6 +28,8 @@
|
||||
#include "GLQuadRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -55,7 +55,7 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
// do gaussian blur
|
||||
GLProgram *program = gaussProgram;
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
int w = buffer.GetWidth();
|
||||
int h = buffer.GetHeight();
|
||||
@ -69,22 +69,22 @@ namespace spades {
|
||||
blur_unitShift(program);
|
||||
blur_textureUniform.SetValue(0);
|
||||
|
||||
dev->ActiveTexture(0);
|
||||
dev.ActiveTexture(0);
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
// x-direction
|
||||
GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, 1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev.BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
blur_unitShift.SetValue(spread / (float)w, 0.f);
|
||||
qr.Draw();
|
||||
buffer.Release();
|
||||
|
||||
// y-direction
|
||||
GLColorBuffer buf3 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, 1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
|
||||
dev.BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
|
||||
blur_unitShift.SetValue(0.f, spread / (float)h);
|
||||
qr.Draw();
|
||||
buf2.Release();
|
||||
@ -96,11 +96,11 @@ namespace spades {
|
||||
float globalBlur, float nearBlur,
|
||||
float farBlur) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
int w = dev->ScreenWidth();
|
||||
int h = dev->ScreenHeight();
|
||||
int w = dev.ScreenWidth();
|
||||
int h = dev.ScreenHeight();
|
||||
int w2 = HighQualityDoFEnabled() ? w : (w + 3) / 4;
|
||||
int h2 = HighQualityDoFEnabled() ? h : (h + 3) / 4;
|
||||
|
||||
@ -151,12 +151,12 @@ namespace spades {
|
||||
farBlurUniform.SetValue(-farBlur);
|
||||
|
||||
qr.SetCoordAttributeIndex(positionAttribute());
|
||||
dev->BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, coc.GetFramebuffer());
|
||||
dev->Viewport(0, 0, w2, h2);
|
||||
dev.BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, coc.GetFramebuffer());
|
||||
dev.Viewport(0, 0, w2, h2);
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
if (HighQualityDoFEnabled()) {
|
||||
@ -183,18 +183,18 @@ namespace spades {
|
||||
cocMix->Use();
|
||||
|
||||
cocBlurTexture.SetValue(1);
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, cocBlur.GetTexture());
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D, cocBlur.GetTexture());
|
||||
|
||||
cocTexture.SetValue(0);
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, coc.GetTexture());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, coc.GetTexture());
|
||||
|
||||
qr.SetCoordAttributeIndex(positionAttribute());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, coc2.GetFramebuffer());
|
||||
dev->Viewport(0, 0, w2, h2);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, coc2.GetFramebuffer());
|
||||
dev.Viewport(0, 0, w2, h2);
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
coc2 = BlurCoC(coc2, .5f);
|
||||
@ -208,7 +208,7 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
// do gaussian blur
|
||||
GLProgram *program = blurProgram;
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
int w = buffer.GetWidth();
|
||||
int h = buffer.GetHeight();
|
||||
@ -226,11 +226,11 @@ namespace spades {
|
||||
blur_offset(program);
|
||||
|
||||
blur_cocUniform.SetValue(1);
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, coc.GetTexture());
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D, coc.GetTexture());
|
||||
|
||||
blur_textureUniform.SetValue(0);
|
||||
dev->ActiveTexture(0);
|
||||
dev.ActiveTexture(0);
|
||||
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
|
||||
@ -240,8 +240,8 @@ namespace spades {
|
||||
while (len > .5f) {
|
||||
GLColorBuffer buf2 =
|
||||
renderer->GetFramebufferManager()->CreateBufferHandle(w2, h2, false);
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev->BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev.BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
blur_offset.SetValue(offset.x * sX, offset.y * sY);
|
||||
qr.Draw();
|
||||
buffer = buf2;
|
||||
@ -257,7 +257,7 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
// do gaussian blur
|
||||
GLProgram *program = gammaMix;
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
int w = buffer1.GetWidth();
|
||||
int h = buffer1.GetHeight();
|
||||
@ -273,13 +273,13 @@ namespace spades {
|
||||
|
||||
blur_textureUniform1(program);
|
||||
blur_textureUniform1.SetValue(1);
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, buffer1.GetTexture());
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D, buffer1.GetTexture());
|
||||
|
||||
blur_textureUniform2(program);
|
||||
blur_textureUniform2.SetValue(0);
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, buffer2.GetTexture());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, buffer2.GetTexture());
|
||||
|
||||
blur_mix1(program);
|
||||
blur_mix2(program);
|
||||
@ -288,11 +288,11 @@ namespace spades {
|
||||
blur_mix2.SetValue(.5f, .5f, .5f);
|
||||
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
// x-direction
|
||||
GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false);
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
qr.Draw();
|
||||
return buf2;
|
||||
}
|
||||
@ -302,7 +302,7 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
// do gaussian blur
|
||||
GLProgram *program = finalMix;
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
int w = tex.GetWidth();
|
||||
int h = tex.GetHeight();
|
||||
@ -318,33 +318,33 @@ namespace spades {
|
||||
|
||||
blur_textureUniform1(program);
|
||||
blur_textureUniform1.SetValue(3);
|
||||
dev->ActiveTexture(3);
|
||||
dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
dev.ActiveTexture(3);
|
||||
dev.BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
|
||||
blur_textureUniform2(program);
|
||||
blur_textureUniform2.SetValue(2);
|
||||
dev->ActiveTexture(2);
|
||||
dev->BindTexture(IGLDevice::Texture2D, blur1.GetTexture());
|
||||
dev.ActiveTexture(2);
|
||||
dev.BindTexture(IGLDevice::Texture2D, blur1.GetTexture());
|
||||
|
||||
blur_textureUniform3(program);
|
||||
blur_textureUniform3.SetValue(1);
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, blur2.GetTexture());
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D, blur2.GetTexture());
|
||||
|
||||
blur_textureUniform4(program);
|
||||
blur_textureUniform4.SetValue(0);
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, coc.GetTexture());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, coc.GetTexture());
|
||||
|
||||
blur_blurredOnlyUniform(program);
|
||||
blur_blurredOnlyUniform.SetValue(HighQualityDoFEnabled() ? 1 : 0);
|
||||
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
// x-direction
|
||||
GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false);
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
qr.Draw();
|
||||
return buf2;
|
||||
}
|
||||
@ -353,7 +353,7 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
// do gaussian blur
|
||||
GLProgram *program = passthrough;
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
int w = tex.GetWidth();
|
||||
int h = tex.GetHeight();
|
||||
@ -367,8 +367,8 @@ namespace spades {
|
||||
|
||||
blur_textureUniform(program);
|
||||
blur_textureUniform.SetValue(0);
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
|
||||
blur_colorUniform(program);
|
||||
blur_colorUniform.SetValue(1.f, 1.f, 1.f, 1.f);
|
||||
@ -377,12 +377,12 @@ namespace spades {
|
||||
blur_texCoordRangeUniform.SetValue(0.f, 0.f, 1.f, 1.f);
|
||||
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
GLColorBuffer buf2 =
|
||||
renderer->GetFramebufferManager()->CreateBufferHandle(w / 2, h / 2, false);
|
||||
dev->Viewport(0, 0, w / 2, h / 2);
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev.Viewport(0, 0, w / 2, h / 2);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
qr.Draw();
|
||||
return buf2;
|
||||
}
|
||||
@ -392,13 +392,13 @@ namespace spades {
|
||||
float nearBlur, float farBlur) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
int w = dev->ScreenWidth();
|
||||
int h = dev->ScreenHeight();
|
||||
int w = dev.ScreenWidth();
|
||||
int h = dev.ScreenHeight();
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
GLColorBuffer coc;
|
||||
|
||||
@ -429,7 +429,7 @@ namespace spades {
|
||||
maxCoc /= (float)divide;
|
||||
}
|
||||
|
||||
dev->Viewport(0, 0, w / divide, h / divide);
|
||||
dev.Viewport(0, 0, w / divide, h / divide);
|
||||
|
||||
GLColorBuffer buf1, buf2;
|
||||
{
|
||||
@ -455,12 +455,12 @@ namespace spades {
|
||||
buf2 = Blur(buf2, coc, MakeVector2(sin60, cos60) * maxCoc);
|
||||
}
|
||||
|
||||
dev->Viewport(0, 0, w, h);
|
||||
dev.Viewport(0, 0, w, h);
|
||||
{
|
||||
GLProfiler::Context p(renderer->GetGLProfiler(), "Mix 2");
|
||||
GLColorBuffer output = FinalMix(input, buf1, buf2, coc);
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -19,10 +19,10 @@
|
||||
*/
|
||||
|
||||
#include "GLDynamicLightShader.h"
|
||||
#include <Core/Settings.h>
|
||||
#include "GLImage.h"
|
||||
#include "GLProgramManager.h"
|
||||
#include "GLRenderer.h"
|
||||
#include <Core/Settings.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -62,7 +62,7 @@ namespace spades {
|
||||
|
||||
const client::DynamicLightParam ¶m = light.GetParam();
|
||||
|
||||
IGLDevice *device = renderer->GetGLDevice();
|
||||
IGLDevice &device = renderer->GetGLDevice();
|
||||
dynamicLightOrigin(program);
|
||||
dynamicLightColor(program);
|
||||
dynamicLightRadius(program);
|
||||
@ -76,7 +76,7 @@ namespace spades {
|
||||
dynamicLightRadiusInversed.SetValue(1.f / param.radius);
|
||||
|
||||
if (param.type == client::DynamicLightTypeSpotlight) {
|
||||
device->ActiveTexture(texStage);
|
||||
device.ActiveTexture(texStage);
|
||||
static_cast<GLImage *>(param.image)->Bind(IGLDevice::Texture2D);
|
||||
dynamicLightProjectionTexture.SetValue(texStage);
|
||||
texStage++;
|
||||
@ -84,13 +84,13 @@ namespace spades {
|
||||
dynamicLightSpotMatrix.SetValue(light.GetProjectionMatrix());
|
||||
|
||||
// bad hack to make texture clamped to edge
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
} else {
|
||||
device->ActiveTexture(texStage);
|
||||
device.ActiveTexture(texStage);
|
||||
whiteImage->Bind(IGLDevice::Texture2D);
|
||||
dynamicLightProjectionTexture.SetValue(texStage);
|
||||
texStage++;
|
||||
@ -101,9 +101,9 @@ namespace spades {
|
||||
Matrix4::Scale(0.0));
|
||||
}
|
||||
|
||||
device->ActiveTexture(texStage);
|
||||
device.ActiveTexture(texStage);
|
||||
|
||||
return texStage;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include "GLFXAAFilter.h"
|
||||
#include "GLProgram.h"
|
||||
#include "GLProgramAttribute.h"
|
||||
@ -29,6 +27,8 @@
|
||||
#include "GLQuadRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -38,14 +38,14 @@ namespace spades {
|
||||
GLColorBuffer GLFXAAFilter::Filter(GLColorBuffer input) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
static GLProgramAttribute lensPosition("positionAttribute");
|
||||
static GLProgramUniform lensTexture("mainTexture");
|
||||
static GLProgramUniform inverseVP("inverseVP");
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
lensPosition(lens);
|
||||
lensTexture(lens);
|
||||
@ -53,20 +53,20 @@ namespace spades {
|
||||
|
||||
lens->Use();
|
||||
|
||||
inverseVP.SetValue(1.f / dev->ScreenWidth(), 1.f / dev->ScreenHeight());
|
||||
inverseVP.SetValue(1.f / dev.ScreenWidth(), 1.f / dev.ScreenHeight());
|
||||
lensTexture.SetValue(0);
|
||||
|
||||
// composite to the final image
|
||||
GLColorBuffer output = input.GetManager()->CreateBufferHandle();
|
||||
|
||||
qr.SetCoordAttributeIndex(lensPosition());
|
||||
dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
dev.BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev.Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -40,11 +40,11 @@ namespace spades {
|
||||
image = renderer->CreateImage(*bmp).Cast<GLImage>();
|
||||
|
||||
image->Bind(IGLDevice::Texture2D);
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
}
|
||||
|
||||
GLFlatMapRenderer::~GLFlatMapRenderer() {}
|
||||
@ -108,7 +108,7 @@ namespace spades {
|
||||
GenerateBitmap(chunkX * ChunkSize, chunkY * ChunkSize, ChunkSize, ChunkSize),
|
||||
false);
|
||||
try {
|
||||
image->SubImage(bmp, chunkX * ChunkSize, chunkY * ChunkSize);
|
||||
image->SubImage(bmp.GetPointerOrNull(), chunkX * ChunkSize, chunkY * ChunkSize);
|
||||
} catch (...) {
|
||||
throw;
|
||||
}
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include "GLFogFilter.h"
|
||||
#include "GLMapShadowRenderer.h"
|
||||
#include "GLProgram.h"
|
||||
@ -30,6 +28,8 @@
|
||||
#include "GLQuadRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -39,7 +39,7 @@ namespace spades {
|
||||
GLColorBuffer GLFogFilter::Filter(GLColorBuffer input) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
static GLProgramAttribute lensPosition("positionAttribute");
|
||||
@ -57,7 +57,7 @@ namespace spades {
|
||||
static GLProgramUniform fogColor("fogColor");
|
||||
static GLProgramUniform fogDistance("fogDistance");
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
lensPosition(lens);
|
||||
lensShadowMapTexture(lens);
|
||||
@ -103,24 +103,24 @@ namespace spades {
|
||||
// composite to the final image
|
||||
GLColorBuffer output = input.GetManager()->CreateBufferHandle();
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
qr.SetCoordAttributeIndex(lensPosition());
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, input.GetManager()->GetDepthTexture());
|
||||
dev->ActiveTexture(2);
|
||||
dev->BindTexture(IGLDevice::Texture2D, renderer->GetMapShadowRenderer()->GetTexture());
|
||||
dev->ActiveTexture(3);
|
||||
dev->BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetMapShadowRenderer()->GetCoarseTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D, input.GetManager()->GetDepthTexture());
|
||||
dev.ActiveTexture(2);
|
||||
dev.BindTexture(IGLDevice::Texture2D, renderer->GetMapShadowRenderer()->GetTexture());
|
||||
dev.ActiveTexture(3);
|
||||
dev.BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetMapShadowRenderer()->GetCoarseTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev.Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
qr.Draw();
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -19,23 +19,18 @@
|
||||
*/
|
||||
|
||||
#include "GLFramebufferManager.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
#include "GLSettings.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
static void RaiseFBStatusError(IGLDevice::Enum status) {
|
||||
std::string type;
|
||||
switch (status) {
|
||||
case IGLDevice::FramebufferComplete:
|
||||
type = "GL_FRAMEBUFFER_COMPLETE";
|
||||
break;
|
||||
case IGLDevice::FramebufferUndefined:
|
||||
type = "GL_FRAMEBUFFER_UNDEFINED";
|
||||
break;
|
||||
case IGLDevice::FramebufferComplete: type = "GL_FRAMEBUFFER_COMPLETE"; break;
|
||||
case IGLDevice::FramebufferUndefined: type = "GL_FRAMEBUFFER_UNDEFINED"; break;
|
||||
case IGLDevice::FramebufferIncompleteAttachment:
|
||||
type = "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
|
||||
break;
|
||||
@ -61,7 +56,7 @@ namespace spades {
|
||||
SPRaise("OpenGL Framebuffer completeness check failed: %s", type.c_str());
|
||||
}
|
||||
|
||||
GLFramebufferManager::GLFramebufferManager(IGLDevice *dev, GLSettings &settings)
|
||||
GLFramebufferManager::GLFramebufferManager(IGLDevice &dev, GLSettings &settings)
|
||||
: device(dev), settings(settings), doingPostProcessing(false) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
@ -83,35 +78,34 @@ namespace spades {
|
||||
// multisample renderbuffer for scene
|
||||
// rendering.
|
||||
|
||||
multisampledFramebuffer = dev->GenFramebuffer();
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
multisampledFramebuffer = dev.GenFramebuffer();
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
|
||||
multisampledDepthRenderbuffer = dev->GenRenderbuffer();
|
||||
dev->BindRenderbuffer(IGLDevice::Renderbuffer, multisampledDepthRenderbuffer);
|
||||
dev->RenderbufferStorage(IGLDevice::Renderbuffer, (int)settings.r_multisamples,
|
||||
IGLDevice::DepthComponent24, dev->ScreenWidth(),
|
||||
dev->ScreenHeight());
|
||||
multisampledDepthRenderbuffer = dev.GenRenderbuffer();
|
||||
dev.BindRenderbuffer(IGLDevice::Renderbuffer, multisampledDepthRenderbuffer);
|
||||
dev.RenderbufferStorage(IGLDevice::Renderbuffer, (int)settings.r_multisamples,
|
||||
IGLDevice::DepthComponent24, dev.ScreenWidth(),
|
||||
dev.ScreenHeight());
|
||||
SPLog("MSAA Depth Buffer Allocated");
|
||||
|
||||
dev->FramebufferRenderbuffer(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Renderbuffer,
|
||||
multisampledDepthRenderbuffer);
|
||||
dev.FramebufferRenderbuffer(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Renderbuffer, multisampledDepthRenderbuffer);
|
||||
|
||||
multisampledColorRenderbuffer = dev->GenRenderbuffer();
|
||||
dev->BindRenderbuffer(IGLDevice::Renderbuffer, multisampledColorRenderbuffer);
|
||||
multisampledColorRenderbuffer = dev.GenRenderbuffer();
|
||||
dev.BindRenderbuffer(IGLDevice::Renderbuffer, multisampledColorRenderbuffer);
|
||||
if (settings.r_srgb) {
|
||||
SPLog("Creating MSAA Color Buffer with SRGB8_ALPHA");
|
||||
useHighPrec = false;
|
||||
dev->RenderbufferStorage(IGLDevice::Renderbuffer, (int)settings.r_multisamples,
|
||||
IGLDevice::SRGB8Alpha, dev->ScreenWidth(),
|
||||
dev->ScreenHeight());
|
||||
dev.RenderbufferStorage(IGLDevice::Renderbuffer, (int)settings.r_multisamples,
|
||||
IGLDevice::SRGB8Alpha, dev.ScreenWidth(),
|
||||
dev.ScreenHeight());
|
||||
|
||||
SPLog("MSAA Color Buffer Allocated");
|
||||
|
||||
dev->FramebufferRenderbuffer(
|
||||
IGLDevice::Framebuffer, IGLDevice::ColorAttachment0, IGLDevice::Renderbuffer,
|
||||
multisampledColorRenderbuffer);
|
||||
IGLDevice::Enum status = dev->CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
dev.FramebufferRenderbuffer(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Renderbuffer,
|
||||
multisampledColorRenderbuffer);
|
||||
IGLDevice::Enum status = dev.CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
if (status != IGLDevice::FramebufferComplete) {
|
||||
RaiseFBStatusError(status);
|
||||
}
|
||||
@ -123,17 +117,16 @@ namespace spades {
|
||||
SPLog("RGB10A2/HDR disabled");
|
||||
SPRaise("jump to catch(...)");
|
||||
}
|
||||
dev->RenderbufferStorage(IGLDevice::Renderbuffer,
|
||||
(int)settings.r_multisamples,
|
||||
useHdr ? IGLDevice::RGBA16F : IGLDevice::RGB10A2,
|
||||
dev->ScreenWidth(), dev->ScreenHeight());
|
||||
dev.RenderbufferStorage(IGLDevice::Renderbuffer,
|
||||
(int)settings.r_multisamples,
|
||||
useHdr ? IGLDevice::RGBA16F : IGLDevice::RGB10A2,
|
||||
dev.ScreenWidth(), dev.ScreenHeight());
|
||||
SPLog("MSAA Color Buffer Allocated");
|
||||
|
||||
dev->FramebufferRenderbuffer(
|
||||
dev.FramebufferRenderbuffer(
|
||||
IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Renderbuffer, multisampledColorRenderbuffer);
|
||||
IGLDevice::Enum status =
|
||||
dev->CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
IGLDevice::Enum status = dev.CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
if (status != IGLDevice::FramebufferComplete) {
|
||||
RaiseFBStatusError(status);
|
||||
}
|
||||
@ -145,17 +138,16 @@ namespace spades {
|
||||
useHighPrec = false;
|
||||
useHdr = false;
|
||||
settings.r_hdr = 0;
|
||||
dev->RenderbufferStorage(IGLDevice::Renderbuffer,
|
||||
(int)settings.r_multisamples, IGLDevice::RGBA8,
|
||||
dev->ScreenWidth(), dev->ScreenHeight());
|
||||
dev.RenderbufferStorage(IGLDevice::Renderbuffer,
|
||||
(int)settings.r_multisamples, IGLDevice::RGBA8,
|
||||
dev.ScreenWidth(), dev.ScreenHeight());
|
||||
|
||||
SPLog("MSAA Color Buffer Allocated");
|
||||
|
||||
dev->FramebufferRenderbuffer(
|
||||
dev.FramebufferRenderbuffer(
|
||||
IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Renderbuffer, multisampledColorRenderbuffer);
|
||||
IGLDevice::Enum status =
|
||||
dev->CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
IGLDevice::Enum status = dev.CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
if (status != IGLDevice::FramebufferComplete) {
|
||||
RaiseFBStatusError(status);
|
||||
}
|
||||
@ -174,49 +166,45 @@ namespace spades {
|
||||
// we must first copy to non-multismapled
|
||||
// framebuffer to use it in shader as a texture.
|
||||
|
||||
renderFramebuffer = dev->GenFramebuffer();
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
renderFramebuffer = dev.GenFramebuffer();
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
|
||||
renderDepthTexture = dev->GenTexture();
|
||||
dev->BindTexture(IGLDevice::Texture2D, renderDepthTexture);
|
||||
dev->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24,
|
||||
dev->ScreenWidth(), dev->ScreenHeight(), 0, IGLDevice::DepthComponent,
|
||||
IGLDevice::UnsignedInt, NULL);
|
||||
renderDepthTexture = dev.GenTexture();
|
||||
dev.BindTexture(IGLDevice::Texture2D, renderDepthTexture);
|
||||
dev.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24, dev.ScreenWidth(),
|
||||
dev.ScreenHeight(), 0, IGLDevice::DepthComponent, IGLDevice::UnsignedInt,
|
||||
NULL);
|
||||
SPLog("Depth Buffer Allocated");
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter, IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter, IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::ClampToEdge);
|
||||
|
||||
dev->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, renderDepthTexture, 0);
|
||||
dev.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, renderDepthTexture, 0);
|
||||
|
||||
renderColorTexture = dev->GenTexture();
|
||||
dev->BindTexture(IGLDevice::Texture2D, renderColorTexture);
|
||||
renderColorTexture = dev.GenTexture();
|
||||
dev.BindTexture(IGLDevice::Texture2D, renderColorTexture);
|
||||
if (settings.r_srgb) {
|
||||
SPLog("Creating Non-MSAA SRGB buffer");
|
||||
useHighPrec = false;
|
||||
dev->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::SRGB8Alpha, dev->ScreenWidth(),
|
||||
dev->ScreenHeight(), 0, IGLDevice::RGBA, IGLDevice::UnsignedByte,
|
||||
NULL);
|
||||
dev.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::SRGB8Alpha, dev.ScreenWidth(),
|
||||
dev.ScreenHeight(), 0, IGLDevice::RGBA, IGLDevice::UnsignedByte,
|
||||
NULL);
|
||||
SPLog("Color Buffer Allocated");
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
dev->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, renderColorTexture, 0);
|
||||
dev.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, renderColorTexture, 0);
|
||||
|
||||
IGLDevice::Enum status = dev->CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
IGLDevice::Enum status = dev.CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
if (status != IGLDevice::FramebufferComplete) {
|
||||
RaiseFBStatusError(status);
|
||||
}
|
||||
@ -228,24 +216,24 @@ namespace spades {
|
||||
SPLog("RGB10A2/HDR disabled");
|
||||
SPRaise("jump to catch(...)");
|
||||
}
|
||||
dev->TexImage2D(IGLDevice::Texture2D, 0,
|
||||
useHdr ? IGLDevice::RGBA16F : IGLDevice::RGB10A2,
|
||||
dev->ScreenWidth(), dev->ScreenHeight(), 0, IGLDevice::RGBA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
dev.TexImage2D(IGLDevice::Texture2D, 0,
|
||||
useHdr ? IGLDevice::RGBA16F : IGLDevice::RGB10A2,
|
||||
dev.ScreenWidth(), dev.ScreenHeight(), 0, IGLDevice::RGBA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
SPLog("Color Buffer Allocated");
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
dev->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, renderColorTexture, 0);
|
||||
dev.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, renderColorTexture, 0);
|
||||
|
||||
IGLDevice::Enum status = dev->CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
IGLDevice::Enum status = dev.CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
if (status != IGLDevice::FramebufferComplete) {
|
||||
RaiseFBStatusError(status);
|
||||
}
|
||||
@ -256,23 +244,23 @@ namespace spades {
|
||||
useHighPrec = false;
|
||||
useHdr = false;
|
||||
settings.r_hdr = 0;
|
||||
dev->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, dev->ScreenWidth(),
|
||||
dev->ScreenHeight(), 0, IGLDevice::RGBA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
dev.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, dev.ScreenWidth(),
|
||||
dev.ScreenHeight(), 0, IGLDevice::RGBA, IGLDevice::UnsignedByte,
|
||||
NULL);
|
||||
SPLog("Color Buffer Allocated");
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
dev->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, renderColorTexture, 0);
|
||||
dev.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, renderColorTexture, 0);
|
||||
|
||||
IGLDevice::Enum status = dev->CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
IGLDevice::Enum status = dev.CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
if (status != IGLDevice::FramebufferComplete) {
|
||||
RaiseFBStatusError(status);
|
||||
}
|
||||
@ -283,73 +271,73 @@ namespace spades {
|
||||
|
||||
if ((int)settings.r_water >= 2) {
|
||||
SPLog("Creating Mirror framebuffer");
|
||||
mirrorFramebuffer = dev->GenFramebuffer();
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, mirrorFramebuffer);
|
||||
mirrorFramebuffer = dev.GenFramebuffer();
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, mirrorFramebuffer);
|
||||
|
||||
mirrorColorTexture = dev->GenTexture();
|
||||
dev->BindTexture(IGLDevice::Texture2D, mirrorColorTexture);
|
||||
mirrorColorTexture = dev.GenTexture();
|
||||
dev.BindTexture(IGLDevice::Texture2D, mirrorColorTexture);
|
||||
SPLog("Creating Mirror texture");
|
||||
dev->TexImage2D(IGLDevice::Texture2D, 0, fbInternalFormat, dev->ScreenWidth(),
|
||||
dev->ScreenHeight(), 0, IGLDevice::RGBA, IGLDevice::UnsignedByte,
|
||||
NULL);
|
||||
dev.TexImage2D(IGLDevice::Texture2D, 0, fbInternalFormat, dev.ScreenWidth(),
|
||||
dev.ScreenHeight(), 0, IGLDevice::RGBA, IGLDevice::UnsignedByte,
|
||||
NULL);
|
||||
|
||||
SPLog("Color Buffer Allocated");
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
dev->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, mirrorColorTexture, 0);
|
||||
dev.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, mirrorColorTexture, 0);
|
||||
|
||||
SPLog("Creating Mirror depth texture");
|
||||
mirrorDepthTexture = dev->GenTexture();
|
||||
dev->BindTexture(IGLDevice::Texture2D, mirrorDepthTexture);
|
||||
dev->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24,
|
||||
dev->ScreenWidth(), dev->ScreenHeight(), 0,
|
||||
IGLDevice::DepthComponent, IGLDevice::UnsignedInt, NULL);
|
||||
mirrorDepthTexture = dev.GenTexture();
|
||||
dev.BindTexture(IGLDevice::Texture2D, mirrorDepthTexture);
|
||||
dev.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24,
|
||||
dev.ScreenWidth(), dev.ScreenHeight(), 0, IGLDevice::DepthComponent,
|
||||
IGLDevice::UnsignedInt, NULL);
|
||||
|
||||
SPLog("Depth Buffer Allocated");
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
dev->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, mirrorDepthTexture, 0);
|
||||
dev.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, mirrorDepthTexture, 0);
|
||||
|
||||
IGLDevice::Enum status = dev->CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
IGLDevice::Enum status = dev.CheckFramebufferStatus(IGLDevice::Framebuffer);
|
||||
if (status != IGLDevice::FramebufferComplete) {
|
||||
RaiseFBStatusError(status);
|
||||
}
|
||||
SPLog("Mirror Framebuffer Created");
|
||||
} // (int)r_water >= 2
|
||||
|
||||
renderFramebufferWithoutDepth = dev->GenFramebuffer();
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, renderFramebufferWithoutDepth);
|
||||
dev->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, renderColorTexture, 0);
|
||||
renderFramebufferWithoutDepth = dev.GenFramebuffer();
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, renderFramebufferWithoutDepth);
|
||||
dev.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, renderColorTexture, 0);
|
||||
|
||||
// add render buffer as a registered buffer
|
||||
Buffer buf;
|
||||
buf.framebuffer = renderFramebufferWithoutDepth;
|
||||
buf.texture = renderColorTexture;
|
||||
buf.refCount = 0;
|
||||
buf.w = device->ScreenWidth();
|
||||
buf.h = device->ScreenHeight();
|
||||
buf.w = device.ScreenWidth();
|
||||
buf.h = device.ScreenHeight();
|
||||
buf.internalFormat = fbInternalFormat;
|
||||
buffers.push_back(buf);
|
||||
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
dev->BindRenderbuffer(IGLDevice::Renderbuffer, 0);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
dev.BindRenderbuffer(IGLDevice::Renderbuffer, 0);
|
||||
}
|
||||
|
||||
GLFramebufferManager::~GLFramebufferManager() {
|
||||
@ -361,11 +349,11 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
if (useMultisample) {
|
||||
// ---- multisampled
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
device->Enable(IGLDevice::Multisample, useMultisample);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
device.Enable(IGLDevice::Multisample, useMultisample);
|
||||
} else {
|
||||
// ---- single sampled
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
|
||||
// calling glDisable(GL_MULTISAMPLE) on non-MSAA FB
|
||||
// causes GL_INVALID_FRAMEBUFFER_OPERATION on
|
||||
@ -374,9 +362,9 @@ namespace spades {
|
||||
|
||||
doingPostProcessing = false;
|
||||
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device->DepthMask(true);
|
||||
device->Viewport(0, 0, device->ScreenWidth(), device->ScreenHeight());
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
device.DepthMask(true);
|
||||
device.Viewport(0, 0, device.ScreenWidth(), device.ScreenHeight());
|
||||
}
|
||||
|
||||
GLColorBuffer
|
||||
@ -394,71 +382,71 @@ namespace spades {
|
||||
captured.Release();
|
||||
}
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, tempFb);
|
||||
device->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, handle.GetTexture(), 0);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, tempFb);
|
||||
device.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, handle.GetTexture(), 0);
|
||||
|
||||
// downsample
|
||||
int w = device->ScreenWidth();
|
||||
int h = device->ScreenHeight();
|
||||
int w = device.ScreenWidth();
|
||||
int h = device.ScreenHeight();
|
||||
|
||||
if (settings.r_blitFramebuffer) {
|
||||
if (useMultisample) {
|
||||
device->BindFramebuffer(IGLDevice::ReadFramebuffer, multisampledFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::ReadFramebuffer, multisampledFramebuffer);
|
||||
} else {
|
||||
device->BindFramebuffer(IGLDevice::ReadFramebuffer, renderFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::ReadFramebuffer, renderFramebuffer);
|
||||
}
|
||||
device->BindFramebuffer(IGLDevice::DrawFramebuffer, tempFb);
|
||||
device->BlitFramebuffer(0, 0, w, h, 0, 0, w, h, IGLDevice::ColorBufferBit,
|
||||
IGLDevice::Nearest);
|
||||
device->BlitFramebuffer(0, 0, w, h, 0, 0, w, h, IGLDevice::DepthBufferBit,
|
||||
IGLDevice::Nearest);
|
||||
device->BindFramebuffer(IGLDevice::ReadFramebuffer, 0);
|
||||
device->BindFramebuffer(IGLDevice::DrawFramebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::DrawFramebuffer, tempFb);
|
||||
device.BlitFramebuffer(0, 0, w, h, 0, 0, w, h, IGLDevice::ColorBufferBit,
|
||||
IGLDevice::Nearest);
|
||||
device.BlitFramebuffer(0, 0, w, h, 0, 0, w, h, IGLDevice::DepthBufferBit,
|
||||
IGLDevice::Nearest);
|
||||
device.BindFramebuffer(IGLDevice::ReadFramebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::DrawFramebuffer, 0);
|
||||
} else {
|
||||
if (useMultisample) {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
} else {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
}
|
||||
device->BindTexture(IGLDevice::Texture2D, handle.GetTexture());
|
||||
device->CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device->BindTexture(IGLDevice::Texture2D, tempDepthTex);
|
||||
device->CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device.BindTexture(IGLDevice::Texture2D, handle.GetTexture());
|
||||
device.CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device.BindTexture(IGLDevice::Texture2D, tempDepthTex);
|
||||
device.CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
}
|
||||
|
||||
// restore render framebuffer
|
||||
if (useMultisample) {
|
||||
// ---- multisampled
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
} else {
|
||||
// ---- single sampled
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void GLFramebufferManager::ClearMirrorTexture(spades::Vector3 bgCol) {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, mirrorFramebuffer);
|
||||
device->Viewport(0, 0, device->ScreenWidth(), device->ScreenHeight());
|
||||
device->ClearColor(bgCol.x, bgCol.y, bgCol.z, 1.f);
|
||||
device->Clear((IGLDevice::Enum)(IGLDevice::ColorBufferBit | IGLDevice::DepthBufferBit));
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, mirrorFramebuffer);
|
||||
device.Viewport(0, 0, device.ScreenWidth(), device.ScreenHeight());
|
||||
device.ClearColor(bgCol.x, bgCol.y, bgCol.z, 1.f);
|
||||
device.Clear((IGLDevice::Enum)(IGLDevice::ColorBufferBit | IGLDevice::DepthBufferBit));
|
||||
|
||||
// restore framebuffer
|
||||
if (useMultisample) {
|
||||
// ---- multisampled
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
} else {
|
||||
// ---- single sampled
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void GLFramebufferManager::CopyToMirrorTexture(IGLDevice::UInteger fb) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
int w = device->ScreenWidth();
|
||||
int h = device->ScreenHeight();
|
||||
int w = device.ScreenWidth();
|
||||
int h = device.ScreenHeight();
|
||||
if (fb == 0) {
|
||||
fb = useMultisample ? multisampledFramebuffer : renderFramebuffer;
|
||||
}
|
||||
@ -468,59 +456,59 @@ namespace spades {
|
||||
if (useMultisample) {
|
||||
// downsample
|
||||
if (settings.r_blitFramebuffer) {
|
||||
device->BindFramebuffer(IGLDevice::ReadFramebuffer, fb);
|
||||
device->BindFramebuffer(IGLDevice::DrawFramebuffer, mirrorFramebuffer);
|
||||
device->BlitFramebuffer(0, 0, w, h, 0, 0, w, h,
|
||||
IGLDevice::ColorBufferBit |
|
||||
(needsDepth ? IGLDevice::DepthBufferBit : 0),
|
||||
IGLDevice::Nearest);
|
||||
device->BindFramebuffer(IGLDevice::ReadFramebuffer, 0);
|
||||
device->BindFramebuffer(IGLDevice::DrawFramebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::ReadFramebuffer, fb);
|
||||
device.BindFramebuffer(IGLDevice::DrawFramebuffer, mirrorFramebuffer);
|
||||
device.BlitFramebuffer(0, 0, w, h, 0, 0, w, h,
|
||||
IGLDevice::ColorBufferBit |
|
||||
(needsDepth ? IGLDevice::DepthBufferBit : 0),
|
||||
IGLDevice::Nearest);
|
||||
device.BindFramebuffer(IGLDevice::ReadFramebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::DrawFramebuffer, 0);
|
||||
} else {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, fb);
|
||||
device->BindTexture(IGLDevice::Texture2D, mirrorColorTexture);
|
||||
device->CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, fb);
|
||||
device.BindTexture(IGLDevice::Texture2D, mirrorColorTexture);
|
||||
device.CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
if (needsDepth) {
|
||||
device->BindTexture(IGLDevice::Texture2D, mirrorDepthTexture);
|
||||
device->CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device.BindTexture(IGLDevice::Texture2D, mirrorDepthTexture);
|
||||
device.CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// copy
|
||||
if (settings.r_blitFramebuffer) {
|
||||
device->BindFramebuffer(IGLDevice::ReadFramebuffer, fb);
|
||||
device->BindFramebuffer(IGLDevice::DrawFramebuffer, mirrorFramebuffer);
|
||||
device->BlitFramebuffer(0, 0, w, h, 0, 0, w, h,
|
||||
IGLDevice::ColorBufferBit |
|
||||
(needsDepth ? IGLDevice::DepthBufferBit : 0),
|
||||
IGLDevice::Nearest);
|
||||
device->BindFramebuffer(IGLDevice::ReadFramebuffer, 0);
|
||||
device->BindFramebuffer(IGLDevice::DrawFramebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::ReadFramebuffer, fb);
|
||||
device.BindFramebuffer(IGLDevice::DrawFramebuffer, mirrorFramebuffer);
|
||||
device.BlitFramebuffer(0, 0, w, h, 0, 0, w, h,
|
||||
IGLDevice::ColorBufferBit |
|
||||
(needsDepth ? IGLDevice::DepthBufferBit : 0),
|
||||
IGLDevice::Nearest);
|
||||
device.BindFramebuffer(IGLDevice::ReadFramebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::DrawFramebuffer, 0);
|
||||
} else {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, fb);
|
||||
device->BindTexture(IGLDevice::Texture2D, mirrorColorTexture);
|
||||
device->CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, fb);
|
||||
device.BindTexture(IGLDevice::Texture2D, mirrorColorTexture);
|
||||
device.CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
if (needsDepth) {
|
||||
device->BindTexture(IGLDevice::Texture2D, mirrorDepthTexture);
|
||||
device->CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device.BindTexture(IGLDevice::Texture2D, mirrorDepthTexture);
|
||||
device.CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
device->BindTexture(IGLDevice::Texture2D, mirrorColorTexture);
|
||||
// device->GenerateMipmap(IGLDevice::Texture2D);
|
||||
device.BindTexture(IGLDevice::Texture2D, mirrorColorTexture);
|
||||
// device.GenerateMipmap(IGLDevice::Texture2D);
|
||||
|
||||
// restore framebuffer
|
||||
if (useMultisample) {
|
||||
// ---- multisampled
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
} else {
|
||||
// ---- single sampled
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, renderFramebuffer);
|
||||
}
|
||||
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device->DepthMask(true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
device.DepthMask(true);
|
||||
}
|
||||
|
||||
GLFramebufferManager::BufferHandle GLFramebufferManager::StartPostProcessing() {
|
||||
@ -530,28 +518,28 @@ namespace spades {
|
||||
|
||||
if (useMultisample) {
|
||||
// downsample
|
||||
int w = device->ScreenWidth();
|
||||
int h = device->ScreenHeight();
|
||||
int w = device.ScreenWidth();
|
||||
int h = device.ScreenHeight();
|
||||
if (settings.r_blitFramebuffer) {
|
||||
device->BindFramebuffer(IGLDevice::ReadFramebuffer, multisampledFramebuffer);
|
||||
device->BindFramebuffer(IGLDevice::DrawFramebuffer, renderFramebuffer);
|
||||
device->BlitFramebuffer(0, 0, w, h, 0, 0, w, h, IGLDevice::ColorBufferBit,
|
||||
IGLDevice::Nearest);
|
||||
device->BlitFramebuffer(0, 0, w, h, 0, 0, w, h, IGLDevice::DepthBufferBit,
|
||||
IGLDevice::Nearest);
|
||||
device->BindFramebuffer(IGLDevice::ReadFramebuffer, 0);
|
||||
device->BindFramebuffer(IGLDevice::DrawFramebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::ReadFramebuffer, multisampledFramebuffer);
|
||||
device.BindFramebuffer(IGLDevice::DrawFramebuffer, renderFramebuffer);
|
||||
device.BlitFramebuffer(0, 0, w, h, 0, 0, w, h, IGLDevice::ColorBufferBit,
|
||||
IGLDevice::Nearest);
|
||||
device.BlitFramebuffer(0, 0, w, h, 0, 0, w, h, IGLDevice::DepthBufferBit,
|
||||
IGLDevice::Nearest);
|
||||
device.BindFramebuffer(IGLDevice::ReadFramebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::DrawFramebuffer, 0);
|
||||
} else {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
device->BindTexture(IGLDevice::Texture2D, renderColorTexture);
|
||||
device->CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device->BindTexture(IGLDevice::Texture2D, renderDepthTexture);
|
||||
device->CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, multisampledFramebuffer);
|
||||
device.BindTexture(IGLDevice::Texture2D, renderColorTexture);
|
||||
device.CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
device.BindTexture(IGLDevice::Texture2D, renderDepthTexture);
|
||||
device.CopyTexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 0, 0, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
device->Enable(IGLDevice::DepthTest, false);
|
||||
device->DepthMask(false);
|
||||
device.Enable(IGLDevice::DepthTest, false);
|
||||
device.DepthMask(false);
|
||||
|
||||
// zero is always renderFramebuffer
|
||||
return BufferHandle(this, 0);
|
||||
@ -583,9 +571,9 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
if (w < 0)
|
||||
w = device->ScreenWidth();
|
||||
w = device.ScreenWidth();
|
||||
if (h < 0)
|
||||
h = device->ScreenHeight();
|
||||
h = device.ScreenHeight();
|
||||
|
||||
// During the main rendering pass the first buffer is allocated to the render target
|
||||
// and cannot be allocated for pre/postprocessing pass
|
||||
@ -610,27 +598,27 @@ namespace spades {
|
||||
// no buffer is free!
|
||||
IGLDevice::Enum ifmt = iFormat;
|
||||
|
||||
IGLDevice::UInteger tex = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture2D, tex);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, ifmt, w, h, 0, IGLDevice::Red,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
IGLDevice::UInteger tex = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, tex);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, ifmt, w, h, 0, IGLDevice::Red,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
SPLog("Texture allocated.");
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
IGLDevice::UInteger fb = device->GenFramebuffer();
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, fb);
|
||||
device->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, tex, 0);
|
||||
IGLDevice::UInteger fb = device.GenFramebuffer();
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, fb);
|
||||
device.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, tex, 0);
|
||||
SPLog("Framebuffer created.");
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
|
||||
Buffer buf;
|
||||
buf.framebuffer = fb;
|
||||
@ -710,5 +698,5 @@ namespace spades {
|
||||
Buffer &b = manager->buffers[bufferIndex];
|
||||
return b.internalFormat;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -54,7 +54,7 @@ namespace spades {
|
||||
};
|
||||
|
||||
private:
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLSettings &settings;
|
||||
|
||||
struct Buffer {
|
||||
@ -93,7 +93,7 @@ namespace spades {
|
||||
std::vector<Buffer> buffers;
|
||||
|
||||
public:
|
||||
GLFramebufferManager(IGLDevice *, GLSettings &);
|
||||
GLFramebufferManager(IGLDevice &, GLSettings &);
|
||||
~GLFramebufferManager();
|
||||
|
||||
/** setups device for scene rendering. */
|
||||
|
@ -78,6 +78,10 @@ namespace spades {
|
||||
IGLDevice::RGBA, IGLDevice::UnsignedByte, bmp->GetPixels());
|
||||
}
|
||||
|
||||
// TODO: Make sure this method is called even for `GLImage`s created via
|
||||
// `GLRenderer::CreateImage`. Otherwise, `GLImage` outliving the
|
||||
// originating `GLRenderer` will cause a use-after-free in its
|
||||
// destructor.
|
||||
void GLImage::Invalidate() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
MakeSureValid();
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
GLImageManager::GLImageManager(IGLDevice *dev) : device(dev), whiteImage(nullptr) {
|
||||
GLImageManager::GLImageManager(IGLDevice &dev) : device(dev), whiteImage(nullptr) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ namespace spades {
|
||||
|
||||
Handle<Bitmap> bmp(Bitmap::Load(name), false);
|
||||
|
||||
return GLImage::FromBitmap(*bmp, device).Unmanage();
|
||||
return GLImage::FromBitmap(*bmp, &device).Unmanage();
|
||||
}
|
||||
|
||||
// draw all imaegs so that all textures are resident
|
||||
|
@ -31,14 +31,14 @@ namespace spades {
|
||||
class GLRenderer;
|
||||
|
||||
class GLImageManager {
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
std::map<std::string, GLImage *> images;
|
||||
GLImage *whiteImage;
|
||||
|
||||
GLImage *CreateImage(const std::string &);
|
||||
|
||||
public:
|
||||
GLImageManager(IGLDevice *);
|
||||
GLImageManager(IGLDevice &);
|
||||
~GLImageManager();
|
||||
|
||||
GLImage *RegisterImage(const std::string &);
|
||||
|
@ -19,20 +19,19 @@
|
||||
*/
|
||||
|
||||
#include "GLImageRenderer.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
#include "GLImage.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
GLImageRenderer::GLImageRenderer(GLRenderer *r)
|
||||
: renderer(r),
|
||||
device(r->GetGLDevice()),
|
||||
invScreenWidthFactored(2.f / device->ScreenWidth()),
|
||||
invScreenHeightFactored(-2.f / device->ScreenHeight()) {
|
||||
invScreenWidthFactored(2.f / device.ScreenWidth()),
|
||||
invScreenHeightFactored(-2.f / device.ScreenHeight()) {
|
||||
|
||||
SPADES_MARK_FUNCTION();
|
||||
image = NULL;
|
||||
@ -79,33 +78,32 @@ namespace spades {
|
||||
|
||||
program->Use();
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
image->Bind(IGLDevice::Texture2D);
|
||||
|
||||
device->VertexAttribPointer((*positionAttribute)(), 2, IGLDevice::FloatType, false,
|
||||
sizeof(ImageVertex), vertices.data());
|
||||
device->VertexAttribPointer((*colorAttribute)(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(ImageVertex),
|
||||
(const char *)vertices.data() + sizeof(float) * 4);
|
||||
device->VertexAttribPointer((*textureCoordAttribute)(), 2, IGLDevice::FloatType, false,
|
||||
sizeof(ImageVertex),
|
||||
(const char *)vertices.data() + sizeof(float) * 2);
|
||||
device.VertexAttribPointer((*positionAttribute)(), 2, IGLDevice::FloatType, false,
|
||||
sizeof(ImageVertex), vertices.data());
|
||||
device.VertexAttribPointer((*colorAttribute)(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(ImageVertex),
|
||||
(const char *)vertices.data() + sizeof(float) * 4);
|
||||
device.VertexAttribPointer((*textureCoordAttribute)(), 2, IGLDevice::FloatType, false,
|
||||
sizeof(ImageVertex),
|
||||
(const char *)vertices.data() + sizeof(float) * 2);
|
||||
|
||||
device->EnableVertexAttribArray((*positionAttribute)(), true);
|
||||
device->EnableVertexAttribArray((*colorAttribute)(), true);
|
||||
device->EnableVertexAttribArray((*textureCoordAttribute)(), true);
|
||||
device.EnableVertexAttribArray((*positionAttribute)(), true);
|
||||
device.EnableVertexAttribArray((*colorAttribute)(), true);
|
||||
device.EnableVertexAttribArray((*textureCoordAttribute)(), true);
|
||||
|
||||
screenSize->SetValue(invScreenWidthFactored, invScreenHeightFactored);
|
||||
textureSize->SetValue(image->GetInvWidth(), image->GetInvHeight());
|
||||
texture->SetValue(0);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedInt, indices.data());
|
||||
device.DrawElements(IGLDevice::Triangles, static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedInt, indices.data());
|
||||
|
||||
device->EnableVertexAttribArray((*positionAttribute)(), false);
|
||||
device->EnableVertexAttribArray((*colorAttribute)(), false);
|
||||
device->EnableVertexAttribArray((*textureCoordAttribute)(), false);
|
||||
device.EnableVertexAttribArray((*positionAttribute)(), false);
|
||||
device.EnableVertexAttribArray((*colorAttribute)(), false);
|
||||
device.EnableVertexAttribArray((*textureCoordAttribute)(), false);
|
||||
|
||||
vertices.clear();
|
||||
indices.clear();
|
||||
@ -164,5 +162,5 @@ namespace spades {
|
||||
indices.push_back(idx + 2);
|
||||
indices.push_back(idx + 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -33,7 +33,7 @@ namespace spades {
|
||||
class GLRenderer;
|
||||
class GLImageRenderer {
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLImage *image;
|
||||
|
||||
float invScreenWidthFactored;
|
||||
@ -70,4 +70,4 @@ namespace spades {
|
||||
float sx4, float sy4, float r, float g, float b, float a);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include "GLImage.h"
|
||||
#include "GLLensDustFilter.h"
|
||||
#include "GLProgram.h"
|
||||
@ -30,6 +28,8 @@
|
||||
#include "GLQuadRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include <Core/Settings.h>
|
||||
|
||||
namespace spades {
|
||||
@ -40,27 +40,25 @@ namespace spades {
|
||||
dust = renderer->RegisterProgram("Shaders/PostFilters/LensDust.program");
|
||||
dustImg = renderer->RegisterImage("Textures/LensDustTexture.jpg").Cast<GLImage>();
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
noiseTex = dev->GenTexture();
|
||||
dev->BindTexture(IGLDevice::Texture2D, noiseTex);
|
||||
dev->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, 128, 128, 0, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
noiseTex = dev.GenTexture();
|
||||
dev.BindTexture(IGLDevice::Texture2D, noiseTex);
|
||||
dev.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, 128, 128, 0, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter, IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter, IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
}
|
||||
|
||||
GLLensDustFilter::~GLLensDustFilter() { renderer->GetGLDevice()->DeleteTexture(noiseTex); }
|
||||
GLLensDustFilter::~GLLensDustFilter() { renderer->GetGLDevice().DeleteTexture(noiseTex); }
|
||||
|
||||
#define Level GLLensDustFilterLevel
|
||||
|
||||
GLColorBuffer GLLensDustFilter::DownSample(GLColorBuffer tex, bool linearize) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
GLProgram *program = thru;
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
int w = tex.GetWidth();
|
||||
int h = tex.GetHeight();
|
||||
@ -75,8 +73,8 @@ namespace spades {
|
||||
|
||||
blur_textureUniform(program);
|
||||
blur_textureUniform.SetValue(0);
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
|
||||
blur_texCoordOffsetUniform(program);
|
||||
blur_texCoordOffsetUniform.SetValue(1.f / w, 1.f / h, -1.f / w, -1.f / h);
|
||||
@ -90,16 +88,16 @@ namespace spades {
|
||||
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
if (linearize) {
|
||||
dev->Enable(IGLDevice::Blend, true);
|
||||
dev->BlendFunc(IGLDevice::SrcColor, IGLDevice::Zero);
|
||||
dev.Enable(IGLDevice::Blend, true);
|
||||
dev.BlendFunc(IGLDevice::SrcColor, IGLDevice::Zero);
|
||||
} else {
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
}
|
||||
|
||||
GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(
|
||||
(w + 1) / 2, (h + 1) / 2, false);
|
||||
dev->Viewport(0, 0, buf2.GetWidth(), buf2.GetHeight());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev.Viewport(0, 0, buf2.GetWidth(), buf2.GetHeight());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
qr.Draw();
|
||||
return buf2;
|
||||
}
|
||||
@ -107,7 +105,7 @@ namespace spades {
|
||||
GLColorBuffer GLLensDustFilter::GaussianBlur(GLColorBuffer tex, bool vertical) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
GLProgram *program = gauss1d;
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
int w = tex.GetWidth();
|
||||
int h = tex.GetHeight();
|
||||
@ -120,18 +118,18 @@ namespace spades {
|
||||
|
||||
blur_textureUniform(program);
|
||||
blur_textureUniform.SetValue(0);
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
|
||||
blur_unitShift(program);
|
||||
blur_unitShift.SetValue(vertical ? 0.f : 1.f / w, vertical ? 1.f / h : 0.f);
|
||||
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false);
|
||||
dev->Viewport(0, 0, buf2.GetWidth(), buf2.GetHeight());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev.Viewport(0, 0, buf2.GetWidth(), buf2.GetHeight());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
qr.Draw();
|
||||
return buf2;
|
||||
}
|
||||
@ -144,10 +142,10 @@ namespace spades {
|
||||
noise[i] = static_cast<std::uint32_t>(SampleRandom());
|
||||
}
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
dev->BindTexture(IGLDevice::Texture2D, noiseTex);
|
||||
dev->TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 128, 128, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, noise.data());
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
dev.BindTexture(IGLDevice::Texture2D, noiseTex);
|
||||
dev.TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, 128, 128, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, noise.data());
|
||||
}
|
||||
|
||||
struct Level {
|
||||
@ -163,7 +161,7 @@ namespace spades {
|
||||
|
||||
std::vector<Level> levels;
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
GLSettings &settings = renderer->GetSettings();
|
||||
@ -185,7 +183,7 @@ namespace spades {
|
||||
thru->Use();
|
||||
thruColor.SetValue(1.f, 1.f, 1.f, 1.f);
|
||||
thruTexture.SetValue(0);
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
levels.reserve(10);
|
||||
|
||||
@ -215,8 +213,8 @@ namespace spades {
|
||||
levels.push_back(lv);
|
||||
}
|
||||
|
||||
dev->Enable(IGLDevice::Blend, true);
|
||||
dev->BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
dev.Enable(IGLDevice::Blend, true);
|
||||
dev.BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
|
||||
// composite levels in the opposite direction
|
||||
thru->Use();
|
||||
@ -237,24 +235,24 @@ namespace spades {
|
||||
targLevel.GetWidth(), targLevel.GetHeight(), false);
|
||||
levels[i - 1].retBuf[j] = targRet;
|
||||
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, targRet.GetFramebuffer());
|
||||
dev->Viewport(0, 0, targRet.GetWidth(), targRet.GetHeight());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, targRet.GetFramebuffer());
|
||||
dev.Viewport(0, 0, targRet.GetWidth(), targRet.GetHeight());
|
||||
|
||||
dev->BindTexture(IGLDevice::Texture2D, targLevel.GetTexture());
|
||||
dev.BindTexture(IGLDevice::Texture2D, targLevel.GetTexture());
|
||||
thruColor.SetValue(1.f, 1.f, 1.f, 1.f);
|
||||
thruTexCoordRange.SetValue(0.f, 0.f, 1.f, 1.f);
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
qr.Draw();
|
||||
|
||||
float cx = 0.f, cy = 0.f;
|
||||
|
||||
dev->BindTexture(IGLDevice::Texture2D, curLevel.GetTexture());
|
||||
dev.BindTexture(IGLDevice::Texture2D, curLevel.GetTexture());
|
||||
thruColor.SetValue(1.f, 1.f, 1.f, alpha);
|
||||
thruTexCoordRange.SetValue(cx, cy, 1.f, 1.f);
|
||||
dev->Enable(IGLDevice::Blend, true);
|
||||
dev.Enable(IGLDevice::Blend, true);
|
||||
qr.Draw();
|
||||
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,26 +281,26 @@ namespace spades {
|
||||
GLColorBuffer topLevel1 = levels[0].retBuf[0];
|
||||
|
||||
qr.SetCoordAttributeIndex(dustPosition());
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D, topLevel1.GetTexture());
|
||||
dev->ActiveTexture(5);
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D, topLevel1.GetTexture());
|
||||
dev.ActiveTexture(5);
|
||||
dustImg->Bind(IGLDevice::Texture2D);
|
||||
dev->ActiveTexture(6);
|
||||
dev->BindTexture(IGLDevice::Texture2D, noiseTex);
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
dev.ActiveTexture(6);
|
||||
dev.BindTexture(IGLDevice::Texture2D, noiseTex);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev.Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
dustBlurTexture1.SetValue(1);
|
||||
dustDustTexture.SetValue(5);
|
||||
dustNoiseTexture.SetValue(6);
|
||||
dustInputTexture.SetValue(0);
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
dev->ActiveTexture(0);
|
||||
dev.ActiveTexture(0);
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -38,14 +38,14 @@ namespace spades {
|
||||
GLColorBuffer GLLensFilter::Filter(GLColorBuffer input) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
static GLProgramAttribute lensPosition("positionAttribute");
|
||||
static GLProgramUniform lensTexture("mainTexture");
|
||||
static GLProgramUniform lensFov("fov");
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
lensPosition(lens);
|
||||
lensTexture(lens);
|
||||
@ -61,11 +61,11 @@ namespace spades {
|
||||
GLColorBuffer output = input.GetManager()->CreateBufferHandle();
|
||||
|
||||
qr.SetCoordAttributeIndex(lensPosition());
|
||||
dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
dev.BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev.Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
#include "GLImage.h"
|
||||
#include "GLLensFlareFilter.h"
|
||||
#include "GLMapShadowRenderer.h"
|
||||
@ -32,6 +30,8 @@
|
||||
#include "GLQuadRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Math.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -52,7 +52,7 @@ namespace spades {
|
||||
GLColorBuffer GLLensFlareFilter::Blur(GLColorBuffer buffer, float spread) {
|
||||
// do gaussian blur
|
||||
GLProgram *program = blurProgram;
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
int w = buffer.GetWidth();
|
||||
int h = buffer.GetHeight();
|
||||
@ -66,22 +66,22 @@ namespace spades {
|
||||
blur_unitShift(program);
|
||||
blur_textureUniform.SetValue(0);
|
||||
|
||||
dev->ActiveTexture(0);
|
||||
dev.ActiveTexture(0);
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
// x-direction
|
||||
GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false);
|
||||
dev->BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev.BindTexture(IGLDevice::Texture2D, buffer.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
blur_unitShift.SetValue(spread / (float)w, 0.f);
|
||||
qr.Draw();
|
||||
buffer.Release();
|
||||
|
||||
// y-direction
|
||||
GLColorBuffer buf3 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, false);
|
||||
dev->BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
|
||||
dev.BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
|
||||
blur_unitShift.SetValue(0.f, spread / (float)h);
|
||||
qr.Draw();
|
||||
buf2.Release();
|
||||
@ -97,7 +97,7 @@ namespace spades {
|
||||
bool infinityDistance) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
|
||||
client::SceneDefinition def = renderer->GetSceneDef();
|
||||
|
||||
@ -110,7 +110,7 @@ namespace spades {
|
||||
return;
|
||||
}
|
||||
|
||||
IGLDevice::UInteger lastFramebuffer = dev->GetInteger(IGLDevice::FramebufferBinding);
|
||||
IGLDevice::UInteger lastFramebuffer = dev.GetInteger(IGLDevice::FramebufferBinding);
|
||||
|
||||
Vector2 fov = {tanf(def.fovX * .5f), tanf(def.fovY * .5f)};
|
||||
Vector2 sunScreen;
|
||||
@ -153,20 +153,20 @@ namespace spades {
|
||||
scanZ.SetValue(far * (near - depth) / (depth * (near - far)));
|
||||
}
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
depthTexture.SetValue(0);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureCompareMode,
|
||||
IGLDevice::CompareRefToTexture);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureCompareFunc,
|
||||
IGLDevice::Less);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureCompareMode,
|
||||
IGLDevice::CompareRefToTexture);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureCompareFunc,
|
||||
IGLDevice::Less);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
|
||||
Vector2 sunTexPos = sunScreen * .5f + .5f;
|
||||
Vector2 sunTexSize = sunSize * .5f;
|
||||
@ -177,20 +177,20 @@ namespace spades {
|
||||
radius.SetValue(32.f);
|
||||
|
||||
qr.SetCoordAttributeIndex(positionAttribute());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, visiblityBuffer.GetFramebuffer());
|
||||
dev->Viewport(0, 0, 64, 64);
|
||||
dev->ClearColor(0, 0, 0, 1);
|
||||
dev->Clear(IGLDevice::ColorBufferBit);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, visiblityBuffer.GetFramebuffer());
|
||||
dev.Viewport(0, 0, 64, 64);
|
||||
dev.ClearColor(0, 0, 0, 1);
|
||||
dev.Clear(IGLDevice::ColorBufferBit);
|
||||
qr.Draw();
|
||||
|
||||
// restore depth texture's compare mode
|
||||
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureCompareMode,
|
||||
IGLDevice::None);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureCompareMode,
|
||||
IGLDevice::None);
|
||||
}
|
||||
|
||||
visiblityBuffer = Blur(visiblityBuffer, 1.f);
|
||||
@ -204,7 +204,7 @@ namespace spades {
|
||||
float aroundness = sunScreen.GetPoweredLength() * 0.6f;
|
||||
float aroundness2 = std::min(sunScreen.GetPoweredLength() * 3.2f, 1.f);
|
||||
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, lastFramebuffer);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, lastFramebuffer);
|
||||
|
||||
{
|
||||
GLProfiler::Context measure(renderer->GetGLProfiler(), "Draw");
|
||||
@ -226,27 +226,27 @@ namespace spades {
|
||||
flareTexture(draw);
|
||||
color(draw);
|
||||
|
||||
dev->Enable(IGLDevice::Blend, true);
|
||||
dev->BlendFunc(IGLDevice::One, IGLDevice::One);
|
||||
dev.Enable(IGLDevice::Blend, true);
|
||||
dev.BlendFunc(IGLDevice::One, IGLDevice::One);
|
||||
|
||||
dev->ActiveTexture(2);
|
||||
dev.ActiveTexture(2);
|
||||
white->Bind(IGLDevice::Texture2D);
|
||||
flareTexture.SetValue(2);
|
||||
|
||||
dev->ActiveTexture(1);
|
||||
dev.ActiveTexture(1);
|
||||
white->Bind(IGLDevice::Texture2D);
|
||||
modulationTexture.SetValue(1);
|
||||
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, visiblityBuffer.GetTexture());
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, visiblityBuffer.GetTexture());
|
||||
visibilityTexture.SetValue(0);
|
||||
|
||||
qr.SetCoordAttributeIndex(positionAttribute());
|
||||
dev->Viewport(0, 0, dev->ScreenWidth(), dev->ScreenHeight());
|
||||
dev.Viewport(0, 0, dev.ScreenWidth(), dev.ScreenHeight());
|
||||
|
||||
/* render flare */
|
||||
|
||||
dev->ActiveTexture(2);
|
||||
dev.ActiveTexture(2);
|
||||
flare4->Bind(IGLDevice::Texture2D);
|
||||
|
||||
color.SetValue(sunColor.x * .04f, sunColor.y * .03f, sunColor.z * .04f);
|
||||
@ -255,7 +255,7 @@ namespace spades {
|
||||
sunScreen.y + sunSize.y * 256.f);
|
||||
qr.Draw();
|
||||
|
||||
dev->ActiveTexture(2);
|
||||
dev.ActiveTexture(2);
|
||||
white->Bind(IGLDevice::Texture2D);
|
||||
|
||||
color.SetValue(sunColor.x * .3f, sunColor.y * .3f, sunColor.z * .3f);
|
||||
@ -287,7 +287,7 @@ namespace spades {
|
||||
|
||||
/* render dusts */
|
||||
|
||||
dev->ActiveTexture(1);
|
||||
dev.ActiveTexture(1);
|
||||
mask3->Bind(IGLDevice::Texture2D);
|
||||
|
||||
color.SetValue(sunColor.x * .4f * aroundness, sunColor.y * .4f * aroundness,
|
||||
@ -299,9 +299,9 @@ namespace spades {
|
||||
|
||||
if (renderReflections) {
|
||||
|
||||
dev->ActiveTexture(1);
|
||||
dev.ActiveTexture(1);
|
||||
white->Bind(IGLDevice::Texture2D);
|
||||
dev->ActiveTexture(2);
|
||||
dev.ActiveTexture(2);
|
||||
flare2->Bind(IGLDevice::Texture2D);
|
||||
|
||||
color.SetValue(sunColor.x * 1.f, sunColor.y * 1.f, sunColor.z * 1.f);
|
||||
@ -336,9 +336,9 @@ namespace spades {
|
||||
|
||||
qr.Draw();
|
||||
|
||||
dev->ActiveTexture(1);
|
||||
dev.ActiveTexture(1);
|
||||
mask2->Bind(IGLDevice::Texture2D);
|
||||
dev->ActiveTexture(2);
|
||||
dev.ActiveTexture(2);
|
||||
flare1->Bind(IGLDevice::Texture2D);
|
||||
|
||||
color.SetValue(sunColor.x * .5f, sunColor.y * .4f, sunColor.z * .3f);
|
||||
@ -357,7 +357,7 @@ namespace spades {
|
||||
|
||||
qr.Draw();
|
||||
|
||||
dev->ActiveTexture(2);
|
||||
dev.ActiveTexture(2);
|
||||
flare3->Bind(IGLDevice::Texture2D);
|
||||
|
||||
color.SetValue(sunColor.x * .3f, sunColor.y * .3f, sunColor.z * .3f);
|
||||
@ -368,9 +368,9 @@ namespace spades {
|
||||
|
||||
qr.Draw();
|
||||
|
||||
dev->ActiveTexture(1);
|
||||
dev.ActiveTexture(1);
|
||||
mask1->Bind(IGLDevice::Texture2D);
|
||||
dev->ActiveTexture(2);
|
||||
dev.ActiveTexture(2);
|
||||
flare3->Bind(IGLDevice::Texture2D);
|
||||
|
||||
color.SetValue(sunColor.x * .8f * aroundness2, sunColor.y * .5f * aroundness2,
|
||||
@ -385,10 +385,10 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
dev->ActiveTexture(0);
|
||||
dev.ActiveTexture(0);
|
||||
|
||||
// restore blend mode
|
||||
dev->BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
dev.BlendFunc(IGLDevice::SrcAlpha, IGLDevice::OneMinusSrcAlpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -19,12 +19,12 @@
|
||||
*/
|
||||
|
||||
#include "GLLongSpriteRenderer.h"
|
||||
#include <Core/Debug.h>
|
||||
#include "GLImage.h"
|
||||
#include "GLProgram.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include "SWFeatureLevel.h"
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Settings.h>
|
||||
|
||||
namespace spades {
|
||||
@ -118,11 +118,11 @@ namespace spades {
|
||||
upVector.SetValue(def.viewAxis[1].x, def.viewAxis[1].y, def.viewAxis[1].z);
|
||||
texture.SetValue(0);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device->EnableVertexAttribArray(texCoordAttribute(), true);
|
||||
device->EnableVertexAttribArray(colorAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(texCoordAttribute(), true);
|
||||
device.EnableVertexAttribArray(colorAttribute(), true);
|
||||
|
||||
for (size_t i = 0; i < sprites.size(); i++) {
|
||||
Sprite &spr = sprites[i];
|
||||
@ -332,9 +332,9 @@ namespace spades {
|
||||
|
||||
Flush();
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->EnableVertexAttribArray(texCoordAttribute(), false);
|
||||
device->EnableVertexAttribArray(colorAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(texCoordAttribute(), false);
|
||||
device.EnableVertexAttribArray(colorAttribute(), false);
|
||||
}
|
||||
|
||||
void GLLongSpriteRenderer::Flush() {
|
||||
@ -343,22 +343,21 @@ namespace spades {
|
||||
if (vertices.empty())
|
||||
return;
|
||||
|
||||
device->VertexAttribPointer(positionAttribute(), 3, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].x));
|
||||
device->VertexAttribPointer(texCoordAttribute(), 2, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].u));
|
||||
device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].r));
|
||||
device.VertexAttribPointer(positionAttribute(), 3, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].x));
|
||||
device.VertexAttribPointer(texCoordAttribute(), 2, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].u));
|
||||
device.VertexAttribPointer(colorAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].r));
|
||||
|
||||
SPAssert(lastImage);
|
||||
lastImage->Bind(IGLDevice::Texture2D);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedInt, indices.data());
|
||||
device.DrawElements(IGLDevice::Triangles, static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedInt, indices.data());
|
||||
|
||||
vertices.clear();
|
||||
indices.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -57,7 +57,7 @@ namespace spades {
|
||||
};
|
||||
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLSettings &settings;
|
||||
std::vector<Sprite> sprites;
|
||||
|
||||
|
@ -21,9 +21,6 @@
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
|
||||
#include <Client/GameMap.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Settings.h>
|
||||
#include "GLDynamicLightShader.h"
|
||||
#include "GLMapChunk.h"
|
||||
#include "GLMapRenderer.h"
|
||||
@ -32,15 +29,18 @@
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <AngelScript/include/angelscript.h> // for asOFFSET. somehow `offsetof` fails on gcc-4.8
|
||||
#include <Client/GameMap.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Settings.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
GLMapChunk::GLMapChunk(spades::draw::GLMapRenderer *r, client::GameMap *mp, int cx, int cy,
|
||||
int cz) {
|
||||
int cz)
|
||||
: device(r->device) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
renderer = r;
|
||||
device = r->device;
|
||||
map = mp;
|
||||
chunkX = cx;
|
||||
chunkY = cy;
|
||||
@ -67,11 +67,11 @@ namespace spades {
|
||||
|
||||
if (!b) {
|
||||
if (buffer) {
|
||||
device->DeleteBuffer(buffer);
|
||||
device.DeleteBuffer(buffer);
|
||||
buffer = 0;
|
||||
}
|
||||
if (iBuffer) {
|
||||
device->DeleteBuffer(iBuffer);
|
||||
device.DeleteBuffer(iBuffer);
|
||||
iBuffer = 0;
|
||||
}
|
||||
std::vector<Vertex> i;
|
||||
@ -218,11 +218,11 @@ namespace spades {
|
||||
vertices.clear();
|
||||
indices.clear();
|
||||
if (buffer) {
|
||||
device->DeleteBuffer(buffer);
|
||||
device.DeleteBuffer(buffer);
|
||||
buffer = 0;
|
||||
}
|
||||
if (iBuffer) {
|
||||
device->DeleteBuffer(iBuffer);
|
||||
device.DeleteBuffer(iBuffer);
|
||||
iBuffer = 0;
|
||||
}
|
||||
|
||||
@ -277,22 +277,22 @@ namespace spades {
|
||||
if (vertices.size() == 0)
|
||||
return;
|
||||
|
||||
buffer = device->GenBuffer();
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
buffer = device.GenBuffer();
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
|
||||
device->BufferData(IGLDevice::ArrayBuffer,
|
||||
device.BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(vertices.size() * sizeof(Vertex)),
|
||||
vertices.data(), IGLDevice::DynamicDraw);
|
||||
|
||||
if (!indices.empty()) {
|
||||
iBuffer = device->GenBuffer();
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, iBuffer);
|
||||
iBuffer = device.GenBuffer();
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, iBuffer);
|
||||
|
||||
device->BufferData(IGLDevice::ArrayBuffer,
|
||||
device.BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(indices.size() * sizeof(uint16_t)),
|
||||
indices.data(), IGLDevice::DynamicDraw);
|
||||
}
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
}
|
||||
|
||||
void GLMapChunk::RenderDepthPass() {
|
||||
@ -343,16 +343,16 @@ namespace spades {
|
||||
|
||||
positionAttribute(depthonlyProgram);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 3, IGLDevice::UnsignedByte, false,
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 3, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)asOFFSET(Vertex, x));
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, iBuffer);
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, iBuffer);
|
||||
device.DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedShort, NULL);
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
}
|
||||
void GLMapChunk::RenderSunlightPass() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
@ -411,28 +411,28 @@ namespace spades {
|
||||
normalAttribute(basicProgram);
|
||||
fixedPositionAttribute(basicProgram);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 3, IGLDevice::UnsignedByte, false,
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 3, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)asOFFSET(Vertex, x));
|
||||
if (ambientOcclusionCoordAttribute() != -1)
|
||||
device->VertexAttribPointer(ambientOcclusionCoordAttribute(), 2,
|
||||
device.VertexAttribPointer(ambientOcclusionCoordAttribute(), 2,
|
||||
IGLDevice::UnsignedShort, false, sizeof(Vertex),
|
||||
(void *)asOFFSET(Vertex, aoX));
|
||||
device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::UnsignedByte, true,
|
||||
device.VertexAttribPointer(colorAttribute(), 4, IGLDevice::UnsignedByte, true,
|
||||
sizeof(Vertex), (void *)asOFFSET(Vertex, colorRed));
|
||||
if (normalAttribute() != -1)
|
||||
device->VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
device.VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)asOFFSET(Vertex, nx));
|
||||
|
||||
device->VertexAttribPointer(fixedPositionAttribute(), 3, IGLDevice::Byte, false,
|
||||
device.VertexAttribPointer(fixedPositionAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)asOFFSET(Vertex, sx));
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, iBuffer);
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, iBuffer);
|
||||
device.DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedShort, NULL);
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
}
|
||||
|
||||
void GLMapChunk::RenderDLightPass(std::vector<GLDynamicLight> lights) {
|
||||
@ -487,16 +487,16 @@ namespace spades {
|
||||
colorAttribute(program);
|
||||
normalAttribute(program);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 3, IGLDevice::UnsignedByte, false,
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 3, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)asOFFSET(Vertex, x));
|
||||
device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::UnsignedByte, true,
|
||||
device.VertexAttribPointer(colorAttribute(), 4, IGLDevice::UnsignedByte, true,
|
||||
sizeof(Vertex), (void *)asOFFSET(Vertex, colorRed));
|
||||
device->VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
device.VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)asOFFSET(Vertex, nx));
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, iBuffer);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, iBuffer);
|
||||
for (size_t i = 0; i < lights.size(); i++) {
|
||||
|
||||
static GLDynamicLightShader lightShader;
|
||||
@ -505,12 +505,12 @@ namespace spades {
|
||||
if (!lights[i].Cull(bx))
|
||||
continue;
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
device.DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedShort, NULL);
|
||||
}
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
}
|
||||
|
||||
float GLMapChunk::DistanceFromEye(const Vector3 &eye) {
|
||||
@ -534,5 +534,5 @@ namespace spades {
|
||||
// return std::max(diff.GetLength() - radius, 0.f);
|
||||
return std::max(dist - ((float)Size * .5f), 0.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -52,7 +52,7 @@ namespace spades {
|
||||
};
|
||||
|
||||
GLMapRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
client::GameMap *map;
|
||||
int chunkX, chunkY, chunkZ;
|
||||
AABB3 aabb;
|
||||
|
@ -19,21 +19,20 @@
|
||||
*/
|
||||
|
||||
#include "GLMapRenderer.h"
|
||||
#include <Client/GameMap.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Settings.h>
|
||||
#include "GLDynamicLightShader.h"
|
||||
#include "GLImage.h"
|
||||
#include "GLMapChunk.h"
|
||||
#include "GLMapShadowRenderer.h"
|
||||
#include "GLProfiler.h"
|
||||
#include "GLProgram.h"
|
||||
#include "GLProgram.h"
|
||||
#include "GLProgramAttribute.h"
|
||||
#include "GLProgramUniform.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "GLShadowShader.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Client/GameMap.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Settings.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -48,11 +47,10 @@ namespace spades {
|
||||
renderer->RegisterImage("Gfx/AmbientOcclusion.png");
|
||||
}
|
||||
|
||||
GLMapRenderer::GLMapRenderer(client::GameMap *m, GLRenderer *r) : renderer(r), gameMap(m) {
|
||||
GLMapRenderer::GLMapRenderer(client::GameMap *m, GLRenderer *r)
|
||||
: renderer(r), device(r->GetGLDevice()), gameMap(m) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device = renderer->GetGLDevice();
|
||||
|
||||
numChunkWidth = gameMap->Width() / GLMapChunk::Size;
|
||||
numChunkHeight = gameMap->Height() / GLMapChunk::Size;
|
||||
numChunkDepth = gameMap->Depth() / GLMapChunk::Size;
|
||||
@ -76,17 +74,17 @@ namespace spades {
|
||||
aoImage = renderer->RegisterImage("Gfx/AmbientOcclusion.png").Cast<GLImage>();
|
||||
|
||||
static const uint8_t squareVertices[] = {0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1};
|
||||
squareVertexBuffer = device->GenBuffer();
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, squareVertexBuffer);
|
||||
device->BufferData(IGLDevice::ArrayBuffer, sizeof(squareVertices), squareVertices,
|
||||
IGLDevice::StaticDraw);
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
squareVertexBuffer = device.GenBuffer();
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, squareVertexBuffer);
|
||||
device.BufferData(IGLDevice::ArrayBuffer, sizeof(squareVertices), squareVertices,
|
||||
IGLDevice::StaticDraw);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
}
|
||||
|
||||
GLMapRenderer::~GLMapRenderer() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device->DeleteBuffer(squareVertexBuffer);
|
||||
device.DeleteBuffer(squareVertexBuffer);
|
||||
for (int i = 0; i < numChunks; i++)
|
||||
delete chunks[i];
|
||||
delete[] chunks;
|
||||
@ -147,19 +145,19 @@ namespace spades {
|
||||
|
||||
void GLMapRenderer::Prerender() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
//depth-only pass
|
||||
// depth-only pass
|
||||
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Map");
|
||||
Vector3 eye = renderer->GetSceneDef().viewOrigin;
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device->ColorMask(false, false, false, false);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
device.ColorMask(false, false, false, false);
|
||||
|
||||
depthonlyProgram->Use();
|
||||
static GLProgramAttribute positionAttribute("positionAttribute");
|
||||
positionAttribute(depthonlyProgram);
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
static GLProgramUniform projectionViewMatrix("projectionViewMatrix");
|
||||
projectionViewMatrix(depthonlyProgram);
|
||||
projectionViewMatrix.SetValue(renderer->GetProjectionViewMatrix());
|
||||
@ -180,10 +178,8 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->ColorMask(true, true, true, true);
|
||||
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.ColorMask(true, true, true, true);
|
||||
}
|
||||
|
||||
void GLMapRenderer::RenderSunlightPass() {
|
||||
@ -198,16 +194,16 @@ namespace spades {
|
||||
// covering themselves by ones.
|
||||
RenderBackface();
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
aoImage->Bind(IGLDevice::Texture2D);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(1);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
|
||||
basicProgram->Use();
|
||||
|
||||
@ -237,7 +233,7 @@ namespace spades {
|
||||
detailTextureUnif(basicProgram);
|
||||
detailTextureUnif.SetValue(1);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
static GLProgramAttribute positionAttribute("positionAttribute");
|
||||
static GLProgramAttribute ambientOcclusionCoordAttribute(
|
||||
@ -252,13 +248,13 @@ namespace spades {
|
||||
normalAttribute(basicProgram);
|
||||
fixedPositionAttribute(basicProgram);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
if (ambientOcclusionCoordAttribute() != -1)
|
||||
device->EnableVertexAttribArray(ambientOcclusionCoordAttribute(), true);
|
||||
device->EnableVertexAttribArray(colorAttribute(), true);
|
||||
device.EnableVertexAttribArray(ambientOcclusionCoordAttribute(), true);
|
||||
device.EnableVertexAttribArray(colorAttribute(), true);
|
||||
if (normalAttribute() != -1)
|
||||
device->EnableVertexAttribArray(normalAttribute(), true);
|
||||
device->EnableVertexAttribArray(fixedPositionAttribute(), true);
|
||||
device.EnableVertexAttribArray(normalAttribute(), true);
|
||||
device.EnableVertexAttribArray(fixedPositionAttribute(), true);
|
||||
|
||||
static GLProgramUniform projectionViewMatrix("projectionViewMatrix");
|
||||
projectionViewMatrix(basicProgram);
|
||||
@ -273,8 +269,9 @@ namespace spades {
|
||||
const auto &viewOrigin = renderer->GetSceneDef().viewOrigin;
|
||||
viewOriginVector.SetValue(viewOrigin.x, viewOrigin.y, viewOrigin.z);
|
||||
|
||||
//RealizeChunks(eye); // should already be realized from the prepass
|
||||
//TODO maybe add some way of checking if the chunks have been realized for the current eye? Probably just a bool called "alreadyrealized" that gets checked in RealizeChunks
|
||||
// RealizeChunks(eye); // should already be realized from the prepass
|
||||
// TODO maybe add some way of checking if the chunks have been realized for the current
|
||||
// eye? Probably just a bool called "alreadyrealized" that gets checked in RealizeChunks
|
||||
|
||||
// draw from nearest to farthest
|
||||
int cx = (int)floorf(eye.x) / GLMapChunk::Size;
|
||||
@ -292,18 +289,18 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
if (ambientOcclusionCoordAttribute() != -1)
|
||||
device->EnableVertexAttribArray(ambientOcclusionCoordAttribute(), false);
|
||||
device->EnableVertexAttribArray(colorAttribute(), false);
|
||||
device.EnableVertexAttribArray(ambientOcclusionCoordAttribute(), false);
|
||||
device.EnableVertexAttribArray(colorAttribute(), false);
|
||||
if (normalAttribute() != -1)
|
||||
device->EnableVertexAttribArray(normalAttribute(), false);
|
||||
device->EnableVertexAttribArray(fixedPositionAttribute(), false);
|
||||
device.EnableVertexAttribArray(normalAttribute(), false);
|
||||
device.EnableVertexAttribArray(fixedPositionAttribute(), false);
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(1);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
void GLMapRenderer::RenderDynamicLightPass(std::vector<GLDynamicLight> lights) {
|
||||
@ -316,11 +313,11 @@ namespace spades {
|
||||
|
||||
Vector3 eye = renderer->GetSceneDef().viewOrigin;
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
|
||||
dlightProgram->Use();
|
||||
|
||||
@ -332,7 +329,7 @@ namespace spades {
|
||||
detailTextureUnif(dlightProgram);
|
||||
detailTextureUnif.SetValue(0);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
static GLProgramAttribute positionAttribute("positionAttribute");
|
||||
static GLProgramAttribute colorAttribute("colorAttribute");
|
||||
@ -342,9 +339,9 @@ namespace spades {
|
||||
colorAttribute(dlightProgram);
|
||||
normalAttribute(dlightProgram);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device->EnableVertexAttribArray(colorAttribute(), true);
|
||||
device->EnableVertexAttribArray(normalAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(colorAttribute(), true);
|
||||
device.EnableVertexAttribArray(normalAttribute(), true);
|
||||
|
||||
static GLProgramUniform projectionViewMatrix("projectionViewMatrix");
|
||||
projectionViewMatrix(dlightProgram);
|
||||
@ -359,7 +356,7 @@ namespace spades {
|
||||
const auto &viewOrigin = renderer->GetSceneDef().viewOrigin;
|
||||
viewOriginVector.SetValue(viewOrigin.x, viewOrigin.y, viewOrigin.z);
|
||||
|
||||
//RealizeChunks(eye); // should already be realized from the prepass
|
||||
// RealizeChunks(eye); // should already be realized from the prepass
|
||||
|
||||
// draw from nearest to farthest
|
||||
int cx = (int)floorf(eye.x) / GLMapChunk::Size;
|
||||
@ -380,12 +377,12 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->EnableVertexAttribArray(colorAttribute(), false);
|
||||
device->EnableVertexAttribArray(normalAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(colorAttribute(), false);
|
||||
device.EnableVertexAttribArray(normalAttribute(), false);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
void GLMapRenderer::DrawColumnDepth(int cx, int cy, int cz, spades::Vector3 eye) {
|
||||
@ -491,7 +488,7 @@ namespace spades {
|
||||
if (vertices.empty())
|
||||
return;
|
||||
|
||||
device->Enable(IGLDevice::CullFace, false);
|
||||
device.Enable(IGLDevice::CullFace, false);
|
||||
|
||||
backfaceProgram->Use();
|
||||
|
||||
@ -503,20 +500,19 @@ namespace spades {
|
||||
|
||||
projectionViewMatrix.SetValue(renderer->GetProjectionViewMatrix());
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device->VertexAttribPointer(positionAttribute(), 3, IGLDevice::Short, false,
|
||||
sizeof(BFVertex), vertices.data());
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.VertexAttribPointer(positionAttribute(), 3, IGLDevice::Short, false,
|
||||
sizeof(BFVertex), vertices.data());
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedShort, indices.data());
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.DrawElements(IGLDevice::Triangles, static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedShort, indices.data());
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -38,7 +38,7 @@ namespace spades {
|
||||
|
||||
protected:
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
|
||||
GLProgram *depthonlyProgram;
|
||||
GLProgram *basicProgram;
|
||||
|
@ -19,40 +19,40 @@
|
||||
*/
|
||||
|
||||
#include "GLMapShadowRenderer.h"
|
||||
#include <Client/GameMap.h>
|
||||
#include <Core/Debug.h>
|
||||
#include "GLProfiler.h"
|
||||
#include "GLRadiosityRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Client/GameMap.h>
|
||||
#include <Core/Debug.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
GLMapShadowRenderer::GLMapShadowRenderer(GLRenderer *renderer, client::GameMap *map)
|
||||
: renderer(renderer), device(renderer->GetGLDevice()), map(map) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
texture = device->GenTexture();
|
||||
coarseTexture = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture2D, texture);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA, map->Width(),
|
||||
map->Height(), 0, IGLDevice::RGBA, IGLDevice::UnsignedByte, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
texture = device.GenTexture();
|
||||
coarseTexture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, texture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA, map->Width(), map->Height(),
|
||||
0, IGLDevice::RGBA, IGLDevice::UnsignedByte, NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
|
||||
device->BindTexture(IGLDevice::Texture2D, coarseTexture);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, map->Width() / CoarseSize,
|
||||
map->Height() / CoarseSize, 0, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
device.BindTexture(IGLDevice::Texture2D, coarseTexture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, map->Width() / CoarseSize,
|
||||
map->Height() / CoarseSize, 0, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
|
||||
w = map->Width();
|
||||
h = map->Height();
|
||||
@ -71,8 +71,8 @@ namespace spades {
|
||||
GLMapShadowRenderer::~GLMapShadowRenderer() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device->DeleteTexture(texture);
|
||||
device->DeleteTexture(coarseTexture);
|
||||
device.DeleteTexture(texture);
|
||||
device.DeleteTexture(coarseTexture);
|
||||
}
|
||||
|
||||
void GLMapShadowRenderer::Update() {
|
||||
@ -85,7 +85,7 @@ namespace spades {
|
||||
coarseUpdateBitmap.resize(coarseBitmap.size());
|
||||
std::fill(coarseUpdateBitmap.begin(), coarseUpdateBitmap.end(), 0);
|
||||
|
||||
device->BindTexture(IGLDevice::Texture2D, texture);
|
||||
device.BindTexture(IGLDevice::Texture2D, texture);
|
||||
for (size_t i = 0; i < updateBitmap.size(); i++) {
|
||||
int y = static_cast<int>(i / updateBitmapPitch);
|
||||
int x = static_cast<int>((i - y * updateBitmapPitch) * 32);
|
||||
@ -118,8 +118,8 @@ namespace spades {
|
||||
coarseUpdateBitmap[((x + j) >> CoarseBits) +
|
||||
(y >> CoarseBits) * (w >> CoarseBits)] = 1;
|
||||
|
||||
device->TexSubImage2D(IGLDevice::Texture2D, 0, x, y, 32, 1, IGLDevice::RGBA,
|
||||
IGLDevice::UnsignedByte, pixels);
|
||||
device.TexSubImage2D(IGLDevice::Texture2D, 0, x, y, 32, 1, IGLDevice::RGBA,
|
||||
IGLDevice::UnsignedByte, pixels);
|
||||
}
|
||||
|
||||
updateBitmap[i] = 0;
|
||||
@ -163,12 +163,13 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
if (coarseUpdated) {
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Coarse Shadow Map Upload");
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(),
|
||||
"Coarse Shadow Map Upload");
|
||||
|
||||
device->BindTexture(IGLDevice::Texture2D, coarseTexture);
|
||||
device->TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, w >> CoarseBits,
|
||||
h >> CoarseBits, IGLDevice::BGRA, IGLDevice::UnsignedByte,
|
||||
coarseBitmap.data());
|
||||
device.BindTexture(IGLDevice::Texture2D, coarseTexture);
|
||||
device.TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, w >> CoarseBits,
|
||||
h >> CoarseBits, IGLDevice::BGRA, IGLDevice::UnsignedByte,
|
||||
coarseBitmap.data());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -226,5 +227,5 @@ namespace spades {
|
||||
MarkUpdate(x, y - z);
|
||||
MarkUpdate(x, y - z - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -39,7 +39,7 @@ namespace spades {
|
||||
enum { CoarseSize = 8, CoarseBits = 3 };
|
||||
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
client::GameMap *map;
|
||||
IGLDevice::UInteger texture;
|
||||
IGLDevice::UInteger coarseTexture;
|
||||
@ -67,4 +67,4 @@ namespace spades {
|
||||
IGLDevice::UInteger GetCoarseTexture() { return coarseTexture; }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace spades {
|
||||
}
|
||||
|
||||
void GLModelRenderer::Prerender(bool ghostPass) {
|
||||
device->ColorMask(false, false, false, false);
|
||||
device.ColorMask(false, false, false, false);
|
||||
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Model [%d model(s), %d unique model type(s)]", modelCount,
|
||||
(int)models.size());
|
||||
@ -81,7 +81,7 @@ namespace spades {
|
||||
model->Prerender(m.params, ghostPass);
|
||||
numModels += (int)m.params.size();
|
||||
}
|
||||
device->ColorMask(true, true, true, true);
|
||||
device.ColorMask(true, true, true, true);
|
||||
}
|
||||
|
||||
void GLModelRenderer::RenderSunlightPass(bool ghostPass) {
|
||||
|
@ -36,7 +36,7 @@ namespace spades {
|
||||
friend class GLSparseShadowMapRenderer;
|
||||
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
|
||||
struct RenderModel {
|
||||
GLModel *model;
|
||||
@ -61,4 +61,4 @@ namespace spades {
|
||||
void Clear();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,14 +39,14 @@ namespace spades {
|
||||
GLColorBuffer GLNonlinearlizeFilter::Filter(GLColorBuffer input) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
static GLProgramAttribute lensPosition("positionAttribute");
|
||||
static GLProgramUniform lensTexture("mainTexture");
|
||||
static GLProgramUniform lensGamma("gamma");
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
lensPosition(lens);
|
||||
lensTexture(lens);
|
||||
@ -61,11 +61,11 @@ namespace spades {
|
||||
GLColorBuffer output = input.GetManager()->CreateBufferHandle();
|
||||
|
||||
qr.SetCoordAttributeIndex(lensPosition());
|
||||
dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
dev.BindTexture(IGLDevice::Texture2D, input.GetTexture());
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev.Viewport(0, 0, output.GetWidth(), output.GetHeight());
|
||||
qr.Draw();
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -20,10 +20,6 @@
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <Core/Bitmap.h>
|
||||
#include <Core/BitmapAtlasGenerator.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
#include "CellToTriangle.h"
|
||||
#include "GLDynamicLightShader.h"
|
||||
#include "GLImage.h"
|
||||
@ -35,6 +31,10 @@
|
||||
#include "GLShadowMapShader.h"
|
||||
#include "GLShadowShader.h"
|
||||
#include "IGLShadowMapRenderer.h"
|
||||
#include <Core/Bitmap.h>
|
||||
#include <Core/BitmapAtlasGenerator.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Exception.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -44,11 +44,11 @@ namespace spades {
|
||||
renderer->RegisterProgram("Shaders/OptimizedVoxelModelShadowMap.program");
|
||||
renderer->RegisterImage("Gfx/AmbientOcclusion.png");
|
||||
}
|
||||
GLOptimizedVoxelModel::GLOptimizedVoxelModel(VoxelModel *m, GLRenderer *r) {
|
||||
GLOptimizedVoxelModel::GLOptimizedVoxelModel(VoxelModel *m, GLRenderer *r)
|
||||
: device{r->GetGLDevice()} {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
renderer = r;
|
||||
device = r->GetGLDevice();
|
||||
|
||||
BuildVertices(m);
|
||||
GenerateTexture();
|
||||
@ -60,18 +60,18 @@ namespace spades {
|
||||
renderer->RegisterProgram("Shaders/OptimizedVoxelModelShadowMap.program");
|
||||
aoImage = renderer->RegisterImage("Gfx/AmbientOcclusion.png").Cast<GLImage>();
|
||||
|
||||
buffer = device->GenBuffer();
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(vertices.size() * sizeof(Vertex)),
|
||||
vertices.data(), IGLDevice::StaticDraw);
|
||||
buffer = device.GenBuffer();
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(vertices.size() * sizeof(Vertex)),
|
||||
vertices.data(), IGLDevice::StaticDraw);
|
||||
|
||||
idxBuffer = device->GenBuffer();
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, idxBuffer);
|
||||
device->BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(indices.size() * sizeof(uint32_t)),
|
||||
indices.data(), IGLDevice::StaticDraw);
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
idxBuffer = device.GenBuffer();
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, idxBuffer);
|
||||
device.BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(indices.size() * sizeof(uint32_t)),
|
||||
indices.data(), IGLDevice::StaticDraw);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
origin = m->GetOrigin();
|
||||
origin -= .5f; // (0,0,0) is center of voxel (0,0,0)
|
||||
@ -96,8 +96,8 @@ namespace spades {
|
||||
GLOptimizedVoxelModel::~GLOptimizedVoxelModel() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device->DeleteBuffer(idxBuffer);
|
||||
device->DeleteBuffer(buffer);
|
||||
device.DeleteBuffer(idxBuffer);
|
||||
device.DeleteBuffer(buffer);
|
||||
}
|
||||
|
||||
void GLOptimizedVoxelModel::GenerateTexture() {
|
||||
@ -354,7 +354,8 @@ namespace spades {
|
||||
p3 += nn;
|
||||
SPAssert(!model->IsSolid(p3.x, p3.y, p3.z));
|
||||
|
||||
uint8_t aoId = calcAOID(model, p3.x, p3.y, p3.z, ux, uy, uz, vx, vy, vz);
|
||||
uint8_t aoId =
|
||||
calcAOID(model, p3.x, p3.y, p3.z, ux, uy, uz, vx, vy, vz);
|
||||
|
||||
if (aoId % 16 == 15) {
|
||||
// These AOIDs are allocated for non-default materials.
|
||||
@ -534,8 +535,8 @@ namespace spades {
|
||||
GLOptimizedVoxelModel::RenderShadowMapPass(std::vector<client::ModelRenderParam> params) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
|
||||
shadowMapProgram->Use();
|
||||
|
||||
@ -553,20 +554,20 @@ namespace spades {
|
||||
positionAttribute(shadowMapProgram);
|
||||
normalAttribute(shadowMapProgram);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
if (normalAttribute() != -1) {
|
||||
device->VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)8);
|
||||
device.VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)8);
|
||||
}
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
if (normalAttribute() != -1)
|
||||
device->EnableVertexAttribArray(normalAttribute(), true);
|
||||
device.EnableVertexAttribArray(normalAttribute(), true);
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
|
||||
for (size_t i = 0; i < params.size(); i++) {
|
||||
const client::ModelRenderParam ¶m = params[i];
|
||||
@ -599,18 +600,18 @@ namespace spades {
|
||||
modelNormalMatrix(shadowMapProgram);
|
||||
modelNormalMatrix.SetValue(modelMatrix);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
device.DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
}
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
if (normalAttribute() != -1)
|
||||
device->EnableVertexAttribArray(normalAttribute(), false);
|
||||
device.EnableVertexAttribArray(normalAttribute(), false);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
void GLOptimizedVoxelModel::RenderSunlightPass(std::vector<client::ModelRenderParam> params,
|
||||
@ -619,20 +620,20 @@ namespace spades {
|
||||
|
||||
bool mirror = renderer->IsRenderingMirror();
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
aoImage->Bind(IGLDevice::Texture2D);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device.ActiveTexture(1);
|
||||
image->Bind(IGLDevice::Texture2D);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
|
||||
program->Use();
|
||||
|
||||
@ -685,20 +686,20 @@ namespace spades {
|
||||
textureCoordAttribute(program);
|
||||
normalAttribute(program);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device->VertexAttribPointer(textureCoordAttribute(), 2, IGLDevice::UnsignedShort, false,
|
||||
sizeof(Vertex), (void *)4);
|
||||
device->VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)8);
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device.VertexAttribPointer(textureCoordAttribute(), 2, IGLDevice::UnsignedShort, false,
|
||||
sizeof(Vertex), (void *)4);
|
||||
device.VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false, sizeof(Vertex),
|
||||
(void *)8);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device->EnableVertexAttribArray(textureCoordAttribute(), true);
|
||||
device->EnableVertexAttribArray(normalAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(textureCoordAttribute(), true);
|
||||
device.EnableVertexAttribArray(normalAttribute(), true);
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
|
||||
for (size_t i = 0; i < params.size(); i++) {
|
||||
const client::ModelRenderParam ¶m = params[i];
|
||||
@ -747,26 +748,26 @@ namespace spades {
|
||||
modelOpacity.SetValue(param.opacity);
|
||||
|
||||
if (param.depthHack) {
|
||||
device->DepthRange(0.f, 0.1f);
|
||||
device.DepthRange(0.f, 0.1f);
|
||||
}
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
device.DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
if (param.depthHack) {
|
||||
device->DepthRange(0.f, 1.f);
|
||||
device.DepthRange(0.f, 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->EnableVertexAttribArray(textureCoordAttribute(), false);
|
||||
device->EnableVertexAttribArray(normalAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(textureCoordAttribute(), false);
|
||||
device.EnableVertexAttribArray(normalAttribute(), false);
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(1);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
void
|
||||
@ -776,20 +777,20 @@ namespace spades {
|
||||
|
||||
bool mirror = renderer->IsRenderingMirror();
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
aoImage->Bind(IGLDevice::Texture2D);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device.ActiveTexture(1);
|
||||
image->Bind(IGLDevice::Texture2D);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
|
||||
dlightProgram->Use();
|
||||
|
||||
@ -825,20 +826,20 @@ namespace spades {
|
||||
textureCoordAttribute(dlightProgram);
|
||||
normalAttribute(dlightProgram);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device->VertexAttribPointer(textureCoordAttribute(), 2, IGLDevice::UnsignedShort, false,
|
||||
sizeof(Vertex), (void *)4);
|
||||
device->VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)8);
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device.VertexAttribPointer(textureCoordAttribute(), 2, IGLDevice::UnsignedShort, false,
|
||||
sizeof(Vertex), (void *)4);
|
||||
device.VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false, sizeof(Vertex),
|
||||
(void *)8);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device->EnableVertexAttribArray(textureCoordAttribute(), true);
|
||||
device->EnableVertexAttribArray(normalAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(textureCoordAttribute(), true);
|
||||
device.EnableVertexAttribArray(normalAttribute(), true);
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
|
||||
for (size_t i = 0; i < params.size(); i++) {
|
||||
const client::ModelRenderParam ¶m = params[i];
|
||||
@ -882,7 +883,7 @@ namespace spades {
|
||||
modelNormalMatrix.SetValue(modelMatrix);
|
||||
|
||||
if (param.depthHack) {
|
||||
device->DepthRange(0.f, 0.1f);
|
||||
device.DepthRange(0.f, 0.1f);
|
||||
}
|
||||
for (size_t i = 0; i < lights.size(); i++) {
|
||||
if (!lights[i].SphereCull(param.matrix.GetOrigin(), rad))
|
||||
@ -890,21 +891,21 @@ namespace spades {
|
||||
|
||||
dlightShader(renderer, dlightProgram, lights[i], 2);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
device.DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
}
|
||||
if (param.depthHack) {
|
||||
device->DepthRange(0.f, 1.f);
|
||||
device.DepthRange(0.f, 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->EnableVertexAttribArray(textureCoordAttribute(), false);
|
||||
device->EnableVertexAttribArray(normalAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(textureCoordAttribute(), false);
|
||||
device.EnableVertexAttribArray(normalAttribute(), false);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -47,7 +47,7 @@ namespace spades {
|
||||
};
|
||||
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLProgram *program;
|
||||
GLProgram *dlightProgram;
|
||||
GLProgram *shadowMapProgram;
|
||||
|
@ -86,7 +86,7 @@ namespace spades {
|
||||
GLProfiler::GLProfiler(GLRenderer &renderer)
|
||||
: m_settings{renderer.GetSettings()},
|
||||
m_renderer{renderer},
|
||||
m_device{*renderer.GetGLDevice()},
|
||||
m_device{renderer.GetGLDevice()},
|
||||
m_active{false},
|
||||
m_lastSaveTime{0.0},
|
||||
m_shouldSaveThisFrame{false},
|
||||
@ -486,7 +486,7 @@ namespace spades {
|
||||
factor{factor} {}
|
||||
|
||||
void DrawText(const char *str) {
|
||||
client::IImage *font = self.m_font;
|
||||
client::IImage &font = *self.m_font;
|
||||
|
||||
while (*str) {
|
||||
char c = *str;
|
||||
@ -547,7 +547,7 @@ namespace spades {
|
||||
float barScale = 4000.0 * self.m_settings.r_debugTimingOutputBarScale;
|
||||
float boxWidth = static_cast<float>(time * barScale);
|
||||
float childBoxWidth = static_cast<float>(subphaseTime * barScale);
|
||||
client::IImage *white = self.m_white;
|
||||
client::IImage &white = *self.m_white;
|
||||
|
||||
renderer.SetColorAlphaPremultiplied(Vector4{0.0f, 0.0f, 0.0f, 0.5f});
|
||||
renderer.DrawImage(white, AABB2{cursor.x, cursor.y + 1.0f, boxWidth, 8.0f});
|
||||
|
@ -49,8 +49,8 @@ namespace spades {
|
||||
bool m_shouldSaveThisFrame;
|
||||
bool m_waitingTimerQueryResult;
|
||||
|
||||
client::IImage *m_font;
|
||||
client::IImage *m_white;
|
||||
Handle<client::IImage> m_font;
|
||||
Handle<client::IImage> m_white;
|
||||
|
||||
Stopwatch m_stopwatch;
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
GLProgramManager::GLProgramManager(IGLDevice *d, IGLShadowMapRenderer *smr,
|
||||
GLProgramManager::GLProgramManager(IGLDevice &d, IGLShadowMapRenderer *smr,
|
||||
GLSettings &settings)
|
||||
: device(d), shadowMapRenderer(smr), settings(settings) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
@ -88,7 +88,7 @@ namespace spades {
|
||||
std::string text = FileManager::ReadAllBytes(name.c_str());
|
||||
std::vector<std::string> lines = SplitIntoLines(text);
|
||||
|
||||
GLProgram *p = new GLProgram(device, name);
|
||||
GLProgram *p = new GLProgram(&device, name);
|
||||
|
||||
for (size_t i = 0; i < lines.size(); i++) {
|
||||
std::string text = TrimSpaces(lines[i]);
|
||||
@ -157,7 +157,7 @@ namespace spades {
|
||||
else
|
||||
SPRaise("Failed to determine the type of a shader: %s", name.c_str());
|
||||
|
||||
GLShader *s = new GLShader(device, type);
|
||||
GLShader *s = new GLShader(&device, type);
|
||||
|
||||
std::string finalSource;
|
||||
|
||||
|
@ -30,7 +30,7 @@ namespace spades {
|
||||
class IGLShadowMapRenderer;
|
||||
class GLSettings;
|
||||
class GLProgramManager {
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLSettings &settings;
|
||||
IGLShadowMapRenderer *shadowMapRenderer;
|
||||
|
||||
@ -41,7 +41,7 @@ namespace spades {
|
||||
GLShader *CreateShader(const std::string &name);
|
||||
|
||||
public:
|
||||
GLProgramManager(IGLDevice *, IGLShadowMapRenderer *shadowMapRenderer,
|
||||
GLProgramManager(IGLDevice &, IGLShadowMapRenderer *shadowMapRenderer,
|
||||
GLSettings &settings);
|
||||
~GLProgramManager();
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
GLQuadRenderer::GLQuadRenderer(IGLDevice *device) : device(device) {}
|
||||
GLQuadRenderer::GLQuadRenderer(IGLDevice &device) : device(device) {}
|
||||
|
||||
GLQuadRenderer::~GLQuadRenderer() {}
|
||||
|
||||
@ -34,10 +34,10 @@ namespace spades {
|
||||
void GLQuadRenderer::Draw() {
|
||||
static const uint8_t vertices[][4] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
|
||||
|
||||
device->EnableVertexAttribArray(attrIndex, true);
|
||||
device->VertexAttribPointer(attrIndex, 2, IGLDevice::UnsignedByte, false, 4, vertices);
|
||||
device->DrawArrays(IGLDevice::TriangleFan, 0, 4);
|
||||
device->EnableVertexAttribArray(attrIndex, false);
|
||||
device.EnableVertexAttribArray(attrIndex, true);
|
||||
device.VertexAttribPointer(attrIndex, 2, IGLDevice::UnsignedByte, false, 4, vertices);
|
||||
device.DrawArrays(IGLDevice::TriangleFan, 0, 4);
|
||||
device.EnableVertexAttribArray(attrIndex, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -29,12 +29,12 @@ namespace spades {
|
||||
* load program by yourself, and GLQuadRenderer does
|
||||
* setting vertex attributes and drawing. */
|
||||
class GLQuadRenderer {
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
|
||||
IGLDevice::UInteger attrIndex;
|
||||
|
||||
public:
|
||||
GLQuadRenderer(IGLDevice *);
|
||||
GLQuadRenderer(IGLDevice &);
|
||||
~GLQuadRenderer();
|
||||
|
||||
/** specifies the index of an attribute that
|
||||
@ -44,4 +44,4 @@ namespace spades {
|
||||
void Draw();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,10 +21,10 @@
|
||||
#include <atomic>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <Client/GameMap.h>
|
||||
#include "GLMapShadowRenderer.h"
|
||||
#include "GLRadiosityRenderer.h"
|
||||
#include "GLRenderer.h"
|
||||
#include <Client/GameMap.h>
|
||||
|
||||
#include <Core/ConcurrentDispatch.h>
|
||||
#include <Core/Settings.h>
|
||||
@ -40,8 +40,8 @@ namespace spades {
|
||||
GLRadiosityRenderer *renderer;
|
||||
|
||||
public:
|
||||
std::atomic<bool> done {false};
|
||||
UpdateDispatch(GLRadiosityRenderer *r) : renderer(r) { }
|
||||
std::atomic<bool> done{false};
|
||||
UpdateDispatch(GLRadiosityRenderer *r) : renderer(r) {}
|
||||
void Run() override {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
@ -92,30 +92,31 @@ namespace spades {
|
||||
c.cz = z;
|
||||
}
|
||||
|
||||
SPLog("Chunk buffer allocated (%d bytes)", (int) sizeof(Chunk) * chunkW * chunkH * chunkD);
|
||||
SPLog("Chunk buffer allocated (%d bytes)",
|
||||
(int)sizeof(Chunk) * chunkW * chunkH * chunkD);
|
||||
|
||||
// make texture
|
||||
textureFlat = device->GenTexture();
|
||||
textureX = device->GenTexture();
|
||||
textureY = device->GenTexture();
|
||||
textureZ = device->GenTexture();
|
||||
textureFlat = device.GenTexture();
|
||||
textureX = device.GenTexture();
|
||||
textureY = device.GenTexture();
|
||||
textureZ = device.GenTexture();
|
||||
|
||||
IGLDevice::UInteger texs[] = {textureFlat, textureX, textureY, textureZ};
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
device->BindTexture(IGLDevice::Texture3D, texs[i]);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::Repeat);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::Repeat);
|
||||
device->TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapR,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexImage3D(
|
||||
device.BindTexture(IGLDevice::Texture3D, texs[i]);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::Repeat);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::Repeat);
|
||||
device.TexParamater(IGLDevice::Texture3D, IGLDevice::TextureWrapR,
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexImage3D(
|
||||
IGLDevice::Texture3D, 0,
|
||||
((int)settings.r_radiosity >= 2) ? IGLDevice::RGB10A2 : IGLDevice::RGB5A1, w, h,
|
||||
d, 0, IGLDevice::BGRA, IGLDevice::UnsignedInt2101010Rev, NULL);
|
||||
@ -129,11 +130,10 @@ namespace spades {
|
||||
|
||||
for (int j = 0; j < 4; j++) {
|
||||
|
||||
device->BindTexture(IGLDevice::Texture3D, texs[j]);
|
||||
device.BindTexture(IGLDevice::Texture3D, texs[j]);
|
||||
for (int i = 0; i < d; i++) {
|
||||
device->TexSubImage3D(IGLDevice::Texture3D, 0, 0, 0, i, w, h, 1,
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedInt2101010Rev,
|
||||
v.data());
|
||||
device.TexSubImage3D(IGLDevice::Texture3D, 0, 0, 0, i, w, h, 1, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedInt2101010Rev, v.data());
|
||||
}
|
||||
}
|
||||
dispatch = NULL;
|
||||
@ -149,10 +149,10 @@ namespace spades {
|
||||
}
|
||||
SPLog("Releasing textures");
|
||||
|
||||
device->DeleteTexture(textureFlat);
|
||||
device->DeleteTexture(textureX);
|
||||
device->DeleteTexture(textureY);
|
||||
device->DeleteTexture(textureZ);
|
||||
device.DeleteTexture(textureFlat);
|
||||
device.DeleteTexture(textureX);
|
||||
device.DeleteTexture(textureY);
|
||||
device.DeleteTexture(textureZ);
|
||||
}
|
||||
|
||||
GLRadiosityRenderer::Result GLRadiosityRenderer::Evaluate(IntVector3 ipos) {
|
||||
@ -355,33 +355,34 @@ namespace spades {
|
||||
if (!chunks[i].transferDone.load())
|
||||
cnt++;
|
||||
}
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Radiosity [>= %d chunk(s)]", cnt);
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Radiosity [>= %d chunk(s)]",
|
||||
cnt);
|
||||
for (size_t i = 0; i < chunks.size(); i++) {
|
||||
Chunk &c = chunks[i];
|
||||
if (!c.transferDone.exchange(true)) {
|
||||
device->BindTexture(IGLDevice::Texture3D, textureFlat);
|
||||
device->TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize, ChunkSize, ChunkSize,
|
||||
ChunkSize, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedInt2101010Rev, c.dataFlat);
|
||||
device.BindTexture(IGLDevice::Texture3D, textureFlat);
|
||||
device.TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize, ChunkSize, ChunkSize,
|
||||
ChunkSize, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedInt2101010Rev, c.dataFlat);
|
||||
|
||||
device->BindTexture(IGLDevice::Texture3D, textureX);
|
||||
device->TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize, ChunkSize, ChunkSize,
|
||||
ChunkSize, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedInt2101010Rev, c.dataX);
|
||||
device.BindTexture(IGLDevice::Texture3D, textureX);
|
||||
device.TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize, ChunkSize, ChunkSize,
|
||||
ChunkSize, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedInt2101010Rev, c.dataX);
|
||||
|
||||
device->BindTexture(IGLDevice::Texture3D, textureY);
|
||||
device->TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize, ChunkSize, ChunkSize,
|
||||
ChunkSize, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedInt2101010Rev, c.dataY);
|
||||
device.BindTexture(IGLDevice::Texture3D, textureY);
|
||||
device.TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize, ChunkSize, ChunkSize,
|
||||
ChunkSize, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedInt2101010Rev, c.dataY);
|
||||
|
||||
device->BindTexture(IGLDevice::Texture3D, textureZ);
|
||||
device->TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize, ChunkSize, ChunkSize,
|
||||
ChunkSize, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedInt2101010Rev, c.dataZ);
|
||||
device.BindTexture(IGLDevice::Texture3D, textureZ);
|
||||
device.TexSubImage3D(IGLDevice::Texture3D, 0, c.cx * ChunkSize,
|
||||
c.cy * ChunkSize, c.cz * ChunkSize, ChunkSize, ChunkSize,
|
||||
ChunkSize, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedInt2101010Rev, c.dataZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -536,5 +537,5 @@ namespace spades {
|
||||
c.dirty = false;
|
||||
c.transferDone = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -43,7 +43,7 @@ namespace spades {
|
||||
class UpdateDispatch;
|
||||
enum { ChunkSize = 16, ChunkSizeBits = 4, Envelope = 6 };
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLSettings &settings;
|
||||
client::GameMap *map;
|
||||
|
||||
|
@ -71,8 +71,8 @@ namespace spades {
|
||||
namespace draw {
|
||||
// TODO: raise error for any calls after Shutdown().
|
||||
|
||||
GLRenderer::GLRenderer(IGLDevice *_device)
|
||||
: device(_device),
|
||||
GLRenderer::GLRenderer(Handle<IGLDevice> _device)
|
||||
: device(std::move(_device)),
|
||||
fbManager(NULL),
|
||||
map(NULL),
|
||||
inited(false),
|
||||
@ -101,12 +101,14 @@ namespace spades {
|
||||
duringSceneRendering(false) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
SPAssert(device);
|
||||
|
||||
SPLog("GLRenderer bootstrap");
|
||||
|
||||
fbManager = new GLFramebufferManager(_device, settings);
|
||||
fbManager = new GLFramebufferManager(*device, settings);
|
||||
|
||||
programManager = new GLProgramManager(_device, shadowMapRenderer, settings);
|
||||
imageManager = new GLImageManager(_device);
|
||||
programManager = new GLProgramManager(*device, shadowMapRenderer, settings);
|
||||
imageManager = new GLImageManager(*device);
|
||||
imageRenderer = new GLImageRenderer(this);
|
||||
profiler.reset(new GLProfiler(*this));
|
||||
|
||||
@ -259,7 +261,7 @@ namespace spades {
|
||||
|
||||
Handle<client::IImage> GLRenderer::CreateImage(spades::Bitmap &bmp) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
return GLImage::FromBitmap(bmp, device).Cast<client::IImage>();
|
||||
return GLImage::FromBitmap(bmp, device.GetPointerOrNull()).Cast<client::IImage>();
|
||||
}
|
||||
|
||||
Handle<client::IModel> GLRenderer::CreateModel(spades::VoxelModel &model) {
|
||||
@ -1035,7 +1037,7 @@ namespace spades {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
device->Enable(IGLDevice::Blend, false);
|
||||
device->Viewport(0, 0, handle.GetWidth(), handle.GetHeight());
|
||||
Handle<GLImage> image(new GLImage(handle.GetTexture(), device, handle.GetWidth(),
|
||||
Handle<GLImage> image(new GLImage(handle.GetTexture(), device.GetPointerOrNull(), handle.GetWidth(),
|
||||
handle.GetHeight(), false),
|
||||
false);
|
||||
SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1));
|
||||
@ -1231,7 +1233,8 @@ namespace spades {
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
device->Enable(IGLDevice::Blend, false);
|
||||
device->Viewport(0, 0, w, h);
|
||||
Handle<GLImage> image(new GLImage(lastColorBufferTexture, device, w, h, false),
|
||||
// TODO: Replace this with `Handle::New`
|
||||
Handle<GLImage> image(new GLImage(lastColorBufferTexture, device.GetPointerOrNull(), w, h, false),
|
||||
false);
|
||||
SetColorAlphaPremultiplied(MakeVector4(1, 1, 1, 1));
|
||||
DrawImage(*image, AABB2(0, h, w, -h));
|
||||
|
@ -146,7 +146,7 @@ namespace spades {
|
||||
~GLRenderer();
|
||||
|
||||
public:
|
||||
GLRenderer(IGLDevice *glDevice);
|
||||
GLRenderer(Handle<IGLDevice> glDevice);
|
||||
|
||||
void Init() override;
|
||||
void Shutdown() override;
|
||||
@ -209,7 +209,7 @@ namespace spades {
|
||||
float ScreenHeight() override;
|
||||
|
||||
GLSettings &GetSettings() { return settings; }
|
||||
IGLDevice *GetGLDevice() { return device; }
|
||||
IGLDevice &GetGLDevice() { return *device; }
|
||||
GLProfiler &GetGLProfiler() { return *profiler; }
|
||||
GLFramebufferManager *GetFramebufferManager() { return fbManager; }
|
||||
IGLShadowMapRenderer *GetShadowMapRenderer() { return shadowMapRenderer; }
|
||||
|
@ -47,7 +47,7 @@ namespace spades {
|
||||
|
||||
GLColorBuffer GLSSAOFilter::GenerateRawSSAOImage(int width, int height) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
GLColorBuffer output =
|
||||
@ -85,30 +85,30 @@ namespace spades {
|
||||
float kernelSize = std::max(1.0f, std::min(width, height) * 0.0018f);
|
||||
sampleOffsetScale.SetValue(kernelSize / (float)width, kernelSize / (float)height);
|
||||
|
||||
if (width < dev->ScreenWidth()) {
|
||||
if (width < dev.ScreenWidth()) {
|
||||
// 2x downsampling
|
||||
texCoordRange.SetValue(0.25f / width, 0.25f / height, 1.f, 1.f);
|
||||
} else {
|
||||
texCoordRange.SetValue(0.f, 0.f, 1.f, 1.f);
|
||||
}
|
||||
|
||||
dev->ActiveTexture(0);
|
||||
dev.ActiveTexture(0);
|
||||
depthTexture.SetValue(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D,
|
||||
dev.BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
|
||||
dev->ActiveTexture(1);
|
||||
dev.ActiveTexture(1);
|
||||
ditherTexture.SetValue(1);
|
||||
ditherPattern->Bind(IGLDevice::Texture2D);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter, IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter, IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter, IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter, IGLDevice::Nearest);
|
||||
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev->Viewport(0, 0, width, height);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
|
||||
dev.Viewport(0, 0, width, height);
|
||||
qr.SetCoordAttributeIndex(positionAttribute());
|
||||
qr.Draw();
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, 0);
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
return output;
|
||||
@ -119,7 +119,7 @@ namespace spades {
|
||||
SPADES_MARK_FUNCTION();
|
||||
// do gaussian blur
|
||||
GLProgram *program = bilateralProgram;
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
GLQuadRenderer qr(dev);
|
||||
|
||||
int w = width == -1 ? tex.GetWidth() : width;
|
||||
@ -145,14 +145,14 @@ namespace spades {
|
||||
pixelShift(program);
|
||||
|
||||
inputTexture.SetValue(0);
|
||||
dev->ActiveTexture(0);
|
||||
dev->BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter, IGLDevice::Nearest);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter, IGLDevice::Nearest);
|
||||
dev.ActiveTexture(0);
|
||||
dev.BindTexture(IGLDevice::Texture2D, tex.GetTexture());
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter, IGLDevice::Nearest);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter, IGLDevice::Nearest);
|
||||
|
||||
depthTexture.SetValue(1);
|
||||
dev->ActiveTexture(1);
|
||||
dev->BindTexture(IGLDevice::Texture2D,
|
||||
dev.ActiveTexture(1);
|
||||
dev.BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
|
||||
texCoordRange.SetValue(0.f, 0.f, 1.f, 1.f);
|
||||
@ -170,13 +170,13 @@ namespace spades {
|
||||
qr.SetCoordAttributeIndex(positionAttribute());
|
||||
|
||||
GLColorBuffer buf2 = renderer->GetFramebufferManager()->CreateBufferHandle(w, h, 1);
|
||||
dev->Viewport(0, 0, w, h);
|
||||
dev->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
dev.Viewport(0, 0, w, h);
|
||||
dev.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
qr.Draw();
|
||||
|
||||
dev->ActiveTexture(0);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter, IGLDevice::Linear);
|
||||
dev->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter, IGLDevice::Linear);
|
||||
dev.ActiveTexture(0);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter, IGLDevice::Linear);
|
||||
dev.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter, IGLDevice::Linear);
|
||||
|
||||
return buf2;
|
||||
}
|
||||
@ -184,12 +184,12 @@ namespace spades {
|
||||
GLColorBuffer GLSSAOFilter::Filter() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice *dev = renderer->GetGLDevice();
|
||||
IGLDevice &dev = renderer->GetGLDevice();
|
||||
|
||||
int width = dev->ScreenWidth();
|
||||
int height = dev->ScreenHeight();
|
||||
int width = dev.ScreenWidth();
|
||||
int height = dev.ScreenHeight();
|
||||
|
||||
dev->Enable(IGLDevice::Blend, false);
|
||||
dev.Enable(IGLDevice::Blend, false);
|
||||
|
||||
bool useLowQualitySSAO = renderer->IsRenderingMirror() || renderer->GetSettings().r_ssao >= 2;
|
||||
GLColorBuffer ssao = useLowQualitySSAO ?
|
||||
|
@ -203,8 +203,8 @@ namespace spades {
|
||||
lastImage = NULL;
|
||||
program->Use();
|
||||
|
||||
device->Enable(IGLDevice::Blend, true);
|
||||
device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
device.Enable(IGLDevice::Blend, true);
|
||||
device.BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
|
||||
projectionViewMatrix(program);
|
||||
rightVector(program);
|
||||
@ -248,18 +248,18 @@ namespace spades {
|
||||
static GLShadowShader shadowShader;
|
||||
shadowShader(renderer, program, 2);
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device->BindTexture(IGLDevice::Texture2D,
|
||||
device.ActiveTexture(1);
|
||||
device.BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device->EnableVertexAttribArray(spritePosAttribute(), true);
|
||||
device->EnableVertexAttribArray(colorAttribute(), true);
|
||||
device->EnableVertexAttribArray(emissionAttribute(), true);
|
||||
device->EnableVertexAttribArray(dlRAttribute(), true);
|
||||
device->EnableVertexAttribArray(dlGAttribute(), true);
|
||||
device->EnableVertexAttribArray(dlBAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(spritePosAttribute(), true);
|
||||
device.EnableVertexAttribArray(colorAttribute(), true);
|
||||
device.EnableVertexAttribArray(emissionAttribute(), true);
|
||||
device.EnableVertexAttribArray(dlRAttribute(), true);
|
||||
device.EnableVertexAttribArray(dlGAttribute(), true);
|
||||
device.EnableVertexAttribArray(dlBAttribute(), true);
|
||||
|
||||
thresLow = tanf(def.fovX * .5f) * tanf(def.fovY * .5f) * 1.8f;
|
||||
thresRange = thresLow * .5f;
|
||||
@ -320,16 +320,16 @@ namespace spades {
|
||||
}
|
||||
|
||||
// low-res sprites
|
||||
IGLDevice::UInteger lastFb = device->GetInteger(IGLDevice::FramebufferBinding);
|
||||
int sW = device->ScreenWidth(), sH = device->ScreenHeight();
|
||||
IGLDevice::UInteger lastFb = device.GetInteger(IGLDevice::FramebufferBinding);
|
||||
int sW = device.ScreenWidth(), sH = device.ScreenHeight();
|
||||
int lW = (sW + 3) / 4, lH = (sH + 3) / 4;
|
||||
int numLowResSprites = 0;
|
||||
GLColorBuffer buf = renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, buf.GetFramebuffer());
|
||||
device->ClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
device->Clear(IGLDevice::ColorBufferBit);
|
||||
device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
device->Viewport(0, 0, lW, lH);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, buf.GetFramebuffer());
|
||||
device.ClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
device.Clear(IGLDevice::ColorBufferBit);
|
||||
device.BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
device.Viewport(0, 0, lW, lH);
|
||||
{
|
||||
GLProfiler::Context measure(renderer->GetGLProfiler(), "Low Resolution");
|
||||
for (size_t i = 0; i < sprites.size(); i++) {
|
||||
@ -387,20 +387,20 @@ namespace spades {
|
||||
|
||||
// finalize
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->EnableVertexAttribArray(spritePosAttribute(), false);
|
||||
device->EnableVertexAttribArray(colorAttribute(), false);
|
||||
device->EnableVertexAttribArray(emissionAttribute(), false);
|
||||
device->EnableVertexAttribArray(dlRAttribute(), false);
|
||||
device->EnableVertexAttribArray(dlGAttribute(), false);
|
||||
device->EnableVertexAttribArray(dlBAttribute(), false);
|
||||
device.ActiveTexture(1);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(spritePosAttribute(), false);
|
||||
device.EnableVertexAttribArray(colorAttribute(), false);
|
||||
device.EnableVertexAttribArray(emissionAttribute(), false);
|
||||
device.EnableVertexAttribArray(dlRAttribute(), false);
|
||||
device.EnableVertexAttribArray(dlGAttribute(), false);
|
||||
device.EnableVertexAttribArray(dlBAttribute(), false);
|
||||
|
||||
// composite downsampled sprite
|
||||
device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
device.BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
if (numLowResSprites > 0) {
|
||||
GLProfiler::Context measure(renderer->GetGLProfiler(), "Finalize");
|
||||
GLQuadRenderer qr(device);
|
||||
@ -416,15 +416,15 @@ namespace spades {
|
||||
blur_textureUniform(program);
|
||||
blur_unitShift(program);
|
||||
blur_textureUniform.SetValue(0);
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
device->Enable(IGLDevice::Blend, false);
|
||||
device.Enable(IGLDevice::Blend, false);
|
||||
|
||||
// x-direction
|
||||
GLColorBuffer buf2 =
|
||||
renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
|
||||
device->BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
device.BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
blur_unitShift.SetValue(1.f / lW, 0.f);
|
||||
qr.Draw();
|
||||
buf.Release();
|
||||
@ -432,15 +432,15 @@ namespace spades {
|
||||
// x-direction
|
||||
GLColorBuffer buf3 =
|
||||
renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
|
||||
device->BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
|
||||
device.BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
|
||||
blur_unitShift.SetValue(0.f, 1.f / lH);
|
||||
qr.Draw();
|
||||
buf2.Release();
|
||||
|
||||
buf = buf3;
|
||||
|
||||
device->Enable(IGLDevice::Blend, true);
|
||||
device.Enable(IGLDevice::Blend, true);
|
||||
|
||||
// composite
|
||||
program = renderer->RegisterProgram("Shaders/PostFilters/PassThrough.program");
|
||||
@ -461,16 +461,16 @@ namespace spades {
|
||||
colorUniform.SetValue(1.f, 1.f, 1.f, 1.f);
|
||||
|
||||
qr.SetCoordAttributeIndex(positionAttribute());
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
device->BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
device->Viewport(0, 0, sW, sH);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
device.BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
device.Viewport(0, 0, sW, sH);
|
||||
qr.Draw();
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
} else {
|
||||
device->Viewport(0, 0, sW, sH);
|
||||
device.Viewport(0, 0, sW, sH);
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
}
|
||||
|
||||
buf.Release();
|
||||
@ -482,25 +482,25 @@ namespace spades {
|
||||
if (vertices.empty())
|
||||
return;
|
||||
|
||||
device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(positionAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].x));
|
||||
device->VertexAttribPointer(spritePosAttribute(), 3, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(spritePosAttribute(), 3, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].sx));
|
||||
device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(colorAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].color));
|
||||
device->VertexAttribPointer(emissionAttribute(), 3, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(emissionAttribute(), 3, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].emission));
|
||||
device->VertexAttribPointer(dlRAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(dlRAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].dlR));
|
||||
device->VertexAttribPointer(dlGAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(dlGAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].dlG));
|
||||
device->VertexAttribPointer(dlBAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(dlBAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].dlB));
|
||||
|
||||
SPAssert(lastImage);
|
||||
lastImage->Bind(IGLDevice::Texture2D);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
device.DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedInt, indices.data());
|
||||
|
||||
|
@ -65,7 +65,7 @@ namespace spades {
|
||||
|
||||
GLRenderer *renderer;
|
||||
GLSettings &settings;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
std::vector<Sprite> sprites;
|
||||
|
||||
GLImage *lastImage;
|
||||
|
@ -106,8 +106,8 @@ namespace spades {
|
||||
lastImage = NULL;
|
||||
program->Use();
|
||||
|
||||
device->Enable(IGLDevice::Blend, true);
|
||||
device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
device.Enable(IGLDevice::Blend, true);
|
||||
device.BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
|
||||
projectionViewMatrix(program);
|
||||
rightVector(program);
|
||||
@ -144,14 +144,14 @@ namespace spades {
|
||||
depthTexture.SetValue(1);
|
||||
zNearFar.SetValue(def.zNear, def.zFar);
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device->BindTexture(IGLDevice::Texture2D,
|
||||
device.ActiveTexture(1);
|
||||
device.BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetDepthTexture());
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device->EnableVertexAttribArray(spritePosAttribute(), true);
|
||||
device->EnableVertexAttribArray(colorAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(spritePosAttribute(), true);
|
||||
device.EnableVertexAttribArray(colorAttribute(), true);
|
||||
|
||||
thresLow = tanf(def.fovX * .5f) * tanf(def.fovY * .5f) * 1.8f;
|
||||
thresRange = thresLow * .5f;
|
||||
@ -213,16 +213,16 @@ namespace spades {
|
||||
}
|
||||
|
||||
// low-res sprites
|
||||
IGLDevice::UInteger lastFb = device->GetInteger(IGLDevice::FramebufferBinding);
|
||||
int sW = device->ScreenWidth(), sH = device->ScreenHeight();
|
||||
IGLDevice::UInteger lastFb = device.GetInteger(IGLDevice::FramebufferBinding);
|
||||
int sW = device.ScreenWidth(), sH = device.ScreenHeight();
|
||||
int lW = (sW + 3) / 4, lH = (sH + 3) / 4;
|
||||
int numLowResSprites = 0;
|
||||
GLColorBuffer buf = renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, buf.GetFramebuffer());
|
||||
device->ClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
device->Clear(IGLDevice::ColorBufferBit);
|
||||
device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
device->Viewport(0, 0, lW, lH);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, buf.GetFramebuffer());
|
||||
device.ClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
device.Clear(IGLDevice::ColorBufferBit);
|
||||
device.BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
device.Viewport(0, 0, lW, lH);
|
||||
{
|
||||
GLProfiler::Context measure(renderer->GetGLProfiler(), "Low Resolution");
|
||||
for (size_t i = 0; i < sprites.size(); i++) {
|
||||
@ -281,16 +281,16 @@ namespace spades {
|
||||
|
||||
// finalize
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->EnableVertexAttribArray(spritePosAttribute(), false);
|
||||
device->EnableVertexAttribArray(colorAttribute(), false);
|
||||
device.ActiveTexture(1);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(spritePosAttribute(), false);
|
||||
device.EnableVertexAttribArray(colorAttribute(), false);
|
||||
|
||||
// composite downsampled sprite
|
||||
device->BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
device.BlendFunc(IGLDevice::One, IGLDevice::OneMinusSrcAlpha);
|
||||
if (numLowResSprites > 0) {
|
||||
GLProfiler::Context measure(renderer->GetGLProfiler(), "Finalize");
|
||||
GLQuadRenderer qr(device);
|
||||
@ -306,15 +306,15 @@ namespace spades {
|
||||
blur_textureUniform(program);
|
||||
blur_unitShift(program);
|
||||
blur_textureUniform.SetValue(0);
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
qr.SetCoordAttributeIndex(blur_positionAttribute());
|
||||
device->Enable(IGLDevice::Blend, false);
|
||||
device.Enable(IGLDevice::Blend, false);
|
||||
|
||||
// x-direction
|
||||
GLColorBuffer buf2 =
|
||||
renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
|
||||
device->BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
device.BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, buf2.GetFramebuffer());
|
||||
blur_unitShift.SetValue(1.f / lW, 0.f);
|
||||
qr.Draw();
|
||||
buf.Release();
|
||||
@ -322,15 +322,15 @@ namespace spades {
|
||||
// x-direction
|
||||
GLColorBuffer buf3 =
|
||||
renderer->GetFramebufferManager()->CreateBufferHandle(lW, lH, true);
|
||||
device->BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
|
||||
device.BindTexture(IGLDevice::Texture2D, buf2.GetTexture());
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, buf3.GetFramebuffer());
|
||||
blur_unitShift.SetValue(0.f, 1.f / lH);
|
||||
qr.Draw();
|
||||
buf2.Release();
|
||||
|
||||
buf = buf3;
|
||||
|
||||
device->Enable(IGLDevice::Blend, true);
|
||||
device.Enable(IGLDevice::Blend, true);
|
||||
|
||||
// composite
|
||||
program = renderer->RegisterProgram("Shaders/PostFilters/PassThrough.program");
|
||||
@ -351,16 +351,16 @@ namespace spades {
|
||||
colorUniform.SetValue(1.f, 1.f, 1.f, 1.f);
|
||||
|
||||
qr.SetCoordAttributeIndex(positionAttribute());
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
device->BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
device->Viewport(0, 0, sW, sH);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
device.BindTexture(IGLDevice::Texture2D, buf.GetTexture());
|
||||
device.Viewport(0, 0, sW, sH);
|
||||
qr.Draw();
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
|
||||
} else {
|
||||
device->Viewport(0, 0, sW, sH);
|
||||
device.Viewport(0, 0, sW, sH);
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
}
|
||||
|
||||
buf.Release();
|
||||
@ -372,17 +372,17 @@ namespace spades {
|
||||
if (vertices.empty())
|
||||
return;
|
||||
|
||||
device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(positionAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].x));
|
||||
device->VertexAttribPointer(spritePosAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(spritePosAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].sx));
|
||||
device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(colorAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].r));
|
||||
|
||||
SPAssert(lastImage);
|
||||
lastImage->Bind(IGLDevice::Texture2D);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
device.DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedInt, indices.data());
|
||||
|
||||
|
@ -58,7 +58,7 @@ namespace spades {
|
||||
};
|
||||
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLSettings &settings;
|
||||
std::vector<Sprite> sprites;
|
||||
|
||||
|
@ -48,63 +48,63 @@ namespace spades {
|
||||
minLod = 0;
|
||||
maxLod = 15;
|
||||
|
||||
colorTexture = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture2D, colorTexture);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGB, textureSize, textureSize, 0,
|
||||
colorTexture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, colorTexture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGB, textureSize, textureSize, 0,
|
||||
IGLDevice::RGB, IGLDevice::UnsignedByte, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
texture = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture2D, texture);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24, textureSize,
|
||||
texture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, texture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24, textureSize,
|
||||
textureSize, 0, IGLDevice::DepthComponent, IGLDevice::UnsignedInt,
|
||||
NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
pagetableTexture = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture2D, pagetableTexture);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, Tiles, Tiles, 0,
|
||||
pagetableTexture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, pagetableTexture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, Tiles, Tiles, 0,
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
framebuffer = device->GenFramebuffer();
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, framebuffer);
|
||||
device->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
framebuffer = device.GenFramebuffer();
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, framebuffer);
|
||||
device.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::ColorAttachment0,
|
||||
IGLDevice::Texture2D, colorTexture, 0);
|
||||
device->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
device.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, texture, 0);
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, 0);
|
||||
}
|
||||
|
||||
GLSparseShadowMapRenderer::~GLSparseShadowMapRenderer() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device->DeleteTexture(texture);
|
||||
device->DeleteTexture(pagetableTexture);
|
||||
device->DeleteFramebuffer(framebuffer);
|
||||
device->DeleteTexture(colorTexture);
|
||||
device.DeleteTexture(texture);
|
||||
device.DeleteTexture(pagetableTexture);
|
||||
device.DeleteFramebuffer(framebuffer);
|
||||
device.DeleteTexture(colorTexture);
|
||||
}
|
||||
|
||||
#define Segment GLSSMRSegment
|
||||
@ -241,7 +241,7 @@ namespace spades {
|
||||
void GLSparseShadowMapRenderer::Render() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
IGLDevice::Integer lastFb = device->GetInteger(IGLDevice::FramebufferBinding);
|
||||
IGLDevice::Integer lastFb = device.GetInteger(IGLDevice::FramebufferBinding);
|
||||
|
||||
// client::SceneDefinition def = GetRenderer()->GetSceneDef();
|
||||
|
||||
@ -250,16 +250,16 @@ namespace spades {
|
||||
|
||||
BuildMatrix(nearDist, farDist);
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, framebuffer);
|
||||
device->Viewport(0, 0, textureSize, textureSize);
|
||||
device->ClearDepth(1.f);
|
||||
device->Clear(IGLDevice::DepthBufferBit);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, framebuffer);
|
||||
device.Viewport(0, 0, textureSize, textureSize);
|
||||
device.ClearDepth(1.f);
|
||||
device.Clear(IGLDevice::DepthBufferBit);
|
||||
|
||||
RenderShadowMapPass();
|
||||
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, lastFb);
|
||||
|
||||
device->Viewport(0, 0, device->ScreenWidth(), device->ScreenHeight());
|
||||
device.Viewport(0, 0, device.ScreenWidth(), device.ScreenHeight());
|
||||
}
|
||||
|
||||
#pragma mark - Sparse Processor
|
||||
@ -750,8 +750,8 @@ namespace spades {
|
||||
|
||||
{
|
||||
GLProfiler::Context profiler(GetRenderer()->GetGLProfiler(), "Page Table Upload");
|
||||
device->BindTexture(IGLDevice::Texture2D, pagetableTexture);
|
||||
device->TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, Tiles, Tiles, IGLDevice::BGRA,
|
||||
device.BindTexture(IGLDevice::Texture2D, pagetableTexture);
|
||||
device.TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, Tiles, Tiles, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, pagetable);
|
||||
}
|
||||
|
||||
@ -761,7 +761,7 @@ namespace spades {
|
||||
ModelRenderer mrend;
|
||||
for (size_t i = 0; i < itnl.groups.size(); i++) {
|
||||
Internal::Group &g = itnl.groups[i];
|
||||
device->Viewport(g.rawX, g.rawY, g.rawW, g.rawH);
|
||||
device.Viewport(g.rawX, g.rawY, g.rawW, g.rawH);
|
||||
|
||||
Vector3 dest1 = Internal::TileToShadowMapCoord(g.tile1);
|
||||
Vector3 dest2 = Internal::TileToShadowMapCoord(g.tile2);
|
||||
|
@ -37,7 +37,7 @@ namespace spades {
|
||||
|
||||
enum { Tiles = 64 };
|
||||
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLSettings &settings;
|
||||
|
||||
int textureSize;
|
||||
|
@ -118,11 +118,11 @@ namespace spades {
|
||||
upVector.SetValue(def.viewAxis[1].x, def.viewAxis[1].y, def.viewAxis[1].z);
|
||||
texture.SetValue(0);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device->EnableVertexAttribArray(spritePosAttribute(), true);
|
||||
device->EnableVertexAttribArray(colorAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(spritePosAttribute(), true);
|
||||
device.EnableVertexAttribArray(colorAttribute(), true);
|
||||
|
||||
for (size_t i = 0; i < sprites.size(); i++) {
|
||||
Sprite &spr = sprites[i];
|
||||
@ -167,9 +167,9 @@ namespace spades {
|
||||
|
||||
Flush();
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->EnableVertexAttribArray(spritePosAttribute(), false);
|
||||
device->EnableVertexAttribArray(colorAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(spritePosAttribute(), false);
|
||||
device.EnableVertexAttribArray(colorAttribute(), false);
|
||||
}
|
||||
|
||||
void GLSpriteRenderer::Flush() {
|
||||
@ -178,17 +178,17 @@ namespace spades {
|
||||
if (vertices.empty())
|
||||
return;
|
||||
|
||||
device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(positionAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].x));
|
||||
device->VertexAttribPointer(spritePosAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(spritePosAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].sx));
|
||||
device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::FloatType, false,
|
||||
device.VertexAttribPointer(colorAttribute(), 4, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), &(vertices[0].r));
|
||||
|
||||
SPAssert(lastImage);
|
||||
lastImage->Bind(IGLDevice::Texture2D);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
device.DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(indices.size()),
|
||||
IGLDevice::UnsignedInt, indices.data());
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace spades {
|
||||
};
|
||||
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLSettings &settings;
|
||||
std::vector<Sprite> sprites;
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
*/
|
||||
|
||||
#include "GLVoxelModel.h"
|
||||
#include <Core/Debug.h>
|
||||
#include "GLDynamicLightShader.h"
|
||||
#include "GLImage.h"
|
||||
#include "GLProgram.h"
|
||||
@ -29,6 +28,7 @@
|
||||
#include "GLShadowMapShader.h"
|
||||
#include "GLShadowShader.h"
|
||||
#include "IGLShadowMapRenderer.h"
|
||||
#include <Core/Debug.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -38,11 +38,10 @@ namespace spades {
|
||||
renderer->RegisterProgram("Shaders/VoxelModelShadowMap.program");
|
||||
renderer->RegisterImage("Gfx/AmbientOcclusion.png");
|
||||
}
|
||||
GLVoxelModel::GLVoxelModel(VoxelModel *m, GLRenderer *r) {
|
||||
GLVoxelModel::GLVoxelModel(VoxelModel *m, GLRenderer *r) : device(r->GetGLDevice()) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
renderer = r;
|
||||
device = r->GetGLDevice();
|
||||
|
||||
program = renderer->RegisterProgram("Shaders/VoxelModel.program");
|
||||
dlightProgram = renderer->RegisterProgram("Shaders/VoxelModelDynamicLit.program");
|
||||
@ -51,18 +50,18 @@ namespace spades {
|
||||
|
||||
BuildVertices(m);
|
||||
|
||||
buffer = device->GenBuffer();
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(vertices.size() * sizeof(Vertex)),
|
||||
vertices.data(), IGLDevice::StaticDraw);
|
||||
buffer = device.GenBuffer();
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(vertices.size() * sizeof(Vertex)),
|
||||
vertices.data(), IGLDevice::StaticDraw);
|
||||
|
||||
idxBuffer = device->GenBuffer();
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, idxBuffer);
|
||||
device->BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(indices.size() * sizeof(uint32_t)),
|
||||
indices.data(), IGLDevice::StaticDraw);
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
idxBuffer = device.GenBuffer();
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, idxBuffer);
|
||||
device.BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(indices.size() * sizeof(uint32_t)),
|
||||
indices.data(), IGLDevice::StaticDraw);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
origin = m->GetOrigin();
|
||||
origin -= .5f; // (0,0,0) is center of voxel (0,0,0)
|
||||
@ -87,8 +86,8 @@ namespace spades {
|
||||
GLVoxelModel::~GLVoxelModel() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device->DeleteBuffer(idxBuffer);
|
||||
device->DeleteBuffer(buffer);
|
||||
device.DeleteBuffer(idxBuffer);
|
||||
device.DeleteBuffer(buffer);
|
||||
}
|
||||
|
||||
uint8_t GLVoxelModel::calcAOID(VoxelModel *m, int x, int y, int z, int ux, int uy, int uz,
|
||||
@ -266,8 +265,8 @@ namespace spades {
|
||||
void GLVoxelModel::RenderShadowMapPass(std::vector<client::ModelRenderParam> params) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
|
||||
shadowMapProgram->Use();
|
||||
|
||||
@ -285,20 +284,20 @@ namespace spades {
|
||||
positionAttribute(shadowMapProgram);
|
||||
normalAttribute(shadowMapProgram);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
if (normalAttribute() != -1) {
|
||||
device->VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)12);
|
||||
device.VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)12);
|
||||
}
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
if (normalAttribute() != -1)
|
||||
device->EnableVertexAttribArray(normalAttribute(), true);
|
||||
device.EnableVertexAttribArray(normalAttribute(), true);
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
|
||||
for (size_t i = 0; i < params.size(); i++) {
|
||||
const client::ModelRenderParam ¶m = params[i];
|
||||
@ -331,30 +330,31 @@ namespace spades {
|
||||
modelNormalMatrix(shadowMapProgram);
|
||||
modelNormalMatrix.SetValue(modelMatrix);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
device.DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
}
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
if (normalAttribute() != -1)
|
||||
device->EnableVertexAttribArray(normalAttribute(), false);
|
||||
device.EnableVertexAttribArray(normalAttribute(), false);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
void GLVoxelModel::RenderSunlightPass(std::vector<client::ModelRenderParam> params, bool ghostPass) {
|
||||
void GLVoxelModel::RenderSunlightPass(std::vector<client::ModelRenderParam> params,
|
||||
bool ghostPass) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
aoImage->Bind(IGLDevice::Texture2D);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
|
||||
program->Use();
|
||||
|
||||
@ -401,23 +401,23 @@ namespace spades {
|
||||
colorAttribute(program);
|
||||
normalAttribute(program);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device->VertexAttribPointer(textureCoordAttribute(), 2, IGLDevice::UnsignedShort, false,
|
||||
sizeof(Vertex), (void *)4);
|
||||
device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::UnsignedByte, true,
|
||||
sizeof(Vertex), (void *)8);
|
||||
device->VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)12);
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device.VertexAttribPointer(textureCoordAttribute(), 2, IGLDevice::UnsignedShort, false,
|
||||
sizeof(Vertex), (void *)4);
|
||||
device.VertexAttribPointer(colorAttribute(), 4, IGLDevice::UnsignedByte, true,
|
||||
sizeof(Vertex), (void *)8);
|
||||
device.VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false, sizeof(Vertex),
|
||||
(void *)12);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device->EnableVertexAttribArray(textureCoordAttribute(), true);
|
||||
device->EnableVertexAttribArray(colorAttribute(), true);
|
||||
device->EnableVertexAttribArray(normalAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(textureCoordAttribute(), true);
|
||||
device.EnableVertexAttribArray(colorAttribute(), true);
|
||||
device.EnableVertexAttribArray(normalAttribute(), true);
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
|
||||
for (size_t i = 0; i < params.size(); i++) {
|
||||
const client::ModelRenderParam ¶m = params[i];
|
||||
@ -463,35 +463,35 @@ namespace spades {
|
||||
modelOpacity.SetValue(param.opacity);
|
||||
|
||||
if (param.depthHack) {
|
||||
device->DepthRange(0.f, 0.1f);
|
||||
device.DepthRange(0.f, 0.1f);
|
||||
}
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
device.DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
if (param.depthHack) {
|
||||
device->DepthRange(0.f, 1.f);
|
||||
device.DepthRange(0.f, 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->EnableVertexAttribArray(textureCoordAttribute(), false);
|
||||
device->EnableVertexAttribArray(colorAttribute(), false);
|
||||
device->EnableVertexAttribArray(normalAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(textureCoordAttribute(), false);
|
||||
device.EnableVertexAttribArray(colorAttribute(), false);
|
||||
device.EnableVertexAttribArray(normalAttribute(), false);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, 0);
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, 0);
|
||||
}
|
||||
|
||||
void GLVoxelModel::RenderDynamicLightPass(std::vector<client::ModelRenderParam> params,
|
||||
std::vector<GLDynamicLight> lights) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
|
||||
device->Enable(IGLDevice::CullFace, true);
|
||||
device->Enable(IGLDevice::DepthTest, true);
|
||||
device.Enable(IGLDevice::CullFace, true);
|
||||
device.Enable(IGLDevice::DepthTest, true);
|
||||
|
||||
dlightProgram->Use();
|
||||
|
||||
@ -525,20 +525,20 @@ namespace spades {
|
||||
colorAttribute(dlightProgram);
|
||||
normalAttribute(dlightProgram);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device->VertexAttribPointer(colorAttribute(), 4, IGLDevice::UnsignedByte, true,
|
||||
sizeof(Vertex), (void *)8);
|
||||
device->VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false,
|
||||
sizeof(Vertex), (void *)12);
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 4, IGLDevice::UnsignedByte, false,
|
||||
sizeof(Vertex), (void *)0);
|
||||
device.VertexAttribPointer(colorAttribute(), 4, IGLDevice::UnsignedByte, true,
|
||||
sizeof(Vertex), (void *)8);
|
||||
device.VertexAttribPointer(normalAttribute(), 3, IGLDevice::Byte, false, sizeof(Vertex),
|
||||
(void *)12);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device->EnableVertexAttribArray(colorAttribute(), true);
|
||||
device->EnableVertexAttribArray(normalAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(colorAttribute(), true);
|
||||
device.EnableVertexAttribArray(normalAttribute(), true);
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
|
||||
for (size_t i = 0; i < params.size(); i++) {
|
||||
const client::ModelRenderParam ¶m = params[i];
|
||||
@ -579,7 +579,7 @@ namespace spades {
|
||||
modelNormalMatrix.SetValue(modelMatrix);
|
||||
|
||||
if (param.depthHack) {
|
||||
device->DepthRange(0.f, 0.1f);
|
||||
device.DepthRange(0.f, 0.1f);
|
||||
}
|
||||
for (size_t i = 0; i < lights.size(); i++) {
|
||||
if (!lights[i].SphereCull(param.matrix.GetOrigin(), rad))
|
||||
@ -587,21 +587,21 @@ namespace spades {
|
||||
|
||||
dlightShader(renderer, dlightProgram, lights[i], 0);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
device.DrawElements(IGLDevice::Triangles, numIndices, IGLDevice::UnsignedInt,
|
||||
(void *)0);
|
||||
}
|
||||
if (param.depthHack) {
|
||||
device->DepthRange(0.f, 1.f);
|
||||
device.DepthRange(0.f, 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device->EnableVertexAttribArray(colorAttribute(), false);
|
||||
device->EnableVertexAttribArray(normalAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(colorAttribute(), false);
|
||||
device.EnableVertexAttribArray(normalAttribute(), false);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -48,7 +48,7 @@ namespace spades {
|
||||
};
|
||||
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLProgram *program;
|
||||
GLProgram *dlightProgram;
|
||||
GLProgram *shadowMapProgram;
|
||||
|
@ -23,10 +23,6 @@
|
||||
|
||||
#include <kiss_fft130/kiss_fft.h>
|
||||
|
||||
#include <Client/GameMap.h>
|
||||
#include <Core/ConcurrentDispatch.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Settings.h>
|
||||
#include "GLFramebufferManager.h"
|
||||
#include "GLImage.h"
|
||||
#include "GLProfiler.h"
|
||||
@ -37,6 +33,10 @@
|
||||
#include "GLShadowShader.h"
|
||||
#include "GLWaterRenderer.h"
|
||||
#include "IGLDevice.h"
|
||||
#include <Client/GameMap.h>
|
||||
#include <Core/ConcurrentDispatch.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <Core/Settings.h>
|
||||
|
||||
namespace spades {
|
||||
namespace draw {
|
||||
@ -422,7 +422,7 @@ namespace spades {
|
||||
int count = (int)floorf(dt * 600.f);
|
||||
if (count > 400)
|
||||
count = 400;
|
||||
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int ox = SampleRandomInt(0, size - 3);
|
||||
int oy = SampleRandomInt(0, size - 3);
|
||||
@ -469,36 +469,36 @@ namespace spades {
|
||||
program = renderer->RegisterProgram("Shaders/Water.program");
|
||||
BuildVertices();
|
||||
|
||||
tempDepthTexture = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture2D, tempDepthTexture);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24,
|
||||
device->ScreenWidth(), device->ScreenHeight(), 0,
|
||||
IGLDevice::DepthComponent, IGLDevice::UnsignedInt, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
tempDepthTexture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, tempDepthTexture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::DepthComponent24,
|
||||
device.ScreenWidth(), device.ScreenHeight(), 0,
|
||||
IGLDevice::DepthComponent, IGLDevice::UnsignedInt, NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::ClampToEdge);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::ClampToEdge);
|
||||
|
||||
tempFramebuffer = device->GenFramebuffer();
|
||||
device->BindFramebuffer(IGLDevice::Framebuffer, tempFramebuffer);
|
||||
device->FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, tempDepthTexture, 0);
|
||||
tempFramebuffer = device.GenFramebuffer();
|
||||
device.BindFramebuffer(IGLDevice::Framebuffer, tempFramebuffer);
|
||||
device.FramebufferTexture2D(IGLDevice::Framebuffer, IGLDevice::DepthAttachment,
|
||||
IGLDevice::Texture2D, tempDepthTexture, 0);
|
||||
|
||||
// create water color texture
|
||||
texture = device->GenTexture();
|
||||
device->BindTexture(IGLDevice::Texture2D, texture);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, map->Width(),
|
||||
map->Height(), 0, IGLDevice::RGBA, IGLDevice::UnsignedByte, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
texture = device.GenTexture();
|
||||
device.BindTexture(IGLDevice::Texture2D, texture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8, map->Width(),
|
||||
map->Height(), 0, IGLDevice::RGBA, IGLDevice::UnsignedByte, NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS, IGLDevice::Repeat);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT, IGLDevice::Repeat);
|
||||
|
||||
w = map->Width();
|
||||
h = map->Height();
|
||||
@ -510,13 +510,11 @@ namespace spades {
|
||||
std::fill(updateBitmap.begin(), updateBitmap.end(), 0xffffffffUL);
|
||||
std::fill(bitmap.begin(), bitmap.end(), 0xffffffffUL);
|
||||
|
||||
device->TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, w, h, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, bitmap.data());
|
||||
|
||||
device.TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, w, h, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, bitmap.data());
|
||||
|
||||
size_t numLayers = ((int)settings.r_water >= 2) ? 3 : 1;
|
||||
|
||||
|
||||
// create wave tank simlation
|
||||
for (size_t i = 0; i < numLayers; i++) {
|
||||
if ((int)settings.r_water >= 3) {
|
||||
@ -525,42 +523,43 @@ namespace spades {
|
||||
waveTanks.push_back(new FFTWaveTank<7>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create heightmap texture
|
||||
waveTexture = device->GenTexture();
|
||||
waveTexture = device.GenTexture();
|
||||
if (numLayers == 1) {
|
||||
device->BindTexture(IGLDevice::Texture2D, waveTexture);
|
||||
device->TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8,
|
||||
waveTanks[0]->GetSize(), waveTanks[0]->GetSize(), 0,
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::LinearMipmapLinear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::Repeat);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::Repeat);
|
||||
device.BindTexture(IGLDevice::Texture2D, waveTexture);
|
||||
device.TexImage2D(IGLDevice::Texture2D, 0, IGLDevice::RGBA8,
|
||||
waveTanks[0]->GetSize(), waveTanks[0]->GetSize(), 0,
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte, NULL);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::LinearMipmapLinear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapS,
|
||||
IGLDevice::Repeat);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureWrapT,
|
||||
IGLDevice::Repeat);
|
||||
if (settings.r_maxAnisotropy > 1.0f) {
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMaxAnisotropy,
|
||||
(float)settings.r_maxAnisotropy);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMaxAnisotropy,
|
||||
(float)settings.r_maxAnisotropy);
|
||||
}
|
||||
} else {
|
||||
device->BindTexture(IGLDevice::Texture2DArray, waveTexture);
|
||||
device->TexImage3D(IGLDevice::Texture2DArray, 0, IGLDevice::RGBA8,
|
||||
waveTanks[0]->GetSize(), waveTanks[0]->GetSize(), static_cast<IGLDevice::Sizei>(numLayers), 0,
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte, NULL);
|
||||
device->TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::LinearMipmapLinear);
|
||||
device->TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureWrapS,
|
||||
IGLDevice::Repeat);
|
||||
device->TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureWrapT,
|
||||
IGLDevice::Repeat);
|
||||
device.BindTexture(IGLDevice::Texture2DArray, waveTexture);
|
||||
device.TexImage3D(IGLDevice::Texture2DArray, 0, IGLDevice::RGBA8,
|
||||
waveTanks[0]->GetSize(), waveTanks[0]->GetSize(),
|
||||
static_cast<IGLDevice::Sizei>(numLayers), 0, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, NULL);
|
||||
device.TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::LinearMipmapLinear);
|
||||
device.TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureWrapS,
|
||||
IGLDevice::Repeat);
|
||||
device.TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureWrapT,
|
||||
IGLDevice::Repeat);
|
||||
if (settings.r_maxAnisotropy > 1.0f) {
|
||||
device->TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureMaxAnisotropy,
|
||||
(float)settings.r_maxAnisotropy);
|
||||
device.TexParamater(IGLDevice::Texture2DArray, IGLDevice::TextureMaxAnisotropy,
|
||||
(float)settings.r_maxAnisotropy);
|
||||
}
|
||||
}
|
||||
|
||||
@ -606,37 +605,37 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
buffer = device->GenBuffer();
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(sizeof(Vertex) * vertices.size()),
|
||||
vertices.data(), IGLDevice::StaticDraw);
|
||||
idxBuffer = device->GenBuffer();
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, idxBuffer);
|
||||
device->BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(sizeof(uint32_t) * indices.size()),
|
||||
indices.data(), IGLDevice::StaticDraw);
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
buffer = device.GenBuffer();
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(sizeof(Vertex) * vertices.size()),
|
||||
vertices.data(), IGLDevice::StaticDraw);
|
||||
idxBuffer = device.GenBuffer();
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, idxBuffer);
|
||||
device.BufferData(IGLDevice::ArrayBuffer,
|
||||
static_cast<IGLDevice::Sizei>(sizeof(uint32_t) * indices.size()),
|
||||
indices.data(), IGLDevice::StaticDraw);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
numIndices = indices.size();
|
||||
}
|
||||
|
||||
GLWaterRenderer::~GLWaterRenderer() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
device->DeleteBuffer(buffer);
|
||||
device->DeleteBuffer(idxBuffer);
|
||||
device->DeleteFramebuffer(tempFramebuffer);
|
||||
device->DeleteTexture(tempDepthTexture);
|
||||
device->DeleteTexture(texture);
|
||||
device.DeleteBuffer(buffer);
|
||||
device.DeleteBuffer(idxBuffer);
|
||||
device.DeleteFramebuffer(tempFramebuffer);
|
||||
device.DeleteTexture(tempDepthTexture);
|
||||
device.DeleteTexture(texture);
|
||||
|
||||
if (occlusionQuery)
|
||||
device->DeleteQuery(occlusionQuery);
|
||||
device.DeleteQuery(occlusionQuery);
|
||||
|
||||
for (size_t i = 0; i < waveTanks.size(); i++) {
|
||||
waveTanks[i]->Join();
|
||||
delete waveTanks[i];
|
||||
}
|
||||
device->DeleteTexture(waveTexture);
|
||||
device.DeleteTexture(waveTexture);
|
||||
}
|
||||
|
||||
void GLWaterRenderer::Render() {
|
||||
@ -645,7 +644,7 @@ namespace spades {
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Render");
|
||||
|
||||
if (occlusionQuery == 0 && settings.r_occlusionQuery)
|
||||
occlusionQuery = device->GenQuery();
|
||||
occlusionQuery = device.GenQuery();
|
||||
|
||||
GLColorBuffer colorBuffer;
|
||||
|
||||
@ -672,8 +671,8 @@ namespace spades {
|
||||
GLProfiler::Context profiler2(renderer->GetGLProfiler(), "Draw Plane");
|
||||
|
||||
// do color
|
||||
device->DepthFunc(IGLDevice::Less);
|
||||
device->ColorMask(true, true, true, true);
|
||||
device.DepthFunc(IGLDevice::Less);
|
||||
device.ColorMask(true, true, true, true);
|
||||
{
|
||||
GLProgram *prg = program;
|
||||
prg->Use();
|
||||
@ -743,49 +742,49 @@ namespace spades {
|
||||
mirrorTexture(prg);
|
||||
mirrorDepthTexture(prg);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device->BindTexture(IGLDevice::Texture2D, colorBuffer.GetTexture());
|
||||
device.ActiveTexture(0);
|
||||
device.BindTexture(IGLDevice::Texture2D, colorBuffer.GetTexture());
|
||||
screenTexture.SetValue(0);
|
||||
// depth is not interpolated, so color shouldn't be
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Nearest);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Nearest);
|
||||
|
||||
device->ActiveTexture(1);
|
||||
device->BindTexture(IGLDevice::Texture2D, tempDepthTexture);
|
||||
device.ActiveTexture(1);
|
||||
device.BindTexture(IGLDevice::Texture2D, tempDepthTexture);
|
||||
depthTexture.SetValue(1);
|
||||
|
||||
device->ActiveTexture(2);
|
||||
device->BindTexture(IGLDevice::Texture2D, texture);
|
||||
device.ActiveTexture(2);
|
||||
device.BindTexture(IGLDevice::Texture2D, texture);
|
||||
textureUnif.SetValue(2);
|
||||
|
||||
static GLShadowShader shadowShader;
|
||||
|
||||
if (waveTanks.size() == 1) {
|
||||
device->ActiveTexture(3);
|
||||
device->BindTexture(IGLDevice::Texture2D, waveTexture);
|
||||
device.ActiveTexture(3);
|
||||
device.BindTexture(IGLDevice::Texture2D, waveTexture);
|
||||
waveTextureUnif.SetValue(3);
|
||||
|
||||
shadowShader(renderer, prg, 4);
|
||||
} else if (waveTanks.size() == 3) {
|
||||
device->ActiveTexture(3);
|
||||
device->BindTexture(IGLDevice::Texture2DArray, waveTexture);
|
||||
device.ActiveTexture(3);
|
||||
device.BindTexture(IGLDevice::Texture2DArray, waveTexture);
|
||||
waveTextureArrayUnif.SetValue(3);
|
||||
|
||||
// mirror
|
||||
device->ActiveTexture(4);
|
||||
device->BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetMirrorTexture());
|
||||
device.ActiveTexture(4);
|
||||
device.BindTexture(IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetMirrorTexture());
|
||||
if ((float)settings.r_maxAnisotropy > 1.1f) {
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMaxAnisotropy,
|
||||
(float)settings.r_maxAnisotropy);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMaxAnisotropy,
|
||||
(float)settings.r_maxAnisotropy);
|
||||
}
|
||||
mirrorTexture.SetValue(4);
|
||||
|
||||
if ((int)settings.r_water >= 3) {
|
||||
device->ActiveTexture(5);
|
||||
device->BindTexture(
|
||||
device.ActiveTexture(5);
|
||||
device.BindTexture(
|
||||
IGLDevice::Texture2D,
|
||||
renderer->GetFramebufferManager()->GetMirrorDepthTexture());
|
||||
mirrorDepthTexture.SetValue(5);
|
||||
@ -802,35 +801,34 @@ namespace spades {
|
||||
|
||||
positionAttribute(prg);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), true);
|
||||
device.EnableVertexAttribArray(positionAttribute(), true);
|
||||
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device->VertexAttribPointer(positionAttribute(), 2, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), NULL);
|
||||
device->BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, buffer);
|
||||
device.VertexAttribPointer(positionAttribute(), 2, IGLDevice::FloatType, false,
|
||||
sizeof(Vertex), NULL);
|
||||
device.BindBuffer(IGLDevice::ArrayBuffer, 0);
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, idxBuffer);
|
||||
|
||||
if (occlusionQuery)
|
||||
device->BeginQuery(IGLDevice::SamplesPassed, occlusionQuery);
|
||||
device.BeginQuery(IGLDevice::SamplesPassed, occlusionQuery);
|
||||
|
||||
device->DrawElements(IGLDevice::Triangles,
|
||||
static_cast<IGLDevice::Sizei>(numIndices),
|
||||
IGLDevice::UnsignedInt, NULL);
|
||||
device.DrawElements(IGLDevice::Triangles, static_cast<IGLDevice::Sizei>(numIndices),
|
||||
IGLDevice::UnsignedInt, NULL);
|
||||
|
||||
if (occlusionQuery)
|
||||
device->EndQuery(IGLDevice::SamplesPassed);
|
||||
device.EndQuery(IGLDevice::SamplesPassed);
|
||||
|
||||
device->BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
device.BindBuffer(IGLDevice::ElementArrayBuffer, 0);
|
||||
|
||||
device->EnableVertexAttribArray(positionAttribute(), false);
|
||||
device.EnableVertexAttribArray(positionAttribute(), false);
|
||||
|
||||
device->ActiveTexture(0);
|
||||
device.ActiveTexture(0);
|
||||
// restore filter mode for color buffer
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device->TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMagFilter,
|
||||
IGLDevice::Linear);
|
||||
device.TexParamater(IGLDevice::Texture2D, IGLDevice::TextureMinFilter,
|
||||
IGLDevice::Linear);
|
||||
}
|
||||
}
|
||||
|
||||
@ -850,7 +848,8 @@ namespace spades {
|
||||
|
||||
// update wavetank simulation
|
||||
{
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Waiting for Simulation To Done");
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(),
|
||||
"Waiting for Simulation To Done");
|
||||
for (size_t i = 0; i < waveTanks.size(); i++) {
|
||||
waveTanks[i]->Join();
|
||||
}
|
||||
@ -859,29 +858,28 @@ namespace spades {
|
||||
{
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Upload");
|
||||
if (waveTanks.size() == 1) {
|
||||
device->BindTexture(IGLDevice::Texture2D, waveTexture);
|
||||
device->TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0,
|
||||
waveTanks[0]->GetSize(), waveTanks[0]->GetSize(),
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte,
|
||||
waveTanks[0]->GetBitmap());
|
||||
device.BindTexture(IGLDevice::Texture2D, waveTexture);
|
||||
device.TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, waveTanks[0]->GetSize(),
|
||||
waveTanks[0]->GetSize(), IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, waveTanks[0]->GetBitmap());
|
||||
} else {
|
||||
device->BindTexture(IGLDevice::Texture2DArray, waveTexture);
|
||||
device.BindTexture(IGLDevice::Texture2DArray, waveTexture);
|
||||
for (size_t i = 0; i < waveTanks.size(); i++) {
|
||||
device->TexSubImage3D(IGLDevice::Texture2DArray, 0, 0, 0, static_cast<IGLDevice::Sizei>(i),
|
||||
waveTanks[i]->GetSize(), waveTanks[i]->GetSize(), 1,
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte,
|
||||
waveTanks[i]->GetBitmap());
|
||||
device.TexSubImage3D(
|
||||
IGLDevice::Texture2DArray, 0, 0, 0, static_cast<IGLDevice::Sizei>(i),
|
||||
waveTanks[i]->GetSize(), waveTanks[i]->GetSize(), 1, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, waveTanks[i]->GetBitmap());
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Generate Mipmap");
|
||||
if (waveTanks.size() == 1) {
|
||||
device->BindTexture(IGLDevice::Texture2D, waveTexture);
|
||||
device->GenerateMipmap(IGLDevice::Texture2D);
|
||||
device.BindTexture(IGLDevice::Texture2D, waveTexture);
|
||||
device.GenerateMipmap(IGLDevice::Texture2D);
|
||||
} else {
|
||||
device->BindTexture(IGLDevice::Texture2DArray, waveTexture);
|
||||
device->GenerateMipmap(IGLDevice::Texture2DArray);
|
||||
device.BindTexture(IGLDevice::Texture2DArray, waveTexture);
|
||||
device.GenerateMipmap(IGLDevice::Texture2DArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -895,8 +893,9 @@ namespace spades {
|
||||
}
|
||||
|
||||
{
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(), "Upload Water Color Texture");
|
||||
device->BindTexture(IGLDevice::Texture2D, texture);
|
||||
GLProfiler::Context profiler(renderer->GetGLProfiler(),
|
||||
"Upload Water Color Texture");
|
||||
device.BindTexture(IGLDevice::Texture2D, texture);
|
||||
bool fullUpdate = true;
|
||||
for (size_t i = 0; i < updateBitmap.size(); i++) {
|
||||
if (updateBitmap[i] == 0) {
|
||||
@ -930,8 +929,8 @@ namespace spades {
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
device->TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, w, h, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, bitmap.data());
|
||||
device.TexSubImage2D(IGLDevice::Texture2D, 0, 0, 0, w, h, IGLDevice::BGRA,
|
||||
IGLDevice::UnsignedByte, bitmap.data());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < updateBitmap.size(); i++) {
|
||||
@ -961,8 +960,8 @@ namespace spades {
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
device->TexSubImage2D(IGLDevice::Texture2D, 0, x, y, 32, 1,
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte, pixels);
|
||||
device.TexSubImage2D(IGLDevice::Texture2D, 0, x, y, 32, 1,
|
||||
IGLDevice::BGRA, IGLDevice::UnsignedByte, pixels);
|
||||
}
|
||||
|
||||
updateBitmap[i] = 0;
|
||||
@ -985,5 +984,5 @@ namespace spades {
|
||||
return;
|
||||
MarkUpdate(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace draw
|
||||
} // namespace spades
|
||||
|
@ -41,7 +41,7 @@ namespace spades {
|
||||
class FFTWaveTank;
|
||||
|
||||
GLRenderer *renderer;
|
||||
IGLDevice *device;
|
||||
IGLDevice &device;
|
||||
GLSettings &settings;
|
||||
client::GameMap *map;
|
||||
|
||||
|
@ -49,9 +49,9 @@ namespace spades {
|
||||
SWFlatMapRenderer(SWRenderer *r, Handle<client::GameMap>);
|
||||
~SWFlatMapRenderer();
|
||||
|
||||
SWImage *GetImage() {
|
||||
SWImage &GetImage() {
|
||||
Update();
|
||||
return img;
|
||||
return *img;
|
||||
}
|
||||
|
||||
void Update(bool firstTime = false);
|
||||
|
@ -280,17 +280,16 @@ namespace spades {
|
||||
const Vertex &v3, SWImageRenderer &r) {
|
||||
// TODO: support null image
|
||||
|
||||
Bitmap *const fb = r.frame;
|
||||
SPAssert(fb != nullptr);
|
||||
Bitmap &fb = *r.frame;
|
||||
|
||||
if (v3.position.y <= 0.f) {
|
||||
// viewport cull
|
||||
return;
|
||||
}
|
||||
|
||||
const int fbW = fb->GetWidth();
|
||||
const int fbH = fb->GetHeight();
|
||||
uint32_t *const bmp = fb->GetPixels();
|
||||
const int fbW = fb.GetWidth();
|
||||
const int fbH = fb.GetHeight();
|
||||
uint32_t *const bmp = fb.GetPixels();
|
||||
|
||||
if (v1.position.y >= static_cast<float>(fbH)) {
|
||||
// viewport cull
|
||||
@ -546,17 +545,16 @@ namespace spades {
|
||||
static void DrawPolygonInternalInner(SWImage *img, const Vertex &v1, const Vertex &v2,
|
||||
const Vertex &v3, SWImageRenderer &r) {
|
||||
|
||||
Bitmap *const fb = r.frame;
|
||||
SPAssert(fb != nullptr);
|
||||
Bitmap &fb = *r.frame;
|
||||
|
||||
if (v3.position.y <= 0.f) {
|
||||
// viewport cull
|
||||
return;
|
||||
}
|
||||
|
||||
const int fbW = fb->GetWidth();
|
||||
const int fbH = fb->GetHeight();
|
||||
uint32_t *const bmp = fb->GetPixels();
|
||||
const int fbW = fb.GetWidth();
|
||||
const int fbH = fb.GetHeight();
|
||||
uint32_t *const bmp = fb.GetPixels();
|
||||
|
||||
if (v1.position.y >= static_cast<float>(fbH)) {
|
||||
// viewport cull
|
||||
@ -980,17 +978,16 @@ namespace spades {
|
||||
static void DrawPolygonInternalInner(SWImage *img, const Vertex &v1, const Vertex &v2,
|
||||
const Vertex &v3, SWImageRenderer &r) {
|
||||
|
||||
Bitmap *const fb = r.frame;
|
||||
SPAssert(fb != nullptr);
|
||||
Bitmap &fb = *r.frame;
|
||||
|
||||
if (v3.position.y <= 0.f) {
|
||||
// viewport cull
|
||||
return;
|
||||
}
|
||||
|
||||
const int fbW = fb->GetWidth();
|
||||
const int fbH = fb->GetHeight();
|
||||
uint32_t *const bmp = fb->GetPixels();
|
||||
const int fbW = fb.GetWidth();
|
||||
const int fbH = fb.GetHeight();
|
||||
uint32_t *const bmp = fb.GetPixels();
|
||||
|
||||
if (v1.position.y >= static_cast<float>(fbH)) {
|
||||
// viewport cull
|
||||
@ -1442,7 +1439,7 @@ namespace spades {
|
||||
|
||||
void SWImageRenderer::DrawPolygon(SWImage *img, const Vertex &v1, const Vertex &v2,
|
||||
const Vertex &v3) {
|
||||
SPAssert(frame != nullptr);
|
||||
SPAssert(frame);
|
||||
switch (shader) {
|
||||
case ShaderType::Sprite:
|
||||
PolygonRenderer2<true, // needs transform
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user