[Scummvm-git-logs] scummvm master -> eab1fe4097d028c89a9eba66e9d2130540874532
aquadran
aquadran at gmail.com
Tue Oct 26 19:59:09 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
eab1fe4097 TINYGL: Implemented tglPolygonOffset function
Commit: eab1fe4097d028c89a9eba66e9d2130540874532
https://github.com/scummvm/scummvm/commit/eab1fe4097d028c89a9eba66e9d2130540874532
Author: PaweÅ KoÅodziejski (aquadran at gmail.com)
Date: 2021-10-26T21:59:04+02:00
Commit Message:
TINYGL: Implemented tglPolygonOffset function
Changed paths:
graphics/tinygl/init.cpp
graphics/tinygl/zbuffer.cpp
graphics/tinygl/zbuffer.h
graphics/tinygl/zdirtyrect.cpp
graphics/tinygl/zdirtyrect.h
graphics/tinygl/zline.cpp
graphics/tinygl/ztriangle.cpp
diff --git a/graphics/tinygl/init.cpp b/graphics/tinygl/init.cpp
index 0aff6d17d1..e391840c9e 100644
--- a/graphics/tinygl/init.cpp
+++ b/graphics/tinygl/init.cpp
@@ -211,6 +211,8 @@ void glInit(void *zbuffer1, int textureSize) {
// opengl 1.1 polygon offset
c->offset_states = 0;
+ c->offset_factor = 0.0f;
+ c->offset_units = 0.0f;
// shadow mode
c->shadow_mode = 0;
diff --git a/graphics/tinygl/zbuffer.cpp b/graphics/tinygl/zbuffer.cpp
index b925eaafc1..873461d9e3 100644
--- a/graphics/tinygl/zbuffer.cpp
+++ b/graphics/tinygl/zbuffer.cpp
@@ -104,6 +104,9 @@ FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelBuffer &fra
_alphaTestEnabled = false;
_depthTestEnabled = false;
_depthFunc = TGL_LESS;
+ _offsetStates = 0;
+ _offsetFactor = 0.0f;
+ _offsetUnits = 0.0f;
}
FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelFormat &format) : _depthWrite(true), _enableScissor(false) {
@@ -131,6 +134,9 @@ FrameBuffer::FrameBuffer(int width, int height, const Graphics::PixelFormat &for
_alphaTestEnabled = false;
_depthTestEnabled = false;
_depthFunc = TGL_LESS;
+ _offsetStates = 0;
+ _offsetFactor = 0.0f;
+ _offsetUnits = 0.0f;
}
FrameBuffer::~FrameBuffer() {
diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h
index 4b68674ebb..2340b3bfe3 100644
--- a/graphics/tinygl/zbuffer.h
+++ b/graphics/tinygl/zbuffer.h
@@ -391,6 +391,18 @@ struct FrameBuffer {
_depthTestEnabled = enable;
}
+ void setOffsetStates(int offsetStates) {
+ _offsetStates = offsetStates;
+ }
+
+ void setOffsetFactor(float offsetFactor) {
+ _offsetFactor = offsetFactor;
+ }
+
+ void setOffsetUnits(float offsetUnits) {
+ _offsetUnits = offsetUnits;
+ }
+
void setBlendingFactors(int sFactor, int dFactor) {
_sourceBlendingFactor = sFactor;
_destinationBlendingFactor = dFactor;
@@ -497,6 +509,9 @@ struct FrameBuffer {
FORCEINLINE int getAlphaTestFunc() const { return _alphaTestFunc; }
FORCEINLINE int getAlphaTestRefVal() const { return _alphaTestRefVal; }
FORCEINLINE int getDepthTestEnabled() const { return _depthTestEnabled; }
+ FORCEINLINE int getOffsetStates() const { return _offsetStates; }
+ FORCEINLINE float getOffsetFactor() const { return _offsetFactor; }
+ FORCEINLINE float getOffsetUnits() const { return _offsetUnits; }
private:
@@ -526,6 +541,9 @@ private:
int _alphaTestFunc;
int _alphaTestRefVal;
int _depthFunc;
+ int _offsetStates;
+ float _offsetFactor;
+ float _offsetUnits;
};
// memory.c
diff --git a/graphics/tinygl/zdirtyrect.cpp b/graphics/tinygl/zdirtyrect.cpp
index 28a6fd45dc..df168e61b4 100644
--- a/graphics/tinygl/zdirtyrect.cpp
+++ b/graphics/tinygl/zdirtyrect.cpp
@@ -448,6 +448,9 @@ RasterizationDrawCall::RasterizationState RasterizationDrawCall::captureState()
state.currentFrontFace = c->current_front_face;
state.currentShadeModel = c->current_shade_model;
state.depthTest = c->depth_test;
+ state.offsetStates = c->offset_states;
+ state.offsetFactor = c->offset_factor;
+ state.offsetUnits = c->offset_units;
state.polygonModeBack = c->polygon_mode_back;
state.polygonModeFront = c->polygon_mode_front;
state.shadowMode = c->shadow_mode;
@@ -478,6 +481,9 @@ void RasterizationDrawCall::applyState(const RasterizationDrawCall::Rasterizatio
c->fb->setDepthFunc(state.depthFunction);
c->fb->enableDepthWrite(state.depthWrite);
c->fb->enableDepthTest(state.depthTestEnabled);
+ c->fb->setOffsetStates(state.offsetStates);
+ c->fb->setOffsetFactor(state.offsetFactor);
+ c->fb->setOffsetUnits(state.offsetUnits);
c->lighting_enabled = state.lightingEnabled;
c->cull_face_enabled = state.cullFaceEnabled;
@@ -662,6 +668,9 @@ bool RasterizationDrawCall::RasterizationState::operator==(const RasterizationSt
cullFaceEnabled == other.cullFaceEnabled &&
colorMask == other.colorMask &&
depthTest == other.depthTest &&
+ offsetStates == other.offsetStates &&
+ offsetFactor == other.offsetFactor &&
+ offsetUnits == other.offsetUnits &&
depthFunction == other.depthFunction &&
depthWrite == other.depthWrite &&
shadowMode == other.shadowMode &&
diff --git a/graphics/tinygl/zdirtyrect.h b/graphics/tinygl/zdirtyrect.h
index c511dd16df..66ee18f243 100644
--- a/graphics/tinygl/zdirtyrect.h
+++ b/graphics/tinygl/zdirtyrect.h
@@ -127,6 +127,9 @@ private:
int sfactor, dfactor;
int textureVersion;
int depthTestEnabled;
+ int offsetStates;
+ float offsetFactor;
+ float offsetUnits;
float viewportTranslation[3];
float viewportScaling[3];
bool alphaTest;
diff --git a/graphics/tinygl/zline.cpp b/graphics/tinygl/zline.cpp
index a493db1c22..23dbdcac95 100644
--- a/graphics/tinygl/zline.cpp
+++ b/graphics/tinygl/zline.cpp
@@ -105,7 +105,7 @@ void FrameBuffer::drawLine(const ZBufferPoint *p1, const ZBufferPoint *p2) {
int color = RGB_TO_PIXEL(r, g, b);
int sr, sg, sb;
- if (kInterpZ) {
+ if (kInterpZ) {
sz = (p2->z - p1->z) / n;
z = p1->z;
}
diff --git a/graphics/tinygl/ztriangle.cpp b/graphics/tinygl/ztriangle.cpp
index 1d86eabd7a..e2699fd5bb 100644
--- a/graphics/tinygl/ztriangle.cpp
+++ b/graphics/tinygl/ztriangle.cpp
@@ -231,6 +231,12 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
dtzdy = (fdx1 * d2 - fdx2 * d1);
}
+ int polyOffset = 0;
+ if (kInterpZ && (_offsetStates & TGL_OFFSET_FILL) && (kDrawLogic == DRAW_FLAT || kDrawLogic == DRAW_SMOOTH)) {
+ int m = MAX(ABS(dzdx), ABS(dzdy));
+ polyOffset = -m * _offsetFactor + -_offsetUnits * (1 << 6);
+ }
+
// screen coordinates
int pp1 = xsize * p0->y;
@@ -312,7 +318,7 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
dxdy_max = dxdy_min + 1;
if (kInterpZ) {
- z1 = l1->z;
+ z1 = l1->z + polyOffset;
dzdl_min = (dzdy + dzdx * dxdy_min);
dzdl_max = dzdl_min + dzdx;
}
More information about the Scummvm-git-logs
mailing list