Celestia

Форк
0
/
multitexture.cpp 
109 строк · 3.0 Кб
1
// multirestexture.cpp
2
//
3
// Copyright (C) 2002 Deon Ramsey <dramsey@sourceforge.net>
4
//
5
// This program is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU General Public License
7
// as published by the Free Software Foundation; either version 2
8
// of the License, or (at your option) any later version.
9

10
#include "multitexture.h"
11
#include "texmanager.h"
12

13
using namespace std;
14

15

16
MultiResTexture::MultiResTexture()
17
{
18
    tex[lores] = InvalidResource;
19
    tex[medres] = InvalidResource;
20
    tex[hires] = InvalidResource;
21
}
22

23

24
MultiResTexture::MultiResTexture(ResourceHandle loTex,
25
                                 ResourceHandle medTex,
26
                                 ResourceHandle hiTex)
27
{
28
    tex[lores] = loTex;
29
    tex[medres] = medTex;
30
    tex[hires] = hiTex;
31
}
32

33

34
MultiResTexture::MultiResTexture(const fs::path& source,
35
                                 const fs::path& path)
36
{
37
    setTexture(source, path);
38
}
39

40

41
void MultiResTexture::setTexture(const fs::path& source,
42
                                 const fs::path& path,
43
                                 unsigned int flags)
44
{
45
    TextureManager* texMan = GetTextureManager();
46
    tex[lores] = texMan->getHandle(TextureInfo(source, path, flags, lores));
47
    tex[medres] = texMan->getHandle(TextureInfo(source, path, flags, medres));
48
    tex[hires] = texMan->getHandle(TextureInfo(source, path, flags, hires));
49
}
50

51

52
void MultiResTexture::setTexture(const fs::path& source,
53
                                 const fs::path& path,
54
                                 float bumpHeight,
55
                                 unsigned int flags)
56
{
57
    TextureManager* texMan = GetTextureManager();
58
    tex[lores] = texMan->getHandle(TextureInfo(source, path, bumpHeight, flags, lores));
59
    tex[medres] = texMan->getHandle(TextureInfo(source, path, bumpHeight, flags, medres));
60
    tex[hires] = texMan->getHandle(TextureInfo(source, path, bumpHeight, flags, hires));
61
}
62

63

64
Texture* MultiResTexture::find(unsigned int resolution)
65
{
66
    TextureManager* texMan = GetTextureManager();
67

68
    Texture* res = texMan->find(tex[resolution]);
69
    if (res != nullptr)
70
        return res;
71

72
    // Preferred resolution isn't available; try the second choice
73
    // Set these to some defaults to avoid GCC complaints
74
    // about possible uninitialized variable usage:
75
    unsigned int secondChoice   = medres;
76
    unsigned int lastResort     = hires;
77
    switch (resolution)
78
    {
79
    case lores:
80
        secondChoice = medres;
81
        lastResort = hires;
82
        break;
83
    case medres:
84
        secondChoice = lores;
85
        lastResort = hires;
86
        break;
87
    case hires:
88
        secondChoice = medres;
89
        lastResort = lores;
90
        break;
91
    }
92

93
    tex[resolution] = tex[secondChoice];
94
    res = texMan->find(tex[resolution]);
95
    if (res != nullptr)
96
        return res;
97

98
    tex[resolution] = tex[lastResort];
99

100
    return texMan->find(tex[resolution]);
101
}
102

103

104
bool MultiResTexture::isValid() const
105
{
106
    return (tex[lores] != InvalidResource ||
107
            tex[medres] != InvalidResource ||
108
            tex[hires] != InvalidResource);
109
}
110

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.