| 930 | |
| 931 | |
| 932 | bool LuaTextureMgr::ParseTexture(lua_State* L, int index) { |
| 933 | // enable/disable for GL_TEXTURE_2D |
| 934 | if (lua_isboolean(L, index)) { |
| 935 | if (lua_tobool(L, index)) { |
| 936 | glEnable(GL_TEXTURE_2D); |
| 937 | } |
| 938 | else { |
| 939 | glDisable(GL_TEXTURE_2D); |
| 940 | } |
| 941 | return true; |
| 942 | } |
| 943 | |
| 944 | // named engine textures |
| 945 | if (lua_israwstring(L, index)) { |
| 946 | const std::string name = lua_tostring(L, index); |
| 947 | if (OpenGLPassState::CreatingList() && !TEXMGR.isLoaded(name)) { |
| 948 | luaL_error(L, "textures can not be created while creating display lists"); |
| 949 | } |
| 950 | const int bzTexID = TEXMGR.getTextureID(name, false); |
| 951 | if (bzTexID < 0) { |
| 952 | glDisable(GL_TEXTURE_2D); |
| 953 | return false; |
| 954 | } |
| 955 | const ImageInfo& ii = TEXMGR.getInfo(bzTexID); |
| 956 | if ((ii.texture == NULL) || !ii.texture->execute()) { |
| 957 | glDisable(GL_TEXTURE_2D); |
| 958 | return false; |
| 959 | } |
| 960 | |
| 961 | glEnable(GL_TEXTURE_2D); |
| 962 | return true; |
| 963 | } |
| 964 | |
| 965 | // lua texture (ref or obj) |
| 966 | const LuaTexture* texture = CheckLuaTexture(L, index); |
| 967 | if ((texture == NULL) || !texture->IsValid()) { |
| 968 | return false; |
| 969 | } |
| 970 | |
| 971 | // enable/disable for lua texture's target |
| 972 | const int stateIndex = index + 1; |
| 973 | if (lua_isboolean(L, stateIndex)) { |
| 974 | if (lua_tobool(L, stateIndex)) { |
| 975 | glEnable(texture->GetTarget()); |
| 976 | } |
| 977 | else { |
| 978 | glDisable(texture->GetTarget()); |
| 979 | } |
| 980 | return true; |
| 981 | } |
| 982 | |
| 983 | // bind a lua texture |
| 984 | if (!texture->Bind()) { |
| 985 | glDisable(texture->GetTarget()); |
| 986 | return false; |
| 987 | } |
| 988 | |
| 989 | glEnable(texture->GetTarget()); |
nothing calls this directly
no test coverage detected