void gl_ParseSkybox()
{
	int facecount=0;

	SC_MustGetString();

	FSkyBox * sb = new FSkyBox;
	uppercopy(sb->Name, sc_String);
	sb->Name[8]=0;
	SC_MustGetStringName("{");
	while (!SC_CheckString("}"))
	{
		SC_MustGetString();
		if (facecount<6) 
		{
			sb->faces[facecount] = TexMan[TexMan.GetTexture(sc_String, FTexture::TEX_Wall, FTextureManager::TEXMAN_TryAny|FTextureManager::TEXMAN_Overridable)];
		}
		facecount++;
	}
	if (facecount != 3 && facecount != 6)
	{
		SC_ScriptError("%s: Skybox definition requires either 3 or 6 faces", sb->Name);
	}
	sb->SetSize();
	TexMan.AddTexture(sb);
	FGLTexture * gltex = FGLTexture::ValidateTexture(sb);
	gltex->bSkybox=true;
}
void gl_ParseSkybox(FScanner &sc)
{
	int facecount=0;

	sc.MustGetString();

	FSkyBox * sb = new FSkyBox;
	sb->Name = sc.String;
	sb->Name.ToUpper();
	if (sc.CheckString("fliptop"))
	{
		sb->fliptop = true;
	}
	sc.MustGetStringName("{");
	while (!sc.CheckString("}"))
	{
		sc.MustGetString();
		if (facecount<6) 
		{
			sb->faces[facecount] = TexMan[TexMan.GetTexture(sc.String, FTexture::TEX_Wall, FTextureManager::TEXMAN_TryAny|FTextureManager::TEXMAN_Overridable)];
		}
		facecount++;
	}
	if (facecount != 3 && facecount != 6)
	{
		sc.ScriptError("%s: Skybox definition requires either 3 or 6 faces", sb->Name.GetChars());
	}
	sb->SetSize();
	TexMan.AddTexture(sb);
}
void gl_ParseVavoomSkybox()
{
	int lump = Wads.CheckNumForName("SKYBOXES");

	if (lump < 0) return;

	FScanner sc(lump);
	while (sc.GetString())
	{
		int facecount=0;
		int maplump = -1;
		FSkyBox * sb = new FSkyBox;
		uppercopy(sb->Name, sc.String);
		sb->Name[8]=0;
		sb->fliptop = true;
		sc.MustGetStringName("{");
		while (!sc.CheckString("}"))
		{
			if (facecount<6) 
			{
				sc.MustGetStringName("{");
				sc.MustGetStringName("map");
				sc.MustGetString();

				maplump = Wads.CheckNumForFullName(sc.String, true);
				if (maplump==-1) 
					Printf("Texture '%s' not found in Vavoom skybox '%s'\n", sc.String, sb->Name);

				FTextureID tex = TexMan.FindTextureByLumpNum(maplump);
				if (!tex.isValid())
				{
					tex = TexMan.CreateTexture(maplump, FTexture::TEX_MiscPatch);
				}
				sb->faces[facecount] = TexMan[tex];
				sc.MustGetStringName("}");
			}
			facecount++;
		}
		if (facecount != 6)
		{
			sc.ScriptError("%s: Skybox definition requires 6 faces", sb->Name);
		}
		sb->SetSize();
		TexMan.AddTexture(sb);
	}
}
void gl_ParseVavoomSkybox()
{
	int lump = Wads.CheckNumForName("SKYBOXES");

	if (lump < 0) return;

	FScanner sc(lump);
	while (sc.GetString())
	{
		int facecount=0;
		int maplump = -1;
		FSkyBox * sb = new FSkyBox;
		sb->Name = sc.String;
		sb->Name.ToUpper();
		sb->fliptop = true;
		sc.MustGetStringName("{");
		while (!sc.CheckString("}"))
		{
			if (facecount<6) 
			{
				sc.MustGetStringName("{");
				sc.MustGetStringName("map");
				sc.MustGetString();

				maplump = Wads.CheckNumForFullName(sc.String, true);

				FTexture *tex = TexMan.FindTexture(sc.String, FTexture::TEX_Wall, FTextureManager::TEXMAN_TryAny);
				if (tex != NULL)
				{
					Printf("Texture '%s' not found in Vavoom skybox '%s'\n", sc.String, sb->Name.GetChars());
				}
				sb->faces[facecount] = tex;
				sc.MustGetStringName("}");
			}
			facecount++;
		}
		if (facecount != 6)
		{
			sc.ScriptError("%s: Skybox definition requires 6 faces", sb->Name.GetChars());
		}
		sb->SetSize();
		TexMan.AddTexture(sb);
	}
}