-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3033bc0
commit 85db329
Showing
50 changed files
with
6,273 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: f1b13696fd211eb86c3c56576a6385cf | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
DirectX Code Generation API Reference | ||
===================================== | ||
|
||
This doc provides an overview of the DirectX code generation functionality in CrossGL, specifically focusing on the `HLSLCodeGen` class. This class is responsible for converting the abstract syntax tree (AST) of CrossGL shaders into HLSL code. | ||
|
||
.. raw:: html | ||
|
||
<div class="large-text">HLSLCodeGen</div> | ||
|
||
HLSLCodeGen is responsible for generating HLSL code from the AST nodes. | ||
|
||
.. raw:: html | ||
|
||
<div class="large-text">Attributes</div> | ||
|
||
- **current_shader** (`ShaderNode`) – The current shader node being processed. | ||
|
||
.. raw:: html | ||
|
||
<div class="large-text">Methods</div> | ||
|
||
``__init__(self)`` | ||
Initializes the code generator. | ||
|
||
``generate(self, ast)`` | ||
Generates HLSL code from the AST. | ||
|
||
- **Parameters**: | ||
- `ast` (`ShaderNode`) – The abstract syntax tree of the shader. | ||
- **Returns**: `str` – The generated HLSL code. | ||
|
||
``generate_shader(self, node)`` | ||
Generates the HLSL code for the shader. | ||
|
||
- **Parameters**: | ||
- `node` (`ShaderNode`) – The shader node of the AST. | ||
- **Returns**: `str` – The generated HLSL code. | ||
|
||
``generate_function(self, node)`` | ||
Generates the HLSL code for a function. | ||
|
||
- **Parameters**: | ||
- `node` (`FunctionNode`) – The function node of the AST. | ||
- **Returns**: `str` – The generated HLSL code. | ||
|
||
``generate_statement(self, stmt, indent=0, is_vs_input=False)`` | ||
Generates the HLSL code for a statement. | ||
|
||
- **Parameters**: | ||
- `stmt` (`ASTNode`) – The statement node of the AST. | ||
- `indent` (`int`) – The indentation level. | ||
- `is_vs_input` (`bool`) – Whether the statement is in the vertex shader input. | ||
- **Returns**: `str` – The generated HLSL code. | ||
|
||
``generate_assignment(self, node, is_vs_input=False)`` | ||
Generates the HLSL code for an assignment statement. | ||
|
||
- **Parameters**: | ||
- `node` (`AssignmentNode`) – The assignment node of the AST. | ||
- `is_vs_input` (`bool`) – Whether the assignment is in the vertex shader input. | ||
- **Returns**: `str` – The generated HLSL code. | ||
|
||
``generate_if(self, node, indent, is_vs_input=False)`` | ||
Generates the HLSL code for an if statement. | ||
|
||
- **Parameters**: | ||
- `node` (`IfNode`) – The if statement node of the AST. | ||
- `indent` (`int`) – The indentation level. | ||
- `is_vs_input` (`bool`) – Whether the if statement is in the vertex shader input. | ||
- **Returns**: `str` – The generated HLSL code. | ||
|
||
``generate_for(self, node, indent, is_vs_input=False)`` | ||
Generates the HLSL code for a for loop statement. | ||
|
||
- **Parameters**: | ||
- `node` (`ForNode`) – The for loop node of the AST. | ||
- `indent` (`int`) – The indentation level. | ||
- `is_vs_input` (`bool`) – Whether the for loop is in the vertex shader input. | ||
- **Returns**: `str` – The generated HLSL code. | ||
|
||
``generate_expression(self, expr, is_vs_input=False)`` | ||
Generates the HLSL code for an expression. | ||
|
||
- **Parameters**: | ||
- `expr` (`ASTNode`) – The expression node of the AST. | ||
- `is_vs_input` (`bool`) – Whether the expression is in the vertex shader input. | ||
- **Returns**: `str` – The generated HLSL code. | ||
|
||
``translate_expression(self, expr, is_vs_input)`` | ||
Translates an expression from CrossGL syntax to HLSL syntax. | ||
|
||
- **Parameters**: | ||
- `expr` (`str`) – The expression in CrossGL syntax. | ||
- `is_vs_input` (`bool`) – Whether the expression is in the vertex shader input. | ||
- **Returns**: `str` – The translated expression. | ||
|
||
``map_type(self, vtype)`` | ||
Maps CrossGL types to HLSL types. | ||
|
||
- **Parameters**: `vtype` (`str`) – The CrossGL type. | ||
- **Returns**: `str` – The corresponding HLSL type. | ||
|
||
``map_operator(self, op)`` | ||
Maps CrossGL operators to HLSL operators. | ||
|
||
- **Parameters**: `op` (`str`) – The CrossGL operator. | ||
- **Returns**: `str` – The corresponding HLSL operator. | ||
|
||
|
||
.. raw:: html | ||
|
||
<div class="large-text">Example</div> | ||
|
||
Here's an example usage of the `HLSLCodeGen` class to generate HLSL code from a CrossGL shader: | ||
|
||
.. code-block:: python | ||
from compiler.lexer import Lexer | ||
from compiler.parser import Parser | ||
code = """ | ||
shader main { | ||
input vec3 position; | ||
input vec2 texCoord; | ||
input mat2 depth; | ||
output vec4 fragColor; | ||
output float depth; | ||
vec3 customFunction(vec3 random, float factor) { | ||
return random * factor; | ||
} | ||
void main() { | ||
vec3 color = vec3(position.x,position.y, 0.0); | ||
float factor = 1.0; | ||
if (texCoord.x > 0.5) { | ||
color = vec3(1.0, 0.0, 0.0); | ||
} else { | ||
color = vec3(0.0, 1.0, 0.0); | ||
} | ||
for (int i = 0; i < 3; i = i + 1) { | ||
factor = factor * 0.5; | ||
color = customFunction(color, factor); | ||
} | ||
if (length(color) > 1.0) { | ||
color = normalize(color); | ||
} | ||
fragColor = vec4(color, 1.0); | ||
} | ||
} | ||
""" | ||
lexer = Lexer(code) | ||
parser = Parser(lexer.tokens) | ||
ast = parser.parse() | ||
codegen = HLSLCodeGen() | ||
hlsl_code = codegen.generate(ast) | ||
print(hlsl_code) | ||
.. raw:: html | ||
|
||
<div class="large-text">Returns</div> | ||
|
||
``str`` – The generated HLSL code as a string. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
Contribution Guidelines | ||
======================= | ||
|
||
We appreciate your interest in contributing to CrossGL. By contributing, you help improve the project and make it more robust and useful for everyone. | ||
|
||
|
||
.. raw:: html | ||
|
||
<div class="large-text">How to Contribute</div> | ||
|
||
**1. Fork the Repository** | ||
|
||
Start by forking the CrossGL repository on GitHub to your own account. | ||
|
||
**2. Clone Your Fork** | ||
|
||
Clone your forked repository to your local machine. | ||
|
||
.. code-block:: bash | ||
git clone https://github.com/your-username/CrossGL.git | ||
cd CrossGL | ||
**3. Create a Branch** | ||
|
||
Create a new branch for your changes. Use a descriptive name for your branch. | ||
|
||
.. code-block:: bash | ||
git checkout -b feature-name | ||
**4. Make Changes** | ||
|
||
Make your changes to the codebase. Follow the project's coding style and guidelines. Ensure that your changes do not break existing functionality. | ||
|
||
**5. Add Tests** | ||
|
||
If applicable, add tests for your changes. Ensure that all tests pass before submitting your contribution. | ||
|
||
**6. Commit Your Changes** | ||
|
||
Commit your changes with a clear and concise commit message. | ||
|
||
.. code-block:: bash | ||
git add . | ||
git commit -m "Description of your changes" | ||
**7. Push to GitHub** | ||
|
||
Push your changes to your forked repository on GitHub. | ||
|
||
.. code-block:: bash | ||
git push origin feature-name | ||
**8. Open a Pull Request** | ||
|
||
Open a pull request on the original repository. Provide a detailed description of your changes and any additional information that may be useful for the reviewers. | ||
|
||
|
||
.. raw:: html | ||
|
||
<div class="large-text">Contribution Pipeline</div> | ||
|
||
1. **Issue Tracking** | ||
|
||
We use GitHub issues to track bugs, enhancements, and tasks. Feel free to open a new issue if you find a bug or have a feature request. | ||
|
||
2. **Code Review** | ||
|
||
All contributions go through a code review process. The maintainers will review your pull request and provide feedback. Be prepared to make additional changes based on the feedback. | ||
|
||
3. **Continuous Integration** | ||
|
||
We use Continuous Integration (CI) to run automated tests on all pull requests. Ensure that your code passes all the tests before submitting your pull request. | ||
|
||
4. **Merging** | ||
|
||
Once your pull request has been reviewed and approved, it will be merged into the main branch. | ||
|
||
.. raw:: html | ||
|
||
<div class="large-text">Thank You ✨</div> | ||
|
||
Thank you for your interest in contributing to CrossGL! Your contributions make a significant impact on the project and the community. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Design | ||
============ | ||
|
||
Here we present how the CrossGL ecosystem works! | ||
|
||
.. image:: _static/workflow.png | ||
:alt: CrossGL Ecosystem Workflow | ||
:align: center | ||
:width: 80% |
Oops, something went wrong.