summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 203d892)
raw | patch | inline | side by side (parent: 203d892)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 28 Dec 2022 21:00:45 +0000 (00:00 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 9 Jun 2023 09:08:30 +0000 (12:08 +0300) |
src/game/renders/opengl/r_draw.pas | patch | blob | history | |
src/game/renders/opengl/r_map.pas | patch | blob | history | |
src/game/renders/opengl/r_textures.pas | patch | blob | history |
index 67bd23041275b237de894398f5960198e4691c30..940b6728d2cc9827204912fcff593d848a6b0afd 100644 (file)
procedure r_Draw_SetRect (l, t, r, b: Integer);
procedure r_Draw_GetRect (out l, t, r, b: Integer);
+ procedure r_Draw_EnableTexture2D (enable: Boolean);
+
implementation
uses
sl, st, sr, sb: Integer;
ScreenWidth, ScreenHeight: Integer;
+ enableTexture2D: Boolean;
+ curR, curG, curB, curA: Byte;
+
+ procedure r_Draw_EnableTexture2D (enable: Boolean);
+ begin
+ if enable <> enableTexture2D then
+ begin
+ if enable then glEnable(GL_TEXTURE_2D) else glDisable(GL_TEXTURE_2D);
+ enableTexture2D := enable;
+ end;
+ end;
+
+ procedure r_Draw_SetColor (r, g, b, a: Byte);
+ begin
+ if (r <> curR) or (g <> curG) or (b <> curB) or (curA <> a) then
+ begin
+ glColor4ub(r, g, b, a);
+ curR := r;
+ curG := g;
+ curB := b;
+ curA := a;
+ end;
+ end;
+
procedure r_Draw_Setup (w, h: Integer);
begin
ASSERT(w >= 0);
begin
if tile = nil then
begin
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_SetColor(rr, gg, bb, aa);
if blend then glBlendFunc(GL_SRC_ALPHA, GL_ONE) else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_TEXTURE_2D);
+ r_Draw_EnableTexture2D(false);
glEnable(GL_BLEND);
DrawQuad(x, y, w, h);
end
ay := (tile.t) / nw;
by := (tile.b + 1) / nh;
l := x; t := y; r := x + w; b := y + h;
- glBindTexture(GL_TEXTURE_2D, tile.id);
- glColor4ub(rr, gg, bb, aa);
+ r_Textures_GL_Bind(tile.id);
+ r_Draw_SetColor(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(true);
if blend then glBlendFunc(GL_SRC_ALPHA, GL_ONE) else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBegin(GL_QUADS);
glTexCoord2f(ax, ay); glVertex2i(r, t);
glTexCoord2f(bx, by); glVertex2i(l, b);
glTexCoord2f(ax, by); glVertex2i(r, b);
glEnd();
- glDisable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, 0);
end
end;
ay := 0 / nw;
by := h / nh;
l := x; t := y; r := x + w; b := y + h;
- glBindTexture(GL_TEXTURE_2D, gltex);
- glColor4ub(rr, gg, bb, aa);
+ r_Textures_GL_Bind(gltex);
+ r_Draw_SetColor(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(true);
if blend then glBlendFunc(GL_SRC_ALPHA, GL_ONE) else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBegin(GL_QUADS);
glTexCoord2f(ax, ay); glVertex2i(r, t);
glTexCoord2f(bx, by); glVertex2i(l, b);
glTexCoord2f(ax, by); glVertex2i(r, b);
glEnd();
- glDisable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, 0);
end;
procedure r_Draw_Texture (img: TGLTexture; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean);
ASSERT(b >= t);
glEnable(GL_BLEND);
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
- glDisable(GL_TEXTURE_2D);
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(false);
+ r_Draw_SetColor(rr, gg, bb, aa);
glBegin(GL_QUADS);
glVertex2i(l, t);
glVertex2i(r, t);
ASSERT(b >= t);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_TEXTURE_2D);
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(false);
+ r_Draw_SetColor(rr, gg, bb, aa);
glBegin(GL_LINE_LOOP);
{
glVertex2i(l, t);
ASSERT(b >= t);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_TEXTURE_2D);
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(false);
+ r_Draw_SetColor(rr, gg, bb, aa);
glBegin(GL_QUADS);
{
glVertex2i(l, t);
ASSERT(b >= t);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
- glDisable(GL_TEXTURE_2D);
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(false);
+ r_Draw_SetColor(rr, gg, bb, aa);
glBegin(GL_QUADS);
glVertex2i(l, t);
glVertex2i(r, t);
index 028c724541e5cd119949d364bef86ea4848e940d..a1d781c5bf7f502aee87e3691457fa14f9c97657 100644 (file)
begin
if gpart_dbg_enabled and (Particles <> nil) then
begin
- glDisable(GL_TEXTURE_2D);
+ r_Draw_EnableTexture2D(false);
if (g_dbg_scale < 0.6) then
glPointSize(1)
else if (g_dbg_scale > 1.3) then
fx := nlerp(Particles[i].oldX, Particles[i].x, gLerpFactor);
fy := nlerp(Particles[i].oldY, Particles[i].y, gLerpFactor);
glColor4ub(Particles[i].red, Particles[i].green, Particles[i].blue, Particles[i].alpha);
- glVertex2f(fx, fy);
+ glVertex2i(fx, fy);
end;
end;
glEnd;
index 34b5b9e7027c8863ad32a0777d22297047fb5dc2..1025abad5f29d73540ecd541e33b28903fe52efe 100644 (file)
function r_Textures_LoadFontFromFile (const filename: AnsiString; constref f: TFontInfo; font2enc: TConvProc; log: Boolean = true): TGLFont;
+ procedure r_Textures_GL_Bind (id: GLuint);
+
implementation
uses
r_GL_RepeatOpt: Boolean;
maxTileSize: Integer;
atl, ratl: array of TGLAtlas;
+ currentTexture2D: GLuint;
+
+ procedure r_Textures_GL_Bind (id: GLuint);
+ begin
+ if id <> currentTexture2D then
+ begin
+ glBindTexture(GL_TEXTURE_2D, id);
+ currentTexture2D := id;
+ end
+ end;
(* --------- TGLAtlasNode --------- *)
ASSERT(n.l + x + w - 1 <= n.r);
ASSERT(n.t + y + h - 1 <= n.b);
ASSERT(n.id > 0);
- glBindTexture(GL_TEXTURE_2D, n.id);
+ r_Textures_GL_Bind(n.id);
glTexSubImage2D(GL_TEXTURE_2D, 0, n.l + x, n.t + y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data);
- glBindTexture(GL_TEXTURE_2D, 0);
+ r_Textures_GL_Bind(0);
end;
(* --------- TGLAtlas --------- *)
glGenTextures(1, @id);
if id <> 0 then
begin
- glBindTexture(GL_TEXTURE_2D, id);
+ r_Textures_GL_Bind(id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
- glBindTexture(GL_TEXTURE_2D, 0);
+ r_Textures_GL_Bind(0);
end;
result := id
end;
procedure r_Textures_Initialize;
begin
+ currentTexture2D := 0;
maxTileSize := r_Textures_GetMaxHardwareSize();
e_LogWritefln('TEXTURE SIZE: %s', [maxTileSize]);
end;