You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.0 KiB
65 lines
2.0 KiB
#pragma once |
|
|
|
#include <cstddef> |
|
#include <cstdint> |
|
#include <span> |
|
|
|
#include "engine/point.hpp" |
|
#include "levels/gendung_defs.hpp" |
|
|
|
namespace devilution { |
|
|
|
class Lightmap { |
|
public: |
|
explicit Lightmap(const uint8_t *outBuffer, std::span<const uint8_t> lightmapBuffer, uint16_t pitch, const uint8_t *lightTables, size_t lightTableSize) |
|
: Lightmap(outBuffer, pitch, lightmapBuffer, pitch, lightTables, lightTableSize) |
|
{ |
|
} |
|
|
|
explicit Lightmap(const uint8_t *outBuffer, uint16_t outPitch, |
|
std::span<const uint8_t> lightmapBuffer, uint16_t lightmapPitch, |
|
const uint8_t *lightTables, size_t lightTableSize); |
|
|
|
uint8_t adjustColor(uint8_t color, uint8_t lightLevel) const |
|
{ |
|
size_t offset = lightLevel * lightTableSize + color; |
|
return lightTables[offset]; |
|
} |
|
|
|
const uint8_t *getLightingAt(const uint8_t *outLoc) const |
|
{ |
|
const ptrdiff_t outDist = outLoc - outBuffer; |
|
const ptrdiff_t rowOffset = outDist % outPitch; |
|
|
|
if (outDist < 0) { |
|
// In order to support "bleed up" for wall tiles, |
|
// reuse the first row whenever outLoc is out of bounds |
|
const int modOffset = rowOffset < 0 ? outPitch : 0; |
|
return lightmapBuffer.data() + rowOffset + modOffset; |
|
} |
|
|
|
const ptrdiff_t row = outDist / outPitch; |
|
return lightmapBuffer.data() + row * lightmapPitch + rowOffset; |
|
} |
|
|
|
static Lightmap build(bool perPixelLighting, Point tilePosition, Point targetBufferPosition, |
|
int viewportWidth, int viewportHeight, int rows, int columns, |
|
const uint8_t *outBuffer, uint16_t outPitch, |
|
const uint8_t *lightTables, size_t lightTableSize, |
|
const uint8_t tileLights[MAXDUNX][MAXDUNY], |
|
uint_fast8_t microTileLen); |
|
|
|
static Lightmap bleedUp(bool perPixelLighting, const Lightmap &source, Point targetBufferPosition, std::span<uint8_t> lightmapBuffer); |
|
|
|
private: |
|
const uint8_t *outBuffer; |
|
const uint16_t outPitch; |
|
|
|
std::span<const uint8_t> lightmapBuffer; |
|
const uint16_t lightmapPitch; |
|
|
|
const uint8_t *lightTables; |
|
const size_t lightTableSize; |
|
}; |
|
|
|
} // namespace devilution
|
|
|