mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-10 11:51:52 +00:00
TINYGL: Fix line color
As in ztriangle, vertex color must be shifted from internal 16-bits fixed-point format to 8-bits colors. To do so, define values similar to the ones describing for ST fixed-point format. Also, use these in tglClear instead of hard-coded multiplicands, as is done in tglColor4f and gl_transform_to_viewport. Also, make tglClear take into account requested clear depth.
This commit is contained in:
parent
1d3d581870
commit
054a2bd920
@ -41,12 +41,10 @@ void glopClearDepth(GLContext *c, GLParam *p) {
|
||||
|
||||
void glopClear(GLContext *c, GLParam *p) {
|
||||
int mask = p[1].i;
|
||||
int z = 0;
|
||||
int r = (int)(c->clear_color.X * 65535);
|
||||
int g = (int)(c->clear_color.Y * 65535);
|
||||
int b = (int)(c->clear_color.Z * 65535);
|
||||
|
||||
// TODO : correct value of Z
|
||||
int z = (int)(c->clear_depth * ((2 << ZB_Z_BITS) - 1));
|
||||
int r = (int)(c->clear_color.X * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN) + ZB_POINT_RED_MIN);
|
||||
int g = (int)(c->clear_color.Y * (ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN) + ZB_POINT_GREEN_MIN);
|
||||
int b = (int)(c->clear_color.Z * (ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN) + ZB_POINT_BLUE_MIN);
|
||||
|
||||
tglIssueDrawCall(new Graphics::ClearBufferDrawCall(mask & TGL_DEPTH_BUFFER_BIT, z, mask & TGL_COLOR_BUFFER_BIT, r, g, b));
|
||||
}
|
||||
|
@ -46,14 +46,29 @@ namespace TinyGL {
|
||||
#define ZB_POINT_ST_MIN ( (1 << ZB_POINT_ST_FRAC_SHIFT) )
|
||||
#define ZB_POINT_ST_MAX ( (c->_textureSize << ZB_POINT_ST_FRAC_BITS) - (1 << ZB_POINT_ST_FRAC_SHIFT) )
|
||||
|
||||
#define ZB_POINT_RED_MIN ( (1 << 10) )
|
||||
#define ZB_POINT_RED_MAX ( (1 << 16) - (1 << 10) )
|
||||
#define ZB_POINT_GREEN_MIN ( (1 << 9) )
|
||||
#define ZB_POINT_GREEN_MAX ( (1 << 16) - (1 << 9) )
|
||||
#define ZB_POINT_BLUE_MIN ( (1 << 10) )
|
||||
#define ZB_POINT_BLUE_MAX ( (1 << 16) - (1 << 10) )
|
||||
#define ZB_POINT_ALPHA_MIN ( (1 << 10) )
|
||||
#define ZB_POINT_ALPHA_MAX ( (1 << 16) - (1 << 10) )
|
||||
#define ZB_POINT_RED_BITS 16
|
||||
#define ZB_POINT_RED_FRAC_BITS 11
|
||||
#define ZB_POINT_RED_FRAC_SHIFT (ZB_POINT_RED_FRAC_BITS - 1)
|
||||
#define ZB_POINT_RED_MIN ( (1 << ZB_POINT_RED_FRAC_SHIFT) )
|
||||
#define ZB_POINT_RED_MAX ( (1 << ZB_POINT_RED_BITS) - (1 << ZB_POINT_RED_FRAC_SHIFT) )
|
||||
|
||||
#define ZB_POINT_GREEN_BITS 16
|
||||
#define ZB_POINT_GREEN_FRAC_BITS 10
|
||||
#define ZB_POINT_GREEN_FRAC_SHIFT (ZB_POINT_GREEN_FRAC_BITS - 1)
|
||||
#define ZB_POINT_GREEN_MIN ( (1 << ZB_POINT_GREEN_FRAC_SHIFT) )
|
||||
#define ZB_POINT_GREEN_MAX ( (1 << ZB_POINT_GREEN_BITS) - (1 << ZB_POINT_GREEN_FRAC_SHIFT) )
|
||||
|
||||
#define ZB_POINT_BLUE_BITS 16
|
||||
#define ZB_POINT_BLUE_FRAC_BITS 11
|
||||
#define ZB_POINT_BLUE_FRAC_SHIFT (ZB_POINT_BLUE_FRAC_BITS - 1)
|
||||
#define ZB_POINT_BLUE_MIN ( (1 << ZB_POINT_BLUE_FRAC_SHIFT) )
|
||||
#define ZB_POINT_BLUE_MAX ( (1 << ZB_POINT_BLUE_BITS) - (1 << ZB_POINT_BLUE_FRAC_SHIFT) )
|
||||
|
||||
#define ZB_POINT_ALPHA_BITS 16
|
||||
#define ZB_POINT_ALPHA_FRAC_BITS 11
|
||||
#define ZB_POINT_ALPHA_FRAC_SHIFT (ZB_POINT_ALPHA_FRAC_BITS - 1)
|
||||
#define ZB_POINT_ALPHA_MIN ( (1 << ZB_POINT_ALPHA_FRAC_SHIFT) )
|
||||
#define ZB_POINT_ALPHA_MAX ( (1 << ZB_POINT_ALPHA_BITS) - (1 << ZB_POINT_ALPHA_FRAC_SHIFT) )
|
||||
|
||||
#define RGB_TO_PIXEL(r, g, b) cmode.ARGBToColor(255, r >> 8, g >> 8, b >> 8) // Default to 255 alpha aka solid colour.
|
||||
|
||||
|
@ -99,9 +99,9 @@ void FrameBuffer::drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2) {
|
||||
int sz;
|
||||
|
||||
// kInterpRGB
|
||||
int r = p1->r;
|
||||
int g = p1->g;
|
||||
int b = p1->b;
|
||||
int r = p1->r >> (ZB_POINT_RED_BITS - 8);
|
||||
int g = p1->g >> (ZB_POINT_GREEN_BITS - 8);
|
||||
int b = p1->b >> (ZB_POINT_BLUE_BITS - 8);
|
||||
int color = RGB_TO_PIXEL(r, g, b);
|
||||
int sr, sg, sb;
|
||||
|
||||
@ -110,9 +110,9 @@ void FrameBuffer::drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2) {
|
||||
z = p1->z;
|
||||
}
|
||||
if (kInterpRGB) {
|
||||
sr = (p2->r - p1->r) / n;
|
||||
sg = (p2->g - p1->g) / n;
|
||||
sb = (p2->b - p1->b) / n;
|
||||
sr = ((p2->r - p1->r) / n) >> (ZB_POINT_RED_BITS - 8);
|
||||
sg = ((p2->g - p1->g) / n) >> (ZB_POINT_GREEN_BITS - 8);
|
||||
sb = ((p2->b - p1->b) / n) >> (ZB_POINT_BLUE_BITS - 8);
|
||||
}
|
||||
while (n--) {
|
||||
if (kInterpZ)
|
||||
|
@ -38,7 +38,7 @@ template <bool kDepthWrite, bool kEnableAlphaTest, bool kEnableScissor, bool kEn
|
||||
FORCEINLINE static void putPixelFlat(FrameBuffer *buffer, int buf, unsigned int *pz, int _a,
|
||||
int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a, int &dzdx) {
|
||||
if ((!kEnableScissor || !buffer->scissorPixel(x + _a, y)) && buffer->compareDepth(z, pz[_a])) {
|
||||
buffer->writePixel<kEnableAlphaTest, kEnableBlending, kDepthWrite>(buf + _a, a / 256, r / 256, g / 256, b / 256, z);
|
||||
buffer->writePixel<kEnableAlphaTest, kEnableBlending, kDepthWrite>(buf + _a, a >> (ZB_POINT_ALPHA_BITS - 8), r >> (ZB_POINT_RED_BITS - 8), g >> (ZB_POINT_GREEN_BITS - 8), b >> (ZB_POINT_BLUE_BITS - 8), z);
|
||||
}
|
||||
z += dzdx;
|
||||
}
|
||||
@ -48,7 +48,7 @@ FORCEINLINE static void putPixelSmooth(FrameBuffer *buffer, int buf, unsigned in
|
||||
int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, unsigned int &a,
|
||||
int &dzdx, int &drdx, int &dgdx, int &dbdx, unsigned int dadx) {
|
||||
if ((!kEnableScissor || !buffer->scissorPixel(x + _a, y)) && buffer->compareDepth(z, pz[_a])) {
|
||||
buffer->writePixel<kEnableAlphaTest, kEnableBlending, kDepthWrite>(buf + _a, a / 256, r / 256, g / 256, b / 256, z);
|
||||
buffer->writePixel<kEnableAlphaTest, kEnableBlending, kDepthWrite>(buf + _a, a >> (ZB_POINT_ALPHA_BITS - 8), r >> (ZB_POINT_RED_BITS - 8), g >> (ZB_POINT_GREEN_BITS - 8), b >> (ZB_POINT_BLUE_BITS - 8), z);
|
||||
}
|
||||
z += dzdx;
|
||||
a += dadx;
|
||||
@ -70,7 +70,7 @@ FORCEINLINE static void putPixelDepth(FrameBuffer *buffer, int buf, unsigned int
|
||||
template <bool kDepthWrite, bool kAlphaTestEnabled, bool kEnableScissor, bool kBlendingEnabled>
|
||||
FORCEINLINE static void putPixelShadow(FrameBuffer *buffer, int buf, unsigned int *pz, int _a, int x, int y, unsigned int &z, unsigned int &r, unsigned int &g, unsigned int &b, int &dzdx, unsigned char *pm) {
|
||||
if ((!kEnableScissor || !buffer->scissorPixel(x + _a, y)) && buffer->compareDepth(z, pz[_a]) && pm[_a]) {
|
||||
buffer->writePixel<kAlphaTestEnabled, kBlendingEnabled, kDepthWrite>(buf + _a, 255, r / 256, g / 256, b / 256, z);
|
||||
buffer->writePixel<kAlphaTestEnabled, kBlendingEnabled, kDepthWrite>(buf + _a, 255, r >> (ZB_POINT_RED_BITS - 8), g >> (ZB_POINT_GREEN_BITS - 8), b >> (ZB_POINT_BLUE_BITS - 8), z);
|
||||
}
|
||||
z += dzdx;
|
||||
}
|
||||
@ -92,14 +92,14 @@ FORCEINLINE static void putPixelTextureMappingPerspective(FrameBuffer *buffer, i
|
||||
c_g = (col >> textureFormat.gShift) & 0xFF;
|
||||
c_b = (col >> textureFormat.bShift) & 0xFF;
|
||||
if (kLightsMode) {
|
||||
unsigned int l_a = (a / 256);
|
||||
unsigned int l_r = (r / 256);
|
||||
unsigned int l_g = (g / 256);
|
||||
unsigned int l_b = (b / 256);
|
||||
c_a = (c_a * l_a) / 256;
|
||||
c_r = (c_r * l_r) / 256;
|
||||
c_g = (c_g * l_g) / 256;
|
||||
c_b = (c_b * l_b) / 256;
|
||||
unsigned int l_a = (a >> (ZB_POINT_ALPHA_BITS - 8));
|
||||
unsigned int l_r = (r >> (ZB_POINT_RED_BITS - 8));
|
||||
unsigned int l_g = (g >> (ZB_POINT_GREEN_BITS - 8));
|
||||
unsigned int l_b = (b >> (ZB_POINT_BLUE_BITS - 8));
|
||||
c_a = (c_a * l_a) >> (ZB_POINT_ALPHA_BITS - 8);
|
||||
c_r = (c_r * l_r) >> (ZB_POINT_RED_BITS - 8);
|
||||
c_g = (c_g * l_g) >> (ZB_POINT_GREEN_BITS - 8);
|
||||
c_b = (c_b * l_b) >> (ZB_POINT_BLUE_BITS - 8);
|
||||
}
|
||||
buffer->writePixel<kEnableAlphaTest, kEnableBlending, kDepthWrite>(buf + _a, c_a, c_r, c_g, c_b, z);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user