Complete BigTask
Sync changed files to Google Drive / sync (push) Successful in 2m2s

This commit is contained in:
admin_d committed 2026-10-08 11:59:40 +05:00
1 parent 9a59f1fe52
commit 6d3b8e6ac5
8 files changed
+4454 -49

No files matched your search

+50 -46
View File
@@ -12,7 +12,12 @@ const
TEX_FORMAT_SIZE: array [TKMTexFormat] of Byte = (2, 4, 1);
type
TKMRenderMode = (rm2D, rm3D);
TKMRenderMode = (rm2D);
TKMSampledVertex = record
X, Y, Z: Single;
U, V: Single;
end;
//General OpenGL handling
TKMRender = class
@@ -34,10 +39,12 @@ type
constructor Create(aScreenX, aScreenY: Integer);
destructor Destroy; override;
procedure SetRenderMode(aRenderMode: TKMRenderMode); //Switch between 2D and 3D perspectives
procedure SetRenderMode(aRenderMode: TKMRenderMode);
class procedure GraphicsContextChanged(aAvailable: Boolean); static;
class function TextureBackendReady: Boolean; static;
class function SampledProgramReady: Boolean; static;
class procedure DrawSampledTriangles(const aVertices: array of TKMSampledVertex; const aColor: TKMColor4f); static;
class function GetMaxTexSize: Cardinal; static;
class function GetMaxViewportDim: Cardinal; static;
class function GenerateTextureCommon(aMinFilter, aMagFilter: TKMFilterType): Cardinal;
@@ -70,8 +77,9 @@ var
implementation
uses
SysUtils, Math,
CastleRenderContext, CastleRenderOptions,
KromOGLUtils, KromUtils,
KM_Log, KM_Defaults, KM_IoPNG, KM_CommonClasses,
KM_Defaults, KM_IoPNG, KM_CommonClasses,
KM_Render_Mobile;
const
@@ -85,38 +93,23 @@ constructor TKMRender.Create(aScreenX, aScreenY: Integer);
begin
inherited Create;
gLog.AddTime('Init Render started');
fFBOInited := False;
if not fBlind then
begin
fMaxViewportDim := GetMaxViewportDim;
gLog.AddTime('GL_MAX_VIEWPORT_DIM = ' + IntToStr(fMaxViewportDim));
glClearColor(0, 0, 0, 0); //Background
glClearStencil(0);
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH); //Enables Smooth Color Shading
glPolygonMode(GL_FRONT, GL_FILL);
glEnable(GL_NORMALIZE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Set alpha mode
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_COLOR_MATERIAL); //Enable Materials
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glDisable(GL_LIGHTING); //We don't need it
//glEnable(GL_CULL_FACE);
//glCullFace(GL_FRONT);
end;
Resize(aScreenX, aScreenY);
gLog.AddTime('Init Render Done');
end;
destructor TKMRender.Destroy;
begin
KMRenderMobileInvalidateSampledProgram;
if not fBlind then
begin
if fFBOInited then
@@ -171,19 +164,9 @@ end;
procedure TKMRender.SetRenderMode(aRenderMode: TKMRenderMode);
begin
if fBlind then Exit;
glMatrixMode(GL_PROJECTION); //Change Matrix Mode to Projection
glLoadIdentity; //Reset View
//In 2D mode we use Z-test to clip terrain shadows behind mountains
//1 unit for each tile strip. 512 means we can handle up to 512x512 maps
case aRenderMode of
rm2D: glOrtho(0, fScreenX, fScreenY, 0, -100, 100);
rm3D: gluPerspective(80, -fScreenX/fScreenY, 0.1, 5000);
end;
glMatrixMode(GL_MODELVIEW); //Return to the modelview matrix
glLoadIdentity; //Reset View
KMRenderMobileApplyOrdinary2DProjection(fScreenX, fScreenY);
end;
@@ -224,9 +207,15 @@ end;
class procedure TKMRender.GraphicsContextChanged(aAvailable: Boolean);
begin
if aAvailable then
KMRenderMobileInitializeCurrentContext
begin
KMRenderMobileInitializeCurrentContext;
KMRenderMobileInitializeSampledProgram;
end
else
begin
KMRenderMobileInvalidateCurrentContext;
KMRenderMobileInvalidateSampledProgram;
end;
end;
@@ -236,6 +225,26 @@ begin
end;
class function TKMRender.SampledProgramReady: Boolean;
begin
Result := KMRenderMobileSampledProgramReady;
end;
class procedure TKMRender.DrawSampledTriangles(const aVertices: array of TKMSampledVertex; const aColor: TKMColor4f);
begin
if Length(aVertices) = 0 then Exit;
if (Length(aVertices) mod 3) <> 0 then
raise Exception.Create('Sampled triangle vertex count must be divisible by three');
RenderContext.DepthFunc := dfLessEqual;
RenderContext.BlendingEnable(bsSrcAlpha, bdOneMinusSrcAlpha);
KMRenderMobileDrawSampledTriangles(@aVertices[0].X, @aVertices[0].U,
SizeOf(TKMSampledVertex), Length(aVertices),
aColor.R, aColor.G, aColor.B, aColor.A);
end;
class function TKMRender.GetMaxTexSize: Cardinal;
begin
Result := KMRenderMobileMaxTextureSize;
@@ -309,8 +318,6 @@ end;
procedure TKMRender.BeginFrame;
begin
if fBlind then Exit;
if SAVE_MAP_TO_FBO_RENDER then
begin
if not fFBOInited then
@@ -320,31 +327,28 @@ begin
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fFBO);
end;
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT);
KMRenderMobileClearCurrentTarget;
SetRenderMode(rm2D);
KMRenderMobileSetActiveTextureUnit0;
TKMRender.InvalidateTextureBindingCache;
RenderContext.DepthFunc := dfLessEqual;
RenderContext.BlendingEnable(bsSrcAlpha, bdOneMinusSrcAlpha);
//RC.Activate for OSX
end;
//Render highlight overlay to make whole picture look brighter (more saturated)
procedure TKMRender.RenderBrightness(aValue: Byte);
var
intensity: Single;
begin
if fBlind then Exit;
//There will be no change to image anyway
if aValue = 0 then Exit;
BindTexture(0); // We have to reset texture to default (0), because it could be bind to any other texture (atlas)
glLoadIdentity;
glBlendFunc(GL_DST_COLOR, GL_ONE);
glColor4f(aValue/20, aValue/20, aValue/20, aValue/20);
glBegin(GL_QUADS);
glkRect(0, 0, ScreenX, ScreenY);
glEnd;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
intensity := aValue / 20;
KMRenderMobileDrawBrightnessOverlay(intensity, ScreenX, ScreenY);
end;
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff