rasterized occlusion culling #38
No files matched your search
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,258 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019, 2020 grondag
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grondag.bitraster;
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
public static final int UP = 1 << 1;
|
||||||
|
public static final int DOWN = 1 << 0;
|
||||||
|
public static final int EAST = 1 << 5;
|
||||||
|
public static final int WEST = 1 << 4;
|
||||||
|
public static final int NORTH = 1 << 2;
|
||||||
|
public static final int SOUTH = 1 << 3;
|
||||||
|
static final int TILE_AXIS_SHIFT = 3;
|
||||||
|
static final int TILE_AXIS_MASK = ~((1 << TILE_AXIS_SHIFT) - 1);
|
||||||
|
static final int TILE_PIXEL_DIAMETER = 1 << TILE_AXIS_SHIFT;
|
||||||
|
static final int TILE_PIXEL_INDEX_MASK = TILE_PIXEL_DIAMETER - 1;
|
||||||
|
static final int TILE_PIXEL_INVERSE_MASK = ~TILE_PIXEL_INDEX_MASK;
|
||||||
|
static final int PRECISION_BITS = 4;
|
||||||
|
static final int PRECISE_FRACTION_MASK = (1 << PRECISION_BITS) - 1;
|
||||||
|
static final int PRECISE_INTEGER_MASK = ~PRECISE_FRACTION_MASK;
|
||||||
|
static final int PRECISE_PIXEL_SIZE = 1 << PRECISION_BITS;
|
||||||
|
static final int PRECISE_PIXEL_CENTER = PRECISE_PIXEL_SIZE / 2;
|
||||||
|
static final int SCANT_PRECISE_PIXEL_CENTER = PRECISE_PIXEL_CENTER - 1;
|
||||||
|
static final int TILE_WIDTH_BITS = 8;
|
||||||
|
static final int TILE_WIDTH = 1 << TILE_WIDTH_BITS;
|
||||||
|
static final int TILE_WIDTH_MASK = TILE_WIDTH - 1;
|
||||||
|
public static final int PIXEL_WIDTH = TILE_WIDTH * TILE_PIXEL_DIAMETER;
|
||||||
|
static final int MAX_PIXEL_X = PIXEL_WIDTH - 1;
|
||||||
|
static final int HALF_PIXEL_WIDTH = PIXEL_WIDTH / 2;
|
||||||
|
static final int PRECISE_WIDTH = PIXEL_WIDTH << PRECISION_BITS;
|
||||||
|
static final int PRECISE_WIDTH_MAX = PRECISE_WIDTH - 1;
|
||||||
|
static final int HALF_PRECISE_WIDTH = PRECISE_WIDTH / 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clamp to this to ensure value + half pixel rounds down to last pixel.
|
||||||
|
*/
|
||||||
|
static final int PRECISE_WIDTH_CLAMP = PRECISE_WIDTH - PRECISE_PIXEL_CENTER;
|
||||||
|
static final int TILE_HEIGHT_BITS = 8;
|
||||||
|
static final int TILE_HEIGHT = 1 << TILE_HEIGHT_BITS;
|
||||||
|
static final int TILE_HEIGHT_MASK = (TILE_HEIGHT - 1) << TILE_WIDTH_BITS;
|
||||||
|
public static final int PIXEL_HEIGHT = TILE_HEIGHT * TILE_PIXEL_DIAMETER;
|
||||||
|
static final int MAX_PIXEL_Y = PIXEL_HEIGHT - 1;
|
||||||
|
static final int HALF_PIXEL_HEIGHT = PIXEL_HEIGHT / 2;
|
||||||
|
static final int PRECISE_HEIGHT = PIXEL_HEIGHT << PRECISION_BITS;
|
||||||
|
static final int PRECISE_HEIGHT_MAX = PRECISE_HEIGHT - 1;
|
||||||
|
static final int PRECISE_CLIP_MAX = PRECISE_HEIGHT - PRECISE_PIXEL_CENTER;
|
||||||
|
static final int HALF_PRECISE_HEIGHT = PRECISE_HEIGHT / 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clamp to this to ensure value + half pixel rounds down to last pixel.
|
||||||
|
*/
|
||||||
|
static final int PRECISE_HEIGHT_CLAMP = PRECISE_HEIGHT - PRECISE_PIXEL_CENTER;
|
||||||
|
static final int GUARD_SIZE = 512 << PRECISION_BITS;
|
||||||
|
static final int GUARD_MAX = PRECISE_WIDTH + GUARD_SIZE;
|
||||||
|
static final int GUARD_MIN = -GUARD_SIZE;
|
||||||
|
static final int CLIP_RANGE = PRECISE_WIDTH + GUARD_SIZE * 2;
|
||||||
|
static final int CLIP_MASK = ~(CLIP_RANGE - 1);
|
||||||
|
static final int TILE_COUNT = TILE_WIDTH * TILE_HEIGHT;
|
||||||
|
static final long[] EMPTY_BITS = new long[TILE_COUNT];
|
||||||
|
public static final int CAMERA_PRECISION_BITS = 12;
|
||||||
|
static final int CAMERA_PRECISION_UNITY = 1 << CAMERA_PRECISION_BITS;
|
||||||
|
static final int CAMERA_PRECISION_CHUNK_MAX = 18 * CAMERA_PRECISION_UNITY;
|
||||||
|
static final int CAMERA_PRECISION_HALF = CAMERA_PRECISION_UNITY / 2;
|
||||||
|
static final int BOUNDS_IN = 0;
|
||||||
|
static final int BOUNDS_OUTSIDE_OR_TOO_SMALL = 1;
|
||||||
|
static final int B_NEGATIVE = 8;
|
||||||
|
static final int B_ZERO = 16;
|
||||||
|
static final int B_POSITIVE = 32;
|
||||||
|
static final int A_NEGATIVE = 1;
|
||||||
|
static final int A_ZERO = 2;
|
||||||
|
static final int A_POSITIVE = 4;
|
||||||
|
static final int EDGE_TOP = B_NEGATIVE | A_ZERO;
|
||||||
|
static final int EDGE_BOTTOM = B_POSITIVE | A_ZERO;
|
||||||
|
static final int EDGE_RIGHT = B_ZERO | A_NEGATIVE;
|
||||||
|
static final int EDGE_LEFT = B_ZERO | A_POSITIVE;
|
||||||
|
static final int EDGE_TOP_RIGHT = B_NEGATIVE | A_NEGATIVE;
|
||||||
|
static final int EDGE_TOP_LEFT = B_NEGATIVE | A_POSITIVE;
|
||||||
|
static final int EDGE_BOTTOM_RIGHT = B_POSITIVE | A_NEGATIVE;
|
||||||
|
static final int EDGE_BOTTOM_LEFT = B_POSITIVE | A_POSITIVE;
|
||||||
|
static final int EDGE_POINT = A_ZERO | B_ZERO;
|
||||||
|
// subtract 1 to fit in 2 bits
|
||||||
|
static final int EVENT_0_LEFT = A_POSITIVE - 1;
|
||||||
|
static final int EVENT_0_FLAT = A_ZERO - 1;
|
||||||
|
static final int EVENT_0_RIGHT = A_NEGATIVE - 1;
|
||||||
|
static final int EVENT_POSITION_MASK = 3;
|
||||||
|
static final int EVENT_1_LEFT = EVENT_0_LEFT << 2;
|
||||||
|
static final int EVENT_1_FLAT = EVENT_0_FLAT << 2;
|
||||||
|
static final int EVENT_1_RIGHT = EVENT_0_RIGHT << 2;
|
||||||
|
static final int EVENT_2_LEFT = EVENT_1_LEFT << 2;
|
||||||
|
static final int EVENT_2_FLAT = EVENT_1_FLAT << 2;
|
||||||
|
static final int EVENT_2_RIGHT = EVENT_1_RIGHT << 2;
|
||||||
|
static final int EVENT_3_LEFT = EVENT_2_LEFT << 2;
|
||||||
|
static final int EVENT_3_FLAT = EVENT_2_FLAT << 2;
|
||||||
|
static final int EVENT_3_RIGHT = EVENT_2_RIGHT << 2;
|
||||||
|
static final int EVENT_012_RRR = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_RIGHT;
|
||||||
|
static final int EVENT_012_LRR = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_RIGHT;
|
||||||
|
static final int EVENT_012_FRR = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_RIGHT;
|
||||||
|
static final int EVENT_012_RLR = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_RIGHT;
|
||||||
|
static final int EVENT_012_LLR = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_RIGHT;
|
||||||
|
static final int EVENT_012_FLR = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_RIGHT;
|
||||||
|
static final int EVENT_012_RFR = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_RIGHT;
|
||||||
|
static final int EVENT_012_LFR = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_RIGHT;
|
||||||
|
static final int EVENT_012_FFR = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_RIGHT;
|
||||||
|
static final int EVENT_012_RRL = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_LEFT;
|
||||||
|
static final int EVENT_012_LRL = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_LEFT;
|
||||||
|
static final int EVENT_012_FRL = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_LEFT;
|
||||||
|
static final int EVENT_012_RLL = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_LEFT;
|
||||||
|
static final int EVENT_012_LLL = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_LEFT;
|
||||||
|
static final int EVENT_012_FLL = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_LEFT;
|
||||||
|
static final int EVENT_012_RFL = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_LEFT;
|
||||||
|
static final int EVENT_012_LFL = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_LEFT;
|
||||||
|
static final int EVENT_012_FFL = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_LEFT;
|
||||||
|
static final int EVENT_012_LRF = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_FLAT;
|
||||||
|
static final int EVENT_012_RRF = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_FLAT;
|
||||||
|
static final int EVENT_012_FRF = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_FLAT;
|
||||||
|
|
||||||
|
////
|
||||||
|
static final int EVENT_012_RLF = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_FLAT;
|
||||||
|
static final int EVENT_012_LLF = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_FLAT;
|
||||||
|
static final int EVENT_012_FLF = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_FLAT;
|
||||||
|
static final int EVENT_012_RFF = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_FLAT;
|
||||||
|
static final int EVENT_012_LFF = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_FLAT;
|
||||||
|
static final int EVENT_012_FFF = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_FLAT;
|
||||||
|
static final int EVENT_0123_RRRR = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_RIGHT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_LRRR = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_RIGHT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_FRRR = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_RIGHT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_RLRR = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_RIGHT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_LLRR = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_RIGHT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_FLRR = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_RIGHT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_RFRR = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_RIGHT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_LFRR = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_RIGHT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_FFRR = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_RIGHT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_RRLR = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_LEFT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_LRLR = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_LEFT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_FRLR = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_LEFT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_RLLR = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_LEFT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_LLLR = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_LEFT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_FLLR = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_LEFT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_RFLR = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_LEFT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_LFLR = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_LEFT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_FFLR = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_LEFT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_LRFR = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_FLAT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_RRFR = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_FLAT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_FRFR = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_FLAT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_RLFR = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_FLAT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_LLFR = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_FLAT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_FLFR = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_FLAT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_RFFR = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_FLAT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_LFFR = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_FLAT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_FFFR = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_FLAT | EVENT_3_RIGHT;
|
||||||
|
static final int EVENT_0123_RRRL = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_RIGHT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_LRRL = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_RIGHT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_FRRL = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_RIGHT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_RLRL = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_RIGHT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_LLRL = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_RIGHT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_FLRL = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_RIGHT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_RFRL = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_RIGHT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_LFRL = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_RIGHT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_FFRL = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_RIGHT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_RRLL = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_LEFT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_LRLL = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_LEFT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_FRLL = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_LEFT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_RLLL = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_LEFT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_LLLL = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_LEFT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_FLLL = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_LEFT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_RFLL = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_LEFT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_LFLL = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_LEFT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_FFLL = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_LEFT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_LRFL = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_FLAT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_RRFL = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_FLAT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_FRFL = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_FLAT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_RLFL = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_FLAT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_LLFL = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_FLAT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_FLFL = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_FLAT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_RFFL = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_FLAT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_LFFL = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_FLAT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_FFFL = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_FLAT | EVENT_3_LEFT;
|
||||||
|
static final int EVENT_0123_RRRF = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_RIGHT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_LRRF = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_RIGHT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_FRRF = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_RIGHT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_RLRF = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_RIGHT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_LLRF = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_RIGHT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_FLRF = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_RIGHT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_RFRF = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_RIGHT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_LFRF = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_RIGHT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_FFRF = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_RIGHT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_RRLF = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_LEFT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_LRLF = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_LEFT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_FRLF = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_LEFT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_RLLF = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_LEFT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_LLLF = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_LEFT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_FLLF = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_LEFT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_RFLF = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_LEFT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_LFLF = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_LEFT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_FFLF = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_LEFT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_LRFF = EVENT_0_LEFT | EVENT_1_RIGHT | EVENT_2_FLAT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_RRFF = EVENT_0_RIGHT | EVENT_1_RIGHT | EVENT_2_FLAT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_FRFF = EVENT_0_FLAT | EVENT_1_RIGHT | EVENT_2_FLAT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_RLFF = EVENT_0_RIGHT | EVENT_1_LEFT | EVENT_2_FLAT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_LLFF = EVENT_0_LEFT | EVENT_1_LEFT | EVENT_2_FLAT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_FLFF = EVENT_0_FLAT | EVENT_1_LEFT | EVENT_2_FLAT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_RFFF = EVENT_0_RIGHT | EVENT_1_FLAT | EVENT_2_FLAT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_LFFF = EVENT_0_LEFT | EVENT_1_FLAT | EVENT_2_FLAT | EVENT_3_FLAT;
|
||||||
|
static final int EVENT_0123_FFFF = EVENT_0_FLAT | EVENT_1_FLAT | EVENT_2_FLAT | EVENT_3_FLAT;
|
||||||
|
|
||||||
|
static final int PV_PX = 0;
|
||||||
|
static final int PV_PY = 1;
|
||||||
|
static final int PV_X = 2;
|
||||||
|
static final int PV_Y = 3;
|
||||||
|
static final int PV_Z = 4;
|
||||||
|
static final int PV_W = 5;
|
||||||
|
static final int PROJECTED_VERTEX_STRIDE = 6;
|
||||||
|
|
||||||
|
static final int V000 = 0;
|
||||||
|
static final int V001 = V000 + PROJECTED_VERTEX_STRIDE;
|
||||||
|
static final int V010 = V001 + PROJECTED_VERTEX_STRIDE;
|
||||||
|
static final int V011 = V010 + PROJECTED_VERTEX_STRIDE;
|
||||||
|
static final int V100 = V011 + PROJECTED_VERTEX_STRIDE;
|
||||||
|
static final int V101 = V100 + PROJECTED_VERTEX_STRIDE;
|
||||||
|
static final int V110 = V101 + PROJECTED_VERTEX_STRIDE;
|
||||||
|
static final int V111 = V110 + PROJECTED_VERTEX_STRIDE;
|
||||||
|
static final int IDX_AX0 = V111 + PROJECTED_VERTEX_STRIDE;
|
||||||
|
static final int IDX_AY0 = IDX_AX0 + 1;
|
||||||
|
static final int IDX_AX1 = IDX_AY0 + 1;
|
||||||
|
static final int IDX_AY1 = IDX_AX1 + 1;
|
||||||
|
|
||||||
|
static final int IDX_BX0 = IDX_AY1 + 1;
|
||||||
|
static final int IDX_BY0 = IDX_BX0 + 1;
|
||||||
|
static final int IDX_BX1 = IDX_BY0 + 1;
|
||||||
|
static final int IDX_BY1 = IDX_BX1 + 1;
|
||||||
|
|
||||||
|
static final int IDX_CX0 = IDX_BY1 + 1;
|
||||||
|
static final int IDX_CY0 = IDX_CX0 + 1;
|
||||||
|
static final int IDX_CX1 = IDX_CY0 + 1;
|
||||||
|
static final int IDX_CY1 = IDX_CX1 + 1;
|
||||||
|
|
||||||
|
static final int IDX_DX0 = IDX_CY1 + 1;
|
||||||
|
static final int IDX_DY0 = IDX_DX0 + 1;
|
||||||
|
static final int IDX_DX1 = IDX_DY0 + 1;
|
||||||
|
static final int IDX_DY1 = IDX_DX1 + 1;
|
||||||
|
|
||||||
|
static final int VERTEX_DATA_LENGTH = IDX_DY1 + 1;
|
||||||
|
|
||||||
|
static final int EVENT_DATA_LENGTH = PIXEL_HEIGHT * 2;
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019, 2020 grondag
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grondag.bitraster;
|
||||||
|
|
||||||
|
import static grondag.bitraster.Constants.TILE_AXIS_SHIFT;
|
||||||
|
import static grondag.bitraster.Constants.TILE_PIXEL_INDEX_MASK;
|
||||||
|
import static grondag.bitraster.Constants.TILE_WIDTH_BITS;
|
||||||
|
|
||||||
|
abstract class Indexer {
|
||||||
|
private Indexer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// only handle 0-7 values
|
||||||
|
static int mortonNumber(int x, int y) {
|
||||||
|
int z = (x & 0b001) | ((y & 0b001) << 1);
|
||||||
|
z |= ((x & 0b010) << 1) | ((y & 0b010) << 2);
|
||||||
|
return z | ((x & 0b100) << 2) | ((y & 0b100) << 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int tileIndex(int tileX, int tileY) {
|
||||||
|
return tileX | (tileY << TILE_WIDTH_BITS);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tileIndexFromPixelXY(int x, int y) {
|
||||||
|
return tileIndex(x >>> TILE_AXIS_SHIFT, y >>> TILE_AXIS_SHIFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pixelIndex(int x, int y) {
|
||||||
|
return ((y & TILE_PIXEL_INDEX_MASK) << TILE_AXIS_SHIFT) | (x & TILE_PIXEL_INDEX_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isPixelClear(long word, int x, int y) {
|
||||||
|
return (word & (1L << pixelIndex(x, y))) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long pixelMask(int x, int y) {
|
||||||
|
return 1L << pixelIndex(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REQUIRES 0-7 inputs!
|
||||||
|
*/
|
||||||
|
static boolean testPixelInWordPreMasked(long word, int x, int y) {
|
||||||
|
return (word & (1L << ((y << TILE_AXIS_SHIFT) | x))) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long setPixelInWordPreMasked(long word, int x, int y) {
|
||||||
|
return word | (1L << ((y << TILE_AXIS_SHIFT) | x));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -0,0 +1,383 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019, 2020 grondag
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grondag.bitraster;
|
||||||
|
|
||||||
|
public class Matrix4L {
|
||||||
|
public static final int MATRIX_PRECISION_BITS = 16;
|
||||||
|
public static final long MATRIX_PRECISION_UNITY = 1 << MATRIX_PRECISION_BITS;
|
||||||
|
public static final long MATRIX_PRECISION_HALF = MATRIX_PRECISION_UNITY / 2;
|
||||||
|
public static final float FLOAT_CONVERSION = 1f / MATRIX_PRECISION_UNITY;
|
||||||
|
|
||||||
|
private long a00;
|
||||||
|
private long a01;
|
||||||
|
private long a02;
|
||||||
|
private long a03;
|
||||||
|
private long a10;
|
||||||
|
private long a11;
|
||||||
|
private long a12;
|
||||||
|
private long a13;
|
||||||
|
private long a20;
|
||||||
|
private long a21;
|
||||||
|
private long a22;
|
||||||
|
private long a23;
|
||||||
|
private long a30;
|
||||||
|
private long a31;
|
||||||
|
private long a32;
|
||||||
|
private long a33;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("[%d, %d, %d, %d], [%d, %d, %d, %d], [%d, %d, %d, %d], [%d, %d, %d, %d]",
|
||||||
|
a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, a30, a31, a32, a33);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(
|
||||||
|
float a00, float a01, float a02, float a03,
|
||||||
|
float a10, float a11, float a12, float a13,
|
||||||
|
float a20, float a21, float a22, float a23,
|
||||||
|
float a30, float a31, float a32, float a33
|
||||||
|
) {
|
||||||
|
this.a00 = Math.round(a00 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a01 = Math.round(a01 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a02 = Math.round(a02 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a03 = Math.round(a03 * MATRIX_PRECISION_UNITY);
|
||||||
|
|
||||||
|
this.a10 = Math.round(a10 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a11 = Math.round(a11 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a12 = Math.round(a12 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a13 = Math.round(a13 * MATRIX_PRECISION_UNITY);
|
||||||
|
|
||||||
|
this.a20 = Math.round(a20 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a21 = Math.round(a21 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a22 = Math.round(a22 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a23 = Math.round(a23 * MATRIX_PRECISION_UNITY);
|
||||||
|
|
||||||
|
this.a30 = Math.round(a30 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a31 = Math.round(a31 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a32 = Math.round(a32 * MATRIX_PRECISION_UNITY);
|
||||||
|
this.a33 = Math.round(a33 * MATRIX_PRECISION_UNITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copyFrom(Matrix4L other) {
|
||||||
|
a00 = other.a00;
|
||||||
|
a01 = other.a01;
|
||||||
|
a02 = other.a02;
|
||||||
|
a03 = other.a03;
|
||||||
|
|
||||||
|
a10 = other.a10;
|
||||||
|
a11 = other.a11;
|
||||||
|
a12 = other.a12;
|
||||||
|
a13 = other.a13;
|
||||||
|
|
||||||
|
a20 = other.a20;
|
||||||
|
a21 = other.a21;
|
||||||
|
a22 = other.a22;
|
||||||
|
a23 = other.a23;
|
||||||
|
|
||||||
|
a30 = other.a30;
|
||||||
|
a31 = other.a31;
|
||||||
|
a32 = other.a32;
|
||||||
|
a33 = other.a33;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matches(Matrix4L other) {
|
||||||
|
return a00 == other.a00
|
||||||
|
&& a01 == other.a01
|
||||||
|
&& a02 == other.a02
|
||||||
|
&& a03 == other.a03
|
||||||
|
|
||||||
|
&& a10 == other.a10
|
||||||
|
&& a11 == other.a11
|
||||||
|
&& a12 == other.a12
|
||||||
|
&& a13 == other.a13
|
||||||
|
|
||||||
|
&& a20 == other.a20
|
||||||
|
&& a21 == other.a21
|
||||||
|
&& a22 == other.a22
|
||||||
|
&& a23 == other.a23
|
||||||
|
|
||||||
|
&& a30 == other.a30
|
||||||
|
&& a31 == other.a31
|
||||||
|
&& a32 == other.a32
|
||||||
|
&& a33 == other.a33;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadIdentity() {
|
||||||
|
a00 = MATRIX_PRECISION_UNITY;
|
||||||
|
a01 = 0;
|
||||||
|
a02 = 0;
|
||||||
|
a03 = 0;
|
||||||
|
a10 = 0;
|
||||||
|
a11 = MATRIX_PRECISION_UNITY;
|
||||||
|
a12 = 0;
|
||||||
|
a13 = 0;
|
||||||
|
a20 = 0;
|
||||||
|
a21 = 0;
|
||||||
|
a22 = MATRIX_PRECISION_UNITY;
|
||||||
|
a23 = 0;
|
||||||
|
a30 = 0;
|
||||||
|
a31 = 0;
|
||||||
|
a32 = 0;
|
||||||
|
a33 = MATRIX_PRECISION_UNITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void multiply(Matrix4L other) {
|
||||||
|
final long f = a00 * other.a00 + a01 * other.a10 + a02 * other.a20 + a03 * other.a30;
|
||||||
|
final long g = a00 * other.a01 + a01 * other.a11 + a02 * other.a21 + a03 * other.a31;
|
||||||
|
final long h = a00 * other.a02 + a01 * other.a12 + a02 * other.a22 + a03 * other.a32;
|
||||||
|
final long i = a00 * other.a03 + a01 * other.a13 + a02 * other.a23 + a03 * other.a33;
|
||||||
|
final long j = a10 * other.a00 + a11 * other.a10 + a12 * other.a20 + a13 * other.a30;
|
||||||
|
final long k = a10 * other.a01 + a11 * other.a11 + a12 * other.a21 + a13 * other.a31;
|
||||||
|
final long l = a10 * other.a02 + a11 * other.a12 + a12 * other.a22 + a13 * other.a32;
|
||||||
|
final long m = a10 * other.a03 + a11 * other.a13 + a12 * other.a23 + a13 * other.a33;
|
||||||
|
final long n = a20 * other.a00 + a21 * other.a10 + a22 * other.a20 + a23 * other.a30;
|
||||||
|
final long o = a20 * other.a01 + a21 * other.a11 + a22 * other.a21 + a23 * other.a31;
|
||||||
|
final long p = a20 * other.a02 + a21 * other.a12 + a22 * other.a22 + a23 * other.a32;
|
||||||
|
final long q = a20 * other.a03 + a21 * other.a13 + a22 * other.a23 + a23 * other.a33;
|
||||||
|
final long r = a30 * other.a00 + a31 * other.a10 + a32 * other.a20 + a33 * other.a30;
|
||||||
|
final long s = a30 * other.a01 + a31 * other.a11 + a32 * other.a21 + a33 * other.a31;
|
||||||
|
final long t = a30 * other.a02 + a31 * other.a12 + a32 * other.a22 + a33 * other.a32;
|
||||||
|
final long u = a30 * other.a03 + a31 * other.a13 + a32 * other.a23 + a33 * other.a33;
|
||||||
|
a00 = ((f + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a01 = ((g + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a02 = ((h + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a03 = ((i + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a10 = ((j + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a11 = ((k + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a12 = ((l + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a13 = ((m + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a20 = ((n + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a21 = ((o + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a22 = ((p + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a23 = ((q + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a30 = ((r + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a31 = ((s + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a32 = ((t + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a33 = ((u + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void translate(long x, long y, long z, int precision) {
|
||||||
|
final int shift = MATRIX_PRECISION_BITS - precision;
|
||||||
|
assert shift >= 0;
|
||||||
|
|
||||||
|
final long t_a03 = x << shift;
|
||||||
|
final long t_a13 = y << shift;
|
||||||
|
final long t_a23 = z << shift;
|
||||||
|
|
||||||
|
final long i = a00 * t_a03 + a01 * t_a13 + a02 * t_a23 + a03;
|
||||||
|
final long m = a10 * t_a03 + a11 * t_a13 + a12 * t_a23 + a13;
|
||||||
|
final long q = a20 * t_a03 + a21 * t_a13 + a22 * t_a23 + a23;
|
||||||
|
final long u = a30 * t_a03 + a31 * t_a13 + a32 * t_a23 + a33;
|
||||||
|
|
||||||
|
a03 += ((i + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a13 += ((m + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a23 += ((q + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
a33 += ((u + MATRIX_PRECISION_HALF) >> MATRIX_PRECISION_BITS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a00f() {
|
||||||
|
return FLOAT_CONVERSION * a00;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a01f() {
|
||||||
|
return FLOAT_CONVERSION * a01;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a02f() {
|
||||||
|
return FLOAT_CONVERSION * a02;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a03f() {
|
||||||
|
return FLOAT_CONVERSION * a03;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a10f() {
|
||||||
|
return FLOAT_CONVERSION * a10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a11f() {
|
||||||
|
return FLOAT_CONVERSION * a11;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a12f() {
|
||||||
|
return FLOAT_CONVERSION * a12;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a13f() {
|
||||||
|
return FLOAT_CONVERSION * a13;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a20f() {
|
||||||
|
return FLOAT_CONVERSION * a20;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a21f() {
|
||||||
|
return FLOAT_CONVERSION * a21;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a22f() {
|
||||||
|
return FLOAT_CONVERSION * a22;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a23f() {
|
||||||
|
return FLOAT_CONVERSION * a23;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a30f() {
|
||||||
|
return FLOAT_CONVERSION * a30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a31f() {
|
||||||
|
return FLOAT_CONVERSION * a31;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a32f() {
|
||||||
|
return FLOAT_CONVERSION * a32;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float a33f() {
|
||||||
|
return FLOAT_CONVERSION * a33;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a00() {
|
||||||
|
return a00;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a01() {
|
||||||
|
return a01;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a02() {
|
||||||
|
return a02;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a03() {
|
||||||
|
return a03;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a10() {
|
||||||
|
return a10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a11() {
|
||||||
|
return a11;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a12() {
|
||||||
|
return a12;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a13() {
|
||||||
|
return a13;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a20() {
|
||||||
|
return a20;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a21() {
|
||||||
|
return a21;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a22() {
|
||||||
|
return a22;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a23() {
|
||||||
|
return a23;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a30() {
|
||||||
|
return a30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a31() {
|
||||||
|
return a31;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a32() {
|
||||||
|
return a32;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long a33() {
|
||||||
|
return a33;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes X component of transformed vector. Assumes input W is 1.
|
||||||
|
* Result has standard precision.
|
||||||
|
*/
|
||||||
|
public long transformVec4X(int x, int y, int z) {
|
||||||
|
return a00 * x + a01 * y + a02 * z + a03;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes Y component of transformed vector. Assumes input W is 1.
|
||||||
|
* Result has standard precision.
|
||||||
|
*/
|
||||||
|
public long transformVec4Y(int x, int y, int z) {
|
||||||
|
return a10 * x + a11 * y + a12 * z + a13;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes Z component of transformed vector. Assumes input W is 1.
|
||||||
|
* Result has standard precision.
|
||||||
|
*/
|
||||||
|
public long transformVec4Z(int x, int y, int z) {
|
||||||
|
return a20 * x + a21 * y + a22 * z + a23;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes W component of transformed vector. Assumes input W is 1.
|
||||||
|
* Result has standard precision.
|
||||||
|
*/
|
||||||
|
public long transformVec4W(int x, int y, int z) {
|
||||||
|
return a30 * x + a31 * y + a32 * z + a33;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes X component of transformed vector.
|
||||||
|
* Result has standard precision.
|
||||||
|
*/
|
||||||
|
public long transformVec4X(int x, int y, int z, int w) {
|
||||||
|
return a00 * x + a01 * y + a02 * z + a03 * w;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes Y component of transformed vector.
|
||||||
|
* Result has standard precision.
|
||||||
|
*/
|
||||||
|
public long transformVec4Y(int x, int y, int z, int w) {
|
||||||
|
return a10 * x + a11 * y + a12 * z + a13 * w;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes Z component of transformed vector.
|
||||||
|
* Result has standard precision.
|
||||||
|
*/
|
||||||
|
public long transformVec4Z(int x, int y, int z, int w) {
|
||||||
|
return a20 * x + a21 * y + a22 * z + a23 * w;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes W component of transformed vector.
|
||||||
|
* Result has standard precision.
|
||||||
|
*/
|
||||||
|
public long transformVec4W(int x, int y, int z, int w) {
|
||||||
|
return a30 * x + a31 * y + a32 * z + a33 * w;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019, 2020 grondag
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grondag.bitraster;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For crude but simple microbenchmarks - for small scope, in-game situations
|
||||||
|
* where JMH would be more than I want.
|
||||||
|
*/
|
||||||
|
public class MicroTimer {
|
||||||
|
private final int sampleSize;
|
||||||
|
private final String label;
|
||||||
|
private int hits;
|
||||||
|
private long elapsed;
|
||||||
|
private long min;
|
||||||
|
private long max;
|
||||||
|
private long started;
|
||||||
|
|
||||||
|
private int subsetHits;
|
||||||
|
private long subsetElapsed;
|
||||||
|
private long subsetMin;
|
||||||
|
private long subsetMax;
|
||||||
|
|
||||||
|
public MicroTimer(String label, int sampleSize) {
|
||||||
|
this.label = label;
|
||||||
|
this.sampleSize = sampleSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hits() {
|
||||||
|
return hits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long elapsed() {
|
||||||
|
return elapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
started = System.nanoTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if timer output stats this sample. For use if want to output
|
||||||
|
* supplementary information at same time.
|
||||||
|
*/
|
||||||
|
public boolean stop(boolean subset) {
|
||||||
|
final long t = System.nanoTime() - started;
|
||||||
|
elapsed += t;
|
||||||
|
|
||||||
|
if (t < min) {
|
||||||
|
min = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t > max) {
|
||||||
|
max = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subset) {
|
||||||
|
++subsetHits;
|
||||||
|
subsetElapsed += t;
|
||||||
|
|
||||||
|
if (t < subsetMin) {
|
||||||
|
subsetMin = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t > subsetMax) {
|
||||||
|
subsetMax = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final long h = ++hits;
|
||||||
|
|
||||||
|
if (h == sampleSize) {
|
||||||
|
reportAndClear();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reportAndClear() {
|
||||||
|
if (hits == 0) {
|
||||||
|
hits = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(String.format("Avg %s duration = %,d ns, min = %d, max = %d, total duration = %,d, total runs = %,d", label,
|
||||||
|
elapsed / hits, min, max, elapsed / 1000000, hits));
|
||||||
|
|
||||||
|
if (subsetHits > 0) {
|
||||||
|
if (subsetElapsed == 0) {
|
||||||
|
subsetElapsed = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(String.format("Subset avg duration = %,d ns, min = %d, max = %d, total duration = %,d, (%d) total runs = %,d",
|
||||||
|
subsetElapsed / subsetHits, subsetMin, subsetMax, subsetElapsed / 1000000, subsetElapsed * 100L / elapsed, subsetHits));
|
||||||
|
|
||||||
|
subsetHits = 0;
|
||||||
|
subsetElapsed = 0;
|
||||||
|
subsetMax = Long.MIN_VALUE;
|
||||||
|
subsetMin = Long.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
hits = 0;
|
||||||
|
elapsed = 0;
|
||||||
|
max = Long.MIN_VALUE;
|
||||||
|
min = Long.MAX_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019, 2020 grondag
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grondag.bitraster;
|
||||||
|
|
||||||
|
import static grondag.bitraster.Constants.HALF_PRECISE_HEIGHT;
|
||||||
|
import static grondag.bitraster.Constants.HALF_PRECISE_WIDTH;
|
||||||
|
import static grondag.bitraster.Constants.PV_PX;
|
||||||
|
import static grondag.bitraster.Constants.PV_PY;
|
||||||
|
import static grondag.bitraster.Constants.PV_X;
|
||||||
|
import static grondag.bitraster.Constants.PV_Y;
|
||||||
|
|
||||||
|
public final class OrthoRasterizer extends AbstractRasterizer {
|
||||||
|
@Override
|
||||||
|
int prepareBounds(int v0, int v1, int v2, int v3) {
|
||||||
|
return prepareBoundsNoClip(v0, v1, v2, v3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override void setupVertex(final int baseIndex, final int x, final int y, final int z) {
|
||||||
|
final int[] data = vertexData;
|
||||||
|
final Matrix4L mvpMatrix = this.mvpMatrix;
|
||||||
|
|
||||||
|
final float tx = mvpMatrix.transformVec4X(x, y, z) * Matrix4L.FLOAT_CONVERSION;
|
||||||
|
final float ty = mvpMatrix.transformVec4Y(x, y, z) * Matrix4L.FLOAT_CONVERSION;
|
||||||
|
|
||||||
|
data[baseIndex + PV_X] = Float.floatToRawIntBits(tx);
|
||||||
|
data[baseIndex + PV_Y] = Float.floatToRawIntBits(ty);
|
||||||
|
|
||||||
|
final int px = Math.round(tx * HALF_PRECISE_WIDTH) + HALF_PRECISE_WIDTH;
|
||||||
|
final int py = Math.round(ty * HALF_PRECISE_HEIGHT) + HALF_PRECISE_HEIGHT;
|
||||||
|
|
||||||
|
data[baseIndex + PV_PX] = px;
|
||||||
|
data[baseIndex + PV_PY] = py;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019, 2020 grondag
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grondag.bitraster;
|
||||||
|
|
||||||
|
public abstract class PackedBox {
|
||||||
|
public static final int RANGE_NEAR = 0;
|
||||||
|
public static final int RANGE_MID = 1;
|
||||||
|
public static final int RANGE_FAR = 2;
|
||||||
|
public static final int RANGE_EXTREME = 3;
|
||||||
|
public static final int CHUNK_DIST_NEAR = 1;
|
||||||
|
public static final int CHUNK_DIST_MID = 2;
|
||||||
|
public static final int CHUNK_DIST_FAR = 8;
|
||||||
|
public static final int SQUARE_CHUNK_DIST_NEAR = CHUNK_DIST_NEAR * CHUNK_DIST_NEAR * 3;
|
||||||
|
public static final int SQUARE_CHUNK_DIST_MID = CHUNK_DIST_MID * CHUNK_DIST_MID * 3;
|
||||||
|
public static final int SQUARE_CHUNK_DIST_FAR = CHUNK_DIST_FAR * CHUNK_DIST_FAR * 3;
|
||||||
|
public static final int EMPTY_BOX = 0;
|
||||||
|
private static final int SHIFT_X0 = 0;
|
||||||
|
private static final int SHIFT_Y0 = SHIFT_X0 + 5;
|
||||||
|
private static final int SHIFT_Z0 = SHIFT_Y0 + 5;
|
||||||
|
private static final int SHIFT_X1 = SHIFT_Z0 + 5;
|
||||||
|
private static final int SHIFT_Y1 = SHIFT_X1 + 5;
|
||||||
|
private static final int SHIFT_Z1 = SHIFT_Y1 + 5;
|
||||||
|
private static final int SHIFT_RANGE = SHIFT_Z1 + 5;
|
||||||
|
public static final int FULL_BOX = pack(0, 0, 0, 16, 16, 16, RANGE_EXTREME);
|
||||||
|
|
||||||
|
private PackedBox() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int rangeFromSquareChunkDist(int squareChunkDist) {
|
||||||
|
if (squareChunkDist <= SQUARE_CHUNK_DIST_MID) {
|
||||||
|
return squareChunkDist > SQUARE_CHUNK_DIST_NEAR ? RANGE_MID : RANGE_NEAR;
|
||||||
|
} else {
|
||||||
|
return squareChunkDist > SQUARE_CHUNK_DIST_FAR ? RANGE_EXTREME : RANGE_FAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int pack(int x0, int y0, int z0, int x1, int y1, int z1, int range) {
|
||||||
|
return x0 | (y0 << SHIFT_Y0) | (z0 << SHIFT_Z0)
|
||||||
|
| ((x1) << SHIFT_X1) | ((y1) << SHIFT_Y1) | ((z1) << SHIFT_Z1)
|
||||||
|
| (range << SHIFT_RANGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int range(int packed) {
|
||||||
|
return (packed >>> SHIFT_RANGE) & 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int x0(int packed) {
|
||||||
|
return (packed & 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int y0(int packed) {
|
||||||
|
return (packed >>> SHIFT_Y0) & 31;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int z0(int packed) {
|
||||||
|
return (packed >>> SHIFT_Z0) & 31;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int x1(int packed) {
|
||||||
|
return ((packed >>> SHIFT_X1) & 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int y1(int packed) {
|
||||||
|
return ((packed >>> SHIFT_Y1) & 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int z1(int packed) {
|
||||||
|
return ((packed >>> SHIFT_Z1) & 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(int packed) {
|
||||||
|
return "(" + x0(packed) + ", " + y0(packed) + ", " + z0(packed) + "), ("
|
||||||
|
+ x1(packed) + ", " + y1(packed) + ", " + z1(packed) + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,755 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019, 2020 grondag
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grondag.bitraster;
|
||||||
|
|
||||||
|
import static grondag.bitraster.Constants.BOUNDS_IN;
|
||||||
|
import static grondag.bitraster.Constants.BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
import static grondag.bitraster.Constants.EVENT_POSITION_MASK;
|
||||||
|
import static grondag.bitraster.Constants.HALF_PRECISE_HEIGHT;
|
||||||
|
import static grondag.bitraster.Constants.HALF_PRECISE_WIDTH;
|
||||||
|
import static grondag.bitraster.Constants.IDX_AX0;
|
||||||
|
import static grondag.bitraster.Constants.IDX_AX1;
|
||||||
|
import static grondag.bitraster.Constants.IDX_AY0;
|
||||||
|
import static grondag.bitraster.Constants.IDX_AY1;
|
||||||
|
import static grondag.bitraster.Constants.IDX_BX0;
|
||||||
|
import static grondag.bitraster.Constants.IDX_BX1;
|
||||||
|
import static grondag.bitraster.Constants.IDX_BY0;
|
||||||
|
import static grondag.bitraster.Constants.IDX_BY1;
|
||||||
|
import static grondag.bitraster.Constants.IDX_CX0;
|
||||||
|
import static grondag.bitraster.Constants.IDX_CX1;
|
||||||
|
import static grondag.bitraster.Constants.IDX_CY0;
|
||||||
|
import static grondag.bitraster.Constants.IDX_CY1;
|
||||||
|
import static grondag.bitraster.Constants.IDX_DX0;
|
||||||
|
import static grondag.bitraster.Constants.IDX_DX1;
|
||||||
|
import static grondag.bitraster.Constants.IDX_DY0;
|
||||||
|
import static grondag.bitraster.Constants.IDX_DY1;
|
||||||
|
import static grondag.bitraster.Constants.PRECISE_HEIGHT;
|
||||||
|
import static grondag.bitraster.Constants.PRECISE_HEIGHT_CLAMP;
|
||||||
|
import static grondag.bitraster.Constants.PRECISE_WIDTH;
|
||||||
|
import static grondag.bitraster.Constants.PRECISE_WIDTH_CLAMP;
|
||||||
|
import static grondag.bitraster.Constants.PRECISION_BITS;
|
||||||
|
import static grondag.bitraster.Constants.PV_PX;
|
||||||
|
import static grondag.bitraster.Constants.PV_PY;
|
||||||
|
import static grondag.bitraster.Constants.PV_W;
|
||||||
|
import static grondag.bitraster.Constants.PV_X;
|
||||||
|
import static grondag.bitraster.Constants.PV_Y;
|
||||||
|
import static grondag.bitraster.Constants.PV_Z;
|
||||||
|
import static grondag.bitraster.Constants.SCANT_PRECISE_PIXEL_CENTER;
|
||||||
|
|
||||||
|
public final class PerspectiveRasterizer extends AbstractRasterizer {
|
||||||
|
/** Holds results of {@link #clipNear(int, int)}. */
|
||||||
|
private int clipX, clipY;
|
||||||
|
|
||||||
|
@Override void setupVertex(final int baseIndex, final int x, final int y, final int z) {
|
||||||
|
final int[] data = vertexData;
|
||||||
|
final Matrix4L mvpMatrix = this.mvpMatrix;
|
||||||
|
|
||||||
|
final float tx = mvpMatrix.transformVec4X(x, y, z) * Matrix4L.FLOAT_CONVERSION;
|
||||||
|
final float ty = mvpMatrix.transformVec4Y(x, y, z) * Matrix4L.FLOAT_CONVERSION;
|
||||||
|
final float w = mvpMatrix.transformVec4W(x, y, z) * Matrix4L.FLOAT_CONVERSION;
|
||||||
|
|
||||||
|
data[baseIndex + PV_X] = Float.floatToRawIntBits(tx);
|
||||||
|
data[baseIndex + PV_Y] = Float.floatToRawIntBits(ty);
|
||||||
|
data[baseIndex + PV_Z] = Float.floatToRawIntBits(mvpMatrix.transformVec4Z(x, y, z) * Matrix4L.FLOAT_CONVERSION);
|
||||||
|
data[baseIndex + PV_W] = Float.floatToRawIntBits(w);
|
||||||
|
|
||||||
|
if (w != 0) {
|
||||||
|
final float iw = 1f / w;
|
||||||
|
final int px = Math.round(tx * iw * HALF_PRECISE_WIDTH) + HALF_PRECISE_WIDTH;
|
||||||
|
final int py = Math.round(ty * iw * HALF_PRECISE_HEIGHT) + HALF_PRECISE_HEIGHT;
|
||||||
|
|
||||||
|
data[baseIndex + PV_PX] = px;
|
||||||
|
data[baseIndex + PV_PY] = py;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clipNear(int internal, int external) {
|
||||||
|
final int[] data = vertexData;
|
||||||
|
|
||||||
|
final float intX = Float.intBitsToFloat(data[internal + PV_X]);
|
||||||
|
final float intY = Float.intBitsToFloat(data[internal + PV_Y]);
|
||||||
|
final float intZ = Float.intBitsToFloat(data[internal + PV_Z]);
|
||||||
|
final float intW = Float.intBitsToFloat(data[internal + PV_W]);
|
||||||
|
|
||||||
|
final float extX = Float.intBitsToFloat(data[external + PV_X]);
|
||||||
|
final float extY = Float.intBitsToFloat(data[external + PV_Y]);
|
||||||
|
final float extZ = Float.intBitsToFloat(data[external + PV_Z]);
|
||||||
|
final float extW = Float.intBitsToFloat(data[external + PV_W]);
|
||||||
|
|
||||||
|
// intersection point is the projection plane, at which point Z == 1
|
||||||
|
// and w will be 0 but projection division isn't needed, so force output to W = 1
|
||||||
|
// see https://www.cs.usfca.edu/~cruse/math202s11/homocoords.pdf
|
||||||
|
|
||||||
|
final float wt = intZ / -(extZ - intZ);
|
||||||
|
|
||||||
|
// note again that projection division isn't needed
|
||||||
|
final float x = (intX + (extX - intX) * wt);
|
||||||
|
final float y = (intY + (extY - intY) * wt);
|
||||||
|
final float w = (intW + (extW - intW) * wt);
|
||||||
|
final float iw = 1f / w;
|
||||||
|
|
||||||
|
clipX = Math.round(iw * x * HALF_PRECISE_WIDTH) + HALF_PRECISE_WIDTH;
|
||||||
|
clipY = Math.round(iw * y * HALF_PRECISE_HEIGHT) + HALF_PRECISE_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int prepareBounds(int v0, int v1, int v2, int v3) {
|
||||||
|
// puts bits in lexical order
|
||||||
|
final int split = needsNearClip(v3) | (needsNearClip(v2) << 1) | (needsNearClip(v1) << 2) | (needsNearClip(v0) << 3);
|
||||||
|
|
||||||
|
switch (split) {
|
||||||
|
case 0b0000:
|
||||||
|
return prepareBounds0000(v0, v1, v2, v3);
|
||||||
|
|
||||||
|
case 0b0001:
|
||||||
|
return prepareBounds0001(v0, v1, v2, v3);
|
||||||
|
|
||||||
|
case 0b0010:
|
||||||
|
return prepareBounds0001(v3, v0, v1, v2);
|
||||||
|
|
||||||
|
case 0b0100:
|
||||||
|
return prepareBounds0001(v2, v3, v0, v1);
|
||||||
|
|
||||||
|
case 0b1000:
|
||||||
|
return prepareBounds0001(v1, v2, v3, v0);
|
||||||
|
|
||||||
|
case 0b0011:
|
||||||
|
return prepareBounds0011(v0, v1, v2, v3);
|
||||||
|
|
||||||
|
case 0b1001:
|
||||||
|
return prepareBounds0011(v1, v2, v3, v0);
|
||||||
|
|
||||||
|
case 0b1100:
|
||||||
|
return prepareBounds0011(v2, v3, v0, v1);
|
||||||
|
|
||||||
|
case 0b0110:
|
||||||
|
return prepareBounds0011(v3, v0, v1, v2);
|
||||||
|
|
||||||
|
case 0b0111:
|
||||||
|
return prepareBounds0111(v0, v1, v2, v3);
|
||||||
|
|
||||||
|
case 0b1011:
|
||||||
|
return prepareBounds0111(v1, v2, v3, v0);
|
||||||
|
|
||||||
|
case 0b1101:
|
||||||
|
return prepareBounds0111(v2, v3, v0, v1);
|
||||||
|
|
||||||
|
case 0b1110:
|
||||||
|
return prepareBounds0111(v3, v0, v1, v2);
|
||||||
|
|
||||||
|
case 0b1111:
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert false : "Occlusion edge case";
|
||||||
|
// NOOP
|
||||||
|
}
|
||||||
|
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int prepareBounds0000(int v0, int v1, int v2, int v3) {
|
||||||
|
final int[] data = vertexData;
|
||||||
|
int ax0, ay0, ax1, ay1;
|
||||||
|
int bx0, by0, bx1, by1;
|
||||||
|
int cx0, cy0, cx1, cy1;
|
||||||
|
int dx0, dy0, dx1, dy1;
|
||||||
|
int minY = 0, maxY = 0, minX = 0, maxX = 0;
|
||||||
|
|
||||||
|
ax0 = data[v0 + PV_PX];
|
||||||
|
ay0 = data[v0 + PV_PY];
|
||||||
|
bx0 = data[v1 + PV_PX];
|
||||||
|
by0 = data[v1 + PV_PY];
|
||||||
|
cx0 = data[v2 + PV_PX];
|
||||||
|
cy0 = data[v2 + PV_PY];
|
||||||
|
dx0 = data[v3 + PV_PX];
|
||||||
|
dy0 = data[v3 + PV_PY];
|
||||||
|
|
||||||
|
ax1 = bx0;
|
||||||
|
ay1 = by0;
|
||||||
|
bx1 = cx0;
|
||||||
|
by1 = cy0;
|
||||||
|
cx1 = dx0;
|
||||||
|
cy1 = dy0;
|
||||||
|
dx1 = ax0;
|
||||||
|
dy1 = ay0;
|
||||||
|
|
||||||
|
minX = ax0;
|
||||||
|
maxX = ax0;
|
||||||
|
|
||||||
|
if (bx0 < minX) {
|
||||||
|
minX = bx0;
|
||||||
|
} else if (bx0 > maxX) {
|
||||||
|
maxX = bx0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cx0 < minX) {
|
||||||
|
minX = cx0;
|
||||||
|
} else if (cx0 > maxX) {
|
||||||
|
maxX = cx0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dx0 < minX) {
|
||||||
|
minX = dx0;
|
||||||
|
} else if (dx0 > maxX) {
|
||||||
|
maxX = dx0;
|
||||||
|
}
|
||||||
|
|
||||||
|
minY = ay0;
|
||||||
|
maxY = ay0;
|
||||||
|
|
||||||
|
if (by0 < minY) {
|
||||||
|
minY = by0;
|
||||||
|
} else if (by0 > maxY) {
|
||||||
|
maxY = by0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cy0 < minY) {
|
||||||
|
minY = cy0;
|
||||||
|
} else if (cy0 > maxY) {
|
||||||
|
maxY = cy0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dy0 < minY) {
|
||||||
|
minY = dy0;
|
||||||
|
} else if (dy0 > maxY) {
|
||||||
|
maxY = dy0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxY <= 0 || minY >= PRECISE_HEIGHT) {
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxX <= 0 || minX >= PRECISE_WIDTH) {
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minX < 0) {
|
||||||
|
minX = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxX >= PRECISE_WIDTH_CLAMP) {
|
||||||
|
maxX = PRECISE_WIDTH_CLAMP;
|
||||||
|
|
||||||
|
if (minX > PRECISE_WIDTH_CLAMP) {
|
||||||
|
minX = PRECISE_WIDTH_CLAMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minY < 0) {
|
||||||
|
minY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxY >= PRECISE_HEIGHT_CLAMP) {
|
||||||
|
maxY = PRECISE_HEIGHT_CLAMP;
|
||||||
|
|
||||||
|
if (minY > PRECISE_HEIGHT_CLAMP) {
|
||||||
|
minY = PRECISE_HEIGHT_CLAMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final int minPixelX = ((minX + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int minPixelY = ((minY + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int maxPixelX = ((maxX + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int maxPixelY = ((maxY + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
|
||||||
|
final int position0 = edgePosition(ax0, ay0, ax1, ay1);
|
||||||
|
final int position1 = edgePosition(bx0, by0, bx1, by1);
|
||||||
|
final int position2 = edgePosition(cx0, cy0, cx1, cy1);
|
||||||
|
final int position3 = edgePosition(dx0, dy0, dx1, dy1);
|
||||||
|
|
||||||
|
this.minPixelX = minPixelX;
|
||||||
|
this.minPixelY = minPixelY;
|
||||||
|
this.maxPixelX = maxPixelX;
|
||||||
|
this.maxPixelY = maxPixelY;
|
||||||
|
data[IDX_AX0] = ax0;
|
||||||
|
data[IDX_AY0] = ay0;
|
||||||
|
data[IDX_AX1] = ax1;
|
||||||
|
data[IDX_AY1] = ay1;
|
||||||
|
data[IDX_BX0] = bx0;
|
||||||
|
data[IDX_BY0] = by0;
|
||||||
|
data[IDX_BX1] = bx1;
|
||||||
|
data[IDX_BY1] = by1;
|
||||||
|
data[IDX_CX0] = cx0;
|
||||||
|
data[IDX_CY0] = cy0;
|
||||||
|
data[IDX_CX1] = cx1;
|
||||||
|
data[IDX_CY1] = cy1;
|
||||||
|
data[IDX_DX0] = dx0;
|
||||||
|
data[IDX_DY0] = dy0;
|
||||||
|
data[IDX_DX1] = dx1;
|
||||||
|
data[IDX_DY1] = dy1;
|
||||||
|
pos0 = position0;
|
||||||
|
pos1 = position1;
|
||||||
|
pos2 = position2;
|
||||||
|
pos3 = position3;
|
||||||
|
|
||||||
|
final int eventKey = (position0 - 1) & EVENT_POSITION_MASK
|
||||||
|
| (((position1 - 1) & EVENT_POSITION_MASK) << 2)
|
||||||
|
| (((position2 - 1) & EVENT_POSITION_MASK) << 4)
|
||||||
|
| (((position3 - 1) & EVENT_POSITION_MASK) << 6);
|
||||||
|
|
||||||
|
prepareEvents(eventKey);
|
||||||
|
return BOUNDS_IN;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int prepareBounds0001(int v0, int v1, int v2, int ext3) {
|
||||||
|
final int[] data = vertexData;
|
||||||
|
int ax0, ay0, ax1, ay1;
|
||||||
|
int bx0, by0, bx1, by1;
|
||||||
|
int cx0, cy0, cx1, cy1;
|
||||||
|
int dx0, dy0, dx1, dy1;
|
||||||
|
int minY = 0, maxY = 0, minX = 0, maxX = 0;
|
||||||
|
|
||||||
|
ax0 = data[v0 + PV_PX];
|
||||||
|
ay0 = data[v0 + PV_PY];
|
||||||
|
ax1 = data[v1 + PV_PX];
|
||||||
|
ay1 = data[v1 + PV_PY];
|
||||||
|
|
||||||
|
bx0 = ax1;
|
||||||
|
by0 = ay1;
|
||||||
|
bx1 = data[v2 + PV_PX];
|
||||||
|
by1 = data[v2 + PV_PY];
|
||||||
|
|
||||||
|
cx0 = bx1;
|
||||||
|
cy0 = by1;
|
||||||
|
clipNear(v2, ext3);
|
||||||
|
cx1 = clipX;
|
||||||
|
cy1 = clipY;
|
||||||
|
|
||||||
|
clipNear(v0, ext3);
|
||||||
|
dx0 = clipX;
|
||||||
|
dy0 = clipY;
|
||||||
|
dx1 = ax0;
|
||||||
|
dy1 = ay0;
|
||||||
|
|
||||||
|
minX = ax0;
|
||||||
|
maxX = ax0;
|
||||||
|
|
||||||
|
// ax1 = bx0 and dx1 = ax0, so no need to test those
|
||||||
|
if (bx0 < minX) {
|
||||||
|
minX = bx0;
|
||||||
|
} else if (bx0 > maxX) {
|
||||||
|
maxX = bx0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cx0 < minX) {
|
||||||
|
minX = cx0;
|
||||||
|
} else if (cx0 > maxX) {
|
||||||
|
maxX = cx0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cx1 < minX) {
|
||||||
|
minX = cx1;
|
||||||
|
} else if (cx1 > maxX) {
|
||||||
|
maxX = cx1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dx0 < minX) {
|
||||||
|
minX = dx0;
|
||||||
|
} else if (dx0 > maxX) {
|
||||||
|
maxX = dx0;
|
||||||
|
}
|
||||||
|
|
||||||
|
minY = ay0;
|
||||||
|
maxY = ay0;
|
||||||
|
|
||||||
|
if (by0 < minY) {
|
||||||
|
minY = by0;
|
||||||
|
} else if (by0 > maxY) {
|
||||||
|
maxY = by0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cy0 < minY) {
|
||||||
|
minY = cy0;
|
||||||
|
} else if (cy0 > maxY) {
|
||||||
|
maxY = cy0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cy1 < minY) {
|
||||||
|
minY = cy1;
|
||||||
|
} else if (cy1 > maxY) {
|
||||||
|
maxY = cy1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dy0 < minY) {
|
||||||
|
minY = dy0;
|
||||||
|
} else if (dy0 > maxY) {
|
||||||
|
maxY = dy0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxY <= 0 || minY >= PRECISE_HEIGHT) {
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxX <= 0 || minX >= PRECISE_WIDTH) {
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minX < 0) {
|
||||||
|
minX = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxX >= PRECISE_WIDTH_CLAMP) {
|
||||||
|
maxX = PRECISE_WIDTH_CLAMP;
|
||||||
|
|
||||||
|
if (minX > PRECISE_WIDTH_CLAMP) {
|
||||||
|
minX = PRECISE_WIDTH_CLAMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minY < 0) {
|
||||||
|
minY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxY >= PRECISE_HEIGHT_CLAMP) {
|
||||||
|
maxY = PRECISE_HEIGHT_CLAMP;
|
||||||
|
|
||||||
|
if (minY > PRECISE_HEIGHT_CLAMP) {
|
||||||
|
minY = PRECISE_HEIGHT_CLAMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final int minPixelX = ((minX + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int minPixelY = ((minY + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int maxPixelX = ((maxX + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int maxPixelY = ((maxY + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
|
||||||
|
final int position0 = edgePosition(ax0, ay0, ax1, ay1);
|
||||||
|
final int position1 = edgePosition(bx0, by0, bx1, by1);
|
||||||
|
final int position2 = edgePosition(cx0, cy0, cx1, cy1);
|
||||||
|
final int position3 = edgePosition(dx0, dy0, dx1, dy1);
|
||||||
|
|
||||||
|
this.minPixelX = minPixelX;
|
||||||
|
this.minPixelY = minPixelY;
|
||||||
|
this.maxPixelX = maxPixelX;
|
||||||
|
this.maxPixelY = maxPixelY;
|
||||||
|
data[IDX_AX0] = ax0;
|
||||||
|
data[IDX_AY0] = ay0;
|
||||||
|
data[IDX_AX1] = ax1;
|
||||||
|
data[IDX_AY1] = ay1;
|
||||||
|
data[IDX_BX0] = bx0;
|
||||||
|
data[IDX_BY0] = by0;
|
||||||
|
data[IDX_BX1] = bx1;
|
||||||
|
data[IDX_BY1] = by1;
|
||||||
|
data[IDX_CX0] = cx0;
|
||||||
|
data[IDX_CY0] = cy0;
|
||||||
|
data[IDX_CX1] = cx1;
|
||||||
|
data[IDX_CY1] = cy1;
|
||||||
|
data[IDX_DX0] = dx0;
|
||||||
|
data[IDX_DY0] = dy0;
|
||||||
|
data[IDX_DX1] = dx1;
|
||||||
|
data[IDX_DY1] = dy1;
|
||||||
|
pos0 = position0;
|
||||||
|
pos1 = position1;
|
||||||
|
pos2 = position2;
|
||||||
|
pos3 = position3;
|
||||||
|
|
||||||
|
final int eventKey = (position0 - 1) & EVENT_POSITION_MASK
|
||||||
|
| (((position1 - 1) & EVENT_POSITION_MASK) << 2)
|
||||||
|
| (((position2 - 1) & EVENT_POSITION_MASK) << 4)
|
||||||
|
| (((position3 - 1) & EVENT_POSITION_MASK) << 6);
|
||||||
|
|
||||||
|
prepareEvents(eventKey);
|
||||||
|
return BOUNDS_IN;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int prepareBounds0011(int v0, int v1, int ext2, int ext3) {
|
||||||
|
final int[] data = vertexData;
|
||||||
|
int ax0, ay0, ax1, ay1;
|
||||||
|
int bx0, by0, bx1, by1;
|
||||||
|
int cx0, cy0, cx1, cy1;
|
||||||
|
int dx0, dy0, dx1, dy1;
|
||||||
|
|
||||||
|
int minY = 0, maxY = 0, minX = 0, maxX = 0;
|
||||||
|
|
||||||
|
ax0 = data[v0 + PV_PX];
|
||||||
|
ay0 = data[v0 + PV_PY];
|
||||||
|
ax1 = data[v1 + PV_PX];
|
||||||
|
ay1 = data[v1 + PV_PY];
|
||||||
|
|
||||||
|
bx0 = ax1;
|
||||||
|
by0 = ay1;
|
||||||
|
clipNear(v1, ext2);
|
||||||
|
bx1 = clipX;
|
||||||
|
by1 = clipY;
|
||||||
|
|
||||||
|
// force line c to be a single, existing point - entire line is clipped and should not influence anything
|
||||||
|
cx0 = ax0;
|
||||||
|
cy0 = ay0;
|
||||||
|
cx1 = ax0;
|
||||||
|
cy1 = ay0;
|
||||||
|
|
||||||
|
clipNear(v0, ext3);
|
||||||
|
dx0 = clipX;
|
||||||
|
dy0 = clipY;
|
||||||
|
dx1 = ax0;
|
||||||
|
dy1 = ay0;
|
||||||
|
|
||||||
|
minX = ax0;
|
||||||
|
maxX = ax0;
|
||||||
|
|
||||||
|
if (bx0 < minX) {
|
||||||
|
minX = bx0;
|
||||||
|
} else if (bx0 > maxX) {
|
||||||
|
maxX = bx0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bx1 < minX) {
|
||||||
|
minX = bx1;
|
||||||
|
} else if (bx1 > maxX) {
|
||||||
|
maxX = bx1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dx0 < minX) {
|
||||||
|
minX = dx0;
|
||||||
|
} else if (dx0 > maxX) {
|
||||||
|
maxX = dx0;
|
||||||
|
}
|
||||||
|
|
||||||
|
minY = ay0;
|
||||||
|
maxY = ay0;
|
||||||
|
|
||||||
|
if (by0 < minY) {
|
||||||
|
minY = by0;
|
||||||
|
} else if (by0 > maxY) {
|
||||||
|
maxY = by0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (by1 < minY) {
|
||||||
|
minY = by1;
|
||||||
|
} else if (by1 > maxY) {
|
||||||
|
maxY = by1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dy0 < minY) {
|
||||||
|
minY = dy0;
|
||||||
|
} else if (dy0 > maxY) {
|
||||||
|
maxY = dy0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxY <= 0 || minY >= PRECISE_HEIGHT) {
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxX <= 0 || minX >= PRECISE_WIDTH) {
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minX < 0) {
|
||||||
|
minX = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxX >= PRECISE_WIDTH_CLAMP) {
|
||||||
|
maxX = PRECISE_WIDTH_CLAMP;
|
||||||
|
|
||||||
|
if (minX > PRECISE_WIDTH_CLAMP) {
|
||||||
|
minX = PRECISE_WIDTH_CLAMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minY < 0) {
|
||||||
|
minY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxY >= PRECISE_HEIGHT_CLAMP) {
|
||||||
|
maxY = PRECISE_HEIGHT_CLAMP;
|
||||||
|
|
||||||
|
if (minY > PRECISE_HEIGHT_CLAMP) {
|
||||||
|
minY = PRECISE_HEIGHT_CLAMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final int minPixelX = ((minX + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int minPixelY = ((minY + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int maxPixelX = ((maxX + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int maxPixelY = ((maxY + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
|
||||||
|
final int position0 = edgePosition(ax0, ay0, ax1, ay1);
|
||||||
|
final int position1 = edgePosition(bx0, by0, bx1, by1);
|
||||||
|
final int position2 = edgePosition(cx0, cy0, cx1, cy1);
|
||||||
|
final int position3 = edgePosition(dx0, dy0, dx1, dy1);
|
||||||
|
|
||||||
|
this.minPixelX = minPixelX;
|
||||||
|
this.minPixelY = minPixelY;
|
||||||
|
this.maxPixelX = maxPixelX;
|
||||||
|
this.maxPixelY = maxPixelY;
|
||||||
|
data[IDX_AX0] = ax0;
|
||||||
|
data[IDX_AY0] = ay0;
|
||||||
|
data[IDX_AX1] = ax1;
|
||||||
|
data[IDX_AY1] = ay1;
|
||||||
|
data[IDX_BX0] = bx0;
|
||||||
|
data[IDX_BY0] = by0;
|
||||||
|
data[IDX_BX1] = bx1;
|
||||||
|
data[IDX_BY1] = by1;
|
||||||
|
data[IDX_CX0] = cx0;
|
||||||
|
data[IDX_CY0] = cy0;
|
||||||
|
data[IDX_CX1] = cx1;
|
||||||
|
data[IDX_CY1] = cy1;
|
||||||
|
data[IDX_DX0] = dx0;
|
||||||
|
data[IDX_DY0] = dy0;
|
||||||
|
data[IDX_DX1] = dx1;
|
||||||
|
data[IDX_DY1] = dy1;
|
||||||
|
pos0 = position0;
|
||||||
|
pos1 = position1;
|
||||||
|
pos2 = position2;
|
||||||
|
pos3 = position3;
|
||||||
|
|
||||||
|
final int eventKey = (position0 - 1) & EVENT_POSITION_MASK
|
||||||
|
| (((position1 - 1) & EVENT_POSITION_MASK) << 2)
|
||||||
|
| (((position2 - 1) & EVENT_POSITION_MASK) << 4)
|
||||||
|
| (((position3 - 1) & EVENT_POSITION_MASK) << 6);
|
||||||
|
|
||||||
|
prepareEvents(eventKey);
|
||||||
|
return BOUNDS_IN;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int prepareBounds0111(int v0, int ext1, int ext2, int ext3) {
|
||||||
|
final int[] data = vertexData;
|
||||||
|
int ax0, ay0, ax1, ay1;
|
||||||
|
int bx0, by0, bx1, by1;
|
||||||
|
int cx0, cy0, cx1, cy1;
|
||||||
|
int dx0, dy0, dx1, dy1;
|
||||||
|
int minY = 0, maxY = 0, minX = 0, maxX = 0;
|
||||||
|
|
||||||
|
ax0 = data[v0 + PV_PX];
|
||||||
|
ay0 = data[v0 + PV_PY];
|
||||||
|
clipNear(v0, ext1);
|
||||||
|
ax1 = clipX;
|
||||||
|
ay1 = clipY;
|
||||||
|
|
||||||
|
// force lines b & c to be a single, existing point - entire line is clipped and should not influence anything
|
||||||
|
bx0 = ax0;
|
||||||
|
by0 = ay0;
|
||||||
|
bx1 = ax0;
|
||||||
|
by1 = ay0;
|
||||||
|
cx0 = ax0;
|
||||||
|
cy0 = ay0;
|
||||||
|
cx1 = ax0;
|
||||||
|
cy1 = ay0;
|
||||||
|
|
||||||
|
clipNear(v0, ext3);
|
||||||
|
dx0 = clipX;
|
||||||
|
dy0 = clipY;
|
||||||
|
dx1 = ax0;
|
||||||
|
dy1 = ay0;
|
||||||
|
|
||||||
|
minX = ax0;
|
||||||
|
maxX = ax0;
|
||||||
|
|
||||||
|
if (ax1 < minX) {
|
||||||
|
minX = ax1;
|
||||||
|
} else if (ax1 > maxX) {
|
||||||
|
maxX = ax1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dx0 < minX) {
|
||||||
|
minX = dx0;
|
||||||
|
} else if (dx0 > maxX) {
|
||||||
|
maxX = dx0;
|
||||||
|
}
|
||||||
|
|
||||||
|
minY = ay0;
|
||||||
|
maxY = ay0;
|
||||||
|
|
||||||
|
if (ay1 < minY) {
|
||||||
|
minY = ay1;
|
||||||
|
} else if (ay1 > maxY) {
|
||||||
|
maxY = ay1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dy0 < minY) {
|
||||||
|
minY = dy0;
|
||||||
|
} else if (dy0 > maxY) {
|
||||||
|
maxY = dy0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxY <= 0 || minY >= PRECISE_HEIGHT) {
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxX <= 0 || minX >= PRECISE_WIDTH) {
|
||||||
|
return BOUNDS_OUTSIDE_OR_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minX < 0) {
|
||||||
|
minX = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxX >= PRECISE_WIDTH_CLAMP) {
|
||||||
|
maxX = PRECISE_WIDTH_CLAMP;
|
||||||
|
|
||||||
|
if (minX > PRECISE_WIDTH_CLAMP) {
|
||||||
|
minX = PRECISE_WIDTH_CLAMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minY < 0) {
|
||||||
|
minY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxY >= PRECISE_HEIGHT_CLAMP) {
|
||||||
|
maxY = PRECISE_HEIGHT_CLAMP;
|
||||||
|
|
||||||
|
if (minY > PRECISE_HEIGHT_CLAMP) {
|
||||||
|
minY = PRECISE_HEIGHT_CLAMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final int minPixelX = ((minX + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int minPixelY = ((minY + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int maxPixelX = ((maxX + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
final int maxPixelY = ((maxY + SCANT_PRECISE_PIXEL_CENTER) >> PRECISION_BITS);
|
||||||
|
|
||||||
|
final int position0 = edgePosition(ax0, ay0, ax1, ay1);
|
||||||
|
final int position1 = edgePosition(bx0, by0, bx1, by1);
|
||||||
|
final int position2 = edgePosition(cx0, cy0, cx1, cy1);
|
||||||
|
final int position3 = edgePosition(dx0, dy0, dx1, dy1);
|
||||||
|
|
||||||
|
this.minPixelX = minPixelX;
|
||||||
|
this.minPixelY = minPixelY;
|
||||||
|
this.maxPixelX = maxPixelX;
|
||||||
|
this.maxPixelY = maxPixelY;
|
||||||
|
data[IDX_AX0] = ax0;
|
||||||
|
data[IDX_AY0] = ay0;
|
||||||
|
data[IDX_AX1] = ax1;
|
||||||
|
data[IDX_AY1] = ay1;
|
||||||
|
data[IDX_BX0] = bx0;
|
||||||
|
data[IDX_BY0] = by0;
|
||||||
|
data[IDX_BX1] = bx1;
|
||||||
|
data[IDX_BY1] = by1;
|
||||||
|
data[IDX_CX0] = cx0;
|
||||||
|
data[IDX_CY0] = cy0;
|
||||||
|
data[IDX_CX1] = cx1;
|
||||||
|
data[IDX_CY1] = cy1;
|
||||||
|
data[IDX_DX0] = dx0;
|
||||||
|
data[IDX_DY0] = dy0;
|
||||||
|
data[IDX_DX1] = dx1;
|
||||||
|
data[IDX_DY1] = dy1;
|
||||||
|
pos0 = position0;
|
||||||
|
pos1 = position1;
|
||||||
|
pos2 = position2;
|
||||||
|
pos3 = position3;
|
||||||
|
|
||||||
|
final int eventKey = (position0 - 1) & EVENT_POSITION_MASK
|
||||||
|
| (((position1 - 1) & EVENT_POSITION_MASK) << 2)
|
||||||
|
| (((position2 - 1) & EVENT_POSITION_MASK) << 4)
|
||||||
|
| (((position3 - 1) & EVENT_POSITION_MASK) << 6);
|
||||||
|
|
||||||
|
prepareEvents(eventKey);
|
||||||
|
return BOUNDS_IN;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019, 2020 grondag
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package grondag.bitraster;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
static void printMask(long mask) {
|
||||||
|
String s = "0000000000000000000000000000000000000000000000000000000000000000" + Long.toBinaryString(mask);
|
||||||
|
s = s.substring(s.length() - 64);
|
||||||
|
printSpaced(s.substring(0, 8));
|
||||||
|
printSpaced(s.substring(8, 16));
|
||||||
|
printSpaced(s.substring(16, 24));
|
||||||
|
printSpaced(s.substring(24, 32));
|
||||||
|
printSpaced(s.substring(32, 40));
|
||||||
|
printSpaced(s.substring(40, 48));
|
||||||
|
printSpaced(s.substring(48, 56));
|
||||||
|
printSpaced(s.substring(56, 64));
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void printSpaced(String s) {
|
||||||
|
System.out.println(s.replace("0", "- ").replace("1", "X "));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user