mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-29 07:22:07 +00:00
- 2D code works in GL legacy mode.
Not tested yet with shaders.
This commit is contained in:
parent
0ff1426b23
commit
077df87704
2 changed files with 33 additions and 41 deletions
|
@ -440,10 +440,15 @@ unsigned char *FGLRenderer::GetTextureBuffer(FTexture *tex, int &w, int &h)
|
|||
//===========================================================================
|
||||
#define TDiO ((F2DDrawer::TwoDVertex*)NULL)
|
||||
|
||||
class F2DVertexBuffer : public FVertexBuffer
|
||||
class F2DVertexBuffer : public FSimpleVertexBuffer
|
||||
{
|
||||
uint32_t ibo_id;
|
||||
|
||||
// Make sure we can build upon FSimpleVertexBuffer.
|
||||
static_assert(&VSiO->x == &TDiO->x, "x not aligned");
|
||||
static_assert(&VSiO->u == &TDiO->u, "y not aligned");
|
||||
static_assert(&VSiO->color == &TDiO->color0, "color not aligned");
|
||||
|
||||
public:
|
||||
|
||||
F2DVertexBuffer()
|
||||
|
@ -464,24 +469,12 @@ public:
|
|||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexcount * sizeof(indices[0]), indices, GL_STREAM_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void BindVBO() override
|
||||
{
|
||||
// set up the vertex buffer for drawing the 2D elements.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||
FSimpleVertexBuffer::BindVBO();
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id);
|
||||
glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(F2DDrawer::TwoDVertex), &TDiO->x);
|
||||
glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(F2DDrawer::TwoDVertex), &TDiO->u);
|
||||
glVertexAttribPointer(VATTR_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(F2DDrawer::TwoDVertex), &TDiO->color0);
|
||||
glEnableVertexAttribArray(VATTR_VERTEX);
|
||||
glEnableVertexAttribArray(VATTR_TEXCOORD);
|
||||
glEnableVertexAttribArray(VATTR_COLOR);
|
||||
glDisableVertexAttribArray(VATTR_VERTEX2);
|
||||
glDisableVertexAttribArray(VATTR_NORMAL);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -517,7 +510,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
|
|||
// already manipulated the data so that some cases will not be handled correctly.
|
||||
// Since we already get a proper mode from the calling code this doesn't really matter.
|
||||
gl_GetRenderStyle(cmd.mRenderStyle, false, false, &tm, &sb, &db, &be);
|
||||
gl_RenderState.BlendEquation(be);
|
||||
gl_RenderState.BlendEquation(be);
|
||||
gl_RenderState.BlendFunc(sb, db);
|
||||
|
||||
// Rather than adding remapping code, let's enforce that the constants here are equal.
|
||||
|
@ -532,11 +525,12 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
|
|||
{
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
// scissor test doesn't use the current viewport for the coordinates, so use real screen coordinates
|
||||
glScissor(
|
||||
GLRenderer->ScreenToWindowX(cmd.mScissor[0]),
|
||||
GLRenderer->ScreenToWindowY(cmd.mScissor[1]),
|
||||
GLRenderer->ScreenToWindowX(cmd.mScissor[2] - cmd.mScissor[0]),
|
||||
GLRenderer->ScreenToWindowY(cmd.mScissor[3] - cmd.mScissor[1]));
|
||||
// Note that the origin here is the lower left corner!
|
||||
auto sciX = ScreenToWindowX(cmd.mScissor[0]);
|
||||
auto sciY = ScreenToWindowY(cmd.mScissor[3]);
|
||||
auto sciW = ScreenToWindowX(cmd.mScissor[2]) - sciX;
|
||||
auto sciH = ScreenToWindowY(cmd.mScissor[1]) - sciY;
|
||||
glScissor(sciX, sciY, sciW, sciH);
|
||||
}
|
||||
else glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
|
@ -574,7 +568,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
|
|||
auto mat = FMaterial::ValidateTexture(cmd.mTexture, false);
|
||||
if (mat == nullptr) continue;
|
||||
int gltrans = GLTranslationPalette::GetInternalTranslation(cmd.mTranslation);
|
||||
gl_RenderState.SetMaterial(mat, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, gltrans, -1, false);
|
||||
gl_RenderState.SetMaterial(mat, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, -gltrans, -1, false);
|
||||
gl_RenderState.EnableTexture(true);
|
||||
}
|
||||
else
|
||||
|
@ -582,8 +576,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
|
|||
gl_RenderState.EnableTexture(false);
|
||||
}
|
||||
gl_RenderState.Apply();
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, cmd.mVertIndex, 4);
|
||||
//glDrawElements(GL_TRIANGLES, cmd.mIndexCount, GL_UNSIGNED_INT, (const void *)(cmd.mIndexIndex * sizeof(unsigned int)));
|
||||
glDrawElements(GL_TRIANGLES, cmd.mIndexCount, GL_UNSIGNED_INT, (const void *)(cmd.mIndexIndex * sizeof(unsigned int)));
|
||||
break;
|
||||
|
||||
case F2DDrawer::DrawTypeLines:
|
||||
|
@ -601,9 +594,11 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
|
|||
}
|
||||
}
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
gl_RenderState.SetVertexBuffer(nullptr);
|
||||
|
||||
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
||||
gl_RenderState.EnableTexture(true);
|
||||
gl_RenderState.SetTextureMode(TM_MODULATE);
|
||||
gl_RenderState.ResetColor();
|
||||
gl_RenderState.Apply();
|
||||
delete vb;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ int F2DDrawer::AddCommand(const RenderCommand *data)
|
|||
{
|
||||
// Merge with the last command.
|
||||
mData.Last().mIndexCount += data->mIndexCount;
|
||||
mData.Last().mVertCount += data->mVertCount;
|
||||
return mData.Size();
|
||||
}
|
||||
else
|
||||
|
@ -223,22 +224,23 @@ bool F2DDrawer::SetStyle(FTexture *tex, DrawParms &parms, PalEntry &vertexcolor,
|
|||
|
||||
void F2DDrawer::SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcolor, PalEntry &overlaycolor)
|
||||
{
|
||||
if (APART(color) != 0)
|
||||
if (color.a != 0 && (color & 0xffffff) != 0)
|
||||
{
|
||||
// overlay color uses premultiplied alpha. The alpha channel is what the main color gets multiplied with in the blending.
|
||||
int a = APART(color) * 256 / 255;
|
||||
// overlay color uses premultiplied alpha.
|
||||
int a = color.a * 256 / 255;
|
||||
overlaycolor.r = (color.r * a) >> 8;
|
||||
overlaycolor.g = (color.g * a) >> 8;
|
||||
overlaycolor.b = (color.b * a) >> 8;
|
||||
overlaycolor.a = 255 - color.a;
|
||||
|
||||
vertexcolor = PalEntry(int(alpha * 255), color.a, color.a, color.a);
|
||||
overlaycolor.a = 0; // The overlay gets added on top of the texture data so to preserve the pixel's alpha this must be 0.
|
||||
}
|
||||
else
|
||||
{
|
||||
overlaycolor = 0;
|
||||
vertexcolor = PalEntry(int(alpha * 255), 255, 255, 255);
|
||||
}
|
||||
// Vertex intensity is the inverse of the overlay so that the shader can do a simple addition to combine them.
|
||||
uint8_t light = 255 - color.a;
|
||||
vertexcolor = PalEntry(int(alpha * 255), light, light, light);
|
||||
|
||||
// The real color gets multiplied into vertexcolor later.
|
||||
}
|
||||
|
||||
|
@ -257,7 +259,6 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms)
|
|||
double w = parms.destwidth;
|
||||
double h = parms.destheight;
|
||||
double u1, v1, u2, v2;
|
||||
int light = 255;
|
||||
PalEntry vertexcolor;
|
||||
|
||||
RenderCommand dg;
|
||||
|
@ -266,13 +267,6 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms)
|
|||
dg.mVertCount = 4;
|
||||
dg.mTexture = img;
|
||||
|
||||
if (parms.colorOverlay && (parms.colorOverlay & 0xffffff) == 0)
|
||||
{
|
||||
// handle black overlays as reduced light.
|
||||
light = 255 - APART(parms.colorOverlay);
|
||||
parms.colorOverlay = 0;
|
||||
}
|
||||
|
||||
dg.mTranslation = 0;
|
||||
SetStyle(img, parms, vertexcolor, dg);
|
||||
|
||||
|
@ -303,7 +297,7 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms)
|
|||
u2 = float(u2 - (parms.texwidth - wi) / parms.texwidth);
|
||||
}
|
||||
|
||||
if (x < (double)parms.lclip || y < (double)parms.uclip || x + w >(double)parms.lclip || y + h >(double)parms.dclip)
|
||||
if (x < (double)parms.lclip || y < (double)parms.uclip || x + w >(double)parms.rclip || y + h >(double)parms.dclip)
|
||||
{
|
||||
dg.mScissor[0] = parms.lclip;
|
||||
dg.mScissor[1] = parms.uclip;
|
||||
|
@ -415,6 +409,7 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FTexture *
|
|||
dg.mTexture = src;
|
||||
dg.mVertCount = 4;
|
||||
dg.mTexture = src;
|
||||
dg.mFlags = DTF_Wrap;
|
||||
|
||||
// scaling is not used here.
|
||||
if (!local_origin)
|
||||
|
@ -484,6 +479,7 @@ void F2DDrawer::AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t c
|
|||
RenderCommand dg;
|
||||
|
||||
dg.mType = DrawTypeLines;
|
||||
dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent];
|
||||
dg.mVertCount = 2;
|
||||
dg.mVertIndex = (int)mVertices.Reserve(2);
|
||||
mVertices[dg.mVertIndex].Set(x1, y1, 0, 0, 0, p);
|
||||
|
@ -505,6 +501,7 @@ void F2DDrawer::AddPixel(int x1, int y1, int palcolor, uint32_t color)
|
|||
RenderCommand dg;
|
||||
|
||||
dg.mType = DrawTypePoints;
|
||||
dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent];
|
||||
dg.mVertCount = 1;
|
||||
dg.mVertIndex = (int)mVertices.Reserve(1);
|
||||
mVertices[dg.mVertIndex].Set(x1, y1, 0, 0, 0, p);
|
||||
|
|
Loading…
Reference in a new issue