Android 그래픽 셰이딩 언어 (AGSL)
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 그래픽 셰이딩 언어 (AGSL)는 Android 13 이상에서 프로그래밍 가능한 RuntimeShader
객체의 동작을 정의하는 데 사용됩니다. AGSL은 대부분의 문법을 GLSL 프래그먼트 셰이더와 공유하지만 Android 그래픽 렌더링 시스템 내에서 작동하여 Canvas
내에서 페인팅을 맞춤설정하고 View
콘텐츠를 필터링합니다.
작동 이론
AGSL 효과는 더 큰 Android 그래픽 파이프라인의 일부로 존재합니다. Android는 GPU 가속 그리기 작업을 실행하면 단일 GPU 프래그먼트 셰이더를 어셈블하여 필요한 작업을 실행합니다. 이 셰이더에는 일반적으로 여러 조각이 포함됩니다.
예를 들어 다음이 포함될 수 있습니다.
- 픽셀이 그려지는 도형의 내부 또는 외부(또는 앤티앨리어싱이 적용될 수 있는 테두리)에 있는지 평가합니다.
- 픽셀이 클리핑 영역 내부 또는 외부에 있는지 평가(테두리 픽셀에 가능한 앤티앨리어싱 로직 사용)
Paint
의 Shader
로직. 셰이더는 실제로 객체 트리일 수 있습니다 (ComposeShader
및 아래에 설명된 기타 기능 때문).
ColorFilter
의 유사한 로직
- 블렌딩 코드 (특정 유형의
BlendMode
)
- Android 색상 관리의 일부인 색상 공간 변환 코드입니다.
Paint
의 Shader
, ColorFilter
또는 BlendMode
필드에 복잡한 객체 트리가 있는 경우 여전히 단일 GPU 프래그먼트 셰이더만 있습니다. 이 트리의 각 노드는 단일 함수를 생성합니다. 클리핑 코드와 도형 코드는 각각 함수를 생성합니다. 혼합 코드로 함수를 만들 수 있습니다.
그러면 전체 프래그먼트 셰이더가 이러한 함수를 모두 호출합니다 (셰이더 트리의 경우와 같이 다른 함수를 호출할 수 있음).
AGSL 효과는 GPU의 프래그먼트 셰이더에 함수를 제공합니다.
기본 문법
AGSL (및 GLSL)은 C 스타일의 도메인별 언어입니다. bool
및 int
와 같은 유형은 C에 상응하는 유형을 면밀히 추적합니다. 도메인 기능을 지원하는 벡터와 행렬을 지원하는 추가 유형이 있습니다.
한정자는 음영 언어에 고유한 방식으로 정밀도 힌트 유형에 적용할 수 있습니다. if-else
문과 같은 제어 구조는 C에서와 매우 유사한 방식으로 작동합니다. 이 언어는 또한 제한된 switch
문과 for
루프를 지원합니다. 일부 컨트롤 구조에는 컴파일 시간에 평가할 수 있는 상수 표현식이 필요합니다.
AGSL은 함수를 지원합니다. 모든 셰이더 프로그램은 main
함수로 시작합니다.
사용자 정의 함수는 어떤 종류의 재귀도 지원하지 않고 지원됩니다.
함수는 '값-반환' 호출 규칙을 사용합니다. 함수에 전달된 값은 함수가 호출될 때 매개변수에 복사되고 출력이 다시 복사됩니다. 이는 in
, out
, inout
한정자에 의해 결정됩니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[],[],null,["# Android Graphics Shading Language (AGSL) is used by Android 13 and above to\ndefine the behavior of programmable\n[`RuntimeShader`](/reference/android/graphics/RuntimeShader) objects. AGSL\nshares much of its syntax with GLSL fragment shaders, but works within the\nAndroid graphics rendering system to both customize painting within `Canvas`\nand filter `View` content.\n\nTheory of operation\n-------------------\n\nAGSL effects exist as part of the larger Android graphics pipeline. When Android\nissues a GPU accelerated drawing operation, it assembles a single GPU fragment\nshader to do the required work. This shader typically includes several pieces.\nFor example, it might include:\n\n- Evaluating whether a pixel falls inside or outside of the shape being drawn (or on the border, where it might apply anti-aliasing).\n- Evaluating whether a pixel falls inside or outside of the clipping region (again, with possible anti-aliasing logic for border pixels).\n- Logic for the [`Shader`](/reference/android/graphics/Shader) on the [`Paint`](/reference/android/graphics/Paint). The Shader can actually be a tree of objects (due to [`ComposeShader`](/reference/android/graphics/ComposeShader) and other features described below).\n- Similar logic for the [`ColorFilter`](/reference/android/graphics/ColorFilter).\n- Blending code (for certain types of [`BlendMode`](/reference/android/graphics/BlendMode)).\n- Color space conversion code, as part of Android's color management.\n- When the `Paint` has a complex tree of objects in the `Shader`, `ColorFilter`, or `BlendMode` fields, there is still only a single GPU fragment shader. Each node in that tree creates a single function. The clipping code and geometry code each create a function. The blending code might create a function. The overall fragment shader then calls all of these functions (which may call other functions, e.g. in the case of a shader tree).\n\nYour AGSL effect contributes a function (or functions) to the GPU's fragment shader.\n\nBasic syntax\n------------\n\nAGSL (and GLSL) are C-style domain specific languages. Types such as `bool` and\n`int` closely track their C equivalents; there are additional types to\nsupport vectors and matrices that support domain functionality.\n\nQualifiers can be applied to types for precision hints in a way that's unique to shading languages. Control structures such as `if-else` statements work much\nlike they do in C; the language also provides support for `switch` statements\nand `for` loops with limitations. Some control structures require constant expressions that can be evaluated at compile time.\n\nAGSL supports functions; every shader program begins with the `main` function.\nUser defined functions are supported, without support for recursion of any kind.\nFunctions use a \"value-return\" calling convention; values passed to functions are\ncopied into parameters when the function is called, and outputs are copied\nback; this is determined by the `in`, `out`, and `inout` qualifiers."]]