- case Func of
- nm4Samples:
- begin
- SetLength(Rec.MatrixU, 2);
- SetEntry(Rec.MatrixU, 0, -1, 0, -0.5);
- SetEntry(Rec.MatrixU, 1, 1, 0, 0.5);
-
- SetLength(Rec.MatrixV, 2);
- SetEntry(Rec.MatrixV, 0, 0, 1, 0.5);
- SetEntry(Rec.MatrixV, 1, 0, -1, -0.5);
- end;
- nmSobel:
- begin
- SetLength(Rec.MatrixU, 6);
- SetEntry(Rec.MatrixU, 0, -1, 1, -1.0);
- SetEntry(Rec.MatrixU, 1, -1, 0, -2.0);
- SetEntry(Rec.MatrixU, 2, -1, -1, -1.0);
- SetEntry(Rec.MatrixU, 3, 1, 1, 1.0);
- SetEntry(Rec.MatrixU, 4, 1, 0, 2.0);
- SetEntry(Rec.MatrixU, 5, 1, -1, 1.0);
-
- SetLength(Rec.MatrixV, 6);
- SetEntry(Rec.MatrixV, 0, -1, 1, 1.0);
- SetEntry(Rec.MatrixV, 1, 0, 1, 2.0);
- SetEntry(Rec.MatrixV, 2, 1, 1, 1.0);
- SetEntry(Rec.MatrixV, 3, -1, -1, -1.0);
- SetEntry(Rec.MatrixV, 4, 0, -1, -2.0);
- SetEntry(Rec.MatrixV, 5, 1, -1, -1.0);
- end;
- nm3x3:
- begin
- SetLength(Rec.MatrixU, 6);
- SetEntry(Rec.MatrixU, 0, -1, 1, -1/6);
- SetEntry(Rec.MatrixU, 1, -1, 0, -1/6);
- SetEntry(Rec.MatrixU, 2, -1, -1, -1/6);
- SetEntry(Rec.MatrixU, 3, 1, 1, 1/6);
- SetEntry(Rec.MatrixU, 4, 1, 0, 1/6);
- SetEntry(Rec.MatrixU, 5, 1, -1, 1/6);
-
- SetLength(Rec.MatrixV, 6);
- SetEntry(Rec.MatrixV, 0, -1, 1, 1/6);
- SetEntry(Rec.MatrixV, 1, 0, 1, 1/6);
- SetEntry(Rec.MatrixV, 2, 1, 1, 1/6);
- SetEntry(Rec.MatrixV, 3, -1, -1, -1/6);
- SetEntry(Rec.MatrixV, 4, 0, -1, -1/6);
- SetEntry(Rec.MatrixV, 5, 1, -1, -1/6);
- end;
- nm5x5:
- begin
- SetLength(Rec.MatrixU, 20);
- SetEntry(Rec.MatrixU, 0, -2, 2, -1 / 16);
- SetEntry(Rec.MatrixU, 1, -1, 2, -1 / 10);
- SetEntry(Rec.MatrixU, 2, 1, 2, 1 / 10);
- SetEntry(Rec.MatrixU, 3, 2, 2, 1 / 16);
- SetEntry(Rec.MatrixU, 4, -2, 1, -1 / 10);
- SetEntry(Rec.MatrixU, 5, -1, 1, -1 / 8);
- SetEntry(Rec.MatrixU, 6, 1, 1, 1 / 8);
- SetEntry(Rec.MatrixU, 7, 2, 1, 1 / 10);
- SetEntry(Rec.MatrixU, 8, -2, 0, -1 / 2.8);
- SetEntry(Rec.MatrixU, 9, -1, 0, -0.5);
- SetEntry(Rec.MatrixU, 10, 1, 0, 0.5);
- SetEntry(Rec.MatrixU, 11, 2, 0, 1 / 2.8);
- SetEntry(Rec.MatrixU, 12, -2, -1, -1 / 10);
- SetEntry(Rec.MatrixU, 13, -1, -1, -1 / 8);
- SetEntry(Rec.MatrixU, 14, 1, -1, 1 / 8);
- SetEntry(Rec.MatrixU, 15, 2, -1, 1 / 10);
- SetEntry(Rec.MatrixU, 16, -2, -2, -1 / 16);
- SetEntry(Rec.MatrixU, 17, -1, -2, -1 / 10);
- SetEntry(Rec.MatrixU, 18, 1, -2, 1 / 10);
- SetEntry(Rec.MatrixU, 19, 2, -2, 1 / 16);
-
- SetLength(Rec.MatrixV, 20);
- SetEntry(Rec.MatrixV, 0, -2, 2, 1 / 16);
- SetEntry(Rec.MatrixV, 1, -1, 2, 1 / 10);
- SetEntry(Rec.MatrixV, 2, 0, 2, 0.25);
- SetEntry(Rec.MatrixV, 3, 1, 2, 1 / 10);
- SetEntry(Rec.MatrixV, 4, 2, 2, 1 / 16);
- SetEntry(Rec.MatrixV, 5, -2, 1, 1 / 10);
- SetEntry(Rec.MatrixV, 6, -1, 1, 1 / 8);
- SetEntry(Rec.MatrixV, 7, 0, 1, 0.5);
- SetEntry(Rec.MatrixV, 8, 1, 1, 1 / 8);
- SetEntry(Rec.MatrixV, 9, 2, 1, 1 / 16);
- SetEntry(Rec.MatrixV, 10, -2, -1, -1 / 16);
- SetEntry(Rec.MatrixV, 11, -1, -1, -1 / 8);
- SetEntry(Rec.MatrixV, 12, 0, -1, -0.5);
- SetEntry(Rec.MatrixV, 13, 1, -1, -1 / 8);
- SetEntry(Rec.MatrixV, 14, 2, -1, -1 / 10);
- SetEntry(Rec.MatrixV, 15, -2, -2, -1 / 16);
- SetEntry(Rec.MatrixV, 16, -1, -2, -1 / 10);
- SetEntry(Rec.MatrixV, 17, 0, -2, -0.25);
- SetEntry(Rec.MatrixV, 18, 1, -2, -1 / 10);
- SetEntry(Rec.MatrixV, 19, 2, -2, -1 / 16);
- end;
- end;
-
- // Daten Sammeln
- if UseAlpha and FormatHasAlpha(InternalFormat) then
- AddFunc(glBitmapToNormalMapPrepareAlphaFunc, False, @Rec)
- else
- AddFunc(glBitmapToNormalMapPrepareFunc, False, @Rec);
-
- // Neues Bild berechnen
- AddFunc(glBitmapToNormalMapFunc, False, @Rec);
- finally
- SetLength(Rec.Heights, 0);
- end;
-end;
-
-
-procedure TglBitmap2D.GrabScreen(Top, Left, Right, Bottom: Integer; Format: TglBitmapInternalFormat);
-var
- Temp: pByte;
- Size: Integer;
- glFormat, glInternalFormat, glType: Cardinal;
-begin
- if not FormatIsUncompressed(Format) then
- raise EglBitmapUnsupportedInternalFormat.Create('TglBitmap2D.GrabScreen - ' + UNSUPPORTED_INTERNAL_FORMAT);
-
- // Only to select Formats
- SelectFormat(Format, glFormat, glInternalFormat, glType, False);
-
- Size := FormatGetImageSize(glBitmapPosition(Right - Left, Bottom - Top), Format);
- GetMem(Temp, Size);
- try
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadPixels(Left, Top, Right - Left, Bottom - Top, glFormat, glType, Temp);
-
- // Set Data
- SetDataPointer(Temp, Format, Right - Left, Bottom - Top);
-
- // Flip
- FlipVert;
- except
- FreeMem(Temp);
- raise;
- end;
-end;
-
-
-procedure TglBitmap2D.GetDataFromTexture;
-var
- Temp: pByte;
- TempWidth, TempHeight, RedSize, GreenSize, BlueSize, AlphaSize, LumSize: Integer;
- TempType, TempIntFormat: Cardinal;
- IntFormat: TglBitmapInternalFormat;
-begin
- Bind;
-
- // Request Data
- glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_WIDTH, @TempWidth);
- glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_HEIGHT, @TempHeight);
- glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_INTERNAL_FORMAT, @TempIntFormat);
-
- glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_RED_SIZE, @RedSize);
- glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_GREEN_SIZE, @GreenSize);
- glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_BLUE_SIZE, @BlueSize);
- glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_ALPHA_SIZE, @AlphaSize);
- glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_LUMINANCE_SIZE, @LumSize);
-
- // Get glBitmapInternalFormat from TempIntFormat
- TempType := GL_UNSIGNED_BYTE;
- case TempIntFormat of
- GL_ALPHA:
- IntFormat := ifAlpha;
- GL_LUMINANCE:
- IntFormat := ifLuminance;
- GL_LUMINANCE_ALPHA:
- IntFormat := ifLuminanceAlpha;
- GL_RGB4:
- begin
- IntFormat := ifR5G6B5;
- TempIntFormat := GL_RGB;
- TempType := GL_UNSIGNED_SHORT_5_6_5;
- end;
- GL_RGB, GL_RGB8:
- IntFormat := ifRGB8;
- GL_RGBA, GL_RGBA4, GL_RGBA8:
- begin
- if (RedSize = 4) and (BlueSize = 4) and (GreenSize = 4) and (AlphaSize = 4) then begin
- IntFormat := ifRGBA4;
- TempIntFormat := GL_BGRA;
- TempType := GL_UNSIGNED_SHORT_4_4_4_4_REV;
- end else
- if (RedSize = 5) and (BlueSize = 5) and (GreenSize = 5) and (AlphaSize = 1) then begin
- IntFormat := ifRGB5A1;
- TempIntFormat := GL_BGRA;
- TempType := GL_UNSIGNED_SHORT_1_5_5_5_REV;
- end else begin
- IntFormat := ifRGBA8;
- end;