mirror of
https://github.com/love2d/love-android.git
synced 2026-08-19 12:14:49 +02:00
Using latest changeset 593639000823 of love-android
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -24,7 +24,6 @@
|
||||
// STD
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
// LOVE
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -24,7 +24,6 @@
|
||||
// STD
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
// LOVE
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -68,7 +68,10 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
|
||||
, toLoop(0)
|
||||
{
|
||||
ALenum fmt = getFormat(soundData->getChannels(), soundData->getBitDepth());
|
||||
staticBuffer = new StaticDataBuffer(fmt, soundData->getData(), soundData->getSize(), soundData->getSampleRate());
|
||||
staticBuffer.set(new StaticDataBuffer(fmt, soundData->getData(), soundData->getSize(), soundData->getSampleRate()));
|
||||
|
||||
// The buffer has a +2 retain count right now, but we want it to have +1.
|
||||
staticBuffer->release();
|
||||
|
||||
float z[3] = {0, 0, 0};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -145,7 +145,7 @@ private:
|
||||
ALuint source;
|
||||
bool valid;
|
||||
|
||||
static const unsigned int MAX_BUFFERS = 32;
|
||||
static const unsigned int MAX_BUFFERS = 8;
|
||||
ALuint streamBuffers[MAX_BUFFERS];
|
||||
|
||||
Object::StrongRef<StaticDataBuffer> staticBuffer;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -26,6 +26,9 @@
|
||||
|
||||
#include "common/runtime.h"
|
||||
|
||||
// C++
|
||||
#include <iostream>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -45,17 +45,11 @@ namespace sdl
|
||||
static void windowToPixelCoords(int *x, int *y)
|
||||
{
|
||||
#ifndef LOVE_ANDROID
|
||||
double scale = 1.0;
|
||||
|
||||
window::Window *window = Module::getInstance<window::Window>(Module::M_WINDOW);
|
||||
if (window != nullptr)
|
||||
scale = window->getPixelScale();
|
||||
|
||||
if (x != nullptr)
|
||||
*x = int(double(*x) * scale);
|
||||
|
||||
if (y != nullptr)
|
||||
*y = int(double(*y) * scale);
|
||||
if (window && x)
|
||||
*x = (int) window->toPixels(*x);
|
||||
if (window && y)
|
||||
*y = (int) window->toPixels(*y);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -109,15 +103,11 @@ Event::~Event()
|
||||
|
||||
void Event::pump()
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
|
||||
static SDL_Event e;
|
||||
|
||||
Message *msg;
|
||||
SDL_Event e;
|
||||
|
||||
while (SDL_PollEvent(&e))
|
||||
{
|
||||
msg = convert(e);
|
||||
Message *msg = convert(e);
|
||||
if (msg)
|
||||
{
|
||||
push(msg);
|
||||
@@ -128,16 +118,17 @@ void Event::pump()
|
||||
|
||||
Message *Event::wait()
|
||||
{
|
||||
static SDL_Event e;
|
||||
bool ok = (SDL_WaitEvent(&e) == 1);
|
||||
if (!ok)
|
||||
return NULL;
|
||||
SDL_Event e;
|
||||
|
||||
if (SDL_WaitEvent(&e) != 1)
|
||||
return nullptr;
|
||||
|
||||
return convert(e);
|
||||
}
|
||||
|
||||
void Event::clear()
|
||||
{
|
||||
static SDL_Event e;
|
||||
SDL_Event e;
|
||||
|
||||
while (SDL_PollEvent(&e))
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "common/EnumMap.h"
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
#include <SDL_events.h>
|
||||
|
||||
// STL
|
||||
#include <map>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -24,7 +24,6 @@
|
||||
// STD
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
// LOVE
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -106,7 +106,7 @@ std::string GlyphData::getGlyphString() const
|
||||
}
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("Decoding error: %s", e.what());
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
// Just in case...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -63,7 +63,7 @@ GlyphData *Rasterizer::getGlyphData(const std::string &text) const
|
||||
}
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("Decoding error: %s", e.what());
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
return getGlyphData(codepoint);
|
||||
@@ -89,7 +89,7 @@ bool Rasterizer::hasGlyphs(const std::string &text) const
|
||||
}
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("Decoding error: %s", e.what());
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -66,7 +66,7 @@ Rasterizer *Font::newRasterizer(love::image::ImageData *data, const std::string
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
delete [] glyphs;
|
||||
throw love::Exception("Decoding error: %s", e.what());
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
Rasterizer *r = newRasterizer(data, glyphs, numglyphs);
|
||||
@@ -90,7 +90,7 @@ GlyphData *Font::newGlyphData(Rasterizer *r, const std::string &text)
|
||||
}
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("Decoding error: %s", e.what());
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
return r->getGlyphData(codepoint);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -121,6 +121,7 @@ StringMap<Texture::WrapMode, Texture::WRAP_MAX_ENUM>::Entry Texture::wrapModeEnt
|
||||
{
|
||||
{ "clamp", Texture::WRAP_CLAMP },
|
||||
{ "repeat", Texture::WRAP_REPEAT },
|
||||
{ "mirroredrepeat", Texture::WRAP_MIRRORED_REPEAT },
|
||||
};
|
||||
|
||||
StringMap<Texture::WrapMode, Texture::WRAP_MAX_ENUM> Texture::wrapModes(Texture::wrapModeEntries, sizeof(Texture::wrapModeEntries));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
{
|
||||
WRAP_CLAMP,
|
||||
WRAP_REPEAT,
|
||||
WRAP_MIRRORED_REPEAT,
|
||||
WRAP_MAX_ENUM
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -371,7 +371,7 @@ void Font::print(const std::string &text, float x, float y, float extra_spacing,
|
||||
}
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("Decoding error: %s", e.what());
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
if (vertexcount <= 0 || glyphinfolist.size() == 0)
|
||||
@@ -466,7 +466,7 @@ int Font::getWidth(const std::string &str)
|
||||
}
|
||||
catch(utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("Decoding error: %s", e.what());
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
if (width > max_width)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
// C
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -108,6 +109,9 @@ void Graphics::restoreState(const DisplayState &s)
|
||||
|
||||
setColorMask(s.colorMask);
|
||||
setWireframe(s.wireframe);
|
||||
|
||||
setDefaultFilter(s.defaultFilter);
|
||||
setDefaultMipmapFilter(s.defaultMipmapFilter, s.defaultMipmapSharpness);
|
||||
}
|
||||
|
||||
void Graphics::restoreStateChecked(const DisplayState &s)
|
||||
@@ -165,6 +169,9 @@ void Graphics::restoreStateChecked(const DisplayState &s)
|
||||
|
||||
if (s.wireframe != cur.wireframe)
|
||||
setWireframe(s.wireframe);
|
||||
|
||||
setDefaultFilter(s.defaultFilter);
|
||||
setDefaultMipmapFilter(s.defaultMipmapFilter, s.defaultMipmapSharpness);
|
||||
}
|
||||
|
||||
void Graphics::setViewportSize(int width, int height)
|
||||
@@ -283,7 +290,7 @@ bool Graphics::setMode(int width, int height, bool &sRGB)
|
||||
|
||||
// Reload all volatile objects.
|
||||
if (!Volatile::loadAll())
|
||||
std::cerr << "Could not reload all volatile objects." << std::endl;
|
||||
::printf("Could not reload all volatile objects.\n");
|
||||
|
||||
// Restore the graphics state.
|
||||
restoreState(states.back());
|
||||
@@ -662,9 +669,9 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int ms
|
||||
return nullptr; // never reached
|
||||
}
|
||||
|
||||
Shader *Graphics::newShader(const Shader::ShaderSources &sources)
|
||||
Shader *Graphics::newShader(const Shader::ShaderSource &source)
|
||||
{
|
||||
return new Shader(sources);
|
||||
return new Shader(source);
|
||||
}
|
||||
|
||||
Mesh *Graphics::newMesh(const std::vector<Vertex> &vertices, Mesh::DrawMode mode)
|
||||
@@ -701,6 +708,12 @@ Color Graphics::getBackgroundColor() const
|
||||
|
||||
void Graphics::setFont(Font *font)
|
||||
{
|
||||
// Hack: the Lua-facing love.graphics.print function will set the current
|
||||
// font if needed, but only on its first call... we want to make sure a nil
|
||||
// font is never accidentally set (e.g. via love.graphics.reset.)
|
||||
if (font == nullptr)
|
||||
return;
|
||||
|
||||
DisplayState &state = states.back();
|
||||
state.font.set(font);
|
||||
}
|
||||
@@ -877,6 +890,7 @@ Graphics::BlendMode Graphics::getBlendMode() const
|
||||
void Graphics::setDefaultFilter(const Texture::Filter &f)
|
||||
{
|
||||
Texture::setDefaultFilter(f);
|
||||
states.back().defaultFilter = f;
|
||||
}
|
||||
|
||||
const Texture::Filter &Graphics::getDefaultFilter() const
|
||||
@@ -888,6 +902,9 @@ void Graphics::setDefaultMipmapFilter(Texture::FilterMode filter, float sharpnes
|
||||
{
|
||||
Image::setDefaultMipmapFilter(filter);
|
||||
Image::setDefaultMipmapSharpness(sharpness);
|
||||
|
||||
states.back().defaultMipmapFilter = filter;
|
||||
states.back().defaultMipmapSharpness = sharpness;
|
||||
}
|
||||
|
||||
void Graphics::getDefaultMipmapFilter(Texture::FilterMode *filter, float *sharpness) const
|
||||
@@ -1418,11 +1435,6 @@ void Graphics::pop()
|
||||
{
|
||||
DisplayState &newstate = states[states.size() - 2];
|
||||
|
||||
// Hack: the Lua-facing love.graphics.print function will set the current
|
||||
// font if needed, but only on its first call... we always want a font.
|
||||
if (newstate.font.get() == nullptr)
|
||||
newstate.font.set(states.back().font.get());
|
||||
|
||||
restoreStateChecked(newstate);
|
||||
|
||||
// The last two states in the stack should be equal now.
|
||||
@@ -1473,6 +1485,9 @@ Graphics::DisplayState::DisplayState()
|
||||
, font(nullptr)
|
||||
, shader(nullptr)
|
||||
, wireframe(false)
|
||||
, defaultFilter()
|
||||
, defaultMipmapFilter(Texture::FILTER_NONE)
|
||||
, defaultMipmapSharpness(0.0f)
|
||||
{
|
||||
// We should just directly initialize the array in the initializer list, but
|
||||
// that feature of C++11 is broken in Visual Studio 2013...
|
||||
@@ -1494,6 +1509,9 @@ Graphics::DisplayState::DisplayState(const DisplayState &other)
|
||||
, shader(other.shader)
|
||||
, canvases(other.canvases)
|
||||
, wireframe(other.wireframe)
|
||||
, defaultFilter(other.defaultFilter)
|
||||
, defaultMipmapFilter(other.defaultMipmapFilter)
|
||||
, defaultMipmapSharpness(other.defaultMipmapSharpness)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
colorMask[i] = other.colorMask[i];
|
||||
@@ -1525,6 +1543,10 @@ Graphics::DisplayState &Graphics::DisplayState::operator = (const DisplayState &
|
||||
|
||||
wireframe = other.wireframe;
|
||||
|
||||
defaultFilter = other.defaultFilter;
|
||||
defaultMipmapFilter = other.defaultMipmapFilter;
|
||||
defaultMipmapSharpness = other.defaultMipmapSharpness;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -22,7 +22,6 @@
|
||||
#define LOVE_GRAPHICS_OPENGL_GRAPHICS_H
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
@@ -168,7 +167,7 @@ public:
|
||||
|
||||
Canvas *newCanvas(int width, int height, Canvas::Format format = Canvas::FORMAT_NORMAL, int msaa = 0);
|
||||
|
||||
Shader *newShader(const Shader::ShaderSources &sources);
|
||||
Shader *newShader(const Shader::ShaderSource &source);
|
||||
|
||||
Mesh *newMesh(const std::vector<Vertex> &vertices, Mesh::DrawMode mode = Mesh::DRAW_MODE_FAN);
|
||||
Mesh *newMesh(int vertexcount, Mesh::DrawMode mode = Mesh::DRAW_MODE_FAN);
|
||||
@@ -478,6 +477,13 @@ private:
|
||||
|
||||
bool wireframe;
|
||||
|
||||
// Default filter.
|
||||
Texture::Filter defaultFilter;
|
||||
|
||||
// Default mipmap filter and sharpness.
|
||||
Texture::FilterMode defaultMipmapFilter;
|
||||
float defaultMipmapSharpness;
|
||||
|
||||
DisplayState();
|
||||
DisplayState(const DisplayState &other);
|
||||
~DisplayState();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -260,6 +260,7 @@ void Image::checkMipmapsCreated()
|
||||
|
||||
void Image::setFilter(const Texture::Filter &f)
|
||||
{
|
||||
const Filter oldfilter = filter;
|
||||
filter = f;
|
||||
|
||||
// We don't want filtering or (attempted) mipmaps on the default texture.
|
||||
@@ -277,7 +278,18 @@ void Image::setFilter(const Texture::Filter &f)
|
||||
|
||||
bind();
|
||||
gl.setTextureFilter(filter);
|
||||
checkMipmapsCreated();
|
||||
|
||||
try
|
||||
{
|
||||
checkMipmapsCreated();
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
// Don't keep the new mipmap filter if we can't create mipmaps.
|
||||
filter = oldfilter;
|
||||
gl.setTextureFilter(filter);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
bool Image::setWrap(const Texture::Wrap &w)
|
||||
@@ -646,6 +658,17 @@ GLenum Image::getCompressedFormat(image::CompressedData::Format cformat) const
|
||||
return GL_COMPRESSED_RG_RGTC2;
|
||||
case image::CompressedData::FORMAT_BC5s:
|
||||
return GL_COMPRESSED_SIGNED_RG_RGTC2;
|
||||
case image::CompressedData::FORMAT_BC6H:
|
||||
return GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB;
|
||||
case image::CompressedData::FORMAT_BC6Hs:
|
||||
return GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB;
|
||||
case image::CompressedData::FORMAT_BC7:
|
||||
if (srgb)
|
||||
return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB;
|
||||
else
|
||||
return GL_COMPRESSED_RGBA_BPTC_UNORM_ARB;
|
||||
case image::CompressedData::FORMAT_BC7SRGB:
|
||||
return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB;
|
||||
case image::CompressedData::FORMAT_ETC1:
|
||||
// The ETC2 format can load ETC1 textures.
|
||||
if (GLAD_VERSION_4_3 || GLAD_ES_VERSION_3_0 || GLAD_ARB_ES3_compatibility)
|
||||
@@ -703,6 +726,11 @@ bool Image::hasCompressedTextureSupport(image::CompressedData::Format format)
|
||||
case image::CompressedData::FORMAT_BC5:
|
||||
case image::CompressedData::FORMAT_BC5s:
|
||||
return (GLAD_VERSION_3_0 || GLAD_ARB_texture_compression_rgtc || GLAD_EXT_texture_compression_rgtc);
|
||||
case image::CompressedData::FORMAT_BC6H:
|
||||
case image::CompressedData::FORMAT_BC6Hs:
|
||||
case image::CompressedData::FORMAT_BC7:
|
||||
case image::CompressedData::FORMAT_BC7SRGB:
|
||||
return GLAD_VERSION_4_2 || GLAD_ARB_texture_compression_bptc;
|
||||
case image::CompressedData::FORMAT_ETC1:
|
||||
// ETC2 support guarantees ETC1 support as well.
|
||||
return GLAD_VERSION_4_3 || GLAD_ES_VERSION_3_0 || GLAD_ARB_ES3_compatibility || GLAD_OES_compressed_ETC1_RGB8_texture;
|
||||
@@ -712,10 +740,8 @@ bool Image::hasCompressedTextureSupport(image::CompressedData::Format format)
|
||||
case image::CompressedData::FORMAT_PVR1_RGBA4:
|
||||
return GLAD_IMG_texture_compression_pvrtc;
|
||||
default:
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Image::hasSRGBSupport()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -729,86 +729,24 @@ float OpenGL::setTextureFilter(graphics::Texture::Filter &f)
|
||||
return f.anisotropy;
|
||||
}
|
||||
|
||||
Texture::Filter OpenGL::getTextureFilter()
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Texture::Filter f;
|
||||
|
||||
switch (gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.min = Texture::FILTER_NEAREST;
|
||||
f.mipmap = Texture::FILTER_NONE;
|
||||
break;
|
||||
case GL_NEAREST_MIPMAP_NEAREST:
|
||||
f.min = f.mipmap = Texture::FILTER_NEAREST;
|
||||
break;
|
||||
case GL_NEAREST_MIPMAP_LINEAR:
|
||||
f.min = Texture::FILTER_NEAREST;
|
||||
f.mipmap = Texture::FILTER_LINEAR;
|
||||
break;
|
||||
case GL_LINEAR_MIPMAP_NEAREST:
|
||||
f.min = Texture::FILTER_LINEAR;
|
||||
f.mipmap = Texture::FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR_MIPMAP_LINEAR:
|
||||
f.min = f.mipmap = Texture::FILTER_LINEAR;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.min = Texture::FILTER_LINEAR;
|
||||
f.mipmap = Texture::FILTER_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gmag)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.mag = Texture::FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.mag = Texture::FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
if (GLAD_EXT_texture_filter_anisotropic)
|
||||
glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &f.anisotropy);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void OpenGL::setTextureWrap(const graphics::Texture::Wrap &w)
|
||||
{
|
||||
GLint gs, gt;
|
||||
|
||||
switch (w.s)
|
||||
auto glWrapMode = [](Texture::WrapMode wmode) -> GLint
|
||||
{
|
||||
case Texture::WRAP_CLAMP:
|
||||
gs = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case Texture::WRAP_REPEAT:
|
||||
default:
|
||||
gs = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
switch (wmode)
|
||||
{
|
||||
case Texture::WRAP_CLAMP:
|
||||
default:
|
||||
return GL_CLAMP_TO_EDGE;
|
||||
case Texture::WRAP_REPEAT:
|
||||
return GL_REPEAT;
|
||||
case Texture::WRAP_MIRRORED_REPEAT:
|
||||
return GL_MIRRORED_REPEAT;
|
||||
}
|
||||
};
|
||||
|
||||
switch (w.t)
|
||||
{
|
||||
case Texture::WRAP_CLAMP:
|
||||
gt = GL_CLAMP_TO_EDGE;
|
||||
break;
|
||||
case Texture::WRAP_REPEAT:
|
||||
default:
|
||||
gt = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gs);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gt);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glWrapMode(w.s));
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, glWrapMode(w.t));
|
||||
}
|
||||
|
||||
int OpenGL::getMaxTextureSize() const
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -318,11 +318,6 @@ public:
|
||||
**/
|
||||
float setTextureFilter(graphics::Texture::Filter &f);
|
||||
|
||||
/**
|
||||
* Returns the texture filter mode for the currently bound texture.
|
||||
**/
|
||||
graphics::Texture::Filter getTextureFilter();
|
||||
|
||||
/**
|
||||
* Sets the texture wrap mode for the currently bound texture.
|
||||
**/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -87,6 +87,8 @@ ParticleSystem::ParticleSystem(Texture *texture, uint32 size)
|
||||
, radialAccelerationMax(0)
|
||||
, tangentialAccelerationMin(0)
|
||||
, tangentialAccelerationMax(0)
|
||||
, linearDampingMin(0.0f)
|
||||
, linearDampingMax(0.0f)
|
||||
, sizeVariation(0)
|
||||
, rotationMin(0)
|
||||
, rotationMax(0)
|
||||
@@ -136,6 +138,8 @@ ParticleSystem::ParticleSystem(const ParticleSystem &p)
|
||||
, radialAccelerationMax(p.radialAccelerationMax)
|
||||
, tangentialAccelerationMin(p.tangentialAccelerationMin)
|
||||
, tangentialAccelerationMax(p.tangentialAccelerationMax)
|
||||
, linearDampingMin(p.linearDampingMin)
|
||||
, linearDampingMax(p.linearDampingMax)
|
||||
, sizes(p.sizes)
|
||||
, sizeVariation(p.sizeVariation)
|
||||
, rotationMin(p.rotationMin)
|
||||
@@ -294,6 +298,10 @@ void ParticleSystem::initParticle(Particle *p, float t)
|
||||
max = tangentialAccelerationMax;
|
||||
p->tangentialAcceleration = (float) rng.random(min, max);
|
||||
|
||||
min = linearDampingMin;
|
||||
max = linearDampingMax;
|
||||
p->linearDamping = (float) rng.random(min, max);
|
||||
|
||||
p->sizeOffset = (float) rng.random(sizeVariation); // time offset for size change
|
||||
p->sizeIntervalSize = (1.0f - (float) rng.random(sizeVariation)) - p->sizeOffset;
|
||||
p->size = sizes[(size_t)(p->sizeOffset - .5f) * (sizes.size() - 1)];
|
||||
@@ -470,12 +478,10 @@ void ParticleSystem::setParticleLifetime(float min, float max)
|
||||
particleLifeMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getParticleLifetime(float *min, float *max) const
|
||||
void ParticleSystem::getParticleLifetime(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = particleLifeMin;
|
||||
if (max)
|
||||
*max = particleLifeMax;
|
||||
min = particleLifeMin;
|
||||
max = particleLifeMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setPosition(float x, float y)
|
||||
@@ -541,12 +547,10 @@ void ParticleSystem::setSpeed(float min, float max)
|
||||
speedMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getSpeed(float *min, float *max) const
|
||||
void ParticleSystem::getSpeed(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = speedMin;
|
||||
if (max)
|
||||
*max = speedMax;
|
||||
min = speedMin;
|
||||
max = speedMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setLinearAcceleration(float x, float y)
|
||||
@@ -561,12 +565,10 @@ void ParticleSystem::setLinearAcceleration(float xmin, float ymin, float xmax, f
|
||||
linearAccelerationMax = love::Vector(xmax, ymax);
|
||||
}
|
||||
|
||||
void ParticleSystem::getLinearAcceleration(love::Vector *min, love::Vector *max) const
|
||||
void ParticleSystem::getLinearAcceleration(love::Vector &min, love::Vector &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = linearAccelerationMin;
|
||||
if (max)
|
||||
*max = linearAccelerationMax;
|
||||
min = linearAccelerationMin;
|
||||
max = linearAccelerationMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRadialAcceleration(float acceleration)
|
||||
@@ -580,12 +582,10 @@ void ParticleSystem::setRadialAcceleration(float min, float max)
|
||||
radialAccelerationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getRadialAcceleration(float *min, float *max) const
|
||||
void ParticleSystem::getRadialAcceleration(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = radialAccelerationMin;
|
||||
if (max)
|
||||
*max = radialAccelerationMax;
|
||||
min = radialAccelerationMin;
|
||||
max = radialAccelerationMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setTangentialAcceleration(float acceleration)
|
||||
@@ -599,12 +599,22 @@ void ParticleSystem::setTangentialAcceleration(float min, float max)
|
||||
tangentialAccelerationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getTangentialAcceleration(float *min, float *max) const
|
||||
void ParticleSystem::getTangentialAcceleration(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = tangentialAccelerationMin;
|
||||
if (max)
|
||||
*max = tangentialAccelerationMax;
|
||||
min = tangentialAccelerationMin;
|
||||
max = tangentialAccelerationMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setLinearDamping(float min, float max)
|
||||
{
|
||||
linearDampingMin = min;
|
||||
linearDampingMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getLinearDamping(float &min, float &max) const
|
||||
{
|
||||
min = linearDampingMin;
|
||||
max = linearDampingMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSize(float size)
|
||||
@@ -644,12 +654,10 @@ void ParticleSystem::setRotation(float min, float max)
|
||||
rotationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::getRotation(float *min, float *max) const
|
||||
void ParticleSystem::getRotation(float &min, float &max) const
|
||||
{
|
||||
if (min)
|
||||
*min = rotationMin;
|
||||
if (max)
|
||||
*max = rotationMax;
|
||||
min = rotationMin;
|
||||
max = rotationMax;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpin(float spin)
|
||||
@@ -664,12 +672,10 @@ void ParticleSystem::setSpin(float start, float end)
|
||||
spinEnd = end;
|
||||
}
|
||||
|
||||
void ParticleSystem::getSpin(float *start, float *end) const
|
||||
void ParticleSystem::getSpin(float &start, float &end) const
|
||||
{
|
||||
if (start)
|
||||
*start = spinStart;
|
||||
if (end)
|
||||
*end = spinEnd;
|
||||
start = spinStart;
|
||||
end = spinEnd;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpinVariation(float variation)
|
||||
@@ -944,6 +950,9 @@ void ParticleSystem::update(float dt)
|
||||
// Update velocity.
|
||||
p->velocity += (radial + tangential + p->linearAcceleration) * dt;
|
||||
|
||||
// Apply damping.
|
||||
p->velocity *= 1.0f / (1.0f + p->linearDamping * dt);
|
||||
|
||||
// Modify position.
|
||||
ppos += p->velocity * dt;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
* @param[out] min The minimum life.
|
||||
* @param[out] max The maximum life.
|
||||
**/
|
||||
void getParticleLifetime(float *min, float *max) const;
|
||||
void getParticleLifetime(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the position of the center of the emitter.
|
||||
@@ -250,7 +250,7 @@ public:
|
||||
* @param[out] min The minimum speed.
|
||||
* @param[out] max The maximum speed.
|
||||
**/
|
||||
void getSpeed(float *min, float *max) const;
|
||||
void getSpeed(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the linear acceleration (the acceleration along the x and y axes).
|
||||
@@ -273,7 +273,7 @@ public:
|
||||
* @param[out] min The minimum acceleration.
|
||||
* @param[out] max The maximum acceleration.
|
||||
**/
|
||||
void getLinearAcceleration(love::Vector *min, love::Vector *max) const;
|
||||
void getLinearAcceleration(love::Vector &min, love::Vector &max) const;
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
@@ -293,7 +293,7 @@ public:
|
||||
* @param[out] min The minimum amount of radial acceleration.
|
||||
* @param[out] max The maximum amount of radial acceleration.
|
||||
**/
|
||||
void getRadialAcceleration(float *min, float *max) const;
|
||||
void getRadialAcceleration(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
@@ -313,7 +313,18 @@ public:
|
||||
* @param[out] min The minimum tangential acceleration.
|
||||
* @param[out] max The maximum tangential acceleration.
|
||||
**/
|
||||
void getTangentialAcceleration(float *min, float *max) const;
|
||||
void getTangentialAcceleration(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the amount of linear damping. Damping reduces the velocity of
|
||||
* particles over time. A value of 0 corresponds to no damping.
|
||||
**/
|
||||
void setLinearDamping(float min, float max);
|
||||
|
||||
/**
|
||||
* Gets the current amount of linear damping.
|
||||
**/
|
||||
void getLinearDamping(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite (1.0 being the default size).
|
||||
@@ -361,7 +372,7 @@ public:
|
||||
* @param[out] min The minimum initial rotation.
|
||||
* @param[out] max The maximum initial rotation.
|
||||
**/
|
||||
void getRotation(float *min, float *max) const;
|
||||
void getRotation(float &min, float &max) const;
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite.
|
||||
@@ -381,7 +392,7 @@ public:
|
||||
* @param[out] start The initial spin, in radians / s.
|
||||
* @param[out] end The final spin, in radians / s.
|
||||
**/
|
||||
void getSpin(float *start, float *end) const;
|
||||
void getSpin(float &start, float &end) const;
|
||||
|
||||
/**
|
||||
* Sets the variation of the start spin (0 being no variation and 1 being a random spin between start and end).
|
||||
@@ -534,6 +545,8 @@ protected:
|
||||
float radialAcceleration;
|
||||
float tangentialAcceleration;
|
||||
|
||||
float linearDamping;
|
||||
|
||||
float size;
|
||||
float sizeOffset;
|
||||
float sizeIntervalSize;
|
||||
@@ -623,6 +636,9 @@ protected:
|
||||
float tangentialAccelerationMin;
|
||||
float tangentialAccelerationMax;
|
||||
|
||||
float linearDampingMin;
|
||||
float linearDampingMax;
|
||||
|
||||
// Size.
|
||||
std::vector<float> sizes;
|
||||
float sizeVariation;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -64,20 +64,20 @@ namespace
|
||||
Shader *Shader::current = nullptr;
|
||||
Shader *Shader::defaultShader = nullptr;
|
||||
|
||||
Shader::ShaderSources Shader::defaultCode[Graphics::RENDERER_MAX_ENUM];
|
||||
Shader::ShaderSource Shader::defaultCode[Graphics::RENDERER_MAX_ENUM];
|
||||
|
||||
GLint Shader::maxTexUnits = 0;
|
||||
std::vector<int> Shader::textureCounters;
|
||||
|
||||
Shader::Shader(const ShaderSources &sources)
|
||||
: shaderSources(sources)
|
||||
Shader::Shader(const ShaderSource &source)
|
||||
: shaderSource(source)
|
||||
, program(0)
|
||||
, builtinUniforms()
|
||||
, vertexAttributes()
|
||||
, builtinAttributes()
|
||||
, lastCanvas((Canvas *) -1)
|
||||
, lastViewport()
|
||||
{
|
||||
if (shaderSources.empty())
|
||||
if (source.vertex.empty() && source.pixel.empty())
|
||||
throw love::Exception("Cannot create shader: no source code!");
|
||||
|
||||
if (maxTexUnits <= 0)
|
||||
@@ -108,21 +108,21 @@ Shader::~Shader()
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
GLuint Shader::compileCode(ShaderType type, const std::string &code)
|
||||
GLuint Shader::compileCode(ShaderStage stage, const std::string &code)
|
||||
{
|
||||
GLenum glshadertype;
|
||||
GLenum glstage;
|
||||
const char *typestr;
|
||||
|
||||
if (!typeNames.find(type, typestr))
|
||||
if (!stageNames.find(stage, typestr))
|
||||
typestr = "";
|
||||
|
||||
switch (type)
|
||||
switch (stage)
|
||||
{
|
||||
case TYPE_VERTEX:
|
||||
glshadertype = GL_VERTEX_SHADER;
|
||||
case STAGE_VERTEX:
|
||||
glstage = GL_VERTEX_SHADER;
|
||||
break;
|
||||
case TYPE_PIXEL:
|
||||
glshadertype = GL_FRAGMENT_SHADER;
|
||||
case STAGE_PIXEL:
|
||||
glstage = GL_FRAGMENT_SHADER;
|
||||
break;
|
||||
default:
|
||||
throw love::Exception("Cannot create shader object: unknown shader type.");
|
||||
@@ -132,125 +132,75 @@ GLuint Shader::compileCode(ShaderType type, const std::string &code)
|
||||
// clear existing errors
|
||||
while (glGetError() != GL_NO_ERROR);
|
||||
|
||||
GLuint shaderid = glCreateShader(glshadertype);
|
||||
GLuint shaderid = glCreateShader(glstage);
|
||||
|
||||
if (shaderid == 0) // oh no!
|
||||
if (shaderid == 0)
|
||||
{
|
||||
GLenum err = glGetError();
|
||||
|
||||
if (err == GL_INVALID_ENUM)
|
||||
if (glGetError() == GL_INVALID_ENUM)
|
||||
throw love::Exception("Cannot create %s shader object: %s shaders not supported.", typestr, typestr);
|
||||
else
|
||||
throw love::Exception("Cannot create %s shader object.", typestr);
|
||||
}
|
||||
|
||||
const char *src = code.c_str();
|
||||
size_t srclen = code.length();
|
||||
glShaderSource(shaderid, 1, (const GLchar **)&src, (GLint *)&srclen);
|
||||
GLint srclen = (GLint) code.length();
|
||||
glShaderSource(shaderid, 1, (const GLchar **)&src, &srclen);
|
||||
|
||||
glCompileShader(shaderid);
|
||||
|
||||
// Get any warnings the shader compiler may have produced.
|
||||
GLint infologlen;
|
||||
glGetShaderiv(shaderid, GL_INFO_LOG_LENGTH, &infologlen);
|
||||
|
||||
GLchar *infolog = new GLchar[infologlen + 1];
|
||||
glGetShaderInfoLog(shaderid, infologlen, nullptr, infolog);
|
||||
|
||||
// Save any warnings for later querying.
|
||||
// Get any warnings the shader compiler may have produced.
|
||||
if (infologlen > 0)
|
||||
shaderWarnings[type] = infolog;
|
||||
{
|
||||
GLchar *infolog = new GLchar[infologlen];
|
||||
glGetShaderInfoLog(shaderid, infologlen, nullptr, infolog);
|
||||
|
||||
delete[] infolog;
|
||||
// Save any warnings for later querying.
|
||||
shaderWarnings[stage] = infolog;
|
||||
|
||||
delete[] infolog;
|
||||
}
|
||||
|
||||
GLint status;
|
||||
glGetShaderiv(shaderid, GL_COMPILE_STATUS, &status);
|
||||
|
||||
if (status == GL_FALSE)
|
||||
{
|
||||
glDeleteShader(shaderid);
|
||||
throw love::Exception("Cannot compile %s shader code:\n%s",
|
||||
typestr, shaderWarnings[type].c_str());
|
||||
typestr, shaderWarnings[stage].c_str());
|
||||
}
|
||||
|
||||
return shaderid;
|
||||
}
|
||||
|
||||
void Shader::createProgram(const std::vector<GLuint> &shaderids)
|
||||
{
|
||||
program = glCreateProgram();
|
||||
if (program == 0)
|
||||
throw love::Exception("Cannot create shader program object.");
|
||||
|
||||
for (GLuint id : shaderids)
|
||||
glAttachShader(program, id);
|
||||
|
||||
// Bind generic vertex attribute indices to names in the shader.
|
||||
for (int i = 0; i < int(OpenGL::ATTRIB_MAX_ENUM); i++)
|
||||
{
|
||||
// Desktop OpenGL should ignore some of these.
|
||||
if (!GLAD_ES_VERSION_2_0 && i <= int(OpenGL::ATTRIB_COLOR))
|
||||
continue;
|
||||
|
||||
OpenGL::VertexAttrib attrib = (OpenGL::VertexAttrib) i;
|
||||
|
||||
// FIXME: We skip this both because pseudo-instancing is temporarily
|
||||
// disabled (see graphics.lua), and because binding a non-existant
|
||||
// attribute name to a location causes a shader linker warning.
|
||||
if (attrib == OpenGL::ATTRIB_PSEUDO_INSTANCE_ID)
|
||||
continue;
|
||||
|
||||
const char *name = nullptr;
|
||||
if (attribNames.find(attrib, name))
|
||||
glBindAttribLocation(program, i, (const GLchar *) name);
|
||||
}
|
||||
|
||||
glLinkProgram(program);
|
||||
|
||||
// flag shaders for auto-deletion when the program object is deleted.
|
||||
for (GLuint id : shaderids)
|
||||
glDeleteShader(id);
|
||||
|
||||
GLint status;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &status);
|
||||
|
||||
if (status == GL_FALSE)
|
||||
{
|
||||
std::string warnings = getProgramWarnings();
|
||||
glDeleteProgram(program);
|
||||
program = 0;
|
||||
|
||||
throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::mapActiveUniforms()
|
||||
{
|
||||
// Built-in uniform locations default to -1 (nonexistant.)
|
||||
for (int i = 0; i < int(BUILTIN_MAX_ENUM); i++)
|
||||
builtinUniforms[i] = -1;
|
||||
|
||||
uniforms.clear();
|
||||
|
||||
GLint numuniforms;
|
||||
glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numuniforms);
|
||||
|
||||
GLsizei bufsize;
|
||||
glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, (GLint *) &bufsize);
|
||||
|
||||
if (bufsize <= 0)
|
||||
return;
|
||||
GLchar cname[256];
|
||||
const GLint bufsize = (GLint) (sizeof(cname) / sizeof(GLchar));
|
||||
|
||||
for (int i = 0; i < numuniforms; i++)
|
||||
{
|
||||
GLchar *cname = new GLchar[bufsize];
|
||||
GLsizei namelength;
|
||||
GLsizei namelen = 0;
|
||||
Uniform u = {};
|
||||
|
||||
Uniform u;
|
||||
glGetActiveUniform(program, (GLuint) i, bufsize, &namelen, &u.count, &u.type, cname);
|
||||
|
||||
glGetActiveUniform(program, (GLuint) i, bufsize, &namelength, &u.count, &u.type, cname);
|
||||
|
||||
u.name = std::string(cname, (size_t) namelength);
|
||||
u.name = std::string(cname, (size_t) namelen);
|
||||
u.location = glGetUniformLocation(program, u.name.c_str());
|
||||
u.baseType = getUniformBaseType(u.type);
|
||||
|
||||
delete[] cname;
|
||||
|
||||
// glGetActiveUniform appends "[0]" to the end of array uniform names...
|
||||
if (u.name.length() > 3)
|
||||
{
|
||||
@@ -279,36 +229,81 @@ bool Shader::loadVolatile()
|
||||
activeTexUnits.clear();
|
||||
activeTexUnits.insert(activeTexUnits.begin(), maxTexUnits, 0);
|
||||
|
||||
// Built-in uniform locations default to -1 (nonexistant.)
|
||||
for (int i = 0; i < int(BUILTIN_MAX_ENUM); i++)
|
||||
builtinUniforms[i] = -1;
|
||||
|
||||
std::vector<GLuint> shaderids;
|
||||
|
||||
for (const auto &source : shaderSources)
|
||||
try
|
||||
{
|
||||
GLuint shaderid = compileCode(source.first, source.second);
|
||||
shaderids.push_back(shaderid);
|
||||
// All shader programs in ES2 must have a vertex and pixel shader.
|
||||
const ShaderSource &defaultESCode = defaultCode[Graphics::RENDERER_OPENGLES];
|
||||
|
||||
if (!shaderSource.vertex.empty())
|
||||
shaderids.push_back(compileCode(STAGE_VERTEX, shaderSource.vertex));
|
||||
else if (GLAD_ES_VERSION_2_0)
|
||||
shaderids.push_back(compileCode(STAGE_VERTEX, defaultESCode.vertex));
|
||||
|
||||
if (!shaderSource.pixel.empty())
|
||||
shaderids.push_back(compileCode(STAGE_PIXEL, shaderSource.pixel));
|
||||
else if (GLAD_ES_VERSION_2_0)
|
||||
shaderids.push_back(compileCode(STAGE_PIXEL, defaultESCode.pixel));
|
||||
}
|
||||
|
||||
// All shader programs in ES2 must have a vertex and pixel shader.
|
||||
if (GLAD_ES_VERSION_2_0)
|
||||
catch (love::Exception &)
|
||||
{
|
||||
ShaderSources &defaults = defaultCode[Graphics::RENDERER_OPENGLES];
|
||||
|
||||
ShaderSources::const_iterator source = shaderSources.find(TYPE_VERTEX);
|
||||
if (source == shaderSources.end())
|
||||
shaderids.push_back(compileCode(TYPE_VERTEX, defaults[TYPE_VERTEX]));
|
||||
|
||||
source = shaderSources.find(TYPE_PIXEL);
|
||||
if (source == shaderSources.end())
|
||||
shaderids.push_back(compileCode(TYPE_PIXEL, defaults[TYPE_PIXEL]));
|
||||
for (GLuint id : shaderids)
|
||||
glDeleteShader(id);
|
||||
throw;
|
||||
}
|
||||
|
||||
if (shaderids.empty())
|
||||
throw love::Exception("Cannot create shader: no valid source code!");
|
||||
|
||||
createProgram(shaderids);
|
||||
program = glCreateProgram();
|
||||
|
||||
if (program == 0)
|
||||
{
|
||||
for (GLuint id : shaderids)
|
||||
glDeleteShader(id);
|
||||
throw love::Exception("Cannot create shader program object.");
|
||||
}
|
||||
|
||||
for (GLuint id : shaderids)
|
||||
glAttachShader(program, id);
|
||||
|
||||
// Bind generic vertex attribute indices to names in the shader.
|
||||
for (int i = 0; i < int(OpenGL::ATTRIB_MAX_ENUM); i++)
|
||||
{
|
||||
// Desktop OpenGL should ignore some of these.
|
||||
if (!GLAD_ES_VERSION_2_0 && i <= int(OpenGL::ATTRIB_COLOR))
|
||||
continue;
|
||||
|
||||
OpenGL::VertexAttrib attrib = (OpenGL::VertexAttrib) i;
|
||||
|
||||
// FIXME: We skip this both because pseudo-instancing is temporarily
|
||||
// disabled (see graphics.lua), and because binding a non-existant
|
||||
// attribute name to a location causes a shader linker warning.
|
||||
if (attrib == OpenGL::ATTRIB_PSEUDO_INSTANCE_ID)
|
||||
continue;
|
||||
|
||||
const char *name = nullptr;
|
||||
if (attribNames.find(attrib, name))
|
||||
glBindAttribLocation(program, i, (const GLchar *) name);
|
||||
}
|
||||
|
||||
glLinkProgram(program);
|
||||
|
||||
// Flag shaders for auto-deletion when the program object is deleted.
|
||||
for (GLuint id : shaderids)
|
||||
glDeleteShader(id);
|
||||
|
||||
GLint status;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &status);
|
||||
|
||||
if (status == GL_FALSE)
|
||||
{
|
||||
std::string warnings = getProgramWarnings();
|
||||
glDeleteProgram(program);
|
||||
program = 0;
|
||||
throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
|
||||
}
|
||||
|
||||
// Retrieve all active uniform variables in this shader from OpenGL.
|
||||
mapActiveUniforms();
|
||||
@@ -317,9 +312,9 @@ bool Shader::loadVolatile()
|
||||
{
|
||||
const char *name = nullptr;
|
||||
if (attribNames.find(OpenGL::VertexAttrib(i), name))
|
||||
vertexAttributes[i] = glGetAttribLocation(program, name);
|
||||
builtinAttributes[i] = glGetAttribLocation(program, name);
|
||||
else
|
||||
vertexAttributes[i] = -1;
|
||||
builtinAttributes[i] = -1;
|
||||
}
|
||||
|
||||
if (current == this)
|
||||
@@ -367,13 +362,16 @@ void Shader::unloadVolatile()
|
||||
|
||||
std::string Shader::getProgramWarnings() const
|
||||
{
|
||||
GLint strlen, nullpos;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &strlen);
|
||||
GLint strsize, nullpos;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &strsize);
|
||||
|
||||
char *tempstr = new char[strlen+1];
|
||||
if (strsize == 0)
|
||||
return "";
|
||||
|
||||
char *tempstr = new char[strsize];
|
||||
// be extra sure that the error string will be 0-terminated
|
||||
memset(tempstr, '\0', strlen+1);
|
||||
glGetProgramInfoLog(program, strlen, &nullpos, tempstr);
|
||||
memset(tempstr, '\0', strsize);
|
||||
glGetProgramInfoLog(program, strsize, &nullpos, tempstr);
|
||||
tempstr[nullpos] = '\0';
|
||||
|
||||
std::string warnings(tempstr);
|
||||
@@ -385,13 +383,13 @@ std::string Shader::getProgramWarnings() const
|
||||
std::string Shader::getWarnings() const
|
||||
{
|
||||
std::string warnings;
|
||||
const char *typestr;
|
||||
const char *stagestr;
|
||||
|
||||
// Get the individual shader stage warnings
|
||||
for (const auto &warning : shaderWarnings)
|
||||
{
|
||||
if (typeNames.find(warning.first, typestr))
|
||||
warnings += std::string(typestr) + std::string(" shader:\n") + warning.second;
|
||||
if (stageNames.find(warning.first, stagestr))
|
||||
warnings += std::string(stagestr) + std::string(" shader:\n") + warning.second;
|
||||
}
|
||||
|
||||
warnings += getProgramWarnings();
|
||||
@@ -438,7 +436,6 @@ void Shader::detach()
|
||||
if (current != nullptr)
|
||||
{
|
||||
glUseProgram(0);
|
||||
current->release();
|
||||
current = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -710,7 +707,7 @@ Shader::UniformType Shader::getExternVariable(const std::string &name, int &comp
|
||||
|
||||
bool Shader::hasVertexAttrib(OpenGL::VertexAttrib attrib) const
|
||||
{
|
||||
return vertexAttributes[int(attrib)] != -1;
|
||||
return builtinAttributes[int(attrib)] != -1;
|
||||
}
|
||||
|
||||
bool Shader::hasBuiltinUniform(BuiltinUniform builtin) const
|
||||
@@ -851,13 +848,13 @@ bool Shader::getConstant(UniformType in, const char *&out)
|
||||
return uniformTypes.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM>::Entry Shader::typeNameEntries[] =
|
||||
StringMap<Shader::ShaderStage, Shader::STAGE_MAX_ENUM>::Entry Shader::stageNameEntries[] =
|
||||
{
|
||||
{"vertex", Shader::TYPE_VERTEX},
|
||||
{"pixel", Shader::TYPE_PIXEL},
|
||||
{"vertex", Shader::STAGE_VERTEX},
|
||||
{"pixel", Shader::STAGE_PIXEL},
|
||||
};
|
||||
|
||||
StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM> Shader::typeNames(Shader::typeNameEntries, sizeof(Shader::typeNameEntries));
|
||||
StringMap<Shader::ShaderStage, Shader::STAGE_MAX_ENUM> Shader::stageNames(Shader::stageNameEntries, sizeof(Shader::stageNameEntries));
|
||||
|
||||
StringMap<Shader::UniformType, Shader::UNIFORM_MAX_ENUM>::Entry Shader::uniformTypeEntries[] =
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -53,11 +53,11 @@ public:
|
||||
// Pointer to the current default Shader.
|
||||
static Shader *defaultShader;
|
||||
|
||||
enum ShaderType
|
||||
enum ShaderStage
|
||||
{
|
||||
TYPE_VERTEX,
|
||||
TYPE_PIXEL,
|
||||
TYPE_MAX_ENUM
|
||||
STAGE_VERTEX,
|
||||
STAGE_PIXEL,
|
||||
STAGE_MAX_ENUM
|
||||
};
|
||||
|
||||
// Built-in uniform (extern) variables.
|
||||
@@ -82,14 +82,17 @@ public:
|
||||
UNIFORM_MAX_ENUM
|
||||
};
|
||||
|
||||
// Type for a list of shader source codes in the form of sources[shadertype] = code
|
||||
typedef std::map<ShaderType, std::string> ShaderSources;
|
||||
struct ShaderSource
|
||||
{
|
||||
std::string vertex;
|
||||
std::string pixel;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new Shader using a list of source codes.
|
||||
* Sources must contain either vertex or pixel shader code, or both.
|
||||
* Source must contain either vertex or pixel shader code, or both.
|
||||
**/
|
||||
Shader(const ShaderSources &sources);
|
||||
Shader(const ShaderSource &source);
|
||||
|
||||
virtual ~Shader();
|
||||
|
||||
@@ -182,7 +185,7 @@ public:
|
||||
static bool isSupported();
|
||||
|
||||
// Default code used when renderers require code for a shader stage.
|
||||
static ShaderSources defaultCode[Graphics::RENDERER_MAX_ENUM];
|
||||
static ShaderSource defaultCode[Graphics::RENDERER_MAX_ENUM];
|
||||
|
||||
static bool getConstant(const char *in, UniformType &out);
|
||||
static bool getConstant(UniformType in, const char *&out);
|
||||
@@ -208,8 +211,7 @@ private:
|
||||
UniformType getUniformBaseType(GLenum type) const;
|
||||
void checkSetUniformError(const Uniform &u, int size, int count, UniformType sendtype) const;
|
||||
|
||||
GLuint compileCode(ShaderType type, const std::string &code);
|
||||
void createProgram(const std::vector<GLuint> &shaderids);
|
||||
GLuint compileCode(ShaderStage stage, const std::string &code);
|
||||
|
||||
int getTextureUnit(const std::string &name);
|
||||
|
||||
@@ -218,12 +220,11 @@ private:
|
||||
// Get any warnings or errors generated only by the shader program object.
|
||||
std::string getProgramWarnings() const;
|
||||
|
||||
|
||||
// List of all shader code attached to this Shader
|
||||
ShaderSources shaderSources;
|
||||
// Source code used for this Shader.
|
||||
ShaderSource shaderSource;
|
||||
|
||||
// Shader compiler warning strings for individual shader stages.
|
||||
std::map<ShaderType, std::string> shaderWarnings;
|
||||
std::map<ShaderStage, std::string> shaderWarnings;
|
||||
|
||||
// volatile
|
||||
GLuint program;
|
||||
@@ -232,7 +233,7 @@ private:
|
||||
GLint builtinUniforms[BUILTIN_MAX_ENUM];
|
||||
|
||||
// Location values for any generic vertex attribute variables.
|
||||
GLint vertexAttributes[OpenGL::ATTRIB_MAX_ENUM];
|
||||
GLint builtinAttributes[OpenGL::ATTRIB_MAX_ENUM];
|
||||
|
||||
// Uniform location buffer map
|
||||
std::map<std::string, Uniform> uniforms;
|
||||
@@ -254,9 +255,8 @@ private:
|
||||
// Counts total number of textures bound to each texture unit in all shaders
|
||||
static std::vector<int> textureCounters;
|
||||
|
||||
|
||||
static StringMap<ShaderType, TYPE_MAX_ENUM>::Entry typeNameEntries[];
|
||||
static StringMap<ShaderType, TYPE_MAX_ENUM> typeNames;
|
||||
static StringMap<ShaderStage, STAGE_MAX_ENUM>::Entry stageNameEntries[];
|
||||
static StringMap<ShaderStage, STAGE_MAX_ENUM> stageNames;
|
||||
|
||||
static StringMap<UniformType, UNIFORM_MAX_ENUM>::Entry uniformTypeEntries[];
|
||||
static StringMap<UniformType, UNIFORM_MAX_ENUM> uniformTypes;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -47,7 +47,7 @@ SpriteBatch::SpriteBatch(Texture *texture, int size, int usage)
|
||||
, next(0)
|
||||
, color(0)
|
||||
, array_buf(nullptr)
|
||||
, element_buf(nullptr)
|
||||
, element_buf(size)
|
||||
, buffer_used_offset(0)
|
||||
, buffer_used_size(0)
|
||||
{
|
||||
@@ -74,18 +74,15 @@ SpriteBatch::SpriteBatch(Texture *texture, int size, int usage)
|
||||
try
|
||||
{
|
||||
array_buf = VertexBuffer::Create(vertex_size, GL_ARRAY_BUFFER, gl_usage);
|
||||
element_buf = new VertexIndex(size);
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
delete array_buf;
|
||||
delete element_buf;
|
||||
throw;
|
||||
}
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
delete array_buf;
|
||||
delete element_buf;
|
||||
throw love::Exception("Out of memory.");
|
||||
}
|
||||
}
|
||||
@@ -94,7 +91,6 @@ SpriteBatch::~SpriteBatch()
|
||||
{
|
||||
delete color;
|
||||
delete array_buf;
|
||||
delete element_buf;
|
||||
}
|
||||
|
||||
int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/)
|
||||
@@ -103,20 +99,9 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl
|
||||
if ((index == -1 && next >= size) || index < -1 || index >= size)
|
||||
return -1;
|
||||
|
||||
Vertex sprite[4];
|
||||
Matrix t(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
|
||||
// Needed for colors.
|
||||
memcpy(sprite, texture->getVertices(), sizeof(Vertex) * 4);
|
||||
|
||||
// Transform.
|
||||
Matrix t;
|
||||
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
t.transform(sprite, sprite, 4);
|
||||
|
||||
if (color)
|
||||
setColorv(sprite, *color);
|
||||
|
||||
addv(sprite, (index == -1) ? next : index);
|
||||
addv(texture->getVertices(), t, (index == -1) ? next : index);
|
||||
|
||||
// Increment counter.
|
||||
if (index == -1)
|
||||
@@ -131,19 +116,9 @@ int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy,
|
||||
if ((index == -1 && next >= size) || index < -1 || index >= next)
|
||||
return -1;
|
||||
|
||||
Vertex sprite[4];
|
||||
Matrix t(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
|
||||
// Needed for colors.
|
||||
memcpy(sprite, quad->getVertices(), sizeof(Vertex) * 4);
|
||||
|
||||
Matrix t;
|
||||
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
t.transform(sprite, sprite, 4);
|
||||
|
||||
if (color)
|
||||
setColorv(sprite, *color);
|
||||
|
||||
addv(sprite, (index == -1) ? next : index);
|
||||
addv(quad->getVertices(), t, (index == -1) ? next : index);
|
||||
|
||||
// Increment counter.
|
||||
if (index == -1)
|
||||
@@ -171,7 +146,7 @@ void SpriteBatch::setTexture(Texture *newtexture)
|
||||
texture.set(newtexture);
|
||||
}
|
||||
|
||||
Texture *SpriteBatch::getTexture()
|
||||
Texture *SpriteBatch::getTexture() const
|
||||
{
|
||||
return texture.get();
|
||||
}
|
||||
@@ -216,37 +191,32 @@ void SpriteBatch::setBufferSize(int newsize)
|
||||
}
|
||||
|
||||
size_t vertex_size = sizeof(Vertex) * 4 * newsize;
|
||||
|
||||
VertexBuffer *new_array_buf = nullptr;
|
||||
VertexIndex *new_element_buf = nullptr;
|
||||
|
||||
try
|
||||
{
|
||||
new_array_buf = VertexBuffer::Create(vertex_size, array_buf->getTarget(), array_buf->getUsage());
|
||||
new_element_buf = new VertexIndex(newsize);
|
||||
|
||||
// Copy as much of the old data into the new VertexBuffer as can fit.
|
||||
VertexBuffer::Bind bind(*new_array_buf);
|
||||
void *new_data = new_array_buf->map();
|
||||
memcpy(new_data, old_data, sizeof(Vertex) * 4 * std::min(newsize, size));
|
||||
|
||||
element_buf = VertexIndex(newsize);
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
delete new_array_buf;
|
||||
delete new_element_buf;
|
||||
throw;
|
||||
}
|
||||
|
||||
// Copy as much of the old data into the new VertexBuffer as can fit.
|
||||
new_array_buf->fill(0, sizeof(Vertex) * 4 * std::min(newsize, size), old_data);
|
||||
|
||||
// We don't need to unmap the old VertexBuffer since we're deleting it.
|
||||
delete array_buf;
|
||||
delete element_buf;
|
||||
|
||||
array_buf = new_array_buf;
|
||||
element_buf = new_element_buf;
|
||||
size = newsize;
|
||||
|
||||
next = std::min(next, newsize);
|
||||
|
||||
// The new VertexBuffer isn't mapped, so we should reset these variables.
|
||||
buffer_used_offset = buffer_used_size = 0;
|
||||
}
|
||||
|
||||
int SpriteBatch::getBufferSize() const
|
||||
@@ -263,8 +233,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
|
||||
if (next == 0)
|
||||
return;
|
||||
|
||||
static Matrix t;
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
Matrix t(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
|
||||
OpenGL::TempTransform transform(gl);
|
||||
transform.get() *= t;
|
||||
@@ -272,7 +241,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
|
||||
texture->predraw();
|
||||
|
||||
VertexBuffer::Bind array_bind(*array_buf);
|
||||
VertexBuffer::Bind element_bind(*element_buf->getVertexBuffer());
|
||||
VertexBuffer::Bind element_bind(*element_buf.getVertexBuffer());
|
||||
|
||||
// Make sure the VBO isn't mapped when we draw (sends data to GPU if needed.)
|
||||
array_buf->unmap(buffer_used_offset, buffer_used_size);
|
||||
@@ -294,7 +263,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
|
||||
gl.setVertexAttribArray(OpenGL::ATTRIB_TEXCOORD, 2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(texel_offset));
|
||||
|
||||
gl.prepareDraw();
|
||||
gl.drawElements(GL_TRIANGLES, element_buf->getIndexCount(next), element_buf->getType(), element_buf->getPointer(0));
|
||||
gl.drawElements(GL_TRIANGLES, element_buf.getIndexCount(next), element_buf.getType(), element_buf.getPointer(0));
|
||||
|
||||
gl.disableVertexAttribArray(OpenGL::ATTRIB_POS);
|
||||
gl.disableVertexAttribArray(OpenGL::ATTRIB_TEXCOORD);
|
||||
@@ -308,9 +277,16 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
|
||||
texture->postdraw();
|
||||
}
|
||||
|
||||
void SpriteBatch::addv(const Vertex *v, int index)
|
||||
void SpriteBatch::addv(const Vertex *v, const Matrix &m, int index)
|
||||
{
|
||||
static const size_t sprite_size = 4 * sizeof(Vertex); // bytecount
|
||||
// Needed for colors.
|
||||
Vertex sprite[4] = {v[0], v[1], v[2], v[3]};
|
||||
const size_t sprite_size = 4 * sizeof(Vertex); // bytecount
|
||||
|
||||
m.transform(sprite, sprite, 4);
|
||||
|
||||
if (color)
|
||||
setColorv(sprite, *color);
|
||||
|
||||
VertexBuffer::Bind bind(*array_buf);
|
||||
|
||||
@@ -318,7 +294,7 @@ void SpriteBatch::addv(const Vertex *v, int index)
|
||||
// on draw.)
|
||||
array_buf->map();
|
||||
|
||||
array_buf->fill(index * sprite_size, sprite_size, v);
|
||||
array_buf->fill(index * sprite_size, sprite_size, sprite);
|
||||
|
||||
buffer_used_offset = std::min(buffer_used_offset, index * sprite_size);
|
||||
buffer_used_size = std::max(buffer_used_size, (index + 1) * sprite_size - buffer_used_offset);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -26,13 +26,13 @@
|
||||
|
||||
// LOVE
|
||||
#include "common/math.h"
|
||||
#include "common/Object.h"
|
||||
#include "common/Matrix.h"
|
||||
#include "common/StringMap.h"
|
||||
#include "graphics/Drawable.h"
|
||||
#include "graphics/Volatile.h"
|
||||
#include "graphics/Color.h"
|
||||
#include "graphics/Quad.h"
|
||||
#include "VertexBuffer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -43,8 +43,6 @@ namespace opengl
|
||||
|
||||
// Forward declarations.
|
||||
class Texture;
|
||||
class VertexBuffer;
|
||||
class VertexIndex;
|
||||
|
||||
class SpriteBatch : public Drawable
|
||||
{
|
||||
@@ -68,7 +66,7 @@ public:
|
||||
void flush();
|
||||
|
||||
void setTexture(Texture *newtexture);
|
||||
Texture *getTexture();
|
||||
Texture *getTexture() const;
|
||||
|
||||
/**
|
||||
* Set the current color for this SpriteBatch. The sprites added
|
||||
@@ -115,7 +113,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void addv(const Vertex *v, int index);
|
||||
void addv(const Vertex *v, const Matrix &m, int index);
|
||||
|
||||
/**
|
||||
* Set the color for vertices.
|
||||
@@ -139,7 +137,7 @@ private:
|
||||
Color *color;
|
||||
|
||||
VertexBuffer *array_buf;
|
||||
VertexIndex *element_buf;
|
||||
VertexIndex element_buf;
|
||||
|
||||
// The portion of the vertex buffer that's been modified while mapped.
|
||||
size_t buffer_used_offset;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -328,6 +328,20 @@ VertexIndex::VertexIndex(size_t size)
|
||||
addSize(size);
|
||||
}
|
||||
|
||||
VertexIndex::VertexIndex(const VertexIndex &other)
|
||||
: size(other.size)
|
||||
{
|
||||
addSize(size);
|
||||
}
|
||||
|
||||
VertexIndex &VertexIndex::operator = (const VertexIndex &other)
|
||||
{
|
||||
addSize(other.size);
|
||||
removeSize(size);
|
||||
size = other.size;
|
||||
return *this;
|
||||
}
|
||||
|
||||
VertexIndex::~VertexIndex()
|
||||
{
|
||||
removeSize(size);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -412,6 +412,9 @@ public:
|
||||
*/
|
||||
VertexIndex(size_t size);
|
||||
|
||||
VertexIndex(const VertexIndex &other);
|
||||
VertexIndex &operator = (const VertexIndex &other);
|
||||
|
||||
/**
|
||||
* Removes an entry from the list of sizes and resizes the VertexBuffer
|
||||
* if needed.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "scripts/graphics.lua.h"
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -409,6 +410,19 @@ int w_newShader(lua_State *L)
|
||||
lua_call(L, 1, 1);
|
||||
lua_replace(L, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if the argument looks like a filepath - we want a nicer
|
||||
// error for misspelled filepath arguments.
|
||||
size_t slen = 0;
|
||||
const char *str = lua_tolstring(L, i, &slen);
|
||||
if (slen > 0 && slen < 256 && !strchr(str, '\n'))
|
||||
{
|
||||
const char *ext = strchr(str, '.');
|
||||
if (ext != nullptr && !strchr(ext, ';') && !strchr(ext, ' '))
|
||||
return luaL_error(L, "Could not open file %s. Does not exist.", str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool has_arg1 = lua_isstring(L, 1);
|
||||
@@ -428,27 +442,21 @@ int w_newShader(lua_State *L)
|
||||
if (lua_pcall(L, 2, 2, 0) != 0)
|
||||
return luaL_error(L, "%s", lua_tostring(L, -1));
|
||||
|
||||
Shader::ShaderSources sources;
|
||||
Shader::ShaderSource source;
|
||||
|
||||
// vertex shader code
|
||||
if (lua_isstring(L, -2))
|
||||
{
|
||||
std::string vertexcode(luaL_checkstring(L, -2));
|
||||
sources[Shader::TYPE_VERTEX] = vertexcode;
|
||||
}
|
||||
source.vertex = luax_checkstring(L, -2);
|
||||
else if (has_arg1 && has_arg2)
|
||||
return luaL_error(L, "Could not parse vertex shader code (missing 'position' function?)");
|
||||
|
||||
// pixel shader code
|
||||
if (lua_isstring(L, -1))
|
||||
{
|
||||
std::string pixelcode(luaL_checkstring(L, -1));
|
||||
sources[Shader::TYPE_PIXEL] = pixelcode;
|
||||
}
|
||||
source.pixel = luax_checkstring(L, -1);
|
||||
else if (has_arg1 && has_arg2)
|
||||
return luaL_error(L, "Could not parse pixel shader code (missing 'effect' function?)");
|
||||
|
||||
if (sources.empty())
|
||||
if (source.vertex.empty() && source.pixel.empty())
|
||||
{
|
||||
// Original args had source code, but effectCodeToGLSL couldn't translate it
|
||||
for (int i = 1; i <= 2; i++)
|
||||
@@ -461,7 +469,7 @@ int w_newShader(lua_State *L)
|
||||
bool should_error = false;
|
||||
try
|
||||
{
|
||||
Shader *shader = instance()->newShader(sources);
|
||||
Shader *shader = instance()->newShader(source);
|
||||
luax_pushtype(L, "Shader", GRAPHICS_SHADER_T, shader);
|
||||
shader->release();
|
||||
}
|
||||
@@ -993,9 +1001,9 @@ int w_setDefaultShaderCode(lua_State *L)
|
||||
lua_rawgeti(L, -1, 1);
|
||||
lua_rawgeti(L, -2, 2);
|
||||
|
||||
Shader::ShaderSources openglcode;
|
||||
openglcode[Shader::TYPE_VERTEX] = luax_checkstring(L, -2);
|
||||
openglcode[Shader::TYPE_PIXEL] = luax_checkstring(L, -1);
|
||||
Shader::ShaderSource openglcode;
|
||||
openglcode.vertex = luax_checkstring(L, -2);
|
||||
openglcode.pixel = luax_checkstring(L, -1);
|
||||
|
||||
lua_pop(L, 3);
|
||||
|
||||
@@ -1003,9 +1011,9 @@ int w_setDefaultShaderCode(lua_State *L)
|
||||
lua_rawgeti(L, -1, 1);
|
||||
lua_rawgeti(L, -2, 2);
|
||||
|
||||
Shader::ShaderSources openglescode;
|
||||
openglescode[Shader::TYPE_VERTEX] = luax_checkstring(L, -2);
|
||||
openglescode[Shader::TYPE_PIXEL] = luax_checkstring(L, -1);
|
||||
Shader::ShaderSource openglescode;
|
||||
openglescode.vertex = luax_checkstring(L, -2);
|
||||
openglescode.pixel = luax_checkstring(L, -1);
|
||||
|
||||
lua_pop(L, 3);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -164,7 +164,7 @@ int w_ParticleSystem_getParticleLifetime(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getParticleLifetime(&min, &max);
|
||||
t->getParticleLifetime(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -278,7 +278,7 @@ int w_ParticleSystem_getSpeed(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getSpeed(&min, &max);
|
||||
t->getSpeed(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -299,7 +299,7 @@ int w_ParticleSystem_getLinearAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
love::Vector min, max;
|
||||
t->getLinearAcceleration(&min, &max);
|
||||
t->getLinearAcceleration(min, max);
|
||||
lua_pushnumber(L, min.x);
|
||||
lua_pushnumber(L, min.y);
|
||||
lua_pushnumber(L, max.x);
|
||||
@@ -320,7 +320,7 @@ int w_ParticleSystem_getRadialAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getRadialAcceleration(&min, &max);
|
||||
t->getRadialAcceleration(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -339,7 +339,26 @@ int w_ParticleSystem_getTangentialAcceleration(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getTangentialAcceleration(&min, &max);
|
||||
t->getTangentialAcceleration(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_setLinearDamping(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setLinearDamping(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_ParticleSystem_getLinearDamping(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getLinearDamping(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -411,7 +430,7 @@ int w_ParticleSystem_getRotation(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float min, max;
|
||||
t->getRotation(&min, &max);
|
||||
t->getRotation(min, max);
|
||||
lua_pushnumber(L, min);
|
||||
lua_pushnumber(L, max);
|
||||
return 2;
|
||||
@@ -430,7 +449,7 @@ int w_ParticleSystem_getSpin(lua_State *L)
|
||||
{
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
float start, end;
|
||||
t->getSpin(&start, &end);
|
||||
t->getSpin(start, end);
|
||||
lua_pushnumber(L, start);
|
||||
lua_pushnumber(L, end);
|
||||
return 2;
|
||||
@@ -730,6 +749,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getRadialAcceleration", w_ParticleSystem_getRadialAcceleration },
|
||||
{ "setTangentialAcceleration", w_ParticleSystem_setTangentialAcceleration },
|
||||
{ "getTangentialAcceleration", w_ParticleSystem_getTangentialAcceleration },
|
||||
{ "setLinearDamping", w_ParticleSystem_setLinearDamping },
|
||||
{ "getLinearDamping", w_ParticleSystem_getLinearDamping },
|
||||
{ "setSizes", w_ParticleSystem_setSizes },
|
||||
{ "getSizes", w_ParticleSystem_getSizes },
|
||||
{ "setSizeVariation", w_ParticleSystem_setSizeVariation },
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -63,6 +63,8 @@ int w_ParticleSystem_setRadialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_getRadialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_setTangentialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_getTangentialAcceleration(lua_State *L);
|
||||
int w_ParticleSystem_setLinearDamping(lua_State *L);
|
||||
int w_ParticleSystem_getLinearDamping(lua_State *L);
|
||||
int w_ParticleSystem_setSizes(lua_State *L);
|
||||
int w_ParticleSystem_getSizes(lua_State *L);
|
||||
int w_ParticleSystem_setSizeVariation(lua_State *L);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2014 LOVE Development Team
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user