Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e4dda2a77 | ||
|
|
6cfa604677 | ||
|
|
7b3cf8ce9b | ||
|
|
cea7cb5ba4 | ||
|
|
c9ff13bb77 | ||
|
|
85bd6f7cf4 | ||
|
|
e165e07e02 | ||
|
|
3f6015db2f | ||
|
|
0c4c107244 | ||
|
|
d5c16a5237 | ||
|
|
1e171411f7 | ||
|
|
bf298ccefa | ||
|
|
67ba86601c | ||
|
|
545aa86a5a | ||
|
|
9d5d4748a9 | ||
|
|
4f6a68c22c | ||
|
|
70c819393c | ||
|
|
0cb2019704 | ||
|
|
f180eaf75a |
No files matched your search
@@ -46,6 +46,7 @@ SD_DIR := $(LIBDIR)/tinyblocks-sdl2
|
||||
PY_DIR := $(LIBDIR)/tinyblocks-python
|
||||
MC_DIR := $(LIBDIR)/tinyblocks-mcp
|
||||
A11Y_DIR := $(LIBDIR)/tinyblocks-a11y
|
||||
QR_DIR := $(LIBDIR)/tinyblocks-qr
|
||||
MCPS_DIR := $(LIBDIR)/tinyblocks-mcp-server
|
||||
|
||||
GFX_INC := $(GX_DIR)/include
|
||||
@@ -86,10 +87,10 @@ CAT_LDFLAGS := $(foreach l,$(CAT_LIBS),-ltinyblocks-$(l))
|
||||
CAT_INCS := $(foreach l,$(CAT_LIBS),-I$(LIBDIR)/tinyblocks-$(l)/include)
|
||||
# Libraries que o editor registra como as de categoria, mas com varios
|
||||
# fontes e o Makefile proprio (o harness nao as compila junto)
|
||||
APP_LIBS := socket ssl http archive tensor ai plot 3d shader gl vk
|
||||
APP_LIBS := ppm bmp png image socket ssl http archive tensor ai plot 3d shader gl vk
|
||||
APP_A := $(foreach l,$(APP_LIBS),$(LIBDIR)/tinyblocks-$(l)/build/libtinyblocks-$(l).a)
|
||||
APP_INCS := $(foreach l,$(APP_LIBS),-I$(LIBDIR)/tinyblocks-$(l)/include)
|
||||
APP_LDLIBS := -lssl -lcrypto -lz -lpthread -lEGL -lOpenGL -lvulkan -ldl
|
||||
APP_LDLIBS := -lssl -lcrypto -lz -lpng -lpthread -lEGL -lOpenGL -lvulkan -ldl
|
||||
ED_A := $(ED_DIR)/build/libtinyblocks-editor.a
|
||||
GX_A := $(GX_DIR)/build/libtinyblocks-graphics.a
|
||||
SD_A := $(SD_DIR)/build/libtinyblocks-sdl2.a
|
||||
@@ -103,6 +104,7 @@ LIBM_A := $(LIBM_DIR)/build/libtinyblocks-libman.a
|
||||
SYN_A := $(SYN_DIR)/build/libtinyblocks-syntax.a
|
||||
SB_A := $(SB_DIR)/build/libtinyblocks-scratchblocks.a
|
||||
A11Y_A := $(A11Y_DIR)/build/libtinyblocks-a11y.a
|
||||
QR_A := $(QR_DIR)/build/libtinyblocks-qr.a
|
||||
MCPS_A := $(MCPS_DIR)/build/libtinyblocks-mcp-server.a
|
||||
LIB_LDFLAGS := -L$(ED_DIR)/build -L$(GX_DIR)/build -L$(SD_DIR)/build \
|
||||
$(foreach l,$(CAT_LIBS),-L$(LIBDIR)/tinyblocks-$(l)/build) -L$(BUILD)
|
||||
@@ -110,7 +112,7 @@ LIB_LDFLAGS := -L$(ED_DIR)/build -L$(GX_DIR)/build -L$(SD_DIR)/build \
|
||||
.PHONY: all help debug release static shared example sdl2 clean run python-lib mcp-lib json \
|
||||
editor run-editor run-sdl2 mylib vector customappearance graphics sdl2-backend test-editor \
|
||||
appdir appimage run-appimage icon \
|
||||
test-toml test-plugin test-blueprint test-a11y test-mcp test-mcp-server test-base64 test-curves test-meta test-ppm test-bmp test-png test-image test-vg test-svg test-jpg \
|
||||
test-toml test-plugin test-blueprint test-qr test-a11y test-mcp test-mcp-server test-base64 test-curves test-meta test-ppm test-bmp test-png test-image test-vg test-svg test-jpg \
|
||||
test-tensor test-ai test-http test-archive test-plot test-3d test-syntax test-os test-value test-vars test-scratchblocks test-input test-stdlib test-regex test-markdown test-opentype \
|
||||
category-libs category-sos libs app-libs \
|
||||
lib-events lib-control lib-errors lib-input lib-operators lib-number lib-string lib-variables lib-vector lib-appearance lib-pen lib-fs lib-os \
|
||||
@@ -177,12 +179,15 @@ $(foreach l,$(APP_LIBS),$(eval $(call CAT_LIB_TARGET,$(l))))
|
||||
|
||||
app-libs: $(foreach l,$(APP_LIBS),lib-$(l)) ## Compila tensor e as outras libraries do app (.a/.so)
|
||||
|
||||
lib-editor: lib-a11y lib-mcp-server
|
||||
lib-editor: lib-a11y lib-mcp-server lib-qr
|
||||
$(MAKE) -C $(ED_DIR)
|
||||
|
||||
lib-a11y:
|
||||
$(MAKE) -C $(A11Y_DIR)
|
||||
|
||||
lib-qr:
|
||||
$(MAKE) -C $(QR_DIR)
|
||||
|
||||
lib-mcp-server:
|
||||
$(MAKE) -C $(MCPS_DIR)
|
||||
|
||||
@@ -308,7 +313,7 @@ $(BUILD)/editor: examples/editor/main.c static libs
|
||||
-I$(JSON_DIR)/include -I$(XML_DIR)/include -I$(CSV_DIR)/include -I$(BP_DIR)/include \
|
||||
-I$(API_DIR)/include -I$(LIBM_DIR)/include -I$(SYN_DIR)/include -I$(A11Y_DIR)/include -I$(MCPS_DIR)/include \
|
||||
$< -o $@ \
|
||||
-Wl,--start-group $(ED_A) $(A11Y_A) $(MCPS_A) $(GX_A) $(SD_A) $(TOML_A) $(JSON_A) $(XML_A) $(CSV_A) $(BP_A) $(SB_A) $(API_A) $(LIBM_A) $(SYN_A) $(CAT_A) $(APP_A) $(LIB_A) -Wl,--end-group \
|
||||
-Wl,--start-group $(ED_A) $(A11Y_A) $(QR_A) $(MCPS_A) $(GX_A) $(SD_A) $(TOML_A) $(JSON_A) $(XML_A) $(CSV_A) $(BP_A) $(SB_A) $(API_A) $(LIBM_A) $(SYN_A) $(CAT_A) $(APP_A) $(LIB_A) -Wl,--end-group \
|
||||
$(SDL2_LIBS) $(SDL2TTF_LIBS) $(APP_LDLIBS) -ldl -lm -rdynamic \
|
||||
'-Wl,-rpath,$$ORIGIN'
|
||||
|
||||
@@ -323,7 +328,7 @@ run-editor: editor ## Compila e abre o editor visual
|
||||
APPIMAGE_LIBS := $(CAT_LIBS) $(APP_LIBS) toml json xml csv blueprint base64 curves ppm bmp png image vg svg jpg syntax regex markdown opentype
|
||||
|
||||
APP_NAME := TinyBlocks
|
||||
APP_VER := 0.1.0
|
||||
APP_VER := 0.2.0
|
||||
APPDIR := $(BUILD)/$(APP_NAME).AppDir
|
||||
APPIMAGE := $(BUILD)/$(APP_NAME)-$(APP_VER)-x86_64.AppImage
|
||||
AITOOL := $(BUILD)/.tools/appimagetool-x86_64.AppImage
|
||||
@@ -358,6 +363,7 @@ appdir: editor ## Monta o AppDir (build/TinyBlocks.AppDir) para o AppImage
|
||||
cp $(PKG_DIR)/tinyblocks.desktop $(APPDIR)/usr/share/applications/tinyblocks.desktop
|
||||
cp $(PKG_DIR)/AppRun $(APPDIR)/AppRun
|
||||
chmod +x $(APPDIR)/AppRun
|
||||
cp -r assets/fonts $(APPDIR)/fonts # Roboto + Material Symbols (TINYBLOCKS_APPDIR/fonts)
|
||||
@echo "Empacotando bibliotecas (exceto as do sistema)..."
|
||||
@ldd $(BUILD)/editor | awk '/=> \//{print $$1, $$3}' | while read name path; do \
|
||||
skip=0; \
|
||||
@@ -464,10 +470,10 @@ $(BUILD)/editor_harness: tests/editor_harness.c $(SRCS) \
|
||||
$(EFILES_DIR)/include/tb_editor_files.h \
|
||||
$(GX_DIR)/src/tb_graphics.c $(A11Y_DIR)/src/tb_a11y.c $(A11Y_DIR)/include/tb_a11y.h \
|
||||
$(EDITOR_SRC)/tb_editor_mcp.c $(EDITOR_SRC)/tb_editor_jit.c $(MCPS_DIR)/src/tb_mcp_server.c $(MCPS_DIR)/src/tb_mcp_http.c \
|
||||
lib-blueprint ed-modules
|
||||
lib-blueprint ed-modules lib-qr
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_DBG) \
|
||||
-I$(ED_DIR)/include -I$(A11Y_DIR)/include -I$(MCPS_DIR)/include -DTB_EDITOR_PRIVATE_API -DTB_MCP_SERVER_PRIVATE_API -I$(EW_DIR)/include -I$(EIMG_DIR)/include -I$(EFILES_DIR)/include -I$(GFX_INC) $(CAT_INCS) -I$(BP_DIR)/include \
|
||||
-I$(ED_DIR)/include -I$(A11Y_DIR)/include -I$(QR_DIR)/include -I$(MCPS_DIR)/include -DTB_EDITOR_PRIVATE_API -DTB_MCP_SERVER_PRIVATE_API -I$(EW_DIR)/include -I$(EIMG_DIR)/include -I$(EFILES_DIR)/include -I$(GFX_INC) $(CAT_INCS) -I$(BP_DIR)/include \
|
||||
-I$(API_DIR)/include -I$(LIBM_DIR)/include -I$(EN_DIR)/include -I$(TOML_DIR)/include -I$(CV_DIR)/include -I$(B64_DIR)/include -I$(PPM_DIR)/include -I$(SYN_DIR)/include -I$(SB_DIR)/include \
|
||||
$(SRCS) \
|
||||
$(EDITOR_SRC)/tb_editor.c $(EDITOR_SRC)/tb_stage_widget.c \
|
||||
@@ -478,7 +484,7 @@ $(BUILD)/editor_harness: tests/editor_harness.c $(SRCS) \
|
||||
$(API_DIR)/src/tb_api.c $(LIBM_DIR)/src/tb_libman.c \
|
||||
$(TOML_LIB_SRCS) $(TOML_DIR)/src/tb_toml.c \
|
||||
$(foreach l,$(CAT_LIBS),$(LIBDIR)/tinyblocks-$(l)/src/tb_$(l).c) \
|
||||
$(CV_DIR)/src/tb_curves.c $(B64_DIR)/src/tb_base64.c $(PPM_DIR)/src/tb_ppm.c $(SYN_DIR)/src/tb_syntax.c $(SB_DIR)/src/tb_scratchblocks.c tests/editor_harness.c -o $@ -ldl -lm -rdynamic
|
||||
$(CV_DIR)/src/tb_curves.c $(B64_DIR)/src/tb_base64.c $(PPM_DIR)/src/tb_ppm.c $(SYN_DIR)/src/tb_syntax.c $(SB_DIR)/src/tb_scratchblocks.c tests/editor_harness.c $(QR_A) -o $@ -ldl -lm -rdynamic
|
||||
|
||||
$(BUILD)/vm_bench: tests/vm_bench.c $(IMG_DIR)/src/tb_imglib.c $(SRCS) \
|
||||
$(EDITOR_SRC)/tb_editor.c $(EDITOR_SRC)/tb_stage_widget.c \
|
||||
@@ -488,10 +494,10 @@ $(BUILD)/vm_bench: tests/vm_bench.c $(IMG_DIR)/src/tb_imglib.c $(SRCS) \
|
||||
$(EFILES_DIR)/include/tb_editor_files.h \
|
||||
$(GX_DIR)/src/tb_graphics.c $(A11Y_DIR)/src/tb_a11y.c $(A11Y_DIR)/include/tb_a11y.h \
|
||||
$(EDITOR_SRC)/tb_editor_mcp.c $(EDITOR_SRC)/tb_editor_jit.c $(MCPS_DIR)/src/tb_mcp_server.c $(MCPS_DIR)/src/tb_mcp_http.c \
|
||||
lib-blueprint ed-modules
|
||||
lib-blueprint ed-modules lib-qr
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_REL) -g -I$(IMG_DIR)/include \
|
||||
-I$(ED_DIR)/include -I$(A11Y_DIR)/include -I$(MCPS_DIR)/include -DTB_EDITOR_PRIVATE_API -DTB_MCP_SERVER_PRIVATE_API -I$(EW_DIR)/include -I$(EIMG_DIR)/include -I$(EFILES_DIR)/include -I$(GFX_INC) $(CAT_INCS) -I$(BP_DIR)/include \
|
||||
-I$(ED_DIR)/include -I$(A11Y_DIR)/include -I$(QR_DIR)/include -I$(MCPS_DIR)/include -DTB_EDITOR_PRIVATE_API -DTB_MCP_SERVER_PRIVATE_API -I$(EW_DIR)/include -I$(EIMG_DIR)/include -I$(EFILES_DIR)/include -I$(GFX_INC) $(CAT_INCS) -I$(BP_DIR)/include \
|
||||
-I$(API_DIR)/include -I$(LIBM_DIR)/include -I$(EN_DIR)/include -I$(TOML_DIR)/include -I$(CV_DIR)/include -I$(B64_DIR)/include -I$(PPM_DIR)/include -I$(SYN_DIR)/include -I$(SB_DIR)/include \
|
||||
$(SRCS) \
|
||||
$(EDITOR_SRC)/tb_editor.c $(EDITOR_SRC)/tb_stage_widget.c \
|
||||
@@ -502,7 +508,7 @@ $(BUILD)/vm_bench: tests/vm_bench.c $(IMG_DIR)/src/tb_imglib.c $(SRCS) \
|
||||
$(API_DIR)/src/tb_api.c $(LIBM_DIR)/src/tb_libman.c \
|
||||
$(TOML_LIB_SRCS) $(TOML_DIR)/src/tb_toml.c \
|
||||
$(foreach l,$(CAT_LIBS),$(LIBDIR)/tinyblocks-$(l)/src/tb_$(l).c) \
|
||||
$(CV_DIR)/src/tb_curves.c $(B64_DIR)/src/tb_base64.c $(PPM_DIR)/src/tb_ppm.c $(SYN_DIR)/src/tb_syntax.c $(SB_DIR)/src/tb_scratchblocks.c $(IMG_DIR)/src/tb_imglib.c tests/vm_bench.c -o $@ -ldl -lm -rdynamic
|
||||
$(CV_DIR)/src/tb_curves.c $(B64_DIR)/src/tb_base64.c $(PPM_DIR)/src/tb_ppm.c $(SYN_DIR)/src/tb_syntax.c $(SB_DIR)/src/tb_scratchblocks.c $(IMG_DIR)/src/tb_imglib.c tests/vm_bench.c $(QR_A) -o $@ -ldl -lm -rdynamic
|
||||
|
||||
bench-vm: $(BUILD)/vm_bench ## Mede a VM do editor num projeto (BENCH=projeto.json)
|
||||
./$(BUILD)/vm_bench $(BENCH) 10
|
||||
@@ -582,6 +588,14 @@ $(BUILD)/mcp_server_test: tests/mcp_server_test.c $(MCPS_DIR)/src/tb_mcp_server.
|
||||
test-mcp-server: $(BUILD)/mcp_server_test ## Roda o teste do servidor MCP (ASan/UBSan)
|
||||
./$(BUILD)/mcp_server_test
|
||||
|
||||
# -- Teste da library qr (gerar e ler QR code) ---
|
||||
$(BUILD)/qr_test: tests/qr_test.c lib-qr
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_DBG) -I$(QR_DIR)/include tests/qr_test.c $(QR_A) -o $@ -lm
|
||||
|
||||
test-qr: $(BUILD)/qr_test ## Roda o teste do QR code (gerar e ler)
|
||||
./$(BUILD)/qr_test
|
||||
|
||||
# -- Teste da library a11y (arvore acessivel) ---
|
||||
$(BUILD)/a11y_test: tests/a11y_test.c $(A11Y_DIR)/src/tb_a11y.c $(A11Y_DIR)/include/tb_a11y.h static
|
||||
@mkdir -p $(BUILD)
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -23,8 +23,8 @@ Makefile).
|
||||
| `make graphics` | Interface gráfica com o backend SDL2. |
|
||||
| `make editor` / `make run-editor` | `build/editor` (o host do editor) / compila e abre. |
|
||||
| `make ed-modules` | Só as libraries privadas do editor (para hot reload com o editor aberto). |
|
||||
| `make appdir`, `make appimage`, `make run-appimage` | Monta `build/TinyBlocks.AppDir` e gera `build/TinyBlocks-0.1.0-x86_64.AppImage` (baixa o `appimagetool` na primeira vez). |
|
||||
| `make exe`, `make run-exe`, `make clean-exe` | Gera `build/win-x86_64/TinyBlocks/TinyBlocks.exe` (com as DLLs) e `build/TinyBlocks-0.1.0-win64.zip`; abre no Wine; apaga a build Windows. |
|
||||
| `make appdir`, `make appimage`, `make run-appimage` | Monta `build/TinyBlocks.AppDir` e gera `build/TinyBlocks-0.2.0-x86_64.AppImage` (baixa o `appimagetool` na primeira vez). |
|
||||
| `make exe`, `make run-exe`, `make clean-exe` | Gera `build/win-x86_64/TinyBlocks/TinyBlocks.exe` (com as DLLs) e `build/TinyBlocks-0.2.0-win64.zip`; abre no Wine; apaga a build Windows. |
|
||||
| `make exe-w2k` | Versão de 32 bits para o Windows 2000 (FreeType/SDL2_ttf estáticas e shims do uniwin). |
|
||||
| `make icon` | Regera `packaging/tinyblocks.png`. |
|
||||
| `make mylib`, `vector`, `json`, `customappearance`, `python-lib`, `mcp-lib` | Plugins de exemplo. |
|
||||
@@ -101,7 +101,7 @@ ligado sem brigar com um editor Linux aberto:
|
||||
### Windows 2000 (`make exe-w2k`)
|
||||
|
||||
`make exe-w2k` gera a build de 32 bits própria para o Windows 2000 em
|
||||
`build/win-i686-w2k/` e o zip `build/TinyBlocks-0.1.0-win2000.zip`. Ela
|
||||
`build/win-i686-w2k/` e o zip `build/TinyBlocks-0.2.0-win2000.zip`. Ela
|
||||
parte da build normal e acrescenta três coisas:
|
||||
|
||||
| Peça | O que faz |
|
||||
@@ -130,7 +130,7 @@ Testado numa VM com Windows 2000 (QEMU), pelo MCP: o programa roda e o
|
||||
|
||||
## Android (.apk)
|
||||
|
||||
`make apk` gera `build/TinyBlocks-0.1.0.apk` com o **NDK** (x86_64 para o
|
||||
`make apk` gera `build/TinyBlocks-0.2.0.apk` com o **NDK** (x86_64 para o
|
||||
emulador e arm64-v8a para aparelho, no mesmo APK) e o assina com a chave de
|
||||
depuração. Tudo do Android está em [`../packaging/android/`](../packaging/android/)
|
||||
(script, manifesto, Java do SDL2, recursos e um README com os detalhes).
|
||||
|
||||
@@ -282,6 +282,10 @@ cinza. A sequência é desenhada **de baixo para cima**, para o encaixe de cada
|
||||
bloco cobrir o seguinte. Campos com nome de variável (`TB_SLOT_VARIABLE`)
|
||||
ficam na cor de Variáveis.
|
||||
|
||||
Um programa pode definir até `MAX_USER_BLOCKS` blocos próprios (8192, em
|
||||
`tb_editor_internal.h`). Os que passarem do limite não são registrados, então
|
||||
as chamadas ficam cinzas como um tipo desconhecido.
|
||||
|
||||
### Encaixes de bloco (`TB_SLOT_CODE`, `TB_SLOT_STACK`)
|
||||
|
||||
Um campo marcado como encaixe recebe o **código** do bloco encaixado, não
|
||||
|
||||
@@ -267,12 +267,16 @@ vocabulário (blocos que, fora de um shader, dão erro), e o compilador da 3d
|
||||
|
||||
```
|
||||
"compile o shader [pilha]" (repórter da 3d; a pilha vem como código JSON)
|
||||
-> d3_shader_compile: nós com tipo (número, cor, condição)
|
||||
|-> GLSL "vec3 tb_shade(P, N, base, light, time)"
|
||||
| -> Tb3dRenderer.compile de cada backend disponível:
|
||||
| vk: monta o fragment 450 e gera SPIR-V (libshaderc, dlopen)
|
||||
-> d3_shader_compile: nós com tipo (número, cor, condição) e o estágio
|
||||
("cor do pixel" = fragmento; "mude a posição do vértice" = vértice)
|
||||
|-> GLSL "vec3 tb_shade(P, N, L, UV, base, tex, light, time)" (fragmento)
|
||||
| ou "vec3 tb_vert(P, N, L, UV, base, tex, light, time)" (vértice)
|
||||
| -> Tb3dRenderer.compile de cada backend disponível (com o estágio):
|
||||
| vk: monta o shader 450 e gera SPIR-V (libshaderc, dlopen);
|
||||
| no vértice junta com um fragmento padrão ao desenhar
|
||||
| gl: liga o programa e devolve o binário do driver (glGetProgramBinary)
|
||||
`-> interpretador (o renderizador em software, pixel a pixel)
|
||||
`-> interpretador (o renderizador em software, pixel a pixel,
|
||||
ou vértice a vértice no shader de vértice)
|
||||
= o shader compilado: um bloco-handle (valor), com referências contadas
|
||||
```
|
||||
|
||||
@@ -285,6 +289,20 @@ libshaderc ou com menos de 160 bytes de push constants) fica de fora do
|
||||
quadro que tem objeto com shader. O `test-3d` compara o xadrez e o degradê
|
||||
dos três renderizadores.
|
||||
|
||||
### Texturas e materiais
|
||||
|
||||
Uma textura nasce de um `TinyBlocks_Image` (`crie a textura [nome] da
|
||||
imagem [...]`): a 3d converte para RGBA8 e guarda num cache por nome. Um
|
||||
material junta um albedo, um normal map (relevo por pixel) e uma cor
|
||||
(`tint`) que multiplica o resultado. `use o material [m] no objeto
|
||||
[o]` liga o material ao objeto; a `frame_build` da 3d preenche
|
||||
`Tb3dDraw.albedo`, o `normaltex` e multiplica `Tb3dDraw.color` pelo tint.
|
||||
Os três renderizadores amostram o albedo no `uv` (bilinear, `uv`
|
||||
repetido), e a amostra chega ao shader como o `vec3 tex` (o bloco
|
||||
`textura do pixel`) e ao caminho padrão como `cor_do_objeto * tex`. Com
|
||||
normal map, o frame de tangentes sai do `u/v` no espaço do objeto e a luz
|
||||
passa a ser por pixel nos três renderizadores.
|
||||
|
||||
### O caminho inverso: renderizadores da 3D
|
||||
|
||||
Na `tinyblocks-3d` a direção é a contrária, como no `tinyblocks-graphics`
|
||||
|
||||
@@ -114,13 +114,17 @@ Um rótulo como `%1 encosta em %2?` não é reconhecido na importação
|
||||
de uma palavra (`tecla %1 pressionada?`) funciona. A 3d usa
|
||||
`objeto %1 encosta em %2` (o formato booleano vem do nome da saída).
|
||||
|
||||
### Shaders: só a cor do pixel
|
||||
### Shaders: falta combinar vertice e fragmento
|
||||
|
||||
Os shaders feitos com blocos mudam a cor do pixel (fragment); ainda não há
|
||||
shader de vértice (deformar a malha), texturas nem luz por pixel nos objetos
|
||||
sem shader (estes usam luz por vértice). O binário do OpenGL só vale para
|
||||
a mesma placa e driver (o projeto salvo não guarda binários: o shader é
|
||||
compilado de novo quando o programa roda).
|
||||
Os shaders feitos com blocos mudam a cor do pixel (fragmento) e a posição
|
||||
do vértice (vértice, `mude a posição do vértice`); o estágio sai sozinho do
|
||||
que a pilha usa. Cada objeto usa um shader (não dá para ter um de vértice e
|
||||
um de fragmento no mesmo objeto ao mesmo tempo). Texturas de **albedo** e
|
||||
de **normal map** e materiais já funcionam (textura, cor, o `textura do
|
||||
pixel` nos shaders e o relevo por pixel no caminho padrão). A luz dos
|
||||
objetos sem shader agora é por pixel (antes era por vértice). O binário do
|
||||
OpenGL só vale para a mesma placa e driver (o projeto salvo não guarda
|
||||
binários: o shader é compilado de novo quando o programa roda).
|
||||
|
||||
### Campo de texto de um bloco corta em 63 caracteres
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ Convenções que valem para toda a API:
|
||||
- [`libraries/tinyblocks-curves/include/tb_curves.h`](#librariestinyblocks-curvesincludetb_curvesh)
|
||||
- [`libraries/tinyblocks-editor/include/tb_editor.h`](#librariestinyblocks-editorincludetb_editorh)
|
||||
- [`libraries/tinyblocks-editor/include/tb_editor_internal.h`](#librariestinyblocks-editorincludetb_editor_internalh)
|
||||
- [`libraries/tinyblocks-editor/include/tb_editor_m3.h`](#librariestinyblocks-editorincludetb_editor_m3h)
|
||||
- [`libraries/tinyblocks-editor/include/tb_editor_modules.h`](#librariestinyblocks-editorincludetb_editor_modulesh)
|
||||
- [`libraries/tinyblocks-editor/include/tb_stage_widget.h`](#librariestinyblocks-editorincludetb_stage_widgeth)
|
||||
- [`libraries/tinyblocks-editor/libraries/tinyblocks-editor-files/include/tb_editor_files.h`](#librariestinyblocks-editorlibrariestinyblocks-editor-filesincludetb_editor_filesh)
|
||||
@@ -80,6 +81,7 @@ Convenções que valem para toda a API:
|
||||
- [`libraries/tinyblocks-mcp-server/include/tb_mcp_server.h`](#librariestinyblocks-mcp-serverincludetb_mcp_serverh)
|
||||
- [`libraries/tinyblocks-mcp-server/include/tb_mcp_server_internal.h`](#librariestinyblocks-mcp-serverincludetb_mcp_server_internalh)
|
||||
- [`libraries/tinyblocks-mcp/include/tinyblocks-mcp/tb_mcp.h`](#librariestinyblocks-mcpincludetinyblocks-mcptb_mcph)
|
||||
- [`libraries/tinyblocks-mcp/src/tb_mcp_py.h`](#librariestinyblocks-mcpsrctb_mcp_pyh)
|
||||
- [`libraries/tinyblocks-number/include/tb_number.h`](#librariestinyblocks-numberincludetb_numberh)
|
||||
- [`libraries/tinyblocks-opentype/include/tb_opentype.h`](#librariestinyblocks-opentypeincludetb_opentypeh)
|
||||
- [`libraries/tinyblocks-operators/include/tb_operators.h`](#librariestinyblocks-operatorsincludetb_operatorsh)
|
||||
@@ -90,6 +92,11 @@ Convenções que valem para toda a API:
|
||||
- [`libraries/tinyblocks-png/include/tb_png.h`](#librariestinyblocks-pngincludetb_pngh)
|
||||
- [`libraries/tinyblocks-ppm/include/tb_ppm.h`](#librariestinyblocks-ppmincludetb_ppmh)
|
||||
- [`libraries/tinyblocks-python/include/tinyblocks-python/tb_python.h`](#librariestinyblocks-pythonincludetinyblocks-pythontb_pythonh)
|
||||
- [`libraries/tinyblocks-qr/include/tb_camera.h`](#librariestinyblocks-qrincludetb_camerah)
|
||||
- [`libraries/tinyblocks-qr/include/tb_qr.h`](#librariestinyblocks-qrincludetb_qrh)
|
||||
- [`libraries/tinyblocks-qr/src/qrcodegen.h`](#librariestinyblocks-qrsrcqrcodegenh)
|
||||
- [`libraries/tinyblocks-qr/src/quirc.h`](#librariestinyblocks-qrsrcquirch)
|
||||
- [`libraries/tinyblocks-qr/src/quirc_internal.h`](#librariestinyblocks-qrsrcquirc_internalh)
|
||||
- [`libraries/tinyblocks-regex/include/tb_regex.h`](#librariestinyblocks-regexincludetb_regexh)
|
||||
- [`libraries/tinyblocks-scratchblocks/include/tb_scratchblocks.h`](#librariestinyblocks-scratchblocksincludetb_scratchblocksh)
|
||||
- [`libraries/tinyblocks-sdl2/include/tb_sdl2.h`](#librariestinyblocks-sdl2includetb_sdl2h)
|
||||
@@ -694,6 +701,16 @@ Uso típico:
|
||||
| `void tb_draw_set_clip (TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h)` | Recorte: só desenha dentro do retângulo (coordenadas da tela). |
|
||||
| `void tb_draw_clear_clip (TinyBlocks_RenderableBlock* rb)` | Tira o recorte. |
|
||||
| `void tb_draw_text (TinyBlocks_RenderableBlock* rb, float x, float y, const char* text, float font_size, float r, float g, float b, float a)` | Texto com a linha de base em (x, y) e tamanho `font_size` em px. |
|
||||
| `#define TB_FONT_REGULAR` = `0` | Roboto Regular |
|
||||
| `#define TB_FONT_MEDIUM` = `1` | Roboto Medium (rotulos, titulos) |
|
||||
| `#define TB_FONT_ICON` = `2` | Material Symbols Outlined |
|
||||
| `#define TB_FONT_ICON_FILLED` = `3` | Material Symbols (preenchido) |
|
||||
| `#define TB_FONT_COUNT` = `4` | |
|
||||
| `#define TB_POLY_MAX` = `16` | Poligono convexo (ate TB_POLY_MAX pontos; xy = x0,y0,x1,y1,...). Formas inclinadas (hexagono, encaixe) ficam lisas em qualquer escala. |
|
||||
| `void tb_draw_fill_poly (TinyBlocks_RenderableBlock* rb, const float* xy, int n, float r, float g, float b, float a)` | |
|
||||
| `int tb_draw_poly_get (const TinyBlocks_DrawCmd* c, float* xy)` | Pontos de um TB_DRAW_FILL_POLY (quem transforma comandos usa os dois) |
|
||||
| `void tb_draw_poly_set (TinyBlocks_DrawCmd* c, const float* xy, int n)` | |
|
||||
| `void tb_draw_text_font (TinyBlocks_RenderableBlock* rb, float x, float y, const char* text, float font_size, int font, float r, float g, float b, float a)` | |
|
||||
| `void tb_draw_image (TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, const TinyBlocks_Image* image)` | Desenha a imagem escalada para o retângulo (x,y,w,h). A imagem é ref-counted; o comando apenas guarda um ponteiro não-owning, portanto a imagem precisa continuar viva até o backend renderizar o frame. |
|
||||
| `void tb_draw_merge_offset(TinyBlocks_RenderableBlock* dst, const TinyBlocks_RenderableBlock* src, float dx, float dy)` | Mescla src em dst deslocando todas as coordenadas por (dx, dy). Usado pelo editor para incorporar sub-renderables de blocos com on_draw. |
|
||||
| `float tb_measure_text(const char* text, float font_size)` | Estimativa de largura de texto (independente de fonte real). Precisa ser substituída por medição real pelo backend quando disponível. |
|
||||
@@ -1017,6 +1034,13 @@ Fluxo de uso mínimo:
|
||||
| `bool tinyblocks_init (TinyBlocks** out_rt, const TinyBlocks_InitOptions* opts)` | Cria o runtime em `*out_rt`. `opts` NULL = alocador `malloc` e capacidades padrão. |
|
||||
| `void tinyblocks_deinit(TinyBlocks** rt)` | Destrói tudo em três fases (instâncias, libraries, órfãos), fecha os `dlopen` e zera `*rt`. |
|
||||
|
||||
### Caminhos de arquivo
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `void tb_path_set_base(const char* dir)` | O aplicativo (ex.: o editor) define o diretorio-base do projeto aberto; os blocos que abrem arquivos resolvem caminhos relativos contra ele, para que um caminho como "atlas.png" ache o arquivo na pasta do projeto mesmo quando o processo roda de outro diretorio (ex.: AppImage aberto pelo menu). |
|
||||
| `const char* tb_path_resolve(const char* path, char* out, size_t out_n)` | |
|
||||
|
||||
### Registro interno (usado pelas implementações de bloco)
|
||||
|
||||
| Declaração | Descrição |
|
||||
@@ -1093,11 +1117,14 @@ OpenGL (clip z em -1..1, y para cima); o Vulkan ajusta por conta propria.
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `#define TB_3D_LIB` = `"tinyblocks-3d"` | TinyBlocks - tb_3d.h Library tinyblocks-3d: uma cena 3D simples feita de blocos (categoria "3D") e o CONTRATO dos renderizadores. A cena tem objetos com nome (cubo, esfera, plano, cilindro), cada um com posicao, rotacao, escala e cor; uma camera; uma luz direcional. O bloco "imagem da cena" desenha tudo numa imagem RGBA, que vai para o palco com "desenhe (imagem da cena ...)". Quem desenha e um Tb3dRenderer. A propria 3d traz um rasterizador em software (sempre disponivel); tinyblocks-vk (Vulkan) e tinyblocks-gl (OpenGL) publicam o deles no lib_userdata, e a 3d procura pelo nome da library no runtime a cada quadro (sem linkar com elas): lib = tb_rt_find_library(rt, "tinyblocks-vk"); const Tb3dRenderer* r = lib ? lib->lib_userdata : NULL; if (r && r->version == TB_3D_RENDERER_VERSION && r->available()) ... A ordem automatica e Vulkan, OpenGL, software ("use o renderizador ..." escolhe um). As matrizes sao 4x4 em colunas (column-major) na convencao do OpenGL (clip z em -1..1, y para cima); o Vulkan ajusta por conta propria. |
|
||||
| `#define TB_3D_RENDERER_VERSION` = `3` | Versão do contrato Tb3dRenderer (quem publica confere). |
|
||||
| tipo `struct Tb3dMesh` | Malha: triangulos com posicao e normal (6 floats por vertice). As malhas da cena sao fixas (cubo, esfera, plano e cilindro de tamanho 1): o renderizador pode guarda-las na GPU pelo id. |
|
||||
| `#define TB_3D_MAX_BINARIES` = `4` | Shader compilado: o valor que o repórter "compile o shader [pilha]" devolve (um bloco-handle; guarde numa variável) e que "use o shader" põe num objeto. A 3d compila os blocos para o corpo de uma funcao GLSL (330 e 450) e pede a cada renderizador disponivel o BINARIO dele (Tb3dRenderer.compile); o formato do binario so o renderizador conhece. vec3 tb_shade(vec3 P, vec3 N, vec3 base, float light, float time) P = ponto no mundo, N = normal (normalizada), base = cor do objeto, light = ambiente + (1 - ambiente) * max(N . luz, 0), time = segundos; devolve a cor do pixel (0..1). id e unico por compilacao (o renderizador guarda o programa da placa por ele) e vale enquanto alguem usar o shader. |
|
||||
| `#define TB_3D_RENDERER_VERSION` = `8` | Versão do contrato Tb3dRenderer (quem publica confere). |
|
||||
| tipo `struct Tb3dMesh` | Malha: triangulos com posicao, normal e uv (8 floats por vertice). Alem das malhas fixas (cubo, esfera, plano e cilindro de tamanho 1), o usuario monta malhas personalizadas com os blocos "crie a malha", "adicione o vertice/a normal/a texcoord" e "finalize a malha". O renderizador guarda a malha na GPU pelo id; quando o version muda, ele sobe de novo. |
|
||||
| `#define TB_3D_STAGE_FRAGMENT` = `0` | Shader compilado: o valor que o repórter "compile o shader [pilha]" devolve (um bloco-handle; guarde numa variável) e que "use o shader" põe num objeto. A pilha é de VÉRTICE ou de FRAGMENTO, e o "compile o shader" descobre sozinho pelo que a pilha usa: vec3 tb_shade(vec3 P, vec3 N, vec3 L, vec2 UV, vec3 base, vec3 tex, float light, float time) vec3 tb_vert (vec3 P, vec3 N, vec3 L, vec2 UV, vec3 base, vec3 tex, float light, float time) No fragmento (estágio 0) P/N são o ponto e a normal no mundo e o shader devolve a COR do pixel (0..1); no vértice (estágio 1) P/N são a posição e a normal no espaço do objeto e o shader devolve a POSIÇÃO do vértice (ainda no espaço do objeto: a câmera e o mova/gire aplicam por cima). tex é a textura de albedo amostrada no UV (branco se o objeto não tem material com textura) - o bloco "textura do pixel" devolve isto. A 3d compila os blocos para o corpo da função GLSL (330 e 450) e pede a cada renderizador disponível o BINÁRIO dele (Tb3dRenderer.compile). light = ambiente + (1 - ambiente) * max(N . luz, 0); time = segundos. id e unico por compilacao (o renderizador guarda o programa da placa por ele) e vale enquanto alguem usar o shader. |
|
||||
| `#define TB_3D_STAGE_VERTEX` = `1` | |
|
||||
| `#define TB_3D_MAX_BINARIES` = `4` | Quantos binários (renderizadores) um shader compilado guarda. |
|
||||
| tipo `struct Tb3dBinary` | Binário de um shader para um renderizador (nome dele, dados com malloc, tamanho); o formato só o renderizador conhece. |
|
||||
| tipo `struct Tb3dShader` | Shader compilado (o valor de "compile o shader"): id único, a função GLSL tb_shade e os binários de cada renderizador. |
|
||||
| tipo `struct Tb3dTexture` | Textura: uma imagem RGBA8 (linha 0 no ALTO), a mesma em todos os renderizadores. O id e estavel; o version muda quando os pixels mudam (o renderizador sobe de novo para a GPU). |
|
||||
| tipo `struct Tb3dDraw` | Um objeto a desenhar |
|
||||
| tipo `struct Tb3dFrame` | Um quadro: tudo o que o renderizador precisa |
|
||||
| tipo `struct Tb3dRenderer` | Renderizador. render escreve width*height*4 bytes RGBA, linha 0 no ALTO. |
|
||||
@@ -1125,9 +1152,11 @@ compilador de shaders (d3_shader.c) e quem o usa (tb_3d.c).
|
||||
| tipo `struct D3Program` | TinyBlocks - d3_internal.h Partes internas da tinyblocks-3d compartilhadas entre os fontes: o compilador de shaders (d3_shader.c) e quem o usa (tb_3d.c). o shader compilado (opaco) |
|
||||
| `D3Program* d3_shader_compile(const TinyBlocks_JsonValue* stack, char* err, size_t cap)` | Compila a pilha (o codigo de um encaixe TB_SLOT_STACK, em JSON). NULL em erro, com a mensagem em err. |
|
||||
| `void d3_shader_free(D3Program* p)` | Libera o shader compilado. |
|
||||
| `const char* d3_shader_glsl(const D3Program* p)` | a funcao tb_shade |
|
||||
| tipo `struct D3Pixel` | Entradas de um pixel e a cor que sai (o interpretador do software) |
|
||||
| `const char* d3_shader_glsl(const D3Program* p)` | tb_shade ou tb_vert |
|
||||
| `int d3_shader_stage(const D3Program* p)` | D3_STAGE_* |
|
||||
| tipo `struct D3Pixel` | Entradas de um pixel/vertice e a cor que sai (interpretador do software). No fragmento P/N sao o ponto e a normal no mundo; no vertice, P e a posicao local (a que o shader de vertice devolve) e N a normal do objeto. |
|
||||
| `void d3_shader_run(const D3Program* p, const D3Pixel* in, float out[3])` | Interpreta o shader para um pixel (renderizador em software). |
|
||||
| `void d3_shader_run_vertex(const D3Program* p, const D3Pixel* in, float out[3])` | |
|
||||
| `bool d3_color_of(const char* name, float out[4])` | Cores por nome (vermelho, azul, dourado...) ou #rrggbb |
|
||||
|
||||
## libraries/tinyblocks-a11y/include/tb_a11y.h
|
||||
@@ -1219,6 +1248,7 @@ nome + ordem entre irmaos iguais), entao foco e selecao podem ser seguidos.
|
||||
| `void tb_a11y_set_name (TinyBlocks_A11yTree* tree, int node, const char* name)` | Troca o nome do nó. |
|
||||
| `void tb_a11y_set_key (TinyBlocks_A11yTree* tree, int node, const char* key)` | Chave estavel para o id quando o nome muda com o conteudo (ex.: um bloco "repita (10) vezes" usa o tipo como chave). Chame antes dos filhos. |
|
||||
| `void tb_a11y_set_point (TinyBlocks_A11yTree* tree, int node, float x, float y)` | Ponto onde as acoes agem (o centro pode cair num filho) |
|
||||
| `void tb_a11y_scale_from (TinyBlocks_A11yTree* tree, int first, float ox, float oy, float s)` | Escala os nos a partir de `first` (ate o ultimo criado) em torno de (ox, oy): conteudo desenhado com zoom (ex.: a area de scripts) |
|
||||
| `void tb_a11y_announce(TinyBlocks_A11yTree* tree, const char* text)` | Aviso para o narrador ler (mensagens de status, erros) |
|
||||
|
||||
### Consulta
|
||||
@@ -1609,6 +1639,8 @@ Uso:
|
||||
| `void tb_editor_preload(const char* path)` | Enfileira um .so para ser carregado automaticamente ao abrir o editor |
|
||||
| tipo `struct TinyBlocks_A11yTree` | Interface de acessibilidade (tb_a11y.h, da tinyblocks-a11y): a arvore acessivel do ultimo quadro desenhado do bloco "Editor.Scene". Serve ao narrador (tb_a11y_set_bridge) e aos testes (tb_a11y_find + do_action). NULL se a acessibilidade estiver desligada (TINYBLOCKS_A11Y=0). |
|
||||
| `TinyBlocks_A11yTree* tb_editor_accessible(TinyBlocks_Block* scene)` | A árvore acessível do último quadro desenhado pela cena (NULL se desligada). |
|
||||
| `void tb_editor_qr_feed(TinyBlocks_Block* scene, const char* text)` | Para testes: entrega ao leitor de QR aberto um texto como se a camera o tivesse lido ("Receber blocos") |
|
||||
| `void tb_editor_qr_show_part(TinyBlocks_Block* scene, int i)` | Para testes: o painel "Compartilhar" mostra a parte i (0..n-1) em vez do loop de 1 s; -1 volta ao loop |
|
||||
| `struct TbMcpServer* tb_editor_mcp_server(TinyBlocks_Block* scene)` | O servidor MCP do editor dessa cena. |
|
||||
|
||||
## libraries/tinyblocks-editor/include/tb_editor_internal.h
|
||||
@@ -1639,6 +1671,7 @@ vem juntas com o editor e podem compartilhar este cabecalho.
|
||||
| `#define FLY_BTN_W` = `150` | Geometria do layout do editor (px). |
|
||||
| `#define PALETTE_W` = `(CAT_W + FLY_W)` | largura padrao da paleta |
|
||||
| `#define STAGE_W` = `360` | largura padrao da coluna do palco |
|
||||
| `#define STAGE_TOP` = `(STAGE_BAR_H + 4)` | onde a vista do palco comeca |
|
||||
| `#define WIN_W` = `(ed->win_w)` | Geometria do layout do editor (px). |
|
||||
| `#define AREA(v)` = `(ed->area[(v)])` | Retangulo de cada view, calculado a cada quadro pela arvore de areas (lay_compute em tb_editor.c). As views podem mudar de lugar e tamanho. |
|
||||
| `#define PAL_X` = `(AREA(V_PALETTE).x)` | Geometria do layout do editor (px). |
|
||||
@@ -1654,7 +1687,7 @@ vem juntas com o editor e podem compartilhar este cabecalho.
|
||||
| `#define TAB_W_MIN` = `84` | Largura mínima de uma aba (abaixo disso a barra rola). |
|
||||
| `#define TAB_W` = `(tab_width(ed))` | Geometria do layout do editor (px). |
|
||||
| `#define PLUS_W` = `28` | Geometria do layout do editor (px). |
|
||||
| `#define PLUS_MENU_W` = `208` | Menu do botao "+" (nova aba) |
|
||||
| `#define PLUS_MENU_W` = `260` | Menu do botao "+" (nova aba) |
|
||||
| `#define PLUS_MENU_N` = `4` | Itens do menu "+" (nova aba). |
|
||||
| `#define CODE_FS` = `13` | Editor de codigo (aba de codigo) |
|
||||
| `#define CODE_GUTTER_W` = `46` | Geometria do layout do editor (px). |
|
||||
@@ -1666,9 +1699,9 @@ vem juntas com o editor e podem compartilhar este cabecalho.
|
||||
| tipo `struct ImgLayer` | Camada do documento de imagem (rasterizada; SVG entra como vetor) |
|
||||
| tipo `struct ImgSel` | Selecao da ferramenta "selecionar" (mover/redimensionar pixels) |
|
||||
| tipo `struct MenuBtn` | Botão da barra de menu (o que não cabe vai para o menu de três traços). |
|
||||
| `#define MENU_BTN_Y` = `7` | Geometria do layout do editor (px). |
|
||||
| `#define MENU_BTN_Y` = `((MENU_H - MENU_BTN_H) / 2)` | Geometria do layout do editor (px). |
|
||||
| `#define MENU_MORE_W` = `40` | Geometria do layout do editor (px). |
|
||||
| `#define COMPACT_W` = `1000` | Modo compacto (janela estreita / celular): uma area de cada vez. Scripts em tela cheia com a paleta em gaveta, ou palco sobre a saida. |
|
||||
| `#define COMPACT_W` = `1000` | abaixo disso (janela estreita) uma area de cada vez |
|
||||
| `#define LAY_NARROW_W` = `1100` | abaixo disso os lados fixos (paleta, palco) ficam <= 40% |
|
||||
|
||||
### Geometria dos blocos
|
||||
@@ -1703,13 +1736,13 @@ vem juntas com o editor e podem compartilhar este cabecalho.
|
||||
| `#define MAX_TABS` = `8` | Abas por projeto. |
|
||||
| `#define MAX_GROUPS` = `32` | Grupos por aba. |
|
||||
| `#define GRP_GRIP` = `16` | canto de baixo a direita: redimensionar |
|
||||
| `#define MAX_CATS` = `24` | Categorias. |
|
||||
| `#define MAX_CATS` = `64` | Categorias. |
|
||||
| `#define MAX_CALL_DEPTH` = `32` | Profundidade de chamadas de Meus Blocos. |
|
||||
| `#define MAX_RUN_BLOCKS` = `200000` | Instâncias do runtime numa execução. |
|
||||
| `#define STAGE_BUF` = `16384` | Tamanho do texto da saída (console). |
|
||||
| `#define LIT_TEXT_CAP` = `512` | Texto de um literal. |
|
||||
| `#define MAX_HOT_TYPES` = `64` | Tipos lembrados no hot reload. |
|
||||
| `#define MAX_USER_BLOCKS` = `16` | Blocos do usuário. |
|
||||
| `#define MAX_USER_BLOCKS` = `8192` | Blocos do usuário. |
|
||||
| `#define MAX_UBLK_SLOTS` = `8` | Entradas/saídas de um bloco do usuário. |
|
||||
| `#define MAX_UBLK_PARTS` = `16` | Partes do protótipo. |
|
||||
|
||||
@@ -1745,10 +1778,13 @@ vem juntas com o editor e podem compartilhar este cabecalho.
|
||||
| `#define REL_ARG0` = `4` | REL_ARG0 + i: campo de entrada i |
|
||||
| `#define MAX_MOUTHS` = `3` | bocas de um bloco C (tente/se der erro/finalmente) |
|
||||
| tipo `struct Part` | Pedaço do rótulo medido: texto ou campo, posição e largura. |
|
||||
| tipo `struct ScrollAnim` | Rolagem animada: de `from` a `to` a partir de t0 (curva standard do M3) |
|
||||
| `#define GHOST_MAX` = `8` | Bloco apagado saindo de cena: os comandos de desenho dele (na tela) |
|
||||
| tipo `struct Ghost` | |
|
||||
| tipo `struct EdBlock` | Bloco no editor: tipo, posição, vínculos por índice, textos dos campos, layout do quadro e caches do executor. |
|
||||
| tipo `struct CodeTok` | Um trecho colorido do editor de codigo (vindo do tinyblocks-syntax). |
|
||||
| tipo `struct Tab` | Aba: pool de blocos, pilhas, rolagem, tipo (blocos, código, imagem) e o estado de cada tipo. |
|
||||
| tipo `enum ParamKind` | Parte do protótipo: número/texto, booleano ou rótulo. |
|
||||
| tipo `enum ParamKind` | PARAM_NAME marca onde o nome do bloco aparece; sem ela, o nome vai na frente |
|
||||
| tipo `struct UserParam` | Parte do protótipo (kind + nome). |
|
||||
| tipo `struct UserBlockDef` | Definição de um bloco do usuário: nome, entradas, saídas, partes, cópia do corpo, tipo registrado, aba e cor. |
|
||||
| tipo `struct CallFrame` | Chamada em andamento de um bloco do usuário: definição, entradas e saídas. |
|
||||
@@ -1780,8 +1816,12 @@ vem juntas com o editor e podem compartilhar este cabecalho.
|
||||
| `#define CT` = `(ed->tabs[ed->cur_tab])` | A aba atual (`ed->tabs[ed->cur_tab]`). |
|
||||
| `void bubble_clear(Ed* ed)` | Fecha o balão de resultado de um repórter. |
|
||||
| `void palette_rebuild(Ed* ed)` | Refaz as categorias e o flyout (libraries novas, variáveis novas). |
|
||||
| `void ghost_capture(Ed* ed, Tab* T, int bi, bool chain, float wsx, float wsy, bool clip)` | Bloco (ou a pilha a partir dele) saindo de cena: fantasma animado |
|
||||
| `void utf8_pop(char* s)` | Apaga a última letra UTF-8 do texto. |
|
||||
| `void append_text(char* dst, size_t cap, const char* add)` | Acrescenta texto respeitando a capacidade. |
|
||||
| `bool te_key(Ed* ed, char* buf, size_t cap, int sc, bool multi)` | Campo de texto em edicao (cursor, selecao, Ctrl+A/C/X/V): as teclas e o texto vao para te_key/te_insert e quem desenha chama te_draw depois do texto (x = inicio do texto, cy = centro da 1a linha, lh = altura da linha) |
|
||||
| `void te_insert(Ed* ed, char* buf, size_t cap, const char* s, bool multi)` | |
|
||||
| `void te_draw(Ed* ed, TinyBlocks_RenderableBlock* rb, char* buf, size_t cap, bool multi, float x, float cy, float lh, float fs, Col caret)` | |
|
||||
| `void dlg_open(Ed* ed, int def_idx)` | Abre o diálogo "Criar um Bloco" (`def_idx` -1 = novo) ou "Editar Bloco". |
|
||||
| `void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb)` | Desenha o diálogo de bloco. |
|
||||
| `bool dlg_click(Ed* ed, float mx, float my)` | Clique no diálogo de bloco. |
|
||||
@@ -1893,6 +1933,201 @@ vem juntas com o editor e podem compartilhar este cabecalho.
|
||||
| `void settings_scroll_by(Ed* ed, float dy)` | Rola as configurações. |
|
||||
| `void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb)` | Desenha as configurações. |
|
||||
|
||||
## libraries/tinyblocks-editor/include/tb_editor_m3.h
|
||||
|
||||
```text
|
||||
Linguagem visual do editor: Material 3 (m3.material.io) com as cores que o
|
||||
editor ja usava. Papeis de cor do M3 apontam para a paleta do TinyBlocks;
|
||||
formas, tipografia (Roboto), icones (Material Symbols), camadas de estado
|
||||
e elevacao seguem o M3. Densidade -2 do M3 (desktop): alturas 4 px menores.
|
||||
Incluido por tb_editor_internal.h (usa Col, C(), COLA() e rb_*).
|
||||
```
|
||||
|
||||
### Papeis de cor (M3) -> paleta do editor
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `#define M3_PRIMARY` = `COL_MENU` | #4C97FF |
|
||||
| `#define M3_ON_PRIMARY` = `COL_WHITE` | |
|
||||
| `#define M3_PRIMARY_DARK` = `COL_MENU_DARK` | |
|
||||
| `#define M3_PRIMARY_CONTAINER` = `COL_HOVER` | #D6E4F8 |
|
||||
| `#define M3_SECONDARY_CONTAINER` = `COL_TAB_OFF` | #D9E3F2 |
|
||||
| `#define M3_SURFACE` = `COL_PANEL` | branco |
|
||||
| `#define M3_SURFACE_LOW` = `COL_FLY` | #F9F9F9 |
|
||||
| `#define M3_SURFACE_CONTAINER` = `COL_UI_BG` | #E5F0FF |
|
||||
| `#define M3_ON_SURFACE` = `COL_TEXT` | #575E75 |
|
||||
| `#define M3_ON_SURFACE_VAR` = `COL_TEXT_DIM` | |
|
||||
| `#define M3_OUTLINE` = `COL_TEXT_DIM` | |
|
||||
| `#define M3_OUTLINE_VAR` = `COL_BORDER` | |
|
||||
| `#define M3_INVERSE_SURFACE` = `COL_TIP_BG` | |
|
||||
| `#define M3_INVERSE_ON_SURFACE` = `COL_CODE_TEXT` | |
|
||||
| `#define M3_INVERSE_PRIMARY` = `COL_TIP_LINK` | |
|
||||
| `#define M3_ERROR` = `COL_STOP` | |
|
||||
|
||||
### Formas (raio dos cantos)
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `#define M3_SHAPE_XS` = `4.f` | |
|
||||
| `#define M3_SHAPE_S` = `8.f` | |
|
||||
| `#define M3_SHAPE_M` = `12.f` | |
|
||||
| `#define M3_SHAPE_L` = `16.f` | |
|
||||
| `#define M3_SHAPE_XL` = `28.f` | |
|
||||
|
||||
### Tipografia (tamanho em px; titulos e rotulos em Roboto Medium)
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `#define M3_HEADLINE_S` = `24.f` | |
|
||||
| `#define M3_TITLE_L` = `22.f` | |
|
||||
| `#define M3_TITLE_M` = `16.f` | |
|
||||
| `#define M3_TITLE_S` = `14.f` | |
|
||||
| `#define M3_LABEL_L` = `14.f` | |
|
||||
| `#define M3_LABEL_M` = `12.f` | |
|
||||
| `#define M3_LABEL_S` = `11.f` | |
|
||||
| `#define M3_BODY_L` = `16.f` | |
|
||||
| `#define M3_BODY_M` = `14.f` | |
|
||||
| `#define M3_BODY_S` = `12.f` | |
|
||||
|
||||
### Camadas de estado (opacidade da cor do conteudo)
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `#define M3_HOVER` = `0.08f` | |
|
||||
| `#define M3_PRESSED` = `0.10f` | |
|
||||
| `#define M3_DRAGGED` = `0.16f` | |
|
||||
|
||||
### Componentes: alturas (densidade -2)
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `#define M3_ICON_BTN` = `36.f` | icon button: alvo (40 no padrao) |
|
||||
| `#define M3_ICON` = `20.f` | icone dentro de botoes |
|
||||
| `#define M3_MENU_ITEM` = `40.f` | item de menu (48 no padrao) |
|
||||
|
||||
### Icones (Material Symbols, codepoints)
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `#define MI_ADD` = `0xe145` | |
|
||||
| `#define MI_ARROW_BACK` = `0xe5c4` | |
|
||||
| `#define MI_ARROW_FORWARD` = `0xe5c8` | |
|
||||
| `#define MI_ARROW_UPWARD` = `0xe5d8` | |
|
||||
| `#define MI_ARROW_RIGHT` = `0xe5df` | |
|
||||
| `#define MI_BRUSH` = `0xe3ae` | |
|
||||
| `#define MI_CANCEL` = `0xe888` | |
|
||||
| `#define MI_CHECK` = `0xe668` | |
|
||||
| `#define MI_CHECK_CIRCLE` = `0xf0be` | |
|
||||
| `#define MI_CHEVRON_LEFT` = `0xe5cb` | |
|
||||
| `#define MI_CHEVRON_RIGHT` = `0xe5cc` | |
|
||||
| `#define MI_CIRCLE` = `0xef4a` | |
|
||||
| `#define MI_CLOSE` = `0xe5cd` | |
|
||||
| `#define MI_CODE` = `0xe86f` | |
|
||||
| `#define MI_COLORIZE` = `0xe3b8` | |
|
||||
| `#define MI_CONTENT_COPY` = `0xe14d` | |
|
||||
| `#define MI_CONTENT_CUT` = `0xe14e` | |
|
||||
| `#define MI_CONTENT_PASTE` = `0xe14f` | |
|
||||
| `#define MI_CREATE_FOLDER` = `0xe2cc` | |
|
||||
| `#define MI_DELETE` = `0xe92e` | |
|
||||
| `#define MI_DESCRIPTION` = `0xe873` | |
|
||||
| `#define MI_DRAFT` = `0xe66d` | |
|
||||
| `#define MI_DRAG_INDICATOR` = `0xe945` | |
|
||||
| `#define MI_EDIT` = `0xf097` | |
|
||||
| `#define MI_ERROR` = `0xf8b6` | |
|
||||
| `#define MI_EXPAND_MORE` = `0xe5cf` | |
|
||||
| `#define MI_EXTENSION` = `0xe87b` | |
|
||||
| `#define MI_FILL` = `0xe23a` | |
|
||||
| `#define MI_FLAG` = `0xf0c6` | |
|
||||
| `#define MI_FOLDER` = `0xe2c7` | |
|
||||
| `#define MI_GRID_VIEW` = `0xe9b0` | |
|
||||
| `#define MI_DATA_OBJECT` = `0xead3` | |
|
||||
| `#define MI_TABLE` = `0xf191` | |
|
||||
| `#define MI_ACCOUNT_TREE` = `0xe97a` | |
|
||||
| `#define MI_SELECT_ALL` = `0xe162` | |
|
||||
| `#define MI_ADD_BOX` = `0xe146` | |
|
||||
| `#define MI_FOLDER_OPEN` = `0xe2c8` | |
|
||||
| `#define MI_HOME` = `0xe9b2` | |
|
||||
| `#define MI_IMAGE` = `0xe3f4` | |
|
||||
| `#define MI_INFO` = `0xe88e` | |
|
||||
| `#define MI_ERASER` = `0xe6d0` | |
|
||||
| `#define MI_IOS_SHARE` = `0xe6b8` | |
|
||||
| `#define MI_LIBRARY_ADD` = `0xe03c` | |
|
||||
| `#define MI_LIBRARY_BOOKS` = `0xe02f` | |
|
||||
| `#define MI_MENU` = `0xe5d2` | |
|
||||
| `#define MI_MORE_VERT` = `0xe5d4` | |
|
||||
| `#define MI_OPEN_IN_NEW` = `0xe89e` | |
|
||||
| `#define MI_CLOSE_FULLSCR` = `0xf1cf` | |
|
||||
| `#define MI_PALETTE` = `0xe40a` | |
|
||||
| `#define MI_PAN_TOOL` = `0xe925` | |
|
||||
| `#define MI_PLAY_ARROW` = `0xe037` | |
|
||||
| `#define MI_RECTANGLE` = `0xeb54` | |
|
||||
| `#define MI_REDO` = `0xe15a` | |
|
||||
| `#define MI_REFRESH` = `0xe5d5` | |
|
||||
| `#define MI_SAVE` = `0xe161` | |
|
||||
| `#define MI_SEARCH` = `0xef7a` | |
|
||||
| `#define MI_SHARE` = `0xe80d` | |
|
||||
| `#define MI_QR_CODE` = `0xe00a` | |
|
||||
| `#define MI_QR_SCANNER` = `0xf206` | |
|
||||
| `#define MI_SOURCE` = `0xf1c8` | |
|
||||
| `#define MI_SELECT` = `0xf74d` | |
|
||||
| `#define MI_SETTINGS` = `0xe8b8` | |
|
||||
| `#define MI_STOP` = `0xe047` | |
|
||||
| `#define MI_STOP_CIRCLE` = `0xef71` | |
|
||||
| `#define MI_SWAP_HORIZ` = `0xe8d4` | |
|
||||
| `#define MI_TERMINAL` = `0xeb8e` | |
|
||||
| `#define MI_TEXT_FIELDS` = `0xe262` | |
|
||||
| `#define MI_UNDO` = `0xe166` | |
|
||||
| `#define MI_UPLOAD_FILE` = `0xe9fc` | |
|
||||
| `#define MI_WARNING` = `0xf083` | |
|
||||
| `#define MI_WIDGETS` = `0xe1bd` | |
|
||||
| `#define MI_ZOOM_IN` = `0xe8ff` | |
|
||||
| `#define MI_ZOOM_OUT` = `0xe900` | |
|
||||
|
||||
### Movimento: curvas do M3 (cubic-bezier, como no CSS)
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `static inline float m3_bezier(float x1, float y1, float x2, float y2, float t) { if (t <= 0.f) return 0.f` | |
|
||||
| `#define M3_EASE_STANDARD(t)` = `m3_bezier(0.2f, 0.f, 0.f, 1.f, (t))` | |
|
||||
| `#define M3_EASE_EMPH_DECEL(t)` = `m3_bezier(0.05f, 0.7f, 0.1f, 1.f, (t))` | entrar |
|
||||
| `#define M3_EASE_EMPH_ACCEL(t)` = `m3_bezier(0.3f, 0.f, 0.8f, 0.15f, (t))` | sair |
|
||||
| `#define M3_DUR_SCROLL` = `260u` | ms |
|
||||
| `#define M3_DUR_SLIDE` = `280u` | |
|
||||
| `#define M3_DUR_APPEAR` = `380u` | |
|
||||
| `#define M3_DUR_EXIT` = `220u` | |
|
||||
|
||||
### Utilitarios
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `static inline Col m3_alpha(Col c, float a) { c.a = a; return c; }` | |
|
||||
| `static inline Col m3_mix(Col bg, Col c, float a) { Col r = { bg.r + (c.r - bg.r) * a, bg.g + (c.g - bg.g) * a, bg.b + (c.b - bg.b) * a, 1.f }` | c sobre o fundo bg com opacidade a (cor solida resultante) |
|
||||
| `static inline float m3_tw_m(const char* s, float fs) { return tw(s, fs) * 1.04f; }` | Largura de um rotulo em Roboto Medium (a medicao do backend e da Regular) |
|
||||
| `static inline void m3_state(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, Col on, bool hover, bool pressed) { float a = pressed ? M3_PRESSED : hover ? M3_HOVER : 0.f` | Camada de estado: a cor do conteudo, translucida, sobre o componente |
|
||||
|
||||
### Botoes (pilula): filled, tonal, outlined, text
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `static inline float m3_button_w(const char* label, unsigned icon) { return m3_tw_m(label, M3_LABEL_L) + (icon ? 16.f + 18.f + 8.f + 24.f : 48.f)` | |
|
||||
| `static inline void m3_button(TinyBlocks_RenderableBlock* rb, int kind, float x, float y, float w, float h, const char* label, unsigned icon, Col accent, bool hover, bool pressed) { float r = h * 0.5f` | accent = cor do papel "primary" deste botao (a do editor ou a do dialogo) |
|
||||
| `static inline void m3_icon_button(TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned icon, Col c, bool hover, bool selected) { float s = M3_ICON_BTN` | Icon button (padrao): so o icone; o circulo aparece no hover/pressionado. selected = toggle ligado (container tonal) |
|
||||
|
||||
### Superficies
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `static inline void m3_menu_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) { rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 2)` | Menu: canto XS, elevacao 2 |
|
||||
| `static inline void m3_menu_item(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, const char* label, unsigned icon, bool hover, Col fg) { m3_state(rb, x, y, w, h, 0, M3_ON_SURFACE, hover, false)` | Item de menu: icone opcional a esquerda, rotulo Label Large |
|
||||
| `static inline void m3_dialog_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) { rb_shadow(rb, x, y, w, h, M3_SHAPE_XL, 3)` | Dialogo: canto XL, elevacao 3 |
|
||||
| `static inline void m3_scrim(TinyBlocks_RenderableBlock* rb, float w, float h) { rb_fill_rect(rb, 0, 0, w, h, COLA(0, 0, 0, 82))` | Scrim atras de dialogos modais |
|
||||
| `static inline void m3_field(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, bool focused, Col accent) { if (focused) { rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, accent)` | Campo de texto "outlined": canto XS, contorno 1 px (2 px na cor primaria quando em foco) |
|
||||
| `static inline void m3_search_bar(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, bool focused, Col accent) { rb_fill_rrect(rb, x, y, w, h, h * 0.5f, M3_SURFACE_CONTAINER)` | Barra de busca: pilula, icone de lupa a esquerda |
|
||||
| `static inline void m3_tab_indicator(TinyBlocks_RenderableBlock* rb, float x, float y_bottom, float w, Col c) { rb_fill_rrect(rb, x, y_bottom - 3.f, w, 6.f, 3.f, c)` | Indicador da aba ativa (aba primaria): 3 px com cantos de cima redondos |
|
||||
| `static inline void m3_chip(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, const char* label, unsigned icon, bool selected, bool hover) { if (selected) rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_S, M3_SECONDARY_CONTAINER)` | Chip (assist/filter): canto S, 32 px |
|
||||
| `static inline void m3_snackbar_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) { rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 3)` | Snackbar: superficie inversa, canto XS, elevacao 3 |
|
||||
| `static inline void m3_switch(TinyBlocks_RenderableBlock* rb, float x, float y, bool on, Col accent) { const float w = 52.f, h = 32.f` | Interruptor (switch) do M3: trilho 52x32, alca 16 (24 ligado) |
|
||||
|
||||
## libraries/tinyblocks-editor/include/tb_editor_modules.h
|
||||
|
||||
**Privado**: compile com `-DTB_EDITOR_PRIVATE_API`.
|
||||
@@ -2106,7 +2341,8 @@ Uso típico (host):
|
||||
| `#define GFX_IN_MOUSE_IN` = `25` | int: 1 se o mouse está sobre esta janela |
|
||||
| `#define GFX_IN_GMOUSE_X` = `26` | real: mouse na tela (global), x |
|
||||
| `#define GFX_IN_GMOUSE_Y` = `27` | real: mouse na tela (global), y |
|
||||
| `#define GFX_IN_COUNT` = `28` | Saídas do bloco `Graphics.Input`. |
|
||||
| `#define GFX_IN_ZOOM` = `28 /* real: pinça do touchpad neste frame (fator; *` | |
|
||||
| `#define GFX_IN_COUNT` = `29` | Saídas do bloco `Graphics.Input`. |
|
||||
| `#define GFX_MAX_TOUCHES` = `10` | Toques guardados por quadro. |
|
||||
| tipo `struct TinyBlocks_GfxInput` | Estado de entrada de uma janela em um frame (preenchido pelo backend) |
|
||||
|
||||
@@ -2130,6 +2366,7 @@ Uso típico (host):
|
||||
| `float tb_graphics_measure_text(const char* text, float font_size)` | Largura de um texto na fonte do backend |
|
||||
| `bool tb_graphics_set_clipboard(const char* text)` | Area de transferencia do sistema (copiar/colar). get devolve malloc (libere com free) ou NULL se estiver vazia. |
|
||||
| `char* tb_graphics_get_clipboard(void)` | Texto da área de transferência (malloc) ou NULL. |
|
||||
| `void tb_graphics_text_input(bool on, float x, float y, float w, float h)` | Diz ao sistema que um campo de texto esta em foco, com o cursor em (x, y, w, h) na janela: no celular abre o teclado, no desktop posiciona o IME. on=false: nenhum campo (o teclado na tela fecha). Chamar de novo com on=true reabre o teclado que o usuario fechou. |
|
||||
| `void tb_graphics_run(TinyBlocks* rt)` | Loop principal: roda todas as janelas abertas até a principal fechar |
|
||||
| `bool tb_graphics_window_is_open(TinyBlocks_Block* window)` | A janela (`Graphics.Window`) está aberta? |
|
||||
|
||||
@@ -2424,6 +2661,8 @@ endereco fica aberta entre as chamadas; tb_mcp_deinit fecha todas.
|
||||
| `char* tb_mcp_call_tool(const char* url, const char* tool, const char* args_json, bool* ok)` | conteudo em texto |
|
||||
| `const TinyBlocks_LibraryDescriptor* tb_mcp_get_library(void)` | Library de blocos (categoria "MCP") |
|
||||
|
||||
## libraries/tinyblocks-mcp/src/tb_mcp_py.h
|
||||
|
||||
## libraries/tinyblocks-number/include/tb_number.h
|
||||
|
||||
```text
|
||||
@@ -2598,6 +2837,115 @@ como TinyBlocks_Image (TB_VALUE_IMAGE). Independente do editor.
|
||||
| `char* tb_python_run_with_vars(const char* code, const char* const* names, const double* vals, int n)` | Executa código passando variáveis como locais (nome=valor float). Equivalente a tb_python_run mas com namespace preenchido. |
|
||||
| `char* tb_python_exec_main(const char* code)` | Executa código no namespace __main__ (definições persistem entre chamadas). Retorna stdout+stderr capturado (caller frees). |
|
||||
|
||||
## libraries/tinyblocks-qr/include/tb_camera.h
|
||||
|
||||
```text
|
||||
Camera do aparelho, em tons de cinza (o que um leitor de QR precisa).
|
||||
Linux: V4L2 (/dev/video0, YUYV: o canal Y ja e o cinza). Android: Camera2
|
||||
do NDK (camera2ndk + AImageReader, sem Java), com a permissao de camera
|
||||
pedida na hora. Sem camera (ou no Windows): tb_camera_open falha e
|
||||
tb_camera_error diz por que.
|
||||
```
|
||||
|
||||
## libraries/tinyblocks-qr/include/tb_qr.h
|
||||
|
||||
```text
|
||||
QR code: gerar (qrcodegen, de Project Nayuki, MIT) e ler de uma imagem em
|
||||
tons de cinza (quirc, de Daniel Beer, ISC). Mais a camera do aparelho para
|
||||
o leitor (tb_camera.h). Usada pelo editor para mandar blocos de uma
|
||||
instancia para outra por QR.
|
||||
```
|
||||
|
||||
## libraries/tinyblocks-qr/src/qrcodegen.h
|
||||
|
||||
```text
|
||||
QR Code generator library (C)
|
||||
Copyright (c) Project Nayuki. (MIT License)
|
||||
https://www.nayuki.io/page/qr-code-generator-library
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
- The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
- The Software is provided "as is", without warranty of any kind, express or
|
||||
implied, including but not limited to the warranties of merchantability,
|
||||
fitness for a particular purpose and noninfringement. In no event shall the
|
||||
authors or copyright holders be liable for any claim, damages or other
|
||||
liability, whether in an action of contract, tort or otherwise, arising from,
|
||||
out of or in connection with the Software or the use or other dealings in the
|
||||
Software.
|
||||
```
|
||||
|
||||
## libraries/tinyblocks-qr/src/quirc.h
|
||||
|
||||
```text
|
||||
quirc -- QR-code recognition library
|
||||
Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
```
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `#define QUIRC_H_` | quirc -- QR-code recognition library Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
|
||||
## libraries/tinyblocks-qr/src/quirc_internal.h
|
||||
|
||||
```text
|
||||
quirc -- QR-code recognition library
|
||||
Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
```
|
||||
|
||||
| Declaração | Descrição |
|
||||
|---|---|
|
||||
| `#define QUIRC_INTERNAL_H_` | quirc -- QR-code recognition library Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
| `#define QUIRC_ASSERT(a)` = `assert(a)` | |
|
||||
| `#define QUIRC_PIXEL_WHITE` = `0` | |
|
||||
| `#define QUIRC_PIXEL_BLACK` = `1` | |
|
||||
| `#define QUIRC_PIXEL_REGION` = `2` | |
|
||||
| `#define QUIRC_MAX_REGIONS` = `254` | |
|
||||
| `#define QUIRC_MAX_CAPSTONES` = `32` | |
|
||||
| `#define QUIRC_MAX_GRIDS` = `(QUIRC_MAX_CAPSTONES * 2)` | |
|
||||
| `#define QUIRC_PERSPECTIVE_PARAMS` = `8` | |
|
||||
| `#define QUIRC_PIXEL_ALIAS_IMAGE` = `1` | |
|
||||
| tipo `typedef uint8_t quirc_pixel_t` | |
|
||||
| `#define QUIRC_PIXEL_ALIAS_IMAGE` = `0` | |
|
||||
| tipo `typedef uint16_t quirc_pixel_t` | |
|
||||
| tipo `typedef QUIRC_FLOAT_TYPE quirc_float_t` | Quirc uses double precision floating point internally by default. On platforms with a single precision FPU but no double precision FPU, this can be changed to float by defining QUIRC_FLOAT_TYPE. When setting QUIRC_FLOAT_TYPE to 'float', consider also defining QUIRC_USE_TGMATH. This will use the type-generic math functions (tgmath.h, C99 or later) instead of the normal ones, which will allow the compiler to use the correct overloaded functions for the type. |
|
||||
| tipo `typedef double quirc_float_t` | |
|
||||
| tipo `struct quirc_region` | |
|
||||
| tipo `struct quirc_capstone` | |
|
||||
| tipo `struct quirc_grid` | |
|
||||
| tipo `struct quirc_flood_fill_vars` | |
|
||||
| tipo `struct quirc` | |
|
||||
| `static inline size_t quirc_image_size(int w, int h) { return (size_t)w * (size_t)h` | |
|
||||
| `static inline size_t quirc_pixel_count(const struct quirc *q) { return quirc_image_size(q->w, q->h)` | |
|
||||
| `#define QUIRC_MAX_VERSION` = `40` | QR-code version information database |
|
||||
| `#define QUIRC_MAX_ALIGNMENT` = `7` | |
|
||||
| tipo `struct quirc_rs_params` | |
|
||||
| tipo `struct quirc_version_info` | |
|
||||
|
||||
## libraries/tinyblocks-regex/include/tb_regex.h
|
||||
|
||||
```text
|
||||
|
||||
@@ -57,16 +57,16 @@ void tb_android_boot(void); /* cwd, TINYBLOCKS_APPDIR, fonte e certificados (p
|
||||
entram no executavel e sao registradas aqui */
|
||||
# include <tb_base64.h>
|
||||
# include <tb_curves.h>
|
||||
# include <tb_ppm.h>
|
||||
# include <tb_bmp.h>
|
||||
# include <tb_png.h>
|
||||
# include <tb_imglib.h>
|
||||
# include <tb_vg.h>
|
||||
# include <tb_svg.h>
|
||||
# include <tb_regex.h>
|
||||
# include <tb_markdown.h>
|
||||
# include <tb_opentype.h>
|
||||
#endif
|
||||
#include <tb_ppm.h>
|
||||
#include <tb_bmp.h>
|
||||
#include <tb_png.h>
|
||||
#include <tb_imglib.h>
|
||||
|
||||
/* Registra uma library de categoria: se existir o .so dela no disco, carrega
|
||||
* por ali (assim "make libs" + hot reload recarrega a lista de blocos na
|
||||
@@ -115,6 +115,10 @@ int main(int argc, char** argv) {
|
||||
reg_core(rt, "tinyblocks-variables", tb_variables_get_library);
|
||||
reg_core(rt, "tinyblocks-vector", tb_vector_get_library);
|
||||
reg_core(rt, "tinyblocks-appearance", tb_appearance_get_library);
|
||||
reg_core(rt, "tinyblocks-ppm", tb_ppm_get_library);
|
||||
reg_core(rt, "tinyblocks-bmp", tb_bmp_get_library);
|
||||
reg_core(rt, "tinyblocks-png", tb_png_get_library);
|
||||
reg_core(rt, "tinyblocks-image", tb_imglib_get_library);
|
||||
reg_core(rt, "tinyblocks-pen", tb_pen_get_library);
|
||||
reg_core(rt, "tinyblocks-fs", tb_fs_get_library);
|
||||
reg_core(rt, "tinyblocks-os", tb_os_get_library);
|
||||
@@ -136,7 +140,6 @@ int main(int argc, char** argv) {
|
||||
#ifdef TB_STATIC_EXTRAS
|
||||
{
|
||||
const TinyBlocks_LibraryDescriptor* (*extras[])(void) = {
|
||||
tb_ppm_get_library, tb_bmp_get_library, tb_png_get_library, tb_imglib_get_library,
|
||||
tb_base64_get_library, tb_curves_get_library, tb_vg_get_library, tb_svg_get_library,
|
||||
tb_regex_get_library, tb_markdown_get_library, tb_opentype_get_library };
|
||||
for (size_t i = 0; i < sizeof(extras) / sizeof(extras[0]); i++) tb_library_register(rt, extras[i]());
|
||||
|
||||
@@ -28,6 +28,48 @@ O texto no canto de baixo mostra quem desenhou o quadro: `vulkan`,
|
||||
`opengl` ou `software`, com a placa. A escolha é automática (Vulkan, depois
|
||||
OpenGL, depois software); `use o renderizador [opengl]` força um.
|
||||
|
||||
## Minecraftzinho (`minecraft.sb`)
|
||||
|
||||
Um mundo de blocos texturizados em primeira pessoa, feito só com blocos (a
|
||||
engine não tem nenhum tipo "voxel"): o mundo, a malha de cada chunk e o
|
||||
controle do jogador saem de poucos blocos próprios.
|
||||
|
||||
- **Chunks**: `monte o chunk (ci) (cj)` monta uma malha de 8x8 células com
|
||||
`crie a malha` e `face` (topo, fundo e as quatro laterais, via `na malha
|
||||
adicione o vértice/a texcoord/o triângulo`). As paredes só viram onde a
|
||||
célula vizinha é mais baixa, então o terreno sai merged, um pedaço por
|
||||
chunk, com o UV resolvido no `atlas.png` de 64x64 (4x4 tiles de 16px;
|
||||
grama no topo, terra no meio, pedra embaixo). Onde a coluna é baixa
|
||||
(altura 0 ou 1) o topo vira areia: são as praias.
|
||||
- **Altura**: a reporter `altura em x (x) z (z)` é uma soma de senos, então
|
||||
o mundo é determinístico (colinas e vales) sem guardar lista nenhuma.
|
||||
- **Lago**: no fundo dos vales um `crie plano` de 16x16 cobre o mundo na
|
||||
altura da água, com `mude a opacidade de [agua_mar] para 0.6` (água
|
||||
translúcida: dá para ver o fundo). É um objeto transparente, então os
|
||||
renderizadores o desenham por último, do mais longe ao mais perto.
|
||||
- **Vegetação**: `monte uma árvore (ax) (az) (ah)` faz o tronco (material
|
||||
`madeira`) e a copa (material `folhas`) com `crie cubo` + `mude o tamanho
|
||||
de`; `plante a floresta` espalha as árvores numa grade determinística,
|
||||
só onde a altura é maior (fora da água e da areia).
|
||||
- **Céu e luz**: `céu` roda a cada quadro e faz um ciclo de dia e noite a
|
||||
partir do `cronômetro`: escolhe a `cor do céu` numa lista (`item (ki) de
|
||||
(lista [ceus])`), gira a direção da `luz` conforme o sol e baixa a `luz
|
||||
ambiente` à noite. A `névoa de 12 até 30` some com o horizonte na cor do
|
||||
céu, escondendo a borda do mundo.
|
||||
- **Jogador**: `monte um humanoide (nome)` monta pernas/tronco/braços/cabeça
|
||||
de caixas com UVs do atlas; em primeira pessoa o jogador fica escondido e
|
||||
a câmera vai na cabeça dele, com yaw/pitch pelo mouse. Dois aldeões (mesma
|
||||
malha, cores diferentes) passeiam pelo mundo.
|
||||
- **Barra de blocos**: `barra de blocos` desenha no palco o fundo escuro,
|
||||
o destaque do slot escolhido e as cinco texturas (`desenhe (img_bN) em x
|
||||
y escala`), depois da imagem da cena. `1..5` trocam o material.
|
||||
- **Controles**: WASD/setas andam relativo ao yaw, `E`/`Q` colocam e tiram
|
||||
bloco à frente (mira `mira.png` no centro), `1..5` trocam o material; o
|
||||
clique do mouse também coloca/tira.
|
||||
|
||||
Arquivos: `minecraft.sb`, o atlas `atlas.png`, a mira `mira.png` e as
|
||||
texturas `tex_*.png` (cada material usa uma delas como albedo).
|
||||
|
||||
## Shaders feitos com blocos (`shaders.sb`)
|
||||
|
||||
O segundo exemplo pinta os objetos com **shaders escritos em blocos**:
|
||||
@@ -58,3 +100,83 @@ comuns também valem (as variáveis viram locais do shader). `GLSL do shader
|
||||
Na notação do fórum, a pilha de um encaixe vem nas linhas de baixo,
|
||||
indentada e fechada com `end`, mesmo quando o bloco com o encaixe está
|
||||
dentro de outro (como o "compile o shader" dentro do "mude").
|
||||
|
||||
## Shader de vértice (`onda.sb`)
|
||||
|
||||
A mesma pilha pode ser um shader de **vértice** em vez de fragmento: use
|
||||
`mude a posição do vértice para x ( ) y ( ) z ( )` no lugar de
|
||||
`cor do pixel = ( )`. O `compile o shader` descobre o estágio sozinho (pelo
|
||||
que a pilha usa) e o `use o shader` põe no objeto.
|
||||
|
||||
```
|
||||
mude [onda v] para (compile o shader)
|
||||
mude a posição do vértice para x ((x do vértice) * (1 + (0.25 * (seno de ((tempo) * (180)))))) y (...) z (...)
|
||||
end
|
||||
use o shader (onda) no objeto [bola]
|
||||
```
|
||||
|
||||
A posição sai no espaço do objeto: a câmera e o `mova`/`gire` do objeto
|
||||
aplicam por cima. Entradas úteis: `x/y/z do vértice` (a posição local),
|
||||
`x/y/z da normal`, `u/v do uv` e `tempo`. Cada objeto usa um shader só (ou
|
||||
de vértice, ou de fragmento); `GLSL do shader (onda)` mostra o `tb_vert`
|
||||
gerado.
|
||||
|
||||
## Malha personalizada e UV (`malha.sb`)
|
||||
|
||||
Além das formas fixas (cubo, esfera, plano, cilindro), dá para montar uma
|
||||
malha vértice a vértice. A malha é um objeto como qualquer outro (move,
|
||||
gira, muda de tamanho e de cor):
|
||||
|
||||
```
|
||||
crie a malha [tri]
|
||||
na malha [tri] adicione o vértice x (-1) y (-1) z (0)
|
||||
na malha [tri] adicione o vértice x (1) y (-1) z (0)
|
||||
na malha [tri] adicione o vértice x (0) y (1) z (0)
|
||||
na malha [tri] adicione a texcoord u (0) v (0)
|
||||
na malha [tri] adicione a texcoord u (1) v (0)
|
||||
na malha [tri] adicione a texcoord u (0.5) v (1)
|
||||
na malha [tri] adicione o triângulo (1) (2) (3) // 1 = o primeiro vértice
|
||||
finalize a malha [tri]
|
||||
```
|
||||
|
||||
A normal de cada vértice é opcional (`na malha [tri] adicione a normal x
|
||||
0 y 0 z 1`); quem não informa, deixa que `finalize a malha` calcule das
|
||||
faces. A texcoord (`u`/`v`, de 0 a 1) é o que faltava para texturas e para
|
||||
ler **Wavefront `.obj`**: os blocos de Shader têm `u do uv` e `v do uv`, e
|
||||
também `x/y/z do vértice` (a posição antes de mover o objeto).
|
||||
|
||||
### Lendo um `.obj`
|
||||
|
||||
Use `leia o arquivo [modelo.obj]` (categoria **Arquivos**) para pegar o
|
||||
texto inteiro de uma vez, `divida (texto) por ...` para separar as linhas
|
||||
e, para cada linha, `divida` de novo pelos espaços e olhe o primeiro
|
||||
campo: `v` é vértice, `vt` é texcoord, `vn` é normal e `f` é triângulo.
|
||||
Os números do `f` no `.obj` começam em 1 (iguais aos do bloco "adicione o
|
||||
triângulo"); quando o índice vier no formato `v/vt/vn` (com barras),
|
||||
divida o campo por `/` e use só o primeiro número.
|
||||
|
||||
## Textura e material (`textura.sb`)
|
||||
|
||||
Uma textura sai de uma imagem (categoria **Imagem**/**PNG**, com `carregue o PNG
|
||||
[tijolo.png]` ou uma imagem feita com os blocos de desenho):
|
||||
|
||||
```
|
||||
crie a textura [pedra] da imagem [pedra.png]
|
||||
crie o material [rocha]
|
||||
no material [rocha] use a textura [pedra] como albedo
|
||||
no material [rocha] use a cor [branco]
|
||||
use o material [rocha] no objeto [chão]
|
||||
```
|
||||
|
||||
O **albedo** é a cor da superfície: o renderizador amostra a textura no
|
||||
`u/v` de cada vértice (malha personalizada, cubo, esfera e cilindro já
|
||||
trazem o `uv`). A amostra chega ao shader com o bloco `textura do pixel`,
|
||||
então quem usa `cor do pixel` pode misturar a textura com a cor e a luz. A
|
||||
`cor` do material multiplica a textura (o padrão é branco, que não muda
|
||||
nada). A textura se repete fora do `0..1`.
|
||||
|
||||
O **normal map** (`no material [rocha] use a textura [relevo] como
|
||||
normal`) inclina a normal por pixel: a textura guarda a normal no espaço do
|
||||
objeto (RGB de 0 a 1: `x = 2r-1`, `y = 2g-1`, `z = 2b-1`), o renderizador
|
||||
monta o frame de tangentes com o `u/v` e a luz passa a ser por pixel. O
|
||||
relevo sai igual no software, no OpenGL e no Vulkan.
|
||||
|
After Width: | Height: | Size: 5.8 KiB |
@@ -0,0 +1,21 @@
|
||||
when flag clicked
|
||||
nova cena 3D
|
||||
cor do céu [#87c7fa]
|
||||
luz vindo de x (0.5) y (1) z (0.3)
|
||||
crie plano [chão] em x (0) y (0) z (0)
|
||||
mude o tamanho de [chão] para x (10) y (1) z (10)
|
||||
mude a cor de [chão] para [#5aa05a]
|
||||
crie cubo [caixa] em x (0) y (0.5) z (0)
|
||||
mude a cor de [caixa] para [azul]
|
||||
crie esfera [bola] em x (2) y (0.6) z (0)
|
||||
mude a cor de [bola] para [vermelho]
|
||||
mude [t v] para (0)
|
||||
sempre
|
||||
mude [t v] para ((t) + (1))
|
||||
gire [caixa] por x (0) y (2) z (0) graus
|
||||
mova [bola] para x ((2) * (seno de ((t) * (3)))) y (0.6) z (0)
|
||||
câmera em x (6) y (5) z (9) olhando para x (0) y (1) z (0)
|
||||
apague tudo
|
||||
desenhe (imagem da cena de (480) por (360)) em x (0) y (0) escala (1)
|
||||
escreva (renderizador da cena) no palco em x (-220) y (-170)
|
||||
end
|
||||
|
After Width: | Height: | Size: 454 B |
|
After Width: | Height: | Size: 601 B |
|
After Width: | Height: | Size: 508 B |
|
After Width: | Height: | Size: 482 B |
@@ -0,0 +1,21 @@
|
||||
when flag clicked
|
||||
nova cena 3D
|
||||
crie a malha [tri]
|
||||
na malha [tri] adicione o vértice x (-1) y (-1) z (0)
|
||||
na malha [tri] adicione o vértice x (1) y (-1) z (0)
|
||||
na malha [tri] adicione o vértice x (0) y (1) z (0)
|
||||
na malha [tri] adicione a texcoord u (0) v (0)
|
||||
na malha [tri] adicione a texcoord u (1) v (0)
|
||||
na malha [tri] adicione a texcoord u (0.5) v (1)
|
||||
na malha [tri] adicione o triângulo (1) (2) (3)
|
||||
finalize a malha [tri]
|
||||
mude [uv v] para (compile o shader)
|
||||
cor do pixel = (cor r (u do uv) g (v do uv) b (0))
|
||||
end
|
||||
use o shader (uv) no objeto [tri]
|
||||
câmera em x (0) y (0) z (3) olhando para x (0) y (0) z (0)
|
||||
sempre
|
||||
gire [tri] por x (0) y (1) z (0) graus
|
||||
apague tudo
|
||||
desenhe (imagem da cena de (480) por (360)) em x (0) y (0) escala (1)
|
||||
end
|
||||
@@ -0,0 +1,456 @@
|
||||
when flag clicked
|
||||
nova cena 3D
|
||||
cor do céu [#87c7fa]
|
||||
luz vindo de x (0.5) y (1) z (0.35)
|
||||
luz ambiente (0.45)
|
||||
campo de visão da câmera (70) graus
|
||||
carregue os materiais
|
||||
monte o mundo
|
||||
mude [jogador_x v] para (8)
|
||||
mude [jogador_z v] para (1)
|
||||
mude [jogador_y v] para (2)
|
||||
mude [sel v] para (1)
|
||||
mude [antes_e v] para (0)
|
||||
mude [antes_d v] para (0)
|
||||
sempre
|
||||
olhe e ande
|
||||
mova o jogador
|
||||
mova os aldeoes
|
||||
use os cliques
|
||||
céu
|
||||
apague tudo
|
||||
desenhe (imagem da cena de (480) por (360)) em x (0) y (0) escala (1)
|
||||
desenhe (img_mira) em x (0) y (0) escala (1)
|
||||
barra de blocos
|
||||
escreva (junte [WASD anda 1-5 troca E/Q bloco] com []) no palco em x (-220) y (165)
|
||||
escreva (renderizador da cena) no palco em x (-220) y (145)
|
||||
end
|
||||
|
||||
define vertice x (x) y (y) z (z) u (u) v (v)
|
||||
na malha (malha_atual) adicione o vértice x (x) y (y) z (z)
|
||||
na malha (malha_atual) adicione a texcoord u (u) v (v)
|
||||
|
||||
define face topo de x (x) y (y) z (z) ate x (X) y (Y) z (Z) u (u) v (v)
|
||||
mude [nb v] para (nv)
|
||||
vertice x (x) y (Y) z (z) u (u) v (v)
|
||||
vertice x (x) y (Y) z (Z) u (u) v ((v) + (0.25))
|
||||
vertice x (X) y (Y) z (Z) u ((u) + (0.25)) v ((v) + (0.25))
|
||||
vertice x (X) y (Y) z (z) u ((u) + (0.25)) v (v)
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (1)) ((nb) + (2))
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (2)) ((nb) + (3))
|
||||
adicione (4) a [nv v]
|
||||
|
||||
define face fundo de x (x) y (y) z (z) ate x (X) y (Y) z (Z) u (u) v (v)
|
||||
mude [nb v] para (nv)
|
||||
vertice x (x) y (y) z (z) u (u) v (v)
|
||||
vertice x (X) y (y) z (z) u ((u) + (0.25)) v (v)
|
||||
vertice x (X) y (y) z (Z) u ((u) + (0.25)) v ((v) + (0.25))
|
||||
vertice x (x) y (y) z (Z) u (u) v ((v) + (0.25))
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (1)) ((nb) + (2))
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (2)) ((nb) + (3))
|
||||
adicione (4) a [nv v]
|
||||
|
||||
define face leste de x (x) y (y) z (z) ate x (X) y (Y) z (Z) u (u) v (v)
|
||||
mude [nb v] para (nv)
|
||||
vertice x (X) y (y) z (z) u (u) v ((v) + (0.25))
|
||||
vertice x (X) y (Y) z (z) u (u) v (v)
|
||||
vertice x (X) y (Y) z (Z) u ((u) + (0.25)) v (v)
|
||||
vertice x (X) y (y) z (Z) u ((u) + (0.25)) v ((v) + (0.25))
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (1)) ((nb) + (2))
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (2)) ((nb) + (3))
|
||||
adicione (4) a [nv v]
|
||||
|
||||
define face oeste de x (x) y (y) z (z) ate x (X) y (Y) z (Z) u (u) v (v)
|
||||
mude [nb v] para (nv)
|
||||
vertice x (x) y (y) z (z) u (u) v ((v) + (0.25))
|
||||
vertice x (x) y (y) z (Z) u ((u) + (0.25)) v ((v) + (0.25))
|
||||
vertice x (x) y (Y) z (Z) u ((u) + (0.25)) v (v)
|
||||
vertice x (x) y (Y) z (z) u (u) v (v)
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (1)) ((nb) + (2))
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (2)) ((nb) + (3))
|
||||
adicione (4) a [nv v]
|
||||
|
||||
define face sul de x (x) y (y) z (z) ate x (X) y (Y) z (Z) u (u) v (v)
|
||||
mude [nb v] para (nv)
|
||||
vertice x (x) y (y) z (Z) u (u) v ((v) + (0.25))
|
||||
vertice x (X) y (y) z (Z) u ((u) + (0.25)) v ((v) + (0.25))
|
||||
vertice x (X) y (Y) z (Z) u ((u) + (0.25)) v (v)
|
||||
vertice x (x) y (Y) z (Z) u (u) v (v)
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (1)) ((nb) + (2))
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (2)) ((nb) + (3))
|
||||
adicione (4) a [nv v]
|
||||
|
||||
define face norte de x (x) y (y) z (z) ate x (X) y (Y) z (Z) u (u) v (v)
|
||||
mude [nb v] para (nv)
|
||||
vertice x (x) y (y) z (z) u (u) v ((v) + (0.25))
|
||||
vertice x (x) y (Y) z (z) u (u) v (v)
|
||||
vertice x (X) y (Y) z (z) u ((u) + (0.25)) v (v)
|
||||
vertice x (X) y (y) z (z) u ((u) + (0.25)) v ((v) + (0.25))
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (1)) ((nb) + (2))
|
||||
na malha (malha_atual) adicione o triângulo (nb) ((nb) + (2)) ((nb) + (3))
|
||||
adicione (4) a [nv v]
|
||||
|
||||
define altura em x (x) z (z)
|
||||
devolva [h] = (limite (arredonde ((((2.1) + ((1.3) * (seno de ((x) * (33))))) + ((1.0) * (cosseno de ((z) * (28))))) + ((0.7) * (seno de (((x) + (z)) * (21)))))) entre (0) e (4))
|
||||
|
||||
define monte o chunk (ci) (cj)
|
||||
mude [malha_atual v] para (junte [chunk] com (junte (ci) com (junte [_] com (cj))))
|
||||
crie a malha (malha_atual)
|
||||
mude [nv v] para (1)
|
||||
mude [lx v] para (0)
|
||||
repita (8) vezes
|
||||
mude [lz v] para (0)
|
||||
repita (8) vezes
|
||||
mude [bx v] para (((ci) * (8)) + (lx))
|
||||
mude [bz v] para (((cj) * (8)) + (lz))
|
||||
mude [h0 v] para (altura em x (bx) z (bz))
|
||||
mude [vt v] para (0)
|
||||
se <(h0) < (2)> então
|
||||
mude [vt v] para (0.5)
|
||||
end
|
||||
face topo de x (bx) y (h0) z (bz) ate x ((bx) + (1)) y (h0) z ((bz) + (1)) u (0) v (vt)
|
||||
mude [hn v] para (-1)
|
||||
se <(bx) > (0)> então
|
||||
mude [hn v] para (altura em x ((bx) + (-1)) z (bz))
|
||||
end
|
||||
mude [yy v] para (hn)
|
||||
repita ((h0) - (hn)) vezes
|
||||
mude [u0 v] para (0.75)
|
||||
se <(yy) > ((h0) - (4))> então
|
||||
mude [u0 v] para (0.5)
|
||||
end
|
||||
se <(yy) = ((h0) - (1))> então
|
||||
mude [u0 v] para (0.25)
|
||||
end
|
||||
face oeste de x (bx) y (yy) z (bz) ate x (bx) y ((yy) + (1)) z ((bz) + (1)) u (u0) v (0)
|
||||
adicione (1) a [yy v]
|
||||
end
|
||||
mude [hn v] para (-1)
|
||||
se <(bx) < (15)> então
|
||||
mude [hn v] para (altura em x ((bx) + (1)) z (bz))
|
||||
end
|
||||
mude [yy v] para (hn)
|
||||
repita ((h0) - (hn)) vezes
|
||||
mude [u0 v] para (0.75)
|
||||
se <(yy) > ((h0) - (4))> então
|
||||
mude [u0 v] para (0.5)
|
||||
end
|
||||
se <(yy) = ((h0) - (1))> então
|
||||
mude [u0 v] para (0.25)
|
||||
end
|
||||
face leste de x (bx) y (yy) z (bz) ate x ((bx) + (1)) y ((yy) + (1)) z ((bz) + (1)) u (u0) v (0)
|
||||
adicione (1) a [yy v]
|
||||
end
|
||||
mude [hn v] para (-1)
|
||||
se <(bz) > (0)> então
|
||||
mude [hn v] para (altura em x (bx) z ((bz) + (-1)))
|
||||
end
|
||||
mude [yy v] para (hn)
|
||||
repita ((h0) - (hn)) vezes
|
||||
mude [u0 v] para (0.75)
|
||||
se <(yy) > ((h0) - (4))> então
|
||||
mude [u0 v] para (0.5)
|
||||
end
|
||||
se <(yy) = ((h0) - (1))> então
|
||||
mude [u0 v] para (0.25)
|
||||
end
|
||||
face norte de x (bx) y (yy) z (bz) ate x ((bx) + (1)) y ((yy) + (1)) z ((bz) + (1)) u (u0) v (0)
|
||||
adicione (1) a [yy v]
|
||||
end
|
||||
mude [hn v] para (-1)
|
||||
se <(bz) < (15)> então
|
||||
mude [hn v] para (altura em x (bx) z ((bz) + (1)))
|
||||
end
|
||||
mude [yy v] para (hn)
|
||||
repita ((h0) - (hn)) vezes
|
||||
mude [u0 v] para (0.75)
|
||||
se <(yy) > ((h0) - (4))> então
|
||||
mude [u0 v] para (0.5)
|
||||
end
|
||||
se <(yy) = ((h0) - (1))> então
|
||||
mude [u0 v] para (0.25)
|
||||
end
|
||||
face sul de x (bx) y (yy) z (bz) ate x ((bx) + (1)) y ((yy) + (1)) z ((bz) + (1)) u (u0) v (0)
|
||||
adicione (1) a [yy v]
|
||||
end
|
||||
adicione (1) a [lz v]
|
||||
end
|
||||
adicione (1) a [lx v]
|
||||
end
|
||||
finalize a malha (malha_atual)
|
||||
use o material [mate] no objeto (malha_atual)
|
||||
|
||||
define monte um humanoide (nome)
|
||||
mude [malha_atual v] para (nome)
|
||||
crie a malha (nome)
|
||||
mude [nv v] para (1)
|
||||
face topo de x (-0.2) y (0) z (-0.12) ate x (-0.02) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face fundo de x (-0.2) y (0) z (-0.12) ate x (-0.02) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face leste de x (-0.2) y (0) z (-0.12) ate x (-0.02) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face oeste de x (-0.2) y (0) z (-0.12) ate x (-0.02) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face sul de x (-0.2) y (0) z (-0.12) ate x (-0.02) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face norte de x (-0.2) y (0) z (-0.12) ate x (-0.02) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face topo de x (0.02) y (0) z (-0.12) ate x (0.2) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face fundo de x (0.02) y (0) z (-0.12) ate x (0.2) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face leste de x (0.02) y (0) z (-0.12) ate x (0.2) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face oeste de x (0.02) y (0) z (-0.12) ate x (0.2) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face sul de x (0.02) y (0) z (-0.12) ate x (0.2) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face norte de x (0.02) y (0) z (-0.12) ate x (0.2) y (0.7) z (0.12) u (0.75) v (0.75)
|
||||
face topo de x (-0.22) y (0.7) z (-0.13) ate x (0.22) y (1.3) z (0.13) u (0.5) v (0.75)
|
||||
face fundo de x (-0.22) y (0.7) z (-0.13) ate x (0.22) y (1.3) z (0.13) u (0.5) v (0.75)
|
||||
face leste de x (-0.22) y (0.7) z (-0.13) ate x (0.22) y (1.3) z (0.13) u (0.5) v (0.75)
|
||||
face oeste de x (-0.22) y (0.7) z (-0.13) ate x (0.22) y (1.3) z (0.13) u (0.5) v (0.75)
|
||||
face sul de x (-0.22) y (0.7) z (-0.13) ate x (0.22) y (1.3) z (0.13) u (0.5) v (0.75)
|
||||
face norte de x (-0.22) y (0.7) z (-0.13) ate x (0.22) y (1.3) z (0.13) u (0.5) v (0.75)
|
||||
face topo de x (-0.35) y (0.72) z (-0.12) ate x (-0.24) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face fundo de x (-0.35) y (0.72) z (-0.12) ate x (-0.24) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face leste de x (-0.35) y (0.72) z (-0.12) ate x (-0.24) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face oeste de x (-0.35) y (0.72) z (-0.12) ate x (-0.24) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face sul de x (-0.35) y (0.72) z (-0.12) ate x (-0.24) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face norte de x (-0.35) y (0.72) z (-0.12) ate x (-0.24) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face topo de x (0.24) y (0.72) z (-0.12) ate x (0.35) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face fundo de x (0.24) y (0.72) z (-0.12) ate x (0.35) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face leste de x (0.24) y (0.72) z (-0.12) ate x (0.35) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face oeste de x (0.24) y (0.72) z (-0.12) ate x (0.35) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face sul de x (0.24) y (0.72) z (-0.12) ate x (0.35) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face norte de x (0.24) y (0.72) z (-0.12) ate x (0.35) y (1.3) z (0.12) u (0.25) v (0.75)
|
||||
face topo de x (-0.2) y (1.3) z (-0.2) ate x (0.2) y (1.75) z (0.2) u (0.25) v (0.75)
|
||||
face fundo de x (-0.2) y (1.3) z (-0.2) ate x (0.2) y (1.75) z (0.2) u (0.25) v (0.75)
|
||||
face leste de x (-0.2) y (1.3) z (-0.2) ate x (0.2) y (1.75) z (0.2) u (0.25) v (0.75)
|
||||
face oeste de x (-0.2) y (1.3) z (-0.2) ate x (0.2) y (1.75) z (0.2) u (0.25) v (0.75)
|
||||
face sul de x (-0.2) y (1.3) z (-0.2) ate x (0.2) y (1.75) z (0.2) u (0.0) v (0.75)
|
||||
face norte de x (-0.2) y (1.3) z (-0.2) ate x (0.2) y (1.75) z (0.2) u (0.25) v (0.75)
|
||||
finalize a malha (nome)
|
||||
use o material [mate] no objeto (nome)
|
||||
mude a cor de (nome) para [#ffffff]
|
||||
|
||||
define carregue os materiais
|
||||
mude [img_atlas v] para (carregue o PNG [atlas.png])
|
||||
crie a textura [atlas] da imagem (img_atlas)
|
||||
crie o material [mate]
|
||||
no material [mate] use a textura [atlas] como albedo
|
||||
mude [img_mira v] para (carregue o PNG [mira.png])
|
||||
mude [img_b1 v] para (carregue o PNG [tex_grama_topo.png])
|
||||
crie a textura [tb1] da imagem (img_b1)
|
||||
crie o material [b1]
|
||||
no material [b1] use a textura [tb1] como albedo
|
||||
mude [img_b2 v] para (carregue o PNG [tex_terra.png])
|
||||
crie a textura [tb2] da imagem (img_b2)
|
||||
crie o material [b2]
|
||||
no material [b2] use a textura [tb2] como albedo
|
||||
mude [img_b3 v] para (carregue o PNG [tex_pedra.png])
|
||||
crie a textura [tb3] da imagem (img_b3)
|
||||
crie o material [b3]
|
||||
no material [b3] use a textura [tb3] como albedo
|
||||
mude [img_b4 v] para (carregue o PNG [tex_madeira_lado.png])
|
||||
crie a textura [tb4] da imagem (img_b4)
|
||||
crie o material [b4]
|
||||
no material [b4] use a textura [tb4] como albedo
|
||||
mude [img_b5 v] para (carregue o PNG [tex_tabuas.png])
|
||||
crie a textura [tb5] da imagem (img_b5)
|
||||
crie o material [b5]
|
||||
no material [b5] use a textura [tb5] como albedo
|
||||
apague todos os itens da lista [blocos]
|
||||
adicione [b1] à lista [blocos]
|
||||
adicione [b2] à lista [blocos]
|
||||
adicione [b3] à lista [blocos]
|
||||
adicione [b4] à lista [blocos]
|
||||
adicione [b5] à lista [blocos]
|
||||
apague todos os itens da lista [ceus]
|
||||
adicione [#0b1a33] à lista [ceus]
|
||||
adicione [#f08050] à lista [ceus]
|
||||
adicione [#9fd0f0] à lista [ceus]
|
||||
adicione [#87c7fa] à lista [ceus]
|
||||
adicione [#87c7fa] à lista [ceus]
|
||||
adicione [#9fd0f0] à lista [ceus]
|
||||
adicione [#e06040] à lista [ceus]
|
||||
adicione [#0b1a33] à lista [ceus]
|
||||
mude [img_b6 v] para (carregue o PNG [tex_madeira_lado.png])
|
||||
crie a textura [tb6] da imagem (img_b6)
|
||||
crie o material [madeira]
|
||||
no material [madeira] use a textura [tb6] como albedo
|
||||
mude [img_b7 v] para (carregue o PNG [tex_folhas.png])
|
||||
crie a textura [tb7] da imagem (img_b7)
|
||||
crie o material [folhas]
|
||||
no material [folhas] use a textura [tb7] como albedo
|
||||
mude [img_b8 v] para (carregue o PNG [tex_agua.png])
|
||||
crie a textura [tb8] da imagem (img_b8)
|
||||
crie o material [agua]
|
||||
no material [agua] use a textura [tb8] como albedo
|
||||
|
||||
define monte o mundo
|
||||
mude [ci v] para (0)
|
||||
repita (2) vezes
|
||||
mude [cj v] para (0)
|
||||
repita (2) vezes
|
||||
monte o chunk (ci) (cj)
|
||||
adicione (1) a [cj v]
|
||||
end
|
||||
adicione (1) a [ci v]
|
||||
end
|
||||
plante a floresta
|
||||
crie plano [agua_mar] em x (8) y (1.2) z (8)
|
||||
mude o tamanho de [agua_mar] para x (16.5) y (1) z (16.5)
|
||||
use o material [agua] no objeto [agua_mar]
|
||||
mude a opacidade de [agua_mar] para (0.6)
|
||||
mude a cor de [agua_mar] para [#cfe6ff]
|
||||
mude [nome v] para [jogador]
|
||||
monte um humanoide (nome)
|
||||
mude [nome v] para [aldeao_1]
|
||||
monte um humanoide (nome)
|
||||
mude [nome v] para [aldeao_2]
|
||||
monte um humanoide (nome)
|
||||
mude a cor de [aldeao_1] para [#d8b070]
|
||||
mude a cor de [aldeao_2] para [#a070d8]
|
||||
esconda o objeto [jogador]
|
||||
|
||||
define olhe e ande
|
||||
mude [cam_yaw v] para (((mouse x) / (240)) * (180))
|
||||
mude [cam_pitch v] para (limite ((((mouse y) / (180)) * (60)) + (-15)) entre (-60) e (60))
|
||||
mude [fx v] para (seno de (cam_yaw))
|
||||
mude [fz v] para (cosseno de (cam_yaw))
|
||||
mude [rx v] para ((0) - (cosseno de (cam_yaw)))
|
||||
mude [rz v] para (seno de (cam_yaw))
|
||||
mude [spd v] para (0.16)
|
||||
se <<tecla [w] pressionada?> ou <tecla [seta para cima] pressionada?>> então
|
||||
mude [jogador_x v] para ((jogador_x) + (((fx) * (spd)) * (1)))
|
||||
mude [jogador_z v] para ((jogador_z) + (((fz) * (spd)) * (1)))
|
||||
end
|
||||
se <<tecla [s] pressionada?> ou <tecla [seta para baixo] pressionada?>> então
|
||||
mude [jogador_x v] para ((jogador_x) + (((fx) * (spd)) * (-1)))
|
||||
mude [jogador_z v] para ((jogador_z) + (((fz) * (spd)) * (-1)))
|
||||
end
|
||||
se <tecla [a] pressionada?> então
|
||||
mude [jogador_x v] para ((jogador_x) + (((rx) * (spd)) * (1)))
|
||||
mude [jogador_z v] para ((jogador_z) + (((rz) * (spd)) * (1)))
|
||||
end
|
||||
se <tecla [d] pressionada?> então
|
||||
mude [jogador_x v] para ((jogador_x) + (((rx) * (spd)) * (-1)))
|
||||
mude [jogador_z v] para ((jogador_z) + (((rz) * (spd)) * (-1)))
|
||||
end
|
||||
se <tecla [1] pressionada?> então
|
||||
mude [sel v] para (1)
|
||||
end
|
||||
se <tecla [2] pressionada?> então
|
||||
mude [sel v] para (2)
|
||||
end
|
||||
se <tecla [3] pressionada?> então
|
||||
mude [sel v] para (3)
|
||||
end
|
||||
se <tecla [4] pressionada?> então
|
||||
mude [sel v] para (4)
|
||||
end
|
||||
se <tecla [5] pressionada?> então
|
||||
mude [sel v] para (5)
|
||||
end
|
||||
mude [jogador_x v] para (limite (jogador_x) entre (0.5) e (15.5))
|
||||
mude [jogador_z v] para (limite (jogador_z) entre (0.5) e (15.5))
|
||||
|
||||
define mova o jogador
|
||||
mude [jogador_y v] para (altura em x (limite (arredonde (jogador_x)) entre (0) e (15)) z (limite (arredonde (jogador_z)) entre (0) e (15)))
|
||||
mova [jogador] para x (jogador_x) y (jogador_y) z (jogador_z)
|
||||
gire [jogador] para x (0) y (cam_yaw) z (0) graus
|
||||
mude [dir_x v] para ((seno de (cam_yaw)) * (cosseno de (cam_pitch)))
|
||||
mude [dir_y v] para (seno de (cam_pitch))
|
||||
mude [dir_z v] para ((cosseno de (cam_yaw)) * (cosseno de (cam_pitch)))
|
||||
câmera em x (jogador_x) y ((jogador_y) + (1.6)) z (jogador_z) olhando para x ((jogador_x) + (dir_x)) y (((jogador_y) + (1.6)) + (dir_y)) z ((jogador_z) + (dir_z))
|
||||
|
||||
define mova os aldeoes
|
||||
mude [t2 v] para ((cronômetro) * (25))
|
||||
mude [p1x v] para ((8) + ((5) * (seno de (t2))))
|
||||
mude [p1z v] para ((8) + ((5) * (cosseno de (t2))))
|
||||
mova [aldeao_1] para x (p1x) y (altura em x (limite (arredonde (p1x)) entre (0) e (15)) z (limite (arredonde (p1z)) entre (0) e (15))) z (p1z)
|
||||
gire [aldeao_1] para x (0) y ((t2) * (5)) z (0) graus
|
||||
mude [p2x v] para ((8) + ((6) * (seno de ((t2) + (120)))))
|
||||
mude [p2z v] para ((8) + ((6) * (cosseno de ((t2) + (120)))))
|
||||
mova [aldeao_2] para x (p2x) y (altura em x (limite (arredonde (p2x)) entre (0) e (15)) z (limite (arredonde (p2z)) entre (0) e (15))) z (p2z)
|
||||
gire [aldeao_2] para x (0) y ((t2) * (-4)) z (0) graus
|
||||
|
||||
define use os cliques
|
||||
se <mouse pressionado?> então
|
||||
se <(antes_e) = (0)> então
|
||||
mude [tx v] para (limite (arredonde ((jogador_x) + ((seno de (cam_yaw)) * (2)))) entre (0) e (15))
|
||||
mude [tz v] para (limite (arredonde ((jogador_z) + ((cosseno de (cam_yaw)) * (2)))) entre (0) e (15))
|
||||
mude [ty v] para ((altura em x (tx) z (tz)) + (1))
|
||||
mude [nm v] para (junte [bloco_] com (junte (tx) com (junte [_] com (junte (ty) com (junte [_] com (tz))))))
|
||||
crie cubo (nm) em x ((tx) + (0.5)) y ((ty) + (0.5)) z ((tz) + (0.5))
|
||||
use o material (item (sel) de (lista [blocos])) no objeto (nm)
|
||||
end
|
||||
mude [antes_e v] para (1)
|
||||
senão
|
||||
mude [antes_e v] para (0)
|
||||
end
|
||||
se <botão direito pressionado?> então
|
||||
se <(antes_d) = (0)> então
|
||||
mude [tx v] para (limite (arredonde ((jogador_x) + ((seno de (cam_yaw)) * (2)))) entre (0) e (15))
|
||||
mude [tz v] para (limite (arredonde ((jogador_z) + ((cosseno de (cam_yaw)) * (2)))) entre (0) e (15))
|
||||
mude [ty v] para ((altura em x (tx) z (tz)) + (1))
|
||||
mude [nm v] para (junte [bloco_] com (junte (tx) com (junte [_] com (junte (ty) com (junte [_] com (tz))))))
|
||||
apague o objeto (nm)
|
||||
end
|
||||
mude [antes_d v] para (1)
|
||||
senão
|
||||
mude [antes_d v] para (0)
|
||||
end
|
||||
se <tecla [e] pressionada?> então
|
||||
mude [tx v] para (limite (arredonde ((jogador_x) + ((seno de (cam_yaw)) * (2)))) entre (0) e (15))
|
||||
mude [tz v] para (limite (arredonde ((jogador_z) + ((cosseno de (cam_yaw)) * (2)))) entre (0) e (15))
|
||||
mude [ty v] para ((altura em x (tx) z (tz)) + (1))
|
||||
mude [nm v] para (junte [bloco_] com (junte (tx) com (junte [_] com (junte (ty) com (junte [_] com (tz))))))
|
||||
crie cubo (nm) em x ((tx) + (0.5)) y ((ty) + (0.5)) z ((tz) + (0.5))
|
||||
use o material (item (sel) de (lista [blocos])) no objeto (nm)
|
||||
end
|
||||
se <tecla [q] pressionada?> então
|
||||
mude [tx v] para (limite (arredonde ((jogador_x) + ((seno de (cam_yaw)) * (2)))) entre (0) e (15))
|
||||
mude [tz v] para (limite (arredonde ((jogador_z) + ((cosseno de (cam_yaw)) * (2)))) entre (0) e (15))
|
||||
mude [ty v] para ((altura em x (tx) z (tz)) + (1))
|
||||
mude [nm v] para (junte [bloco_] com (junte (tx) com (junte [_] com (junte (ty) com (junte [_] com (tz))))))
|
||||
apague o objeto (nm)
|
||||
end
|
||||
|
||||
define céu
|
||||
mude [dia v] para ((cronômetro) / (40))
|
||||
mude [dia v] para ((dia) - (arredonde (dia) para baixo))
|
||||
mude [sol v] para ((dia) * (360))
|
||||
mude [sl v] para (seno de (sol))
|
||||
mude [cl v] para (cosseno de (sol))
|
||||
luz vindo de x ((cl) * (0.6)) y (limite (sl) entre (0.15) e (1)) z (0.35)
|
||||
luz ambiente (limite (((sl) + (0.5)) * (0.75)) entre (0.15) e (0.72))
|
||||
mude [ki v] para ((arredonde ((dia) * (7))) + (1))
|
||||
cor do céu (item (ki) de (lista [ceus]))
|
||||
névoa de (12) até (30)
|
||||
|
||||
define barra de blocos
|
||||
mude a cor da caneta para r (20) g (20) b (28)
|
||||
desenhe retângulo em x (0) y (-158) largura (196) altura (38)
|
||||
mude a cor da caneta para r (250) g (210) b (90)
|
||||
desenhe retângulo em x ((((sel) - (1)) * (36)) + (-72)) y (-158) largura (34) altura (34)
|
||||
desenhe (img_b1) em x (-72) y (-158) escala (1.5)
|
||||
desenhe (img_b2) em x (-36) y (-158) escala (1.5)
|
||||
desenhe (img_b3) em x (0) y (-158) escala (1.5)
|
||||
desenhe (img_b4) em x (36) y (-158) escala (1.5)
|
||||
desenhe (img_b5) em x (72) y (-158) escala (1.5)
|
||||
|
||||
define monte uma árvore (ax) (az) (ah)
|
||||
mude [tm v] para (junte [arv_ma_] com (junte (ax) com (junte [_] com (az))))
|
||||
crie cubo (tm) em x ((ax) + (0.5)) y ((ah) + (1.5)) z ((az) + (0.5))
|
||||
mude o tamanho de (tm) para x (0.34) y (3) z (0.34)
|
||||
use o material [madeira] no objeto (tm)
|
||||
mude [tf v] para (junte [arv_fo_] com (junte (ax) com (junte [_] com (az))))
|
||||
crie cubo (tf) em x ((ax) + (0.5)) y ((ah) + (3.3)) z ((az) + (0.5))
|
||||
mude o tamanho de (tf) para x (2.6) y (2.2) z (2.6)
|
||||
use o material [folhas] no objeto (tf)
|
||||
|
||||
define plante a floresta
|
||||
mude [px v] para (2)
|
||||
repita (4) vezes
|
||||
mude [pz v] para (2)
|
||||
repita (4) vezes
|
||||
mude [hh v] para (altura em x (px) z (pz))
|
||||
se <(hh) > (1)> então
|
||||
monte uma árvore (px) (pz) (hh)
|
||||
end
|
||||
mude [pz v] para ((pz) + (4))
|
||||
end
|
||||
mude [px v] para ((px) + (4))
|
||||
end
|
||||
|
After Width: | Height: | Size: 101 B |
@@ -0,0 +1,13 @@
|
||||
when flag clicked
|
||||
nova cena 3D
|
||||
crie esfera [bola] em x (0) y (0.5) z (0)
|
||||
mude a cor de [bola] para [azul]
|
||||
mude [onda v] para (compile o shader)
|
||||
mude a posição do vértice para x ((x do vértice) * ((1) + ((0.25) * (seno de ((tempo) * (180)))))) y ((y do vértice) * ((1) + ((0.25) * (seno de ((tempo) * (180)))))) z ((z do vértice) * ((1) + ((0.25) * (seno de ((tempo) * (180))))))
|
||||
end
|
||||
use o shader (onda) no objeto [bola]
|
||||
câmera em x (0) y (3) z (6) olhando para x (0) y (0.5) z (0)
|
||||
sempre
|
||||
apague tudo
|
||||
desenhe (imagem da cena de (480) por (360)) em x (0) y (0) escala (1)
|
||||
end
|
||||
|
After Width: | Height: | Size: 433 B |
|
After Width: | Height: | Size: 275 B |
|
After Width: | Height: | Size: 335 B |
|
After Width: | Height: | Size: 494 B |
|
After Width: | Height: | Size: 492 B |
|
After Width: | Height: | Size: 415 B |
|
After Width: | Height: | Size: 438 B |
|
After Width: | Height: | Size: 424 B |
|
After Width: | Height: | Size: 427 B |
|
After Width: | Height: | Size: 354 B |
|
After Width: | Height: | Size: 496 B |
|
After Width: | Height: | Size: 544 B |
|
After Width: | Height: | Size: 516 B |
|
After Width: | Height: | Size: 503 B |
|
After Width: | Height: | Size: 494 B |
|
After Width: | Height: | Size: 471 B |
|
After Width: | Height: | Size: 278 B |
|
After Width: | Height: | Size: 337 B |
|
After Width: | Height: | Size: 371 B |
|
After Width: | Height: | Size: 501 B |
|
After Width: | Height: | Size: 394 B |
@@ -0,0 +1,17 @@
|
||||
when flag clicked
|
||||
nova cena 3D
|
||||
mude [tijolo v] para (carregue o PNG [tijolo.png])
|
||||
crie a textura [pedra] da imagem (tijolo)
|
||||
mude [relevo v] para (carregue o PNG [relevo.png])
|
||||
crie a textura [bump] da imagem (relevo)
|
||||
crie o material [rocha]
|
||||
no material [rocha] use a textura [pedra] como albedo
|
||||
no material [rocha] use a textura [bump] como normal
|
||||
crie cubo [caixa] em x (0) y (0.5) z (0)
|
||||
use o material [rocha] no objeto [caixa]
|
||||
câmera em x (3) y (3.5) z (5) olhando para x (0) y (0.5) z (0)
|
||||
sempre
|
||||
gire [caixa] por x (0) y (1) z (0) graus
|
||||
apague tudo
|
||||
desenhe (imagem da cena de (480) por (360)) em x (0) y (0) escala (1)
|
||||
end
|
||||
|
After Width: | Height: | Size: 93 B |
@@ -35,13 +35,17 @@ typedef enum {
|
||||
TB_DRAW_CLEAR_CLIP, /* remove clip */
|
||||
TB_DRAW_TEXT, /* texto (x,y=baseline-left; font_size em px) */
|
||||
TB_DRAW_IMAGE, /* imagem escalada em (x,y,w,h); ver field image */
|
||||
TB_DRAW_FILL_POLY, /* poligono convexo preenchido (antialias); os pontos *
|
||||
* ficam no espaco do text (tb_draw_poly_get/set), *
|
||||
* param = quantos; x,y,w,h = caixa que o contem */
|
||||
} TinyBlocks_DrawCmdKind;
|
||||
|
||||
typedef struct {
|
||||
TinyBlocks_DrawCmdKind kind;
|
||||
float x, y, w, h; /* geometria (significado varia por kind) */
|
||||
float r, g, b, a; /* cor RGBA [0..1] */
|
||||
float param; /* radius (rrect/circle), espessura (linha/stroke) */
|
||||
float param; /* radius (rrect/circle), espessura (linha/stroke); *
|
||||
* no TB_DRAW_TEXT, a fonte (TB_FONT_*) */
|
||||
float font_size; /* tamanho da fonte em pixels (TB_DRAW_TEXT) */
|
||||
char text[128]; /* conteúdo do texto (TB_DRAW_TEXT) */
|
||||
const TinyBlocks_Image* image; /* pixels (TB_DRAW_IMAGE, não-owning) */
|
||||
@@ -105,6 +109,28 @@ TB_API void tb_draw_text (TinyBlocks_RenderableBlock* rb,
|
||||
float x, float y, const char* text, float font_size,
|
||||
float r, float g, float b, float a);
|
||||
|
||||
/* Fontes do texto (param do TB_DRAW_TEXT). Os icones sao glifos do Material
|
||||
* Symbols (codepoints da area privada, ex.: U+E8B8 = "settings"); o backend
|
||||
* sem a fonte de icones nao desenha nada. */
|
||||
#define TB_FONT_REGULAR 0 /* Roboto Regular */
|
||||
#define TB_FONT_MEDIUM 1 /* Roboto Medium (rotulos, titulos) */
|
||||
#define TB_FONT_ICON 2 /* Material Symbols Outlined */
|
||||
#define TB_FONT_ICON_FILLED 3 /* Material Symbols (preenchido) */
|
||||
#define TB_FONT_COUNT 4
|
||||
|
||||
/* Poligono convexo (ate TB_POLY_MAX pontos; xy = x0,y0,x1,y1,...). Formas
|
||||
* inclinadas (hexagono, encaixe) ficam lisas em qualquer escala. */
|
||||
#define TB_POLY_MAX 16
|
||||
TB_API void tb_draw_fill_poly (TinyBlocks_RenderableBlock* rb, const float* xy, int n,
|
||||
float r, float g, float b, float a);
|
||||
/* Pontos de um TB_DRAW_FILL_POLY (quem transforma comandos usa os dois) */
|
||||
TB_API int tb_draw_poly_get (const TinyBlocks_DrawCmd* c, float* xy);
|
||||
TB_API void tb_draw_poly_set (TinyBlocks_DrawCmd* c, const float* xy, int n);
|
||||
|
||||
TB_API void tb_draw_text_font (TinyBlocks_RenderableBlock* rb,
|
||||
float x, float y, const char* text, float font_size, int font,
|
||||
float r, float g, float b, float a);
|
||||
|
||||
/* Desenha a imagem escalada para o retângulo (x,y,w,h). A imagem é
|
||||
* ref-counted; o comando apenas guarda um ponteiro não-owning, portanto a
|
||||
* imagem precisa continuar viva até o backend renderizar o frame. */
|
||||
|
||||
@@ -92,6 +92,14 @@ typedef struct TinyBlocks_InitOptions {
|
||||
TB_API bool tinyblocks_init (TinyBlocks** out_rt, const TinyBlocks_InitOptions* opts);
|
||||
TB_API void tinyblocks_deinit(TinyBlocks** rt);
|
||||
|
||||
/* -- Caminhos de arquivo --- */
|
||||
/* O aplicativo (ex.: o editor) define o diretorio-base do projeto aberto;
|
||||
os blocos que abrem arquivos resolvem caminhos relativos contra ele, para
|
||||
que um caminho como "atlas.png" ache o arquivo na pasta do projeto mesmo
|
||||
quando o processo roda de outro diretorio (ex.: AppImage aberto pelo menu). */
|
||||
TB_API void tb_path_set_base(const char* dir);
|
||||
TB_API const char* tb_path_resolve(const char* path, char* out, size_t out_n);
|
||||
|
||||
/* -- Registro interno (usado pelas implementações de bloco) --- */
|
||||
TB_API bool tb_rt_register_block (TinyBlocks* rt, TinyBlocks_Block* block);
|
||||
TB_API void tb_rt_unregister_block(TinyBlocks* rt, TinyBlocks_Block* block);
|
||||
|
||||
@@ -29,14 +29,17 @@
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
|
||||
#define TB_3D_LIB "tinyblocks-3d"
|
||||
#define TB_3D_RENDERER_VERSION 3
|
||||
#define TB_3D_RENDERER_VERSION 8
|
||||
|
||||
/* Malha: triangulos com posicao e normal (6 floats por vertice). As malhas
|
||||
da cena sao fixas (cubo, esfera, plano e cilindro de tamanho 1): o
|
||||
renderizador pode guarda-las na GPU pelo id. */
|
||||
/* Malha: triangulos com posicao, normal e uv (8 floats por vertice). Alem
|
||||
das malhas fixas (cubo, esfera, plano e cilindro de tamanho 1), o usuario
|
||||
monta malhas personalizadas com os blocos "crie a malha", "adicione o
|
||||
vertice/a normal/a texcoord" e "finalize a malha". O renderizador guarda
|
||||
a malha na GPU pelo id; quando o version muda, ele sobe de novo. */
|
||||
typedef struct Tb3dMesh {
|
||||
int id; /* 1.. (estavel enquanto a library viver) */
|
||||
const float* verts; /* x y z nx ny nz, vcount vezes */
|
||||
unsigned version; /* muda quando os dados mudam (malha personalizada) */
|
||||
const float* verts; /* x y z nx ny nz u v, vcount vezes */
|
||||
int vcount;
|
||||
const uint32_t* index; /* 3 por triangulo */
|
||||
int icount;
|
||||
@@ -44,18 +47,26 @@ typedef struct Tb3dMesh {
|
||||
|
||||
/* Shader compilado: o valor que o repórter "compile o shader [pilha]"
|
||||
devolve (um bloco-handle; guarde numa variável) e que "use o shader" põe
|
||||
num objeto. A 3d compila os blocos para o corpo de uma funcao GLSL (330
|
||||
e 450) e pede a cada renderizador disponivel o BINARIO dele
|
||||
(Tb3dRenderer.compile); o formato do binario so o renderizador conhece.
|
||||
num objeto. A pilha é de VÉRTICE ou de FRAGMENTO, e o "compile o shader"
|
||||
descobre sozinho pelo que a pilha usa:
|
||||
|
||||
vec3 tb_shade(vec3 P, vec3 N, vec3 base, float light, float time)
|
||||
vec3 tb_shade(vec3 P, vec3 N, vec3 L, vec2 UV, vec3 base, vec3 tex, float light, float time)
|
||||
vec3 tb_vert (vec3 P, vec3 N, vec3 L, vec2 UV, vec3 base, vec3 tex, float light, float time)
|
||||
|
||||
P = ponto no mundo, N = normal (normalizada), base = cor do objeto,
|
||||
light = ambiente + (1 - ambiente) * max(N . luz, 0), time = segundos;
|
||||
devolve a cor do pixel (0..1).
|
||||
No fragmento (estágio 0) P/N são o ponto e a normal no mundo e o shader
|
||||
devolve a COR do pixel (0..1); no vértice (estágio 1) P/N são a posição e
|
||||
a normal no espaço do objeto e o shader devolve a POSIÇÃO do vértice
|
||||
(ainda no espaço do objeto: a câmera e o mova/gire aplicam por cima).
|
||||
tex é a textura de albedo amostrada no UV (branco se o objeto não tem
|
||||
material com textura) — o bloco "textura do pixel" devolve isto.
|
||||
A 3d compila os blocos para o corpo da função GLSL (330 e 450) e pede a
|
||||
cada renderizador disponível o BINÁRIO dele (Tb3dRenderer.compile).
|
||||
light = ambiente + (1 - ambiente) * max(N . luz, 0); time = segundos.
|
||||
|
||||
id e unico por compilacao (o renderizador guarda o programa da placa por
|
||||
ele) e vale enquanto alguem usar o shader. */
|
||||
#define TB_3D_STAGE_FRAGMENT 0
|
||||
#define TB_3D_STAGE_VERTEX 1
|
||||
#define TB_3D_MAX_BINARIES 4
|
||||
typedef struct Tb3dBinary {
|
||||
char renderer[16]; /* Tb3dRenderer.name de quem compilou */
|
||||
@@ -66,11 +77,22 @@ typedef struct Tb3dBinary {
|
||||
typedef struct Tb3dShader {
|
||||
int id;
|
||||
int version; /* sempre 1 (cada compilacao tem outro id) */
|
||||
int stage; /* TB_3D_STAGE_FRAGMENT ou _VERTEX */
|
||||
const char* glsl;
|
||||
Tb3dBinary bin[TB_3D_MAX_BINARIES];
|
||||
int bin_n;
|
||||
} Tb3dShader;
|
||||
|
||||
/* Textura: uma imagem RGBA8 (linha 0 no ALTO), a mesma em todos os
|
||||
renderizadores. O id e estavel; o version muda quando os pixels mudam
|
||||
(o renderizador sobe de novo para a GPU). */
|
||||
typedef struct Tb3dTexture {
|
||||
int id;
|
||||
unsigned version;
|
||||
const uint8_t* rgba;
|
||||
int width, height;
|
||||
} Tb3dTexture;
|
||||
|
||||
/* Um objeto a desenhar */
|
||||
typedef struct Tb3dDraw {
|
||||
const Tb3dMesh* mesh;
|
||||
@@ -78,8 +100,10 @@ typedef struct Tb3dDraw {
|
||||
float mvp[16]; /* viewproj * model (ja calculada: os
|
||||
renderizadores nao precisam de matematica) */
|
||||
float normal[9]; /* matriz das normais (3x3, colunas) */
|
||||
float color[4]; /* RGBA 0..1 */
|
||||
const Tb3dShader* shader; /* NULL = a luz padrao (lambert por vertice) */
|
||||
float color[4]; /* RGB 0..1; A = opacidade (< 1: transparente) */
|
||||
const Tb3dShader* shader; /* NULL = a luz padrao (lambert por vertice) */
|
||||
const Tb3dTexture* albedo; /* NULL = sem textura (branco) */
|
||||
const Tb3dTexture* normaltex; /* NULL = sem normal map (usado depois) */
|
||||
} Tb3dDraw;
|
||||
|
||||
/* Um quadro: tudo o que o renderizador precisa */
|
||||
@@ -92,8 +116,17 @@ typedef struct Tb3dFrame {
|
||||
float light_dir[3]; /* direcao PARA a luz, normalizada */
|
||||
float ambient; /* 0..1 */
|
||||
float time; /* segundos desde a "nova cena 3D" */
|
||||
/* Nevoa: a cor do pixel vai para fog_color conforme a profundidade na
|
||||
camera (o w do clip), de fog_start (nada) a fog_end (so nevoa).
|
||||
fog_end <= fog_start = sem nevoa. */
|
||||
float fog_color[3];
|
||||
float fog_start, fog_end;
|
||||
/* Os draws vem com os opacos primeiro e, depois de opaque_count, os
|
||||
transparentes (color[3] < 1) do mais longe para o mais perto: o
|
||||
renderizador mistura esses com o fundo e nao grava a profundidade. */
|
||||
const Tb3dDraw* draws;
|
||||
int draw_count;
|
||||
int opaque_count;
|
||||
} Tb3dFrame;
|
||||
|
||||
/* Renderizador. render escreve width*height*4 bytes RGBA, linha 0 no ALTO. */
|
||||
@@ -109,7 +142,7 @@ typedef struct Tb3dRenderer {
|
||||
/* Binario do shader para esta placa, a partir do GLSL (tb_shade). data
|
||||
com malloc (a 3d libera com free). NULL = o renderizador nao guarda
|
||||
binario (compila na hora de desenhar). */
|
||||
bool (*compile)(const char* glsl, void** data, size_t* size, char* err, size_t cap);
|
||||
bool (*compile)(const char* glsl, int stage, void** data, size_t* size, char* err, size_t cap);
|
||||
} Tb3dRenderer;
|
||||
|
||||
TB_API const TinyBlocks_LibraryDescriptor* tb_3d_get_library(void);
|
||||
|
||||
@@ -12,18 +12,29 @@
|
||||
|
||||
typedef struct D3Program D3Program; /* o shader compilado (opaco) */
|
||||
|
||||
/* Estagio do shader: o "compile o shader" descobre sozinho (tem
|
||||
"mude a posicao do vertice" = vertice; "cor do pixel" = fragmento). */
|
||||
enum { D3_STAGE_NONE, D3_STAGE_FRAGMENT, D3_STAGE_VERTEX };
|
||||
|
||||
/* Compila a pilha (o codigo de um encaixe TB_SLOT_STACK, em JSON).
|
||||
NULL em erro, com a mensagem em err. */
|
||||
D3Program* d3_shader_compile(const TinyBlocks_JsonValue* stack, char* err, size_t cap);
|
||||
void d3_shader_free(D3Program* p);
|
||||
const char* d3_shader_glsl(const D3Program* p); /* a funcao tb_shade */
|
||||
const char* d3_shader_glsl(const D3Program* p); /* tb_shade ou tb_vert */
|
||||
int d3_shader_stage(const D3Program* p); /* D3_STAGE_* */
|
||||
|
||||
/* Entradas de um pixel e a cor que sai (o interpretador do software) */
|
||||
/* Entradas de um pixel/vertice e a cor que sai (interpretador do software).
|
||||
No fragmento P/N sao o ponto e a normal no mundo; no vertice, P e a
|
||||
posicao local (a que o shader de vertice devolve) e N a normal do objeto. */
|
||||
typedef struct {
|
||||
float P[3], N[3], base[3];
|
||||
float P[3], N[3], L[3]; /* ponto/vertice, normal, vertice local */
|
||||
float uv[2]; /* coordenada de textura */
|
||||
float base[3];
|
||||
float tex[3]; /* textura de albedo amostrada no uv */
|
||||
float light, time;
|
||||
} D3Pixel;
|
||||
void d3_shader_run(const D3Program* p, const D3Pixel* in, float out[3]);
|
||||
void d3_shader_run_vertex(const D3Program* p, const D3Pixel* in, float out[3]);
|
||||
|
||||
/* Cores por nome (vermelho, azul, dourado...) ou #rrggbb */
|
||||
bool d3_color_of(const char* name, float out[4]);
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
* Entrada: o codigo de uma pilha (JSON de um encaixe TB_SLOT_STACK, ver
|
||||
* tb_defs.h). Saida: uma arvore compacta (nos num vetor) com o tipo de
|
||||
* cada expressao (numero, cor ou condicao), de onde saem
|
||||
* - o GLSL da funcao tb_shade (OpenGL e Vulkan), e
|
||||
* - o GLSL da funcao tb_shade (fragmento) ou tb_vert (vertice), e
|
||||
* - o interpretador usado pelo renderizador em software.
|
||||
* O estagio sai sozinho: a pilha que usa "cor do pixel" e de fragmento; a
|
||||
* que usa "mude a posicao do vertice" e de vertice.
|
||||
*
|
||||
* Valores: numero (F), cor (V, tres canais) e condicao (B). Uma conta entre
|
||||
* cor e numero vale para os tres canais (como no GLSL). No interpretador um
|
||||
@@ -27,13 +29,13 @@ enum { TF, TV, TB }; /* numero, cor, condicao */
|
||||
|
||||
enum {
|
||||
/* expressoes */
|
||||
E_CONST, E_VAR, E_PIX, E_BASE, E_LIGHT, E_TIME, E_P, E_N, /* E_P/E_N: canal em k[0] */
|
||||
E_CONST, E_VAR, E_PIX, E_BASE, E_LIGHT, E_TIME, E_P, E_N, E_L, E_UV, E_TEX, /* canal em k[0] */
|
||||
E_RGB, E_ADD, E_SUB, E_MUL, E_DIV, E_MOD, E_MIN, E_MAX, E_POW, E_MIX, E_CLAMP,
|
||||
E_ABS, E_SQRT, E_FLOOR, E_CEIL, E_ROUND, E_SIN, E_COS, E_TAN, E_EXP, E_LN,
|
||||
E_CHAN, E_GRAY, /* E_CHAN: canal em k[0] */
|
||||
E_LT, E_EQ, E_GT, E_AND, E_OR, E_NOT,
|
||||
/* comandos */
|
||||
S_PIXEL, S_SET, S_IF,
|
||||
S_PIXEL, S_VPOS, S_SET, S_IF,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@@ -49,6 +51,7 @@ struct D3Program {
|
||||
Node* n;
|
||||
int nn, cap;
|
||||
int first; /* primeiro comando */
|
||||
int stage; /* D3_STAGE_* */
|
||||
char local[MAX_LOCALS][32];
|
||||
int ltype[MAX_LOCALS];
|
||||
int nl;
|
||||
@@ -187,11 +190,15 @@ static int expr(C* c, const TinyBlocks_JsonValue* j) {
|
||||
if (!strcmp(t, "Shader.ObjectColor")) return node(c, E_BASE, TV);
|
||||
if (!strcmp(t, "Shader.Light")) return node(c, E_LIGHT, TF);
|
||||
if (!strcmp(t, "Shader.Time")) return node(c, E_TIME, TF);
|
||||
const char* axes[] = { "Shader.X", "Shader.Y", "Shader.Z", "Shader.NX", "Shader.NY", "Shader.NZ" };
|
||||
for (int k = 0; k < 6; k++)
|
||||
if (!strcmp(t, "Shader.Texture")) return node(c, E_TEX, TV);
|
||||
const char* axes[] = { "Shader.X", "Shader.Y", "Shader.Z", "Shader.NX", "Shader.NY", "Shader.NZ",
|
||||
"Shader.VX", "Shader.VY", "Shader.VZ", "Shader.U", "Shader.V" };
|
||||
for (int k = 0; k < 11; k++)
|
||||
if (!strcmp(t, axes[k])) {
|
||||
int n = node(c, k < 3 ? E_P : E_N, TF);
|
||||
if (n >= 0) c->p->n[n].k[0] = (float)(k % 3);
|
||||
int op = k < 3 ? E_P : k < 6 ? E_N : k < 9 ? E_L : E_UV;
|
||||
int ch = k < 9 ? k % 3 : k - 9;
|
||||
int n = node(c, op, TF);
|
||||
if (n >= 0) c->p->n[n].k[0] = (float)ch;
|
||||
return n;
|
||||
}
|
||||
if (!strcmp(t, "Shader.Rgb")) {
|
||||
@@ -310,6 +317,8 @@ static int set_var(C* c, const TinyBlocks_JsonValue* j, bool change) {
|
||||
static int stmt(C* c, const TinyBlocks_JsonValue* j) {
|
||||
const char* t = jtype(j);
|
||||
if (!strcmp(t, "Shader.Pixel")) {
|
||||
if (c->p->stage == D3_STAGE_VERTEX) { fail(c, "\"cor do pixel\" não vale num shader de vértice"); return -1; }
|
||||
c->p->stage = D3_STAGE_FRAGMENT;
|
||||
int e = expr_in(c, j, 0);
|
||||
if (e < 0) return -1;
|
||||
if (c->p->n[e].type == TB) { fail(c, "\"cor do pixel =\" recebe uma cor ou um número"); return -1; }
|
||||
@@ -317,6 +326,22 @@ static int stmt(C* c, const TinyBlocks_JsonValue* j) {
|
||||
if (n >= 0) c->p->n[n].a = e;
|
||||
return n;
|
||||
}
|
||||
if (!strcmp(t, "Shader.Vertex")) {
|
||||
if (c->p->stage == D3_STAGE_FRAGMENT) { fail(c, "\"mude a posição do vértice\" não vale num shader de fragmento"); return -1; }
|
||||
c->p->stage = D3_STAGE_VERTEX;
|
||||
int a = expr_in(c, j, 0), b = expr_in(c, j, 1), d = expr_in(c, j, 2);
|
||||
if (a < 0 || b < 0 || d < 0) return -1;
|
||||
if (c->p->n[a].type != TF || c->p->n[b].type != TF || c->p->n[d].type != TF) {
|
||||
fail(c, "\"mude a posição do vértice\" recebe três números");
|
||||
return -1;
|
||||
}
|
||||
int e = node(c, E_RGB, TV);
|
||||
if (e < 0) return -1;
|
||||
c->p->n[e].a = a; c->p->n[e].b = b; c->p->n[e].c = d;
|
||||
int n = node(c, S_VPOS, -1);
|
||||
if (n >= 0) c->p->n[n].a = e;
|
||||
return n;
|
||||
}
|
||||
if (!strcmp(t, "Variables.Set")) return set_var(c, j, false);
|
||||
if (!strcmp(t, "Variables.Change")) return set_var(c, j, true);
|
||||
if (!strcmp(t, "Control.If") || !strcmp(t, "Control.IfElse")) {
|
||||
@@ -398,6 +423,9 @@ static void gx(const D3Program* p, Str* o, int i) {
|
||||
case E_TIME: put(o, "time"); break;
|
||||
case E_P: put(o, "P.%c", ch[(int)x->k[0]]); break;
|
||||
case E_N: put(o, "N.%c", ch[(int)x->k[0]]); break;
|
||||
case E_L: put(o, "L.%c", ch[(int)x->k[0]]); break;
|
||||
case E_UV: put(o, "UV.%c", ch[(int)x->k[0]]); break;
|
||||
case E_TEX: put(o, "tex"); break;
|
||||
case E_RGB: put(o, "vec3("); gx(p, o, x->a); put(o, ", "); gx(p, o, x->b); put(o, ", "); gx(p, o, x->c); put(o, ")"); break;
|
||||
case E_ADD: case E_SUB: case E_MUL: case E_DIV:
|
||||
put(o, "("); gx(p, o, x->a);
|
||||
@@ -438,6 +466,7 @@ static void gs(const D3Program* p, Str* o, int i, int depth) {
|
||||
const Node* x = &p->n[i];
|
||||
put(o, "%*s", depth * 4, "");
|
||||
if (x->op == S_PIXEL) { put(o, "pix = "); gv(p, o, x->a, true); put(o, ";\n"); }
|
||||
else if (x->op == S_VPOS) { put(o, "vpos = "); gv(p, o, x->a, true); put(o, ";\n"); }
|
||||
else if (x->op == S_SET) { put(o, "l%d = ", x->var); gx(p, o, x->a); put(o, ";\n"); }
|
||||
else if (x->op == S_IF) {
|
||||
put(o, "if "); gx(p, o, x->a); put(o, " {\n");
|
||||
@@ -451,12 +480,17 @@ static void gs(const D3Program* p, Str* o, int i, int depth) {
|
||||
|
||||
static char* emit_glsl(const D3Program* p) {
|
||||
Str o = {0};
|
||||
put(&o, "vec3 tb_shade(vec3 P, vec3 N, vec3 base, float light, float time) {\n");
|
||||
put(&o, " vec3 pix = base * light;\n");
|
||||
if (p->stage == D3_STAGE_VERTEX) {
|
||||
put(&o, "vec3 tb_vert(vec3 P, vec3 N, vec3 L, vec2 UV, vec3 base, vec3 tex, float light, float time) {\n");
|
||||
put(&o, " vec3 vpos = P;\n");
|
||||
} else {
|
||||
put(&o, "vec3 tb_shade(vec3 P, vec3 N, vec3 L, vec2 UV, vec3 base, vec3 tex, float light, float time) {\n");
|
||||
put(&o, " vec3 pix = base * light;\n");
|
||||
}
|
||||
for (int i = 0; i < p->nl; i++)
|
||||
put(&o, p->ltype[i] == TV ? " vec3 l%d = vec3(0.0);\n" : " float l%d = 0.0;\n", i);
|
||||
gs(p, &o, p->first, 1);
|
||||
put(&o, " return clamp(pix, 0.0, 1.0);\n}\n");
|
||||
put(&o, p->stage == D3_STAGE_VERTEX ? " return vpos;\n}\n" : " return clamp(pix, 0.0, 1.0);\n}\n");
|
||||
return o.s;
|
||||
}
|
||||
|
||||
@@ -468,7 +502,8 @@ D3Program* d3_shader_compile(const TinyBlocks_JsonValue* stack, char* err, size_
|
||||
C c = { p, err, cap, false };
|
||||
if (!stack || tb_json_kind(stack) != TB_JSON_ARRAY) fail(&c, "encaixe uma pilha de blocos de shader");
|
||||
else p->first = stmts(&c, stack);
|
||||
if (!c.failed && p->first < 0) fail(&c, "o shader está vazio (use \"cor do pixel = ...\")");
|
||||
if (!c.failed && p->stage == D3_STAGE_NONE)
|
||||
fail(&c, "o shader está vazio (use \"cor do pixel = ...\" ou \"mude a posição do vértice para ...\")");
|
||||
if (!c.failed) {
|
||||
p->glsl = emit_glsl(p);
|
||||
if (!p->glsl) fail(&c, "sem memória");
|
||||
@@ -485,9 +520,10 @@ void d3_shader_free(D3Program* p) {
|
||||
}
|
||||
|
||||
const char* d3_shader_glsl(const D3Program* p) { return p ? p->glsl : ""; }
|
||||
int d3_shader_stage(const D3Program* p) { return p ? p->stage : D3_STAGE_NONE; }
|
||||
|
||||
/* == Interpretador (software): cada valor e um float[3] ================ */
|
||||
typedef struct { const D3Pixel* in; float pix[3]; float loc[MAX_LOCALS][3]; } Run;
|
||||
typedef struct { const D3Pixel* in; float pix[3]; float vpos[3]; float loc[MAX_LOCALS][3]; } Run;
|
||||
|
||||
static float fmod_glsl(float a, float b) { return b == 0 ? 0 : a - b * floorf(a / b); }
|
||||
|
||||
@@ -504,6 +540,9 @@ static void ev(const D3Program* p, Run* r, int i, float o[3]) {
|
||||
case E_TIME: o[0] = o[1] = o[2] = r->in->time; return;
|
||||
case E_P: o[0] = o[1] = o[2] = r->in->P[(int)x->k[0]]; return;
|
||||
case E_N: o[0] = o[1] = o[2] = r->in->N[(int)x->k[0]]; return;
|
||||
case E_L: o[0] = o[1] = o[2] = r->in->L[(int)x->k[0]]; return;
|
||||
case E_UV: o[0] = o[1] = o[2] = r->in->uv[(int)x->k[0]]; return;
|
||||
case E_TEX: memcpy(o, r->in->tex, sizeof(r->in->tex)); return;
|
||||
case E_RGB: ev(p, r, x->a, a); ev(p, r, x->b, b); ev(p, r, x->c, c); o[0] = a[0]; o[1] = b[0]; o[2] = c[0]; return;
|
||||
case E_CHAN: ev(p, r, x->a, a); o[0] = o[1] = o[2] = a[(int)x->k[0]]; return;
|
||||
case E_GRAY: ev(p, r, x->a, a); o[0] = o[1] = o[2] = a[0] * 0.299f + a[1] * 0.587f + a[2] * 0.114f; return;
|
||||
@@ -551,6 +590,7 @@ static void ex(const D3Program* p, Run* r, int i) {
|
||||
for (; i >= 0; i = p->n[i].next) {
|
||||
const Node* x = &p->n[i];
|
||||
if (x->op == S_PIXEL) ev(p, r, x->a, r->pix);
|
||||
else if (x->op == S_VPOS) ev(p, r, x->a, r->vpos);
|
||||
else if (x->op == S_SET) ev(p, r, x->a, r->loc[x->var]);
|
||||
else if (x->op == S_IF) {
|
||||
float c[3];
|
||||
@@ -568,3 +608,13 @@ void d3_shader_run(const D3Program* p, const D3Pixel* in, float out[3]) {
|
||||
ex(p, &r, p->first);
|
||||
for (int k = 0; k < 3; k++) out[k] = fminf(fmaxf(r.pix[k], 0.f), 1.f);
|
||||
}
|
||||
|
||||
void d3_shader_run_vertex(const D3Program* p, const D3Pixel* in, float out[3]) {
|
||||
Run r;
|
||||
r.in = in;
|
||||
memcpy(r.vpos, in->P, sizeof(r.vpos));
|
||||
for (int k = 0; k < 3; k++) r.pix[k] = in->base[k] * in->light;
|
||||
memset(r.loc, 0, sizeof(float) * 3 * (size_t)(p->nl ? p->nl : 1));
|
||||
ex(p, &r, p->first);
|
||||
memcpy(out, r.vpos, sizeof(r.vpos));
|
||||
}
|
||||
@@ -91,10 +91,10 @@ static void rot3(float r[9], const float deg[3]) {
|
||||
/* == Malhas fixas (tamanho 1, centradas na origem) ===================== */
|
||||
typedef struct { float* v; uint32_t* ix; int vn, in, vcap, icap; } MeshBuf;
|
||||
|
||||
static void mb_vert(MeshBuf* b, float x, float y, float z, float nx, float ny, float nz) {
|
||||
if (b->vn == b->vcap) { b->vcap = b->vcap ? b->vcap * 2 : 64; b->v = realloc(b->v, (size_t)b->vcap * 6 * sizeof(float)); }
|
||||
float* p = b->v + (size_t)b->vn * 6;
|
||||
p[0] = x; p[1] = y; p[2] = z; p[3] = nx; p[4] = ny; p[5] = nz;
|
||||
static void mb_vert(MeshBuf* b, float x, float y, float z, float nx, float ny, float nz, float u, float v) {
|
||||
if (b->vn == b->vcap) { b->vcap = b->vcap ? b->vcap * 2 : 64; b->v = realloc(b->v, (size_t)b->vcap * 8 * sizeof(float)); }
|
||||
float* p = b->v + (size_t)b->vn * 8;
|
||||
p[0] = x; p[1] = y; p[2] = z; p[3] = nx; p[4] = ny; p[5] = nz; p[6] = u; p[7] = v;
|
||||
b->vn++;
|
||||
}
|
||||
static void mb_tri(MeshBuf* b, int i0, int i1, int i2) {
|
||||
@@ -102,7 +102,7 @@ static void mb_tri(MeshBuf* b, int i0, int i1, int i2) {
|
||||
b->ix[b->in++] = (uint32_t)i0; b->ix[b->in++] = (uint32_t)i1; b->ix[b->in++] = (uint32_t)i2;
|
||||
}
|
||||
|
||||
enum { K_CUBE, K_SPHERE, K_PLANE, K_CYLINDER, K_COUNT };
|
||||
enum { K_CUBE, K_SPHERE, K_PLANE, K_CYLINDER, K_COUNT, K_CUSTOM };
|
||||
static Tb3dMesh s_mesh[K_COUNT];
|
||||
static MeshBuf s_mb[K_COUNT];
|
||||
|
||||
@@ -116,7 +116,7 @@ static void build_cube(MeshBuf* b) {
|
||||
for (int k = 0; k < 4; k++) {
|
||||
float su = (k == 1 || k == 2) ? 0.5f : -0.5f, sv = (k >= 2) ? 0.5f : -0.5f;
|
||||
mb_vert(b, N[0] * 0.5f + U[0] * su + V[0] * sv, N[1] * 0.5f + U[1] * su + V[1] * sv,
|
||||
N[2] * 0.5f + U[2] * su + V[2] * sv, N[0], N[1], N[2]);
|
||||
N[2] * 0.5f + U[2] * su + V[2] * sv, N[0], N[1], N[2], su + 0.5f, sv + 0.5f);
|
||||
}
|
||||
mb_tri(b, base, base + 1, base + 2);
|
||||
mb_tri(b, base, base + 2, base + 3);
|
||||
@@ -129,7 +129,7 @@ static void build_sphere(MeshBuf* b, int seg, int ring) {
|
||||
for (int s = 0; s <= seg; s++) {
|
||||
float ph = 2 * PI_F * s / seg;
|
||||
float x = sinf(th) * cosf(ph), y = cosf(th), z = sinf(th) * sinf(ph);
|
||||
mb_vert(b, x * 0.5f, y * 0.5f, z * 0.5f, x, y, z);
|
||||
mb_vert(b, x * 0.5f, y * 0.5f, z * 0.5f, x, y, z, (float)s / seg, 1.f - (float)r / ring);
|
||||
}
|
||||
}
|
||||
for (int r = 0; r < ring; r++)
|
||||
@@ -141,10 +141,10 @@ static void build_sphere(MeshBuf* b, int seg, int ring) {
|
||||
}
|
||||
|
||||
static void build_plane(MeshBuf* b) {
|
||||
mb_vert(b, -0.5f, 0, -0.5f, 0, 1, 0);
|
||||
mb_vert(b, -0.5f, 0, 0.5f, 0, 1, 0);
|
||||
mb_vert(b, 0.5f, 0, 0.5f, 0, 1, 0);
|
||||
mb_vert(b, 0.5f, 0, -0.5f, 0, 1, 0);
|
||||
mb_vert(b, -0.5f, 0, -0.5f, 0, 1, 0, 0, 0);
|
||||
mb_vert(b, -0.5f, 0, 0.5f, 0, 1, 0, 0, 1);
|
||||
mb_vert(b, 0.5f, 0, 0.5f, 0, 1, 0, 1, 1);
|
||||
mb_vert(b, 0.5f, 0, -0.5f, 0, 1, 0, 1, 0);
|
||||
mb_tri(b, 0, 1, 2);
|
||||
mb_tri(b, 0, 2, 3);
|
||||
}
|
||||
@@ -152,8 +152,8 @@ static void build_plane(MeshBuf* b) {
|
||||
static void build_cylinder(MeshBuf* b, int seg) {
|
||||
for (int s = 0; s <= seg; s++) { /* lateral */
|
||||
float ph = 2 * PI_F * s / seg, x = cosf(ph), z = sinf(ph);
|
||||
mb_vert(b, x * 0.5f, -0.5f, z * 0.5f, x, 0, z);
|
||||
mb_vert(b, x * 0.5f, 0.5f, z * 0.5f, x, 0, z);
|
||||
mb_vert(b, x * 0.5f, -0.5f, z * 0.5f, x, 0, z, (float)s / seg, 0);
|
||||
mb_vert(b, x * 0.5f, 0.5f, z * 0.5f, x, 0, z, (float)s / seg, 1);
|
||||
}
|
||||
for (int s = 0; s < seg; s++) {
|
||||
int a = s * 2;
|
||||
@@ -163,10 +163,10 @@ static void build_cylinder(MeshBuf* b, int seg) {
|
||||
for (int cap = 0; cap < 2; cap++) { /* tampas */
|
||||
float y = cap ? 0.5f : -0.5f, ny = cap ? 1.f : -1.f;
|
||||
int c = b->vn;
|
||||
mb_vert(b, 0, y, 0, 0, ny, 0);
|
||||
mb_vert(b, 0, y, 0, 0, ny, 0, 0.5f, 0.5f);
|
||||
for (int s = 0; s <= seg; s++) {
|
||||
float ph = 2 * PI_F * s / seg;
|
||||
mb_vert(b, cosf(ph) * 0.5f, y, sinf(ph) * 0.5f, 0, ny, 0);
|
||||
mb_vert(b, cosf(ph) * 0.5f, y, sinf(ph) * 0.5f, 0, ny, 0, cosf(ph) * 0.5f + 0.5f, sinf(ph) * 0.5f + 0.5f);
|
||||
}
|
||||
for (int s = 0; s < seg; s++) {
|
||||
if (cap) mb_tri(b, c, c + 2 + s, c + 1 + s);
|
||||
@@ -182,7 +182,7 @@ static void meshes_build(void) {
|
||||
build_plane(&s_mb[K_PLANE]);
|
||||
build_cylinder(&s_mb[K_CYLINDER], 24);
|
||||
for (int k = 0; k < K_COUNT; k++)
|
||||
s_mesh[k] = (Tb3dMesh){ k + 1, s_mb[k].v, s_mb[k].vn, s_mb[k].ix, s_mb[k].in };
|
||||
s_mesh[k] = (Tb3dMesh){ k + 1, 1u, s_mb[k].v, s_mb[k].vn, s_mb[k].ix, s_mb[k].in };
|
||||
}
|
||||
|
||||
static void meshes_free(void) {
|
||||
@@ -191,14 +191,39 @@ static void meshes_free(void) {
|
||||
}
|
||||
|
||||
/* == Cena =============================================================== */
|
||||
/* Malha personalizada em construcao: os blocos vao empilhando vertices,
|
||||
normais, texcoords e triangulos; "finalize a malha" vira os arrays que o
|
||||
renderizador desenha. Normais vazias sao calculadas das faces. */
|
||||
typedef struct {
|
||||
float* v; int vn, vcap; /* x y z por vertice */
|
||||
float* n; int nn, ncap; /* nx ny nz por vertice */
|
||||
float* t; int tn, tcap; /* u v por vertice */
|
||||
int* f; int fn, fcap; /* 3 indices por triangulo (1-based) */
|
||||
} MeshBuild;
|
||||
|
||||
typedef struct Mat Mat; /* material (texturas + cor) */
|
||||
|
||||
typedef struct {
|
||||
char name[48];
|
||||
int kind;
|
||||
float pos[3], rot[3], scale[3], color[4];
|
||||
bool visible;
|
||||
struct Shd* shader; /* NULL = luz padrao */
|
||||
Mat* material; /* NULL = sem material (cor pura) */
|
||||
MeshBuild mb; /* malha personalizada (K_CUSTOM) */
|
||||
Tb3dMesh mesh; /* a malha finalizada */
|
||||
float bmin[3], bmax[3]; /* caixa local ("encosta em") */
|
||||
} Obj;
|
||||
|
||||
static void mesh_clear(Obj* o) {
|
||||
free(o->mb.v); free(o->mb.n); free(o->mb.t); free(o->mb.f);
|
||||
memset(&o->mb, 0, sizeof(o->mb));
|
||||
free((void*)o->mesh.verts); free((void*)o->mesh.index);
|
||||
memset(&o->mesh, 0, sizeof(o->mesh));
|
||||
o->bmin[0] = o->bmin[1] = o->bmin[2] = 0;
|
||||
o->bmax[0] = o->bmax[1] = o->bmax[2] = 0;
|
||||
}
|
||||
|
||||
/* Shader compilado ("compile o shader [pilha]"): o valor que viaja num
|
||||
bloco-handle; o handle e cada objeto que o usa guardam uma referencia. */
|
||||
typedef struct Shd {
|
||||
@@ -207,6 +232,7 @@ typedef struct Shd {
|
||||
int refs;
|
||||
} Shd;
|
||||
static int s_shd_seq; /* ids unicos por compilacao */
|
||||
static int s_mesh_seq = 5; /* ids unicos de malha (1..4 sao fixas) */
|
||||
|
||||
static Shd* shd_retain(Shd* s) { if (s) s->refs++; return s; }
|
||||
static void shd_release(Shd* s) {
|
||||
@@ -216,6 +242,95 @@ static void shd_release(Shd* s) {
|
||||
free(s);
|
||||
}
|
||||
|
||||
/* Textura ("crie a textura [nome] da imagem [img]"): guarda a imagem e uma
|
||||
copia RGBA8 (linha 0 no alto) que os renderizadores sobem para a GPU. */
|
||||
typedef struct Tex {
|
||||
Tb3dTexture pub; /* primeiro: o renderizador ve so isto */
|
||||
char name[48];
|
||||
TinyBlocks_Image* img;
|
||||
uint8_t* rgba;
|
||||
int refs;
|
||||
} Tex;
|
||||
struct Mat {
|
||||
char name[48];
|
||||
Tex* albedo;
|
||||
Tex* normal;
|
||||
float tint[3]; /* multiplica a cor do objeto */
|
||||
};
|
||||
|
||||
static struct { Tex** t; int n, cap; } s_tex;
|
||||
static struct { Mat** m; int n, cap; } s_mat;
|
||||
static int s_tex_seq; /* ids unicos por textura */
|
||||
|
||||
static void tex_release(Tex* t) {
|
||||
if (!t || --t->refs > 0) return;
|
||||
if (t->img) tb_image_release(t->img);
|
||||
free(t->rgba);
|
||||
free(t);
|
||||
}
|
||||
|
||||
static void textures_clear(void) {
|
||||
for (int i = 0; i < s_tex.n; i++) tex_release(s_tex.t[i]);
|
||||
s_tex.n = 0;
|
||||
for (int i = 0; i < s_mat.n; i++) {
|
||||
tex_release(s_mat.m[i]->albedo);
|
||||
tex_release(s_mat.m[i]->normal);
|
||||
free(s_mat.m[i]);
|
||||
}
|
||||
s_mat.n = 0;
|
||||
}
|
||||
|
||||
static Mat* mat_get(const char* name, bool create) {
|
||||
for (int i = 0; i < s_mat.n; i++) if (!strcmp(s_mat.m[i]->name, name)) return s_mat.m[i];
|
||||
if (!create) return NULL;
|
||||
if (s_mat.n == s_mat.cap) {
|
||||
int nc = s_mat.cap ? s_mat.cap * 2 : 8;
|
||||
Mat** q = realloc(s_mat.m, (size_t)nc * sizeof(*q));
|
||||
if (!q) return NULL;
|
||||
s_mat.m = q; s_mat.cap = nc;
|
||||
}
|
||||
Mat* m = calloc(1, sizeof(*m));
|
||||
if (!m) return NULL;
|
||||
snprintf(m->name, sizeof(m->name), "%s", name);
|
||||
m->tint[0] = m->tint[1] = m->tint[2] = 1.f;
|
||||
s_mat.m[s_mat.n++] = m;
|
||||
return m;
|
||||
}
|
||||
|
||||
static Tex* tex_get(const char* name) {
|
||||
for (int i = 0; i < s_tex.n; i++) if (!strcmp(s_tex.t[i]->name, name)) return s_tex.t[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Converte a imagem para RGBA8 (linha 0 no alto), como os renderizadores querem */
|
||||
static void tex_from_image(Tex* t, TinyBlocks_Image* img) {
|
||||
if (t->img) tb_image_release(t->img);
|
||||
t->img = NULL;
|
||||
free(t->rgba);
|
||||
t->rgba = NULL;
|
||||
t->pub.rgba = NULL;
|
||||
t->pub.width = t->pub.height = 0;
|
||||
if (!img) return;
|
||||
int w = tb_image_width(img), h = tb_image_height(img);
|
||||
if (w <= 0 || h <= 0) return;
|
||||
uint8_t* p = malloc((size_t)w * h * 4);
|
||||
if (!p) return;
|
||||
for (int y = 0; y < h; y++)
|
||||
for (int x = 0; x < w; x++) {
|
||||
uint8_t r, g, b, a;
|
||||
tb_image_get_pixel(img, x, y, &r, &g, &b, &a);
|
||||
uint8_t* q = p + ((size_t)y * w + x) * 4;
|
||||
q[0] = r; q[1] = g; q[2] = b; q[3] = a;
|
||||
}
|
||||
t->img = img;
|
||||
tb_image_retain(img);
|
||||
t->rgba = p;
|
||||
t->pub.rgba = p;
|
||||
t->pub.width = w;
|
||||
t->pub.height = h;
|
||||
t->pub.version++;
|
||||
}
|
||||
|
||||
static double now_s(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
@@ -228,14 +343,16 @@ static struct {
|
||||
int n, cap;
|
||||
float eye[3], at[3], fov;
|
||||
float light[3], ambient, sky[4];
|
||||
float fog_start, fog_end; /* nevoa (fim <= inicio = sem) */
|
||||
char want[16]; /* "" = automatico */
|
||||
char used[64], err[160];
|
||||
double t0; /* "nova cena 3D" (o "tempo" dos shaders) */
|
||||
} S;
|
||||
|
||||
static void scene_reset(void) {
|
||||
for (int i = 0; i < S.n; i++) shd_release(S.o[i].shader);
|
||||
for (int i = 0; i < S.n; i++) { shd_release(S.o[i].shader); mesh_clear(&S.o[i]); }
|
||||
S.n = 0;
|
||||
textures_clear();
|
||||
S.eye[0] = 0; S.eye[1] = 6; S.eye[2] = 10;
|
||||
S.at[0] = S.at[1] = S.at[2] = 0;
|
||||
S.fov = 60;
|
||||
@@ -243,6 +360,7 @@ static void scene_reset(void) {
|
||||
v3_norm(S.light);
|
||||
S.ambient = 0.35f;
|
||||
S.sky[0] = 0.53f; S.sky[1] = 0.78f; S.sky[2] = 0.98f; S.sky[3] = 1;
|
||||
S.fog_start = S.fog_end = 0;
|
||||
S.t0 = now_s();
|
||||
}
|
||||
|
||||
@@ -291,6 +409,21 @@ static void obj_matrices(const Obj* o, float model[16], float normal[9]) {
|
||||
static void obj_aabb(const Obj* o, float lo[3], float hi[3]) {
|
||||
float r[9];
|
||||
rot3(r, o->rot);
|
||||
if (o->kind == K_CUSTOM) {
|
||||
float c[3], h[3], cw[3], e[3] = { 0, 0, 0 };
|
||||
for (int k = 0; k < 3; k++) {
|
||||
c[k] = (o->bmin[k] + o->bmax[k]) * 0.5f;
|
||||
h[k] = (o->bmax[k] - o->bmin[k]) * 0.5f;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
float s = 0;
|
||||
for (int j = 0; j < 3; j++) s += r[j * 3 + i] * (c[j] * o->scale[j]);
|
||||
cw[i] = s;
|
||||
for (int j = 0; j < 3; j++) e[i] += fabsf(r[j * 3 + i] * o->scale[j]) * h[j];
|
||||
}
|
||||
for (int i = 0; i < 3; i++) { lo[i] = o->pos[i] + cw[i] - e[i]; hi[i] = o->pos[i] + cw[i] + e[i]; }
|
||||
return;
|
||||
}
|
||||
float h[3] = { fabsf(o->scale[0]) * 0.5f, fabsf(o->scale[1]) * 0.5f, fabsf(o->scale[2]) * 0.5f };
|
||||
if (o->kind == K_PLANE) h[1] = 0.01f;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -304,6 +437,13 @@ static void obj_aabb(const Obj* o, float lo[3], float hi[3]) {
|
||||
static Tb3dDraw* s_draws;
|
||||
static int s_draws_cap;
|
||||
|
||||
/* Distancia (ao quadrado) do centro do objeto ao olho: ordem dos transparentes */
|
||||
static float draw_depth(const Tb3dDraw* d, const float eye[3]) {
|
||||
float c[3];
|
||||
for (int k = 0; k < 3; k++) c[k] = d->model[12 + k] - eye[k];
|
||||
return c[0] * c[0] + c[1] * c[1] + c[2] * c[2];
|
||||
}
|
||||
|
||||
static bool frame_build(Tb3dFrame* f, int w, int h) {
|
||||
meshes_build();
|
||||
memset(f, 0, sizeof(*f));
|
||||
@@ -316,6 +456,9 @@ static bool frame_build(Tb3dFrame* f, int w, int h) {
|
||||
memcpy(f->light_dir, S.light, sizeof(f->light_dir));
|
||||
f->ambient = S.ambient;
|
||||
f->time = (float)(now_s() - S.t0);
|
||||
memcpy(f->fog_color, S.sky, sizeof(f->fog_color)); /* a nevoa some no ceu */
|
||||
f->fog_start = S.fog_start;
|
||||
f->fog_end = S.fog_end;
|
||||
if (S.n > s_draws_cap) {
|
||||
Tb3dDraw* d = realloc(s_draws, (size_t)S.n * sizeof(*d));
|
||||
if (!d) return false;
|
||||
@@ -326,31 +469,82 @@ static bool frame_build(Tb3dFrame* f, int w, int h) {
|
||||
const Obj* o = &S.o[i];
|
||||
if (!o->visible) continue;
|
||||
Tb3dDraw* d = &s_draws[n++];
|
||||
d->mesh = &s_mesh[o->kind];
|
||||
if (o->kind == K_CUSTOM) {
|
||||
if (o->mesh.icount <= 0) { n--; continue; }
|
||||
d->mesh = &o->mesh;
|
||||
} else {
|
||||
d->mesh = &s_mesh[o->kind];
|
||||
}
|
||||
obj_matrices(o, d->model, d->normal);
|
||||
tb_3d_mat_mul(d->mvp, f->viewproj, d->model);
|
||||
memcpy(d->color, o->color, sizeof(d->color));
|
||||
d->shader = o->shader ? &o->shader->pub : NULL;
|
||||
d->albedo = (o->material && o->material->albedo) ? &o->material->albedo->pub : NULL;
|
||||
d->normaltex = (o->material && o->material->normal) ? &o->material->normal->pub : NULL;
|
||||
if (o->material)
|
||||
for (int k = 0; k < 3; k++) d->color[k] = o->color[k] * o->material->tint[k];
|
||||
}
|
||||
/* opacos primeiro; os transparentes no fim, do mais longe ao mais perto */
|
||||
int no = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
if (s_draws[i].color[3] >= 0.999f) {
|
||||
Tb3dDraw t = s_draws[i]; s_draws[i] = s_draws[no]; s_draws[no] = t;
|
||||
no++;
|
||||
}
|
||||
for (int i = no + 1; i < n; i++) { /* insercao: poucos transparentes */
|
||||
Tb3dDraw t = s_draws[i];
|
||||
float dt = draw_depth(&t, S.eye);
|
||||
int j = i - 1;
|
||||
while (j >= no && draw_depth(&s_draws[j], S.eye) < dt) { s_draws[j + 1] = s_draws[j]; j--; }
|
||||
s_draws[j + 1] = t;
|
||||
}
|
||||
f->draws = s_draws;
|
||||
f->draw_count = n;
|
||||
f->opaque_count = no;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* == Rasterizador em software ======================================== */
|
||||
/* Vertice no clip + cor (luz por vertice) + ponto e normal no mundo (shader).
|
||||
Tudo float, para o corte no plano de perto interpolar campo a campo. */
|
||||
typedef struct { float x, y, z, w, r, g, b, P[3], N[3]; } CV;
|
||||
typedef struct { float x, y, z, w, r, g, b, P[3], N[3], No[3], L[3], uv[2]; } CV;
|
||||
#define CV_N ((int)(sizeof(CV) / sizeof(float)))
|
||||
|
||||
/* Quem o rasterizador esta desenhando agora (shader do objeto) */
|
||||
static const D3Program* s_prog;
|
||||
static const D3Program* s_vprog; /* shader de vertice (ou NULL) */
|
||||
static const Tb3dTexture* s_albedo; /* textura do objeto (ou NULL) */
|
||||
static const Tb3dTexture* s_normal; /* normal map do objeto (ou NULL) */
|
||||
static const Tb3dFrame* s_frame;
|
||||
static float s_base[3];
|
||||
static float s_nmat[9]; /* matriz das normais (objeto -> mundo) */
|
||||
|
||||
static float s_alpha = 1.f; /* opacidade do objeto (< 1: mistura, sem z) */
|
||||
|
||||
static float* s_zbuf;
|
||||
static size_t s_zcap;
|
||||
|
||||
/* Amostra a textura (bilinear, uv repetido); sem textura, devolve branco */
|
||||
static void sample_tex(const Tb3dTexture* t, float u, float v, float out[3]) {
|
||||
out[0] = out[1] = out[2] = 1.f;
|
||||
if (!t || !t->rgba || t->width <= 0 || t->height <= 0) return;
|
||||
int w = t->width, h = t->height;
|
||||
float fu = u - floorf(u), fv = v - floorf(v);
|
||||
float fx = fu * w - 0.5f, fy = fv * h - 0.5f;
|
||||
int x0 = (int)floorf(fx), y0 = (int)floorf(fy);
|
||||
float tx = fx - x0, ty = fy - y0;
|
||||
int x1 = x0 + 1, y1 = y0 + 1;
|
||||
x0 = ((x0 % w) + w) % w; x1 = ((x1 % w) + w) % w;
|
||||
y0 = ((y0 % h) + h) % h; y1 = ((y1 % h) + h) % h;
|
||||
for (int c = 0; c < 3; c++) {
|
||||
float a0 = t->rgba[((size_t)y0 * w + x0) * 4 + c] / 255.f;
|
||||
float b0 = t->rgba[((size_t)y0 * w + x1) * 4 + c] / 255.f;
|
||||
float a1 = t->rgba[((size_t)y1 * w + x0) * 4 + c] / 255.f;
|
||||
float b1 = t->rgba[((size_t)y1 * w + x1) * 4 + c] / 255.f;
|
||||
out[c] = (a0 * (1 - tx) + b0 * tx) * (1 - ty) + (a1 * (1 - tx) + b1 * tx) * ty;
|
||||
}
|
||||
}
|
||||
|
||||
static void raster_tri(const CV* a, const CV* b, const CV* c, int W, int H, uint8_t* px) {
|
||||
float ax = (a->x / a->w * 0.5f + 0.5f) * W, ay = (0.5f - a->y / a->w * 0.5f) * H, az = a->z / a->w;
|
||||
float bx = (b->x / b->w * 0.5f + 0.5f) * W, by = (0.5f - b->y / b->w * 0.5f) * H, bz = b->z / b->w;
|
||||
@@ -364,6 +558,26 @@ static void raster_tri(const CV* a, const CV* b, const CV* c, int W, int H, uint
|
||||
if (x1 > W) x1 = W;
|
||||
if (y1 > H) y1 = H;
|
||||
float inv = 1.f / area;
|
||||
/* Tangent frame por triangulo, no espaco do OBJETO (o GL e o Vulkan tiram
|
||||
o mesmo dos dFdx da posicao local e do uv, para dar o mesmo resultado). */
|
||||
float T[3] = { 0, 0, 0 }, B[3] = { 0, 0, 0 };
|
||||
bool have_tb = false;
|
||||
if (s_normal) {
|
||||
float e1[3], e2[3];
|
||||
for (int k = 0; k < 3; k++) { e1[k] = b->L[k] - a->L[k]; e2[k] = c->L[k] - a->L[k]; }
|
||||
float d1u = b->uv[0] - a->uv[0], d1v = b->uv[1] - a->uv[1];
|
||||
float d2u = c->uv[0] - a->uv[0], d2v = c->uv[1] - a->uv[1];
|
||||
float det = d1u * d2v - d2u * d1v;
|
||||
if (fabsf(det) > 1e-12f) {
|
||||
float f = 1.f / det;
|
||||
for (int k = 0; k < 3; k++) {
|
||||
T[k] = (e1[k] * d2v - e2[k] * d1v) * f;
|
||||
B[k] = (e2[k] * d1u - e1[k] * d2u) * f;
|
||||
}
|
||||
v3_norm(T); v3_norm(B);
|
||||
have_tb = true;
|
||||
}
|
||||
}
|
||||
for (int y = y0; y < y1; y++) {
|
||||
float py = y + 0.5f;
|
||||
for (int x = x0; x < x1; x++) {
|
||||
@@ -376,32 +590,71 @@ static void raster_tri(const CV* a, const CV* b, const CV* c, int W, int H, uint
|
||||
if (z < -1.f || z > 1.f) continue;
|
||||
float* zb = &s_zbuf[(size_t)y * W + x];
|
||||
if (z >= *zb) continue;
|
||||
*zb = z;
|
||||
if (s_alpha >= 0.999f) *zb = z;
|
||||
uint8_t* p = px + ((size_t)y * W + x) * 4;
|
||||
float r, g, bl;
|
||||
float q0 = w0 / a->w, q1 = w1 / b->w, q2 = w2 / c->w, qs = 1.f / (q0 + q1 + q2);
|
||||
float iu = (q0 * a->uv[0] + q1 * b->uv[0] + q2 * c->uv[0]) * qs;
|
||||
float iv = (q0 * a->uv[1] + q1 * b->uv[1] + q2 * c->uv[1]) * qs;
|
||||
float tex[3];
|
||||
sample_tex(s_albedo, iu, iv, tex);
|
||||
float Nw[3]; /* normal no mundo (talvez com relevo) */
|
||||
for (int k = 0; k < 3; k++)
|
||||
Nw[k] = (q0 * a->N[k] + q1 * b->N[k] + q2 * c->N[k]) * qs;
|
||||
v3_norm(Nw);
|
||||
if (have_tb) { /* normal map: perturba no espaco do objeto */
|
||||
float No[3], nm[3], nb[3];
|
||||
for (int k = 0; k < 3; k++)
|
||||
No[k] = (q0 * a->No[k] + q1 * b->No[k] + q2 * c->No[k]) * qs;
|
||||
v3_norm(No);
|
||||
sample_tex(s_normal, iu, iv, nm);
|
||||
for (int k = 0; k < 3; k++)
|
||||
nb[k] = T[k] * (2 * nm[0] - 1) + B[k] * (2 * nm[1] - 1) + No[k] * (2 * nm[2] - 1);
|
||||
v3_norm(nb);
|
||||
for (int k = 0; k < 3; k++)
|
||||
Nw[k] = s_nmat[0 * 3 + k] * nb[0] + s_nmat[1 * 3 + k] * nb[1] + s_nmat[2 * 3 + k] * nb[2];
|
||||
v3_norm(Nw);
|
||||
}
|
||||
float lam = v3_dot(Nw, s_frame->light_dir);
|
||||
float I = s_frame->ambient + (1.f - s_frame->ambient) * (lam > 0 ? lam : 0);
|
||||
if (s_prog) { /* shader: ponto e normal com perspectiva */
|
||||
float q0 = w0 / a->w, q1 = w1 / b->w, q2 = w2 / c->w, qs = 1.f / (q0 + q1 + q2);
|
||||
D3Pixel in;
|
||||
for (int k = 0; k < 3; k++) {
|
||||
in.P[k] = (q0 * a->P[k] + q1 * b->P[k] + q2 * c->P[k]) * qs;
|
||||
in.N[k] = (q0 * a->N[k] + q1 * b->N[k] + q2 * c->N[k]) * qs;
|
||||
in.N[k] = Nw[k];
|
||||
in.L[k] = (q0 * a->L[k] + q1 * b->L[k] + q2 * c->L[k]) * qs;
|
||||
in.base[k] = s_base[k];
|
||||
in.tex[k] = tex[k];
|
||||
}
|
||||
v3_norm(in.N);
|
||||
float lam = v3_dot(in.N, s_frame->light_dir);
|
||||
in.light = s_frame->ambient + (1.f - s_frame->ambient) * (lam > 0 ? lam : 0);
|
||||
in.uv[0] = iu;
|
||||
in.uv[1] = iv;
|
||||
in.light = I;
|
||||
in.time = s_frame->time;
|
||||
float o[3];
|
||||
d3_shader_run(s_prog, &in, o);
|
||||
r = o[0]; g = o[1]; bl = o[2];
|
||||
} else {
|
||||
r = w0 * a->r + w1 * b->r + w2 * c->r;
|
||||
g = w0 * a->g + w1 * b->g + w2 * c->g;
|
||||
bl = w0 * a->b + w1 * b->b + w2 * c->b;
|
||||
r = (w0 * a->r + w1 * b->r + w2 * c->r) * I * tex[0];
|
||||
g = (w0 * a->g + w1 * b->g + w2 * c->g) * I * tex[1];
|
||||
bl = (w0 * a->b + w1 * b->b + w2 * c->b) * I * tex[2];
|
||||
}
|
||||
p[0] = (uint8_t)(fminf(r, 1.f) * 255.f + .5f);
|
||||
p[1] = (uint8_t)(fminf(g, 1.f) * 255.f + .5f);
|
||||
p[2] = (uint8_t)(fminf(bl, 1.f) * 255.f + .5f);
|
||||
r = fminf(r, 1.f); g = fminf(g, 1.f); bl = fminf(bl, 1.f);
|
||||
if (s_frame->fog_end > s_frame->fog_start) { /* nevoa pela profundidade (w do clip) */
|
||||
float t = (qs - s_frame->fog_start) / (s_frame->fog_end - s_frame->fog_start);
|
||||
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
||||
r += (s_frame->fog_color[0] - r) * t;
|
||||
g += (s_frame->fog_color[1] - g) * t;
|
||||
bl += (s_frame->fog_color[2] - bl) * t;
|
||||
}
|
||||
if (s_alpha < 0.999f) {
|
||||
float a = s_alpha < 0 ? 0 : s_alpha;
|
||||
r = r * a + p[0] / 255.f * (1 - a);
|
||||
g = g * a + p[1] / 255.f * (1 - a);
|
||||
bl = bl * a + p[2] / 255.f * (1 - a);
|
||||
}
|
||||
p[0] = (uint8_t)(r * 255.f + .5f);
|
||||
p[1] = (uint8_t)(g * 255.f + .5f);
|
||||
p[2] = (uint8_t)(bl * 255.f + .5f);
|
||||
p[3] = 255;
|
||||
}
|
||||
}
|
||||
@@ -430,7 +683,19 @@ static void clip_and_raster(const CV in[3], int W, int H, uint8_t* px) {
|
||||
|
||||
/* Cor de um vertice: lambert por vertice (o GL e o Vulkan fazem igual) */
|
||||
static void shade(const Tb3dFrame* f, const Tb3dDraw* d, const float* v, CV* o) {
|
||||
float p[4] = { v[0], v[1], v[2], 1 }, c[4] = { 0 };
|
||||
float lp[3] = { v[0], v[1], v[2] };
|
||||
if (s_vprog) { /* shader de vertice: move o vertice */
|
||||
D3Pixel in;
|
||||
in.P[0] = v[0]; in.P[1] = v[1]; in.P[2] = v[2];
|
||||
in.N[0] = v[3]; in.N[1] = v[4]; in.N[2] = v[5];
|
||||
in.L[0] = v[0]; in.L[1] = v[1]; in.L[2] = v[2];
|
||||
in.uv[0] = v[6]; in.uv[1] = v[7];
|
||||
in.base[0] = d->color[0]; in.base[1] = d->color[1]; in.base[2] = d->color[2];
|
||||
in.tex[0] = in.tex[1] = in.tex[2] = 1.f;
|
||||
in.light = 1.f; in.time = f->time;
|
||||
d3_shader_run_vertex(s_vprog, &in, lp);
|
||||
}
|
||||
float p[4] = { lp[0], lp[1], lp[2], 1 }, c[4] = { 0 };
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int k = 0; k < 4; k++) c[i] += d->mvp[k * 4 + i] * p[k];
|
||||
float n[3] = { 0 };
|
||||
@@ -439,13 +704,16 @@ static void shade(const Tb3dFrame* f, const Tb3dDraw* d, const float* v, CV* o)
|
||||
v3_norm(n);
|
||||
for (int i = 0; i < 3; i++) { /* ponto no mundo (shader) */
|
||||
o->P[i] = d->model[12 + i];
|
||||
for (int k = 0; k < 3; k++) o->P[i] += d->model[k * 4 + i] * v[k];
|
||||
for (int k = 0; k < 3; k++) o->P[i] += d->model[k * 4 + i] * lp[k];
|
||||
o->N[i] = n[i];
|
||||
o->L[i] = lp[i]; /* vertice local (shader) */
|
||||
}
|
||||
float lam = v3_dot(n, f->light_dir);
|
||||
float I = f->ambient + (1.f - f->ambient) * (lam > 0 ? lam : 0);
|
||||
o->uv[0] = v[6]; o->uv[1] = v[7];
|
||||
float no[3] = { v[3], v[4], v[5] };
|
||||
v3_norm(no);
|
||||
for (int i = 0; i < 3; i++) o->No[i] = no[i];
|
||||
o->x = c[0]; o->y = c[1]; o->z = c[2]; o->w = c[3];
|
||||
o->r = d->color[0] * I; o->g = d->color[1] * I; o->b = d->color[2] * I;
|
||||
o->r = d->color[0]; o->g = d->color[1]; o->b = d->color[2];
|
||||
}
|
||||
|
||||
static bool sw_available(void) { return true; }
|
||||
@@ -473,10 +741,16 @@ static bool sw_render(const Tb3dFrame* f, uint8_t* px) {
|
||||
if (!p) { free(cv); return false; }
|
||||
cv = p; cv_cap = m->vcount;
|
||||
}
|
||||
for (int i = 0; i < m->vcount; i++) shade(f, d, m->verts + (size_t)i * 6, &cv[i]);
|
||||
s_prog = d->shader ? ((const Shd*)d->shader)->prog : NULL; /* pub e o 1o campo */
|
||||
const D3Program* prog = d->shader ? ((const Shd*)d->shader)->prog : NULL; /* pub e o 1o campo */
|
||||
s_vprog = (prog && d3_shader_stage(prog) == D3_STAGE_VERTEX) ? prog : NULL;
|
||||
s_prog = (prog && d3_shader_stage(prog) == D3_STAGE_FRAGMENT) ? prog : NULL;
|
||||
s_albedo = d->albedo;
|
||||
s_normal = d->normaltex;
|
||||
memcpy(s_nmat, d->normal, sizeof(s_nmat));
|
||||
s_frame = f;
|
||||
s_alpha = d->color[3];
|
||||
memcpy(s_base, d->color, sizeof(s_base));
|
||||
for (int i = 0; i < m->vcount; i++) shade(f, d, m->verts + (size_t)i * 8, &cv[i]);
|
||||
for (int t = 0; t + 2 < m->icount; t += 3) {
|
||||
CV tri[3] = { cv[m->index[t]], cv[m->index[t + 1]], cv[m->index[t + 2]] };
|
||||
if (tri[0].z < -tri[0].w && tri[1].z < -tri[1].w && tri[2].z < -tri[2].w) continue;
|
||||
@@ -484,7 +758,9 @@ static bool sw_render(const Tb3dFrame* f, uint8_t* px) {
|
||||
}
|
||||
}
|
||||
free(cv);
|
||||
s_prog = NULL;
|
||||
s_prog = s_vprog = NULL;
|
||||
s_albedo = s_normal = NULL;
|
||||
s_alpha = 1.f;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -550,6 +826,7 @@ static void create(TinyBlocks_Block* self, TinyBlocks* rt, int kind) {
|
||||
memset(o, 0, sizeof(*o));
|
||||
snprintf(o->name, sizeof(o->name), "%s", n);
|
||||
}
|
||||
mesh_clear(o);
|
||||
o->kind = kind;
|
||||
vec_in(self, rt, 1, o->pos);
|
||||
o->rot[0] = o->rot[1] = o->rot[2] = 0;
|
||||
@@ -565,6 +842,137 @@ static void eval_sphere(TinyBlocks_Block* s, TinyBlocks* rt) { create(s, rt, K
|
||||
static void eval_plane(TinyBlocks_Block* s, TinyBlocks* rt) { create(s, rt, K_PLANE); }
|
||||
static void eval_cylinder(TinyBlocks_Block* s, TinyBlocks* rt) { create(s, rt, K_CYLINDER); }
|
||||
|
||||
/* == Malha personalizada (leitor de .obj e afins) ===================== */
|
||||
static Obj* obj_ensure(const char* n) {
|
||||
Obj* o = find(n);
|
||||
if (o) return o;
|
||||
if (S.n >= MAX_OBJS) return NULL;
|
||||
if (S.n == S.cap) {
|
||||
int nc = S.cap ? S.cap * 2 : 64;
|
||||
Obj* p = realloc(S.o, (size_t)nc * sizeof(*p));
|
||||
if (!p) return NULL;
|
||||
S.o = p; S.cap = nc;
|
||||
}
|
||||
o = &S.o[S.n++];
|
||||
memset(o, 0, sizeof(*o));
|
||||
snprintf(o->name, sizeof(o->name), "%s", n);
|
||||
return o;
|
||||
}
|
||||
|
||||
static Obj* mesh_need(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* n = name_in(self, rt, 0);
|
||||
Obj* o = find(n);
|
||||
if (!o || o->kind != K_CUSTOM) { tinyblocks_set_error(rt, "não existe a malha '%s'", n); return NULL; }
|
||||
return o;
|
||||
}
|
||||
|
||||
static void eval_mesh_create(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
const char* n = name_in(self, rt, 0);
|
||||
if (!n[0]) { tinyblocks_set_error(rt, "dê um nome à malha"); return; }
|
||||
Obj* o = obj_ensure(n);
|
||||
if (!o) { tinyblocks_set_error(rt, "a cena já tem objetos demais"); return; }
|
||||
mesh_clear(o);
|
||||
shd_release(o->shader); o->shader = NULL;
|
||||
o->kind = K_CUSTOM;
|
||||
o->pos[0] = o->pos[1] = o->pos[2] = 0;
|
||||
o->rot[0] = o->rot[1] = o->rot[2] = 0;
|
||||
o->scale[0] = o->scale[1] = o->scale[2] = 1;
|
||||
o->color[0] = o->color[1] = o->color[2] = 0.8f; o->color[3] = 1;
|
||||
o->visible = true;
|
||||
}
|
||||
|
||||
static void mb_push3(float** a, int* n, int* cap, float x, float y, float z) {
|
||||
if (*n == *cap) { *cap = *cap ? *cap * 2 : 64; *a = realloc(*a, (size_t)(*cap) * 3 * sizeof(float)); }
|
||||
float* p = *a + (size_t)(*n) * 3; p[0] = x; p[1] = y; p[2] = z; (*n)++;
|
||||
}
|
||||
static void mb_push2(float** a, int* n, int* cap, float u, float v) {
|
||||
if (*n == *cap) { *cap = *cap ? *cap * 2 : 64; *a = realloc(*a, (size_t)(*cap) * 2 * sizeof(float)); }
|
||||
float* p = *a + (size_t)(*n) * 2; p[0] = u; p[1] = v; (*n)++;
|
||||
}
|
||||
|
||||
static void eval_mesh_vert(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
Obj* o = mesh_need(self, rt); if (!o) return;
|
||||
float v[3]; vec_in(self, rt, 1, v);
|
||||
mb_push3(&o->mb.v, &o->mb.vn, &o->mb.vcap, v[0], v[1], v[2]);
|
||||
}
|
||||
static void eval_mesh_norm(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
Obj* o = mesh_need(self, rt); if (!o) return;
|
||||
float v[3]; vec_in(self, rt, 1, v);
|
||||
mb_push3(&o->mb.n, &o->mb.nn, &o->mb.ncap, v[0], v[1], v[2]);
|
||||
}
|
||||
static void eval_mesh_uv(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
Obj* o = mesh_need(self, rt); if (!o) return;
|
||||
mb_push2(&o->mb.t, &o->mb.tn, &o->mb.tcap,
|
||||
(float)tb_block_input_number(self, rt, 1, 0), (float)tb_block_input_number(self, rt, 2, 0));
|
||||
}
|
||||
static void eval_mesh_tri(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
Obj* o = mesh_need(self, rt); if (!o) return;
|
||||
if (o->mb.fn + 3 > o->mb.fcap) { o->mb.fcap = o->mb.fcap ? o->mb.fcap * 2 : 96; o->mb.f = realloc(o->mb.f, (size_t)o->mb.fcap * sizeof(int)); }
|
||||
for (int k = 0; k < 3; k++)
|
||||
o->mb.f[o->mb.fn++] = (int)tb_block_input_number(self, rt, 1 + (uint32_t)k, 0);
|
||||
}
|
||||
|
||||
static void eval_mesh_finish(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
Obj* o = mesh_need(self, rt); if (!o) return;
|
||||
int vn = o->mb.vn;
|
||||
if (vn <= 0) { tinyblocks_set_error(rt, "a malha '%s' não tem vértices", o->name); return; }
|
||||
bool have_n = o->mb.nn >= vn;
|
||||
float* verts = malloc((size_t)vn * 8 * sizeof(float));
|
||||
uint32_t* idx = malloc((o->mb.fn > 0 ? (size_t)o->mb.fn : 1) * sizeof(uint32_t));
|
||||
float* acc = have_n ? NULL : calloc((size_t)vn * 3, sizeof(float));
|
||||
if (!verts || !idx || (!have_n && !acc)) { free(verts); free(idx); free(acc); tinyblocks_set_error(rt, "sem memória"); return; }
|
||||
if (!have_n) /* normais: soma as das faces */
|
||||
for (int f = 0; f + 2 < o->mb.fn; f += 3) {
|
||||
int a = o->mb.f[f] - 1, b = o->mb.f[f + 1] - 1, c = o->mb.f[f + 2] - 1;
|
||||
if (a < 0 || b < 0 || c < 0 || a >= vn || b >= vn || c >= vn) continue;
|
||||
float e1[3], e2[3], cr[3];
|
||||
for (int k = 0; k < 3; k++) { e1[k] = o->mb.v[b*3+k] - o->mb.v[a*3+k]; e2[k] = o->mb.v[c*3+k] - o->mb.v[a*3+k]; }
|
||||
cr[0] = e1[1]*e2[2] - e1[2]*e2[1]; cr[1] = e1[2]*e2[0] - e1[0]*e2[2]; cr[2] = e1[0]*e2[1] - e1[1]*e2[0];
|
||||
for (int k = 0; k < 3; k++) { acc[a*3+k] += cr[k]; acc[b*3+k] += cr[k]; acc[c*3+k] += cr[k]; }
|
||||
}
|
||||
o->bmin[0] = o->bmin[1] = o->bmin[2] = 1e30f;
|
||||
o->bmax[0] = o->bmax[1] = o->bmax[2] = -1e30f;
|
||||
for (int i = 0; i < vn; i++) {
|
||||
float nx, ny, nz;
|
||||
if (have_n) { nx = o->mb.n[i*3]; ny = o->mb.n[i*3+1]; nz = o->mb.n[i*3+2]; }
|
||||
else { nx = acc[i*3]; ny = acc[i*3+1]; nz = acc[i*3+2]; }
|
||||
float len = sqrtf(nx*nx + ny*ny + nz*nz);
|
||||
if (len > 1e-6f) { nx /= len; ny /= len; nz /= len; } else { nx = 0; ny = 1; nz = 0; }
|
||||
float* p = verts + (size_t)i * 8;
|
||||
p[0] = o->mb.v[i*3]; p[1] = o->mb.v[i*3+1]; p[2] = o->mb.v[i*3+2];
|
||||
p[3] = nx; p[4] = ny; p[5] = nz;
|
||||
p[6] = i < o->mb.tn ? o->mb.t[i*2] : 0.f;
|
||||
p[7] = i < o->mb.tn ? o->mb.t[i*2+1] : 0.f;
|
||||
for (int k = 0; k < 3; k++) {
|
||||
float c = o->mb.v[i*3+k];
|
||||
if (c < o->bmin[k]) o->bmin[k] = c;
|
||||
if (c > o->bmax[k]) o->bmax[k] = c;
|
||||
}
|
||||
}
|
||||
int ic = 0;
|
||||
for (int f = 0; f + 2 < o->mb.fn; f += 3) {
|
||||
int a = o->mb.f[f] - 1, b = o->mb.f[f + 1] - 1, c = o->mb.f[f + 2] - 1;
|
||||
if (a < 0 || b < 0 || c < 0 || a >= vn || b >= vn || c >= vn) continue;
|
||||
idx[ic++] = (uint32_t)a; idx[ic++] = (uint32_t)b; idx[ic++] = (uint32_t)c;
|
||||
}
|
||||
free(acc);
|
||||
free((void*)o->mesh.verts); free((void*)o->mesh.index);
|
||||
if (o->mesh.id == 0) {
|
||||
if (s_mesh_seq >= 256) { tinyblocks_set_error(rt, "malhas demais na cena"); free(verts); free(idx); return; }
|
||||
o->mesh.id = s_mesh_seq++;
|
||||
}
|
||||
o->mesh.version++;
|
||||
o->mesh.verts = verts; o->mesh.vcount = vn;
|
||||
o->mesh.index = idx; o->mesh.icount = ic;
|
||||
if (ic == 0) tinyblocks_set_error(rt, "a malha '%s' não tem triângulos", o->name);
|
||||
}
|
||||
|
||||
#define OBJ_CMD(fname, body) \
|
||||
static void fname(TinyBlocks_Block* self, TinyBlocks* rt) { \
|
||||
self->dirty = false; Obj* o = need(self, rt, 0); if (!o) return; float v[3]; (void)v; body }
|
||||
@@ -575,14 +983,19 @@ OBJ_CMD(eval_rot_by, vec_in(self, rt, 1, v); for (int k = 0; k < 3; k++) o->r
|
||||
OBJ_CMD(eval_scale, vec_in(self, rt, 1, v); memcpy(o->scale, v, sizeof(v));)
|
||||
OBJ_CMD(eval_show, o->visible = true;)
|
||||
OBJ_CMD(eval_hide, o->visible = false;)
|
||||
OBJ_CMD(eval_color, if (!d3_color_of(name_in(self, rt, 1), o->color))
|
||||
tinyblocks_set_error(rt, "cor desconhecida '%s' (use um nome ou #rrggbb)", name_in(self, rt, 1));)
|
||||
OBJ_CMD(eval_color, float a = o->color[3];
|
||||
if (!d3_color_of(name_in(self, rt, 1), o->color))
|
||||
tinyblocks_set_error(rt, "cor desconhecida '%s' (use um nome ou #rrggbb)", name_in(self, rt, 1));
|
||||
o->color[3] = a;)
|
||||
OBJ_CMD(eval_opacity, double a = tb_block_input_number(self, rt, 1, 1.0);
|
||||
o->color[3] = a < 0 ? 0.f : a > 1 ? 1.f : (float)a;)
|
||||
|
||||
static void eval_delete(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
Obj* o = find(name_in(self, rt, 0));
|
||||
if (o) {
|
||||
shd_release(o->shader);
|
||||
mesh_clear(o);
|
||||
int i = (int)(o - S.o);
|
||||
memmove(o, o + 1, (size_t)(S.n - i - 1) * sizeof(*o));
|
||||
S.n--;
|
||||
@@ -657,6 +1070,13 @@ static void eval_sky(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
if (!d3_color_of(name_in(self, rt, 0), S.sky)) tinyblocks_set_error(rt, "cor desconhecida '%s'", name_in(self, rt, 0));
|
||||
}
|
||||
|
||||
static void eval_fog(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
double a = tb_block_input_number(self, rt, 0, 20), b = tb_block_input_number(self, rt, 1, 60);
|
||||
S.fog_start = a < 0 ? 0.f : (float)a;
|
||||
S.fog_end = (float)b;
|
||||
}
|
||||
|
||||
static void eval_use(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
const char* w = name_in(self, rt, 0);
|
||||
@@ -741,7 +1161,7 @@ static void shd_binaries(TinyBlocks* rt, Shd* sh) {
|
||||
if (!r || r->version != TB_3D_RENDERER_VERSION || !r->compile || !r->available() || !r->shaders()) continue;
|
||||
Tb3dBinary* b = &sh->pub.bin[sh->pub.bin_n];
|
||||
char err[200];
|
||||
if (!r->compile(sh->pub.glsl, &b->data, &b->size, err, sizeof(err))) {
|
||||
if (!r->compile(sh->pub.glsl, sh->pub.stage, &b->data, &b->size, err, sizeof(err))) {
|
||||
snprintf(S.err, sizeof(S.err), "%s: %.140s", r->name, err);
|
||||
continue;
|
||||
}
|
||||
@@ -765,6 +1185,7 @@ static void eval_shader(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
sh->refs = 1;
|
||||
sh->pub.id = ++s_shd_seq;
|
||||
sh->pub.version = 1;
|
||||
sh->pub.stage = d3_shader_stage(prog) == D3_STAGE_VERTEX ? TB_3D_STAGE_VERTEX : TB_3D_STAGE_FRAGMENT;
|
||||
sh->pub.glsl = d3_shader_glsl(prog);
|
||||
shd_binaries(rt, sh);
|
||||
ShdProducer* p = self->userdata;
|
||||
@@ -802,6 +1223,86 @@ static void eval_shader_glsl(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
tb_block_set_output(self, 0, tb_value_text(sh->pub.glsl));
|
||||
}
|
||||
|
||||
/* -- Texturas e materiais --- */
|
||||
static void eval_texture(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
const char* name = tb_block_input_text(self, rt, 0);
|
||||
if (!name[0]) { tinyblocks_set_error(rt, "dê um nome à textura"); return; }
|
||||
TinyBlocks_Image* img = tb_value_as_image(tb_block_get_input(self, rt, 1));
|
||||
if (!img) { tinyblocks_set_error(rt, "a textura precisa de uma imagem (\"carregue imagem ...\")"); return; }
|
||||
Tex* t = tex_get(name);
|
||||
if (!t) {
|
||||
t = calloc(1, sizeof(*t));
|
||||
if (!t) { tinyblocks_set_error(rt, "sem memória"); return; }
|
||||
t->refs = 1;
|
||||
t->pub.id = ++s_tex_seq;
|
||||
t->pub.version = 1;
|
||||
snprintf(t->name, sizeof(t->name), "%s", name);
|
||||
if (s_tex.n == s_tex.cap) {
|
||||
int nc = s_tex.cap ? s_tex.cap * 2 : 8;
|
||||
Tex** q = realloc(s_tex.t, (size_t)nc * sizeof(*q));
|
||||
if (!q) { free(t); tinyblocks_set_error(rt, "sem memória"); return; }
|
||||
s_tex.t = q; s_tex.cap = nc;
|
||||
}
|
||||
s_tex.t[s_tex.n++] = t;
|
||||
}
|
||||
tex_from_image(t, img);
|
||||
}
|
||||
|
||||
static void eval_material(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
const char* name = tb_block_input_text(self, rt, 0);
|
||||
if (!name[0]) { tinyblocks_set_error(rt, "dê um nome ao material"); return; }
|
||||
if (!mat_get(name, true)) tinyblocks_set_error(rt, "sem memória");
|
||||
}
|
||||
|
||||
static void eval_material_albedo(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
const char* mn = tb_block_input_text(self, rt, 0);
|
||||
Mat* m = mat_get(mn, false);
|
||||
if (!m) { tinyblocks_set_error(rt, "não existe o material '%s'", mn); return; }
|
||||
const char* tn = tb_block_input_text(self, rt, 1);
|
||||
Tex* t = tex_get(tn);
|
||||
if (!t) { tinyblocks_set_error(rt, "não existe a textura '%s'", tn); return; }
|
||||
t->refs++;
|
||||
tex_release(m->albedo);
|
||||
m->albedo = t;
|
||||
}
|
||||
|
||||
static void eval_material_normal(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
const char* mn = tb_block_input_text(self, rt, 0);
|
||||
Mat* m = mat_get(mn, false);
|
||||
if (!m) { tinyblocks_set_error(rt, "não existe o material '%s'", mn); return; }
|
||||
const char* tn = tb_block_input_text(self, rt, 1);
|
||||
Tex* t = tex_get(tn);
|
||||
if (!t) { tinyblocks_set_error(rt, "não existe a textura '%s'", tn); return; }
|
||||
t->refs++;
|
||||
tex_release(m->normal);
|
||||
m->normal = t;
|
||||
}
|
||||
|
||||
static void eval_material_color(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
const char* mn = tb_block_input_text(self, rt, 0);
|
||||
Mat* m = mat_get(mn, false);
|
||||
if (!m) { tinyblocks_set_error(rt, "não existe o material '%s'", mn); return; }
|
||||
const char* cn = tb_block_input_text(self, rt, 1);
|
||||
float c[4];
|
||||
if (!d3_color_of(cn, c)) { tinyblocks_set_error(rt, "cor desconhecida '%s'", cn); return; }
|
||||
m->tint[0] = c[0]; m->tint[1] = c[1]; m->tint[2] = c[2];
|
||||
}
|
||||
|
||||
static void eval_material_use(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
const char* mn = tb_block_input_text(self, rt, 0);
|
||||
Mat* m = mat_get(mn, false);
|
||||
if (!m) { tinyblocks_set_error(rt, "não existe o material '%s'", mn); return; }
|
||||
Obj* o = need(self, rt, 1);
|
||||
if (!o) return;
|
||||
o->material = m;
|
||||
}
|
||||
|
||||
static void eval_renderer(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
if (!S.used[0]) { const Tb3dRenderer* r = pick(rt); snprintf(S.used, sizeof(S.used), "%s (%s)", r->name, r->device()); }
|
||||
@@ -835,12 +1336,25 @@ static const Spec s_specs[] = {
|
||||
{ "3D.Sphere", "crie esfera %1 em x %2 y %3 z %4", "bola|0|0.5|0", 4, {T,R,R,R}, O_NONE, -1, S_(eval_sphere), "Esfera de diâmetro 1" },
|
||||
{ "3D.Plane", "crie plano %1 em x %2 y %3 z %4", "chão" XYZ, 4, {T,R,R,R}, O_NONE, -1, S_(eval_plane), "Plano deitado de 10 por 10" },
|
||||
{ "3D.Cylinder", "crie cilindro %1 em x %2 y %3 z %4", "moeda|0|0.5|0", 4, {T,R,R,R}, O_NONE, -1, S_(eval_cylinder), "Cilindro em pé, diâmetro 1 e altura 1" },
|
||||
{ "3D.MeshCreate", "crie a malha %1", "minha malha", 1, {T}, O_NONE, -1, S_(eval_mesh_create), "Começa uma malha personalizada (os vértices e triângulos vêm nos blocos seguintes)" },
|
||||
{ "3D.MeshVertex", "na malha %1 adicione o vértice x %2 y %3 z %4", "minha malha|0|0|0", 4, {T,R,R,R}, O_NONE, -1, S_(eval_mesh_vert), "Empilha um vértice (posição) na malha" },
|
||||
{ "3D.MeshNormal", "na malha %1 adicione a normal x %2 y %3 z %4", "minha malha|0|1|0", 4, {T,R,R,R}, O_NONE, -1, S_(eval_mesh_norm), "Empilha a normal de um vértice (sem nenhuma, a malha calcula das faces)" },
|
||||
{ "3D.MeshUV", "na malha %1 adicione a texcoord u %2 v %3", "minha malha|0|0", 3, {T,R,R}, O_NONE, -1, S_(eval_mesh_uv), "Empilha a coordenada de textura (0 a 1) de um vértice" },
|
||||
{ "3D.MeshTri", "na malha %1 adicione o triângulo %2 %3 %4", "minha malha|1|2|3", 4, {T,I,I,I}, O_NONE, -1, S_(eval_mesh_tri), "Um triângulo pelos números dos vértices (1 = o primeiro)" },
|
||||
{ "3D.MeshFinish", "finalize a malha %1", "minha malha", 1, {T}, O_NONE, -1, S_(eval_mesh_finish), "Monta a malha (com as normais que faltam) e a deixa pronta para desenhar" },
|
||||
{ "3D.Texture", "crie a textura %1 da imagem %2", "telha|", 2, {T,TB_VALUE_IMAGE}, O_NONE, -1, S_(eval_texture), "Guarda uma textura com esse nome a partir de uma imagem" },
|
||||
{ "3D.Material", "crie o material %1", "meu material", 1, {T}, O_NONE, -1, S_(eval_material), "Começa um material (cor + texturas)" },
|
||||
{ "3D.MaterialAlbedo", "no material %1 use a textura %2 como albedo", "meu material|telha", 2, {T,T}, O_NONE, -1, S_(eval_material_albedo), "A textura que dá a cor do material" },
|
||||
{ "3D.MaterialNormal", "no material %1 use a textura %2 como normal", "meu material|relevo", 2, {T,T}, O_NONE, -1, S_(eval_material_normal), "A textura de relevo (normal map) do material" },
|
||||
{ "3D.MaterialColor", "no material %1 use a cor %2", "meu material|branco", 2, {T,T}, O_NONE, -1, S_(eval_material_color), "A cor que multiplica a textura (padrão branco)" },
|
||||
{ "3D.MaterialUse", "use o material %1 no objeto %2", "meu material|jogador", 2, {T,T}, O_NONE, -1, S_(eval_material_use), "O objeto passa a usar o material (textura e cor)" },
|
||||
{ "3D.MoveTo", "mova %1 para x %2 y %3 z %4", "jogador|0|0.5|0", 4, {T,R,R,R}, O_NONE, -1, S_(eval_move_to), "Põe o objeto nessa posição" },
|
||||
{ "3D.MoveBy", "mova %1 por x %2 y %3 z %4", "jogador|0|0|0.1", 4, {T,R,R,R}, O_NONE, -1, S_(eval_move_by), "Soma à posição do objeto" },
|
||||
{ "3D.RotateTo", "gire %1 para x %2 y %3 z %4 graus", "jogador|0|45|0", 4, {T,R,R,R}, O_NONE, -1, S_(eval_rot_to), "Rotação nos eixos x, y e z (em graus)" },
|
||||
{ "3D.RotateBy", "gire %1 por x %2 y %3 z %4 graus", "jogador|0|5|0", 4, {T,R,R,R}, O_NONE, -1, S_(eval_rot_by), "Soma à rotação do objeto" },
|
||||
{ "3D.Scale", "mude o tamanho de %1 para x %2 y %3 z %4", "chão|20|1|20", 4, {T,R,R,R}, O_NONE, -1, S_(eval_scale), "Escala do objeto em cada eixo" },
|
||||
{ "3D.Color", "mude a cor de %1 para %2", "jogador|vermelho", 2, {T,T}, O_NONE, -1, S_(eval_color), "Cor por nome (vermelho, azul, dourado...) ou #rrggbb" },
|
||||
{ "3D.Opacity", "mude a opacidade de %1 para %2", "água|0.6", 2, {T,R}, O_NONE, -1, S_(eval_opacity), "0 = invisível, 1 = sólido (água, vidro, fantasmas)" },
|
||||
{ "3D.Show", "mostre o objeto %1", "jogador", 1, {T}, O_NONE, -1, S_(eval_show), "Volta a desenhar o objeto" },
|
||||
{ "3D.Hide", "esconda o objeto %1", "jogador", 1, {T}, O_NONE, -1, S_(eval_hide), "Deixa de desenhar o objeto (e ele não encosta)" },
|
||||
{ "3D.Delete", "apague o objeto %1", "jogador", 1, {T}, O_NONE, -1, S_(eval_delete), "Tira o objeto da cena" },
|
||||
@@ -855,6 +1369,7 @@ static const Spec s_specs[] = {
|
||||
{ "3D.Light", "luz vindo de x %1 y %2 z %3", "0.4|1|0.6", 3, {R,R,R}, O_NONE, -1, S_(eval_light), "Direção de onde vem a luz do sol" },
|
||||
{ "3D.Ambient", "luz ambiente %1", "0.35", 1, {R}, O_NONE, -1, S_(eval_ambient), "Claridade das partes na sombra (0 a 1)" },
|
||||
{ "3D.Sky", "cor do céu %1", "#87c7fa", 1, {T}, O_NONE, -1, S_(eval_sky), "Cor do fundo" },
|
||||
{ "3D.Fog", "névoa de %1 até %2", "20|60", 2, {R,R}, O_NONE, -1, S_(eval_fog), "Longe da câmera tudo some na cor do céu: começa na 1a distância e cobre tudo na 2a (0 e 0 = sem névoa)" },
|
||||
{ "3D.Image", "imagem da cena de %1 por %2", "480|360", 2, {I,I}, O_IMAGE, -1, S_(eval_image), "Desenha a cena numa imagem (use com \"desenhe\")" },
|
||||
{ "3D.Use", "use o renderizador %1", "automático", 1, {T}, O_NONE, -1, S_(eval_use), "vulkan, opengl, software ou automático" },
|
||||
{ "3D.Renderer", "renderizador da cena", "", 0, {T}, O_TEXT, -1, S_(eval_renderer), "Quem desenhou o último quadro (e em qual placa)" },
|
||||
|
||||
@@ -176,6 +176,9 @@ TB_API void tb_a11y_set_name (TinyBlocks_A11yTree* tree, int node, const c
|
||||
TB_API void tb_a11y_set_key (TinyBlocks_A11yTree* tree, int node, const char* key);
|
||||
/* Ponto onde as acoes agem (o centro pode cair num filho) */
|
||||
TB_API void tb_a11y_set_point (TinyBlocks_A11yTree* tree, int node, float x, float y);
|
||||
/* Escala os nos a partir de `first` (ate o ultimo criado) em torno de (ox, oy):
|
||||
* conteudo desenhado com zoom (ex.: a area de scripts) */
|
||||
TB_API void tb_a11y_scale_from (TinyBlocks_A11yTree* tree, int first, float ox, float oy, float s);
|
||||
/* Aviso para o narrador ler (mensagens de status, erros) */
|
||||
TB_API void tb_a11y_announce(TinyBlocks_A11yTree* tree, const char* text);
|
||||
|
||||
|
||||
@@ -199,6 +199,16 @@ void tb_a11y_set_point(TinyBlocks_A11yTree* t, int node, float x, float y) {
|
||||
t->nodes[node].py = y;
|
||||
}
|
||||
|
||||
void tb_a11y_scale_from(TinyBlocks_A11yTree* t, int first, float ox, float oy, float s) {
|
||||
if (!t || first < 0) return;
|
||||
for (int i = first; i < t->n; i++) {
|
||||
TinyBlocks_A11yNode* nd = &t->nodes[i];
|
||||
nd->x = ox + (nd->x - ox) * s; nd->y = oy + (nd->y - oy) * s;
|
||||
nd->px = ox + (nd->px - ox) * s; nd->py = oy + (nd->py - oy) * s;
|
||||
nd->w *= s; nd->h *= s;
|
||||
}
|
||||
}
|
||||
|
||||
void tb_a11y_announce(TinyBlocks_A11yTree* t, const char* text) {
|
||||
if (!t || !text || !text[0] || t->announce_n >= 8) return;
|
||||
scopy(t->announce[t->announce_n++], TB_A11Y_DESC_MAX, text);
|
||||
|
||||
@@ -78,7 +78,8 @@ typedef struct {
|
||||
} TbBpTab;
|
||||
|
||||
/* -- Blocos compostos (protótipo) --- */
|
||||
typedef enum { TB_BP_PARAM_NUM, TB_BP_PARAM_BOOL, TB_BP_PARAM_LABEL } TbBpParamKind;
|
||||
typedef enum { TB_BP_PARAM_NUM, TB_BP_PARAM_BOOL, TB_BP_PARAM_LABEL,
|
||||
TB_BP_PARAM_NAME /* posicao do nome (sem ela: na frente) */ } TbBpParamKind;
|
||||
typedef struct { TbBpParamKind kind; char name[32]; } TbBpParam;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -16,7 +16,7 @@ CFLAGS := -std=c11 -O2 -Wall -Wextra -pedantic -fvisibility=hidden \
|
||||
-I../tinyblocks-libman/include \
|
||||
-I../tinyblocks-syntax/include \
|
||||
-I../tinyblocks-scratchblocks/include \
|
||||
-I../tinyblocks-a11y/include \
|
||||
-I../tinyblocks-a11y/include -I../tinyblocks-qr/include \
|
||||
-I../tinyblocks-mcp-server/include \
|
||||
-Ilibraries/tinyblocks-editor-widgets/include \
|
||||
-Ilibraries/tinyblocks-editor-image/include \
|
||||
|
||||
@@ -40,6 +40,12 @@ TB_API void tb_editor_preload(const char* path);
|
||||
* NULL se a acessibilidade estiver desligada (TINYBLOCKS_A11Y=0). */
|
||||
typedef struct TinyBlocks_A11yTree TinyBlocks_A11yTree;
|
||||
TB_API TinyBlocks_A11yTree* tb_editor_accessible(TinyBlocks_Block* scene);
|
||||
/* Para testes: entrega ao leitor de QR aberto um texto como se a camera o
|
||||
* tivesse lido ("Receber blocos") */
|
||||
TB_API void tb_editor_qr_feed(TinyBlocks_Block* scene, const char* text);
|
||||
/* Para testes: o painel "Compartilhar" mostra a parte i (0..n-1) em vez do
|
||||
* loop de 1 s; -1 volta ao loop */
|
||||
TB_API void tb_editor_qr_show_part(TinyBlocks_Block* scene, int i);
|
||||
|
||||
/* Servidor MCP do editor (tb_mcp_server.h, da tinyblocks-mcp-server): as
|
||||
* ferramentas para agentes lerem e editarem as pilhas. Escuta em
|
||||
|
||||
@@ -57,15 +57,16 @@ typedef struct TinyBlocks_A11yTree TinyBlocks_A11yTree;
|
||||
* === */
|
||||
#define WIN_W_DEFAULT 1280
|
||||
#define WIN_H_DEFAULT 720
|
||||
#define MENU_H 44
|
||||
#define TAB_H 36
|
||||
#define MENU_H 56 /* top app bar do M3 (densidade -2) */
|
||||
#define TAB_H 40 /* cabecalho das areas / abas (M3, densidade -2) */
|
||||
#define CAT_W 68
|
||||
#define FLY_W 250
|
||||
#define FLY_PAD 12
|
||||
#define FLY_BTN_W 150
|
||||
#define PALETTE_W (CAT_W + FLY_W) /* largura padrao da paleta */
|
||||
#define STAGE_W 360 /* largura padrao da coluna do palco */
|
||||
#define STAGE_BAR_H 44
|
||||
#define STAGE_BAR_H TAB_H
|
||||
#define STAGE_TOP (STAGE_BAR_H + 4) /* onde a vista do palco comeca */
|
||||
#define WIN_W (ed->win_w)
|
||||
#define WIN_H (ed->win_h)
|
||||
|
||||
@@ -88,8 +89,8 @@ typedef struct TinyBlocks_A11yTree TinyBlocks_A11yTree;
|
||||
#define PLUS_W 28
|
||||
|
||||
/* Menu do botao "+" (nova aba) */
|
||||
#define PLUS_MENU_W 208
|
||||
#define PLUS_MENU_ITEM_H 36
|
||||
#define PLUS_MENU_W 260
|
||||
#define PLUS_MENU_ITEM_H 52 /* item de duas linhas (M3) */
|
||||
#define PLUS_MENU_N 4
|
||||
|
||||
/* Editor de codigo (aba de codigo) */
|
||||
@@ -143,8 +144,8 @@ enum { IT_SEL = 0, IT_BRUSH, IT_LINE, IT_RECT, IT_ELLIPSE,
|
||||
(menu_layout em tb_editor.c): o que nao cabe vai para o menu "☰". */
|
||||
enum { MB_OPEN, MB_SAVE, MB_EXPORT, MB_LIBMAN, MB_LIB, MB_CFG, MB_COUNT };
|
||||
typedef struct { float x, w; bool shown; } MenuBtn;
|
||||
#define MENU_BTN_Y 7
|
||||
#define MENU_BTN_H (MENU_H - 14)
|
||||
#define MENU_BTN_H 36
|
||||
#define MENU_BTN_Y ((MENU_H - MENU_BTN_H) / 2)
|
||||
#define MENU_MORE_W 40
|
||||
|
||||
/* Modo compacto (janela estreita / celular): uma area de cada vez.
|
||||
@@ -196,13 +197,13 @@ enum { CV_CODE, CV_STAGE };
|
||||
#define MAX_GROUPS 32
|
||||
#define GRP_HEAD_H 28 /* faixa do titulo (arrastar = mover tudo) */
|
||||
#define GRP_GRIP 16 /* canto de baixo a direita: redimensionar */
|
||||
#define MAX_CATS 24
|
||||
#define MAX_CATS 64
|
||||
#define MAX_CALL_DEPTH 32
|
||||
#define MAX_RUN_BLOCKS 200000
|
||||
#define STAGE_BUF 16384
|
||||
#define LIT_TEXT_CAP 512
|
||||
#define MAX_HOT_TYPES 64
|
||||
#define MAX_USER_BLOCKS 16
|
||||
#define MAX_USER_BLOCKS 8192
|
||||
#define MAX_UBLK_SLOTS 8
|
||||
#define MAX_UBLK_PARTS 16
|
||||
|
||||
@@ -245,6 +246,10 @@ typedef struct {
|
||||
#define rb_text_c tb_ed_w.text_c
|
||||
#define tw tb_ed_w.text_width
|
||||
#define in_rect tb_ed_w.in_rect
|
||||
#define rb_text_f tb_ed_w.text_f
|
||||
#define rb_icon tb_ed_w.icon
|
||||
#define rb_shadow tb_ed_w.shadow
|
||||
#define rb_ripple tb_ed_w.ripple
|
||||
|
||||
static const Col COL_MENU TB_EW_UNUSED = C( 76,151,255); /* #4C97FF */
|
||||
static const Col COL_MENU_DARK TB_EW_UNUSED = C( 61,121,204);
|
||||
@@ -275,6 +280,7 @@ static const Col COL_CODE_BG TB_EW_UNUSED = C( 40, 44, 52);
|
||||
static const Col COL_CODE_GUTTER TB_EW_UNUSED = C( 33, 37, 43);
|
||||
static const Col COL_CODE_CURLINE TB_EW_UNUSED = C( 51, 57, 67);
|
||||
static const Col COL_CODE_FOCUS TB_EW_UNUSED = C( 62, 74, 53);
|
||||
static const Col COL_CODE_SEL TB_EW_UNUSED = C( 38, 79,120); /* selecao no editor de codigo */
|
||||
static const Col COL_CODE_BAR TB_EW_UNUSED = C( 33, 37, 43);
|
||||
static const Col COL_CODE_TEXT TB_EW_UNUSED = C(212, 212, 212);
|
||||
static const Col COL_TIP_BG TB_EW_UNUSED = C( 37, 37, 38);
|
||||
@@ -295,6 +301,8 @@ static const Col s_user_colors[USER_COLOR_COUNT] TB_EW_UNUSED = {
|
||||
C(255,191, 0), C(255,171, 25), C( 89,192, 89), C( 15,189,140),
|
||||
};
|
||||
|
||||
#include "tb_editor_m3.h" /* Material 3 sobre a paleta acima */
|
||||
|
||||
/* == Rótulos dos blocos (%N - campo de entrada N) === */
|
||||
typedef struct {
|
||||
const char* type;
|
||||
@@ -381,6 +389,7 @@ static const BlockSpec s_specs[] = {
|
||||
{"Stage.ImageByNumber", "desenhe imagem número %1 em x %2 y %3", "1|0|0"},
|
||||
{"Stage.Text", "escreva %1 no palco em x %2 y %3", "Olá!|-40|0"},
|
||||
/* Arquivos: pastas e testes (tinyblocks-fs) */
|
||||
{"FS.ReadText", "leia o arquivo %1", "projeto.json"},
|
||||
{"FS.ListDir", "itens da pasta %1", ".|"},
|
||||
{"FS.ListCount", "quantidade de itens na pasta %1", ".|"},
|
||||
{"FS.ListItem", "item %2 da pasta %1", ".|1"},
|
||||
@@ -544,6 +553,20 @@ typedef struct {
|
||||
float x, w;
|
||||
} Part;
|
||||
|
||||
/* Rolagem animada: de `from` a `to` a partir de t0 (curva standard do M3) */
|
||||
typedef struct { bool on; float from, to; unsigned t0; } ScrollAnim;
|
||||
|
||||
/* Bloco apagado saindo de cena: os comandos de desenho dele (na tela) */
|
||||
#define GHOST_MAX 8
|
||||
typedef struct {
|
||||
TinyBlocks_DrawCmd* cmds;
|
||||
int n;
|
||||
float cx, cy;
|
||||
unsigned t0;
|
||||
bool clip;
|
||||
float clip_r[4];
|
||||
} Ghost;
|
||||
|
||||
typedef struct {
|
||||
bool used;
|
||||
bool dragging;
|
||||
@@ -578,6 +601,13 @@ typedef struct {
|
||||
const void* jst_T;
|
||||
int jst_bi, jst_depth;
|
||||
uint32_t jst_gen;
|
||||
/* animacao: deslize ao mudar de lugar na pilha (offset que vai a zero) e
|
||||
surgir (blocos criados por codigo); l_* = o ultimo layout visto */
|
||||
float an_dx, an_dy;
|
||||
unsigned an_t0, ap_t0;
|
||||
bool l_ok;
|
||||
int l_root;
|
||||
float l_x, l_y, l_rx, l_ry;
|
||||
} EdBlock;
|
||||
|
||||
/* Um trecho colorido do editor de codigo (vindo do tinyblocks-syntax). */
|
||||
@@ -597,6 +627,7 @@ typedef struct Tab {
|
||||
int top_cap;
|
||||
int top_n;
|
||||
float ws_sx, ws_sy;
|
||||
float ws_zoom; /* escala da area de scripts (0 = 100%) */
|
||||
char name[48];
|
||||
bool is_composite;
|
||||
int comp_id;
|
||||
@@ -608,6 +639,8 @@ typedef struct Tab {
|
||||
char* code_text;
|
||||
int code_len, code_cap;
|
||||
int code_caret; /* posicao do cursor (offset em bytes) */
|
||||
int code_anchor; /* outra ponta da selecao (= caret: sem selecao) */
|
||||
bool code_drag; /* mouse estendendo a selecao */
|
||||
int code_scroll; /* primeira linha visivel (0-based) */
|
||||
int code_focus; /* linha destacada (1-based), -1 = nenhuma */
|
||||
char code_path[256];
|
||||
@@ -644,7 +677,8 @@ typedef struct Tab {
|
||||
int group_n;
|
||||
} Tab;
|
||||
|
||||
typedef enum { PARAM_NUM, PARAM_BOOL, PARAM_LABEL } ParamKind;
|
||||
/* PARAM_NAME marca onde o nome do bloco aparece; sem ela, o nome vai na frente */
|
||||
typedef enum { PARAM_NUM, PARAM_BOOL, PARAM_LABEL, PARAM_NAME } ParamKind;
|
||||
|
||||
typedef struct { ParamKind kind; char name[32]; } UserParam;
|
||||
|
||||
@@ -678,7 +712,8 @@ typedef enum { SN_NONE, SN_NEXT, SN_SUB, SN_ABOVE, SN_ARG, SN_STACK } SnapKind;
|
||||
enum { CM_DUPLICATE, CM_DELETE, CM_EDIT_DEF, CM_CLEANUP, CM_NEW_COMPOSITE,
|
||||
CM_EXP_JSON, CM_EXP_XML, CM_EXP_CSV, CM_EXP_SB, CM_PASTE_SB,
|
||||
CM_GROUP_NEW, CM_GROUP_STACK, CM_GROUP_RENAME, CM_GROUP_COLOR, CM_GROUP_DELETE,
|
||||
CM_MB_OPEN, CM_MB_SAVE, CM_MB_EXPORT, CM_MB_LIBMAN, CM_MB_LIB, CM_MB_CFG };
|
||||
CM_MB_OPEN, CM_MB_SAVE, CM_MB_EXPORT, CM_MB_LIBMAN, CM_MB_LIB, CM_MB_CFG,
|
||||
CM_SOURCE, CM_SHARE_STACK, CM_SHARE_TAB, CM_RECEIVE };
|
||||
|
||||
/* Modos da barra de caminho do menu (path_input) */
|
||||
enum { PM_NONE, PM_LIB, PM_LOAD, PM_SAVE, PM_EXP_JSON, PM_EXP_XML, PM_EXP_CSV,
|
||||
@@ -820,14 +855,13 @@ typedef struct Ed {
|
||||
int comp_dialog_def; /* -1 = novo; senão índice em user_blocks */
|
||||
bool comp_dialog_in_tab; /* novo bloco: chapéu "defina" na aba atual */
|
||||
bool comp_dialog_editing; /* true = edição de nome/rótulo em andamento */
|
||||
int comp_dialog_edit_part; /* índice da parte em edição, -1 = nome do bloco */
|
||||
int comp_dialog_edit_part; /* índice da parte em edição (a PARAM_NAME edita o nome) */
|
||||
char comp_dialog_name[48];
|
||||
UserParam comp_dialog_parts[MAX_UBLK_PARTS];
|
||||
UserParam comp_dialog_parts[MAX_UBLK_PARTS + 1]; /* + a PARAM_NAME */
|
||||
int comp_dialog_part_n;
|
||||
int comp_dialog_sel; /* parte selecionada (-1 = nenhuma) */
|
||||
int comp_dialog_color;
|
||||
float comp_dialog_geom[MAX_UBLK_PARTS][2]; /* x,w desenhados (para hit test) */
|
||||
float comp_dialog_name_x, comp_dialog_name_w;
|
||||
float comp_dialog_geom[MAX_UBLK_PARTS + 1][2]; /* x,w desenhados (para hit test) */
|
||||
|
||||
bool ctx_menu_open;
|
||||
bool ctx_export; /* menu de contexto aberto e o de exportacao */
|
||||
@@ -862,6 +896,8 @@ typedef struct Ed {
|
||||
SnapKind snap_kind;
|
||||
int snap_bi, snap_idx;
|
||||
float pan_mx, pan_my, pan_sx, pan_sy;
|
||||
bool pinch; /* dois dedos na area de scripts: zoom */
|
||||
float pinch_d0, pinch_z0, pinch_wx, pinch_wy;
|
||||
|
||||
bool editing;
|
||||
int edit_bi, edit_in;
|
||||
@@ -1034,8 +1070,70 @@ typedef struct Ed {
|
||||
|
||||
/* Servidor MCP: agentes leem e editam as pilhas por ferramentas */
|
||||
struct TbMcpServer* mcp;
|
||||
|
||||
/* Animacoes (curvas do M3). anim_off: TINYBLOCKS_REDUCE_MOTION=1 (e os
|
||||
testes): tudo vai direto ao fim */
|
||||
unsigned t_ms; /* relogio do quadro */
|
||||
bool anim_off;
|
||||
bool appear_batch; /* blocos criados agora surgem animados */
|
||||
int appear_k; /* ordem dentro do lote (cascata) */
|
||||
ScrollAnim sa_ws_x, sa_ws_y, sa_fly, sa_cat, sa_lm, sa_st;
|
||||
int sa_ws_tab;
|
||||
struct { bool on; float from, to, ax, ay; unsigned t0; int tab; } za; /* zoom */
|
||||
Ghost ghosts[GHOST_MAX]; /* blocos apagados saindo de cena */
|
||||
int ghost_n;
|
||||
|
||||
/* QR: compartilhar (painel com os QR em loop, 1 s cada) e receber (camera) */
|
||||
bool qrs_open;
|
||||
char* qrs_text; /* scratchblocks inteiro */
|
||||
int qrs_n; /* quantas partes */
|
||||
unsigned qrs_t0;
|
||||
char qrs_id[8];
|
||||
char qrs_title[64];
|
||||
int qrs_force; /* testes: parte fixa no painel (-1 = loop) */
|
||||
bool qrr_open, qrr_cam;
|
||||
struct TbQrReader* qrr_reader;
|
||||
unsigned char* qrr_gray;
|
||||
TinyBlocks_Image* qrr_img; /* previa da camera */
|
||||
char qrr_id[8];
|
||||
int qrr_n, qrr_got;
|
||||
char** qrr_part;
|
||||
float qrr_x, qrr_y; /* onde os blocos recebidos entram */
|
||||
char qrr_msg[200];
|
||||
|
||||
/* Edicao de texto (te_*): o campo em edicao tem cursor e selecao; o
|
||||
editor de codigo tem os dele (code_caret/code_anchor). Alcas e barra
|
||||
de acoes (toque) servem aos dois (te_owner). */
|
||||
unsigned frame_no, draw_no; /* quadros (entrada) e desenhos da principal */
|
||||
bool key_shift, key_ctrl; /* modificadores da tecla/clique atual */
|
||||
char* te_buf; /* campo ligado (NULL = nenhum) */
|
||||
size_t te_cap;
|
||||
bool te_multi; /* aceita quebra de linha */
|
||||
int te_caret, te_anchor; /* selecao = entre os dois (bytes) */
|
||||
unsigned te_frame, te_draw_frame; /* ultimo uso (quadro) / desenho (draw_no) */
|
||||
float te_x, te_y, te_lh, te_fs; /* desenho: x do texto, centro da 1a linha */
|
||||
bool te_ws; /* desenhado na area de scripts (zoom) */
|
||||
bool ws_drawing; /* desenhando a area de scripts agora */
|
||||
int te_owner; /* TE_FIELD / TE_CODE */
|
||||
bool ti_on, ti_kick; /* campo avisado ao SO; toque neste quadro */
|
||||
float ti_x, ti_y, ti_h; /* cursor avisado (teclado na tela / IME) */
|
||||
bool te_drag; /* mouse estendendo a selecao */
|
||||
bool te_handles; /* toque: alcas + barra de acoes */
|
||||
int te_handle_drag; /* alca arrastada (0 = inicio, 1 = fim) */
|
||||
bool te_press; /* dedo apertou no texto (segurar = palavra) */
|
||||
bool te_eat_up; /* o soltar deste toque ja foi tratado */
|
||||
int te_press_owner;
|
||||
float te_press_x, te_press_y;
|
||||
unsigned te_press_t;
|
||||
unsigned te_click_t; /* clique duplo = palavra */
|
||||
float te_click_x, te_click_y;
|
||||
bool te_hvis; /* alcas desenhadas neste quadro */
|
||||
float te_hx[2], te_hy[2]; /* ponta de cima de cada alca (tela) */
|
||||
float te_bar_x, te_bar_y, te_bar_w; /* barra Recortar/Copiar/Colar/Tudo */
|
||||
} Ed;
|
||||
|
||||
enum { TE_NONE, TE_FIELD, TE_CODE };
|
||||
|
||||
static inline TinyBlocks_A11yTree* ed_ax(Ed* ed) { return ed->ax_on ? ed->ax_tree : NULL; }
|
||||
|
||||
#define CT (ed->tabs[ed->cur_tab])
|
||||
@@ -1047,8 +1145,17 @@ static Ed* g_active_ed TB_EW_UNUSED = NULL;
|
||||
void bubble_clear(Ed* ed);
|
||||
|
||||
void palette_rebuild(Ed* ed);
|
||||
/* Bloco (ou a pilha a partir dele) saindo de cena: fantasma animado */
|
||||
void ghost_capture(Ed* ed, Tab* T, int bi, bool chain, float wsx, float wsy, bool clip);
|
||||
void utf8_pop(char* s);
|
||||
void append_text(char* dst, size_t cap, const char* add);
|
||||
/* Campo de texto em edicao (cursor, selecao, Ctrl+A/C/X/V): as teclas e o
|
||||
texto vao para te_key/te_insert e quem desenha chama te_draw depois do
|
||||
texto (x = inicio do texto, cy = centro da 1a linha, lh = altura da linha) */
|
||||
bool te_key(Ed* ed, char* buf, size_t cap, int sc, bool multi);
|
||||
void te_insert(Ed* ed, char* buf, size_t cap, const char* s, bool multi);
|
||||
void te_draw(Ed* ed, TinyBlocks_RenderableBlock* rb, char* buf, size_t cap, bool multi,
|
||||
float x, float cy, float lh, float fs, Col caret);
|
||||
void dlg_open(Ed* ed, int def_idx);
|
||||
void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb);
|
||||
bool dlg_click(Ed* ed, float mx, float my);
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
* TinyBlocks - tb_editor_m3.h
|
||||
*
|
||||
* Linguagem visual do editor: Material 3 (m3.material.io) com as cores que o
|
||||
* editor ja usava. Papeis de cor do M3 apontam para a paleta do TinyBlocks;
|
||||
* formas, tipografia (Roboto), icones (Material Symbols), camadas de estado
|
||||
* e elevacao seguem o M3. Densidade -2 do M3 (desktop): alturas 4 px menores.
|
||||
*
|
||||
* Incluido por tb_editor_internal.h (usa Col, C(), COLA() e rb_*).
|
||||
*/
|
||||
#ifndef TB_EDITOR_M3_H
|
||||
#define TB_EDITOR_M3_H
|
||||
|
||||
/* == Papeis de cor (M3) -> paleta do editor === */
|
||||
#define M3_PRIMARY COL_MENU /* #4C97FF */
|
||||
#define M3_ON_PRIMARY COL_WHITE
|
||||
#define M3_PRIMARY_DARK COL_MENU_DARK
|
||||
#define M3_PRIMARY_CONTAINER COL_HOVER /* #D6E4F8 */
|
||||
#define M3_SECONDARY_CONTAINER COL_TAB_OFF /* #D9E3F2 */
|
||||
#define M3_SURFACE COL_PANEL /* branco */
|
||||
#define M3_SURFACE_LOW COL_FLY /* #F9F9F9 */
|
||||
#define M3_SURFACE_CONTAINER COL_UI_BG /* #E5F0FF */
|
||||
#define M3_ON_SURFACE COL_TEXT /* #575E75 */
|
||||
#define M3_ON_SURFACE_VAR COL_TEXT_DIM
|
||||
#define M3_OUTLINE COL_TEXT_DIM
|
||||
#define M3_OUTLINE_VAR COL_BORDER
|
||||
#define M3_INVERSE_SURFACE COL_TIP_BG
|
||||
#define M3_INVERSE_ON_SURFACE COL_CODE_TEXT
|
||||
#define M3_INVERSE_PRIMARY COL_TIP_LINK
|
||||
#define M3_ERROR COL_STOP
|
||||
|
||||
/* == Formas (raio dos cantos) === */
|
||||
#define M3_SHAPE_XS 4.f
|
||||
#define M3_SHAPE_S 8.f
|
||||
#define M3_SHAPE_M 12.f
|
||||
#define M3_SHAPE_L 16.f
|
||||
#define M3_SHAPE_XL 28.f
|
||||
|
||||
/* == Tipografia (tamanho em px; titulos e rotulos em Roboto Medium) === */
|
||||
#define M3_HEADLINE_S 24.f
|
||||
#define M3_TITLE_L 22.f
|
||||
#define M3_TITLE_M 16.f
|
||||
#define M3_TITLE_S 14.f
|
||||
#define M3_LABEL_L 14.f
|
||||
#define M3_LABEL_M 12.f
|
||||
#define M3_LABEL_S 11.f
|
||||
#define M3_BODY_L 16.f
|
||||
#define M3_BODY_M 14.f
|
||||
#define M3_BODY_S 12.f
|
||||
|
||||
/* == Camadas de estado (opacidade da cor do conteudo) === */
|
||||
#define M3_HOVER 0.08f
|
||||
#define M3_PRESSED 0.10f
|
||||
#define M3_DRAGGED 0.16f
|
||||
|
||||
/* == Componentes: alturas (densidade -2) === */
|
||||
#define M3_BUTTON_H 36.f /* botoes comuns (40 no M3 padrao) */
|
||||
#define M3_ICON_BTN 36.f /* icon button: alvo (40 no padrao) */
|
||||
#define M3_ICON 20.f /* icone dentro de botoes */
|
||||
#define M3_MENU_ITEM 40.f /* item de menu (48 no padrao) */
|
||||
|
||||
/* == Icones (Material Symbols, codepoints) === */
|
||||
#define MI_ADD 0xe145
|
||||
#define MI_ARROW_BACK 0xe5c4
|
||||
#define MI_ARROW_FORWARD 0xe5c8
|
||||
#define MI_ARROW_UPWARD 0xe5d8
|
||||
#define MI_ARROW_RIGHT 0xe5df
|
||||
#define MI_BRUSH 0xe3ae
|
||||
#define MI_CANCEL 0xe888
|
||||
#define MI_CHECK 0xe668
|
||||
#define MI_CHECK_CIRCLE 0xf0be
|
||||
#define MI_CHEVRON_LEFT 0xe5cb
|
||||
#define MI_CHEVRON_RIGHT 0xe5cc
|
||||
#define MI_CIRCLE 0xef4a
|
||||
#define MI_CLOSE 0xe5cd
|
||||
#define MI_CODE 0xe86f
|
||||
#define MI_COLORIZE 0xe3b8
|
||||
#define MI_CONTENT_COPY 0xe14d
|
||||
#define MI_CONTENT_CUT 0xe14e
|
||||
#define MI_CONTENT_PASTE 0xe14f
|
||||
#define MI_CREATE_FOLDER 0xe2cc
|
||||
#define MI_DELETE 0xe92e
|
||||
#define MI_DESCRIPTION 0xe873
|
||||
#define MI_DRAFT 0xe66d
|
||||
#define MI_DRAG_INDICATOR 0xe945
|
||||
#define MI_EDIT 0xf097
|
||||
#define MI_ERROR 0xf8b6
|
||||
#define MI_EXPAND_MORE 0xe5cf
|
||||
#define MI_EXTENSION 0xe87b
|
||||
#define MI_FILL 0xe23a
|
||||
#define MI_FLAG 0xf0c6
|
||||
#define MI_FOLDER 0xe2c7
|
||||
#define MI_GRID_VIEW 0xe9b0
|
||||
#define MI_DATA_OBJECT 0xead3
|
||||
#define MI_TABLE 0xf191
|
||||
#define MI_ACCOUNT_TREE 0xe97a
|
||||
#define MI_SELECT_ALL 0xe162
|
||||
#define MI_ADD_BOX 0xe146
|
||||
#define MI_FOLDER_OPEN 0xe2c8
|
||||
#define MI_HOME 0xe9b2
|
||||
#define MI_IMAGE 0xe3f4
|
||||
#define MI_INFO 0xe88e
|
||||
#define MI_ERASER 0xe6d0
|
||||
#define MI_IOS_SHARE 0xe6b8
|
||||
#define MI_LIBRARY_ADD 0xe03c
|
||||
#define MI_LIBRARY_BOOKS 0xe02f
|
||||
#define MI_MENU 0xe5d2
|
||||
#define MI_MORE_VERT 0xe5d4
|
||||
#define MI_OPEN_IN_NEW 0xe89e
|
||||
#define MI_CLOSE_FULLSCR 0xf1cf
|
||||
#define MI_PALETTE 0xe40a
|
||||
#define MI_PAN_TOOL 0xe925
|
||||
#define MI_PLAY_ARROW 0xe037
|
||||
#define MI_RECTANGLE 0xeb54
|
||||
#define MI_REDO 0xe15a
|
||||
#define MI_REFRESH 0xe5d5
|
||||
#define MI_SAVE 0xe161
|
||||
#define MI_SEARCH 0xef7a
|
||||
#define MI_SHARE 0xe80d
|
||||
#define MI_QR_CODE 0xe00a
|
||||
#define MI_QR_SCANNER 0xf206
|
||||
#define MI_SOURCE 0xf1c8
|
||||
#define MI_SELECT 0xf74d
|
||||
#define MI_SETTINGS 0xe8b8
|
||||
#define MI_STOP 0xe047
|
||||
#define MI_STOP_CIRCLE 0xef71
|
||||
#define MI_SWAP_HORIZ 0xe8d4
|
||||
#define MI_TERMINAL 0xeb8e
|
||||
#define MI_TEXT_FIELDS 0xe262
|
||||
#define MI_UNDO 0xe166
|
||||
#define MI_UPLOAD_FILE 0xe9fc
|
||||
#define MI_WARNING 0xf083
|
||||
#define MI_WIDGETS 0xe1bd
|
||||
#define MI_ZOOM_IN 0xe8ff
|
||||
#define MI_ZOOM_OUT 0xe900
|
||||
|
||||
/* == Movimento: curvas do M3 (cubic-bezier, como no CSS) === */
|
||||
static inline float m3_bezier(float x1, float y1, float x2, float y2, float t) {
|
||||
if (t <= 0.f) return 0.f;
|
||||
if (t >= 1.f) return 1.f;
|
||||
float lo = 0.f, hi = 1.f, u = t;
|
||||
for (int i = 0; i < 24; i++) { /* acha u com x(u) = t (bissecao) */
|
||||
u = (lo + hi) * 0.5f;
|
||||
float iu = 1.f - u;
|
||||
float x = 3.f * iu * iu * u * x1 + 3.f * iu * u * u * x2 + u * u * u;
|
||||
if (x < t) lo = u; else hi = u;
|
||||
}
|
||||
float iu = 1.f - u;
|
||||
return 3.f * iu * iu * u * y1 + 3.f * iu * u * u * y2 + u * u * u;
|
||||
}
|
||||
#define M3_EASE_STANDARD(t) m3_bezier(0.2f, 0.f, 0.f, 1.f, (t))
|
||||
#define M3_EASE_EMPH_DECEL(t) m3_bezier(0.05f, 0.7f, 0.1f, 1.f, (t)) /* entrar */
|
||||
#define M3_EASE_EMPH_ACCEL(t) m3_bezier(0.3f, 0.f, 0.8f, 0.15f, (t)) /* sair */
|
||||
#define M3_DUR_SCROLL 260u /* ms */
|
||||
#define M3_DUR_SLIDE 280u
|
||||
#define M3_DUR_APPEAR 380u
|
||||
#define M3_DUR_EXIT 220u
|
||||
|
||||
/* == Utilitarios === */
|
||||
static inline Col m3_alpha(Col c, float a) { c.a = a; return c; }
|
||||
|
||||
/* c sobre o fundo bg com opacidade a (cor solida resultante) */
|
||||
static inline Col m3_mix(Col bg, Col c, float a) {
|
||||
Col r = { bg.r + (c.r - bg.r) * a, bg.g + (c.g - bg.g) * a, bg.b + (c.b - bg.b) * a, 1.f };
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Largura de um rotulo em Roboto Medium (a medicao do backend e da Regular) */
|
||||
static inline float m3_tw_m(const char* s, float fs) { return tw(s, fs) * 1.04f; }
|
||||
|
||||
/* Camada de estado: a cor do conteudo, translucida, sobre o componente */
|
||||
static inline void m3_state(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad,
|
||||
Col on, bool hover, bool pressed) {
|
||||
float a = pressed ? M3_PRESSED : hover ? M3_HOVER : 0.f;
|
||||
if (a > 0.f) rb_fill_rrect(rb, x, y, w, h, rad, m3_alpha(on, a));
|
||||
rb_ripple(rb, x, y, w, h, rad, on); /* gota do toque/clique */
|
||||
}
|
||||
|
||||
/* == Botoes (pilula): filled, tonal, outlined, text === */
|
||||
enum { M3_FILLED, M3_TONAL, M3_OUTLINED, M3_TEXT };
|
||||
|
||||
static inline float m3_button_w(const char* label, unsigned icon) {
|
||||
return m3_tw_m(label, M3_LABEL_L) + (icon ? 16.f + 18.f + 8.f + 24.f : 48.f);
|
||||
}
|
||||
|
||||
/* accent = cor do papel "primary" deste botao (a do editor ou a do dialogo) */
|
||||
static inline void m3_button(TinyBlocks_RenderableBlock* rb, int kind, float x, float y, float w, float h,
|
||||
const char* label, unsigned icon, Col accent, bool hover, bool pressed) {
|
||||
float r = h * 0.5f;
|
||||
Col on = accent;
|
||||
if (kind == M3_FILLED) {
|
||||
rb_fill_rrect(rb, x, y, w, h, r, accent);
|
||||
on = M3_ON_PRIMARY;
|
||||
} else if (kind == M3_TONAL) {
|
||||
rb_fill_rrect(rb, x, y, w, h, r, m3_mix(M3_SURFACE, accent, 0.16f));
|
||||
on = col_mul(accent, 0.8f);
|
||||
} else if (kind == M3_OUTLINED) {
|
||||
rb_fill_rrect(rb, x, y, w, h, r, M3_OUTLINE_VAR);
|
||||
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, r - 1, M3_SURFACE);
|
||||
}
|
||||
m3_state(rb, x, y, w, h, r, on, hover, pressed);
|
||||
float lw = m3_tw_m(label, M3_LABEL_L);
|
||||
float cx = x + w * 0.5f, cy = y + h * 0.5f;
|
||||
if (icon) {
|
||||
float total = 18.f + 8.f + lw;
|
||||
float ix = cx - total * 0.5f;
|
||||
rb_icon(rb, ix + 9.f, cy, icon, 18.f, on, false);
|
||||
rb_text_f(rb, ix + 26.f, cy, label, on, M3_LABEL_L, TB_FONT_MEDIUM);
|
||||
} else {
|
||||
rb_text_f(rb, cx - lw * 0.5f, cy, label, on, M3_LABEL_L, TB_FONT_MEDIUM);
|
||||
}
|
||||
}
|
||||
|
||||
/* Icon button (padrao): so o icone; o circulo aparece no hover/pressionado.
|
||||
selected = toggle ligado (container tonal) */
|
||||
static inline void m3_icon_button(TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned icon, Col c,
|
||||
bool hover, bool selected) {
|
||||
float s = M3_ICON_BTN;
|
||||
if (selected) rb_fill_circle(rb, cx, cy, s * 0.5f, m3_alpha(c, 0.16f));
|
||||
if (hover) rb_fill_circle(rb, cx, cy, s * 0.5f, m3_alpha(c, M3_HOVER));
|
||||
rb_ripple(rb, cx - s * 0.5f, cy - s * 0.5f, s, s, s * 0.5f, c);
|
||||
rb_icon(rb, cx, cy, icon, M3_ICON, c, selected);
|
||||
}
|
||||
|
||||
/* == Superficies === */
|
||||
/* Menu: canto XS, elevacao 2 */
|
||||
static inline void m3_menu_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
|
||||
rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 2);
|
||||
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_SURFACE);
|
||||
}
|
||||
|
||||
/* Item de menu: icone opcional a esquerda, rotulo Label Large */
|
||||
static inline void m3_menu_item(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
|
||||
const char* label, unsigned icon, bool hover, Col fg) {
|
||||
m3_state(rb, x, y, w, h, 0, M3_ON_SURFACE, hover, false);
|
||||
float tx = x + 12.f;
|
||||
if (icon) { rb_icon(rb, tx + 10.f, y + h * 0.5f, icon, M3_ICON, M3_ON_SURFACE_VAR, false); tx += 20.f + 12.f; }
|
||||
rb_text_f(rb, tx, y + h * 0.5f, label, fg, M3_LABEL_L, TB_FONT_REGULAR);
|
||||
}
|
||||
|
||||
/* Dialogo: canto XL, elevacao 3 */
|
||||
static inline void m3_dialog_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
|
||||
rb_shadow(rb, x, y, w, h, M3_SHAPE_XL, 3);
|
||||
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XL, M3_SURFACE);
|
||||
}
|
||||
|
||||
/* Scrim atras de dialogos modais */
|
||||
static inline void m3_scrim(TinyBlocks_RenderableBlock* rb, float w, float h) {
|
||||
rb_fill_rect(rb, 0, 0, w, h, COLA(0, 0, 0, 82));
|
||||
}
|
||||
|
||||
/* Campo de texto "outlined": canto XS, contorno 1 px (2 px na cor
|
||||
primaria quando em foco) */
|
||||
static inline void m3_field(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
|
||||
bool focused, Col accent) {
|
||||
if (focused) {
|
||||
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, accent);
|
||||
rb_fill_rrect(rb, x + 2, y + 2, w - 4, h - 4, M3_SHAPE_XS - 1, M3_SURFACE);
|
||||
} else {
|
||||
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_OUTLINE);
|
||||
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, M3_SHAPE_XS - 0.5f, M3_SURFACE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Barra de busca: pilula, icone de lupa a esquerda */
|
||||
static inline void m3_search_bar(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
|
||||
bool focused, Col accent) {
|
||||
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, M3_SURFACE_CONTAINER);
|
||||
if (focused) {
|
||||
rb_fill_rrect(rb, x - 1, y - 1, w + 2, h + 2, h * 0.5f + 1, accent);
|
||||
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, h * 0.5f - 1, M3_SURFACE_CONTAINER);
|
||||
}
|
||||
rb_icon(rb, x + 16.f + 12.f, y + h * 0.5f, MI_SEARCH, 24.f, M3_ON_SURFACE_VAR, false);
|
||||
}
|
||||
|
||||
/* Indicador da aba ativa (aba primaria): 3 px com cantos de cima redondos */
|
||||
static inline void m3_tab_indicator(TinyBlocks_RenderableBlock* rb, float x, float y_bottom, float w, Col c) {
|
||||
rb_fill_rrect(rb, x, y_bottom - 3.f, w, 6.f, 3.f, c);
|
||||
}
|
||||
|
||||
/* Chip (assist/filter): canto S, 32 px */
|
||||
static inline void m3_chip(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, const char* label,
|
||||
unsigned icon, bool selected, bool hover) {
|
||||
if (selected) rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_S, M3_SECONDARY_CONTAINER);
|
||||
else {
|
||||
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_S, M3_OUTLINE_VAR);
|
||||
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, M3_SHAPE_S - 1, M3_SURFACE);
|
||||
}
|
||||
m3_state(rb, x, y, w, h, M3_SHAPE_S, M3_ON_SURFACE, hover, false);
|
||||
float tx = x + 12.f;
|
||||
if (icon) { rb_icon(rb, x + 8.f + 9.f, y + h * 0.5f, icon, 18.f, M3_PRIMARY, false); tx = x + 8.f + 18.f + 8.f; }
|
||||
rb_text_f(rb, tx, y + h * 0.5f, label, M3_ON_SURFACE, M3_LABEL_L, TB_FONT_MEDIUM);
|
||||
}
|
||||
|
||||
/* Snackbar: superficie inversa, canto XS, elevacao 3 */
|
||||
static inline void m3_snackbar_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
|
||||
rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 3);
|
||||
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_INVERSE_SURFACE);
|
||||
}
|
||||
|
||||
/* Interruptor (switch) do M3: trilho 52x32, alca 16 (24 ligado) */
|
||||
static inline void m3_switch(TinyBlocks_RenderableBlock* rb, float x, float y, bool on, Col accent) {
|
||||
const float w = 52.f, h = 32.f;
|
||||
if (on) {
|
||||
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, accent);
|
||||
rb_fill_circle(rb, x + w - 16.f, y + h * 0.5f, 12.f, M3_ON_PRIMARY);
|
||||
rb_icon(rb, x + w - 16.f, y + h * 0.5f, MI_CHECK, 16.f, accent, false);
|
||||
} else {
|
||||
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, M3_OUTLINE);
|
||||
rb_fill_rrect(rb, x + 2, y + 2, w - 4, h - 4, h * 0.5f - 2, M3_SURFACE_CONTAINER);
|
||||
rb_fill_circle(rb, x + 16.f, y + h * 0.5f, 8.f, M3_OUTLINE);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* TB_EDITOR_M3_H */
|
||||
@@ -48,6 +48,13 @@ typedef struct {
|
||||
void (*text_c) (TinyBlocks_RenderableBlock*, float, float, const char*, TbEwColor, float);
|
||||
float (*text_width) (const char*, float);
|
||||
bool (*in_rect) (float, float, float, float, float, float);
|
||||
void (*text_f) (TinyBlocks_RenderableBlock*, float, float, const char*, TbEwColor, float, int);
|
||||
void (*icon) (TinyBlocks_RenderableBlock*, float, float, unsigned, float, TbEwColor, bool);
|
||||
void (*shadow) (TinyBlocks_RenderableBlock*, float, float, float, float, float, int);
|
||||
void (*anim_now) (double);
|
||||
void (*ripple_down) (float, float);
|
||||
void (*ripple_up) (void);
|
||||
void (*ripple) (TinyBlocks_RenderableBlock*, float, float, float, float, float, TbEwColor);
|
||||
} TbEdWidgetsApi;
|
||||
|
||||
/* API da library privada tinyblocks-editor-image */
|
||||
|
||||
@@ -21,19 +21,17 @@
|
||||
#include "tb_editor_files.h"
|
||||
|
||||
/* -- Geometria --- */
|
||||
#define FD_HEAD_H 46
|
||||
#define FD_HEAD_H 60
|
||||
#define FD_BAR_H 44
|
||||
#define FD_SIDE_W 196
|
||||
#define FD_COLH_H 26
|
||||
#define FD_ROW_H 26
|
||||
#define FD_ROW_H 32
|
||||
#define FD_FOOT_H 100
|
||||
#define FD_PAD 14
|
||||
#define FD_BTN_W 104
|
||||
#define FD_BTN_H 32
|
||||
#define FD_BTN_H 36
|
||||
|
||||
static const Col COL_FD_FOLDER = C(255,191, 38);
|
||||
static const Col COL_FD_FOLDER_DARK = C(222,150, 10);
|
||||
static const Col COL_FD_SIDE = C(242,246,252);
|
||||
static const Col COL_FD_JSON = C(255,140, 26);
|
||||
static const Col COL_FD_IMAGE = C( 15,189,140);
|
||||
static const Col COL_FD_LIB = C(153,102,255);
|
||||
@@ -66,8 +64,8 @@ static void fd_layout(Ed* ed, FdL* L) {
|
||||
L->w = w; L->h = h;
|
||||
L->x = (WIN_W - w) * 0.5f;
|
||||
L->y = (WIN_H - h) * 0.5f;
|
||||
L->close_cx = L->x + w - 26.f;
|
||||
L->close_cy = L->y + FD_HEAD_H * 0.5f;
|
||||
L->close_cx = L->x + w - 32.f;
|
||||
L->close_cy = L->y + FD_HEAD_H * 0.5f + 2.f;
|
||||
L->bar_y = L->y + FD_HEAD_H + 7.f;
|
||||
L->up_x = L->x + FD_PAD;
|
||||
L->crumb_x = L->up_x + 40.f;
|
||||
@@ -565,11 +563,11 @@ void tb_editor_files_open(Ed* ed, int mode, const char* def) {
|
||||
|
||||
/* -- Desenho --- */
|
||||
|
||||
/* Icones do Material Symbols (x, y = canto do quadrado de 20 px) */
|
||||
static void fd_icon_folder(TinyBlocks_RenderableBlock* rb, float x, float y, bool dim) {
|
||||
Col c = COL_FD_FOLDER, d = COL_FD_FOLDER_DARK;
|
||||
if (dim) { c.a = 0.55f; d.a = 0.55f; }
|
||||
rb_fill_rrect(rb, x, y + 1, 9, 6, 2, d);
|
||||
rb_fill_rrect(rb, x, y + 4, 19, 13, 2, c);
|
||||
Col c = COL_FD_FOLDER;
|
||||
if (dim) c.a = 0.55f;
|
||||
rb_icon(rb, x + 10, y + 9, dim ? MI_ARROW_UPWARD : MI_FOLDER, 20.f, dim ? M3_ON_SURFACE_VAR : c, !dim);
|
||||
}
|
||||
|
||||
static Col fd_type_col(const char* name) {
|
||||
@@ -583,37 +581,38 @@ static Col fd_type_col(const char* name) {
|
||||
return COL_TEXT_DIM;
|
||||
}
|
||||
|
||||
static void fd_icon_file(TinyBlocks_RenderableBlock* rb, float x, float y, Col band) {
|
||||
rb_fill_rrect(rb, x + 2, y, 15, 18, 2, COL_BORDER);
|
||||
rb_fill_rrect(rb, x + 3, y + 1, 13, 16, 1.5f, COL_WHITE);
|
||||
rb_fill_rect(rb, x + 3, y + 11, 13, 5, band);
|
||||
rb_line(rb, x + 6, y + 5, x + 13, y + 5, 1, COL_BORDER);
|
||||
rb_line(rb, x + 6, y + 8, x + 13, y + 8, 1, COL_BORDER);
|
||||
static unsigned fd_type_icon(const char* name) {
|
||||
const char* e = fd_ext(name);
|
||||
if (!strcasecmp(e, ".json") || !strcasecmp(e, ".xml") || !strcasecmp(e, ".csv")) return MI_DATA_OBJECT;
|
||||
if (!strcasecmp(e, ".png") || !strcasecmp(e, ".jpg") || !strcasecmp(e, ".jpeg") ||
|
||||
!strcasecmp(e, ".bmp") || !strcasecmp(e, ".ppm") || !strcasecmp(e, ".svg")) return MI_IMAGE;
|
||||
if (!strcasecmp(e, ".so")) return MI_EXTENSION;
|
||||
if (!strcasecmp(e, ".c") || !strcasecmp(e, ".h") || !strcasecmp(e, ".py") ||
|
||||
!strcasecmp(e, ".md") || !strcasecmp(e, ".toml")) return MI_CODE;
|
||||
return MI_DRAFT;
|
||||
}
|
||||
|
||||
static void fd_icon_file(TinyBlocks_RenderableBlock* rb, float x, float y, Col band, const char* name) {
|
||||
rb_icon(rb, x + 10, y + 9, fd_type_icon(name), 20.f, band, false);
|
||||
}
|
||||
|
||||
/* Caixa de selecao do M3 (16 px aqui, canto 2) com o rotulo */
|
||||
static void fd_checkbox(TinyBlocks_RenderableBlock* rb, float x, float cy, bool on, const char* label) {
|
||||
float s = 16;
|
||||
float s = 18;
|
||||
if (on) {
|
||||
rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 3, COL_MENU);
|
||||
rb_line(rb, x + 4, cy, x + 7, cy + 4, 2, COL_WHITE);
|
||||
rb_line(rb, x + 7, cy + 4, x + 12, cy - 4, 2, COL_WHITE);
|
||||
rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 2, M3_PRIMARY);
|
||||
rb_icon(rb, x + s * 0.5f, cy, MI_CHECK, 16.f, M3_ON_PRIMARY, false);
|
||||
} else {
|
||||
rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 3, COL_BORDER);
|
||||
rb_fill_rrect(rb, x + 1.5f, cy - s * 0.5f + 1.5f, s - 3, s - 3, 2, COL_WHITE);
|
||||
rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 2, M3_ON_SURFACE_VAR);
|
||||
rb_fill_rrect(rb, x + 2, cy - s * 0.5f + 2, s - 4, s - 4, 1, M3_SURFACE);
|
||||
}
|
||||
rb_text_c(rb, x + s + 8, cy, label, COL_TEXT, FS_UI);
|
||||
rb_text_f(rb, x + s + 10, cy, label, M3_ON_SURFACE, M3_BODY_M, TB_FONT_REGULAR);
|
||||
}
|
||||
|
||||
/* Acoes do dialogo: a principal e "filled", a outra e botao de texto */
|
||||
static void fd_button(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
|
||||
const char* label, bool primary, bool hov, Col accent) {
|
||||
if (primary) {
|
||||
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, hov ? col_mul(accent, 0.86f) : accent);
|
||||
rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, y + h * 0.5f, label, COL_WHITE, FS_UI);
|
||||
} else {
|
||||
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, COL_BORDER);
|
||||
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, h * 0.5f - 1, hov ? COL_HOVER : COL_WHITE);
|
||||
rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, y + h * 0.5f, label, COL_TEXT, FS_UI);
|
||||
}
|
||||
m3_button(rb, primary ? M3_FILLED : M3_TEXT, x, y, w, h, label, 0, accent, hov, false);
|
||||
}
|
||||
|
||||
/* Caixa de confirmacao "substituir?" (geometria compartilhada com o clique) */
|
||||
@@ -712,34 +711,26 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
bool modal_free = !F->confirm;
|
||||
char buf[512];
|
||||
|
||||
rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, COLA(0, 0, 0, 120));
|
||||
rb_fill_rrect(rb, L.x + 3, L.y + 4, L.w, L.h, 12, COLA(0, 0, 0, 70));
|
||||
rb_fill_rrect(rb, L.x, L.y, L.w, L.h, 12, COL_PANEL);
|
||||
m3_scrim(rb, WIN_W, WIN_H);
|
||||
m3_dialog_surface(rb, L.x, L.y, L.w, L.h);
|
||||
|
||||
/* Cabecalho */
|
||||
rb_fill_rrect(rb, L.x, L.y, L.w, FD_HEAD_H, 12, COL_MENU);
|
||||
rb_fill_rect(rb, L.x, L.y + FD_HEAD_H - 12, L.w, 12, COL_MENU);
|
||||
rb_text_c(rb, L.x + (L.w - tw(F->title, 18)) * 0.5f, L.y + FD_HEAD_H * 0.5f, F->title, COL_WHITE, 18);
|
||||
{
|
||||
bool hov = modal_free && hypotf(mx - L.close_cx, my - L.close_cy) < 14.f;
|
||||
rb_fill_circle(rb, L.close_cx, L.close_cy, 13, COLA(255, 255, 255, hov ? 110 : 60));
|
||||
rb_line(rb, L.close_cx - 5, L.close_cy - 5, L.close_cx + 5, L.close_cy + 5, 2, COL_WHITE);
|
||||
rb_line(rb, L.close_cx + 5, L.close_cy - 5, L.close_cx - 5, L.close_cy + 5, 2, COL_WHITE);
|
||||
}
|
||||
/* Cabecalho: icone + titulo (headline) a esquerda, fechar a direita */
|
||||
rb_icon(rb, L.x + 24 + 12, L.y + FD_HEAD_H * 0.5f + 2, F->save ? MI_SAVE : MI_FOLDER_OPEN, 24.f, M3_PRIMARY, false);
|
||||
rb_text_f(rb, L.x + 24 + 24 + 12, L.y + FD_HEAD_H * 0.5f + 2, F->title, M3_ON_SURFACE, M3_HEADLINE_S,
|
||||
TB_FONT_REGULAR);
|
||||
m3_icon_button(rb, L.close_cx, L.close_cy, MI_CLOSE, M3_ON_SURFACE_VAR,
|
||||
modal_free && hypotf(mx - L.close_cx, my - L.close_cy) < 16.f, false);
|
||||
|
||||
/* Barra: pasta acima + trilha */
|
||||
{
|
||||
float by = L.bar_y, bh = 30;
|
||||
bool hov = modal_free && in_rect(mx, my, L.up_x, by, 32, bh);
|
||||
bool can_up = strcmp(F->dir, "/") != 0;
|
||||
rb_fill_rrect(rb, L.up_x, by, 32, bh, 6, hov && can_up ? COL_HOVER : COL_UI_BG);
|
||||
Col ac = can_up ? COL_TEXT : COL_TEXT_DIM;
|
||||
float cx = L.up_x + 16, cy = by + bh * 0.5f;
|
||||
rb_line(rb, cx, cy + 7, cx, cy - 7, 2, ac);
|
||||
rb_line(rb, cx - 6, cy - 1, cx, cy - 7, 2, ac);
|
||||
rb_line(rb, cx + 6, cy - 1, cx, cy - 7, 2, ac);
|
||||
m3_icon_button(rb, cx, cy, MI_ARROW_UPWARD, can_up ? M3_ON_SURFACE_VAR : m3_alpha(M3_ON_SURFACE, 0.38f),
|
||||
hov && can_up, false);
|
||||
|
||||
rb_fill_rrect(rb, L.crumb_x, by, L.crumb_w, bh, 6, COL_UI_BG);
|
||||
rb_fill_rrect(rb, L.crumb_x, by, L.crumb_w, bh, bh * 0.5f, M3_SURFACE_CONTAINER);
|
||||
FdCrumbs K;
|
||||
fd_crumbs(ed, &L, &K);
|
||||
if (K.ellipsis)
|
||||
@@ -750,37 +741,39 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
fd_fit(fit, sizeof(fit), lb, FS_UI, K.w[k] - 16.f);
|
||||
bool last = k == K.n - 1;
|
||||
bool h = modal_free && !last && in_rect(mx, my, K.x[k], by + 3, K.w[k], bh - 6);
|
||||
if (last) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, 5, COL_WHITE);
|
||||
else if (h) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, 5, COL_HOVER);
|
||||
rb_text_c(rb, K.x[k] + 8, cy, fit, last ? COL_TEXT : COL_MENU_DARK, FS_UI);
|
||||
if (!last && k > 0) rb_text_c(rb, K.x[k] + K.w[k] + 3, cy, "/", COL_TEXT_DIM, FS_UI);
|
||||
if (last) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, (bh - 6) * 0.5f, M3_SECONDARY_CONTAINER);
|
||||
else if (h) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, (bh - 6) * 0.5f,
|
||||
m3_alpha(M3_ON_SURFACE, M3_HOVER));
|
||||
rb_text_f(rb, K.x[k] + 8, cy, fit, last ? M3_ON_SURFACE : M3_PRIMARY_DARK, M3_LABEL_L, TB_FONT_MEDIUM);
|
||||
if (!last && k > 0) rb_icon(rb, K.x[k] + K.w[k] + 7, cy, MI_CHEVRON_RIGHT, 16.f, M3_ON_SURFACE_VAR, false);
|
||||
}
|
||||
}
|
||||
|
||||
/* Barra lateral: locais */
|
||||
rb_line(rb, L.x, L.side_y, L.x + L.w, L.side_y, 1, COL_BORDER);
|
||||
rb_line(rb, L.x, L.side_y, L.x + L.w, L.side_y, 1, M3_OUTLINE_VAR);
|
||||
if (L.side_w > 0) {
|
||||
rb_fill_rect(rb, L.side_x, L.side_y, L.side_w, L.side_h, COL_FD_SIDE);
|
||||
rb_line(rb, L.side_x + L.side_w, L.side_y, L.side_x + L.side_w, L.side_y + L.side_h, 1, COL_BORDER);
|
||||
rb_text_c(rb, L.side_x + FD_PAD, L.side_y + 16, "Locais", COL_TEXT_DIM, FS_SM);
|
||||
rb_line(rb, L.side_x + L.side_w, L.side_y, L.side_x + L.side_w, L.side_y + L.side_h, 1, M3_OUTLINE_VAR);
|
||||
rb_text_f(rb, L.side_x + FD_PAD + 4, L.side_y + 16, "Locais", M3_ON_SURFACE_VAR, M3_TITLE_S, TB_FONT_MEDIUM);
|
||||
}
|
||||
for (int i = 0; L.side_w > 0 && i < F->place_n; i++) {
|
||||
for (int i = 0; L.side_w > 0 && i < F->place_n; i++) { /* itens da gaveta de navegacao */
|
||||
float iy = L.side_y + 30 + i * 32;
|
||||
bool cur = strcmp(F->dir, F->place_path[i]) == 0;
|
||||
bool h = modal_free && in_rect(mx, my, L.side_x + 6, iy, L.side_w - 12, 30);
|
||||
if (cur || h) rb_fill_rrect(rb, L.side_x + 6, iy, L.side_w - 12, 30, 6, cur ? COL_HOVER : COLA(214, 228, 248, 140));
|
||||
if (cur) rb_fill_rrect(rb, L.side_x + 6, iy + 6, 3, 18, 1.5f, COL_MENU);
|
||||
fd_icon_folder(rb, L.side_x + 16, iy + 6, false);
|
||||
if (cur) rb_fill_rrect(rb, L.side_x + 6, iy, L.side_w - 12, 30, 15, M3_SECONDARY_CONTAINER);
|
||||
m3_state(rb, L.side_x + 6, iy, L.side_w - 12, 30, 15, M3_ON_SURFACE, h, false);
|
||||
rb_icon(rb, L.side_x + 16 + 10, iy + 15, MI_FOLDER, 20.f, cur ? M3_ON_SURFACE : M3_ON_SURFACE_VAR, cur);
|
||||
fd_fit(buf, sizeof(buf), F->place_label[i], FS_UI, L.side_w - 60);
|
||||
rb_text_c(rb, L.side_x + 42, iy + 15, buf, cur ? COL_MENU_DARK : COL_TEXT, FS_UI);
|
||||
rb_text_f(rb, L.side_x + 44, iy + 15, buf, M3_ON_SURFACE, M3_LABEL_L, cur ? TB_FONT_MEDIUM : TB_FONT_REGULAR);
|
||||
}
|
||||
|
||||
/* Cabecalho das colunas */
|
||||
float col_size = L.col_size, col_time = L.col_time;
|
||||
rb_text_c(rb, L.list_x + 44, L.colh_y + FD_COLH_H * 0.5f, "Nome", COL_TEXT_DIM, FS_SM);
|
||||
if (col_size) rb_text_c(rb, col_size, L.colh_y + FD_COLH_H * 0.5f, "Tamanho", COL_TEXT_DIM, FS_SM);
|
||||
if (col_time) rb_text_c(rb, col_time, L.colh_y + FD_COLH_H * 0.5f, "Modificado", COL_TEXT_DIM, FS_SM);
|
||||
rb_line(rb, L.list_x, L.list_y, L.list_x + L.list_w, L.list_y, 1, COL_BORDER);
|
||||
rb_text_f(rb, L.list_x + 44, L.colh_y + FD_COLH_H * 0.5f, "Nome", M3_ON_SURFACE_VAR, M3_LABEL_M, TB_FONT_MEDIUM);
|
||||
if (col_size) rb_text_f(rb, col_size, L.colh_y + FD_COLH_H * 0.5f, "Tamanho", M3_ON_SURFACE_VAR, M3_LABEL_M,
|
||||
TB_FONT_MEDIUM);
|
||||
if (col_time) rb_text_f(rb, col_time, L.colh_y + FD_COLH_H * 0.5f, "Modificado", M3_ON_SURFACE_VAR, M3_LABEL_M,
|
||||
TB_FONT_MEDIUM);
|
||||
rb_line(rb, L.list_x, L.list_y, L.list_x + L.list_w, L.list_y, 1, M3_OUTLINE_VAR);
|
||||
|
||||
/* Linhas */
|
||||
int end = F->scroll + L.rows;
|
||||
@@ -790,12 +783,14 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
float ry = L.list_y + (float)(i - F->scroll) * FD_ROW_H;
|
||||
bool sel = i == F->sel;
|
||||
bool h = modal_free && in_rect(mx, my, L.list_x, ry, L.list_w - 12, FD_ROW_H);
|
||||
if (sel) rb_fill_rrect(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, 5, COL_MENU);
|
||||
else if (h) rb_fill_rrect(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, 5, COL_HOVER);
|
||||
Col tc = sel ? COL_WHITE : COL_TEXT;
|
||||
Col dc = sel ? COLA(255, 255, 255, 210) : COL_TEXT_DIM;
|
||||
if (e->is_dir) fd_icon_folder(rb, L.list_x + 14, ry + 4, e->is_dir == 2);
|
||||
else fd_icon_file(rb, L.list_x + 14, ry + 4, fd_type_col(e->name));
|
||||
if (sel) rb_fill_rrect(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, M3_SHAPE_S,
|
||||
M3_SECONDARY_CONTAINER);
|
||||
m3_state(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, M3_SHAPE_S, M3_ON_SURFACE, h, false);
|
||||
Col tc = M3_ON_SURFACE;
|
||||
Col dc = M3_ON_SURFACE_VAR;
|
||||
float iy = ry + (FD_ROW_H - 18) * 0.5f;
|
||||
if (e->is_dir) fd_icon_folder(rb, L.list_x + 14, iy, e->is_dir == 2);
|
||||
else fd_icon_file(rb, L.list_x + 14, iy, fd_type_col(e->name), e->name);
|
||||
fd_fit(buf, sizeof(buf), e->is_dir == 2 ? ".. (pasta acima)" : e->name, FS_UI,
|
||||
L.name_end - (L.list_x + 44) - 16);
|
||||
rb_text_c(rb, L.list_x + 44, ry + FD_ROW_H * 0.5f, buf, tc, FS_UI);
|
||||
@@ -821,8 +816,7 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
float kh = th * (float)L.rows / (float)F->n;
|
||||
if (kh < 24) kh = 24;
|
||||
float ky = L.list_y + 4 + (th - kh) * (float)F->scroll / (float)(F->n - L.rows);
|
||||
rb_fill_rrect(rb, tx, L.list_y + 4, 6, th, 3, COL_UI_BG);
|
||||
rb_fill_rrect(rb, tx, ky, 6, kh, 3, COL_TEXT_DIM);
|
||||
rb_fill_rrect(rb, tx + 1, ky, 4, kh, 2, m3_alpha(M3_ON_SURFACE, 0.38f));
|
||||
}
|
||||
if (F->err[0]) {
|
||||
float ey = L.list_y + L.list_h - 30;
|
||||
@@ -833,10 +827,9 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
|
||||
/* Rodape: nome + opcoes + botoes */
|
||||
float foot = L.name_y - 14.f;
|
||||
rb_line(rb, L.x, foot, L.x + L.w, foot, 1, COL_BORDER);
|
||||
rb_text_c(rb, L.x + FD_PAD, L.name_y + 15, "Nome:", COL_TEXT, FS_UI);
|
||||
rb_fill_rrect(rb, L.name_x, L.name_y, L.name_w, 30, 6, COL_MENU);
|
||||
rb_fill_rrect(rb, L.name_x + 1.5f, L.name_y + 1.5f, L.name_w - 3, 27, 5, COL_WHITE);
|
||||
rb_line(rb, L.x, foot, L.x + L.w, foot, 1, M3_OUTLINE_VAR);
|
||||
rb_text_f(rb, L.x + FD_PAD + 4, L.name_y + 15, "Nome:", M3_ON_SURFACE, M3_BODY_M, TB_FONT_MEDIUM);
|
||||
m3_field(rb, L.name_x, L.name_y - 3, L.name_w, 36, true, M3_PRIMARY);
|
||||
{
|
||||
float maxw = L.name_w - 24;
|
||||
const char* s = F->name;
|
||||
@@ -860,7 +853,7 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
char f2[120];
|
||||
snprintf(f2, sizeof(f2), "(%s)", F->filter);
|
||||
fd_fit(buf, sizeof(buf), f2, FS_SM, L.chk_hid_x - L.chk_all_x - 160);
|
||||
rb_text_c(rb, L.chk_all_x + 24 + tw("Todos os arquivos", FS_UI) + 8, r2, buf, COL_TEXT_DIM, FS_SM);
|
||||
rb_text_f(rb, L.chk_all_x + 28 + tw("Todos os arquivos", M3_BODY_M) + 10, r2, buf, M3_ON_SURFACE_VAR, M3_BODY_S, TB_FONT_REGULAR);
|
||||
}
|
||||
}
|
||||
fd_checkbox(rb, L.chk_hid_x, r2, F->show_hidden, "Mostrar ocultos");
|
||||
@@ -871,18 +864,17 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
|
||||
/* Confirmacao de substituicao */
|
||||
if (F->confirm) {
|
||||
rb_fill_rrect(rb, L.x, L.y, L.w, L.h, 12, COLA(0, 0, 0, 60));
|
||||
rb_fill_rrect(rb, L.x, L.y, L.w, L.h, M3_SHAPE_XL, COLA(0, 0, 0, 60));
|
||||
float bx, by, bw, bh;
|
||||
fd_confirm_geom(&L, &bx, &by, &bw, &bh);
|
||||
rb_fill_rrect(rb, bx + 2, by + 3, bw, bh, 10, COLA(0, 0, 0, 60));
|
||||
rb_fill_rrect(rb, bx, by, bw, bh, 10, COL_PANEL);
|
||||
m3_dialog_surface(rb, bx, by, bw, bh);
|
||||
const char* b = strrchr(F->name, '/');
|
||||
b = b ? b + 1 : F->name;
|
||||
char q[400];
|
||||
snprintf(q, sizeof(q), "\"%s\" já existe.", b);
|
||||
fd_fit(buf, sizeof(buf), q, 15, bw - 40);
|
||||
rb_text_c(rb, bx + 20, by + 34, buf, COL_TEXT, 15);
|
||||
rb_text_c(rb, bx + 20, by + 60, "Deseja substituir o arquivo?", COL_TEXT_DIM, FS_UI);
|
||||
rb_text_f(rb, bx + 24, by + 36, buf, M3_ON_SURFACE, M3_TITLE_L - 2, TB_FONT_REGULAR);
|
||||
rb_text_f(rb, bx + 24, by + 64, "Deseja substituir o arquivo?", M3_ON_SURFACE_VAR, M3_BODY_M, TB_FONT_REGULAR);
|
||||
float yb = by + bh - FD_BTN_H - 16;
|
||||
float xo = bx + bw - 20 - FD_BTN_W, xc = xo - 10 - FD_BTN_W;
|
||||
fd_button(rb, xc, yb, FD_BTN_W, FD_BTN_H, "Cancelar", false,
|
||||
|
||||
@@ -25,7 +25,6 @@ static void img_clear_layer(Tab* T);
|
||||
static const Col COL_PAINT_BG = C(233,238,242);
|
||||
static const Col COL_PAINT_LINE = C(212,220,228);
|
||||
static const Col COL_PAINT_SHAD = C(196,205,214);
|
||||
static const Col COL_PAINT_BTN = C(255,255,255);
|
||||
static const Col COL_L_RASTER = C(255,152, 0);
|
||||
static const Col COL_L_VECTOR = C( 0,151,167);
|
||||
static const Col COL_CHK_A = C(255,255,255);
|
||||
@@ -180,10 +179,10 @@ static float img_pal_y(Ed* ed) {
|
||||
static void img_zoom_slider(Ed* ed, float* x, float* y, float* w, float* h) {
|
||||
float ax, ay, aw, ah;
|
||||
img_area(ed, &ax, &ay, &aw, &ah);
|
||||
*x = ax + 176;
|
||||
*w = aw - 176 - 14;
|
||||
*x = ax + 8 + 112 + 4 + 96 + 20; /* depois de Desfazer e Limpar */
|
||||
*w = aw - (8 + 112 + 4 + 96 + 20) - 28;
|
||||
*h = IMG_SLIDER_H;
|
||||
*y = img_foot_y(ed) + 22.f;
|
||||
*y = img_foot_y(ed) + (IMG_FOOT_H - IMG_SLIDER_H) * 0.5f + 4.f;
|
||||
(void)h; (void)ah;
|
||||
*h = IMG_SLIDER_H;
|
||||
}
|
||||
@@ -214,10 +213,10 @@ static void img_foot_btn(Ed* ed, int which, float* x, float* y, float* w, float*
|
||||
float ax, ay, aw, ah, fy;
|
||||
img_area(ed, &ax, &ay, &aw, &ah);
|
||||
fy = img_foot_y(ed);
|
||||
*y = fy + 5; *h = 24;
|
||||
*y = fy + 3; *h = 28;
|
||||
switch (which) {
|
||||
case 0: *w = 78; *x = ax + 10; break; /* Desfazer */
|
||||
case 1: *w = 68; *x = ax + 96; break; /* Limpar */
|
||||
case 0: *w = 112; *x = ax + 8; break; /* Desfazer */
|
||||
case 1: *w = 96; *x = ax + 8 + 112 + 4; break; /* Limpar */
|
||||
|
||||
default: *w = 30; *x = ax + aw - 40; break;
|
||||
}
|
||||
@@ -644,40 +643,14 @@ static void img_undo_do(Tab* T) {
|
||||
T->img_rev++;
|
||||
}
|
||||
|
||||
/* Icones das ferramentas --- */
|
||||
static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, float cy, Col c) {
|
||||
switch (tool) {
|
||||
case IT_SEL:
|
||||
rb_line(rb, cx - 6, cy - 8, cx - 6, cy + 7, 2.f, c);
|
||||
rb_line(rb, cx - 6, cy - 8, cx + 5, cy + 1, 2.f, c);
|
||||
rb_line(rb, cx - 6, cy - 1, cx + 3, cy + 7, 2.f, c);
|
||||
break;
|
||||
case IT_BRUSH:
|
||||
rb_line(rb, cx - 8, cy + 8, cx + 3, cy - 3, 5.f, c);
|
||||
rb_fill_circle(rb, cx + 6, cy - 6, 3.4f, c);
|
||||
break;
|
||||
case IT_LINE:
|
||||
rb_line(rb, cx - 8, cy + 8, cx + 8, cy - 8, 2.f, c);
|
||||
break;
|
||||
case IT_RECT:
|
||||
rb_stroke_rect(rb, cx - 8, cy - 6, 16, 12, 2.f, c);
|
||||
break;
|
||||
case IT_ELLIPSE:
|
||||
rb_stroke_circle(rb, cx, cy, 8, 2.f, c);
|
||||
break;
|
||||
case IT_FILL:
|
||||
rb_fill_rrect(rb, cx - 8, cy - 8, 13, 13, 3, c);
|
||||
rb_fill_circle(rb, cx + 4, cy + 5, 4, c);
|
||||
break;
|
||||
case IT_ERASER:
|
||||
rb_fill_rrect(rb, cx - 8, cy - 3, 16, 9, 2, c);
|
||||
rb_line(rb, cx - 8, cy + 6, cx + 8, cy + 6, 2.f, col_mul(c, 0.6f));
|
||||
break;
|
||||
case IT_PICK:
|
||||
rb_line(rb, cx + 7, cy - 7, cx + 2, cy - 2, 3.f, c);
|
||||
rb_fill_circle(rb, cx - 2, cy + 2, 4.4f, c);
|
||||
break;
|
||||
}
|
||||
/* Icones das ferramentas (Material Symbols) --- */
|
||||
static const unsigned IMG_TOOL_ICON[IT_N] = {
|
||||
[IT_SEL] = 0xf82f /* arrow_selector_tool */, [IT_BRUSH] = MI_BRUSH, [IT_LINE] = 0xf41e /* diagonal_line */,
|
||||
[IT_RECT] = MI_RECTANGLE, [IT_ELLIPSE] = MI_CIRCLE, [IT_FILL] = MI_FILL,
|
||||
[IT_ERASER] = MI_ERASER, [IT_PICK] = MI_COLORIZE,
|
||||
};
|
||||
static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, float cy, Col c, bool on) {
|
||||
rb_icon(rb, cx, cy, IMG_TOOL_ICON[tool], 24.f, c, on);
|
||||
}
|
||||
|
||||
/* Render --- */
|
||||
@@ -810,32 +783,33 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
rb_fill_rect(rb, WS_X, WS_Y, WS_W, WS_H, COL_PAINT_BG);
|
||||
|
||||
/* --- coluna esquerda: ferramentas --- */
|
||||
rb_fill_rect(rb, WS_X, WS_Y, IMG_TOOL_W, WS_H, COL_PANEL);
|
||||
rb_line(rb, WS_X + IMG_TOOL_W - 1, WS_Y, WS_X + IMG_TOOL_W - 1, WS_Y + WS_H, 1.f, COL_PAINT_LINE);
|
||||
for (int i = 0; i < IT_N; i++) {
|
||||
rb_fill_rect(rb, WS_X, WS_Y, IMG_TOOL_W, WS_H, M3_SURFACE);
|
||||
rb_line(rb, WS_X + IMG_TOOL_W - 1, WS_Y, WS_X + IMG_TOOL_W - 1, WS_Y + WS_H, 1.f, M3_OUTLINE_VAR);
|
||||
for (int i = 0; i < IT_N; i++) { /* icon buttons de alternar (M3) */
|
||||
float bx, by;
|
||||
img_tool_rect(ed, i, &bx, &by);
|
||||
bool sel = T->img_tool == i;
|
||||
bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, IMG_TH, IMG_TH);
|
||||
Col bg = sel ? COL_MENU : (hov ? COL_HOVER : COL_PAINT_BTN);
|
||||
rb_fill_rrect(rb, bx, by, IMG_TH, IMG_TH, 8, bg);
|
||||
if (!sel) rb_stroke_rect(rb, bx, by, IMG_TH, IMG_TH, 1.f, COL_PAINT_LINE);
|
||||
img_draw_icon(rb, i, bx + IMG_TH * 0.5f, by + IMG_TH * 0.5f, sel ? COL_WHITE : COL_TEXT);
|
||||
if (hov && !sel)
|
||||
rb_text_c(rb, bx + IMG_TH + 6, by + IMG_TH * 0.5f, img_tool_tip(i), COL_TEXT_DIM, 10.f);
|
||||
if (sel) rb_fill_rrect(rb, bx, by, IMG_TH, IMG_TH, M3_SHAPE_M, M3_PRIMARY);
|
||||
m3_state(rb, bx, by, IMG_TH, IMG_TH, M3_SHAPE_M, sel ? M3_ON_PRIMARY : M3_ON_SURFACE, hov, false);
|
||||
img_draw_icon(rb, i, bx + IMG_TH * 0.5f, by + IMG_TH * 0.5f, sel ? M3_ON_PRIMARY : M3_ON_SURFACE_VAR, sel);
|
||||
if (hov && !sel) { /* tooltip simples do M3 */
|
||||
const char* tip = img_tool_tip(i);
|
||||
float tw_ = tw(tip, M3_BODY_S) + 16, ty = by + IMG_TH * 0.5f - 12;
|
||||
rb_fill_rrect(rb, bx + IMG_TH + 6, ty, tw_, 24, M3_SHAPE_XS, M3_INVERSE_SURFACE);
|
||||
rb_text_f(rb, bx + IMG_TH + 14, ty + 12, tip, M3_INVERSE_ON_SURFACE, M3_BODY_S, TB_FONT_REGULAR);
|
||||
}
|
||||
}
|
||||
|
||||
/* --- barra superior (arquivo) --- */
|
||||
rb_fill_rect(rb, WS_X + IMG_TOOL_W, WS_Y, WS_W - IMG_TOOL_W, IMG_BAR_H, COL_PANEL);
|
||||
rb_fill_rect(rb, WS_X + IMG_TOOL_W, WS_Y, WS_W - IMG_TOOL_W, IMG_BAR_H, M3_SURFACE);
|
||||
rb_line(rb, WS_X + IMG_TOOL_W, WS_Y + IMG_BAR_H - 1,
|
||||
WS_X + WS_W, WS_Y + IMG_BAR_H - 1, 1.f, COL_PAINT_LINE);
|
||||
WS_X + WS_W, WS_Y + IMG_BAR_H - 1, 1.f, M3_OUTLINE_VAR);
|
||||
{
|
||||
float bx = WS_X + IMG_TOOL_W + 10;
|
||||
rb_fill_rrect(rb, bx, WS_Y + 5, 62, 24, 6, COL_MENU);
|
||||
rb_text_c(rb, bx + (62 - tw("Abrir", FS_UI-1)) * 0.5f, WS_Y + 17, "Abrir", COL_WHITE, FS_UI-1);
|
||||
float bx = WS_X + IMG_TOOL_W + 10, mx = ed->mouse_x, my = ed->mouse_y;
|
||||
m3_button(rb, M3_TONAL, bx, WS_Y + 4, 62, 26, "Abrir", 0, M3_PRIMARY, in_rect(mx, my, bx, WS_Y + 4, 62, 26), false);
|
||||
bx += 70;
|
||||
rb_fill_rrect(rb, bx, WS_Y + 5, 62, 24, 6, COL_MENU_DARK);
|
||||
rb_text_c(rb, bx + (62 - tw("Salvar", FS_UI-1)) * 0.5f, WS_Y + 17, "Salvar", COL_WHITE, FS_UI-1);
|
||||
m3_button(rb, M3_FILLED, bx, WS_Y + 4, 62, 26, "Salvar", 0, M3_PRIMARY, in_rect(mx, my, bx, WS_Y + 4, 62, 26), false);
|
||||
bx += 74;
|
||||
char pbuf[40];
|
||||
snprintf(pbuf, sizeof(pbuf), "%.30s", T->img_path[0] ? T->img_path : "sem arquivo");
|
||||
@@ -848,8 +822,8 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
(int)(T->img_zoom * 100.f + 0.5f), T->img_w, T->img_h);
|
||||
if (img_narrow(ed)) { /* sem espaco para o resumo: botao da coluna */
|
||||
float cx = WS_X + WS_W - IMG_PANEL_BTN_W - 8;
|
||||
rb_fill_rrect(rb, cx, WS_Y + 5, IMG_PANEL_BTN_W, 24, 6, ed->img_panel_open ? COL_MENU_DARK : COL_MENU);
|
||||
rb_text_c(rb, cx + (IMG_PANEL_BTN_W - tw("Cores", FS_UI-1)) * 0.5f, WS_Y + 17, "Cores", COL_WHITE, FS_UI-1);
|
||||
m3_button(rb, ed->img_panel_open ? M3_FILLED : M3_TONAL, cx, WS_Y + 4, IMG_PANEL_BTN_W, 26, "Cores", 0,
|
||||
M3_PRIMARY, in_rect(ed->mouse_x, ed->mouse_y, cx, WS_Y + 4, IMG_PANEL_BTN_W, 26), false);
|
||||
} else
|
||||
rb_text_c(rb, WS_X + WS_W - 12 - tw(info, FS_UI-1), WS_Y + 17, info, COL_TEXT_DIM, FS_UI-1);
|
||||
}
|
||||
@@ -926,18 +900,16 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
float ax, ay, aw, ah, fy;
|
||||
img_area(ed, &ax, &ay, &aw, &ah);
|
||||
fy = img_foot_y(ed);
|
||||
rb_fill_rect(rb, ax, fy, aw, IMG_FOOT_H, COL_PANEL);
|
||||
rb_line(rb, ax, fy, WS_X + WS_W, fy, 1.f, COL_PAINT_LINE);
|
||||
rb_fill_rect(rb, ax, fy, aw, IMG_FOOT_H, M3_SURFACE);
|
||||
rb_line(rb, ax, fy, WS_X + WS_W, fy, 1.f, M3_OUTLINE_VAR);
|
||||
const char* labels[2] = { "Desfazer", "Limpar" };
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int i = 0; i < 2; i++) { /* botoes de texto com icone */
|
||||
float bx, by, bw, bh;
|
||||
img_foot_btn(ed, i, &bx, &by, &bw, &bh);
|
||||
bool enabled = !(i == 0 && T->img_undo_n == 0);
|
||||
bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, bw, bh);
|
||||
rb_fill_rrect(rb, bx, by, bw, bh, 6, hov && enabled ? COL_HOVER : COL_PAINT_BTN);
|
||||
rb_stroke_rect(rb, bx, by, bw, bh, 1.f, COL_PAINT_LINE);
|
||||
rb_text_c(rb, bx + (bw - tw(labels[i], FS_UI-1)) * 0.5f, by + bh * 0.5f,
|
||||
labels[i], enabled ? COL_TEXT : COL_TEXT_DIM, FS_UI - 1);
|
||||
m3_button(rb, M3_TEXT, bx, by, bw, bh, labels[i], i == 0 ? MI_UNDO : MI_DELETE,
|
||||
enabled ? M3_PRIMARY : m3_alpha(M3_ON_SURFACE, 0.38f), hov && enabled, false);
|
||||
}
|
||||
|
||||
/* --- widget novo: slider de zoom --- */
|
||||
@@ -947,19 +919,17 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
float t = img_zoom_t(T->img_zoom);
|
||||
float kx = sx + t * (sw - 14.f) + 7.f;
|
||||
bool hov = in_rect(ed->mouse_x, ed->mouse_y, sx - 6, sy - 10, sw + 12, sh + 20);
|
||||
/* trilha */
|
||||
rb_fill_rrect(rb, sx, sy, sw, sh, 3, COL_PAINT_BTN);
|
||||
/* parte preenchida ate o botao */
|
||||
rb_fill_rrect(rb, sx, sy, kx - sx, sh, 3, hov ? COL_MENU : COLA(0, 122, 216, 255));
|
||||
rb_stroke_rect(rb, sx, sy, sw, sh, 1.f, COL_PAINT_LINE);
|
||||
/* marcas de 100% */
|
||||
{
|
||||
/* slider do M3: trilha ativa (primaria) e inativa (container) */
|
||||
float tcy = sy + sh * 0.5f;
|
||||
rb_fill_rrect(rb, sx, tcy - 2, sw, 4, 2, M3_SECONDARY_CONTAINER);
|
||||
rb_fill_rrect(rb, sx, tcy - 2, kx - sx, 4, 2, M3_PRIMARY);
|
||||
{ /* marca de 100% */
|
||||
float mxr = sx + img_zoom_t(1.f) * (sw - 14.f) + 7.f;
|
||||
rb_fill_rect(rb, mxr - 0.5f, sy - 3, 1.f, sh + 6, COL_TEXT_DIM);
|
||||
rb_fill_circle(rb, mxr, tcy, 1.5f, kx > mxr ? M3_ON_PRIMARY : M3_PRIMARY);
|
||||
}
|
||||
/* botao */
|
||||
rb_fill_circle(rb, kx, sy + sh * 0.5f, 7.f, COL_WHITE);
|
||||
rb_stroke_circle(rb, kx, sy + sh * 0.5f, 7.f, 2.f, hov ? COL_MENU : COLA(0, 122, 216, 255));
|
||||
/* alca */
|
||||
if (hov) rb_fill_circle(rb, kx, tcy, 14.f, m3_alpha(M3_PRIMARY, M3_HOVER));
|
||||
rb_fill_circle(rb, kx, tcy, 8.f, M3_PRIMARY);
|
||||
/* porcentagem acima do botao */
|
||||
{
|
||||
char z[16];
|
||||
@@ -976,16 +946,16 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
if (img_panel_shown(ed)) {
|
||||
float px = img_color_x(ed);
|
||||
float cx_, cy_, ro, ri;
|
||||
rb_fill_rect(rb, px, WS_Y, IMG_RIGHT_W, WS_H, COL_PANEL);
|
||||
rb_line(rb, px - 1, WS_Y, px - 1, WS_Y + WS_H, 1.f, COL_PAINT_LINE);
|
||||
rb_text_c(rb, px + 12, WS_Y + 16, "Cores", COL_TEXT_DIM, 11.f);
|
||||
rb_fill_rect(rb, px, WS_Y, IMG_RIGHT_W, WS_H, M3_SURFACE);
|
||||
rb_line(rb, px - 1, WS_Y, px - 1, WS_Y + WS_H, 1.f, M3_OUTLINE_VAR);
|
||||
rb_text_f(rb, px + 12, WS_Y + 18, "Cores", M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM);
|
||||
|
||||
/* amostra da cor atual */
|
||||
{
|
||||
Col cc = COLA(T->img_rgb[0], T->img_rgb[1], T->img_rgb[2], 255);
|
||||
float sw = 30.f, sx = px + IMG_RIGHT_W - 14 - sw;
|
||||
rb_fill_rrect(rb, sx, WS_Y + 5, sw, sw, 5, COL_PAINT_LINE);
|
||||
rb_fill_rrect(rb, sx + 2, WS_Y + 7, sw - 4, sw - 4, 4, cc);
|
||||
rb_fill_circle(rb, sx + sw * 0.5f, WS_Y + 5 + sw * 0.5f, sw * 0.5f, M3_OUTLINE_VAR);
|
||||
rb_fill_circle(rb, sx + sw * 0.5f, WS_Y + 5 + sw * 0.5f, sw * 0.5f - 2, cc);
|
||||
}
|
||||
|
||||
/* roda de matiz: linhas radiais coloridas */
|
||||
@@ -1025,15 +995,15 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
rb_stroke_circle(rb, mx_, my_, 5.f, 1.2f, COL_TEXT);
|
||||
}
|
||||
/* paleta rapida (3 x 4) */
|
||||
rb_text_c(rb, px + 12, img_pal_y(ed) - 14, "Paleta", COL_TEXT_DIM, 10.f);
|
||||
rb_text_f(rb, px + 12, img_pal_y(ed) - 14, "Paleta", M3_ON_SURFACE_VAR, M3_LABEL_M, TB_FONT_MEDIUM);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
float sx, sy;
|
||||
img_swatch_rect(ed, i, &sx, &sy);
|
||||
bool hov = in_rect(ed->mouse_x, ed->mouse_y, sx, sy, 34, 22);
|
||||
rb_fill_rrect(rb, sx, sy, 34, 22, 4, COL_PAINT_LINE);
|
||||
rb_fill_rrect(rb, sx + 2, sy + 2, 30, 18, 3, IMG_PALETTE[i]);
|
||||
if (i == T->img_swatch) rb_stroke_rect(rb, sx - 1, sy - 1, 36, 24, 2.f, COL_MENU);
|
||||
else if (hov) rb_stroke_rect(rb, sx - 1, sy - 1, 36, 24, 1.4f, COL_TEXT_DIM);
|
||||
bool on = i == T->img_swatch;
|
||||
if (on || hov) rb_fill_rrect(rb, sx - 2, sy - 2, 38, 26, M3_SHAPE_S, on ? M3_PRIMARY : M3_OUTLINE);
|
||||
rb_fill_rrect(rb, sx, sy, 34, 22, M3_SHAPE_S - 2, on || hov ? M3_SURFACE : M3_OUTLINE_VAR);
|
||||
rb_fill_rrect(rb, sx + 2, sy + 2, 30, 18, M3_SHAPE_S - 3, IMG_PALETTE[i]);
|
||||
}
|
||||
/* informacao da cor escolhida */
|
||||
{
|
||||
@@ -1044,19 +1014,21 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
|
||||
/* --- camadas: embaixo da roda de cores (como no Krita) --- */
|
||||
rb_line(rb, px + IMG_PAD, img_layers_title_y(ed) - 14,
|
||||
px + IMG_RIGHT_W - IMG_PAD, img_layers_title_y(ed) - 14, 1.f, COL_PAINT_LINE);
|
||||
rb_text_c(rb, px + IMG_PAD, img_layers_title_y(ed), "Camadas", COL_TEXT_DIM, 11.f);
|
||||
px + IMG_RIGHT_W - IMG_PAD, img_layers_title_y(ed) - 14, 1.f, M3_OUTLINE_VAR);
|
||||
rb_icon(rb, px + IMG_PAD + 9, img_layers_title_y(ed), 0xe53b /* layers */, 18.f, M3_ON_SURFACE_VAR, false);
|
||||
rb_text_f(rb, px + IMG_PAD + 24, img_layers_title_y(ed), "Camadas", M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM);
|
||||
for (int i = 0; i < T->img_layer_n; i++) {
|
||||
float rx, ry, rw, rh;
|
||||
img_layer_row(ed, i, &rx, &ry, &rw, &rh);
|
||||
bool sel = (i == T->img_layer_cur);
|
||||
bool hov = in_rect(ed->mouse_x, ed->mouse_y, rx, ry, rw, rh);
|
||||
rb_fill_rrect(rb, rx, ry, rw, rh, 6, sel ? COL_MENU : (hov ? COL_HOVER : COL_PAINT_BTN));
|
||||
rb_stroke_rect(rb, rx, ry, rw, rh, 1.f, sel ? COL_MENU_DARK : COL_PAINT_LINE);
|
||||
Col tc = sel ? COL_WHITE : COL_TEXT;
|
||||
/* item de lista do M3; selecionado = container */
|
||||
if (sel) rb_fill_rrect(rb, rx, ry, rw, rh, M3_SHAPE_S, M3_SECONDARY_CONTAINER);
|
||||
m3_state(rb, rx, ry, rw, rh, M3_SHAPE_S, M3_ON_SURFACE, hov, false);
|
||||
Col tc = M3_ON_SURFACE;
|
||||
/* olho (visibilidade) */
|
||||
if (T->img_layers[i].visible) rb_fill_circle(rb, rx + 11, ry + rh * 0.5f, 4.5f, tc);
|
||||
else rb_stroke_circle(rb, rx + 11, ry + rh * 0.5f, 4.5f, 1.4f, tc);
|
||||
rb_icon(rb, rx + 11, ry + rh * 0.5f, T->img_layers[i].visible ? 0xe8f4 : 0xe8f5, 16.f,
|
||||
M3_ON_SURFACE_VAR, false);
|
||||
/* miniatura (como uma fantasia do Scratch) */
|
||||
{
|
||||
float tx = rx + 20, ty = ry + 4, tw_ = rw - 26, th_ = rh - 8;
|
||||
@@ -1076,17 +1048,16 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
}
|
||||
/* botoes: excluir / nova raster / nova vetor */
|
||||
{
|
||||
const char* labels[3] = { "- Camada", "+ Raster", "+ Vetor" };
|
||||
Col bgs[3] = { {236/255.f,120/255.f,110/255.f,1.f}, COL_MENU, COL_L_VECTOR };
|
||||
const char* labels[3] = { "Camada", "Raster", "Vetor" };
|
||||
static const unsigned icons[3] = { 0xe15b /* remove */, MI_ADD, MI_ADD };
|
||||
Col bgs[3] = { COL_STOP, M3_PRIMARY, COL_L_VECTOR };
|
||||
for (int i = 0; i < 3; i++) {
|
||||
float bx2, by2, bw2, bh2;
|
||||
img_side_btn(ed, i, &bx2, &by2, &bw2, &bh2);
|
||||
bool enabled = !(i == 0 && T->img_layer_n <= 1);
|
||||
bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx2, by2, bw2, bh2);
|
||||
Col bg = enabled ? (hov ? col_mul(bgs[i], 0.85f) : bgs[i]) : COL_PAINT_SHAD;
|
||||
rb_fill_rrect(rb, bx2, by2, bw2, bh2, 6, bg);
|
||||
rb_text_c(rb, bx2 + (bw2 - tw(labels[i], FS_UI-1)) * 0.5f, by2 + bh2 * 0.5f,
|
||||
labels[i], COL_WHITE, FS_UI - 1);
|
||||
m3_button(rb, i == 0 ? M3_OUTLINED : M3_TONAL, bx2, by2, bw2, bh2, labels[i], icons[i],
|
||||
enabled ? bgs[i] : m3_alpha(M3_ON_SURFACE, 0.38f), hov && enabled, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,22 @@ void tb_ew_line (TinyBlocks_RenderableBlock* rb, float x0, float y0, float
|
||||
void tb_ew_text_c (TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs);
|
||||
/* Largura real do texto, medida pelo backend grafico */
|
||||
float tb_ew_text_width(const char* s, float fs);
|
||||
/* Texto numa fonte (TB_FONT_REGULAR / TB_FONT_MEDIUM), centrado em cy */
|
||||
void tb_ew_text_f (TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs,
|
||||
int font);
|
||||
/* Icone do Material Symbols (codepoint, ex.: 0xE8B8 = settings) centrado em
|
||||
* (cx, cy); size = lado do icone (24 no Material 3) */
|
||||
void tb_ew_icon (TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned cp, float size, TbEwColor c,
|
||||
bool filled);
|
||||
/* Sombra de elevacao do Material 3 (level 1..5) atras de (x, y, w, h) */
|
||||
/* Ripple do M3 (a gota que cresce do ponto tocado): o editor informa o
|
||||
* relogio e o apertar/soltar; cada componente chama tb_ew_ripple com o
|
||||
* proprio retangulo (so desenha se o toque comecou nele) */
|
||||
void tb_ew_anim_now (double ms);
|
||||
void tb_ew_ripple_down(float x, float y);
|
||||
void tb_ew_ripple_up (void);
|
||||
void tb_ew_ripple (TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, TbEwColor on);
|
||||
void tb_ew_shadow (TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, int level);
|
||||
|
||||
bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* traduz chamadas em TinyBlocks_DrawCmd.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <tb_graphics.h>
|
||||
#include "tb_editor_widgets.h"
|
||||
|
||||
@@ -40,5 +41,82 @@ float tb_ew_text_width(const char* s, float fs) {
|
||||
return tb_graphics_measure_text(s, fs);
|
||||
}
|
||||
|
||||
void tb_ew_text_f(TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs,
|
||||
int font) {
|
||||
if (!s || !s[0]) return;
|
||||
tb_draw_text_font(rb, x, cy + fs * 0.36f, s, fs, font, c.r, c.g, c.b, c.a);
|
||||
}
|
||||
|
||||
void tb_ew_icon(TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned cp, float size, TbEwColor c,
|
||||
bool filled) {
|
||||
char u[5] = {0}; /* UTF-8 do codepoint (area privada: 3 bytes) */
|
||||
if (cp < 0x800) { u[0] = (char)(0xC0 | (cp >> 6)); u[1] = (char)(0x80 | (cp & 0x3F)); }
|
||||
else if (cp < 0x10000) {
|
||||
u[0] = (char)(0xE0 | (cp >> 12)); u[1] = (char)(0x80 | ((cp >> 6) & 0x3F));
|
||||
u[2] = (char)(0x80 | (cp & 0x3F));
|
||||
} else {
|
||||
u[0] = (char)(0xF0 | (cp >> 18)); u[1] = (char)(0x80 | ((cp >> 12) & 0x3F));
|
||||
u[2] = (char)(0x80 | ((cp >> 6) & 0x3F)); u[3] = (char)(0x80 | (cp & 0x3F));
|
||||
}
|
||||
/* o glifo ocupa 1 em acima da linha de base, avanco = 1 em */
|
||||
tb_draw_text_font(rb, cx - size * 0.5f, cy + size * 0.5f, u, size,
|
||||
filled ? TB_FONT_ICON_FILLED : TB_FONT_ICON, c.r, c.g, c.b, c.a);
|
||||
}
|
||||
|
||||
static struct { bool on, held; float x, y; double down, up; } s_rip;
|
||||
static double s_now;
|
||||
|
||||
void tb_ew_anim_now(double ms) { s_now = ms; }
|
||||
void tb_ew_ripple_down(float x, float y) {
|
||||
s_rip.on = true; s_rip.held = true; s_rip.x = x; s_rip.y = y; s_rip.down = s_now;
|
||||
}
|
||||
void tb_ew_ripple_up(void) { if (s_rip.held) { s_rip.held = false; s_rip.up = s_now; } }
|
||||
|
||||
/* cubic-bezier(0.05, 0.7, 0.1, 1) ~ "emphasized decelerate" do M3 */
|
||||
static float ease_out(float t) { float u = 1.f - t; return 1.f - u * u * u * u; }
|
||||
|
||||
void tb_ew_ripple(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, TbEwColor on) {
|
||||
if (!s_rip.on || s_rip.x < x || s_rip.x >= x + w || s_rip.y < y || s_rip.y >= y + h) return;
|
||||
const double GROW = 300.0, FADE = 220.0;
|
||||
float g = (float)((s_now - s_rip.down) / GROW);
|
||||
if (g > 1.f) g = 1.f;
|
||||
float a = 0.12f;
|
||||
if (!s_rip.held) { /* some depois de crescer ate o fim */
|
||||
double st = s_rip.up > s_rip.down + 150.0 ? s_rip.up : s_rip.down + 150.0;
|
||||
float f = (float)((s_now - st) / FADE);
|
||||
if (f >= 1.f) { s_rip.on = false; return; }
|
||||
if (f > 0.f) a *= 1.f - f;
|
||||
}
|
||||
float dx = fmaxf(s_rip.x - x, x + w - s_rip.x), dy = fmaxf(s_rip.y - y, y + h - s_rip.y);
|
||||
float r = sqrtf(dx * dx + dy * dy) * (0.2f + 0.8f * ease_out(g));
|
||||
if (rad > w * 0.5f) rad = w * 0.5f;
|
||||
if (rad > h * 0.5f) rad = h * 0.5f;
|
||||
/* circulo recortado no retangulo de cantos redondos, em faixas */
|
||||
float step = h > 80.f ? 2.f : 1.f;
|
||||
for (float yy = y; yy < y + h; yy += step) {
|
||||
float cy = yy + step * 0.5f, d = cy - s_rip.y;
|
||||
if (fabsf(d) >= r) continue;
|
||||
float hw = sqrtf(r * r - d * d);
|
||||
float l = s_rip.x - hw, rr = s_rip.x + hw, in = 0.f;
|
||||
if (cy < y + rad) { float k = y + rad - cy; in = rad - sqrtf(fmaxf(0.f, rad * rad - k * k)); }
|
||||
else if (cy > y + h - rad) { float k = cy - (y + h - rad); in = rad - sqrtf(fmaxf(0.f, rad * rad - k * k)); }
|
||||
if (l < x + in) l = x + in;
|
||||
if (rr > x + w - in) rr = x + w - in;
|
||||
if (rr > l) tb_draw_fill_rect(rb, l, yy, rr - l, step, on.r, on.g, on.b, on.a * a);
|
||||
}
|
||||
}
|
||||
|
||||
void tb_ew_shadow(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, int level) {
|
||||
if (level <= 0) return;
|
||||
/* camadas cada vez maiores e mais fracas, puxadas para baixo (luz de cima) */
|
||||
float dy = 0.5f + level * 0.75f;
|
||||
int n = 2 + level;
|
||||
for (int i = n; i >= 1; i--) {
|
||||
float g = (float)i;
|
||||
float a = 0.10f / (float)n * (float)(n - i + 1) * (0.6f + 0.1f * level);
|
||||
tb_draw_fill_rrect(rb, x - g * 0.5f, y - g * 0.5f + dy, w + g, h + g, rad + g * 0.5f, 0, 0, 0, a);
|
||||
}
|
||||
}
|
||||
|
||||
bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h)
|
||||
{ return mx >= x && mx < x + w && my >= y && my < y + h; }
|
||||
@@ -405,6 +405,7 @@ static void t_replace_stack(void* user, TbMcpRequest* rq) {
|
||||
warn[0] ? ": " : "", warn, head);
|
||||
return;
|
||||
}
|
||||
if (T == &CT && AREA(V_SCRIPTS).shown) ghost_capture(ed, T, head, true, WS_X, WS_Y, true); /* sai de cena */
|
||||
free_tree(ed, T, head);
|
||||
changed(ed, T);
|
||||
report_new_stacks(ed, rq, T, heads, n < 64 ? n : 64, warn);
|
||||
@@ -419,6 +420,7 @@ static void t_delete_stack(void* user, TbMcpRequest* rq) {
|
||||
head = stack_root(T, head);
|
||||
char label[TB_A11Y_NAME_MAX];
|
||||
ax_block_label(T, head, label, sizeof(label), 0);
|
||||
if (T == &CT && AREA(V_SCRIPTS).shown) ghost_capture(ed, T, head, true, WS_X, WS_Y, true); /* sai de cena */
|
||||
free_tree(ed, T, head);
|
||||
changed(ed, T);
|
||||
tb_mcp_req_text(rq, "Pilha %d (\"%s\") apagada", head, label);
|
||||
@@ -616,6 +618,7 @@ static void t_delete_block(void* user, TbMcpRequest* rq) {
|
||||
char label[TB_A11Y_NAME_MAX];
|
||||
ax_block_label(T, bi, label, sizeof(label), 0);
|
||||
if (tb_mcp_req_bool(rq, "with_below", false)) {
|
||||
if (T == &CT && AREA(V_SCRIPTS).shown) ghost_capture(ed, T, bi, true, WS_X, WS_Y, true);
|
||||
if (T->ws[bi].parent >= 0) detach(T, bi);
|
||||
free_tree(ed, T, bi);
|
||||
} else {
|
||||
@@ -920,7 +923,12 @@ void ed_mcp_start(Ed* ed) {
|
||||
}
|
||||
|
||||
void ed_mcp_poll(Ed* ed) {
|
||||
if (ed->mcp) tb_mcp_server_poll(ed->mcp);
|
||||
if (!ed->mcp) return;
|
||||
/* blocos criados por agentes surgem animados (em cascata, por pedido) */
|
||||
ed->appear_batch = true;
|
||||
ed->appear_k = 0;
|
||||
tb_mcp_server_poll(ed->mcp);
|
||||
ed->appear_batch = false;
|
||||
}
|
||||
|
||||
void ed_mcp_stop(Ed* ed) {
|
||||
|
||||
@@ -124,8 +124,16 @@ static bool resolve_widgets(void) {
|
||||
sym_fn(&w.text_c, "tinyblocks-editor-widgets", "tb_ew_text_c");
|
||||
sym_fn(&w.text_width, "tinyblocks-editor-widgets", "tb_ew_text_width");
|
||||
sym_fn(&w.in_rect, "tinyblocks-editor-widgets", "tb_ew_in_rect");
|
||||
sym_fn(&w.text_f, "tinyblocks-editor-widgets", "tb_ew_text_f");
|
||||
sym_fn(&w.icon, "tinyblocks-editor-widgets", "tb_ew_icon");
|
||||
sym_fn(&w.shadow, "tinyblocks-editor-widgets", "tb_ew_shadow");
|
||||
sym_fn(&w.anim_now, "tinyblocks-editor-widgets", "tb_ew_anim_now");
|
||||
sym_fn(&w.ripple_down, "tinyblocks-editor-widgets", "tb_ew_ripple_down");
|
||||
sym_fn(&w.ripple_up, "tinyblocks-editor-widgets", "tb_ew_ripple_up");
|
||||
sym_fn(&w.ripple, "tinyblocks-editor-widgets", "tb_ew_ripple");
|
||||
bool ok = w.col_mul && w.fill_rect && w.fill_rrect && w.fill_circle && w.stroke_rect &&
|
||||
w.stroke_circle && w.line && w.text_c && w.text_width && w.in_rect;
|
||||
w.stroke_circle && w.line && w.text_c && w.text_width && w.in_rect &&
|
||||
w.text_f && w.icon && w.shadow && w.anim_now && w.ripple_down && w.ripple_up && w.ripple;
|
||||
if (ok) tb_ed_w = w;
|
||||
return ok;
|
||||
}
|
||||
@@ -174,7 +182,10 @@ bool tb_ed_modules_load(Ed* ed) {
|
||||
.col_mul = tb_ew_col_mul, .fill_rect = tb_ew_fill_rect, .fill_rrect = tb_ew_fill_rrect,
|
||||
.fill_circle = tb_ew_fill_circle, .stroke_rect = tb_ew_stroke_rect,
|
||||
.stroke_circle = tb_ew_stroke_circle, .line = tb_ew_line, .text_c = tb_ew_text_c,
|
||||
.text_width = tb_ew_text_width, .in_rect = tb_ew_in_rect };
|
||||
.text_width = tb_ew_text_width, .in_rect = tb_ew_in_rect,
|
||||
.text_f = tb_ew_text_f, .icon = tb_ew_icon, .shadow = tb_ew_shadow,
|
||||
.anim_now = tb_ew_anim_now, .ripple_down = tb_ew_ripple_down, .ripple_up = tb_ew_ripple_up,
|
||||
.ripple = tb_ew_ripple };
|
||||
tb_ed_img = (TbEdImageApi){
|
||||
.view = tb_editor_image_view, .click = tb_editor_image_click, .drag = tb_editor_image_drag,
|
||||
.release = tb_editor_image_release, .load_file = tb_editor_image_load_file,
|
||||
|
||||
@@ -45,10 +45,11 @@ static int64_t in_int(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
|
||||
static void eval_open(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = tb_block_input_text(self, rt, 0);
|
||||
char rpath[1100];
|
||||
int slot = fs_slot();
|
||||
int64_t handle = 0;
|
||||
if (slot >= 0 && path[0]) {
|
||||
FILE* f = fopen(path, "rb");
|
||||
FILE* f = fopen(tb_path_resolve(path, rpath, sizeof(rpath)), "rb");
|
||||
if (f) { s_files[slot] = f; handle = slot + 1; }
|
||||
}
|
||||
tb_block_set_output(self, 0, tb_value_integer(handle));
|
||||
@@ -78,6 +79,28 @@ static void eval_read(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_readtext(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = tb_block_input_text(self, rt, 0);
|
||||
char rpath[1100];
|
||||
char* buf = NULL;
|
||||
if (path[0]) {
|
||||
FILE* f = fopen(tb_path_resolve(path, rpath, sizeof(rpath)), "rb");
|
||||
if (f) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
long end = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
size_t cap = (end > 0) ? (size_t)end : 0;
|
||||
buf = (char*)malloc(cap + 1);
|
||||
if (buf) { size_t n = fread(buf, 1, cap, f); buf[n] = 0; }
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
TinyBlocks_Value v = tb_value_text(buf ? buf : "");
|
||||
free(buf);
|
||||
tb_block_set_output(self, 0, v);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
static void eval_write(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
FILE* f = fs_get(in_int(self, rt, 0));
|
||||
const char* text = tb_block_input_text(self, rt, 1);
|
||||
@@ -88,8 +111,9 @@ static void eval_write(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
static void eval_append(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = tb_block_input_text(self, rt, 0);
|
||||
const char* text = tb_block_input_text(self, rt, 1);
|
||||
char rpath[1100];
|
||||
if (path[0]) {
|
||||
FILE* f = fopen(path, "ab");
|
||||
FILE* f = fopen(tb_path_resolve(path, rpath, sizeof(rpath)), "ab");
|
||||
if (f) { fwrite(text, 1, strlen(text), f); fclose(f); }
|
||||
}
|
||||
self->dirty = false;
|
||||
@@ -244,6 +268,8 @@ static bool fs_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
static const TinyBlocks_SlotDesc isdir_out[] = {{"é pasta?", TB_VALUE_INTEGER}};
|
||||
static const TinyBlocks_SlotDesc exist_out[] = {{"existe?", TB_VALUE_INTEGER}};
|
||||
|
||||
TB_BLOCK_META("FS.ReadText", "eval_readtext",
|
||||
"Le o arquivo inteiro de uma vez e devolve o texto (vazio se nao abrir)");
|
||||
TB_BLOCK_META("FS.ListDir", "eval_listdir",
|
||||
"Lista com os nomes dos itens da pasta (ordem alfabetica)");
|
||||
TB_BLOCK_META("FS.ListCount", "eval_listcount",
|
||||
@@ -259,6 +285,7 @@ static bool fs_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
|
||||
|
||||
return reg(rt, lib, "FS.Open", open_in, 1, handle_out, 1, eval_open)
|
||||
&& reg(rt, lib, "FS.Read", read_in, 2, text_out, 1, eval_read)
|
||||
&& reg(rt, lib, "FS.ReadText", path_in, 1, text_out, 1, eval_readtext)
|
||||
&& reg(rt, lib, "FS.Write", write_in, 2, NULL, 0, eval_write)
|
||||
&& reg(rt, lib, "FS.Append", append_in, 2, NULL, 0, eval_append)
|
||||
&& reg(rt, lib, "FS.Tell", tell_in, 1, pos_out, 1, eval_tell)
|
||||
|
||||
@@ -27,6 +27,7 @@ static struct {
|
||||
const Tb3dFrame* job;
|
||||
uint8_t* out;
|
||||
const char* glsl; /* != NULL: compilar */
|
||||
int stage; /* estagio do shader a compilar */
|
||||
void** bin;
|
||||
size_t* bin_size;
|
||||
bool busy, ok;
|
||||
@@ -37,15 +38,22 @@ static struct {
|
||||
static EGLDisplay s_dpy = EGL_NO_DISPLAY;
|
||||
static EGLContext s_ctx = EGL_NO_CONTEXT;
|
||||
static GLuint s_prog, s_fbo, s_color, s_depth;
|
||||
static GLint u_mvp, u_nrm, u_color, u_light, u_ambient;
|
||||
static GLint u_mvp, u_nrm, u_color, u_light, u_ambient, u_fog, u_fog_end;
|
||||
static int s_w, s_h;
|
||||
static uint8_t* s_rows; /* leitura (de baixo para cima) */
|
||||
static size_t s_rows_cap;
|
||||
typedef struct { GLuint vao, vbo, ebo; int icount; } GpuMesh;
|
||||
static GpuMesh s_mesh[32]; /* pelo id da malha */
|
||||
typedef struct { GLuint vao, vbo, ebo; int icount; unsigned version; } GpuMesh;
|
||||
static GpuMesh s_mesh[256]; /* pelo id da malha (1..255) */
|
||||
|
||||
/* Texturas (cache pelo id) e a textura branca de 1x1 que substitui quem
|
||||
nao tem material com albedo */
|
||||
typedef struct { GLuint tex; int id; unsigned version; } GpuTex;
|
||||
static GpuTex s_tex[128];
|
||||
static GLuint s_white;
|
||||
static GLuint s_flat; /* normal map neutro (0,0,1) */
|
||||
|
||||
/* Programas dos shaders feitos com blocos: cache pelo id (id % 64) */
|
||||
typedef struct { GLuint prog; int id; GLint mvp, model, nrm, color, light, ambient, time; } GpuShader;
|
||||
typedef struct { GLuint prog; int id; GLint mvp, model, nrm, color, light, ambient, time, albedo, normalmap, fog, fog_end; } GpuShader;
|
||||
static GpuShader s_shd[64];
|
||||
|
||||
static void fail(const char* fmt, const char* a) { snprintf(G.err, sizeof(G.err), fmt, a); }
|
||||
@@ -54,52 +62,115 @@ static const char* VS =
|
||||
"#version 330 core\n"
|
||||
"layout(location = 0) in vec3 a_pos;\n"
|
||||
"layout(location = 1) in vec3 a_nrm;\n"
|
||||
"layout(location = 2) in vec2 a_uv;\n"
|
||||
"uniform mat4 u_mvp;\n"
|
||||
"out vec3 v_local;\n"
|
||||
"out vec3 v_nobj;\n"
|
||||
"out vec2 v_uv;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = u_mvp * vec4(a_pos, 1.0);\n"
|
||||
" v_local = a_pos;\n"
|
||||
" v_nobj = a_nrm;\n"
|
||||
" v_uv = a_uv;\n"
|
||||
"}\n";
|
||||
static const char* FS =
|
||||
"#version 330 core\n"
|
||||
"in vec3 v_local;\n"
|
||||
"in vec3 v_nobj;\n"
|
||||
"in vec2 v_uv;\n"
|
||||
"uniform mat3 u_nrm;\n"
|
||||
"uniform vec4 u_color;\n"
|
||||
"uniform vec3 u_light;\n"
|
||||
"uniform float u_ambient;\n"
|
||||
"out vec3 v_col;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = u_mvp * vec4(a_pos, 1.0);\n"
|
||||
" vec3 n = normalize(u_nrm * a_nrm);\n"
|
||||
" float I = u_ambient + (1.0 - u_ambient) * max(dot(n, u_light), 0.0);\n"
|
||||
" v_col = u_color.rgb * I;\n"
|
||||
"}\n";
|
||||
static const char* FS =
|
||||
"#version 330 core\n"
|
||||
"in vec3 v_col;\n"
|
||||
"uniform sampler2D u_albedo;\n"
|
||||
"uniform sampler2D u_normalmap;\n"
|
||||
"uniform vec4 u_fog;\n" /* rgb = cor da nevoa, a = inicio */
|
||||
"uniform float u_fog_end;\n"
|
||||
"vec3 tb_fog(vec3 c) {\n"
|
||||
" if (u_fog_end <= u_fog.w) return c;\n"
|
||||
" float t = clamp((1.0 / gl_FragCoord.w - u_fog.w) / (u_fog_end - u_fog.w), 0.0, 1.0);\n"
|
||||
" return mix(c, u_fog.rgb, t);\n"
|
||||
"}\n"
|
||||
"out vec4 o_color;\n"
|
||||
"void main() { o_color = vec4(min(v_col, vec3(1.0)), 1.0); }\n";
|
||||
"void main() {\n"
|
||||
" vec3 No = normalize(v_nobj);\n"
|
||||
" vec3 dp1 = dFdx(v_local), dp2 = dFdy(v_local);\n"
|
||||
" vec2 duv1 = dFdx(v_uv), duv2 = dFdy(v_uv);\n"
|
||||
" vec3 T = normalize(dp1 * duv2.y - dp2 * duv1.y);\n"
|
||||
" vec3 B = normalize(dp2 * duv1.x - dp1 * duv2.x);\n"
|
||||
" vec3 nm = texture(u_normalmap, v_uv).xyz * 2.0 - 1.0;\n"
|
||||
" vec3 N = normalize(u_nrm * normalize(mat3(T, B, No) * nm));\n"
|
||||
" float I = u_ambient + (1.0 - u_ambient) * max(dot(N, u_light), 0.0);\n"
|
||||
" o_color = vec4(tb_fog(min(u_color.rgb * I * texture(u_albedo, v_uv).rgb, vec3(1.0))), u_color.a);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* VS_SHADER =
|
||||
static const char* VS_VERT_HEAD =
|
||||
"#version 330 core\n"
|
||||
"layout(location = 0) in vec3 a_pos;\n"
|
||||
"layout(location = 1) in vec3 a_nrm;\n"
|
||||
"layout(location = 2) in vec2 a_uv;\n"
|
||||
"uniform mat4 u_mvp;\n"
|
||||
"uniform mat4 u_model;\n"
|
||||
"uniform mat3 u_nrm;\n"
|
||||
"out vec3 v_pos;\n"
|
||||
"out vec3 v_nrm;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = u_mvp * vec4(a_pos, 1.0);\n"
|
||||
" v_pos = (u_model * vec4(a_pos, 1.0)).xyz;\n"
|
||||
" v_nrm = u_nrm * a_nrm;\n"
|
||||
"}\n";
|
||||
static const char* FS_HEAD =
|
||||
"#version 330 core\n"
|
||||
"in vec3 v_pos;\n"
|
||||
"in vec3 v_nrm;\n"
|
||||
"uniform vec4 u_color;\n"
|
||||
"uniform vec3 u_light;\n"
|
||||
"uniform float u_ambient;\n"
|
||||
"uniform float u_time;\n"
|
||||
"out vec3 v_pos;\n"
|
||||
"out vec3 v_nrm;\n"
|
||||
"out vec3 v_local;\n"
|
||||
"out vec3 v_nobj;\n"
|
||||
"out vec2 v_uv;\n";
|
||||
static const char* VS_VERT_MAIN =
|
||||
"void main() {\n"
|
||||
" vec3 n = normalize(u_nrm * a_nrm);\n"
|
||||
" float light = u_ambient + (1.0 - u_ambient) * max(dot(n, u_light), 0.0);\n"
|
||||
" vec3 P = tb_vert(a_pos, a_nrm, a_pos, a_uv, u_color.rgb, vec3(1.0), light, u_time);\n"
|
||||
" gl_Position = u_mvp * vec4(P, 1.0);\n"
|
||||
" v_pos = (u_model * vec4(P, 1.0)).xyz;\n"
|
||||
" v_nrm = u_nrm * a_nrm;\n"
|
||||
" v_local = P;\n"
|
||||
" v_nobj = a_nrm;\n"
|
||||
" v_uv = a_uv;\n"
|
||||
"}\n";
|
||||
static const char* DEFAULT_VERT =
|
||||
"vec3 tb_vert(vec3 P, vec3 N, vec3 L, vec2 UV, vec3 base, vec3 tex, float light, float time) { return P; }\n";
|
||||
static const char* DEFAULT_FRAG =
|
||||
"vec3 tb_shade(vec3 P, vec3 N, vec3 L, vec2 UV, vec3 base, vec3 tex, float light, float time) { return base * light; }\n";
|
||||
static const char* FS_HEAD =
|
||||
"#version 330 core\n"
|
||||
"in vec3 v_pos;\n"
|
||||
"in vec3 v_nrm;\n"
|
||||
"in vec3 v_local;\n"
|
||||
"in vec3 v_nobj;\n"
|
||||
"in vec2 v_uv;\n"
|
||||
"uniform mat3 u_nrm;\n"
|
||||
"uniform vec4 u_color;\n"
|
||||
"uniform vec3 u_light;\n"
|
||||
"uniform float u_ambient;\n"
|
||||
"uniform float u_time;\n"
|
||||
"uniform sampler2D u_albedo;\n"
|
||||
"uniform sampler2D u_normalmap;\n"
|
||||
"uniform vec4 u_fog;\n" /* rgb = cor da nevoa, a = inicio */
|
||||
"uniform float u_fog_end;\n"
|
||||
"vec3 tb_fog(vec3 c) {\n"
|
||||
" if (u_fog_end <= u_fog.w) return c;\n"
|
||||
" float t = clamp((1.0 / gl_FragCoord.w - u_fog.w) / (u_fog_end - u_fog.w), 0.0, 1.0);\n"
|
||||
" return mix(c, u_fog.rgb, t);\n"
|
||||
"}\n"
|
||||
"out vec4 o_color;\n";
|
||||
static const char* FS_MAIN =
|
||||
"void main() {\n"
|
||||
" vec3 N = normalize(v_nrm);\n"
|
||||
" vec3 No = normalize(v_nobj);\n"
|
||||
" vec3 dp1 = dFdx(v_local), dp2 = dFdy(v_local);\n"
|
||||
" vec2 duv1 = dFdx(v_uv), duv2 = dFdy(v_uv);\n"
|
||||
" vec3 T = normalize(dp1 * duv2.y - dp2 * duv1.y);\n"
|
||||
" vec3 B = normalize(dp2 * duv1.x - dp1 * duv2.x);\n"
|
||||
" vec3 nm = texture(u_normalmap, v_uv).xyz * 2.0 - 1.0;\n"
|
||||
" vec3 N = normalize(u_nrm * normalize(mat3(T, B, No) * nm));\n"
|
||||
" float light = u_ambient + (1.0 - u_ambient) * max(dot(N, u_light), 0.0);\n"
|
||||
" o_color = vec4(tb_shade(v_pos, N, u_color.rgb, light, u_time), 1.0);\n"
|
||||
" vec3 tex = texture(u_albedo, v_uv).rgb;\n"
|
||||
" o_color = vec4(tb_fog(min(tb_shade(v_pos, N, v_local, v_uv, u_color.rgb, tex, light, u_time), vec3(1.0))), u_color.a);\n"
|
||||
"}\n";
|
||||
|
||||
static GLuint shader(GLenum kind, const char* src) {
|
||||
@@ -133,13 +204,21 @@ static GLuint link_hint(GLuint vs, GLuint fs, bool retrievable) {
|
||||
return p;
|
||||
}
|
||||
|
||||
/* O programa do shader feito com blocos, compilado do GLSL */
|
||||
static GLuint program_from_glsl(const char* glsl, bool retrievable) {
|
||||
size_t n = strlen(FS_HEAD) + strlen(glsl) + strlen(FS_MAIN) + 1;
|
||||
char* fs = malloc(n);
|
||||
if (!fs) return 0;
|
||||
snprintf(fs, n, "%s%s%s", FS_HEAD, glsl, FS_MAIN);
|
||||
GLuint p = link_hint(shader(GL_VERTEX_SHADER, VS_SHADER), shader(GL_FRAGMENT_SHADER, fs), retrievable);
|
||||
/* O programa do shader feito com blocos, compilado do GLSL. O estagio diz
|
||||
qual funcao o GLSL traz (tb_vert ou tb_shade); o outro estagio usa o
|
||||
padrao (posicao intacta / cor do objeto com luz). */
|
||||
static GLuint program_from_glsl(const char* glsl, int stage, bool retrievable) {
|
||||
bool vert = stage == TB_3D_STAGE_VERTEX;
|
||||
const char* vb = vert ? glsl : DEFAULT_VERT;
|
||||
const char* fb = vert ? DEFAULT_FRAG : glsl;
|
||||
size_t nv = strlen(VS_VERT_HEAD) + strlen(vb) + strlen(VS_VERT_MAIN) + 1;
|
||||
size_t nf = strlen(FS_HEAD) + strlen(fb) + strlen(FS_MAIN) + 1;
|
||||
char* vs = malloc(nv), *fs = malloc(nf);
|
||||
if (!vs || !fs) { free(vs); free(fs); return 0; }
|
||||
snprintf(vs, nv, "%s%s%s", VS_VERT_HEAD, vb, VS_VERT_MAIN);
|
||||
snprintf(fs, nf, "%s%s%s", FS_HEAD, fb, FS_MAIN);
|
||||
GLuint p = link_hint(shader(GL_VERTEX_SHADER, vs), shader(GL_FRAGMENT_SHADER, fs), retrievable);
|
||||
free(vs);
|
||||
free(fs);
|
||||
return p;
|
||||
}
|
||||
@@ -147,12 +226,12 @@ static GLuint program_from_glsl(const char* glsl, bool retrievable) {
|
||||
/* O binario do OpenGL e o programa ja ligado, como o driver o devolve
|
||||
(glGetProgramBinary): 4 bytes com o formato e os bytes do driver. So
|
||||
serve para a mesma placa e driver; se o driver o recusar, recompila. */
|
||||
static bool binary_compile(const char* glsl, void** data, size_t* size) {
|
||||
static bool binary_compile(const char* glsl, int stage, void** data, size_t* size) {
|
||||
*data = NULL; *size = 0;
|
||||
GLint nfmt = 0;
|
||||
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &nfmt);
|
||||
if (nfmt < 1) { fail("%s", "o driver não devolve binários de programa"); return false; }
|
||||
GLuint p = program_from_glsl(glsl, true);
|
||||
GLuint p = program_from_glsl(glsl, stage, true);
|
||||
if (!p) return false;
|
||||
GLint len = 0;
|
||||
glGetProgramiv(p, GL_PROGRAM_BINARY_LENGTH, &len);
|
||||
@@ -189,7 +268,7 @@ static GpuShader* gpu_shader(const Tb3dShader* sh) {
|
||||
memset(g, 0, sizeof(*g));
|
||||
for (int i = 0; i < sh->bin_n && !g->prog; i++)
|
||||
if (!strcmp(sh->bin[i].renderer, "opengl")) g->prog = program_from_binary(sh->bin[i].data, sh->bin[i].size);
|
||||
if (!g->prog) g->prog = program_from_glsl(sh->glsl, false);
|
||||
if (!g->prog) g->prog = program_from_glsl(sh->glsl, sh->stage, false);
|
||||
if (!g->prog) return NULL;
|
||||
g->id = sh->id;
|
||||
g->mvp = glGetUniformLocation(g->prog, "u_mvp");
|
||||
@@ -199,6 +278,10 @@ static GpuShader* gpu_shader(const Tb3dShader* sh) {
|
||||
g->light = glGetUniformLocation(g->prog, "u_light");
|
||||
g->ambient = glGetUniformLocation(g->prog, "u_ambient");
|
||||
g->time = glGetUniformLocation(g->prog, "u_time");
|
||||
g->albedo = glGetUniformLocation(g->prog, "u_albedo");
|
||||
g->normalmap = glGetUniformLocation(g->prog, "u_normalmap");
|
||||
g->fog = glGetUniformLocation(g->prog, "u_fog");
|
||||
g->fog_end = glGetUniformLocation(g->prog, "u_fog_end");
|
||||
return g;
|
||||
}
|
||||
|
||||
@@ -239,6 +322,20 @@ static bool gl_setup(void) {
|
||||
u_color = glGetUniformLocation(s_prog, "u_color");
|
||||
u_light = glGetUniformLocation(s_prog, "u_light");
|
||||
u_ambient = glGetUniformLocation(s_prog, "u_ambient");
|
||||
u_fog = glGetUniformLocation(s_prog, "u_fog");
|
||||
u_fog_end = glGetUniformLocation(s_prog, "u_fog_end");
|
||||
glGenTextures(1, &s_white);
|
||||
glBindTexture(GL_TEXTURE_2D, s_white);
|
||||
static const uint8_t branco[4] = { 255, 255, 255, 255 };
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, branco);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glGenTextures(1, &s_flat);
|
||||
glBindTexture(GL_TEXTURE_2D, s_flat);
|
||||
static const uint8_t plano[4] = { 128, 128, 255, 255 }; /* normal para fora */
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, plano);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glGenFramebuffers(1, &s_fbo);
|
||||
glGenRenderbuffers(1, &s_color);
|
||||
glGenRenderbuffers(1, &s_depth);
|
||||
@@ -260,25 +357,50 @@ static bool target(int w, int h) {
|
||||
}
|
||||
|
||||
static GpuMesh* gpu_mesh(const Tb3dMesh* m) {
|
||||
if (m->id <= 0 || m->id >= 32) return NULL;
|
||||
if (m->id <= 0 || m->id >= 256) return NULL;
|
||||
GpuMesh* g = &s_mesh[m->id];
|
||||
if (g->vao) return g;
|
||||
if (g->vao && g->version == m->version) return g;
|
||||
if (g->vao) {
|
||||
glDeleteVertexArrays(1, &g->vao); glDeleteBuffers(1, &g->vbo); glDeleteBuffers(1, &g->ebo);
|
||||
memset(g, 0, sizeof(*g));
|
||||
}
|
||||
glGenVertexArrays(1, &g->vao);
|
||||
glGenBuffers(1, &g->vbo);
|
||||
glGenBuffers(1, &g->ebo);
|
||||
glBindVertexArray(g->vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g->vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)m->vcount * 6 * sizeof(float), m->verts, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)m->vcount * 8 * sizeof(float), m->verts, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g->ebo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)m->icount * sizeof(uint32_t), m->index, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
g->icount = m->icount;
|
||||
g->version = m->version;
|
||||
return g;
|
||||
}
|
||||
|
||||
/* A textura na GPU (cache pelo id): sobe RGBA8 com filtro linear e uv repetido */
|
||||
static GLuint gpu_tex(const Tb3dTexture* t) {
|
||||
if (!t || !t->rgba || t->id <= 0 || t->id >= 128) return s_white;
|
||||
GpuTex* g = &s_tex[t->id];
|
||||
if (g->tex && g->version == t->version) return g->tex;
|
||||
if (!g->tex) glGenTextures(1, &g->tex);
|
||||
glBindTexture(GL_TEXTURE_2D, g->tex);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, t->width, t->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, t->rgba);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
g->id = t->id;
|
||||
g->version = t->version;
|
||||
return g->tex;
|
||||
}
|
||||
|
||||
static bool draw(const Tb3dFrame* f, uint8_t* out) {
|
||||
if (!target(f->width, f->height)) return false;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, s_fbo);
|
||||
@@ -288,14 +410,29 @@ static bool draw(const Tb3dFrame* f, uint8_t* out) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDisable(GL_BLEND); /* um quadro que parou no meio */
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glUseProgram(s_prog);
|
||||
glUniform3fv(u_light, 1, f->light_dir);
|
||||
glUniform1f(u_ambient, f->ambient);
|
||||
float fog[4] = { f->fog_color[0], f->fog_color[1], f->fog_color[2], f->fog_start };
|
||||
glUniform4fv(u_fog, 1, fog);
|
||||
glUniform1f(u_fog_end, f->fog_end);
|
||||
/* transparentes: misturam a cor (o alfa da imagem fica 1) sem gravar o z */
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glUniform1i(glGetUniformLocation(s_prog, "u_albedo"), 0);
|
||||
glUniform1i(glGetUniformLocation(s_prog, "u_normalmap"), 1);
|
||||
for (int i = 0; i < f->draw_count; i++) {
|
||||
const Tb3dDraw* d = &f->draws[i];
|
||||
GpuMesh* g = gpu_mesh(d->mesh);
|
||||
if (!g) continue;
|
||||
if (i == f->opaque_count) { glEnable(GL_BLEND); glDepthMask(GL_FALSE); }
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, gpu_tex(d->albedo));
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, d->normaltex ? gpu_tex(d->normaltex) : s_flat);
|
||||
if (d->shader) { /* shader feito com blocos */
|
||||
GpuShader* sh = gpu_shader(d->shader);
|
||||
if (!sh) return false; /* a 3d desenha esse quadro em software */
|
||||
@@ -307,6 +444,10 @@ static bool draw(const Tb3dFrame* f, uint8_t* out) {
|
||||
glUniform3fv(sh->light, 1, f->light_dir);
|
||||
glUniform1f(sh->ambient, f->ambient);
|
||||
glUniform1f(sh->time, f->time);
|
||||
glUniform1i(sh->albedo, 0);
|
||||
glUniform1i(sh->normalmap, 1);
|
||||
glUniform4fv(sh->fog, 1, fog);
|
||||
glUniform1f(sh->fog_end, f->fog_end);
|
||||
glBindVertexArray(g->vao);
|
||||
glDrawElements(GL_TRIANGLES, g->icount, GL_UNSIGNED_INT, (void*)0);
|
||||
glUseProgram(s_prog);
|
||||
@@ -318,6 +459,8 @@ static bool draw(const Tb3dFrame* f, uint8_t* out) {
|
||||
glBindVertexArray(g->vao);
|
||||
glDrawElements(GL_TRIANGLES, g->icount, GL_UNSIGNED_INT, (void*)0);
|
||||
}
|
||||
glDisable(GL_BLEND);
|
||||
glDepthMask(GL_TRUE);
|
||||
size_t row = (size_t)f->width * 4, n = row * (size_t)f->height;
|
||||
if (n > s_rows_cap) {
|
||||
uint8_t* p = realloc(s_rows, n);
|
||||
@@ -334,13 +477,19 @@ static bool draw(const Tb3dFrame* f, uint8_t* out) {
|
||||
}
|
||||
|
||||
static void cleanup(void) {
|
||||
for (int i = 0; i < 32; i++)
|
||||
for (int i = 0; i < 256; i++)
|
||||
if (s_mesh[i].vao) {
|
||||
glDeleteVertexArrays(1, &s_mesh[i].vao);
|
||||
glDeleteBuffers(1, &s_mesh[i].vbo);
|
||||
glDeleteBuffers(1, &s_mesh[i].ebo);
|
||||
}
|
||||
memset(s_mesh, 0, sizeof(s_mesh));
|
||||
for (int i = 0; i < 128; i++) if (s_tex[i].tex) glDeleteTextures(1, &s_tex[i].tex);
|
||||
memset(s_tex, 0, sizeof(s_tex));
|
||||
if (s_white) glDeleteTextures(1, &s_white);
|
||||
s_white = 0;
|
||||
if (s_flat) glDeleteTextures(1, &s_flat);
|
||||
s_flat = 0;
|
||||
for (int i = 0; i < 64; i++) if (s_shd[i].prog) glDeleteProgram(s_shd[i].prog);
|
||||
memset(s_shd, 0, sizeof(s_shd));
|
||||
if (s_prog) glDeleteProgram(s_prog);
|
||||
@@ -369,7 +518,7 @@ static void* gl_thread(void* arg) {
|
||||
uint8_t* out = G.out;
|
||||
const char* glsl = G.glsl;
|
||||
pthread_mutex_unlock(&G.mu);
|
||||
bool r = glsl ? binary_compile(glsl, G.bin, G.bin_size) : draw(f, out);
|
||||
bool r = glsl ? binary_compile(glsl, G.stage, G.bin, G.bin_size) : draw(f, out);
|
||||
pthread_mutex_lock(&G.mu);
|
||||
G.ok = r;
|
||||
G.busy = false;
|
||||
@@ -409,10 +558,10 @@ static const char* gl_error(void) { return G.err; }
|
||||
static bool gl_shaders(void) { return true; }
|
||||
|
||||
/* Tb3dRenderer.compile: pede o binario a thread do OpenGL */
|
||||
static bool gl_compile(const char* glsl, void** data, size_t* size, char* err, size_t cap) {
|
||||
static bool gl_compile(const char* glsl, int stage, void** data, size_t* size, char* err, size_t cap) {
|
||||
if (!gl_available()) { snprintf(err, cap, "%s", G.err); return false; }
|
||||
pthread_mutex_lock(&G.mu);
|
||||
G.glsl = glsl; G.bin = data; G.bin_size = size; G.busy = true;
|
||||
G.glsl = glsl; G.stage = stage; G.bin = data; G.bin_size = size; G.busy = true;
|
||||
pthread_cond_broadcast(&G.cv);
|
||||
while (G.busy) pthread_cond_wait(&G.cv, &G.mu);
|
||||
bool ok = G.ok;
|
||||
|
||||
@@ -82,7 +82,9 @@ enum {
|
||||
#define GFX_IN_MOUSE_IN 25 /* int: 1 se o mouse está sobre esta janela */
|
||||
#define GFX_IN_GMOUSE_X 26 /* real: mouse na tela (global), x */
|
||||
#define GFX_IN_GMOUSE_Y 27 /* real: mouse na tela (global), y */
|
||||
#define GFX_IN_COUNT 28
|
||||
#define GFX_IN_ZOOM 28 /* real: pinça do touchpad neste frame (fator; *
|
||||
* 0 = nenhuma, >1 aproxima) */
|
||||
#define GFX_IN_COUNT 29
|
||||
|
||||
#define GFX_MAX_TOUCHES 10
|
||||
|
||||
@@ -107,6 +109,7 @@ typedef struct TinyBlocks_GfxInput {
|
||||
int win_x, win_y; /* posicao da janela na tela */
|
||||
int mouse_in; /* o mouse esta sobre esta janela */
|
||||
float gmouse_x, gmouse_y; /* mouse na tela (coordenadas globais) */
|
||||
float zoom; /* pinca do touchpad: fator (0 = nenhuma) */
|
||||
} TinyBlocks_GfxInput;
|
||||
|
||||
/* -- Contrato de um backend gráfico --- */
|
||||
@@ -124,6 +127,9 @@ typedef struct TinyBlocks_GraphicsBackend {
|
||||
/* Area de transferencia (opcionais; NULL = memoria interna do graphics) */
|
||||
bool (*clipboard_set)(const char* text);
|
||||
char* (*clipboard_get)(void); /* malloc; NULL = vazia */
|
||||
/* Campo de texto em foco (opcional): o SO mostra o teclado na tela e poe o
|
||||
IME junto do cursor. x y w h na janela (coordenadas da cena) */
|
||||
void (*text_input)(bool on, float x, float y, float w, float h);
|
||||
} TinyBlocks_GraphicsBackend;
|
||||
|
||||
/* Símbolo exportado por um backend carregado como .so */
|
||||
@@ -147,6 +153,12 @@ TB_API float tb_graphics_measure_text(const char* text, float font_size);
|
||||
TB_API bool tb_graphics_set_clipboard(const char* text);
|
||||
TB_API char* tb_graphics_get_clipboard(void);
|
||||
|
||||
/* Diz ao sistema que um campo de texto esta em foco, com o cursor em
|
||||
(x, y, w, h) na janela: no celular abre o teclado, no desktop posiciona o
|
||||
IME. on=false: nenhum campo (o teclado na tela fecha). Chamar de novo com
|
||||
on=true reabre o teclado que o usuario fechou. */
|
||||
TB_API void tb_graphics_text_input(bool on, float x, float y, float w, float h);
|
||||
|
||||
/* Loop principal: roda todas as janelas abertas até a principal fechar */
|
||||
TB_API void tb_graphics_run(TinyBlocks* rt);
|
||||
TB_API bool tb_graphics_window_is_open(TinyBlocks_Block* window);
|
||||
|
||||
@@ -162,6 +162,11 @@ char* tb_graphics_get_clipboard(void) {
|
||||
return s_clip ? strdup(s_clip) : NULL;
|
||||
}
|
||||
|
||||
void tb_graphics_text_input(bool on, float x, float y, float w, float h) {
|
||||
const TinyBlocks_GraphicsBackend* b = backend_ready();
|
||||
if (b->text_input) b->text_input(on, x, y, w, h);
|
||||
}
|
||||
|
||||
float tb_graphics_measure_text(const char* text, float font_size) {
|
||||
if (!text || !text[0]) return 0.f;
|
||||
const TinyBlocks_GraphicsBackend* b = backend_ready();
|
||||
@@ -187,6 +192,7 @@ static const TinyBlocks_SlotDesc s_input_outs[GFX_IN_COUNT] = {
|
||||
{"win_x", TB_VALUE_INTEGER}, {"win_y", TB_VALUE_INTEGER},
|
||||
{"mouse_in", TB_VALUE_INTEGER},
|
||||
{"gmouse_x", TB_VALUE_REAL}, {"gmouse_y", TB_VALUE_REAL},
|
||||
{"zoom", TB_VALUE_REAL},
|
||||
};
|
||||
|
||||
static void eval_input(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
@@ -279,6 +285,7 @@ static void input_push(TinyBlocks_Block* b, const TinyBlocks_GfxInput* in) {
|
||||
SET(GFX_IN_MOUSE_IN, tb_value_integer(in->mouse_in));
|
||||
SET(GFX_IN_GMOUSE_X, tb_value_real(in->gmouse_x));
|
||||
SET(GFX_IN_GMOUSE_Y, tb_value_real(in->gmouse_y));
|
||||
SET(GFX_IN_ZOOM, tb_value_real(in->zoom));
|
||||
#undef SET
|
||||
b->dirty = false;
|
||||
}
|
||||
|
||||
@@ -141,6 +141,8 @@ static void eval_scale(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
}
|
||||
static void eval_load(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = tb_block_input_text(self, rt, 0);
|
||||
char rpath[1100];
|
||||
path = tb_path_resolve(path, rpath, sizeof(rpath));
|
||||
TinyBlocks_Image* img = tb_image_load(path);
|
||||
if (!img) { tinyblocks_set_error(rt, "nao carregou '%s' (formato?)", path); self->dirty = false; return; }
|
||||
/* A imagem carregada ganha nome (nome do arquivo) e numero no armazem,
|
||||
|
||||
@@ -21,6 +21,9 @@ const char* tb_png_last_error(void) { return s_err; }
|
||||
TinyBlocks_Image* tb_png_load(const char* path) {
|
||||
s_err[0] = 0;
|
||||
if (!path) { snprintf(s_err, sizeof(s_err), "caminho nulo"); return NULL; }
|
||||
char rpath[1100];
|
||||
tb_path_resolve(path, rpath, sizeof(rpath));
|
||||
path = rpath;
|
||||
png_image pv;
|
||||
memset(&pv, 0, sizeof(pv));
|
||||
pv.version = PNG_IMAGE_VERSION;
|
||||
@@ -48,6 +51,8 @@ TinyBlocks_Image* tb_png_load(const char* path) {
|
||||
bool tb_png_save(const TinyBlocks_Image* img, const char* path) {
|
||||
s_err[0] = 0;
|
||||
if (!img || !path) { snprintf(s_err, sizeof(s_err), "imagem/caminho nulo"); return false; }
|
||||
char rpath[1100];
|
||||
path = tb_path_resolve(path, rpath, sizeof(rpath));
|
||||
int w = tb_image_width(img), h = tb_image_height(img);
|
||||
if (w <= 0 || h <= 0) { snprintf(s_err, sizeof(s_err), "imagem vazia"); return false; }
|
||||
size_t sz = (size_t)w * h * 4;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* QR Code generator library (C)
|
||||
*
|
||||
* Copyright (c) Project Nayuki. (MIT License)
|
||||
* https://www.nayuki.io/page/qr-code-generator-library
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
* - The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
* - The Software is provided "as is", without warranty of any kind, express or
|
||||
* implied, including but not limited to the warranties of merchantability,
|
||||
* fitness for a particular purpose and noninfringement. In no event shall the
|
||||
* authors or copyright holders be liable for any claim, damages or other
|
||||
* liability, whether in an action of contract, tort or otherwise, arising from,
|
||||
* out of or in connection with the Software or the use or other dealings in the
|
||||
* Software.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
quirc -- QR-code recognition library
|
||||
Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
|
||||
|
||||
ISC License
|
||||
===========
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for
|
||||
any purpose with or without fee is hereby granted, provided that the
|
||||
above copyright notice and this permission notice appear in all
|
||||
copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
@@ -0,0 +1,36 @@
|
||||
# Makefile da library qr (gerar e ler QR code + camera em cinza)
|
||||
# Constroi build/libtinyblocks-qr.a e build/libtinyblocks-qr.so
|
||||
CC := gcc
|
||||
BUILD := build
|
||||
|
||||
CFLAGS := -std=c11 -O2 -Wall -Wextra -fvisibility=hidden \
|
||||
-D_DEFAULT_SOURCE -I../../include -Iinclude
|
||||
# codigo de terceiros (qrcodegen, quirc): sem -pedantic, avisos deles nao
|
||||
CFLAGS_3P := -std=c11 -O2 -w -fvisibility=hidden -Iinclude
|
||||
|
||||
OBJ := $(BUILD)/tb_qr.o $(BUILD)/tb_camera.o \
|
||||
$(BUILD)/qrcodegen.o $(BUILD)/quirc.o $(BUILD)/decode.o $(BUILD)/identify.o $(BUILD)/version_db.o
|
||||
LIB_A := $(BUILD)/libtinyblocks-qr.a
|
||||
LIB_SO := $(BUILD)/libtinyblocks-qr.so
|
||||
|
||||
.PHONY: all static shared clean
|
||||
all: static shared
|
||||
static: $(LIB_A)
|
||||
shared: $(LIB_SO)
|
||||
|
||||
$(BUILD)/tb_%.o: src/tb_%.c include/tb_qr.h include/tb_camera.h
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD)/%.o: src/%.c
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS_3P) -fPIC -c $< -o $@
|
||||
|
||||
$(LIB_A): $(OBJ)
|
||||
ar rcs $@ $^
|
||||
|
||||
$(LIB_SO): $(OBJ)
|
||||
$(CC) -shared -o $@ $^ -lm
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD)
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* TinyBlocks - tb_camera.h
|
||||
*
|
||||
* Camera do aparelho, em tons de cinza (o que um leitor de QR precisa).
|
||||
* Linux: V4L2 (/dev/video0, YUYV: o canal Y ja e o cinza). Android: Camera2
|
||||
* do NDK (camera2ndk + AImageReader, sem Java), com a permissao de camera
|
||||
* pedida na hora. Sem camera (ou no Windows): tb_camera_open falha e
|
||||
* tb_camera_error diz por que.
|
||||
*/
|
||||
#ifndef TB_CAMERA_H
|
||||
#define TB_CAMERA_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <tinyblocks/tb_defs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Abre a camera (traseira, se houver) perto de want_w x want_h */
|
||||
TB_API bool tb_camera_open(int want_w, int want_h);
|
||||
|
||||
/* Copia o quadro mais novo (cinza, 1 byte/pixel, de pe) para gray.
|
||||
* Devolve false se nao chegou quadro novo desde a ultima chamada. */
|
||||
TB_API bool tb_camera_frame(unsigned char* gray, int cap, int* w, int* h);
|
||||
|
||||
TB_API void tb_camera_close(void);
|
||||
TB_API bool tb_camera_is_open(void);
|
||||
TB_API const char* tb_camera_error(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TB_CAMERA_H */
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* TinyBlocks - tb_qr.h
|
||||
*
|
||||
* QR code: gerar (qrcodegen, de Project Nayuki, MIT) e ler de uma imagem em
|
||||
* tons de cinza (quirc, de Daniel Beer, ISC). Mais a camera do aparelho para
|
||||
* o leitor (tb_camera.h). Usada pelo editor para mandar blocos de uma
|
||||
* instancia para outra por QR.
|
||||
*/
|
||||
#ifndef TB_QR_H
|
||||
#define TB_QR_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <tinyblocks/tb_defs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Lado maximo (modulos) de um QR: versao 40 */
|
||||
#define TB_QR_MAX_SIDE 177
|
||||
|
||||
/* Gera o QR do texto (correcao media; a menor versao que couber).
|
||||
* mods recebe lado*lado bytes, 1 = modulo escuro. Devolve o lado, ou 0 se o
|
||||
* texto nao couber num QR. */
|
||||
TB_API int tb_qr_encode(const char* text, unsigned char* mods, int cap);
|
||||
|
||||
/* Leitor: acha e decodifica os QRs de uma imagem em cinza (1 byte/pixel) */
|
||||
typedef struct TbQrReader TbQrReader;
|
||||
typedef void (*TbQrFound)(const char* text, int len, void* user);
|
||||
|
||||
TB_API TbQrReader* tb_qr_reader_new(void);
|
||||
/* Chama found para cada QR lido; devolve quantos foram lidos */
|
||||
TB_API int tb_qr_reader_scan(TbQrReader* r, const unsigned char* gray, int w, int h,
|
||||
TbQrFound found, void* user);
|
||||
TB_API void tb_qr_reader_free(TbQrReader* r);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TB_QR_H */
|
||||
@@ -0,0 +1,19 @@
|
||||
# Metadados da library qr. Nao tem blocos: gera e le QR codes e abre a
|
||||
# camera em cinza; o editor usa para mandar blocos de uma instancia para
|
||||
# outra (compartilhar / receber). Codigo de terceiros: qrcodegen (MIT) e
|
||||
# quirc (ISC), ver LICENSE-*.txt.
|
||||
[library]
|
||||
name = "tinyblocks-qr"
|
||||
private = true
|
||||
version = "1.0.0"
|
||||
category = "QR"
|
||||
description = "QR code (gerar e ler) e camera em cinza"
|
||||
color = [76, 151, 255, 255]
|
||||
dark = [51, 115, 230, 255]
|
||||
|
||||
[build]
|
||||
sources = ["src/tb_qr.c", "src/tb_camera.c", "src/qrcodegen.c", "src/quirc.c", "src/decode.c", "src/identify.c", "src/version_db.c"]
|
||||
includes = ["include"]
|
||||
shared = "build/libtinyblocks-qr.so"
|
||||
static = "build/libtinyblocks-qr.a"
|
||||
depends = []
|
||||
@@ -0,0 +1,948 @@
|
||||
/* quirc -- QR-code recognition library
|
||||
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "quirc_internal.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAX_POLY 64
|
||||
|
||||
/************************************************************************
|
||||
* Galois fields
|
||||
*/
|
||||
|
||||
struct galois_field {
|
||||
int p;
|
||||
const uint8_t *log;
|
||||
const uint8_t *exp;
|
||||
};
|
||||
|
||||
static const uint8_t gf16_exp[16] = {
|
||||
0x01, 0x02, 0x04, 0x08, 0x03, 0x06, 0x0c, 0x0b,
|
||||
0x05, 0x0a, 0x07, 0x0e, 0x0f, 0x0d, 0x09, 0x01
|
||||
};
|
||||
|
||||
static const uint8_t gf16_log[16] = {
|
||||
0x00, 0x0f, 0x01, 0x04, 0x02, 0x08, 0x05, 0x0a,
|
||||
0x03, 0x0e, 0x09, 0x07, 0x06, 0x0d, 0x0b, 0x0c
|
||||
};
|
||||
|
||||
static const struct galois_field gf16 = {
|
||||
.p = 15,
|
||||
.log = gf16_log,
|
||||
.exp = gf16_exp
|
||||
};
|
||||
|
||||
static const uint8_t gf256_exp[256] = {
|
||||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
|
||||
0x1d, 0x3a, 0x74, 0xe8, 0xcd, 0x87, 0x13, 0x26,
|
||||
0x4c, 0x98, 0x2d, 0x5a, 0xb4, 0x75, 0xea, 0xc9,
|
||||
0x8f, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0,
|
||||
0x9d, 0x27, 0x4e, 0x9c, 0x25, 0x4a, 0x94, 0x35,
|
||||
0x6a, 0xd4, 0xb5, 0x77, 0xee, 0xc1, 0x9f, 0x23,
|
||||
0x46, 0x8c, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0,
|
||||
0x5d, 0xba, 0x69, 0xd2, 0xb9, 0x6f, 0xde, 0xa1,
|
||||
0x5f, 0xbe, 0x61, 0xc2, 0x99, 0x2f, 0x5e, 0xbc,
|
||||
0x65, 0xca, 0x89, 0x0f, 0x1e, 0x3c, 0x78, 0xf0,
|
||||
0xfd, 0xe7, 0xd3, 0xbb, 0x6b, 0xd6, 0xb1, 0x7f,
|
||||
0xfe, 0xe1, 0xdf, 0xa3, 0x5b, 0xb6, 0x71, 0xe2,
|
||||
0xd9, 0xaf, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88,
|
||||
0x0d, 0x1a, 0x34, 0x68, 0xd0, 0xbd, 0x67, 0xce,
|
||||
0x81, 0x1f, 0x3e, 0x7c, 0xf8, 0xed, 0xc7, 0x93,
|
||||
0x3b, 0x76, 0xec, 0xc5, 0x97, 0x33, 0x66, 0xcc,
|
||||
0x85, 0x17, 0x2e, 0x5c, 0xb8, 0x6d, 0xda, 0xa9,
|
||||
0x4f, 0x9e, 0x21, 0x42, 0x84, 0x15, 0x2a, 0x54,
|
||||
0xa8, 0x4d, 0x9a, 0x29, 0x52, 0xa4, 0x55, 0xaa,
|
||||
0x49, 0x92, 0x39, 0x72, 0xe4, 0xd5, 0xb7, 0x73,
|
||||
0xe6, 0xd1, 0xbf, 0x63, 0xc6, 0x91, 0x3f, 0x7e,
|
||||
0xfc, 0xe5, 0xd7, 0xb3, 0x7b, 0xf6, 0xf1, 0xff,
|
||||
0xe3, 0xdb, 0xab, 0x4b, 0x96, 0x31, 0x62, 0xc4,
|
||||
0x95, 0x37, 0x6e, 0xdc, 0xa5, 0x57, 0xae, 0x41,
|
||||
0x82, 0x19, 0x32, 0x64, 0xc8, 0x8d, 0x07, 0x0e,
|
||||
0x1c, 0x38, 0x70, 0xe0, 0xdd, 0xa7, 0x53, 0xa6,
|
||||
0x51, 0xa2, 0x59, 0xb2, 0x79, 0xf2, 0xf9, 0xef,
|
||||
0xc3, 0x9b, 0x2b, 0x56, 0xac, 0x45, 0x8a, 0x09,
|
||||
0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5,
|
||||
0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16,
|
||||
0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83,
|
||||
0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x01
|
||||
};
|
||||
|
||||
static const uint8_t gf256_log[256] = {
|
||||
0x00, 0xff, 0x01, 0x19, 0x02, 0x32, 0x1a, 0xc6,
|
||||
0x03, 0xdf, 0x33, 0xee, 0x1b, 0x68, 0xc7, 0x4b,
|
||||
0x04, 0x64, 0xe0, 0x0e, 0x34, 0x8d, 0xef, 0x81,
|
||||
0x1c, 0xc1, 0x69, 0xf8, 0xc8, 0x08, 0x4c, 0x71,
|
||||
0x05, 0x8a, 0x65, 0x2f, 0xe1, 0x24, 0x0f, 0x21,
|
||||
0x35, 0x93, 0x8e, 0xda, 0xf0, 0x12, 0x82, 0x45,
|
||||
0x1d, 0xb5, 0xc2, 0x7d, 0x6a, 0x27, 0xf9, 0xb9,
|
||||
0xc9, 0x9a, 0x09, 0x78, 0x4d, 0xe4, 0x72, 0xa6,
|
||||
0x06, 0xbf, 0x8b, 0x62, 0x66, 0xdd, 0x30, 0xfd,
|
||||
0xe2, 0x98, 0x25, 0xb3, 0x10, 0x91, 0x22, 0x88,
|
||||
0x36, 0xd0, 0x94, 0xce, 0x8f, 0x96, 0xdb, 0xbd,
|
||||
0xf1, 0xd2, 0x13, 0x5c, 0x83, 0x38, 0x46, 0x40,
|
||||
0x1e, 0x42, 0xb6, 0xa3, 0xc3, 0x48, 0x7e, 0x6e,
|
||||
0x6b, 0x3a, 0x28, 0x54, 0xfa, 0x85, 0xba, 0x3d,
|
||||
0xca, 0x5e, 0x9b, 0x9f, 0x0a, 0x15, 0x79, 0x2b,
|
||||
0x4e, 0xd4, 0xe5, 0xac, 0x73, 0xf3, 0xa7, 0x57,
|
||||
0x07, 0x70, 0xc0, 0xf7, 0x8c, 0x80, 0x63, 0x0d,
|
||||
0x67, 0x4a, 0xde, 0xed, 0x31, 0xc5, 0xfe, 0x18,
|
||||
0xe3, 0xa5, 0x99, 0x77, 0x26, 0xb8, 0xb4, 0x7c,
|
||||
0x11, 0x44, 0x92, 0xd9, 0x23, 0x20, 0x89, 0x2e,
|
||||
0x37, 0x3f, 0xd1, 0x5b, 0x95, 0xbc, 0xcf, 0xcd,
|
||||
0x90, 0x87, 0x97, 0xb2, 0xdc, 0xfc, 0xbe, 0x61,
|
||||
0xf2, 0x56, 0xd3, 0xab, 0x14, 0x2a, 0x5d, 0x9e,
|
||||
0x84, 0x3c, 0x39, 0x53, 0x47, 0x6d, 0x41, 0xa2,
|
||||
0x1f, 0x2d, 0x43, 0xd8, 0xb7, 0x7b, 0xa4, 0x76,
|
||||
0xc4, 0x17, 0x49, 0xec, 0x7f, 0x0c, 0x6f, 0xf6,
|
||||
0x6c, 0xa1, 0x3b, 0x52, 0x29, 0x9d, 0x55, 0xaa,
|
||||
0xfb, 0x60, 0x86, 0xb1, 0xbb, 0xcc, 0x3e, 0x5a,
|
||||
0xcb, 0x59, 0x5f, 0xb0, 0x9c, 0xa9, 0xa0, 0x51,
|
||||
0x0b, 0xf5, 0x16, 0xeb, 0x7a, 0x75, 0x2c, 0xd7,
|
||||
0x4f, 0xae, 0xd5, 0xe9, 0xe6, 0xe7, 0xad, 0xe8,
|
||||
0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf
|
||||
};
|
||||
|
||||
static const struct galois_field gf256 = {
|
||||
.p = 255,
|
||||
.log = gf256_log,
|
||||
.exp = gf256_exp
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* Polynomial operations
|
||||
*/
|
||||
|
||||
static void poly_add(uint8_t *dst, const uint8_t *src, uint8_t c,
|
||||
int shift, const struct galois_field *gf)
|
||||
{
|
||||
int i;
|
||||
int log_c = gf->log[c];
|
||||
|
||||
if (!c)
|
||||
return;
|
||||
|
||||
for (i = 0; i < MAX_POLY; i++) {
|
||||
int p = i + shift;
|
||||
uint8_t v = src[i];
|
||||
|
||||
if (p < 0 || p >= MAX_POLY)
|
||||
continue;
|
||||
if (!v)
|
||||
continue;
|
||||
|
||||
dst[p] ^= gf->exp[(gf->log[v] + log_c) % gf->p];
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t poly_eval(const uint8_t *s, uint8_t x,
|
||||
const struct galois_field *gf)
|
||||
{
|
||||
int i;
|
||||
uint8_t sum = 0;
|
||||
uint8_t log_x = gf->log[x];
|
||||
|
||||
if (!x)
|
||||
return s[0];
|
||||
|
||||
for (i = 0; i < MAX_POLY; i++) {
|
||||
uint8_t c = s[i];
|
||||
|
||||
if (!c)
|
||||
continue;
|
||||
|
||||
sum ^= gf->exp[(gf->log[c] + log_x * i) % gf->p];
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Berlekamp-Massey algorithm for finding error locator polynomials.
|
||||
*/
|
||||
|
||||
static void berlekamp_massey(const uint8_t *s, int N,
|
||||
const struct galois_field *gf,
|
||||
uint8_t *sigma)
|
||||
{
|
||||
uint8_t C[MAX_POLY];
|
||||
uint8_t B[MAX_POLY];
|
||||
int L = 0;
|
||||
int m = 1;
|
||||
uint8_t b = 1;
|
||||
int n;
|
||||
|
||||
memset(B, 0, sizeof(B));
|
||||
memset(C, 0, sizeof(C));
|
||||
B[0] = 1;
|
||||
C[0] = 1;
|
||||
|
||||
for (n = 0; n < N; n++) {
|
||||
uint8_t d = s[n];
|
||||
uint8_t mult;
|
||||
int i;
|
||||
|
||||
for (i = 1; i <= L; i++) {
|
||||
if (!(C[i] && s[n - i]))
|
||||
continue;
|
||||
|
||||
d ^= gf->exp[(gf->log[C[i]] +
|
||||
gf->log[s[n - i]]) %
|
||||
gf->p];
|
||||
}
|
||||
|
||||
mult = gf->exp[(gf->p - gf->log[b] + gf->log[d]) % gf->p];
|
||||
|
||||
if (!d) {
|
||||
m++;
|
||||
} else if (L * 2 <= n) {
|
||||
uint8_t T[MAX_POLY];
|
||||
|
||||
memcpy(T, C, sizeof(T));
|
||||
poly_add(C, B, mult, m, gf);
|
||||
memcpy(B, T, sizeof(B));
|
||||
L = n + 1 - L;
|
||||
b = d;
|
||||
m = 1;
|
||||
} else {
|
||||
poly_add(C, B, mult, m, gf);
|
||||
m++;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(sigma, C, MAX_POLY);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Code stream error correction
|
||||
*
|
||||
* Generator polynomial for GF(2^8) is x^8 + x^4 + x^3 + x^2 + 1
|
||||
*/
|
||||
|
||||
static int block_syndromes(const uint8_t *data, int bs, int npar, uint8_t *s)
|
||||
{
|
||||
int nonzero = 0;
|
||||
int i;
|
||||
|
||||
memset(s, 0, MAX_POLY);
|
||||
|
||||
for (i = 0; i < npar; i++) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < bs; j++) {
|
||||
uint8_t c = data[bs - j - 1];
|
||||
|
||||
if (!c)
|
||||
continue;
|
||||
|
||||
s[i] ^= gf256_exp[((int)gf256_log[c] +
|
||||
i * j) % 255];
|
||||
}
|
||||
|
||||
if (s[i])
|
||||
nonzero = 1;
|
||||
}
|
||||
|
||||
return nonzero;
|
||||
}
|
||||
|
||||
static void eloc_poly(uint8_t *omega,
|
||||
const uint8_t *s, const uint8_t *sigma,
|
||||
int npar)
|
||||
{
|
||||
int i;
|
||||
|
||||
memset(omega, 0, MAX_POLY);
|
||||
|
||||
for (i = 0; i < npar; i++) {
|
||||
const uint8_t a = sigma[i];
|
||||
const uint8_t log_a = gf256_log[a];
|
||||
int j;
|
||||
|
||||
if (!a)
|
||||
continue;
|
||||
|
||||
for (j = 0; j + 1 < MAX_POLY; j++) {
|
||||
const uint8_t b = s[j + 1];
|
||||
|
||||
if (i + j >= npar)
|
||||
break;
|
||||
|
||||
if (!b)
|
||||
continue;
|
||||
|
||||
omega[i + j] ^=
|
||||
gf256_exp[(log_a + gf256_log[b]) % 255];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static quirc_decode_error_t correct_block(uint8_t *data,
|
||||
const struct quirc_rs_params *ecc)
|
||||
{
|
||||
int npar = ecc->bs - ecc->dw;
|
||||
uint8_t s[MAX_POLY];
|
||||
uint8_t sigma[MAX_POLY];
|
||||
uint8_t sigma_deriv[MAX_POLY];
|
||||
uint8_t omega[MAX_POLY];
|
||||
int i;
|
||||
|
||||
/* Compute syndrome vector */
|
||||
if (!block_syndromes(data, ecc->bs, npar, s))
|
||||
return QUIRC_SUCCESS;
|
||||
|
||||
berlekamp_massey(s, npar, &gf256, sigma);
|
||||
|
||||
/* Compute derivative of sigma */
|
||||
memset(sigma_deriv, 0, MAX_POLY);
|
||||
for (i = 0; i + 1 < MAX_POLY; i += 2)
|
||||
sigma_deriv[i] = sigma[i + 1];
|
||||
|
||||
/* Compute error evaluator polynomial */
|
||||
eloc_poly(omega, s, sigma, npar - 1);
|
||||
|
||||
/* Find error locations and magnitudes */
|
||||
for (i = 0; i < ecc->bs; i++) {
|
||||
uint8_t xinv = gf256_exp[255 - i];
|
||||
|
||||
if (!poly_eval(sigma, xinv, &gf256)) {
|
||||
uint8_t sd_x = poly_eval(sigma_deriv, xinv, &gf256);
|
||||
uint8_t omega_x = poly_eval(omega, xinv, &gf256);
|
||||
uint8_t error = gf256_exp[(255 - gf256_log[sd_x] +
|
||||
gf256_log[omega_x]) % 255];
|
||||
|
||||
data[ecc->bs - i - 1] ^= error;
|
||||
}
|
||||
}
|
||||
|
||||
if (block_syndromes(data, ecc->bs, npar, s))
|
||||
return QUIRC_ERROR_DATA_ECC;
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Format value error correction
|
||||
*
|
||||
* Generator polynomial for GF(2^4) is x^4 + x + 1
|
||||
*/
|
||||
|
||||
#define FORMAT_MAX_ERROR 3
|
||||
#define FORMAT_SYNDROMES (FORMAT_MAX_ERROR * 2)
|
||||
#define FORMAT_BITS 15
|
||||
|
||||
static int format_syndromes(uint16_t u, uint8_t *s)
|
||||
{
|
||||
int i;
|
||||
int nonzero = 0;
|
||||
|
||||
memset(s, 0, MAX_POLY);
|
||||
|
||||
for (i = 0; i < FORMAT_SYNDROMES; i++) {
|
||||
int j;
|
||||
|
||||
s[i] = 0;
|
||||
for (j = 0; j < FORMAT_BITS; j++)
|
||||
if (u & (1 << j))
|
||||
s[i] ^= gf16_exp[((i + 1) * j) % 15];
|
||||
|
||||
if (s[i])
|
||||
nonzero = 1;
|
||||
}
|
||||
|
||||
return nonzero;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t correct_format(uint16_t *f_ret)
|
||||
{
|
||||
uint16_t u = *f_ret;
|
||||
int i;
|
||||
uint8_t s[MAX_POLY];
|
||||
uint8_t sigma[MAX_POLY];
|
||||
|
||||
/* Evaluate U (received codeword) at each of alpha_1 .. alpha_6
|
||||
* to get S_1 .. S_6 (but we index them from 0).
|
||||
*/
|
||||
if (!format_syndromes(u, s))
|
||||
return QUIRC_SUCCESS;
|
||||
|
||||
berlekamp_massey(s, FORMAT_SYNDROMES, &gf16, sigma);
|
||||
|
||||
/* Now, find the roots of the polynomial */
|
||||
for (i = 0; i < 15; i++)
|
||||
if (!poly_eval(sigma, gf16_exp[15 - i], &gf16))
|
||||
u ^= (1 << i);
|
||||
|
||||
if (format_syndromes(u, s))
|
||||
return QUIRC_ERROR_FORMAT_ECC;
|
||||
|
||||
*f_ret = u;
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Decoder algorithm
|
||||
*/
|
||||
|
||||
struct datastream {
|
||||
uint8_t *raw;
|
||||
int data_bits;
|
||||
int ptr;
|
||||
|
||||
uint8_t data[QUIRC_MAX_PAYLOAD];
|
||||
};
|
||||
|
||||
static inline int grid_bit(const struct quirc_code *code, int x, int y)
|
||||
{
|
||||
int p = y * code->size + x;
|
||||
return (code->cell_bitmap[p >> 3] >> (p & 7)) & 1;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t read_format(const struct quirc_code *code,
|
||||
struct quirc_data *data, int which)
|
||||
{
|
||||
int i;
|
||||
uint16_t format = 0;
|
||||
uint16_t fdata;
|
||||
quirc_decode_error_t err;
|
||||
|
||||
if (which) {
|
||||
for (i = 0; i < 7; i++)
|
||||
format = (format << 1) |
|
||||
grid_bit(code, 8, code->size - 1 - i);
|
||||
for (i = 0; i < 8; i++)
|
||||
format = (format << 1) |
|
||||
grid_bit(code, code->size - 8 + i, 8);
|
||||
} else {
|
||||
static const int xs[15] = {
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 7, 5, 4, 3, 2, 1, 0
|
||||
};
|
||||
static const int ys[15] = {
|
||||
0, 1, 2, 3, 4, 5, 7, 8, 8, 8, 8, 8, 8, 8, 8
|
||||
};
|
||||
|
||||
for (i = 14; i >= 0; i--)
|
||||
format = (format << 1) | grid_bit(code, xs[i], ys[i]);
|
||||
}
|
||||
|
||||
format ^= 0x5412;
|
||||
|
||||
err = correct_format(&format);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
fdata = format >> 10;
|
||||
data->ecc_level = fdata >> 3;
|
||||
data->mask = fdata & 7;
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
static int mask_bit(int mask, int i, int j)
|
||||
{
|
||||
switch (mask) {
|
||||
case 0: return !((i + j) % 2);
|
||||
case 1: return !(i % 2);
|
||||
case 2: return !(j % 3);
|
||||
case 3: return !((i + j) % 3);
|
||||
case 4: return !(((i / 2) + (j / 3)) % 2);
|
||||
case 5: return !((i * j) % 2 + (i * j) % 3);
|
||||
case 6: return !(((i * j) % 2 + (i * j) % 3) % 2);
|
||||
case 7: return !(((i * j) % 3 + (i + j) % 2) % 2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int reserved_cell(int version, int i, int j)
|
||||
{
|
||||
const struct quirc_version_info *ver = &quirc_version_db[version];
|
||||
int size = version * 4 + 17;
|
||||
int ai = -1, aj = -1, a;
|
||||
|
||||
/* Finder + format: top left */
|
||||
if (i < 9 && j < 9)
|
||||
return 1;
|
||||
|
||||
/* Finder + format: bottom left */
|
||||
if (i + 8 >= size && j < 9)
|
||||
return 1;
|
||||
|
||||
/* Finder + format: top right */
|
||||
if (i < 9 && j + 8 >= size)
|
||||
return 1;
|
||||
|
||||
/* Exclude timing patterns */
|
||||
if (i == 6 || j == 6)
|
||||
return 1;
|
||||
|
||||
/* Exclude version info, if it exists. Version info sits adjacent to
|
||||
* the top-right and bottom-left finders in three rows, bounded by
|
||||
* the timing pattern.
|
||||
*/
|
||||
if (version >= 7) {
|
||||
if (i < 6 && j + 11 >= size)
|
||||
return 1;
|
||||
if (i + 11 >= size && j < 6)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Exclude alignment patterns */
|
||||
for (a = 0; a < QUIRC_MAX_ALIGNMENT && ver->apat[a]; a++) {
|
||||
int p = ver->apat[a];
|
||||
|
||||
if (abs(p - i) < 3)
|
||||
ai = a;
|
||||
if (abs(p - j) < 3)
|
||||
aj = a;
|
||||
}
|
||||
|
||||
if (ai >= 0 && aj >= 0) {
|
||||
a--;
|
||||
if (ai > 0 && ai < a)
|
||||
return 1;
|
||||
if (aj > 0 && aj < a)
|
||||
return 1;
|
||||
if (aj == a && ai == a)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void read_bit(const struct quirc_code *code,
|
||||
struct quirc_data *data,
|
||||
struct datastream *ds, int i, int j)
|
||||
{
|
||||
int bitpos = ds->data_bits & 7;
|
||||
int bytepos = ds->data_bits >> 3;
|
||||
int v = grid_bit(code, j, i);
|
||||
|
||||
if (mask_bit(data->mask, i, j))
|
||||
v ^= 1;
|
||||
|
||||
if (v)
|
||||
ds->raw[bytepos] |= (0x80 >> bitpos);
|
||||
|
||||
ds->data_bits++;
|
||||
}
|
||||
|
||||
static void read_data(const struct quirc_code *code,
|
||||
struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
int y = code->size - 1;
|
||||
int x = code->size - 1;
|
||||
int dir = -1;
|
||||
|
||||
while (x > 0) {
|
||||
if (x == 6)
|
||||
x--;
|
||||
|
||||
if (!reserved_cell(data->version, y, x))
|
||||
read_bit(code, data, ds, y, x);
|
||||
|
||||
if (!reserved_cell(data->version, y, x - 1))
|
||||
read_bit(code, data, ds, y, x - 1);
|
||||
|
||||
y += dir;
|
||||
if (y < 0 || y >= code->size) {
|
||||
dir = -dir;
|
||||
x -= 2;
|
||||
y += dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static quirc_decode_error_t codestream_ecc(struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
const struct quirc_version_info *ver =
|
||||
&quirc_version_db[data->version];
|
||||
const struct quirc_rs_params *sb_ecc = &ver->ecc[data->ecc_level];
|
||||
struct quirc_rs_params lb_ecc;
|
||||
const int lb_count =
|
||||
(ver->data_bytes - sb_ecc->bs * sb_ecc->ns) / (sb_ecc->bs + 1);
|
||||
const int bc = lb_count + sb_ecc->ns;
|
||||
const int ecc_offset = sb_ecc->dw * bc + lb_count;
|
||||
int dst_offset = 0;
|
||||
int i;
|
||||
|
||||
memcpy(&lb_ecc, sb_ecc, sizeof(lb_ecc));
|
||||
lb_ecc.dw++;
|
||||
lb_ecc.bs++;
|
||||
|
||||
for (i = 0; i < bc; i++) {
|
||||
uint8_t *dst = ds->data + dst_offset;
|
||||
const struct quirc_rs_params *ecc =
|
||||
(i < sb_ecc->ns) ? sb_ecc : &lb_ecc;
|
||||
const int num_ec = ecc->bs - ecc->dw;
|
||||
quirc_decode_error_t err;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < ecc->dw; j++)
|
||||
dst[j] = ds->raw[j * bc + i];
|
||||
for (j = 0; j < num_ec; j++)
|
||||
dst[ecc->dw + j] = ds->raw[ecc_offset + j * bc + i];
|
||||
|
||||
err = correct_block(dst, ecc);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
dst_offset += ecc->dw;
|
||||
}
|
||||
|
||||
ds->data_bits = dst_offset * 8;
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
static inline int bits_remaining(const struct datastream *ds)
|
||||
{
|
||||
return ds->data_bits - ds->ptr;
|
||||
}
|
||||
|
||||
static int take_bits(struct datastream *ds, int len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
while (len && (ds->ptr < ds->data_bits)) {
|
||||
uint8_t b = ds->data[ds->ptr >> 3];
|
||||
int bitpos = ds->ptr & 7;
|
||||
|
||||
ret <<= 1;
|
||||
if ((b << bitpos) & 0x80)
|
||||
ret |= 1;
|
||||
|
||||
ds->ptr++;
|
||||
len--;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int numeric_tuple(struct quirc_data *data,
|
||||
struct datastream *ds,
|
||||
int bits, int digits)
|
||||
{
|
||||
int tuple;
|
||||
int i;
|
||||
|
||||
if (bits_remaining(ds) < bits)
|
||||
return -1;
|
||||
|
||||
tuple = take_bits(ds, bits);
|
||||
|
||||
for (i = digits - 1; i >= 0; i--) {
|
||||
data->payload[data->payload_len + i] = tuple % 10 + '0';
|
||||
tuple /= 10;
|
||||
}
|
||||
|
||||
data->payload_len += digits;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t decode_numeric(struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
int bits = 14;
|
||||
int count;
|
||||
|
||||
if (data->version < 10)
|
||||
bits = 10;
|
||||
else if (data->version < 27)
|
||||
bits = 12;
|
||||
|
||||
count = take_bits(ds, bits);
|
||||
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
|
||||
return QUIRC_ERROR_DATA_OVERFLOW;
|
||||
|
||||
while (count >= 3) {
|
||||
if (numeric_tuple(data, ds, 10, 3) < 0)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
count -= 3;
|
||||
}
|
||||
|
||||
if (count >= 2) {
|
||||
if (numeric_tuple(data, ds, 7, 2) < 0)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
count -= 2;
|
||||
}
|
||||
|
||||
if (count) {
|
||||
if (numeric_tuple(data, ds, 4, 1) < 0)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
count--;
|
||||
}
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
static int alpha_tuple(struct quirc_data *data,
|
||||
struct datastream *ds,
|
||||
int bits, int digits)
|
||||
{
|
||||
int tuple;
|
||||
int i;
|
||||
|
||||
if (bits_remaining(ds) < bits)
|
||||
return -1;
|
||||
|
||||
tuple = take_bits(ds, bits);
|
||||
|
||||
for (i = 0; i < digits; i++) {
|
||||
static const char *alpha_map =
|
||||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
||||
|
||||
data->payload[data->payload_len + digits - i - 1] =
|
||||
alpha_map[tuple % 45];
|
||||
tuple /= 45;
|
||||
}
|
||||
|
||||
data->payload_len += digits;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t decode_alpha(struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
int bits = 13;
|
||||
int count;
|
||||
|
||||
if (data->version < 10)
|
||||
bits = 9;
|
||||
else if (data->version < 27)
|
||||
bits = 11;
|
||||
|
||||
count = take_bits(ds, bits);
|
||||
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
|
||||
return QUIRC_ERROR_DATA_OVERFLOW;
|
||||
|
||||
while (count >= 2) {
|
||||
if (alpha_tuple(data, ds, 11, 2) < 0)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
count -= 2;
|
||||
}
|
||||
|
||||
if (count) {
|
||||
if (alpha_tuple(data, ds, 6, 1) < 0)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
count--;
|
||||
}
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t decode_byte(struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
int bits = 16;
|
||||
int count;
|
||||
int i;
|
||||
|
||||
if (data->version < 10)
|
||||
bits = 8;
|
||||
|
||||
count = take_bits(ds, bits);
|
||||
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
|
||||
return QUIRC_ERROR_DATA_OVERFLOW;
|
||||
if (bits_remaining(ds) < count * 8)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
data->payload[data->payload_len++] = take_bits(ds, 8);
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t decode_kanji(struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
int bits = 12;
|
||||
int count;
|
||||
int i;
|
||||
|
||||
if (data->version < 10)
|
||||
bits = 8;
|
||||
else if (data->version < 27)
|
||||
bits = 10;
|
||||
|
||||
count = take_bits(ds, bits);
|
||||
if (data->payload_len + count * 2 + 1 > QUIRC_MAX_PAYLOAD)
|
||||
return QUIRC_ERROR_DATA_OVERFLOW;
|
||||
if (bits_remaining(ds) < count * 13)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
int d = take_bits(ds, 13);
|
||||
int msB = d / 0xc0;
|
||||
int lsB = d % 0xc0;
|
||||
int intermediate = (msB << 8) | lsB;
|
||||
uint16_t sjw;
|
||||
|
||||
if (intermediate + 0x8140 <= 0x9ffc) {
|
||||
/* bytes are in the range 0x8140 to 0x9FFC */
|
||||
sjw = intermediate + 0x8140;
|
||||
} else {
|
||||
/* bytes are in the range 0xE040 to 0xEBBF */
|
||||
sjw = intermediate + 0xc140;
|
||||
}
|
||||
|
||||
data->payload[data->payload_len++] = sjw >> 8;
|
||||
data->payload[data->payload_len++] = sjw & 0xff;
|
||||
}
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t decode_eci(struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
if (bits_remaining(ds) < 8)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
|
||||
data->eci = take_bits(ds, 8);
|
||||
|
||||
if ((data->eci & 0xc0) == 0x80) {
|
||||
if (bits_remaining(ds) < 8)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
|
||||
data->eci = (data->eci << 8) | take_bits(ds, 8);
|
||||
} else if ((data->eci & 0xe0) == 0xc0) {
|
||||
if (bits_remaining(ds) < 16)
|
||||
return QUIRC_ERROR_DATA_UNDERFLOW;
|
||||
|
||||
data->eci = (data->eci << 16) | take_bits(ds, 16);
|
||||
}
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
static quirc_decode_error_t decode_payload(struct quirc_data *data,
|
||||
struct datastream *ds)
|
||||
{
|
||||
while (bits_remaining(ds) >= 4) {
|
||||
quirc_decode_error_t err = QUIRC_SUCCESS;
|
||||
int type = take_bits(ds, 4);
|
||||
|
||||
switch (type) {
|
||||
case QUIRC_DATA_TYPE_NUMERIC:
|
||||
err = decode_numeric(data, ds);
|
||||
break;
|
||||
|
||||
case QUIRC_DATA_TYPE_ALPHA:
|
||||
err = decode_alpha(data, ds);
|
||||
break;
|
||||
|
||||
case QUIRC_DATA_TYPE_BYTE:
|
||||
err = decode_byte(data, ds);
|
||||
break;
|
||||
|
||||
case QUIRC_DATA_TYPE_KANJI:
|
||||
err = decode_kanji(data, ds);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
err = decode_eci(data, ds);
|
||||
break;
|
||||
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (!(type & (type - 1)) && (type > data->data_type))
|
||||
data->data_type = type;
|
||||
}
|
||||
done:
|
||||
|
||||
/* Add nul terminator to all payloads */
|
||||
if (data->payload_len >= (int) sizeof(data->payload))
|
||||
data->payload_len--;
|
||||
data->payload[data->payload_len] = 0;
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
|
||||
struct quirc_data *data)
|
||||
{
|
||||
quirc_decode_error_t err;
|
||||
struct datastream ds;
|
||||
|
||||
if (code->size > QUIRC_MAX_GRID_SIZE)
|
||||
return QUIRC_ERROR_INVALID_GRID_SIZE;
|
||||
|
||||
if ((code->size - 17) % 4)
|
||||
return QUIRC_ERROR_INVALID_GRID_SIZE;
|
||||
|
||||
memset(data, 0, sizeof(*data));
|
||||
memset(&ds, 0, sizeof(ds));
|
||||
|
||||
data->version = (code->size - 17) / 4;
|
||||
|
||||
if (data->version < 1 ||
|
||||
data->version > QUIRC_MAX_VERSION)
|
||||
return QUIRC_ERROR_INVALID_VERSION;
|
||||
|
||||
/* Read format information -- try both locations */
|
||||
err = read_format(code, data, 0);
|
||||
if (err)
|
||||
err = read_format(code, data, 1);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/*
|
||||
* Borrow data->payload to store the raw bits.
|
||||
* It's only used during read_data + coddestream_ecc below.
|
||||
*
|
||||
* This trick saves the size of struct datastream, which we allocate
|
||||
* on the stack.
|
||||
*/
|
||||
|
||||
ds.raw = data->payload;
|
||||
|
||||
read_data(code, data, &ds);
|
||||
err = codestream_ecc(data, &ds);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
ds.raw = NULL; /* We've done with this buffer. */
|
||||
|
||||
err = decode_payload(data, &ds);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return QUIRC_SUCCESS;
|
||||
}
|
||||
|
||||
void quirc_flip(struct quirc_code *code)
|
||||
{
|
||||
struct quirc_code flipped = {0};
|
||||
unsigned int offset = 0;
|
||||
for (int y = 0; y < code->size; y++) {
|
||||
for (int x = 0; x < code->size; x++) {
|
||||
if (grid_bit(code, y, x)) {
|
||||
flipped.cell_bitmap[offset >> 3u] |= (1u << (offset & 7u));
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
memcpy(&code->cell_bitmap, &flipped.cell_bitmap, sizeof(flipped.cell_bitmap));
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
/*
|
||||
* QR Code generator library (C)
|
||||
*
|
||||
* Copyright (c) Project Nayuki. (MIT License)
|
||||
* https://www.nayuki.io/page/qr-code-generator-library
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
* - The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
* - The Software is provided "as is", without warranty of any kind, express or
|
||||
* implied, including but not limited to the warranties of merchantability,
|
||||
* fitness for a particular purpose and noninfringement. In no event shall the
|
||||
* authors or copyright holders be liable for any claim, damages or other
|
||||
* liability, whether in an action of contract, tort or otherwise, arising from,
|
||||
* out of or in connection with the Software or the use or other dealings in the
|
||||
* Software.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* This library creates QR Code symbols, which is a type of two-dimension barcode.
|
||||
* Invented by Denso Wave and described in the ISO/IEC 18004 standard.
|
||||
* A QR Code structure is an immutable square grid of dark and light cells.
|
||||
* The library provides functions to create a QR Code from text or binary data.
|
||||
* The library covers the QR Code Model 2 specification, supporting all versions (sizes)
|
||||
* from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
|
||||
*
|
||||
* Ways to create a QR Code object:
|
||||
* - High level: Take the payload data and call qrcodegen_encodeText() or qrcodegen_encodeBinary().
|
||||
* - Low level: Custom-make the list of segments and call
|
||||
* qrcodegen_encodeSegments() or qrcodegen_encodeSegmentsAdvanced().
|
||||
* (Note that all ways require supplying the desired error correction level and various byte buffers.)
|
||||
*/
|
||||
|
||||
|
||||
/*---- Enum and struct types----*/
|
||||
|
||||
/*
|
||||
* The error correction level in a QR Code symbol.
|
||||
*/
|
||||
enum qrcodegen_Ecc {
|
||||
// Must be declared in ascending order of error protection
|
||||
// so that an internal qrcodegen function works properly
|
||||
qrcodegen_Ecc_LOW = 0 , // The QR Code can tolerate about 7% erroneous codewords
|
||||
qrcodegen_Ecc_MEDIUM , // The QR Code can tolerate about 15% erroneous codewords
|
||||
qrcodegen_Ecc_QUARTILE, // The QR Code can tolerate about 25% erroneous codewords
|
||||
qrcodegen_Ecc_HIGH , // The QR Code can tolerate about 30% erroneous codewords
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* The mask pattern used in a QR Code symbol.
|
||||
*/
|
||||
enum qrcodegen_Mask {
|
||||
// A special value to tell the QR Code encoder to
|
||||
// automatically select an appropriate mask pattern
|
||||
qrcodegen_Mask_AUTO = -1,
|
||||
// The eight actual mask patterns
|
||||
qrcodegen_Mask_0 = 0,
|
||||
qrcodegen_Mask_1,
|
||||
qrcodegen_Mask_2,
|
||||
qrcodegen_Mask_3,
|
||||
qrcodegen_Mask_4,
|
||||
qrcodegen_Mask_5,
|
||||
qrcodegen_Mask_6,
|
||||
qrcodegen_Mask_7,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Describes how a segment's data bits are interpreted.
|
||||
*/
|
||||
enum qrcodegen_Mode {
|
||||
qrcodegen_Mode_NUMERIC = 0x1,
|
||||
qrcodegen_Mode_ALPHANUMERIC = 0x2,
|
||||
qrcodegen_Mode_BYTE = 0x4,
|
||||
qrcodegen_Mode_KANJI = 0x8,
|
||||
qrcodegen_Mode_ECI = 0x7,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* A segment of character/binary/control data in a QR Code symbol.
|
||||
* The mid-level way to create a segment is to take the payload data
|
||||
* and call a factory function such as qrcodegen_makeNumeric().
|
||||
* The low-level way to create a segment is to custom-make the bit buffer
|
||||
* and initialize a qrcodegen_Segment struct with appropriate values.
|
||||
* Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
|
||||
* Any segment longer than this is meaningless for the purpose of generating QR Codes.
|
||||
* Moreover, the maximum allowed bit length is 32767 because
|
||||
* the largest QR Code (version 40) has 31329 modules.
|
||||
*/
|
||||
struct qrcodegen_Segment {
|
||||
// The mode indicator of this segment.
|
||||
enum qrcodegen_Mode mode;
|
||||
|
||||
// The length of this segment's unencoded data. Measured in characters for
|
||||
// numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
|
||||
// Always zero or positive. Not the same as the data's bit length.
|
||||
int numChars;
|
||||
|
||||
// The data bits of this segment, packed in bitwise big endian.
|
||||
// Can be null if the bit length is zero.
|
||||
uint8_t *data;
|
||||
|
||||
// The number of valid data bits used in the buffer. Requires
|
||||
// 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8.
|
||||
// The character count (numChars) must agree with the mode and the bit buffer length.
|
||||
int bitLength;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*---- Macro constants and functions ----*/
|
||||
|
||||
#define qrcodegen_VERSION_MIN 1 // The minimum version number supported in the QR Code Model 2 standard
|
||||
#define qrcodegen_VERSION_MAX 40 // The maximum version number supported in the QR Code Model 2 standard
|
||||
|
||||
// Calculates the number of bytes needed to store any QR Code up to and including the given version number,
|
||||
// as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];'
|
||||
// can store any single QR Code from version 1 to 25 (inclusive). The result fits in an int (or int16).
|
||||
// Requires qrcodegen_VERSION_MIN <= n <= qrcodegen_VERSION_MAX.
|
||||
#define qrcodegen_BUFFER_LEN_FOR_VERSION(n) ((((n) * 4 + 17) * ((n) * 4 + 17) + 7) / 8 + 1)
|
||||
|
||||
// The worst-case number of bytes needed to store one QR Code, up to and including
|
||||
// version 40. This value equals 3918, which is just under 4 kilobytes.
|
||||
// Use this more convenient value to avoid calculating tighter memory bounds for buffers.
|
||||
#define qrcodegen_BUFFER_LEN_MAX qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX)
|
||||
|
||||
|
||||
|
||||
/*---- Functions (high level) to generate QR Codes ----*/
|
||||
|
||||
/*
|
||||
* Encodes the given text string to a QR Code, returning true if successful.
|
||||
* If the data is too long to fit in any version in the given range
|
||||
* at the given ECC level, then false is returned.
|
||||
*
|
||||
* The input text must be encoded in UTF-8 and contain no NULs.
|
||||
* Requires 1 <= minVersion <= maxVersion <= 40.
|
||||
*
|
||||
* The smallest possible QR Code version within the given range is automatically
|
||||
* chosen for the output. Iff boostEcl is true, then the ECC level of the result
|
||||
* may be higher than the ecl argument if it can be done without increasing the
|
||||
* version. The mask is either between qrcodegen_Mask_0 to 7 to force that mask, or
|
||||
* qrcodegen_Mask_AUTO to automatically choose an appropriate mask (which may be slow).
|
||||
*
|
||||
* About the arrays, letting len = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion):
|
||||
* - Before calling the function:
|
||||
* - The array ranges tempBuffer[0 : len] and qrcode[0 : len] must allow
|
||||
* reading and writing; hence each array must have a length of at least len.
|
||||
* - The two ranges must not overlap (aliasing).
|
||||
* - The initial state of both ranges can be uninitialized
|
||||
* because the function always writes before reading.
|
||||
* - After the function returns:
|
||||
* - Both ranges have no guarantee on which elements are initialized and what values are stored.
|
||||
* - tempBuffer contains no useful data and should be treated as entirely uninitialized.
|
||||
* - If successful, qrcode can be passed into qrcodegen_getSize() and qrcodegen_getModule().
|
||||
*
|
||||
* If successful, the resulting QR Code may use numeric,
|
||||
* alphanumeric, or byte mode to encode the text.
|
||||
*
|
||||
* In the most optimistic case, a QR Code at version 40 with low ECC
|
||||
* can hold any UTF-8 string up to 2953 bytes, or any alphanumeric string
|
||||
* up to 4296 characters, or any digit string up to 7089 characters.
|
||||
* These numbers represent the hard upper limit of the QR Code standard.
|
||||
*
|
||||
* Please consult the QR Code specification for information on
|
||||
* data capacities per version, ECC level, and text encoding mode.
|
||||
*/
|
||||
bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[],
|
||||
enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl);
|
||||
|
||||
|
||||
/*
|
||||
* Encodes the given binary data to a QR Code, returning true if successful.
|
||||
* If the data is too long to fit in any version in the given range
|
||||
* at the given ECC level, then false is returned.
|
||||
*
|
||||
* Requires 1 <= minVersion <= maxVersion <= 40.
|
||||
*
|
||||
* The smallest possible QR Code version within the given range is automatically
|
||||
* chosen for the output. Iff boostEcl is true, then the ECC level of the result
|
||||
* may be higher than the ecl argument if it can be done without increasing the
|
||||
* version. The mask is either between qrcodegen_Mask_0 to 7 to force that mask, or
|
||||
* qrcodegen_Mask_AUTO to automatically choose an appropriate mask (which may be slow).
|
||||
*
|
||||
* About the arrays, letting len = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion):
|
||||
* - Before calling the function:
|
||||
* - The array ranges dataAndTemp[0 : len] and qrcode[0 : len] must allow
|
||||
* reading and writing; hence each array must have a length of at least len.
|
||||
* - The two ranges must not overlap (aliasing).
|
||||
* - The input array range dataAndTemp[0 : dataLen] should normally be
|
||||
* valid UTF-8 text, but is not required by the QR Code standard.
|
||||
* - The initial state of dataAndTemp[dataLen : len] and qrcode[0 : len]
|
||||
* can be uninitialized because the function always writes before reading.
|
||||
* - After the function returns:
|
||||
* - Both ranges have no guarantee on which elements are initialized and what values are stored.
|
||||
* - dataAndTemp contains no useful data and should be treated as entirely uninitialized.
|
||||
* - If successful, qrcode can be passed into qrcodegen_getSize() and qrcodegen_getModule().
|
||||
*
|
||||
* If successful, the resulting QR Code will use byte mode to encode the data.
|
||||
*
|
||||
* In the most optimistic case, a QR Code at version 40 with low ECC can hold any byte
|
||||
* sequence up to length 2953. This is the hard upper limit of the QR Code standard.
|
||||
*
|
||||
* Please consult the QR Code specification for information on
|
||||
* data capacities per version, ECC level, and text encoding mode.
|
||||
*/
|
||||
bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[],
|
||||
enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl);
|
||||
|
||||
|
||||
/*---- Functions (low level) to generate QR Codes ----*/
|
||||
|
||||
/*
|
||||
* Encodes the given segments to a QR Code, returning true if successful.
|
||||
* If the data is too long to fit in any version at the given ECC level,
|
||||
* then false is returned.
|
||||
*
|
||||
* The smallest possible QR Code version is automatically chosen for
|
||||
* the output. The ECC level of the result may be higher than the
|
||||
* ecl argument if it can be done without increasing the version.
|
||||
*
|
||||
* About the byte arrays, letting len = qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX):
|
||||
* - Before calling the function:
|
||||
* - The array ranges tempBuffer[0 : len] and qrcode[0 : len] must allow
|
||||
* reading and writing; hence each array must have a length of at least len.
|
||||
* - The two ranges must not overlap (aliasing).
|
||||
* - The initial state of both ranges can be uninitialized
|
||||
* because the function always writes before reading.
|
||||
* - The input array segs can contain segments whose data buffers overlap with tempBuffer.
|
||||
* - After the function returns:
|
||||
* - Both ranges have no guarantee on which elements are initialized and what values are stored.
|
||||
* - tempBuffer contains no useful data and should be treated as entirely uninitialized.
|
||||
* - Any segment whose data buffer overlaps with tempBuffer[0 : len]
|
||||
* must be treated as having invalid values in that array.
|
||||
* - If successful, qrcode can be passed into qrcodegen_getSize() and qrcodegen_getModule().
|
||||
*
|
||||
* Please consult the QR Code specification for information on
|
||||
* data capacities per version, ECC level, and text encoding mode.
|
||||
*
|
||||
* This function allows the user to create a custom sequence of segments that switches
|
||||
* between modes (such as alphanumeric and byte) to encode text in less space.
|
||||
* This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary().
|
||||
*/
|
||||
bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len,
|
||||
enum qrcodegen_Ecc ecl, uint8_t tempBuffer[], uint8_t qrcode[]);
|
||||
|
||||
|
||||
/*
|
||||
* Encodes the given segments to a QR Code, returning true if successful.
|
||||
* If the data is too long to fit in any version in the given range
|
||||
* at the given ECC level, then false is returned.
|
||||
*
|
||||
* Requires 1 <= minVersion <= maxVersion <= 40.
|
||||
*
|
||||
* The smallest possible QR Code version within the given range is automatically
|
||||
* chosen for the output. Iff boostEcl is true, then the ECC level of the result
|
||||
* may be higher than the ecl argument if it can be done without increasing the
|
||||
* version. The mask is either between qrcodegen_Mask_0 to 7 to force that mask, or
|
||||
* qrcodegen_Mask_AUTO to automatically choose an appropriate mask (which may be slow).
|
||||
*
|
||||
* About the byte arrays, letting len = qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX):
|
||||
* - Before calling the function:
|
||||
* - The array ranges tempBuffer[0 : len] and qrcode[0 : len] must allow
|
||||
* reading and writing; hence each array must have a length of at least len.
|
||||
* - The two ranges must not overlap (aliasing).
|
||||
* - The initial state of both ranges can be uninitialized
|
||||
* because the function always writes before reading.
|
||||
* - The input array segs can contain segments whose data buffers overlap with tempBuffer.
|
||||
* - After the function returns:
|
||||
* - Both ranges have no guarantee on which elements are initialized and what values are stored.
|
||||
* - tempBuffer contains no useful data and should be treated as entirely uninitialized.
|
||||
* - Any segment whose data buffer overlaps with tempBuffer[0 : len]
|
||||
* must be treated as having invalid values in that array.
|
||||
* - If successful, qrcode can be passed into qrcodegen_getSize() and qrcodegen_getModule().
|
||||
*
|
||||
* Please consult the QR Code specification for information on
|
||||
* data capacities per version, ECC level, and text encoding mode.
|
||||
*
|
||||
* This function allows the user to create a custom sequence of segments that switches
|
||||
* between modes (such as alphanumeric and byte) to encode text in less space.
|
||||
* This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary().
|
||||
*/
|
||||
bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], size_t len, enum qrcodegen_Ecc ecl,
|
||||
int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl, uint8_t tempBuffer[], uint8_t qrcode[]);
|
||||
|
||||
|
||||
/*
|
||||
* Tests whether the given string can be encoded as a segment in numeric mode.
|
||||
* A string is encodable iff each character is in the range 0 to 9.
|
||||
*/
|
||||
bool qrcodegen_isNumeric(const char *text);
|
||||
|
||||
|
||||
/*
|
||||
* Tests whether the given string can be encoded as a segment in alphanumeric mode.
|
||||
* A string is encodable iff each character is in the following set: 0 to 9, A to Z
|
||||
* (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
||||
*/
|
||||
bool qrcodegen_isAlphanumeric(const char *text);
|
||||
|
||||
|
||||
/*
|
||||
* Returns the number of bytes (uint8_t) needed for the data buffer of a segment
|
||||
* containing the given number of characters using the given mode. Notes:
|
||||
* - Returns SIZE_MAX on failure, i.e. numChars > INT16_MAX or the internal
|
||||
* calculation of the number of needed bits exceeds INT16_MAX (i.e. 32767).
|
||||
* - Otherwise, all valid results are in the range [0, ceil(INT16_MAX / 8)], i.e. at most 4096.
|
||||
* - It is okay for the user to allocate more bytes for the buffer than needed.
|
||||
* - For byte mode, numChars measures the number of bytes, not Unicode code points.
|
||||
* - For ECI mode, numChars must be 0, and the worst-case number of bytes is returned.
|
||||
* An actual ECI segment can have shorter data. For non-ECI modes, the result is exact.
|
||||
*/
|
||||
size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars);
|
||||
|
||||
|
||||
/*
|
||||
* Returns a segment representing the given binary data encoded in
|
||||
* byte mode. All input byte arrays are acceptable. Any text string
|
||||
* can be converted to UTF-8 bytes and encoded as a byte mode segment.
|
||||
*/
|
||||
struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]);
|
||||
|
||||
|
||||
/*
|
||||
* Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
||||
*/
|
||||
struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]);
|
||||
|
||||
|
||||
/*
|
||||
* Returns a segment representing the given text string encoded in alphanumeric mode.
|
||||
* The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
||||
* dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
||||
*/
|
||||
struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]);
|
||||
|
||||
|
||||
/*
|
||||
* Returns a segment representing an Extended Channel Interpretation
|
||||
* (ECI) designator with the given assignment value.
|
||||
*/
|
||||
struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]);
|
||||
|
||||
|
||||
/*---- Functions to extract raw data from QR Codes ----*/
|
||||
|
||||
/*
|
||||
* Returns the side length of the given QR Code, assuming that encoding succeeded.
|
||||
* The result is in the range [21, 177]. Note that the length of the array buffer
|
||||
* is related to the side length - every 'uint8_t qrcode[]' must have length at least
|
||||
* qrcodegen_BUFFER_LEN_FOR_VERSION(version), which equals ceil(size^2 / 8 + 1).
|
||||
*/
|
||||
int qrcodegen_getSize(const uint8_t qrcode[]);
|
||||
|
||||
|
||||
/*
|
||||
* Returns the color of the module (pixel) at the given coordinates, which is false
|
||||
* for light or true for dark. The top left corner has the coordinates (x=0, y=0).
|
||||
* If the given coordinates are out of bounds, then false (light) is returned.
|
||||
*/
|
||||
bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,171 @@
|
||||
/* quirc -- QR-code recognition library
|
||||
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "quirc_internal.h"
|
||||
|
||||
const char *quirc_version(void)
|
||||
{
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
struct quirc *quirc_new(void)
|
||||
{
|
||||
struct quirc *q = malloc(sizeof(*q));
|
||||
|
||||
if (!q)
|
||||
return NULL;
|
||||
|
||||
memset(q, 0, sizeof(*q));
|
||||
return q;
|
||||
}
|
||||
|
||||
void quirc_destroy(struct quirc *q)
|
||||
{
|
||||
free(q->image);
|
||||
/* q->pixels may alias q->image when their type representation is of the
|
||||
same size, so we need to be careful here to avoid a double free */
|
||||
if (!QUIRC_PIXEL_ALIAS_IMAGE)
|
||||
free(q->pixels);
|
||||
free(q->flood_fill_vars);
|
||||
free(q);
|
||||
}
|
||||
|
||||
int quirc_resize(struct quirc *q, int w, int h)
|
||||
{
|
||||
uint8_t *image = NULL;
|
||||
quirc_pixel_t *pixels = NULL;
|
||||
size_t num_vars;
|
||||
size_t vars_byte_size;
|
||||
struct quirc_flood_fill_vars *vars = NULL;
|
||||
|
||||
/*
|
||||
* XXX: w and h should be size_t (or at least unsigned) as negatives
|
||||
* values would not make much sense. The downside is that it would break
|
||||
* both the API and ABI. Thus, at the moment, let's just do a sanity
|
||||
* check.
|
||||
*/
|
||||
if (w < 0 || h < 0)
|
||||
goto fail;
|
||||
|
||||
/*
|
||||
* alloc a new buffer for q->image. We avoid realloc(3) because we want
|
||||
* on failure to be leave `q` in a consistant, unmodified state.
|
||||
*/
|
||||
image = calloc(w, h);
|
||||
if (!image)
|
||||
goto fail;
|
||||
|
||||
/* compute the "old" (i.e. currently allocated) and the "new"
|
||||
(i.e. requested) image dimensions. Cast to size_t *before*
|
||||
multiplying: w, h and q->w, q->h are int, so "w * h" would
|
||||
otherwise be evaluated in (signed) int arithmetic and can
|
||||
overflow for large-but-valid dimensions (e.g. 50000x50000),
|
||||
corrupting the memcpy() bound below via a bogus wrapped
|
||||
value instead of failing safely. */
|
||||
size_t olddim = quirc_pixel_count(q);
|
||||
size_t newdim = quirc_image_size(w, h);
|
||||
size_t min = (olddim < newdim ? olddim : newdim);
|
||||
|
||||
/*
|
||||
* copy the data into the new buffer, avoiding (a) to read beyond the
|
||||
* old buffer when the new size is greater and (b) to write beyond the
|
||||
* new buffer when the new size is smaller, hence the min computation.
|
||||
*/
|
||||
if (min > 0)
|
||||
(void)memcpy(image, q->image, min);
|
||||
|
||||
/* alloc a new buffer for q->pixels if needed */
|
||||
if (!QUIRC_PIXEL_ALIAS_IMAGE) {
|
||||
pixels = calloc(newdim, sizeof(quirc_pixel_t));
|
||||
if (!pixels)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* alloc the work area for the flood filling logic.
|
||||
*
|
||||
* the size was chosen with the following assumptions and observations:
|
||||
*
|
||||
* - rings are the regions which requires the biggest work area.
|
||||
* - they consumes the most when they are rotated by about 45 degree.
|
||||
* in that case, the necessary depth is about (2 * height_of_the_ring).
|
||||
* - the maximum height of rings would be about 1/3 of the image height.
|
||||
*/
|
||||
|
||||
if ((size_t)h * 2 / 2 != h) {
|
||||
goto fail; /* size_t overflow */
|
||||
}
|
||||
num_vars = (size_t)h * 2 / 3;
|
||||
if (num_vars == 0) {
|
||||
num_vars = 1;
|
||||
}
|
||||
|
||||
vars_byte_size = sizeof(*vars) * num_vars;
|
||||
if (vars_byte_size / sizeof(*vars) != num_vars) {
|
||||
goto fail; /* size_t overflow */
|
||||
}
|
||||
vars = malloc(vars_byte_size);
|
||||
if (!vars)
|
||||
goto fail;
|
||||
|
||||
/* alloc succeeded, update `q` with the new size and buffers */
|
||||
q->w = w;
|
||||
q->h = h;
|
||||
free(q->image);
|
||||
q->image = image;
|
||||
if (!QUIRC_PIXEL_ALIAS_IMAGE) {
|
||||
free(q->pixels);
|
||||
q->pixels = pixels;
|
||||
}
|
||||
free(q->flood_fill_vars);
|
||||
q->flood_fill_vars = vars;
|
||||
q->num_flood_fill_vars = num_vars;
|
||||
|
||||
return 0;
|
||||
/* NOTREACHED */
|
||||
fail:
|
||||
free(image);
|
||||
free(pixels);
|
||||
free(vars);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int quirc_count(const struct quirc *q)
|
||||
{
|
||||
return q->num_grids;
|
||||
}
|
||||
|
||||
static const char *const error_table[] = {
|
||||
[QUIRC_SUCCESS] = "Success",
|
||||
[QUIRC_ERROR_INVALID_GRID_SIZE] = "Invalid grid size",
|
||||
[QUIRC_ERROR_INVALID_VERSION] = "Invalid version",
|
||||
[QUIRC_ERROR_FORMAT_ECC] = "Format data ECC failure",
|
||||
[QUIRC_ERROR_DATA_ECC] = "ECC failure",
|
||||
[QUIRC_ERROR_UNKNOWN_DATA_TYPE] = "Unknown data type",
|
||||
[QUIRC_ERROR_DATA_OVERFLOW] = "Data overflow",
|
||||
[QUIRC_ERROR_DATA_UNDERFLOW] = "Data underflow"
|
||||
};
|
||||
|
||||
const char *quirc_strerror(quirc_decode_error_t err)
|
||||
{
|
||||
if (err >= 0 && err < sizeof(error_table) / sizeof(error_table[0]))
|
||||
return error_table[err];
|
||||
|
||||
return "Unknown error";
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
/* quirc -- QR-code recognition library
|
||||
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef QUIRC_H_
|
||||
#define QUIRC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct quirc;
|
||||
|
||||
/* Obtain the library version string. */
|
||||
const char *quirc_version(void);
|
||||
|
||||
/* Construct a new QR-code recognizer. This function will return NULL
|
||||
* if sufficient memory could not be allocated.
|
||||
*/
|
||||
struct quirc *quirc_new(void);
|
||||
|
||||
/* Destroy a QR-code recognizer. */
|
||||
void quirc_destroy(struct quirc *q);
|
||||
|
||||
/* Resize the QR-code recognizer. The size of an image must be
|
||||
* specified before codes can be analyzed.
|
||||
*
|
||||
* This function returns 0 on success, or -1 if sufficient memory could
|
||||
* not be allocated.
|
||||
*/
|
||||
int quirc_resize(struct quirc *q, int w, int h);
|
||||
|
||||
/* These functions are used to process images for QR-code recognition.
|
||||
* quirc_begin() must first be called to obtain access to a buffer into
|
||||
* which the input image should be placed. Optionally, the current
|
||||
* width and height may be returned.
|
||||
*
|
||||
* After filling the buffer, quirc_end() should be called to process
|
||||
* the image for QR-code recognition. The locations and content of each
|
||||
* code may be obtained using accessor functions described below.
|
||||
*/
|
||||
uint8_t *quirc_begin(struct quirc *q, int *w, int *h);
|
||||
void quirc_end(struct quirc *q);
|
||||
|
||||
/* This structure describes a location in the input image buffer. */
|
||||
struct quirc_point {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
/* This enum describes the various decoder errors which may occur. */
|
||||
typedef enum {
|
||||
QUIRC_SUCCESS = 0,
|
||||
QUIRC_ERROR_INVALID_GRID_SIZE,
|
||||
QUIRC_ERROR_INVALID_VERSION,
|
||||
QUIRC_ERROR_FORMAT_ECC,
|
||||
QUIRC_ERROR_DATA_ECC,
|
||||
QUIRC_ERROR_UNKNOWN_DATA_TYPE,
|
||||
QUIRC_ERROR_DATA_OVERFLOW,
|
||||
QUIRC_ERROR_DATA_UNDERFLOW
|
||||
} quirc_decode_error_t;
|
||||
|
||||
/* Return a string error message for an error code. */
|
||||
const char *quirc_strerror(quirc_decode_error_t err);
|
||||
|
||||
/* Limits on the maximum size of QR-codes and their content. */
|
||||
#define QUIRC_MAX_VERSION 40
|
||||
#define QUIRC_MAX_GRID_SIZE (QUIRC_MAX_VERSION * 4 + 17)
|
||||
#define QUIRC_MAX_BITMAP (((QUIRC_MAX_GRID_SIZE * QUIRC_MAX_GRID_SIZE) + 7) / 8)
|
||||
#define QUIRC_MAX_PAYLOAD 8896
|
||||
|
||||
/* QR-code ECC types. */
|
||||
#define QUIRC_ECC_LEVEL_M 0
|
||||
#define QUIRC_ECC_LEVEL_L 1
|
||||
#define QUIRC_ECC_LEVEL_H 2
|
||||
#define QUIRC_ECC_LEVEL_Q 3
|
||||
|
||||
/* QR-code data types. */
|
||||
#define QUIRC_DATA_TYPE_NUMERIC 1
|
||||
#define QUIRC_DATA_TYPE_ALPHA 2
|
||||
#define QUIRC_DATA_TYPE_BYTE 4
|
||||
#define QUIRC_DATA_TYPE_KANJI 8
|
||||
|
||||
/* Common character encodings */
|
||||
#define QUIRC_ECI_ISO_8859_1 1
|
||||
#define QUIRC_ECI_IBM437 2
|
||||
#define QUIRC_ECI_ISO_8859_2 4
|
||||
#define QUIRC_ECI_ISO_8859_3 5
|
||||
#define QUIRC_ECI_ISO_8859_4 6
|
||||
#define QUIRC_ECI_ISO_8859_5 7
|
||||
#define QUIRC_ECI_ISO_8859_6 8
|
||||
#define QUIRC_ECI_ISO_8859_7 9
|
||||
#define QUIRC_ECI_ISO_8859_8 10
|
||||
#define QUIRC_ECI_ISO_8859_9 11
|
||||
#define QUIRC_ECI_WINDOWS_874 13
|
||||
#define QUIRC_ECI_ISO_8859_13 15
|
||||
#define QUIRC_ECI_ISO_8859_15 17
|
||||
#define QUIRC_ECI_SHIFT_JIS 20
|
||||
#define QUIRC_ECI_UTF_8 26
|
||||
|
||||
/* This structure is used to return information about detected QR codes
|
||||
* in the input image.
|
||||
*/
|
||||
struct quirc_code {
|
||||
/* The four corners of the QR-code, from top left, clockwise */
|
||||
struct quirc_point corners[4];
|
||||
|
||||
/* The number of cells across in the QR-code. The cell bitmap
|
||||
* is a bitmask giving the actual values of cells. If the cell
|
||||
* at (x, y) is black, then the following bit is set:
|
||||
*
|
||||
* cell_bitmap[i >> 3] & (1 << (i & 7))
|
||||
*
|
||||
* where i = (y * size) + x.
|
||||
*/
|
||||
int size;
|
||||
uint8_t cell_bitmap[QUIRC_MAX_BITMAP];
|
||||
};
|
||||
|
||||
/* This structure holds the decoded QR-code data */
|
||||
struct quirc_data {
|
||||
/* Various parameters of the QR-code. These can mostly be
|
||||
* ignored if you only care about the data.
|
||||
*/
|
||||
int version;
|
||||
int ecc_level;
|
||||
int mask;
|
||||
|
||||
/* This field is the highest-valued data type found in the QR
|
||||
* code.
|
||||
*/
|
||||
int data_type;
|
||||
|
||||
/* Data payload. For the Kanji datatype, payload is encoded as
|
||||
* Shift-JIS. For all other datatypes, payload is ASCII text.
|
||||
*/
|
||||
uint8_t payload[QUIRC_MAX_PAYLOAD];
|
||||
int payload_len;
|
||||
|
||||
/* ECI assignment number */
|
||||
uint32_t eci;
|
||||
};
|
||||
|
||||
/* Return the number of QR-codes identified in the last processed
|
||||
* image.
|
||||
*/
|
||||
int quirc_count(const struct quirc *q);
|
||||
|
||||
/* Extract the QR-code specified by the given index. */
|
||||
void quirc_extract(const struct quirc *q, int index,
|
||||
struct quirc_code *code);
|
||||
|
||||
/* Decode a QR-code, returning the payload data. */
|
||||
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
|
||||
struct quirc_data *data);
|
||||
|
||||
/* Flip a QR-code according to optional mirror feature of ISO 18004:2015 */
|
||||
void quirc_flip(struct quirc_code *code);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,153 @@
|
||||
/* quirc -- QR-code recognition library
|
||||
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef QUIRC_INTERNAL_H_
|
||||
#define QUIRC_INTERNAL_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "quirc.h"
|
||||
|
||||
#define QUIRC_ASSERT(a) assert(a)
|
||||
|
||||
#define QUIRC_PIXEL_WHITE 0
|
||||
#define QUIRC_PIXEL_BLACK 1
|
||||
#define QUIRC_PIXEL_REGION 2
|
||||
|
||||
#ifndef QUIRC_MAX_REGIONS
|
||||
#define QUIRC_MAX_REGIONS 254
|
||||
#endif
|
||||
#define QUIRC_MAX_CAPSTONES 32
|
||||
#define QUIRC_MAX_GRIDS (QUIRC_MAX_CAPSTONES * 2)
|
||||
|
||||
#define QUIRC_PERSPECTIVE_PARAMS 8
|
||||
|
||||
#if QUIRC_MAX_REGIONS < UINT8_MAX
|
||||
#define QUIRC_PIXEL_ALIAS_IMAGE 1
|
||||
typedef uint8_t quirc_pixel_t;
|
||||
#elif QUIRC_MAX_REGIONS < UINT16_MAX
|
||||
#define QUIRC_PIXEL_ALIAS_IMAGE 0
|
||||
typedef uint16_t quirc_pixel_t;
|
||||
#else
|
||||
#error "QUIRC_MAX_REGIONS > 65534 is not supported"
|
||||
#endif
|
||||
|
||||
#ifdef QUIRC_FLOAT_TYPE
|
||||
/* Quirc uses double precision floating point internally by default.
|
||||
* On platforms with a single precision FPU but no double precision FPU,
|
||||
* this can be changed to float by defining QUIRC_FLOAT_TYPE.
|
||||
*
|
||||
* When setting QUIRC_FLOAT_TYPE to 'float', consider also defining QUIRC_USE_TGMATH.
|
||||
* This will use the type-generic math functions (tgmath.h, C99 or later) instead of the normal ones,
|
||||
* which will allow the compiler to use the correct overloaded functions for the type.
|
||||
*/
|
||||
typedef QUIRC_FLOAT_TYPE quirc_float_t;
|
||||
#else
|
||||
typedef double quirc_float_t;
|
||||
#endif
|
||||
|
||||
struct quirc_region {
|
||||
struct quirc_point seed;
|
||||
int count;
|
||||
int capstone;
|
||||
};
|
||||
|
||||
struct quirc_capstone {
|
||||
int ring;
|
||||
int stone;
|
||||
|
||||
struct quirc_point corners[4];
|
||||
struct quirc_point center;
|
||||
quirc_float_t c[QUIRC_PERSPECTIVE_PARAMS];
|
||||
|
||||
int qr_grid;
|
||||
};
|
||||
|
||||
struct quirc_grid {
|
||||
/* Capstone indices */
|
||||
int caps[3];
|
||||
|
||||
/* Alignment pattern region and corner */
|
||||
int align_region;
|
||||
struct quirc_point align;
|
||||
|
||||
/* Timing pattern endpoints */
|
||||
struct quirc_point tpep[3];
|
||||
|
||||
/* Grid size and perspective transform */
|
||||
int grid_size;
|
||||
quirc_float_t c[QUIRC_PERSPECTIVE_PARAMS];
|
||||
};
|
||||
|
||||
struct quirc_flood_fill_vars {
|
||||
int y;
|
||||
int right;
|
||||
int left_up;
|
||||
int left_down;
|
||||
};
|
||||
|
||||
struct quirc {
|
||||
uint8_t *image;
|
||||
quirc_pixel_t *pixels;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
int num_regions;
|
||||
struct quirc_region regions[QUIRC_MAX_REGIONS];
|
||||
|
||||
int num_capstones;
|
||||
struct quirc_capstone capstones[QUIRC_MAX_CAPSTONES];
|
||||
|
||||
int num_grids;
|
||||
struct quirc_grid grids[QUIRC_MAX_GRIDS];
|
||||
|
||||
size_t num_flood_fill_vars;
|
||||
struct quirc_flood_fill_vars *flood_fill_vars;
|
||||
};
|
||||
|
||||
static inline size_t quirc_image_size(int w, int h)
|
||||
{
|
||||
return (size_t)w * (size_t)h;
|
||||
}
|
||||
|
||||
static inline size_t quirc_pixel_count(const struct quirc *q)
|
||||
{
|
||||
return quirc_image_size(q->w, q->h);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* QR-code version information database
|
||||
*/
|
||||
|
||||
#define QUIRC_MAX_VERSION 40
|
||||
#define QUIRC_MAX_ALIGNMENT 7
|
||||
|
||||
struct quirc_rs_params {
|
||||
int bs; /* Small block size */
|
||||
int dw; /* Small data words */
|
||||
int ns; /* Number of small blocks */
|
||||
};
|
||||
|
||||
struct quirc_version_info {
|
||||
int data_bytes;
|
||||
int apat[QUIRC_MAX_ALIGNMENT];
|
||||
struct quirc_rs_params ecc[4];
|
||||
};
|
||||
|
||||
extern const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1];
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* TinyBlocks - tb_camera.c
|
||||
* Camera em tons de cinza: V4L2 (Linux), Camera2 por JNI (Android), nada
|
||||
* nos outros sistemas.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../include/tb_camera.h"
|
||||
|
||||
static char s_err[200] = "";
|
||||
static bool s_open = false;
|
||||
|
||||
static void set_err(const char* m) { snprintf(s_err, sizeof(s_err), "%s", m); }
|
||||
const char* tb_camera_error(void) { return s_err; }
|
||||
bool tb_camera_is_open(void) { return s_open; }
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
/* == Android: Camera2 do NDK (camera2ndk + AImageReader), sem Java ===
|
||||
* A permissao vem do SDL_AndroidRequestPermission (pergunta ao usuario). Os
|
||||
* quadros sao lidos sob demanda (acquireLatestImage), sem thread nossa. */
|
||||
#include <camera/NdkCameraManager.h>
|
||||
#include <camera/NdkCameraDevice.h>
|
||||
#include <camera/NdkCameraMetadataTags.h>
|
||||
#include <media/NdkImageReader.h>
|
||||
#include <SDL2/SDL_system.h>
|
||||
|
||||
static ACameraManager* s_mgr;
|
||||
static ACameraDevice* s_dev;
|
||||
static AImageReader* s_reader;
|
||||
static ANativeWindow* s_win;
|
||||
static ACaptureSessionOutputContainer* s_cont;
|
||||
static ACaptureSessionOutput* s_out;
|
||||
static ACameraOutputTarget* s_target;
|
||||
static ACaptureRequest* s_req;
|
||||
static ACameraCaptureSession* s_session;
|
||||
static int s_rot; /* orientacao do sensor (graus) */
|
||||
|
||||
static void dev_disconnected(void* ctx, ACameraDevice* d) { (void)ctx; (void)d; set_err("Camera desconectada"); }
|
||||
static void dev_error(void* ctx, ACameraDevice* d, int e) { (void)ctx; (void)d; char m[64]; snprintf(m, sizeof(m), "Erro na camera (%d)", e); set_err(m); }
|
||||
static void ses_noop(void* ctx, ACameraCaptureSession* s) { (void)ctx; (void)s; }
|
||||
|
||||
static void cam_free(void) {
|
||||
if (s_session) { ACameraCaptureSession_stopRepeating(s_session); ACameraCaptureSession_close(s_session); }
|
||||
if (s_req) ACaptureRequest_free(s_req);
|
||||
if (s_target) ACameraOutputTarget_free(s_target);
|
||||
if (s_cont && s_out) ACaptureSessionOutputContainer_remove(s_cont, s_out);
|
||||
if (s_out) ACaptureSessionOutput_free(s_out);
|
||||
if (s_cont) ACaptureSessionOutputContainer_free(s_cont);
|
||||
if (s_dev) ACameraDevice_close(s_dev);
|
||||
if (s_reader) AImageReader_delete(s_reader);
|
||||
if (s_mgr) ACameraManager_delete(s_mgr);
|
||||
s_session = NULL; s_req = NULL; s_target = NULL; s_out = NULL; s_cont = NULL;
|
||||
s_dev = NULL; s_reader = NULL; s_win = NULL; s_mgr = NULL;
|
||||
}
|
||||
|
||||
bool tb_camera_open(int want_w, int want_h) {
|
||||
if (s_open) return true;
|
||||
if (!SDL_AndroidRequestPermission("android.permission.CAMERA")) {
|
||||
set_err("Sem permissao para usar a camera");
|
||||
return false;
|
||||
}
|
||||
s_mgr = ACameraManager_create();
|
||||
ACameraIdList* ids = NULL;
|
||||
if (!s_mgr || ACameraManager_getCameraIdList(s_mgr, &ids) != ACAMERA_OK || !ids || ids->numCameras < 1) {
|
||||
if (ids) ACameraManager_deleteCameraIdList(ids);
|
||||
set_err("Nenhuma camera no aparelho");
|
||||
cam_free();
|
||||
return false;
|
||||
}
|
||||
const char* id = ids->cameraIds[0]; /* a traseira, se houver */
|
||||
s_rot = 0;
|
||||
for (int i = 0; i < ids->numCameras; i++) {
|
||||
ACameraMetadata* meta = NULL;
|
||||
if (ACameraManager_getCameraCharacteristics(s_mgr, ids->cameraIds[i], &meta) != ACAMERA_OK) continue;
|
||||
ACameraMetadata_const_entry e;
|
||||
bool back = ACameraMetadata_getConstEntry(meta, ACAMERA_LENS_FACING, &e) == ACAMERA_OK &&
|
||||
e.data.u8[0] == ACAMERA_LENS_FACING_BACK;
|
||||
if (back || i == 0) {
|
||||
id = ids->cameraIds[i];
|
||||
if (ACameraMetadata_getConstEntry(meta, ACAMERA_SENSOR_ORIENTATION, &e) == ACAMERA_OK) s_rot = e.data.i32[0];
|
||||
}
|
||||
ACameraMetadata_free(meta);
|
||||
if (back) break;
|
||||
}
|
||||
ACameraDevice_StateCallbacks dcb = { NULL, dev_disconnected, dev_error };
|
||||
camera_status_t st = ACameraManager_openCamera(s_mgr, id, &dcb, &s_dev);
|
||||
ACameraManager_deleteCameraIdList(ids);
|
||||
if (st != ACAMERA_OK) { set_err("Camera ocupada ou sem permissao"); cam_free(); return false; }
|
||||
|
||||
if (AImageReader_new(want_w, want_h, AIMAGE_FORMAT_YUV_420_888, 2, &s_reader) != AMEDIA_OK ||
|
||||
AImageReader_getWindow(s_reader, &s_win) != AMEDIA_OK) {
|
||||
set_err("Falha ao criar o leitor de imagens");
|
||||
cam_free();
|
||||
return false;
|
||||
}
|
||||
ACameraCaptureSession_stateCallbacks scb = { NULL, ses_noop, ses_noop, ses_noop };
|
||||
if (ACaptureSessionOutputContainer_create(&s_cont) != ACAMERA_OK ||
|
||||
ACaptureSessionOutput_create(s_win, &s_out) != ACAMERA_OK ||
|
||||
ACaptureSessionOutputContainer_add(s_cont, s_out) != ACAMERA_OK ||
|
||||
ACameraOutputTarget_create(s_win, &s_target) != ACAMERA_OK ||
|
||||
ACameraDevice_createCaptureRequest(s_dev, TEMPLATE_PREVIEW, &s_req) != ACAMERA_OK ||
|
||||
ACaptureRequest_addTarget(s_req, s_target) != ACAMERA_OK) {
|
||||
set_err("Falha ao preparar a camera");
|
||||
cam_free();
|
||||
return false;
|
||||
}
|
||||
uint8_t af = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
|
||||
ACaptureRequest_setEntry_u8(s_req, ACAMERA_CONTROL_AF_MODE, 1, &af);
|
||||
if (ACameraDevice_createCaptureSession(s_dev, s_cont, &scb, &s_session) != ACAMERA_OK ||
|
||||
ACameraCaptureSession_setRepeatingRequest(s_session, NULL, 1, &s_req, NULL) != ACAMERA_OK) {
|
||||
set_err("Falha ao iniciar a camera");
|
||||
cam_free();
|
||||
return false;
|
||||
}
|
||||
s_open = true;
|
||||
s_err[0] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Canal Y do quadro mais novo, girado conforme o sensor (de pe) */
|
||||
bool tb_camera_frame(unsigned char* gray, int cap, int* w, int* h) {
|
||||
if (!s_open || !s_reader) return false;
|
||||
AImage* img = NULL;
|
||||
if (AImageReader_acquireLatestImage(s_reader, &img) != AMEDIA_OK || !img) return false;
|
||||
int32_t iw = 0, ih = 0, rs = 0, ps = 1;
|
||||
uint8_t* data = NULL;
|
||||
int len = 0;
|
||||
bool ok = AImage_getWidth(img, &iw) == AMEDIA_OK && AImage_getHeight(img, &ih) == AMEDIA_OK &&
|
||||
AImage_getPlaneRowStride(img, 0, &rs) == AMEDIA_OK &&
|
||||
AImage_getPlanePixelStride(img, 0, &ps) == AMEDIA_OK &&
|
||||
AImage_getPlaneData(img, 0, &data, &len) == AMEDIA_OK && data && iw * ih <= cap;
|
||||
if (ok) {
|
||||
bool swap = s_rot == 90 || s_rot == 270;
|
||||
int ow = swap ? ih : iw, oh = swap ? iw : ih;
|
||||
for (int y = 0; y < ih; y++) {
|
||||
const uint8_t* row = data + (size_t)y * (size_t)rs;
|
||||
for (int x = 0; x < iw; x++) {
|
||||
int dx, dy;
|
||||
switch (s_rot) {
|
||||
case 90: dx = ih - 1 - y; dy = x; break;
|
||||
case 180: dx = iw - 1 - x; dy = ih - 1 - y; break;
|
||||
case 270: dx = y; dy = iw - 1 - x; break;
|
||||
default: dx = x; dy = y; break;
|
||||
}
|
||||
gray[dy * ow + dx] = row[x * ps];
|
||||
}
|
||||
}
|
||||
*w = ow; *h = oh;
|
||||
}
|
||||
AImage_delete(img);
|
||||
return ok;
|
||||
}
|
||||
|
||||
void tb_camera_close(void) {
|
||||
if (!s_open && !s_mgr) return;
|
||||
s_open = false;
|
||||
cam_free();
|
||||
}
|
||||
|
||||
#elif defined(__linux__)
|
||||
/* == Linux: V4L2 em YUYV (o canal Y e o cinza) === */
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#define CAM_BUFS 4
|
||||
static int s_fd = -1;
|
||||
static void* s_map[CAM_BUFS];
|
||||
static size_t s_len[CAM_BUFS];
|
||||
static int s_nbuf, s_w, s_h;
|
||||
|
||||
static int xioctl(int fd, unsigned long req, void* arg) {
|
||||
int r;
|
||||
do r = ioctl(fd, req, arg); while (r < 0 && errno == EINTR);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool tb_camera_open(int want_w, int want_h) {
|
||||
if (s_open) return true;
|
||||
const char* dev = getenv("TINYBLOCKS_CAMERA");
|
||||
if (!dev || !dev[0]) dev = "/dev/video0";
|
||||
s_fd = open(dev, O_RDWR | O_NONBLOCK);
|
||||
if (s_fd < 0) { set_err("Nenhuma camera encontrada (/dev/video0)"); return false; }
|
||||
struct v4l2_format f;
|
||||
memset(&f, 0, sizeof(f));
|
||||
f.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
f.fmt.pix.width = (unsigned)want_w;
|
||||
f.fmt.pix.height = (unsigned)want_h;
|
||||
f.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
|
||||
f.fmt.pix.field = V4L2_FIELD_ANY;
|
||||
if (xioctl(s_fd, VIDIOC_S_FMT, &f) < 0 || f.fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV) {
|
||||
set_err("A camera nao entrega YUYV");
|
||||
close(s_fd); s_fd = -1;
|
||||
return false;
|
||||
}
|
||||
s_w = (int)f.fmt.pix.width; s_h = (int)f.fmt.pix.height;
|
||||
struct v4l2_requestbuffers rq;
|
||||
memset(&rq, 0, sizeof(rq));
|
||||
rq.count = CAM_BUFS; rq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; rq.memory = V4L2_MEMORY_MMAP;
|
||||
if (xioctl(s_fd, VIDIOC_REQBUFS, &rq) < 0 || rq.count < 2) {
|
||||
set_err("A camera nao aceitou os buffers");
|
||||
close(s_fd); s_fd = -1;
|
||||
return false;
|
||||
}
|
||||
s_nbuf = (int)(rq.count < CAM_BUFS ? rq.count : CAM_BUFS);
|
||||
for (int i = 0; i < s_nbuf; i++) {
|
||||
struct v4l2_buffer b;
|
||||
memset(&b, 0, sizeof(b));
|
||||
b.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; b.memory = V4L2_MEMORY_MMAP; b.index = (unsigned)i;
|
||||
if (xioctl(s_fd, VIDIOC_QUERYBUF, &b) < 0) { set_err("Falha em QUERYBUF"); tb_camera_close(); return false; }
|
||||
s_len[i] = b.length;
|
||||
s_map[i] = mmap(NULL, b.length, PROT_READ | PROT_WRITE, MAP_SHARED, s_fd, b.m.offset);
|
||||
if (s_map[i] == MAP_FAILED) { s_map[i] = NULL; set_err("Falha no mmap"); tb_camera_close(); return false; }
|
||||
xioctl(s_fd, VIDIOC_QBUF, &b);
|
||||
}
|
||||
enum v4l2_buf_type t = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (xioctl(s_fd, VIDIOC_STREAMON, &t) < 0) { set_err("Falha em STREAMON"); tb_camera_close(); return false; }
|
||||
s_open = true;
|
||||
s_err[0] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tb_camera_frame(unsigned char* gray, int cap, int* w, int* h) {
|
||||
if (!s_open || s_w * s_h > cap) return false;
|
||||
struct v4l2_buffer b;
|
||||
bool got = false;
|
||||
for (;;) { /* esvazia a fila: fica o mais novo */
|
||||
memset(&b, 0, sizeof(b));
|
||||
b.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; b.memory = V4L2_MEMORY_MMAP;
|
||||
if (xioctl(s_fd, VIDIOC_DQBUF, &b) < 0) break;
|
||||
if (b.index < (unsigned)s_nbuf && s_map[b.index]) {
|
||||
const unsigned char* p = (const unsigned char*)s_map[b.index];
|
||||
for (int i = 0; i < s_w * s_h; i++) gray[i] = p[2 * i];
|
||||
got = true;
|
||||
}
|
||||
xioctl(s_fd, VIDIOC_QBUF, &b);
|
||||
}
|
||||
if (got) { *w = s_w; *h = s_h; }
|
||||
return got;
|
||||
}
|
||||
|
||||
void tb_camera_close(void) {
|
||||
if (s_fd >= 0) {
|
||||
enum v4l2_buf_type t = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
xioctl(s_fd, VIDIOC_STREAMOFF, &t);
|
||||
for (int i = 0; i < s_nbuf; i++) if (s_map[i]) { munmap(s_map[i], s_len[i]); s_map[i] = NULL; }
|
||||
close(s_fd);
|
||||
}
|
||||
s_fd = -1; s_nbuf = 0; s_open = false;
|
||||
}
|
||||
|
||||
#else
|
||||
/* == Sem camera (Windows...) === */
|
||||
bool tb_camera_open(int want_w, int want_h) {
|
||||
(void)want_w; (void)want_h;
|
||||
set_err("Camera nao suportada neste sistema");
|
||||
return false;
|
||||
}
|
||||
bool tb_camera_frame(unsigned char* gray, int cap, int* w, int* h) {
|
||||
(void)gray; (void)cap; (void)w; (void)h;
|
||||
return false;
|
||||
}
|
||||
void tb_camera_close(void) { s_open = false; }
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* TinyBlocks - tb_qr.c
|
||||
* Gerar (qrcodegen) e ler (quirc) QR codes.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../include/tb_qr.h"
|
||||
#include "qrcodegen.h"
|
||||
#include "quirc.h"
|
||||
|
||||
int tb_qr_encode(const char* text, unsigned char* mods, int cap) {
|
||||
if (!text || !mods) return 0;
|
||||
uint8_t tmp[qrcodegen_BUFFER_LEN_MAX], qr[qrcodegen_BUFFER_LEN_MAX];
|
||||
if (!qrcodegen_encodeText(text, tmp, qr, qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN,
|
||||
qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true))
|
||||
return 0;
|
||||
int side = qrcodegen_getSize(qr);
|
||||
if (side * side > cap) return 0;
|
||||
for (int y = 0; y < side; y++)
|
||||
for (int x = 0; x < side; x++)
|
||||
mods[y * side + x] = qrcodegen_getModule(qr, x, y) ? 1 : 0;
|
||||
return side;
|
||||
}
|
||||
|
||||
struct TbQrReader {
|
||||
struct quirc* q;
|
||||
int w, h;
|
||||
};
|
||||
|
||||
TbQrReader* tb_qr_reader_new(void) {
|
||||
TbQrReader* r = (TbQrReader*)calloc(1, sizeof(*r));
|
||||
if (!r) return NULL;
|
||||
r->q = quirc_new();
|
||||
if (!r->q) { free(r); return NULL; }
|
||||
return r;
|
||||
}
|
||||
|
||||
int tb_qr_reader_scan(TbQrReader* r, const unsigned char* gray, int w, int h, TbQrFound found, void* user) {
|
||||
if (!r || !gray || w <= 0 || h <= 0) return 0;
|
||||
if (w != r->w || h != r->h) {
|
||||
if (quirc_resize(r->q, w, h) < 0) return 0;
|
||||
r->w = w; r->h = h;
|
||||
}
|
||||
int qw = 0, qh = 0;
|
||||
uint8_t* buf = quirc_begin(r->q, &qw, &qh);
|
||||
memcpy(buf, gray, (size_t)w * (size_t)h);
|
||||
quirc_end(r->q);
|
||||
int n = quirc_count(r->q), got = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
struct quirc_code code;
|
||||
struct quirc_data data;
|
||||
quirc_extract(r->q, i, &code);
|
||||
quirc_decode_error_t e = quirc_decode(&code, &data);
|
||||
if (e == QUIRC_ERROR_DATA_ECC) { /* visto no espelho (camera frontal) */
|
||||
quirc_flip(&code);
|
||||
e = quirc_decode(&code, &data);
|
||||
}
|
||||
if (e) continue;
|
||||
got++;
|
||||
if (found) found((const char*)data.payload, data.payload_len, user);
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
void tb_qr_reader_free(TbQrReader* r) {
|
||||
if (!r) return;
|
||||
quirc_destroy(r->q);
|
||||
free(r);
|
||||
}
|
||||
@@ -0,0 +1,421 @@
|
||||
/* quirc -- QR-code recognition library
|
||||
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "quirc_internal.h"
|
||||
|
||||
const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1] = {
|
||||
{0},
|
||||
{ /* Version 1 */
|
||||
.data_bytes = 26,
|
||||
.apat = {0},
|
||||
.ecc = {
|
||||
{.bs = 26, .dw = 16, .ns = 1},
|
||||
{.bs = 26, .dw = 19, .ns = 1},
|
||||
{.bs = 26, .dw = 9, .ns = 1},
|
||||
{.bs = 26, .dw = 13, .ns = 1}
|
||||
}
|
||||
},
|
||||
{ /* Version 2 */
|
||||
.data_bytes = 44,
|
||||
.apat = {6, 18, 0},
|
||||
.ecc = {
|
||||
{.bs = 44, .dw = 28, .ns = 1},
|
||||
{.bs = 44, .dw = 34, .ns = 1},
|
||||
{.bs = 44, .dw = 16, .ns = 1},
|
||||
{.bs = 44, .dw = 22, .ns = 1}
|
||||
}
|
||||
},
|
||||
{ /* Version 3 */
|
||||
.data_bytes = 70,
|
||||
.apat = {6, 22, 0},
|
||||
.ecc = {
|
||||
{.bs = 70, .dw = 44, .ns = 1},
|
||||
{.bs = 70, .dw = 55, .ns = 1},
|
||||
{.bs = 35, .dw = 13, .ns = 2},
|
||||
{.bs = 35, .dw = 17, .ns = 2}
|
||||
}
|
||||
},
|
||||
{ /* Version 4 */
|
||||
.data_bytes = 100,
|
||||
.apat = {6, 26, 0},
|
||||
.ecc = {
|
||||
{.bs = 50, .dw = 32, .ns = 2},
|
||||
{.bs = 100, .dw = 80, .ns = 1},
|
||||
{.bs = 25, .dw = 9, .ns = 4},
|
||||
{.bs = 50, .dw = 24, .ns = 2}
|
||||
}
|
||||
},
|
||||
{ /* Version 5 */
|
||||
.data_bytes = 134,
|
||||
.apat = {6, 30, 0},
|
||||
.ecc = {
|
||||
{.bs = 67, .dw = 43, .ns = 2},
|
||||
{.bs = 134, .dw = 108, .ns = 1},
|
||||
{.bs = 33, .dw = 11, .ns = 2},
|
||||
{.bs = 33, .dw = 15, .ns = 2}
|
||||
}
|
||||
},
|
||||
{ /* Version 6 */
|
||||
.data_bytes = 172,
|
||||
.apat = {6, 34, 0},
|
||||
.ecc = {
|
||||
{.bs = 43, .dw = 27, .ns = 4},
|
||||
{.bs = 86, .dw = 68, .ns = 2},
|
||||
{.bs = 43, .dw = 15, .ns = 4},
|
||||
{.bs = 43, .dw = 19, .ns = 4}
|
||||
}
|
||||
},
|
||||
{ /* Version 7 */
|
||||
.data_bytes = 196,
|
||||
.apat = {6, 22, 38, 0},
|
||||
.ecc = {
|
||||
{.bs = 49, .dw = 31, .ns = 4},
|
||||
{.bs = 98, .dw = 78, .ns = 2},
|
||||
{.bs = 39, .dw = 13, .ns = 4},
|
||||
{.bs = 32, .dw = 14, .ns = 2}
|
||||
}
|
||||
},
|
||||
{ /* Version 8 */
|
||||
.data_bytes = 242,
|
||||
.apat = {6, 24, 42, 0},
|
||||
.ecc = {
|
||||
{.bs = 60, .dw = 38, .ns = 2},
|
||||
{.bs = 121, .dw = 97, .ns = 2},
|
||||
{.bs = 40, .dw = 14, .ns = 4},
|
||||
{.bs = 40, .dw = 18, .ns = 4}
|
||||
}
|
||||
},
|
||||
{ /* Version 9 */
|
||||
.data_bytes = 292,
|
||||
.apat = {6, 26, 46, 0},
|
||||
.ecc = {
|
||||
{.bs = 58, .dw = 36, .ns = 3},
|
||||
{.bs = 146, .dw = 116, .ns = 2},
|
||||
{.bs = 36, .dw = 12, .ns = 4},
|
||||
{.bs = 36, .dw = 16, .ns = 4}
|
||||
}
|
||||
},
|
||||
{ /* Version 10 */
|
||||
.data_bytes = 346,
|
||||
.apat = {6, 28, 50, 0},
|
||||
.ecc = {
|
||||
{.bs = 69, .dw = 43, .ns = 4},
|
||||
{.bs = 86, .dw = 68, .ns = 2},
|
||||
{.bs = 43, .dw = 15, .ns = 6},
|
||||
{.bs = 43, .dw = 19, .ns = 6}
|
||||
}
|
||||
},
|
||||
{ /* Version 11 */
|
||||
.data_bytes = 404,
|
||||
.apat = {6, 30, 54, 0},
|
||||
.ecc = {
|
||||
{.bs = 80, .dw = 50, .ns = 1},
|
||||
{.bs = 101, .dw = 81, .ns = 4},
|
||||
{.bs = 36, .dw = 12, .ns = 3},
|
||||
{.bs = 50, .dw = 22, .ns = 4}
|
||||
}
|
||||
},
|
||||
{ /* Version 12 */
|
||||
.data_bytes = 466,
|
||||
.apat = {6, 32, 58, 0},
|
||||
.ecc = {
|
||||
{.bs = 58, .dw = 36, .ns = 6},
|
||||
{.bs = 116, .dw = 92, .ns = 2},
|
||||
{.bs = 42, .dw = 14, .ns = 7},
|
||||
{.bs = 46, .dw = 20, .ns = 4}
|
||||
}
|
||||
},
|
||||
{ /* Version 13 */
|
||||
.data_bytes = 532,
|
||||
.apat = {6, 34, 62, 0},
|
||||
.ecc = {
|
||||
{.bs = 59, .dw = 37, .ns = 8},
|
||||
{.bs = 133, .dw = 107, .ns = 4},
|
||||
{.bs = 33, .dw = 11, .ns = 12},
|
||||
{.bs = 44, .dw = 20, .ns = 8}
|
||||
}
|
||||
},
|
||||
{ /* Version 14 */
|
||||
.data_bytes = 581,
|
||||
.apat = {6, 26, 46, 66, 0},
|
||||
.ecc = {
|
||||
{.bs = 64, .dw = 40, .ns = 4},
|
||||
{.bs = 145, .dw = 115, .ns = 3},
|
||||
{.bs = 36, .dw = 12, .ns = 11},
|
||||
{.bs = 36, .dw = 16, .ns = 11}
|
||||
}
|
||||
},
|
||||
{ /* Version 15 */
|
||||
.data_bytes = 655,
|
||||
.apat = {6, 26, 48, 70, 0},
|
||||
.ecc = {
|
||||
{.bs = 65, .dw = 41, .ns = 5},
|
||||
{.bs = 109, .dw = 87, .ns = 5},
|
||||
{.bs = 36, .dw = 12, .ns = 11},
|
||||
{.bs = 54, .dw = 24, .ns = 5}
|
||||
}
|
||||
},
|
||||
{ /* Version 16 */
|
||||
.data_bytes = 733,
|
||||
.apat = {6, 26, 50, 74, 0},
|
||||
.ecc = {
|
||||
{.bs = 73, .dw = 45, .ns = 7},
|
||||
{.bs = 122, .dw = 98, .ns = 5},
|
||||
{.bs = 45, .dw = 15, .ns = 3},
|
||||
{.bs = 43, .dw = 19, .ns = 15}
|
||||
}
|
||||
},
|
||||
{ /* Version 17 */
|
||||
.data_bytes = 815,
|
||||
.apat = {6, 30, 54, 78, 0},
|
||||
.ecc = {
|
||||
{.bs = 74, .dw = 46, .ns = 10},
|
||||
{.bs = 135, .dw = 107, .ns = 1},
|
||||
{.bs = 42, .dw = 14, .ns = 2},
|
||||
{.bs = 50, .dw = 22, .ns = 1}
|
||||
}
|
||||
},
|
||||
{ /* Version 18 */
|
||||
.data_bytes = 901,
|
||||
.apat = {6, 30, 56, 82, 0},
|
||||
.ecc = {
|
||||
{.bs = 69, .dw = 43, .ns = 9},
|
||||
{.bs = 150, .dw = 120, .ns = 5},
|
||||
{.bs = 42, .dw = 14, .ns = 2},
|
||||
{.bs = 50, .dw = 22, .ns = 17}
|
||||
}
|
||||
},
|
||||
{ /* Version 19 */
|
||||
.data_bytes = 991,
|
||||
.apat = {6, 30, 58, 86, 0},
|
||||
.ecc = {
|
||||
{.bs = 70, .dw = 44, .ns = 3},
|
||||
{.bs = 141, .dw = 113, .ns = 3},
|
||||
{.bs = 39, .dw = 13, .ns = 9},
|
||||
{.bs = 47, .dw = 21, .ns = 17}
|
||||
}
|
||||
},
|
||||
{ /* Version 20 */
|
||||
.data_bytes = 1085,
|
||||
.apat = {6, 34, 62, 90, 0},
|
||||
.ecc = {
|
||||
{.bs = 67, .dw = 41, .ns = 3},
|
||||
{.bs = 135, .dw = 107, .ns = 3},
|
||||
{.bs = 43, .dw = 15, .ns = 15},
|
||||
{.bs = 54, .dw = 24, .ns = 15}
|
||||
}
|
||||
},
|
||||
{ /* Version 21 */
|
||||
.data_bytes = 1156,
|
||||
.apat = {6, 28, 50, 72, 92, 0},
|
||||
.ecc = {
|
||||
{.bs = 68, .dw = 42, .ns = 17},
|
||||
{.bs = 144, .dw = 116, .ns = 4},
|
||||
{.bs = 46, .dw = 16, .ns = 19},
|
||||
{.bs = 50, .dw = 22, .ns = 17}
|
||||
}
|
||||
},
|
||||
{ /* Version 22 */
|
||||
.data_bytes = 1258,
|
||||
.apat = {6, 26, 50, 74, 98, 0},
|
||||
.ecc = {
|
||||
{.bs = 74, .dw = 46, .ns = 17},
|
||||
{.bs = 139, .dw = 111, .ns = 2},
|
||||
{.bs = 37, .dw = 13, .ns = 34},
|
||||
{.bs = 54, .dw = 24, .ns = 7}
|
||||
}
|
||||
},
|
||||
{ /* Version 23 */
|
||||
.data_bytes = 1364,
|
||||
.apat = {6, 30, 54, 78, 102, 0},
|
||||
.ecc = {
|
||||
{.bs = 75, .dw = 47, .ns = 4},
|
||||
{.bs = 151, .dw = 121, .ns = 4},
|
||||
{.bs = 45, .dw = 15, .ns = 16},
|
||||
{.bs = 54, .dw = 24, .ns = 11}
|
||||
}
|
||||
},
|
||||
{ /* Version 24 */
|
||||
.data_bytes = 1474,
|
||||
.apat = {6, 28, 54, 80, 106, 0},
|
||||
.ecc = {
|
||||
{.bs = 73, .dw = 45, .ns = 6},
|
||||
{.bs = 147, .dw = 117, .ns = 6},
|
||||
{.bs = 46, .dw = 16, .ns = 30},
|
||||
{.bs = 54, .dw = 24, .ns = 11}
|
||||
}
|
||||
},
|
||||
{ /* Version 25 */
|
||||
.data_bytes = 1588,
|
||||
.apat = {6, 32, 58, 84, 110, 0},
|
||||
.ecc = {
|
||||
{.bs = 75, .dw = 47, .ns = 8},
|
||||
{.bs = 132, .dw = 106, .ns = 8},
|
||||
{.bs = 45, .dw = 15, .ns = 22},
|
||||
{.bs = 54, .dw = 24, .ns = 7}
|
||||
}
|
||||
},
|
||||
{ /* Version 26 */
|
||||
.data_bytes = 1706,
|
||||
.apat = {6, 30, 58, 86, 114, 0},
|
||||
.ecc = {
|
||||
{.bs = 74, .dw = 46, .ns = 19},
|
||||
{.bs = 142, .dw = 114, .ns = 10},
|
||||
{.bs = 46, .dw = 16, .ns = 33},
|
||||
{.bs = 50, .dw = 22, .ns = 28}
|
||||
}
|
||||
},
|
||||
{ /* Version 27 */
|
||||
.data_bytes = 1828,
|
||||
.apat = {6, 34, 62, 90, 118, 0},
|
||||
.ecc = {
|
||||
{.bs = 73, .dw = 45, .ns = 22},
|
||||
{.bs = 152, .dw = 122, .ns = 8},
|
||||
{.bs = 45, .dw = 15, .ns = 12},
|
||||
{.bs = 53, .dw = 23, .ns = 8}
|
||||
}
|
||||
},
|
||||
{ /* Version 28 */
|
||||
.data_bytes = 1921,
|
||||
.apat = {6, 26, 50, 74, 98, 122, 0},
|
||||
.ecc = {
|
||||
{.bs = 73, .dw = 45, .ns = 3},
|
||||
{.bs = 147, .dw = 117, .ns = 3},
|
||||
{.bs = 45, .dw = 15, .ns = 11},
|
||||
{.bs = 54, .dw = 24, .ns = 4}
|
||||
}
|
||||
},
|
||||
{ /* Version 29 */
|
||||
.data_bytes = 2051,
|
||||
.apat = {6, 30, 54, 78, 102, 126, 0},
|
||||
.ecc = {
|
||||
{.bs = 73, .dw = 45, .ns = 21},
|
||||
{.bs = 146, .dw = 116, .ns = 7},
|
||||
{.bs = 45, .dw = 15, .ns = 19},
|
||||
{.bs = 53, .dw = 23, .ns = 1}
|
||||
}
|
||||
},
|
||||
{ /* Version 30 */
|
||||
.data_bytes = 2185,
|
||||
.apat = {6, 26, 52, 78, 104, 130, 0},
|
||||
.ecc = {
|
||||
{.bs = 75, .dw = 47, .ns = 19},
|
||||
{.bs = 145, .dw = 115, .ns = 5},
|
||||
{.bs = 45, .dw = 15, .ns = 23},
|
||||
{.bs = 54, .dw = 24, .ns = 15}
|
||||
}
|
||||
},
|
||||
{ /* Version 31 */
|
||||
.data_bytes = 2323,
|
||||
.apat = {6, 30, 56, 82, 108, 134, 0},
|
||||
.ecc = {
|
||||
{.bs = 74, .dw = 46, .ns = 2},
|
||||
{.bs = 145, .dw = 115, .ns = 13},
|
||||
{.bs = 45, .dw = 15, .ns = 23},
|
||||
{.bs = 54, .dw = 24, .ns = 42}
|
||||
}
|
||||
},
|
||||
{ /* Version 32 */
|
||||
.data_bytes = 2465,
|
||||
.apat = {6, 34, 60, 86, 112, 138, 0},
|
||||
.ecc = {
|
||||
{.bs = 74, .dw = 46, .ns = 10},
|
||||
{.bs = 145, .dw = 115, .ns = 17},
|
||||
{.bs = 45, .dw = 15, .ns = 19},
|
||||
{.bs = 54, .dw = 24, .ns = 10}
|
||||
}
|
||||
},
|
||||
{ /* Version 33 */
|
||||
.data_bytes = 2611,
|
||||
.apat = {6, 30, 58, 86, 114, 142, 0},
|
||||
.ecc = {
|
||||
{.bs = 74, .dw = 46, .ns = 14},
|
||||
{.bs = 145, .dw = 115, .ns = 17},
|
||||
{.bs = 45, .dw = 15, .ns = 11},
|
||||
{.bs = 54, .dw = 24, .ns = 29}
|
||||
}
|
||||
},
|
||||
{ /* Version 34 */
|
||||
.data_bytes = 2761,
|
||||
.apat = {6, 34, 62, 90, 118, 146, 0},
|
||||
.ecc = {
|
||||
{.bs = 74, .dw = 46, .ns = 14},
|
||||
{.bs = 145, .dw = 115, .ns = 13},
|
||||
{.bs = 46, .dw = 16, .ns = 59},
|
||||
{.bs = 54, .dw = 24, .ns = 44}
|
||||
}
|
||||
},
|
||||
{ /* Version 35 */
|
||||
.data_bytes = 2876,
|
||||
.apat = {6, 30, 54, 78, 102, 126, 150},
|
||||
.ecc = {
|
||||
{.bs = 75, .dw = 47, .ns = 12},
|
||||
{.bs = 151, .dw = 121, .ns = 12},
|
||||
{.bs = 45, .dw = 15, .ns = 22},
|
||||
{.bs = 54, .dw = 24, .ns = 39}
|
||||
}
|
||||
},
|
||||
{ /* Version 36 */
|
||||
.data_bytes = 3034,
|
||||
.apat = {6, 24, 50, 76, 102, 128, 154},
|
||||
.ecc = {
|
||||
{.bs = 75, .dw = 47, .ns = 6},
|
||||
{.bs = 151, .dw = 121, .ns = 6},
|
||||
{.bs = 45, .dw = 15, .ns = 2},
|
||||
{.bs = 54, .dw = 24, .ns = 46}
|
||||
}
|
||||
},
|
||||
{ /* Version 37 */
|
||||
.data_bytes = 3196,
|
||||
.apat = {6, 28, 54, 80, 106, 132, 158},
|
||||
.ecc = {
|
||||
{.bs = 74, .dw = 46, .ns = 29},
|
||||
{.bs = 152, .dw = 122, .ns = 17},
|
||||
{.bs = 45, .dw = 15, .ns = 24},
|
||||
{.bs = 54, .dw = 24, .ns = 49}
|
||||
}
|
||||
},
|
||||
{ /* Version 38 */
|
||||
.data_bytes = 3362,
|
||||
.apat = {6, 32, 58, 84, 110, 136, 162},
|
||||
.ecc = {
|
||||
{.bs = 74, .dw = 46, .ns = 13},
|
||||
{.bs = 152, .dw = 122, .ns = 4},
|
||||
{.bs = 45, .dw = 15, .ns = 42},
|
||||
{.bs = 54, .dw = 24, .ns = 48}
|
||||
}
|
||||
},
|
||||
{ /* Version 39 */
|
||||
.data_bytes = 3532,
|
||||
.apat = {6, 26, 54, 82, 110, 138, 166},
|
||||
.ecc = {
|
||||
{.bs = 75, .dw = 47, .ns = 40},
|
||||
{.bs = 147, .dw = 117, .ns = 20},
|
||||
{.bs = 45, .dw = 15, .ns = 10},
|
||||
{.bs = 54, .dw = 24, .ns = 43}
|
||||
}
|
||||
},
|
||||
{ /* Version 40 */
|
||||
.data_bytes = 3706,
|
||||
.apat = {6, 30, 58, 86, 114, 142, 170},
|
||||
.ecc = {
|
||||
{.bs = 75, .dw = 47, .ns = 18},
|
||||
{.bs = 148, .dw = 118, .ns = 19},
|
||||
{.bs = 45, .dw = 15, .ns = 20},
|
||||
{.bs = 54, .dw = 24, .ns = 34}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -514,6 +514,15 @@ static bool model_fits(const Model* m, const TbBpTab* tab, int bi) {
|
||||
|
||||
static void render_block(const Models* M, const TbBpTab* tab, int bi, Sb* out, bool outer);
|
||||
|
||||
static bool is_number(const char* s);
|
||||
|
||||
/* Delimitador de um valor: campo redondo com texto que nao e numero vai entre
|
||||
colchetes, como no Scratch ("= [a]"); "(a)" seria lido de volta como a
|
||||
variavel a */
|
||||
static char slot_open(int kind, const char* v) {
|
||||
return kind == T_ROUND && is_number(v) ? '(' : '[';
|
||||
}
|
||||
|
||||
/* Valor de um campo, no parentese pedido pelo modelo ('(' '[' '<') */
|
||||
static void render_slot(const Models* M, const TbBpTab* tab, int bi, int s, int kind, bool dropdown, Sb* out) {
|
||||
const TbBpBlock* b = &tab->blocks[bi];
|
||||
@@ -521,7 +530,8 @@ static void render_slot(const Models* M, const TbBpTab* tab, int bi, int s, int
|
||||
if (c >= 0 && is_literal(tab->blocks[c].type)) {
|
||||
const TbBpBlock* L = &tab->blocks[c];
|
||||
const char* v = strcmp(L->type, "Literal.Text") == 0 && L->lit[0] ? L->lit : L->in_text[0];
|
||||
sb_str(out, kind == T_ROUND ? "(" : "["); sb_esc(out, v); sb_str(out, kind == T_ROUND ? ")" : "]");
|
||||
char o = slot_open(kind, v);
|
||||
sb_str(out, o == '(' ? "(" : "["); sb_esc(out, v); sb_str(out, o == '(' ? ")" : "]");
|
||||
return;
|
||||
}
|
||||
if (c >= 0 && kind == T_ANGLE && !strcmp(tab->blocks[c].type, "Port.In")) { /* <ok :: custom-arg> */
|
||||
@@ -531,10 +541,11 @@ static void render_slot(const Models* M, const TbBpTab* tab, int bi, int s, int
|
||||
if (c >= 0) { render_block(M, tab, c, out, true); return; }
|
||||
const char* v = s < TB_BP_MAX_INPUTS ? b->in_text[s] : "";
|
||||
if (kind == T_ANGLE) { sb_str(out, "<>"); return; }
|
||||
sb_str(out, kind == T_ROUND ? "(" : "[");
|
||||
char o = dropdown ? (kind == T_ROUND ? '(' : '[') : slot_open(kind, v);
|
||||
sb_str(out, o == '(' ? "(" : "[");
|
||||
sb_esc(out, v);
|
||||
if (dropdown) sb_str(out, " v");
|
||||
sb_str(out, kind == T_ROUND ? ")" : "]");
|
||||
sb_str(out, o == '(' ? ")" : "]");
|
||||
}
|
||||
|
||||
static void render_tokens(const Models* M, const Model* m, const TbBpTab* tab, int bi, Sb* out) {
|
||||
|
||||
@@ -76,10 +76,10 @@ static void eval_handle_noop(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
/* ===
|
||||
* Fonte TTF - cache por tamanho
|
||||
* === */
|
||||
#define FONT_CACHE_CAP 8
|
||||
#define FONT_CACHE_CAP 64 /* o zoom da area de scripts pede muitos tamanhos */
|
||||
#define FONT_SEARCH_COUNT 9
|
||||
|
||||
typedef struct { int size; TTF_Font* font; } FontEntry;
|
||||
typedef struct { int size, family; TTF_Font* font; unsigned used; } FontEntry;
|
||||
|
||||
static FontEntry s_font_cache[FONT_CACHE_CAP];
|
||||
static int s_font_cache_n = 0;
|
||||
@@ -96,8 +96,37 @@ static const char* s_font_paths[FONT_SEARCH_COUNT] = {
|
||||
"C:/Windows/Fonts/arial.ttf",
|
||||
};
|
||||
|
||||
/* A fonte que vai junto do programa (pacote Windows, AppImage):
|
||||
<pasta do executavel>/fonts/DejaVuSans.ttf */
|
||||
/* Fontes que vao junto do programa (TB_FONT_*): Roboto e Material Symbols.
|
||||
Procura em $TINYBLOCKS_APPDIR/fonts (AppImage, Android), <pasta do
|
||||
executavel>/fonts (pacote Windows) e <pasta do executavel>/../assets/fonts
|
||||
(rodando da arvore: build/editor). DejaVu fica de reserva para o texto. */
|
||||
static const char* s_family_files[TB_FONT_COUNT] = {
|
||||
"Roboto-Regular.ttf", "Roboto-Medium.ttf",
|
||||
"MaterialSymbolsOutlined.ttf", "MaterialSymbolsFilled.ttf",
|
||||
};
|
||||
|
||||
static TTF_Font* open_in(const char* dir, const char* sub, const char* file, int size) {
|
||||
char path[1200];
|
||||
snprintf(path, sizeof(path), "%s%s%s", dir, sub, file);
|
||||
return TTF_OpenFont(path, size);
|
||||
}
|
||||
|
||||
static TTF_Font* family_font(int family, int size) {
|
||||
const char* file = s_family_files[family];
|
||||
TTF_Font* f = NULL;
|
||||
const char* dir = getenv("TINYBLOCKS_APPDIR");
|
||||
if (dir && dir[0]) f = open_in(dir, "/fonts/", file, size);
|
||||
char* base = f ? NULL : SDL_GetBasePath();
|
||||
if (base) {
|
||||
f = open_in(base, "fonts/", file, size);
|
||||
if (!f) f = open_in(base, "../assets/fonts/", file, size);
|
||||
SDL_free(base);
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
if (!f) f = open_in("", "fonts/", file, size); /* assets do APK */
|
||||
#endif
|
||||
return f;
|
||||
}
|
||||
static TTF_Font* bundled_font(int size) {
|
||||
char path[1024];
|
||||
const char* dir = getenv("TINYBLOCKS_APPDIR");
|
||||
@@ -113,19 +142,37 @@ static TTF_Font* bundled_font(int size) {
|
||||
return TTF_OpenFont(path, size);
|
||||
}
|
||||
|
||||
static TTF_Font* get_font(int size) {
|
||||
static TTF_Font* get_font(int size, int family) {
|
||||
static unsigned tick = 0;
|
||||
tick++;
|
||||
if (family < 0 || family >= TB_FONT_COUNT) family = TB_FONT_REGULAR;
|
||||
for (int i = 0; i < s_font_cache_n; i++)
|
||||
if (s_font_cache[i].size == size) return s_font_cache[i].font;
|
||||
if (s_font_cache[i].size == size && s_font_cache[i].family == family) {
|
||||
s_font_cache[i].used = tick;
|
||||
return s_font_cache[i].font;
|
||||
}
|
||||
|
||||
TTF_Font* f = bundled_font(size);
|
||||
for (int i = 0; i < FONT_SEARCH_COUNT && !f; i++)
|
||||
f = TTF_OpenFont(s_font_paths[i], size);
|
||||
|
||||
if (f && s_font_cache_n < FONT_CACHE_CAP) {
|
||||
s_font_cache[s_font_cache_n].size = size;
|
||||
s_font_cache[s_font_cache_n].font = f;
|
||||
s_font_cache_n++;
|
||||
TTF_Font* f = family_font(family, size);
|
||||
if (!f && family == TB_FONT_MEDIUM) f = family_font(TB_FONT_REGULAR, size);
|
||||
if (!f && family <= TB_FONT_MEDIUM) { /* sem Roboto: DejaVu */
|
||||
f = bundled_font(size);
|
||||
for (int i = 0; i < FONT_SEARCH_COUNT && !f; i++)
|
||||
f = TTF_OpenFont(s_font_paths[i], size);
|
||||
}
|
||||
if (!f) return NULL; /* sem icones: nada */
|
||||
|
||||
/* cheio: fecha o usado ha mais tempo (antes vazava uma fonte por chamada) */
|
||||
int slot = s_font_cache_n;
|
||||
if (slot >= FONT_CACHE_CAP) {
|
||||
slot = 0;
|
||||
for (int i = 1; i < FONT_CACHE_CAP; i++)
|
||||
if (s_font_cache[i].used < s_font_cache[slot].used) slot = i;
|
||||
TTF_CloseFont(s_font_cache[slot].font);
|
||||
} else s_font_cache_n++;
|
||||
s_font_cache[slot].size = size;
|
||||
s_font_cache[slot].family = family;
|
||||
s_font_cache[slot].font = f;
|
||||
s_font_cache[slot].used = tick;
|
||||
return f;
|
||||
}
|
||||
|
||||
@@ -321,7 +368,13 @@ static void sdl2_execute(SDL_Renderer* ren,
|
||||
scaled = *cmd;
|
||||
scaled.x *= s_ui_scale; scaled.y *= s_ui_scale;
|
||||
scaled.w *= s_ui_scale; scaled.h *= s_ui_scale;
|
||||
scaled.param *= s_ui_scale; scaled.font_size *= s_ui_scale;
|
||||
if (cmd->kind == TB_DRAW_FILL_POLY) { /* param = quantos pontos */
|
||||
float xy[2 * TB_POLY_MAX];
|
||||
int n = tb_draw_poly_get(cmd, xy);
|
||||
for (int k = 0; k < 2 * n; k++) xy[k] *= s_ui_scale;
|
||||
tb_draw_poly_set(&scaled, xy, n);
|
||||
} else if (cmd->kind != TB_DRAW_TEXT) scaled.param *= s_ui_scale; /* no texto e a fonte */
|
||||
scaled.font_size *= s_ui_scale;
|
||||
cmd = &scaled;
|
||||
}
|
||||
switch (cmd->kind) {
|
||||
@@ -348,6 +401,14 @@ static void sdl2_execute(SDL_Renderer* ren,
|
||||
aa_line(ren, rgba_of(cmd), cmd->x, cmd->y, cmd->w, cmd->h, cmd->param);
|
||||
break;
|
||||
|
||||
case TB_DRAW_FILL_POLY: {
|
||||
float xy[2 * TB_POLY_MAX], px[TB_POLY_MAX], py[TB_POLY_MAX];
|
||||
int n = tb_draw_poly_get(cmd, xy);
|
||||
for (int k = 0; k < n; k++) { px[k] = xy[2*k]; py[k] = xy[2*k+1]; }
|
||||
if (n >= 3) aa_fill_poly(ren, rgba_of(cmd), px, py, n);
|
||||
break;
|
||||
}
|
||||
|
||||
case TB_DRAW_STROKE_RECT: {
|
||||
/* Quatro faixas sem sobreposição, espessura para dentro */
|
||||
Rgba c = rgba_of(cmd);
|
||||
@@ -420,7 +481,7 @@ static void sdl2_execute(SDL_Renderer* ren,
|
||||
|
||||
case TB_DRAW_TEXT:
|
||||
if (cmd->text[0]) {
|
||||
TTF_Font* font = get_font((int)(cmd->font_size + 0.5f));
|
||||
TTF_Font* font = get_font((int)(cmd->font_size + 0.5f), (int)cmd->param);
|
||||
if (font) {
|
||||
SDL_Color col = {
|
||||
(Uint8)(cmd->r*255.f), (Uint8)(cmd->g*255.f),
|
||||
@@ -429,6 +490,8 @@ static void sdl2_execute(SDL_Renderer* ren,
|
||||
SDL_Surface* surf = TTF_RenderUTF8_Blended(font, cmd->text, col);
|
||||
if (surf) {
|
||||
SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, surf);
|
||||
if (tex && cmd->a < 1.f) /* o Blended nao usa o alfa da cor */
|
||||
SDL_SetTextureAlphaMod(tex, (Uint8)(fmaxf(0.f, cmd->a) * 255.f + 0.5f));
|
||||
if (tex) {
|
||||
/* cmd->x,cmd->y é baseline-left; converte para o
|
||||
topo do retângulo usando o ascent real da fonte. */
|
||||
@@ -456,12 +519,104 @@ typedef struct SdlWin {
|
||||
Uint32 id;
|
||||
TinyBlocks_GfxInput in;
|
||||
int pos_fresh; /* posicao do mouse veio de um evento neste quadro */
|
||||
unsigned long xwin; /* janela X11 (0 fora do X11) */
|
||||
float pinch_acc; /* pinca do touchpad acumulada (fator; 0 = nenhuma) */
|
||||
float pinch_last; /* escala do gesto no evento anterior */
|
||||
struct SdlWin* next;
|
||||
} SdlWin;
|
||||
|
||||
static SdlWin* s_wins = NULL;
|
||||
static bool s_be_inited = false;
|
||||
|
||||
/* ===
|
||||
* Pinca do touchpad no X11: o SDL2 nao repassa os gestos do XInput 2.4, entao
|
||||
* a janela os pede (XISelectEvents) e um observador de eventos le o
|
||||
* SDL_SYSWMEVENT enquanto o cookie ainda tem os dados. libXi/libX11 vem por
|
||||
* dlopen (o SDL ja os carregou); sem eles, ou fora do X11, nada muda.
|
||||
* === */
|
||||
#if defined(__linux__) && !defined(__ANDROID__) && defined(__has_include)
|
||||
#if __has_include(<X11/extensions/XInput2.h>)
|
||||
#define TB_XI_GESTURES 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TB_XI_GESTURES
|
||||
#include <dlfcn.h>
|
||||
#include <SDL2/SDL_syswm.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/XInput2.h>
|
||||
|
||||
static int s_xi_state = 0; /* 0 = nao tentado, 1 = ok, -1 = indisponivel */
|
||||
static int s_xi_opcode = 0;
|
||||
static int (*p_XISelectEvents)(Display*, Window, XIEventMask*, int);
|
||||
|
||||
static int SDLCALL xi_watch(void* user, SDL_Event* e) {
|
||||
(void)user;
|
||||
if (e->type != SDL_SYSWMEVENT || !e->syswm.msg || e->syswm.msg->subsystem != SDL_SYSWM_X11) return 1;
|
||||
XGenericEventCookie* ck = &e->syswm.msg->msg.x11.event.xcookie;
|
||||
if (ck->type != GenericEvent || ck->extension != s_xi_opcode || !ck->data) return 1;
|
||||
if (ck->evtype < XI_GesturePinchBegin || ck->evtype > XI_GesturePinchEnd) return 1;
|
||||
const XIGesturePinchEvent* g = (const XIGesturePinchEvent*)ck->data;
|
||||
for (SdlWin* w = s_wins; w; w = w->next) {
|
||||
if (w->xwin != (unsigned long)g->event) continue;
|
||||
if (ck->evtype == XI_GesturePinchBegin) { w->pinch_last = 1.f; break; }
|
||||
float sc = (float)g->scale;
|
||||
if (sc > 0.f && w->pinch_last > 0.f) {
|
||||
w->pinch_acc = (w->pinch_acc > 0.f ? w->pinch_acc : 1.f) * (sc / w->pinch_last);
|
||||
w->pinch_last = sc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* dlsym -> ponteiro de funcao sem cast fora do padrao */
|
||||
static void sym_fn(void* dst, void* lib, const char* name) {
|
||||
void* p = dlsym(lib, name);
|
||||
memcpy(dst, &p, sizeof(p));
|
||||
}
|
||||
|
||||
static bool xi_init(Display* dpy) {
|
||||
if (s_xi_state) return s_xi_state > 0;
|
||||
s_xi_state = -1;
|
||||
void* xi = dlopen("libXi.so.6", RTLD_NOW | RTLD_LOCAL);
|
||||
void* x11 = dlopen("libX11.so.6", RTLD_NOW | RTLD_LOCAL);
|
||||
if (!xi || !x11) return false;
|
||||
Bool (*q_ext)(Display*, const char*, int*, int*, int*);
|
||||
Status (*q_ver)(Display*, int*, int*);
|
||||
sym_fn(&q_ext, x11, "XQueryExtension");
|
||||
sym_fn(&q_ver, xi, "XIQueryVersion");
|
||||
sym_fn(&p_XISelectEvents, xi, "XISelectEvents");
|
||||
int ev, err, major = 2, minor = 4;
|
||||
if (!q_ext || !q_ver || !p_XISelectEvents) return false;
|
||||
if (!q_ext(dpy, "XInputExtension", &s_xi_opcode, &ev, &err)) return false;
|
||||
if (q_ver(dpy, &major, &minor) != Success || major < 2 || (major == 2 && minor < 4)) return false;
|
||||
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
|
||||
SDL_AddEventWatch(xi_watch, NULL);
|
||||
s_xi_state = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Pede os gestos de pinca na janela. A mascara substitui a que o SDL pos
|
||||
(toque), entao os eventos de toque vao junto. */
|
||||
static void xi_select(SdlWin* sw) {
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
if (!SDL_GetWindowWMInfo(sw->win, &info) || info.subsystem != SDL_SYSWM_X11) return;
|
||||
Display* dpy = info.info.x11.display;
|
||||
if (!xi_init(dpy)) return;
|
||||
unsigned char bits[XIMaskLen(XI_GesturePinchEnd)] = {0};
|
||||
XISetMask(bits, XI_TouchBegin); XISetMask(bits, XI_TouchUpdate); XISetMask(bits, XI_TouchEnd);
|
||||
XISetMask(bits, XI_GesturePinchBegin); XISetMask(bits, XI_GesturePinchUpdate);
|
||||
XISetMask(bits, XI_GesturePinchEnd);
|
||||
XIEventMask m = { XIAllMasterDevices, (int)sizeof(bits), bits };
|
||||
p_XISelectEvents(dpy, info.info.x11.window, &m, 1);
|
||||
sw->xwin = (unsigned long)info.info.x11.window;
|
||||
}
|
||||
#else
|
||||
static void xi_select(SdlWin* sw) { (void)sw; }
|
||||
#endif
|
||||
|
||||
static int map_key(SDL_Scancode sc) {
|
||||
if (sc >= SDL_SCANCODE_A && sc <= SDL_SCANCODE_Z) return TB_KEY_A + (sc - SDL_SCANCODE_A);
|
||||
if (sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_9) return TB_KEY_0 + 1 + (sc - SDL_SCANCODE_1);
|
||||
@@ -527,7 +682,10 @@ static bool be_init(void) {
|
||||
return false;
|
||||
}
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
SDL_StartTextInput();
|
||||
/* Com teclado na tela (celular) a entrada de texto so liga com um campo
|
||||
em foco (be_text_input); senao o teclado abriria ja na partida */
|
||||
if (SDL_HasScreenKeyboardSupport()) SDL_StopTextInput();
|
||||
else SDL_StartTextInput();
|
||||
ui_scale_begin();
|
||||
sensors_open();
|
||||
s_be_inited = true;
|
||||
@@ -578,6 +736,7 @@ static void* be_window_open(const char* title, int w, int h) {
|
||||
sw->in.win_w = w; sw->in.win_h = h;
|
||||
sw->next = s_wins;
|
||||
s_wins = sw;
|
||||
xi_select(sw);
|
||||
return sw;
|
||||
}
|
||||
|
||||
@@ -601,6 +760,10 @@ static bool be_apply(SDL_Event* ev) {
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
if ((w = win_by_id(ev->motion.windowID))) {
|
||||
/* depois de apertar/soltar neste quadro, o movimento fica para o
|
||||
proximo: o editor precisa ver onde o dedo apertou e onde soltou
|
||||
(um deslize rapido, como a roda no emulador, cabe num quadro) */
|
||||
if (w->in.l_down || w->in.l_up) return false;
|
||||
w->in.mouse_x = (float)ev->motion.x / S;
|
||||
w->in.mouse_y = (float)ev->motion.y / S;
|
||||
w->pos_fresh = 1;
|
||||
@@ -613,8 +776,9 @@ static bool be_apply(SDL_Event* ev) {
|
||||
w->in.mouse_x = (float)ev->button.x / S;
|
||||
w->in.mouse_y = (float)ev->button.y / S;
|
||||
w->pos_fresh = 1;
|
||||
/* clique repetido no mesmo quadro: espera o proximo */
|
||||
if (ev->button.button == SDL_BUTTON_LEFT && (down ? w->in.l_down : w->in.l_up)) return false;
|
||||
/* uma mudanca do botao esquerdo por quadro: apertar e soltar no
|
||||
mesmo quadro viram dois (senao o deslize parece toque parado) */
|
||||
if (ev->button.button == SDL_BUTTON_LEFT && (w->in.l_down || w->in.l_up)) return false;
|
||||
if (ev->button.button == SDL_BUTTON_LEFT) { if (down) w->in.l_down = 1; else w->in.l_up = 1; }
|
||||
if (ev->button.button == SDL_BUTTON_RIGHT) { if (down) w->in.r_down = 1; else w->in.r_up = 1; }
|
||||
}
|
||||
@@ -676,6 +840,10 @@ static void be_poll(void) {
|
||||
while (!s_has_pending && SDL_PollEvent(&ev)) {
|
||||
if (!be_apply(&ev)) { s_pending = ev; s_has_pending = true; }
|
||||
}
|
||||
for (SdlWin* w = s_wins; w; w = w->next) { /* pinca do touchpad (xi_watch) */
|
||||
w->in.zoom = w->pinch_acc;
|
||||
w->pinch_acc = 0.f;
|
||||
}
|
||||
|
||||
/* Dispositivo: teclas seguradas (janela com o foco do teclado), dedos na
|
||||
tela e sensores (todas as janelas) */
|
||||
@@ -760,18 +928,64 @@ static char* be_clipboard_get(void) {
|
||||
return r;
|
||||
}
|
||||
|
||||
static void be_text_input(bool on, float x, float y, float w, float h) {
|
||||
if (!be_init()) return;
|
||||
if (on) {
|
||||
const float S = s_ui_scale > 0.f ? s_ui_scale : 1.f;
|
||||
SDL_Rect r = { (int)(x * S), (int)(y * S), (int)(w * S + 0.5f), (int)(h * S + 0.5f) };
|
||||
SDL_SetTextInputRect(&r);
|
||||
SDL_StartTextInput(); /* reabre o teclado se foi fechado */
|
||||
} else if (SDL_HasScreenKeyboardSupport()) {
|
||||
SDL_StopTextInput(); /* desktop: o texto segue ligado (atalhos) */
|
||||
}
|
||||
}
|
||||
|
||||
/* Captura para conferir o visual sem olhar a tela de ninguem:
|
||||
TINYBLOCKS_SHOT=arquivo.bmp salva a 1a janela depois de
|
||||
TINYBLOCKS_SHOT_FRAMES quadros (padrao 30) e sai. Com TINYBLOCKS_SHOT_COUNT=n
|
||||
(e o caminho com %d), salva n quadros, um a cada TINYBLOCKS_SHOT_STEP. */
|
||||
static void shot_check(SdlWin* w) {
|
||||
static int frames = 0;
|
||||
static bool done = false;
|
||||
const char* path = getenv("TINYBLOCKS_SHOT");
|
||||
if (done || !path || !path[0]) return;
|
||||
SdlWin* first = s_wins;
|
||||
while (first && first->next) first = first->next; /* a lista e LIFO */
|
||||
if (w != first) return;
|
||||
const char* fe = getenv("TINYBLOCKS_SHOT_FRAMES");
|
||||
const char* fc = getenv("TINYBLOCKS_SHOT_COUNT"); /* >1: sequencia (path com %d) */
|
||||
const char* fs = getenv("TINYBLOCKS_SHOT_STEP");
|
||||
int start = fe && atoi(fe) > 0 ? atoi(fe) : 30, count = fc && atoi(fc) > 1 ? atoi(fc) : 1;
|
||||
int step = fs && atoi(fs) > 0 ? atoi(fs) : 1;
|
||||
++frames;
|
||||
if (frames < start || (frames - start) % step) return;
|
||||
int idx = (frames - start) / step;
|
||||
char name[1200];
|
||||
if (count > 1) snprintf(name, sizeof(name), path, idx); else snprintf(name, sizeof(name), "%s", path);
|
||||
int pw = 0, ph = 0;
|
||||
SDL_GetRendererOutputSize(w->ren, &pw, &ph);
|
||||
SDL_Surface* s = SDL_CreateRGBSurfaceWithFormat(0, pw, ph, 32, SDL_PIXELFORMAT_ARGB8888);
|
||||
if (s && SDL_RenderReadPixels(w->ren, NULL, SDL_PIXELFORMAT_ARGB8888, s->pixels, s->pitch) == 0)
|
||||
SDL_SaveBMP(s, name);
|
||||
if (s) SDL_FreeSurface(s);
|
||||
if (idx + 1 < count) return;
|
||||
done = true;
|
||||
exit(0); /* so para conferir: sai em seguida */
|
||||
}
|
||||
|
||||
static void be_window_present(void* handle, const TinyBlocks_RenderableBlock* rb) {
|
||||
SdlWin* w = (SdlWin*)handle;
|
||||
SDL_SetRenderDrawColor(w->ren, 0, 0, 0, 255);
|
||||
SDL_RenderClear(w->ren);
|
||||
if (rb) sdl2_execute(w->ren, rb);
|
||||
shot_check(w);
|
||||
SDL_RenderPresent(w->ren);
|
||||
}
|
||||
|
||||
static float be_measure_text(const char* text, float font_size) {
|
||||
if (!be_init()) return 0.f;
|
||||
const float S = s_ui_scale > 0.f ? s_ui_scale : 1.f;
|
||||
TTF_Font* font = get_font((int)(font_size * S + 0.5f));
|
||||
TTF_Font* font = get_font((int)(font_size * S + 0.5f), TB_FONT_REGULAR);
|
||||
int w = 0, h = 0;
|
||||
if (!font || TTF_SizeUTF8(font, text, &w, &h) != 0) return 0.f;
|
||||
return (float)w / S; /* largura em unidades logicas */
|
||||
@@ -805,6 +1019,7 @@ static const TinyBlocks_GraphicsBackend s_sdl2_backend = {
|
||||
.frame_wait = be_frame_wait,
|
||||
.clipboard_set = be_clipboard_set,
|
||||
.clipboard_get = be_clipboard_get,
|
||||
.text_input = be_text_input,
|
||||
};
|
||||
|
||||
const TinyBlocks_GraphicsBackend* tb_sdl2_graphics_backend(void) {
|
||||
|
||||
@@ -15,7 +15,8 @@ static void eval_outside(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
typedef struct { const char* name; const char* label; const char* defs; int nin; bool cmd; const char* doc; } Spec;
|
||||
|
||||
static const Spec s_specs[] = {
|
||||
{ "Shader.Pixel", "cor do pixel = %1", "", 1, true, "Muda a cor do pixel (uma cor, ou um número para cinza)" },
|
||||
{ "Shader.Pixel", "cor do pixel = %1", "", 1, true, "Muda a cor do pixel (uma cor, ou um número para cinza). Faz o shader ser de FRAGMENTO" },
|
||||
{ "Shader.Vertex", "mude a posição do vértice para x %1 y %2 z %3", "|0|0", 3, true, "A posição do vértice no espaço do objeto (a câmera e o mova/gire aplicam por cima). Faz o shader ser de VÉRTICE" },
|
||||
{ "Shader.PixelColor", "cor do pixel", "", 0, false, "A cor do pixel até aqui (começa com a cor do objeto já iluminada)" },
|
||||
{ "Shader.ObjectColor", "cor do objeto", "", 0, false, "A cor dada ao objeto (\"mude a cor de\"), sem luz" },
|
||||
{ "Shader.Light", "luz", "", 0, false, "Claridade do ponto (luz ambiente + sol), de 0 a 1" },
|
||||
@@ -26,6 +27,12 @@ static const Spec s_specs[] = {
|
||||
{ "Shader.NX", "x da normal", "", 0, false, "Para onde a superfície aponta (x, de -1 a 1)" },
|
||||
{ "Shader.NY", "y da normal", "", 0, false, "Para onde a superfície aponta (y: 1 = para cima)" },
|
||||
{ "Shader.NZ", "z da normal", "", 0, false, "Para onde a superfície aponta (z)" },
|
||||
{ "Shader.VX", "x do vértice", "", 0, false, "Posição x do vértice antes de mover o objeto (espaço do objeto)" },
|
||||
{ "Shader.VY", "y do vértice", "", 0, false, "Posição y do vértice antes de mover o objeto" },
|
||||
{ "Shader.VZ", "z do vértice", "", 0, false, "Posição z do vértice antes de mover o objeto" },
|
||||
{ "Shader.U", "u do uv", "", 0, false, "Coordenada de textura u do ponto (0 a 1)" },
|
||||
{ "Shader.V", "v do uv", "", 0, false, "Coordenada de textura v do ponto (0 a 1)" },
|
||||
{ "Shader.Texture", "textura do pixel", "", 0, false, "A cor da textura de albedo do material neste ponto (branco se o objeto não tem textura)" },
|
||||
{ "Shader.Rgb", "cor r %1 g %2 b %3", "1|0.5|0", 3, false, "Uma cor pelos canais, de 0 a 1" },
|
||||
{ "Shader.Color", "cor %1", "azul", 1, false, "Uma cor pelo nome (azul, dourado...) ou #rrggbb" },
|
||||
{ "Shader.Mix", "misture %1 com %2 por %3", "||0.5", 3, false, "Mistura duas cores (ou números): 0 = a primeira, 1 = a segunda" },
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
#version 450
|
||||
layout(location = 0) in vec3 v_col;
|
||||
layout(location = 0) in vec3 v_local;
|
||||
layout(location = 1) in vec3 v_nobj;
|
||||
layout(location = 2) in vec2 v_uv;
|
||||
layout(set = 0, binding = 0) uniform sampler2D u_albedo;
|
||||
layout(set = 0, binding = 1) uniform sampler2D u_normalmap;
|
||||
// Do quadro: fog.rgb = cor da nevoa, fog.w = inicio; p.x = fim, p.y = luz ambiente
|
||||
layout(set = 0, binding = 2) uniform Frame { vec4 fog; vec4 p; } fr;
|
||||
// color.rgb = cor do objeto, color.a = opacidade
|
||||
layout(push_constant) uniform PC { mat4 mvp; vec4 n0; vec4 n1; vec4 n2; vec4 color; } pc;
|
||||
layout(location = 0) out vec4 o_color;
|
||||
|
||||
void main() { o_color = vec4(min(v_col, vec3(1.0)), 1.0); }
|
||||
vec3 tb_fog(vec3 c) {
|
||||
if (fr.p.x <= fr.fog.w) return c;
|
||||
float t = clamp((1.0 / gl_FragCoord.w - fr.fog.w) / (fr.p.x - fr.fog.w), 0.0, 1.0);
|
||||
return mix(c, fr.fog.rgb, t);
|
||||
}
|
||||
|
||||
void main() {
|
||||
mat3 Nmat = mat3(pc.n0.xyz, pc.n1.xyz, pc.n2.xyz);
|
||||
vec3 No = normalize(v_nobj);
|
||||
vec3 dp1 = dFdx(v_local), dp2 = dFdy(v_local);
|
||||
vec2 duv1 = dFdx(v_uv), duv2 = dFdy(v_uv);
|
||||
// o dFdy do Vulkan aponta para baixo (viewport com altura negativa):
|
||||
// negar T e B deixa o frame igual ao do GL e do software
|
||||
vec3 T = -normalize(dp1 * duv2.y - dp2 * duv1.y);
|
||||
vec3 B = -normalize(dp2 * duv1.x - dp1 * duv2.x);
|
||||
vec3 nm = texture(u_normalmap, v_uv).xyz * 2.0 - 1.0;
|
||||
vec3 N = normalize(Nmat * normalize(mat3(T, B, No) * nm));
|
||||
vec3 L = vec3(pc.n0.w, pc.n1.w, pc.n2.w);
|
||||
float I = fr.p.y + (1.0 - fr.p.y) * max(dot(N, L), 0.0);
|
||||
o_color = vec4(tb_fog(min(pc.color.rgb * I * texture(u_albedo, v_uv).rgb, vec3(1.0))), pc.color.a);
|
||||
}
|
||||
@@ -1,20 +1,22 @@
|
||||
#version 450
|
||||
// Vertice da tinyblocks-vk: o mesmo calculo do GL e do software (lambert
|
||||
// por vertice). Push constants (128 bytes, o minimo garantido):
|
||||
// Vertice da tinyblocks-vk: passa posicao local, normal de objeto e uv para o
|
||||
// fragment, que faz a luz (e o relevo) por pixel. Push constants (128 bytes):
|
||||
// mvp; n0..n2 = colunas da matriz das normais, com a direcao da luz nos .w;
|
||||
// color.rgb = cor do objeto, color.a = luz ambiente.
|
||||
// color.rgb = cor do objeto, color.a = opacidade (a luz ambiente vem do
|
||||
// uniform do quadro, binding 2).
|
||||
layout(location = 0) in vec3 a_pos;
|
||||
layout(location = 1) in vec3 a_nrm;
|
||||
layout(location = 2) in vec2 a_uv;
|
||||
layout(push_constant) uniform PC { mat4 mvp; vec4 n0; vec4 n1; vec4 n2; vec4 color; } pc;
|
||||
layout(location = 0) out vec3 v_col;
|
||||
layout(location = 0) out vec3 v_local;
|
||||
layout(location = 1) out vec3 v_nobj;
|
||||
layout(location = 2) out vec2 v_uv;
|
||||
|
||||
void main() {
|
||||
vec4 p = pc.mvp * vec4(a_pos, 1.0);
|
||||
p.z = (p.z + p.w) * 0.5; // z do GL (-1..1) para o do Vulkan (0..1)
|
||||
gl_Position = p;
|
||||
mat3 N = mat3(pc.n0.xyz, pc.n1.xyz, pc.n2.xyz);
|
||||
vec3 L = vec3(pc.n0.w, pc.n1.w, pc.n2.w);
|
||||
vec3 n = normalize(N * a_nrm);
|
||||
float I = pc.color.a + (1.0 - pc.color.a) * max(dot(n, L), 0.0);
|
||||
v_col = pc.color.rgb * I;
|
||||
v_local = a_pos;
|
||||
v_nobj = a_nrm;
|
||||
v_uv = a_uv;
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
#version 450
|
||||
// Vertice dos objetos com shader feito com blocos: passa o ponto e a normal
|
||||
// no mundo para o fragment (que chama tb_shade). Push constants (160 bytes):
|
||||
// mvp; model; color.rgb = cor do objeto, color.a = luz ambiente;
|
||||
// mvp; model; color.rgb = cor do objeto, color.a = opacidade;
|
||||
// light.xyz = direcao da luz, light.w = tempo.
|
||||
layout(location = 0) in vec3 a_pos;
|
||||
layout(location = 1) in vec3 a_nrm;
|
||||
layout(location = 2) in vec2 a_uv;
|
||||
layout(push_constant) uniform PC { mat4 mvp; mat4 model; vec4 color; vec4 light; } pc;
|
||||
layout(location = 0) out vec3 v_pos;
|
||||
layout(location = 1) out vec3 v_nrm;
|
||||
layout(location = 2) out vec3 v_local;
|
||||
layout(location = 3) out vec2 v_uv;
|
||||
layout(location = 4) out vec3 v_nobj;
|
||||
|
||||
void main() {
|
||||
vec4 p = pc.mvp * vec4(a_pos, 1.0);
|
||||
@@ -15,4 +19,7 @@ void main() {
|
||||
gl_Position = p;
|
||||
v_pos = (pc.model * vec4(a_pos, 1.0)).xyz;
|
||||
v_nrm = transpose(inverse(mat3(pc.model))) * a_nrm;
|
||||
v_local = a_pos;
|
||||
v_uv = a_uv;
|
||||
v_nobj = a_nrm;
|
||||
}
|
||||
@@ -17,11 +17,14 @@
|
||||
#include "tb_vk_shaders.h"
|
||||
|
||||
typedef struct { VkBuffer buf; VkDeviceMemory mem; void* map; VkDeviceSize size; } Buf;
|
||||
typedef struct { Buf vb, ib; int icount; } GpuMesh;
|
||||
typedef struct { Buf vb, ib; int icount; unsigned version; } GpuMesh;
|
||||
|
||||
/* Pipeline de um shader feito com blocos: cache pelo id (id % 64) */
|
||||
typedef struct { VkPipeline pipe; int id; } GpuShader;
|
||||
|
||||
/* Textura na GPU (cache pelo id) */
|
||||
typedef struct { VkImage img; VkDeviceMemory mem; VkImageView view; int id; unsigned version; } GpuTex;
|
||||
|
||||
/* -- libshaderc (GLSL -> SPIR-V), carregada por dlopen -------------------- */
|
||||
/* So as funcoes da API C usadas aqui (estavel; nao precisa do header) */
|
||||
typedef void* (*ShcInit)(void);
|
||||
@@ -61,27 +64,80 @@ static const char* FS_HEAD =
|
||||
"#version 450\n"
|
||||
"layout(location = 0) in vec3 v_pos;\n"
|
||||
"layout(location = 1) in vec3 v_nrm;\n"
|
||||
"layout(location = 2) in vec3 v_local;\n"
|
||||
"layout(location = 3) in vec2 v_uv;\n"
|
||||
"layout(location = 4) in vec3 v_nobj;\n"
|
||||
"layout(set = 0, binding = 0) uniform sampler2D u_albedo;\n"
|
||||
"layout(set = 0, binding = 1) uniform sampler2D u_normalmap;\n"
|
||||
"layout(set = 0, binding = 2) uniform Frame { vec4 fog; vec4 p; } fr;\n"
|
||||
"layout(push_constant) uniform PC { mat4 mvp; mat4 model; vec4 color; vec4 light; } pc;\n"
|
||||
"layout(location = 0) out vec4 o_color;\n";
|
||||
"layout(location = 0) out vec4 o_color;\n"
|
||||
"vec3 tb_fog(vec3 c) {\n"
|
||||
" if (fr.p.x <= fr.fog.w) return c;\n"
|
||||
" float t = clamp((1.0 / gl_FragCoord.w - fr.fog.w) / (fr.p.x - fr.fog.w), 0.0, 1.0);\n"
|
||||
" return mix(c, fr.fog.rgb, t);\n"
|
||||
"}\n";
|
||||
static const char* FS_MAIN =
|
||||
"void main() {\n"
|
||||
" vec3 N = normalize(v_nrm);\n"
|
||||
" float light = pc.color.a + (1.0 - pc.color.a) * max(dot(N, pc.light.xyz), 0.0);\n"
|
||||
" o_color = vec4(tb_shade(v_pos, N, pc.color.rgb, light, pc.light.w), 1.0);\n"
|
||||
" mat3 Nmat = transpose(inverse(mat3(pc.model)));\n"
|
||||
" vec3 No = normalize(v_nobj);\n"
|
||||
" vec3 dp1 = dFdx(v_local), dp2 = dFdy(v_local);\n"
|
||||
" vec2 duv1 = dFdx(v_uv), duv2 = dFdy(v_uv);\n"
|
||||
" vec3 T = -normalize(dp1 * duv2.y - dp2 * duv1.y);\n"
|
||||
" vec3 B = -normalize(dp2 * duv1.x - dp1 * duv2.x);\n"
|
||||
" vec3 nm = texture(u_normalmap, v_uv).xyz * 2.0 - 1.0;\n"
|
||||
" vec3 N = normalize(Nmat * normalize(mat3(T, B, No) * nm));\n"
|
||||
" float light = fr.p.y + (1.0 - fr.p.y) * max(dot(N, pc.light.xyz), 0.0);\n"
|
||||
" vec3 tex = texture(u_albedo, v_uv).rgb;\n"
|
||||
" o_color = vec4(tb_fog(min(tb_shade(v_pos, N, v_local, v_uv, pc.color.rgb, tex, light, pc.light.w), vec3(1.0))), pc.color.a);\n"
|
||||
"}\n";
|
||||
|
||||
/* Tb3dRenderer.compile: o binario do shader para o Vulkan e o SPIR-V do
|
||||
fragment inteiro (a interface com o vertice fixo esta em FS_HEAD) */
|
||||
static uint32_t* spirv_fragment(const char* glsl, size_t* words, char* err, size_t cap) {
|
||||
/* Estagio de VERTICE: o VS chama tb_vert e sai a interface que o fragmento
|
||||
espera (posicao no mundo, normal, vertice local e uv). */
|
||||
static const char* VS_VERT_HEAD =
|
||||
"#version 450\n"
|
||||
"layout(location = 0) in vec3 a_pos;\n"
|
||||
"layout(location = 1) in vec3 a_nrm;\n"
|
||||
"layout(location = 2) in vec2 a_uv;\n"
|
||||
"layout(push_constant) uniform PC { mat4 mvp; mat4 model; vec4 color; vec4 light; } pc;\n"
|
||||
"layout(set = 0, binding = 2) uniform Frame { vec4 fog; vec4 p; } fr;\n"
|
||||
"layout(location = 0) out vec3 v_pos;\n"
|
||||
"layout(location = 1) out vec3 v_nrm;\n"
|
||||
"layout(location = 2) out vec3 v_local;\n"
|
||||
"layout(location = 3) out vec2 v_uv;\n"
|
||||
"layout(location = 4) out vec3 v_nobj;\n";
|
||||
static const char* VS_VERT_MAIN =
|
||||
"void main() {\n"
|
||||
" vec3 n = normalize(transpose(inverse(mat3(pc.model))) * a_nrm);\n"
|
||||
" float light = fr.p.y + (1.0 - fr.p.y) * max(dot(n, pc.light.xyz), 0.0);\n"
|
||||
" vec3 P = tb_vert(a_pos, a_nrm, a_pos, a_uv, pc.color.rgb, vec3(1.0), light, pc.light.w);\n"
|
||||
" vec4 p = pc.mvp * vec4(P, 1.0);\n"
|
||||
" p.z = (p.z + p.w) * 0.5;\n"
|
||||
" gl_Position = p;\n"
|
||||
" v_pos = (pc.model * vec4(P, 1.0)).xyz;\n"
|
||||
" v_nrm = transpose(inverse(mat3(pc.model))) * a_nrm;\n"
|
||||
" v_local = P;\n"
|
||||
" v_uv = a_uv;\n"
|
||||
" v_nobj = a_nrm;\n"
|
||||
"}\n";
|
||||
/* Fragmento padrao de quem so tem shader de vertice (cor do objeto com luz) */
|
||||
static const char* DEFAULT_FRAG =
|
||||
"vec3 tb_shade(vec3 P, vec3 N, vec3 L, vec2 UV, vec3 base, vec3 tex, float light, float time) { return base * light; }\n";
|
||||
|
||||
/* Monta o fonte completo de um estagio (o corpo GLSL vem dos blocos) */
|
||||
static char* wrap(const char* head, const char* body, const char* tail, const char* fallback) {
|
||||
const char* b = body ? body : fallback;
|
||||
size_t n = strlen(head) + strlen(b) + strlen(tail) + 1;
|
||||
char* s = malloc(n);
|
||||
if (s) snprintf(s, n, "%s%s%s", head, b, tail);
|
||||
return s;
|
||||
}
|
||||
|
||||
static uint32_t* spirv_stage(const char* src, int stage, size_t* words, char* err, size_t cap) {
|
||||
*words = 0;
|
||||
if (err && cap) err[0] = 0;
|
||||
if (!shaderc_load()) { snprintf(err, cap, "sem a libshaderc: shaders feitos com blocos não rodam no Vulkan"); return NULL; }
|
||||
size_t n = strlen(FS_HEAD) + strlen(glsl) + strlen(FS_MAIN) + 1;
|
||||
char* src = malloc(n);
|
||||
if (!src) return NULL;
|
||||
snprintf(src, n, "%s%s%s", FS_HEAD, glsl, FS_MAIN);
|
||||
void* res = SC.compile(SC.compiler, src, strlen(src), 1 /* fragment */, "shader.frag", "main", NULL);
|
||||
free(src);
|
||||
void* res = SC.compile(SC.compiler, src, strlen(src), stage, stage == 0 ? "shader.vert" : "shader.frag", "main", NULL);
|
||||
if (!res || SC.status(res) != 0) {
|
||||
snprintf(err, cap, "shaderc: %.200s", res ? SC.error(res) : "falhou");
|
||||
if (res) SC.release_result(res);
|
||||
@@ -94,10 +150,27 @@ static uint32_t* spirv_fragment(const char* glsl, size_t* words, char* err, size
|
||||
return spv;
|
||||
}
|
||||
|
||||
/* Tb3dRenderer.compile: o binario do shader para o Vulkan e o SPIR-V do
|
||||
estagio inteiro (vertice: junta com o fragmento padrao ao desenhar;
|
||||
fragmento: a interface com o vertice fixo esta em FS_HEAD) */
|
||||
static uint32_t* spirv_shader(const char* glsl, int stage, size_t* words, char* err, size_t cap) {
|
||||
if (stage == TB_3D_STAGE_VERTEX) {
|
||||
char* src = wrap(VS_VERT_HEAD, glsl, VS_VERT_MAIN, NULL);
|
||||
if (!src) { snprintf(err, cap, "sem memória"); return NULL; }
|
||||
uint32_t* spv = spirv_stage(src, 0, words, err, cap);
|
||||
free(src);
|
||||
return spv;
|
||||
}
|
||||
char* src = wrap(FS_HEAD, glsl, FS_MAIN, NULL);
|
||||
if (!src) { snprintf(err, cap, "sem memória"); return NULL; }
|
||||
uint32_t* spv = spirv_stage(src, 1, words, err, cap);
|
||||
free(src);
|
||||
return spv;
|
||||
}
|
||||
|
||||
static bool vk_compile(const char* glsl, void** data, size_t* size, char* err, size_t cap) {
|
||||
static bool vk_compile(const char* glsl, int stage, void** data, size_t* size, char* err, size_t cap) {
|
||||
size_t words = 0;
|
||||
uint32_t* spv = spirv_fragment(glsl, &words, err, cap);
|
||||
uint32_t* spv = spirv_shader(glsl, stage, &words, err, cap);
|
||||
*data = spv;
|
||||
*size = words * 4;
|
||||
return spv != NULL;
|
||||
@@ -119,10 +192,20 @@ static struct {
|
||||
VkRenderPass pass;
|
||||
VkPipelineLayout layout;
|
||||
VkPipeline pipe;
|
||||
VkPipeline pipe_blend; /* o mesmo, para transparentes */
|
||||
Buf frame_ubo; /* nevoa e luz ambiente do quadro */
|
||||
VkPipelineLayout shd_layout; /* 160 bytes de push constants */
|
||||
VkShaderModule shd_vert;
|
||||
bool shd_ok; /* da para usar shaders feitos com blocos */
|
||||
GpuShader shd[64];
|
||||
/* texturas: layout com um sampler, pool e um descritor */
|
||||
VkDescriptorSetLayout desc_layout;
|
||||
VkDescriptorPool desc_pool;
|
||||
VkDescriptorSet desc_set;
|
||||
VkSampler sampler;
|
||||
GpuTex tex[128];
|
||||
GpuTex white; /* 1x1 branco: quem nao tem albedo */
|
||||
GpuTex flat; /* 1x1 (128,128,255): normal neutro */
|
||||
/* alvo (recriado quando muda o tamanho) */
|
||||
int w, h;
|
||||
VkImage color, depth;
|
||||
@@ -130,7 +213,7 @@ static struct {
|
||||
VkImageView color_view, depth_view;
|
||||
VkFramebuffer fb;
|
||||
Buf readback;
|
||||
GpuMesh mesh[32];
|
||||
GpuMesh mesh[256];
|
||||
} V;
|
||||
|
||||
#define CK(x, what) do { VkResult r_ = (x); if (r_ != VK_SUCCESS) { snprintf(V.err, sizeof(V.err), "%s (VkResult %d)", what, (int)r_); return false; } } while (0)
|
||||
@@ -221,15 +304,17 @@ static bool pick_device(void) {
|
||||
|
||||
/* Pipeline com os estados fixos da vk (vertice pos+normal, profundidade,
|
||||
viewport/scissor dinamicos) e os dois modulos dados */
|
||||
static VkResult build_pipe(VkShaderModule vs, VkShaderModule fs, VkPipelineLayout layout, VkPipeline* out) {
|
||||
/* blend: transparente (mistura a cor, mantem o alfa da imagem e nao grava o z) */
|
||||
static VkResult build_pipe(VkShaderModule vs, VkShaderModule fs, VkPipelineLayout layout, bool blend, VkPipeline* out) {
|
||||
VkPipelineShaderStageCreateInfo st[2] = {
|
||||
{ VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, NULL, 0, VK_SHADER_STAGE_VERTEX_BIT, vs, "main", NULL },
|
||||
{ VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, NULL, 0, VK_SHADER_STAGE_FRAGMENT_BIT, fs, "main", NULL },
|
||||
};
|
||||
VkVertexInputBindingDescription bind = { 0, 6 * sizeof(float), VK_VERTEX_INPUT_RATE_VERTEX };
|
||||
VkVertexInputAttributeDescription attr[2] = { { 0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0 },
|
||||
{ 1, 0, VK_FORMAT_R32G32B32_SFLOAT, 3 * sizeof(float) } };
|
||||
VkPipelineVertexInputStateCreateInfo vi = { VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, NULL, 0, 1, &bind, 2, attr };
|
||||
VkVertexInputBindingDescription bind = { 0, 8 * sizeof(float), VK_VERTEX_INPUT_RATE_VERTEX };
|
||||
VkVertexInputAttributeDescription attr[3] = { { 0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0 },
|
||||
{ 1, 0, VK_FORMAT_R32G32B32_SFLOAT, 3 * sizeof(float) },
|
||||
{ 2, 0, VK_FORMAT_R32G32_SFLOAT, 6 * sizeof(float) } };
|
||||
VkPipelineVertexInputStateCreateInfo vi = { VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, NULL, 0, 1, &bind, 3, attr };
|
||||
VkPipelineInputAssemblyStateCreateInfo ia = { VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, NULL, 0,
|
||||
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, VK_FALSE };
|
||||
VkPipelineViewportStateCreateInfo vp = { VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, NULL, 0, 1, NULL, 1, NULL };
|
||||
@@ -238,8 +323,11 @@ static VkResult build_pipe(VkShaderModule vs, VkShaderModule fs, VkPipelineLayou
|
||||
VkPipelineMultisampleStateCreateInfo ms = { VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, NULL, 0,
|
||||
VK_SAMPLE_COUNT_1_BIT, VK_FALSE, 0, NULL, VK_FALSE, VK_FALSE };
|
||||
VkPipelineDepthStencilStateCreateInfo ds = { VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, NULL, 0,
|
||||
VK_TRUE, VK_TRUE, VK_COMPARE_OP_LESS, VK_FALSE, VK_FALSE, {0}, {0}, 0, 1 };
|
||||
VK_TRUE, blend ? VK_FALSE : VK_TRUE, VK_COMPARE_OP_LESS, VK_FALSE, VK_FALSE, {0}, {0}, 0, 1 };
|
||||
VkPipelineColorBlendAttachmentState cba = { VK_FALSE, 0, 0, 0, 0, 0, 0, 0xf };
|
||||
if (blend) cba = (VkPipelineColorBlendAttachmentState){ VK_TRUE,
|
||||
VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, VK_BLEND_OP_ADD,
|
||||
VK_BLEND_FACTOR_ZERO, VK_BLEND_FACTOR_ONE, VK_BLEND_OP_ADD, 0xf };
|
||||
VkPipelineColorBlendStateCreateInfo cb = { VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, NULL, 0,
|
||||
VK_FALSE, 0, 1, &cba, {0} };
|
||||
VkDynamicState dyn_s[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
|
||||
@@ -249,6 +337,74 @@ static VkResult build_pipe(VkShaderModule vs, VkShaderModule fs, VkPipelineLayou
|
||||
return vkCreateGraphicsPipelines(V.dev, VK_NULL_HANDLE, 1, &gp, NULL, out);
|
||||
}
|
||||
|
||||
/* Cria a imagem (com memoria) e a view, ja em SHADER_READ_ONLY, subindo os
|
||||
pixels por um buffer temporario (um comando proprio, antes do desenho). */
|
||||
static bool tex_create(const uint8_t* rgba, int w, int h, GpuTex* g) {
|
||||
VkImageCreateInfo ci = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, NULL, 0, VK_IMAGE_TYPE_2D,
|
||||
VK_FORMAT_R8G8B8A8_UNORM, { (uint32_t)w, (uint32_t)h, 1 }, 1, 1, VK_SAMPLE_COUNT_1_BIT,
|
||||
VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VK_SHARING_MODE_EXCLUSIVE, 0, NULL, VK_IMAGE_LAYOUT_UNDEFINED };
|
||||
if (vkCreateImage(V.dev, &ci, NULL, &g->img) != VK_SUCCESS) return false;
|
||||
VkMemoryRequirements req;
|
||||
vkGetImageMemoryRequirements(V.dev, g->img, &req);
|
||||
uint32_t t;
|
||||
if (!mem_type(req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &t)) return false;
|
||||
VkMemoryAllocateInfo ai = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, NULL, req.size, t };
|
||||
if (vkAllocateMemory(V.dev, &ai, NULL, &g->mem) != VK_SUCCESS) return false;
|
||||
if (vkBindImageMemory(V.dev, g->img, g->mem, 0) != VK_SUCCESS) return false;
|
||||
Buf st = {0};
|
||||
if (!buf_new(&st, (VkDeviceSize)w * h * 4, VK_BUFFER_USAGE_TRANSFER_SRC_BIT)) return false;
|
||||
memcpy(st.map, rgba, (size_t)w * h * 4);
|
||||
VkCommandBuffer cmd = VK_NULL_HANDLE;
|
||||
VkCommandBufferAllocateInfo cb = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, NULL, V.pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
|
||||
if (vkAllocateCommandBuffers(V.dev, &cb, &cmd) != VK_SUCCESS) { buf_free(&st); return false; }
|
||||
VkCommandBufferBeginInfo bi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, NULL, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, NULL };
|
||||
vkBeginCommandBuffer(cmd, &bi);
|
||||
VkImageMemoryBarrier b1 = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, NULL, 0, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED,
|
||||
g->img, { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
|
||||
vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &b1);
|
||||
VkBufferImageCopy cp = { 0, 0, 0, { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }, {0,0,0}, { (uint32_t)w, (uint32_t)h, 1 } };
|
||||
vkCmdCopyBufferToImage(cmd, st.buf, g->img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cp);
|
||||
VkImageMemoryBarrier b2 = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, NULL, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED,
|
||||
g->img, { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
|
||||
vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, &b2);
|
||||
vkEndCommandBuffer(cmd);
|
||||
VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, NULL, 0, NULL, NULL, 1, &cmd, 0, NULL };
|
||||
vkResetFences(V.dev, 1, &V.fence);
|
||||
vkQueueSubmit(V.queue, 1, &si, V.fence);
|
||||
vkWaitForFences(V.dev, 1, &V.fence, VK_TRUE, 5000000000ull);
|
||||
vkFreeCommandBuffers(V.dev, V.pool, 1, &cmd);
|
||||
buf_free(&st);
|
||||
VkImageViewCreateInfo vi = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, NULL, 0, g->img,
|
||||
VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM,
|
||||
{ VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY },
|
||||
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
|
||||
return vkCreateImageView(V.dev, &vi, NULL, &g->view) == VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void tex_destroy(GpuTex* g) {
|
||||
if (!g->img && !g->view) return;
|
||||
vkDeviceWaitIdle(V.dev);
|
||||
if (g->view) vkDestroyImageView(V.dev, g->view, NULL);
|
||||
if (g->img) vkDestroyImage(V.dev, g->img, NULL);
|
||||
if (g->mem) vkFreeMemory(V.dev, g->mem, NULL);
|
||||
memset(g, 0, sizeof(*g));
|
||||
}
|
||||
|
||||
/* A view da textura do objeto (branco se nao tem), subindo para a GPU se mudou */
|
||||
static VkImageView gpu_tex(const Tb3dTexture* t) {
|
||||
if (!t || !t->rgba || t->id <= 0 || t->id >= 128) return V.white.view;
|
||||
GpuTex* g = &V.tex[t->id];
|
||||
if (g->view && g->version == t->version) return g->view;
|
||||
tex_destroy(g);
|
||||
if (!tex_create(t->rgba, t->width, t->height, g)) { memset(g, 0, sizeof(*g)); return V.white.view; }
|
||||
g->id = t->id;
|
||||
g->version = t->version;
|
||||
return g->view;
|
||||
}
|
||||
|
||||
static bool make_pipeline(void) {
|
||||
VkAttachmentDescription att[2] = {
|
||||
{ 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE,
|
||||
@@ -268,8 +424,29 @@ static bool make_pipeline(void) {
|
||||
VkRenderPassCreateInfo rp = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, NULL, 0, 2, att, 1, &sub, 1, &dep };
|
||||
CK(vkCreateRenderPass(V.dev, &rp, NULL, &V.pass), "vkCreateRenderPass");
|
||||
|
||||
VkPushConstantRange pcr = { VK_SHADER_STAGE_VERTEX_BIT, 0, 128 };
|
||||
VkPipelineLayoutCreateInfo pl = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, NULL, 0, 0, NULL, 1, &pcr };
|
||||
VkDescriptorSetLayoutBinding b[3] = {
|
||||
{ 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, NULL },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, NULL },
|
||||
{ 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, NULL } };
|
||||
VkDescriptorSetLayoutCreateInfo dl = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, NULL, 0, 3, b };
|
||||
CK(vkCreateDescriptorSetLayout(V.dev, &dl, NULL, &V.desc_layout), "vkCreateDescriptorSetLayout");
|
||||
VkDescriptorPoolSize ps[2] = { { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2 }, { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1 } };
|
||||
VkDescriptorPoolCreateInfo dp = { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, NULL, 0, 1, 2, ps };
|
||||
CK(vkCreateDescriptorPool(V.dev, &dp, NULL, &V.desc_pool), "vkCreateDescriptorPool");
|
||||
VkDescriptorSetAllocateInfo da = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, NULL, V.desc_pool, 1, &V.desc_layout };
|
||||
CK(vkAllocateDescriptorSets(V.dev, &da, &V.desc_set), "vkAllocateDescriptorSets");
|
||||
if (!buf_new(&V.frame_ubo, 32, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) return false;
|
||||
VkDescriptorBufferInfo ubi = { V.frame_ubo.buf, 0, 32 };
|
||||
VkWriteDescriptorSet uw = { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, V.desc_set, 2, 0, 1,
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, NULL, &ubi, NULL };
|
||||
vkUpdateDescriptorSets(V.dev, 1, &uw, 0, NULL);
|
||||
VkSamplerCreateInfo sc = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, NULL, 0,
|
||||
VK_FILTER_LINEAR, VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||
VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
||||
0, VK_FALSE, 1.f, VK_FALSE, VK_COMPARE_OP_NEVER, 0, 0, VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE, VK_FALSE };
|
||||
CK(vkCreateSampler(V.dev, &sc, NULL, &V.sampler), "vkCreateSampler");
|
||||
VkPushConstantRange pcr = { VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 128 };
|
||||
VkPipelineLayoutCreateInfo pl = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, NULL, 0, 1, &V.desc_layout, 1, &pcr };
|
||||
CK(vkCreatePipelineLayout(V.dev, &pl, NULL, &V.layout), "vkCreatePipelineLayout");
|
||||
|
||||
VkShaderModule vs, fs;
|
||||
@@ -277,7 +454,8 @@ static bool make_pipeline(void) {
|
||||
CK(vkCreateShaderModule(V.dev, &sm, NULL, &vs), "shader de vértice");
|
||||
sm.codeSize = sizeof(s_frag_spv); sm.pCode = s_frag_spv;
|
||||
CK(vkCreateShaderModule(V.dev, &sm, NULL, &fs), "shader de fragmento");
|
||||
VkResult r = build_pipe(vs, fs, V.layout, &V.pipe);
|
||||
VkResult r = build_pipe(vs, fs, V.layout, false, &V.pipe);
|
||||
if (r == VK_SUCCESS) r = build_pipe(vs, fs, V.layout, true, &V.pipe_blend);
|
||||
vkDestroyShaderModule(V.dev, vs, NULL);
|
||||
vkDestroyShaderModule(V.dev, fs, NULL);
|
||||
CK(r, "vkCreateGraphicsPipelines");
|
||||
@@ -287,11 +465,15 @@ static bool make_pipeline(void) {
|
||||
vkGetPhysicalDeviceProperties(V.phys, &props);
|
||||
if (props.limits.maxPushConstantsSize >= 160) {
|
||||
VkPushConstantRange r2 = { VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 160 };
|
||||
VkPipelineLayoutCreateInfo pl2 = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, NULL, 0, 0, NULL, 1, &r2 };
|
||||
VkPipelineLayoutCreateInfo pl2 = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, NULL, 0, 1, &V.desc_layout, 1, &r2 };
|
||||
VkShaderModuleCreateInfo sv = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, NULL, 0, sizeof(s_vert_shd_spv), s_vert_shd_spv };
|
||||
V.shd_ok = vkCreatePipelineLayout(V.dev, &pl2, NULL, &V.shd_layout) == VK_SUCCESS &&
|
||||
vkCreateShaderModule(V.dev, &sv, NULL, &V.shd_vert) == VK_SUCCESS;
|
||||
}
|
||||
static const uint8_t branco[4] = { 255, 255, 255, 255 };
|
||||
if (!tex_create(branco, 1, 1, &V.white)) snprintf(V.err, sizeof(V.err), "textura branca falhou");
|
||||
static const uint8_t plano[4] = { 128, 128, 255, 255 };
|
||||
if (!tex_create(plano, 1, 1, &V.flat)) snprintf(V.err, sizeof(V.err), "normal neutro falhou");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -372,17 +554,19 @@ static bool target(int w, int h) {
|
||||
}
|
||||
|
||||
static GpuMesh* gpu_mesh(const Tb3dMesh* m) {
|
||||
if (m->id <= 0 || m->id >= 32) return NULL;
|
||||
if (m->id <= 0 || m->id >= 256) return NULL;
|
||||
GpuMesh* g = &V.mesh[m->id];
|
||||
if (g->vb.buf) return g;
|
||||
if (!buf_new(&g->vb, (VkDeviceSize)m->vcount * 6 * sizeof(float), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) ||
|
||||
if (g->vb.buf && g->version == m->version) return g;
|
||||
if (g->vb.buf) { buf_free(&g->vb); buf_free(&g->ib); }
|
||||
if (!buf_new(&g->vb, (VkDeviceSize)m->vcount * 8 * sizeof(float), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) ||
|
||||
!buf_new(&g->ib, (VkDeviceSize)m->icount * sizeof(uint32_t), VK_BUFFER_USAGE_INDEX_BUFFER_BIT)) {
|
||||
buf_free(&g->vb); buf_free(&g->ib);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(g->vb.map, m->verts, (size_t)m->vcount * 6 * sizeof(float));
|
||||
memcpy(g->vb.map, m->verts, (size_t)m->vcount * 8 * sizeof(float));
|
||||
memcpy(g->ib.map, m->index, (size_t)m->icount * sizeof(uint32_t));
|
||||
g->icount = m->icount;
|
||||
g->version = m->version;
|
||||
return g;
|
||||
}
|
||||
|
||||
@@ -390,6 +574,7 @@ static GpuMesh* gpu_mesh(const Tb3dMesh* m) {
|
||||
static GpuShader* gpu_shader(const Tb3dShader* sh) {
|
||||
GpuShader* g = &V.shd[(unsigned)sh->id % 64u];
|
||||
if (g->pipe && g->id == sh->id) return g;
|
||||
bool vert = sh->stage == TB_3D_STAGE_VERTEX;
|
||||
/* o binario que veio no shader ("compile o shader"); sem ele, compila agora */
|
||||
const void* code = NULL;
|
||||
size_t size = 0;
|
||||
@@ -397,31 +582,71 @@ static GpuShader* gpu_shader(const Tb3dShader* sh) {
|
||||
for (int i = 0; i < sh->bin_n; i++)
|
||||
if (!strcmp(sh->bin[i].renderer, "vulkan")) { code = sh->bin[i].data; size = sh->bin[i].size; }
|
||||
if (!code) {
|
||||
if (!vk_compile(sh->glsl, &own, &size, V.err, sizeof(V.err))) return NULL;
|
||||
if (!vk_compile(sh->glsl, sh->stage, &own, &size, V.err, sizeof(V.err))) return NULL;
|
||||
code = own;
|
||||
}
|
||||
VkShaderModuleCreateInfo sm = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, NULL, 0, size, code };
|
||||
VkShaderModule fs;
|
||||
VkResult r = vkCreateShaderModule(V.dev, &sm, NULL, &fs);
|
||||
VkShaderModule mod;
|
||||
VkResult r = vkCreateShaderModule(V.dev, &sm, NULL, &mod);
|
||||
free(own);
|
||||
if (r != VK_SUCCESS) { snprintf(V.err, sizeof(V.err), "binário do shader recusado (%d)", (int)r); return NULL; }
|
||||
VkShaderModule vs, fs;
|
||||
if (vert) { /* vertice: junta com o fragmento padrao */
|
||||
vs = mod;
|
||||
void* def = NULL;
|
||||
size_t dsz = 0;
|
||||
if (!vk_compile(DEFAULT_FRAG, TB_3D_STAGE_FRAGMENT, &def, &dsz, V.err, sizeof(V.err))) {
|
||||
vkDestroyShaderModule(V.dev, vs, NULL);
|
||||
return NULL;
|
||||
}
|
||||
VkShaderModuleCreateInfo sf = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, NULL, 0, dsz, def };
|
||||
VkResult r2 = vkCreateShaderModule(V.dev, &sf, NULL, &fs);
|
||||
free(def);
|
||||
if (r2 != VK_SUCCESS) {
|
||||
vkDestroyShaderModule(V.dev, vs, NULL);
|
||||
snprintf(V.err, sizeof(V.err), "binário do fragmento padrão recusado (%d)", (int)r2);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
fs = mod;
|
||||
vs = V.shd_vert;
|
||||
}
|
||||
vkDeviceWaitIdle(V.dev);
|
||||
if (g->pipe) vkDestroyPipeline(V.dev, g->pipe, NULL);
|
||||
g->pipe = VK_NULL_HANDLE;
|
||||
r = build_pipe(V.shd_vert, fs, V.shd_layout, &g->pipe);
|
||||
vkDestroyShaderModule(V.dev, fs, NULL);
|
||||
r = build_pipe(vs, fs, V.shd_layout, false, &g->pipe);
|
||||
if (vert) vkDestroyShaderModule(V.dev, fs, NULL);
|
||||
vkDestroyShaderModule(V.dev, mod, NULL);
|
||||
if (r != VK_SUCCESS) { snprintf(V.err, sizeof(V.err), "pipeline do shader recusado (%d)", (int)r); return NULL; }
|
||||
g->id = sh->id;
|
||||
return g;
|
||||
}
|
||||
|
||||
static void bind_tex(VkCommandBuffer cmd, VkPipelineLayout layout, const Tb3dTexture* albedo, const Tb3dTexture* normal) {
|
||||
VkDescriptorImageInfo di[2] = {
|
||||
{ V.sampler, gpu_tex(albedo), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL },
|
||||
{ V.sampler, normal ? gpu_tex(normal) : V.flat.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL },
|
||||
};
|
||||
VkWriteDescriptorSet w[2] = {
|
||||
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, V.desc_set, 0, 0, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &di[0], NULL, NULL },
|
||||
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, NULL, V.desc_set, 1, 0, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &di[1], NULL, NULL },
|
||||
};
|
||||
vkUpdateDescriptorSets(V.dev, 2, w, 0, NULL);
|
||||
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, 1, &V.desc_set, 0, NULL);
|
||||
}
|
||||
|
||||
static bool vk_draw(const Tb3dFrame* f, uint8_t* out) {
|
||||
if (!target(f->width, f->height)) return false;
|
||||
/* as malhas antes de gravar os comandos */
|
||||
/* as malhas e texturas antes de gravar os comandos */
|
||||
for (int i = 0; i < f->draw_count; i++) {
|
||||
if (!gpu_mesh(f->draws[i].mesh)) return false;
|
||||
if (f->draws[i].shader && !gpu_shader(f->draws[i].shader)) return false; /* a 3d usa outro */
|
||||
gpu_tex(f->draws[i].albedo);
|
||||
if (f->draws[i].normaltex) gpu_tex(f->draws[i].normaltex);
|
||||
}
|
||||
float fu[8] = { f->fog_color[0], f->fog_color[1], f->fog_color[2], f->fog_start,
|
||||
f->fog_end, f->ambient, 0, 0 };
|
||||
memcpy(V.frame_ubo.map, fu, sizeof(fu)); /* a fila esta parada: pode escrever */
|
||||
CK(vkResetCommandBuffer(V.cmd, 0), "vkResetCommandBuffer");
|
||||
VkCommandBufferBeginInfo bi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, NULL, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, NULL };
|
||||
CK(vkBeginCommandBuffer(V.cmd, &bi), "vkBeginCommandBuffer");
|
||||
@@ -440,20 +665,22 @@ static bool vk_draw(const Tb3dFrame* f, uint8_t* out) {
|
||||
for (int i = 0; i < f->draw_count; i++) {
|
||||
const Tb3dDraw* d = &f->draws[i];
|
||||
GpuMesh* g = gpu_mesh(d->mesh);
|
||||
if (i == f->opaque_count) vkCmdBindPipeline(V.cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, V.pipe_blend);
|
||||
if (d->shader) { /* shader feito com blocos */
|
||||
float pc[40];
|
||||
memcpy(pc, d->mvp, sizeof(d->mvp));
|
||||
memcpy(pc + 16, d->model, sizeof(d->model));
|
||||
pc[32] = d->color[0]; pc[33] = d->color[1]; pc[34] = d->color[2]; pc[35] = f->ambient;
|
||||
pc[32] = d->color[0]; pc[33] = d->color[1]; pc[34] = d->color[2]; pc[35] = d->color[3];
|
||||
pc[36] = f->light_dir[0]; pc[37] = f->light_dir[1]; pc[38] = f->light_dir[2]; pc[39] = f->time;
|
||||
vkCmdBindPipeline(V.cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, V.shd[(unsigned)d->shader->id % 64u].pipe);
|
||||
bind_tex(V.cmd, V.shd_layout, d->albedo, d->normaltex);
|
||||
vkCmdPushConstants(V.cmd, V.shd_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
0, sizeof(pc), pc);
|
||||
VkDeviceSize off = 0;
|
||||
vkCmdBindVertexBuffers(V.cmd, 0, 1, &g->vb.buf, &off);
|
||||
vkCmdBindIndexBuffer(V.cmd, g->ib.buf, 0, VK_INDEX_TYPE_UINT32);
|
||||
vkCmdDrawIndexed(V.cmd, (uint32_t)g->icount, 1, 0, 0, 0);
|
||||
vkCmdBindPipeline(V.cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, V.pipe);
|
||||
vkCmdBindPipeline(V.cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, i >= f->opaque_count ? V.pipe_blend : V.pipe);
|
||||
continue;
|
||||
}
|
||||
float pc[32];
|
||||
@@ -464,8 +691,9 @@ static bool vk_draw(const Tb3dFrame* f, uint8_t* out) {
|
||||
pc[16 + c * 4 + 2] = d->normal[c * 3 + 2];
|
||||
pc[16 + c * 4 + 3] = f->light_dir[c];
|
||||
}
|
||||
pc[28] = d->color[0]; pc[29] = d->color[1]; pc[30] = d->color[2]; pc[31] = f->ambient;
|
||||
vkCmdPushConstants(V.cmd, V.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(pc), pc);
|
||||
pc[28] = d->color[0]; pc[29] = d->color[1]; pc[30] = d->color[2]; pc[31] = d->color[3];
|
||||
bind_tex(V.cmd, V.layout, d->albedo, d->normaltex);
|
||||
vkCmdPushConstants(V.cmd, V.layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(pc), pc);
|
||||
VkDeviceSize off = 0;
|
||||
vkCmdBindVertexBuffers(V.cmd, 0, 1, &g->vb.buf, &off);
|
||||
vkCmdBindIndexBuffer(V.cmd, g->ib.buf, 0, VK_INDEX_TYPE_UINT32);
|
||||
@@ -491,12 +719,20 @@ static bool vk_draw(const Tb3dFrame* f, uint8_t* out) {
|
||||
static void vk_cleanup(void) {
|
||||
if (V.dev) {
|
||||
vkDeviceWaitIdle(V.dev);
|
||||
for (int i = 0; i < 32; i++) { buf_free(&V.mesh[i].vb); buf_free(&V.mesh[i].ib); }
|
||||
for (int i = 0; i < 256; i++) { buf_free(&V.mesh[i].vb); buf_free(&V.mesh[i].ib); }
|
||||
target_free();
|
||||
for (int i = 0; i < 64; i++) if (V.shd[i].pipe) vkDestroyPipeline(V.dev, V.shd[i].pipe, NULL);
|
||||
for (int i = 0; i < 128; i++) tex_destroy(&V.tex[i]);
|
||||
tex_destroy(&V.white);
|
||||
tex_destroy(&V.flat);
|
||||
if (V.sampler) vkDestroySampler(V.dev, V.sampler, NULL);
|
||||
if (V.desc_pool) vkDestroyDescriptorPool(V.dev, V.desc_pool, NULL);
|
||||
if (V.desc_layout) vkDestroyDescriptorSetLayout(V.dev, V.desc_layout, NULL);
|
||||
if (V.shd_vert) vkDestroyShaderModule(V.dev, V.shd_vert, NULL);
|
||||
if (V.shd_layout) vkDestroyPipelineLayout(V.dev, V.shd_layout, NULL);
|
||||
if (V.pipe) vkDestroyPipeline(V.dev, V.pipe, NULL);
|
||||
if (V.pipe_blend) vkDestroyPipeline(V.dev, V.pipe_blend, NULL);
|
||||
buf_free(&V.frame_ubo);
|
||||
if (V.layout) vkDestroyPipelineLayout(V.dev, V.layout, NULL);
|
||||
if (V.pass) vkDestroyRenderPass(V.dev, V.pass, NULL);
|
||||
if (V.fence) vkDestroyFence(V.dev, V.fence, NULL);
|
||||
|
||||
@@ -3,37 +3,198 @@
|
||||
#define TB_VK_SHADERS_H
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint32_t s_vert_spv[528] = {
|
||||
0x07230203, 0x00010000, 0x000d000b, 0x00000077, 0x00000000, 0x00020011, 0x00000001, 0x0006000b,
|
||||
static const uint32_t s_vert_spv[341] = {
|
||||
0x07230203, 0x00010000, 0x000d000b, 0x00000041, 0x00000000, 0x00020011, 0x00000001, 0x0006000b,
|
||||
0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001,
|
||||
0x0009000f, 0x00000000, 0x00000004, 0x6e69616d, 0x00000000, 0x00000015, 0x0000002d, 0x0000005b,
|
||||
0x0000006d, 0x00040048, 0x0000000b, 0x00000000, 0x00000005, 0x00050048, 0x0000000b, 0x00000000,
|
||||
0x00000023, 0x00000000, 0x00050048, 0x0000000b, 0x00000000, 0x00000007, 0x00000010, 0x00050048,
|
||||
0x0000000b, 0x00000001, 0x00000023, 0x00000040, 0x00050048, 0x0000000b, 0x00000002, 0x00000023,
|
||||
0x00000050, 0x00050048, 0x0000000b, 0x00000003, 0x00000023, 0x00000060, 0x00050048, 0x0000000b,
|
||||
0x00000004, 0x00000023, 0x00000070, 0x00030047, 0x0000000b, 0x00000002, 0x00040047, 0x00000015,
|
||||
0x0000001e, 0x00000000, 0x00050048, 0x0000002b, 0x00000000, 0x0000000b, 0x00000000, 0x00050048,
|
||||
0x0000002b, 0x00000001, 0x0000000b, 0x00000001, 0x00050048, 0x0000002b, 0x00000002, 0x0000000b,
|
||||
0x00000003, 0x00050048, 0x0000002b, 0x00000003, 0x0000000b, 0x00000004, 0x00030047, 0x0000002b,
|
||||
0x00000002, 0x00040047, 0x0000005b, 0x0000001e, 0x00000001, 0x00040047, 0x0000006d, 0x0000001e,
|
||||
0x00000000, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00030016, 0x00000006,
|
||||
0x00000020, 0x00040017, 0x00000007, 0x00000006, 0x00000004, 0x00040018, 0x0000000a, 0x00000007,
|
||||
0x00000004, 0x0007001e, 0x0000000b, 0x0000000a, 0x00000007, 0x00000007, 0x00000007, 0x00000007,
|
||||
0x00040020, 0x0000000c, 0x00000009, 0x0000000b, 0x0004003b, 0x0000000c, 0x0000000d, 0x00000009,
|
||||
0x00040015, 0x0000000e, 0x00000020, 0x00000001, 0x0004002b, 0x0000000e, 0x0000000f, 0x00000000,
|
||||
0x00040020, 0x00000010, 0x00000009, 0x0000000a, 0x00040017, 0x00000013, 0x00000006, 0x00000003,
|
||||
0x00040020, 0x00000014, 0x00000001, 0x00000013, 0x0004003b, 0x00000014, 0x00000015, 0x00000001,
|
||||
0x0004002b, 0x00000006, 0x00000017, 0x3f800000, 0x00040015, 0x0000001d, 0x00000020, 0x00000000,
|
||||
0x0004002b, 0x0000001d, 0x00000022, 0x00000003, 0x0004002b, 0x00000006, 0x00000026, 0x3f000000,
|
||||
0x000c000f, 0x00000000, 0x00000004, 0x6e69616d, 0x00000000, 0x00000015, 0x0000002d, 0x00000032,
|
||||
0x00000034, 0x00000035, 0x00000039, 0x0000003b, 0x00040048, 0x0000000b, 0x00000000, 0x00000005,
|
||||
0x00050048, 0x0000000b, 0x00000000, 0x00000023, 0x00000000, 0x00050048, 0x0000000b, 0x00000000,
|
||||
0x00000007, 0x00000010, 0x00050048, 0x0000000b, 0x00000001, 0x00000023, 0x00000040, 0x00050048,
|
||||
0x0000000b, 0x00000002, 0x00000023, 0x00000050, 0x00050048, 0x0000000b, 0x00000003, 0x00000023,
|
||||
0x00000060, 0x00050048, 0x0000000b, 0x00000004, 0x00000023, 0x00000070, 0x00030047, 0x0000000b,
|
||||
0x00000002, 0x00040047, 0x00000015, 0x0000001e, 0x00000000, 0x00050048, 0x0000002b, 0x00000000,
|
||||
0x0000000b, 0x00000000, 0x00050048, 0x0000002b, 0x00000001, 0x0000000b, 0x00000001, 0x00050048,
|
||||
0x0000002b, 0x00000002, 0x0000000b, 0x00000003, 0x00050048, 0x0000002b, 0x00000003, 0x0000000b,
|
||||
0x00000004, 0x00030047, 0x0000002b, 0x00000002, 0x00040047, 0x00000032, 0x0000001e, 0x00000000,
|
||||
0x00040047, 0x00000034, 0x0000001e, 0x00000001, 0x00040047, 0x00000035, 0x0000001e, 0x00000001,
|
||||
0x00040047, 0x00000039, 0x0000001e, 0x00000002, 0x00040047, 0x0000003b, 0x0000001e, 0x00000002,
|
||||
0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00030016, 0x00000006, 0x00000020,
|
||||
0x00040017, 0x00000007, 0x00000006, 0x00000004, 0x00040018, 0x0000000a, 0x00000007, 0x00000004,
|
||||
0x0007001e, 0x0000000b, 0x0000000a, 0x00000007, 0x00000007, 0x00000007, 0x00000007, 0x00040020,
|
||||
0x0000000c, 0x00000009, 0x0000000b, 0x0004003b, 0x0000000c, 0x0000000d, 0x00000009, 0x00040015,
|
||||
0x0000000e, 0x00000020, 0x00000001, 0x0004002b, 0x0000000e, 0x0000000f, 0x00000000, 0x00040020,
|
||||
0x00000010, 0x00000009, 0x0000000a, 0x00040017, 0x00000013, 0x00000006, 0x00000003, 0x00040020,
|
||||
0x00000014, 0x00000001, 0x00000013, 0x0004003b, 0x00000014, 0x00000015, 0x00000001, 0x0004002b,
|
||||
0x00000006, 0x00000017, 0x3f800000, 0x00040015, 0x0000001d, 0x00000020, 0x00000000, 0x0004002b,
|
||||
0x00000006, 0x00000026, 0x3f000000, 0x0004002b, 0x0000001d, 0x00000029, 0x00000001, 0x0004001c,
|
||||
0x0000002a, 0x00000006, 0x00000029, 0x0006001e, 0x0000002b, 0x00000007, 0x00000006, 0x0000002a,
|
||||
0x0000002a, 0x00040020, 0x0000002c, 0x00000003, 0x0000002b, 0x0004003b, 0x0000002c, 0x0000002d,
|
||||
0x00000003, 0x00040020, 0x0000002f, 0x00000003, 0x00000007, 0x00040020, 0x00000031, 0x00000003,
|
||||
0x00000013, 0x0004003b, 0x00000031, 0x00000032, 0x00000003, 0x0004003b, 0x00000031, 0x00000034,
|
||||
0x00000003, 0x0004003b, 0x00000014, 0x00000035, 0x00000001, 0x00040017, 0x00000037, 0x00000006,
|
||||
0x00000002, 0x00040020, 0x00000038, 0x00000003, 0x00000037, 0x0004003b, 0x00000038, 0x00000039,
|
||||
0x00000003, 0x00040020, 0x0000003a, 0x00000001, 0x00000037, 0x0004003b, 0x0000003a, 0x0000003b,
|
||||
0x00000001, 0x00050036, 0x00000002, 0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005,
|
||||
0x00050041, 0x00000010, 0x00000011, 0x0000000d, 0x0000000f, 0x0004003d, 0x0000000a, 0x00000012,
|
||||
0x00000011, 0x0004003d, 0x00000013, 0x00000016, 0x00000015, 0x00050051, 0x00000006, 0x00000018,
|
||||
0x00000016, 0x00000000, 0x00050051, 0x00000006, 0x00000019, 0x00000016, 0x00000001, 0x00050051,
|
||||
0x00000006, 0x0000001a, 0x00000016, 0x00000002, 0x00070050, 0x00000007, 0x0000001b, 0x00000018,
|
||||
0x00000019, 0x0000001a, 0x00000017, 0x00050091, 0x00000007, 0x0000001c, 0x00000012, 0x0000001b,
|
||||
0x00050051, 0x00000006, 0x00000021, 0x0000001c, 0x00000002, 0x00050051, 0x00000006, 0x00000024,
|
||||
0x0000001c, 0x00000003, 0x00050081, 0x00000006, 0x00000025, 0x00000021, 0x00000024, 0x00050085,
|
||||
0x00000006, 0x00000027, 0x00000025, 0x00000026, 0x00060052, 0x00000007, 0x00000040, 0x00000027,
|
||||
0x0000001c, 0x00000002, 0x00050041, 0x0000002f, 0x00000030, 0x0000002d, 0x0000000f, 0x0003003e,
|
||||
0x00000030, 0x00000040, 0x0003003e, 0x00000032, 0x00000016, 0x0004003d, 0x00000013, 0x00000036,
|
||||
0x00000035, 0x0003003e, 0x00000034, 0x00000036, 0x0004003d, 0x00000037, 0x0000003c, 0x0000003b,
|
||||
0x0003003e, 0x00000039, 0x0000003c, 0x000100fd, 0x00010038,
|
||||
};
|
||||
|
||||
static const uint32_t s_frag_spv[864] = {
|
||||
0x07230203, 0x00010000, 0x000d000b, 0x00000111, 0x00000000, 0x00020011, 0x00000001, 0x0006000b,
|
||||
0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001,
|
||||
0x000a000f, 0x00000004, 0x00000004, 0x6e69616d, 0x00000000, 0x00000026, 0x00000062, 0x00000066,
|
||||
0x00000070, 0x000000c9, 0x00030010, 0x00000004, 0x00000007, 0x00050048, 0x0000000e, 0x00000000,
|
||||
0x00000023, 0x00000000, 0x00050048, 0x0000000e, 0x00000001, 0x00000023, 0x00000010, 0x00030047,
|
||||
0x0000000e, 0x00000002, 0x00040047, 0x00000010, 0x00000022, 0x00000000, 0x00040047, 0x00000010,
|
||||
0x00000021, 0x00000002, 0x00040047, 0x00000026, 0x0000000b, 0x0000000f, 0x00040048, 0x00000044,
|
||||
0x00000000, 0x00000005, 0x00050048, 0x00000044, 0x00000000, 0x00000023, 0x00000000, 0x00050048,
|
||||
0x00000044, 0x00000000, 0x00000007, 0x00000010, 0x00050048, 0x00000044, 0x00000001, 0x00000023,
|
||||
0x00000040, 0x00050048, 0x00000044, 0x00000002, 0x00000023, 0x00000050, 0x00050048, 0x00000044,
|
||||
0x00000003, 0x00000023, 0x00000060, 0x00050048, 0x00000044, 0x00000004, 0x00000023, 0x00000070,
|
||||
0x00030047, 0x00000044, 0x00000002, 0x00040047, 0x00000062, 0x0000001e, 0x00000001, 0x00040047,
|
||||
0x00000066, 0x0000001e, 0x00000000, 0x00040047, 0x00000070, 0x0000001e, 0x00000002, 0x00040047,
|
||||
0x00000093, 0x00000022, 0x00000000, 0x00040047, 0x00000093, 0x00000021, 0x00000001, 0x00040047,
|
||||
0x000000c9, 0x0000001e, 0x00000000, 0x00040047, 0x000000d0, 0x00000022, 0x00000000, 0x00040047,
|
||||
0x000000d0, 0x00000021, 0x00000000, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002,
|
||||
0x00030016, 0x00000006, 0x00000020, 0x00040017, 0x00000007, 0x00000006, 0x00000003, 0x00040017,
|
||||
0x0000000d, 0x00000006, 0x00000004, 0x0004001e, 0x0000000e, 0x0000000d, 0x0000000d, 0x00040020,
|
||||
0x0000000f, 0x00000002, 0x0000000e, 0x0004003b, 0x0000000f, 0x00000010, 0x00000002, 0x00040015,
|
||||
0x00000011, 0x00000020, 0x00000001, 0x0004002b, 0x00000011, 0x00000012, 0x00000001, 0x00040015,
|
||||
0x00000013, 0x00000020, 0x00000000, 0x0004002b, 0x00000013, 0x00000014, 0x00000000, 0x00040020,
|
||||
0x00000015, 0x00000002, 0x00000006, 0x0004002b, 0x00000011, 0x00000018, 0x00000000, 0x0004002b,
|
||||
0x00000013, 0x00000019, 0x00000003, 0x00020014, 0x0000001c, 0x0004002b, 0x00000006, 0x00000024,
|
||||
0x3f800000, 0x00040020, 0x00000025, 0x00000001, 0x0000000d, 0x0004003b, 0x00000025, 0x00000026,
|
||||
0x00000001, 0x00040020, 0x00000027, 0x00000001, 0x00000006, 0x0004002b, 0x00000006, 0x00000034,
|
||||
0x00000000, 0x00040020, 0x00000037, 0x00000002, 0x0000000d, 0x00040018, 0x00000040, 0x00000007,
|
||||
0x00000003, 0x00040018, 0x00000043, 0x0000000d, 0x00000004, 0x0007001e, 0x00000044, 0x00000043,
|
||||
0x0000000d, 0x0000000d, 0x0000000d, 0x0000000d, 0x00040020, 0x00000045, 0x00000009, 0x00000044,
|
||||
0x0004003b, 0x00000045, 0x00000046, 0x00000009, 0x00040020, 0x00000047, 0x00000009, 0x0000000d,
|
||||
0x0004002b, 0x00000011, 0x0000004b, 0x00000002, 0x0004002b, 0x00000011, 0x0000004f, 0x00000003,
|
||||
0x00040020, 0x00000061, 0x00000001, 0x00000007, 0x0004003b, 0x00000061, 0x00000062, 0x00000001,
|
||||
0x0004003b, 0x00000061, 0x00000066, 0x00000001, 0x00040017, 0x0000006c, 0x00000006, 0x00000002,
|
||||
0x00040020, 0x0000006f, 0x00000001, 0x0000006c, 0x0004003b, 0x0000006f, 0x00000070, 0x00000001,
|
||||
0x0004002b, 0x00000013, 0x00000078, 0x00000001, 0x00090019, 0x00000090, 0x00000006, 0x00000001,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x0003001b, 0x00000091, 0x00000090,
|
||||
0x00040020, 0x00000092, 0x00000000, 0x00000091, 0x0004003b, 0x00000092, 0x00000093, 0x00000000,
|
||||
0x0004002b, 0x00000006, 0x00000098, 0x40000000, 0x00040020, 0x000000b4, 0x00000009, 0x00000006,
|
||||
0x00040020, 0x000000c8, 0x00000003, 0x0000000d, 0x0004003b, 0x000000c8, 0x000000c9, 0x00000003,
|
||||
0x0004002b, 0x00000011, 0x000000ca, 0x00000004, 0x0004003b, 0x00000092, 0x000000d0, 0x00000000,
|
||||
0x0006002c, 0x00000007, 0x000000d6, 0x00000024, 0x00000024, 0x00000024, 0x00050036, 0x00000002,
|
||||
0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x00050041, 0x00000047, 0x00000048,
|
||||
0x00000046, 0x00000012, 0x0004003d, 0x0000000d, 0x00000049, 0x00000048, 0x00050041, 0x00000047,
|
||||
0x0000004c, 0x00000046, 0x0000004b, 0x0004003d, 0x0000000d, 0x0000004d, 0x0000004c, 0x00050041,
|
||||
0x00000047, 0x00000050, 0x00000046, 0x0000004f, 0x0004003d, 0x0000000d, 0x00000051, 0x00000050,
|
||||
0x00050051, 0x00000006, 0x00000053, 0x00000049, 0x00000000, 0x00050051, 0x00000006, 0x00000054,
|
||||
0x00000049, 0x00000001, 0x00050051, 0x00000006, 0x00000055, 0x00000049, 0x00000002, 0x00050051,
|
||||
0x00000006, 0x00000056, 0x0000004d, 0x00000000, 0x00050051, 0x00000006, 0x00000057, 0x0000004d,
|
||||
0x00000001, 0x00050051, 0x00000006, 0x00000058, 0x0000004d, 0x00000002, 0x00050051, 0x00000006,
|
||||
0x00000059, 0x00000051, 0x00000000, 0x00050051, 0x00000006, 0x0000005a, 0x00000051, 0x00000001,
|
||||
0x00050051, 0x00000006, 0x0000005b, 0x00000051, 0x00000002, 0x00060050, 0x00000007, 0x0000005c,
|
||||
0x00000053, 0x00000054, 0x00000055, 0x00060050, 0x00000007, 0x0000005d, 0x00000056, 0x00000057,
|
||||
0x00000058, 0x00060050, 0x00000007, 0x0000005e, 0x00000059, 0x0000005a, 0x0000005b, 0x00060050,
|
||||
0x00000040, 0x0000005f, 0x0000005c, 0x0000005d, 0x0000005e, 0x0004003d, 0x00000007, 0x00000063,
|
||||
0x00000062, 0x0006000c, 0x00000007, 0x00000064, 0x00000001, 0x00000045, 0x00000063, 0x0004003d,
|
||||
0x00000007, 0x00000067, 0x00000066, 0x000400cf, 0x00000007, 0x00000068, 0x00000067, 0x000400d0,
|
||||
0x00000007, 0x0000006b, 0x00000067, 0x0004003d, 0x0000006c, 0x00000071, 0x00000070, 0x000400cf,
|
||||
0x0000006c, 0x00000072, 0x00000071, 0x000400d0, 0x0000006c, 0x00000075, 0x00000071, 0x00050051,
|
||||
0x00000006, 0x0000007a, 0x00000075, 0x00000001, 0x0005008e, 0x00000007, 0x0000007b, 0x00000068,
|
||||
0x0000007a, 0x00050051, 0x00000006, 0x0000007e, 0x00000072, 0x00000001, 0x0005008e, 0x00000007,
|
||||
0x0000007f, 0x0000006b, 0x0000007e, 0x00050083, 0x00000007, 0x00000080, 0x0000007b, 0x0000007f,
|
||||
0x0006000c, 0x00000007, 0x00000081, 0x00000001, 0x00000045, 0x00000080, 0x0004007f, 0x00000007,
|
||||
0x00000082, 0x00000081, 0x00050051, 0x00000006, 0x00000086, 0x00000072, 0x00000000, 0x0005008e,
|
||||
0x00000007, 0x00000087, 0x0000006b, 0x00000086, 0x00050051, 0x00000006, 0x0000008a, 0x00000075,
|
||||
0x00000000, 0x0005008e, 0x00000007, 0x0000008b, 0x00000068, 0x0000008a, 0x00050083, 0x00000007,
|
||||
0x0000008c, 0x00000087, 0x0000008b, 0x0006000c, 0x00000007, 0x0000008d, 0x00000001, 0x00000045,
|
||||
0x0000008c, 0x0004007f, 0x00000007, 0x0000008e, 0x0000008d, 0x0004003d, 0x00000091, 0x00000094,
|
||||
0x00000093, 0x00050057, 0x0000000d, 0x00000096, 0x00000094, 0x00000071, 0x0008004f, 0x00000007,
|
||||
0x00000097, 0x00000096, 0x00000096, 0x00000000, 0x00000001, 0x00000002, 0x0005008e, 0x00000007,
|
||||
0x00000099, 0x00000097, 0x00000098, 0x00050083, 0x00000007, 0x0000009b, 0x00000099, 0x000000d6,
|
||||
0x00060050, 0x00000040, 0x000000ad, 0x00000082, 0x0000008e, 0x00000064, 0x00050091, 0x00000007,
|
||||
0x000000af, 0x000000ad, 0x0000009b, 0x0006000c, 0x00000007, 0x000000b0, 0x00000001, 0x00000045,
|
||||
0x000000af, 0x00050091, 0x00000007, 0x000000b1, 0x0000005f, 0x000000b0, 0x0006000c, 0x00000007,
|
||||
0x000000b2, 0x00000001, 0x00000045, 0x000000b1, 0x00060041, 0x000000b4, 0x000000b5, 0x00000046,
|
||||
0x00000012, 0x00000019, 0x0004003d, 0x00000006, 0x000000b6, 0x000000b5, 0x00060041, 0x000000b4,
|
||||
0x000000b7, 0x00000046, 0x0000004b, 0x00000019, 0x0004003d, 0x00000006, 0x000000b8, 0x000000b7,
|
||||
0x00060041, 0x000000b4, 0x000000b9, 0x00000046, 0x0000004f, 0x00000019, 0x0004003d, 0x00000006,
|
||||
0x000000ba, 0x000000b9, 0x00060050, 0x00000007, 0x000000bb, 0x000000b6, 0x000000b8, 0x000000ba,
|
||||
0x00060041, 0x00000015, 0x000000bd, 0x00000010, 0x00000012, 0x00000078, 0x0004003d, 0x00000006,
|
||||
0x000000be, 0x000000bd, 0x00050083, 0x00000006, 0x000000c1, 0x00000024, 0x000000be, 0x00050094,
|
||||
0x00000006, 0x000000c4, 0x000000b2, 0x000000bb, 0x0007000c, 0x00000006, 0x000000c5, 0x00000001,
|
||||
0x00000028, 0x000000c4, 0x00000034, 0x0008000c, 0x00000006, 0x000000c7, 0x00000001, 0x00000032,
|
||||
0x000000c1, 0x000000c5, 0x000000be, 0x00050041, 0x00000047, 0x000000cb, 0x00000046, 0x000000ca,
|
||||
0x0004003d, 0x0000000d, 0x000000cc, 0x000000cb, 0x0008004f, 0x00000007, 0x000000cd, 0x000000cc,
|
||||
0x000000cc, 0x00000000, 0x00000001, 0x00000002, 0x0005008e, 0x00000007, 0x000000cf, 0x000000cd,
|
||||
0x000000c7, 0x0004003d, 0x00000091, 0x000000d1, 0x000000d0, 0x00050057, 0x0000000d, 0x000000d3,
|
||||
0x000000d1, 0x00000071, 0x0008004f, 0x00000007, 0x000000d4, 0x000000d3, 0x000000d3, 0x00000000,
|
||||
0x00000001, 0x00000002, 0x00050085, 0x00000007, 0x000000d5, 0x000000cf, 0x000000d4, 0x0007000c,
|
||||
0x00000007, 0x000000d7, 0x00000001, 0x00000025, 0x000000d5, 0x000000d6, 0x000300f7, 0x0000010a,
|
||||
0x00000000, 0x000300fb, 0x00000014, 0x000000ed, 0x000200f8, 0x000000ed, 0x00060041, 0x00000015,
|
||||
0x000000ee, 0x00000010, 0x00000012, 0x00000014, 0x0004003d, 0x00000006, 0x000000ef, 0x000000ee,
|
||||
0x00060041, 0x00000015, 0x000000f0, 0x00000010, 0x00000018, 0x00000019, 0x0004003d, 0x00000006,
|
||||
0x000000f1, 0x000000f0, 0x000500bc, 0x0000001c, 0x000000f2, 0x000000ef, 0x000000f1, 0x000300f7,
|
||||
0x000000f5, 0x00000000, 0x000400fa, 0x000000f2, 0x000000f3, 0x000000f5, 0x000200f8, 0x000000f3,
|
||||
0x000200f9, 0x0000010a, 0x000200f8, 0x000000f5, 0x00050041, 0x00000027, 0x000000f6, 0x00000026,
|
||||
0x00000019, 0x0004003d, 0x00000006, 0x000000f7, 0x000000f6, 0x00050088, 0x00000006, 0x000000f8,
|
||||
0x00000024, 0x000000f7, 0x00050083, 0x00000006, 0x000000fb, 0x000000f8, 0x000000f1, 0x00050083,
|
||||
0x00000006, 0x00000100, 0x000000ef, 0x000000f1, 0x00050088, 0x00000006, 0x00000101, 0x000000fb,
|
||||
0x00000100, 0x0008000c, 0x00000006, 0x00000102, 0x00000001, 0x0000002b, 0x00000101, 0x00000034,
|
||||
0x00000024, 0x00050041, 0x00000037, 0x00000104, 0x00000010, 0x00000018, 0x0004003d, 0x0000000d,
|
||||
0x00000105, 0x00000104, 0x0008004f, 0x00000007, 0x00000106, 0x00000105, 0x00000105, 0x00000000,
|
||||
0x00000001, 0x00000002, 0x00060050, 0x00000007, 0x00000108, 0x00000102, 0x00000102, 0x00000102,
|
||||
0x0008000c, 0x00000007, 0x00000109, 0x00000001, 0x0000002e, 0x000000d7, 0x00000106, 0x00000108,
|
||||
0x000200f9, 0x0000010a, 0x000200f8, 0x0000010a, 0x000700f5, 0x00000007, 0x00000110, 0x000000d7,
|
||||
0x000000f3, 0x00000109, 0x000000f5, 0x00060041, 0x000000b4, 0x000000da, 0x00000046, 0x000000ca,
|
||||
0x00000019, 0x0004003d, 0x00000006, 0x000000db, 0x000000da, 0x00050051, 0x00000006, 0x000000dc,
|
||||
0x00000110, 0x00000000, 0x00050051, 0x00000006, 0x000000dd, 0x00000110, 0x00000001, 0x00050051,
|
||||
0x00000006, 0x000000de, 0x00000110, 0x00000002, 0x00070050, 0x0000000d, 0x000000df, 0x000000dc,
|
||||
0x000000dd, 0x000000de, 0x000000db, 0x0003003e, 0x000000c9, 0x000000df, 0x000100fd, 0x00010038,
|
||||
};
|
||||
|
||||
static const uint32_t s_vert_shd_spv[458] = {
|
||||
0x07230203, 0x00010000, 0x000d000b, 0x0000005b, 0x00000000, 0x00020011, 0x00000001, 0x0006000b,
|
||||
0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001,
|
||||
0x000e000f, 0x00000000, 0x00000004, 0x6e69616d, 0x00000000, 0x00000015, 0x0000002d, 0x00000032,
|
||||
0x0000003d, 0x0000004a, 0x0000004d, 0x00000051, 0x00000053, 0x00000055, 0x00040048, 0x0000000b,
|
||||
0x00000000, 0x00000005, 0x00050048, 0x0000000b, 0x00000000, 0x00000023, 0x00000000, 0x00050048,
|
||||
0x0000000b, 0x00000000, 0x00000007, 0x00000010, 0x00040048, 0x0000000b, 0x00000001, 0x00000005,
|
||||
0x00050048, 0x0000000b, 0x00000001, 0x00000023, 0x00000040, 0x00050048, 0x0000000b, 0x00000001,
|
||||
0x00000007, 0x00000010, 0x00050048, 0x0000000b, 0x00000002, 0x00000023, 0x00000080, 0x00050048,
|
||||
0x0000000b, 0x00000003, 0x00000023, 0x00000090, 0x00030047, 0x0000000b, 0x00000002, 0x00040047,
|
||||
0x00000015, 0x0000001e, 0x00000000, 0x00050048, 0x0000002b, 0x00000000, 0x0000000b, 0x00000000,
|
||||
0x00050048, 0x0000002b, 0x00000001, 0x0000000b, 0x00000001, 0x00050048, 0x0000002b, 0x00000002,
|
||||
0x0000000b, 0x00000003, 0x00050048, 0x0000002b, 0x00000003, 0x0000000b, 0x00000004, 0x00030047,
|
||||
0x0000002b, 0x00000002, 0x00040047, 0x00000032, 0x0000001e, 0x00000000, 0x00040047, 0x0000003d,
|
||||
0x0000001e, 0x00000001, 0x00040047, 0x0000004a, 0x0000001e, 0x00000001, 0x00040047, 0x0000004d,
|
||||
0x0000001e, 0x00000002, 0x00040047, 0x00000051, 0x0000001e, 0x00000003, 0x00040047, 0x00000053,
|
||||
0x0000001e, 0x00000002, 0x00040047, 0x00000055, 0x0000001e, 0x00000004, 0x00020013, 0x00000002,
|
||||
0x00030021, 0x00000003, 0x00000002, 0x00030016, 0x00000006, 0x00000020, 0x00040017, 0x00000007,
|
||||
0x00000006, 0x00000004, 0x00040018, 0x0000000a, 0x00000007, 0x00000004, 0x0006001e, 0x0000000b,
|
||||
0x0000000a, 0x0000000a, 0x00000007, 0x00000007, 0x00040020, 0x0000000c, 0x00000009, 0x0000000b,
|
||||
0x0004003b, 0x0000000c, 0x0000000d, 0x00000009, 0x00040015, 0x0000000e, 0x00000020, 0x00000001,
|
||||
0x0004002b, 0x0000000e, 0x0000000f, 0x00000000, 0x00040020, 0x00000010, 0x00000009, 0x0000000a,
|
||||
0x00040017, 0x00000013, 0x00000006, 0x00000003, 0x00040020, 0x00000014, 0x00000001, 0x00000013,
|
||||
0x0004003b, 0x00000014, 0x00000015, 0x00000001, 0x0004002b, 0x00000006, 0x00000017, 0x3f800000,
|
||||
0x00040015, 0x0000001d, 0x00000020, 0x00000000, 0x0004002b, 0x00000006, 0x00000026, 0x3f000000,
|
||||
0x0004002b, 0x0000001d, 0x00000029, 0x00000001, 0x0004001c, 0x0000002a, 0x00000006, 0x00000029,
|
||||
0x0006001e, 0x0000002b, 0x00000007, 0x00000006, 0x0000002a, 0x0000002a, 0x00040020, 0x0000002c,
|
||||
0x00000003, 0x0000002b, 0x0004003b, 0x0000002c, 0x0000002d, 0x00000003, 0x00040020, 0x0000002f,
|
||||
0x00000003, 0x00000007, 0x00040018, 0x00000031, 0x00000013, 0x00000003, 0x0004002b, 0x0000000e,
|
||||
0x00000034, 0x00000001, 0x00040020, 0x00000035, 0x00000009, 0x00000007, 0x0004002b, 0x0000000e,
|
||||
0x00000039, 0x00000002, 0x0004002b, 0x0000000e, 0x0000003d, 0x00000003, 0x0004002b, 0x00000006,
|
||||
0x00000041, 0x00000000, 0x00040020, 0x00000051, 0x00000009, 0x00000006, 0x0004003b, 0x00000014,
|
||||
0x0000005b, 0x00000001, 0x0004002b, 0x0000000e, 0x00000060, 0x00000004, 0x00040020, 0x0000006c,
|
||||
0x00000003, 0x00000013, 0x0004003b, 0x0000006c, 0x0000006d, 0x00000003, 0x00050036, 0x00000002,
|
||||
0x00000003, 0x00000007, 0x00040020, 0x00000031, 0x00000003, 0x00000013, 0x0004003b, 0x00000031,
|
||||
0x00000032, 0x00000003, 0x0004002b, 0x0000000e, 0x00000033, 0x00000001, 0x0004003b, 0x00000031,
|
||||
0x0000003d, 0x00000003, 0x00040018, 0x00000040, 0x00000013, 0x00000003, 0x0004003b, 0x00000014,
|
||||
0x0000004a, 0x00000001, 0x0004003b, 0x00000031, 0x0000004d, 0x00000003, 0x00040017, 0x0000004f,
|
||||
0x00000006, 0x00000002, 0x00040020, 0x00000050, 0x00000003, 0x0000004f, 0x0004003b, 0x00000050,
|
||||
0x00000051, 0x00000003, 0x00040020, 0x00000052, 0x00000001, 0x0000004f, 0x0004003b, 0x00000052,
|
||||
0x00000053, 0x00000001, 0x0004003b, 0x00000031, 0x00000055, 0x00000003, 0x00050036, 0x00000002,
|
||||
0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x00050041, 0x00000010, 0x00000011,
|
||||
0x0000000d, 0x0000000f, 0x0004003d, 0x0000000a, 0x00000012, 0x00000011, 0x0004003d, 0x00000013,
|
||||
0x00000016, 0x00000015, 0x00050051, 0x00000006, 0x00000018, 0x00000016, 0x00000000, 0x00050051,
|
||||
@@ -42,94 +203,8 @@ static const uint32_t s_vert_spv[528] = {
|
||||
0x00050091, 0x00000007, 0x0000001c, 0x00000012, 0x0000001b, 0x00050051, 0x00000006, 0x00000021,
|
||||
0x0000001c, 0x00000002, 0x00050051, 0x00000006, 0x00000024, 0x0000001c, 0x00000003, 0x00050081,
|
||||
0x00000006, 0x00000025, 0x00000021, 0x00000024, 0x00050085, 0x00000006, 0x00000027, 0x00000025,
|
||||
0x00000026, 0x00060052, 0x00000007, 0x00000076, 0x00000027, 0x0000001c, 0x00000002, 0x00050041,
|
||||
0x0000002f, 0x00000030, 0x0000002d, 0x0000000f, 0x0003003e, 0x00000030, 0x00000076, 0x00050041,
|
||||
0x00000035, 0x00000036, 0x0000000d, 0x00000034, 0x0004003d, 0x00000007, 0x00000037, 0x00000036,
|
||||
0x00050041, 0x00000035, 0x0000003a, 0x0000000d, 0x00000039, 0x0004003d, 0x00000007, 0x0000003b,
|
||||
0x0000003a, 0x00050041, 0x00000035, 0x0000003e, 0x0000000d, 0x0000003d, 0x0004003d, 0x00000007,
|
||||
0x0000003f, 0x0000003e, 0x00050051, 0x00000006, 0x00000042, 0x00000037, 0x00000000, 0x00050051,
|
||||
0x00000006, 0x00000043, 0x00000037, 0x00000001, 0x00050051, 0x00000006, 0x00000044, 0x00000037,
|
||||
0x00000002, 0x00050051, 0x00000006, 0x00000045, 0x0000003b, 0x00000000, 0x00050051, 0x00000006,
|
||||
0x00000046, 0x0000003b, 0x00000001, 0x00050051, 0x00000006, 0x00000047, 0x0000003b, 0x00000002,
|
||||
0x00050051, 0x00000006, 0x00000048, 0x0000003f, 0x00000000, 0x00050051, 0x00000006, 0x00000049,
|
||||
0x0000003f, 0x00000001, 0x00050051, 0x00000006, 0x0000004a, 0x0000003f, 0x00000002, 0x00060050,
|
||||
0x00000013, 0x0000004b, 0x00000042, 0x00000043, 0x00000044, 0x00060050, 0x00000013, 0x0000004c,
|
||||
0x00000045, 0x00000046, 0x00000047, 0x00060050, 0x00000013, 0x0000004d, 0x00000048, 0x00000049,
|
||||
0x0000004a, 0x00060050, 0x00000031, 0x0000004e, 0x0000004b, 0x0000004c, 0x0000004d, 0x00060041,
|
||||
0x00000051, 0x00000052, 0x0000000d, 0x00000034, 0x00000022, 0x0004003d, 0x00000006, 0x00000053,
|
||||
0x00000052, 0x00060041, 0x00000051, 0x00000054, 0x0000000d, 0x00000039, 0x00000022, 0x0004003d,
|
||||
0x00000006, 0x00000055, 0x00000054, 0x00060041, 0x00000051, 0x00000056, 0x0000000d, 0x0000003d,
|
||||
0x00000022, 0x0004003d, 0x00000006, 0x00000057, 0x00000056, 0x00060050, 0x00000013, 0x00000058,
|
||||
0x00000053, 0x00000055, 0x00000057, 0x0004003d, 0x00000013, 0x0000005c, 0x0000005b, 0x00050091,
|
||||
0x00000013, 0x0000005d, 0x0000004e, 0x0000005c, 0x0006000c, 0x00000013, 0x0000005e, 0x00000001,
|
||||
0x00000045, 0x0000005d, 0x00060041, 0x00000051, 0x00000061, 0x0000000d, 0x00000060, 0x00000022,
|
||||
0x0004003d, 0x00000006, 0x00000062, 0x00000061, 0x00050083, 0x00000006, 0x00000065, 0x00000017,
|
||||
0x00000062, 0x00050094, 0x00000006, 0x00000068, 0x0000005e, 0x00000058, 0x0007000c, 0x00000006,
|
||||
0x00000069, 0x00000001, 0x00000028, 0x00000068, 0x00000041, 0x0008000c, 0x00000006, 0x0000006b,
|
||||
0x00000001, 0x00000032, 0x00000065, 0x00000069, 0x00000062, 0x00050041, 0x00000035, 0x0000006e,
|
||||
0x0000000d, 0x00000060, 0x0004003d, 0x00000007, 0x0000006f, 0x0000006e, 0x0008004f, 0x00000013,
|
||||
0x00000070, 0x0000006f, 0x0000006f, 0x00000000, 0x00000001, 0x00000002, 0x0005008e, 0x00000013,
|
||||
0x00000072, 0x00000070, 0x0000006b, 0x0003003e, 0x0000006d, 0x00000072, 0x000100fd, 0x00010038,
|
||||
};
|
||||
|
||||
static const uint32_t s_frag_spv[121] = {
|
||||
0x07230203, 0x00010000, 0x000d000b, 0x00000015, 0x00000000, 0x00020011, 0x00000001, 0x0006000b,
|
||||
0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001,
|
||||
0x0007000f, 0x00000004, 0x00000004, 0x6e69616d, 0x00000000, 0x00000009, 0x0000000c, 0x00030010,
|
||||
0x00000004, 0x00000007, 0x00040047, 0x00000009, 0x0000001e, 0x00000000, 0x00040047, 0x0000000c,
|
||||
0x0000001e, 0x00000000, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00030016,
|
||||
0x00000006, 0x00000020, 0x00040017, 0x00000007, 0x00000006, 0x00000004, 0x00040020, 0x00000008,
|
||||
0x00000003, 0x00000007, 0x0004003b, 0x00000008, 0x00000009, 0x00000003, 0x00040017, 0x0000000a,
|
||||
0x00000006, 0x00000003, 0x00040020, 0x0000000b, 0x00000001, 0x0000000a, 0x0004003b, 0x0000000b,
|
||||
0x0000000c, 0x00000001, 0x0004002b, 0x00000006, 0x0000000e, 0x3f800000, 0x0006002c, 0x0000000a,
|
||||
0x0000000f, 0x0000000e, 0x0000000e, 0x0000000e, 0x00050036, 0x00000002, 0x00000004, 0x00000000,
|
||||
0x00000003, 0x000200f8, 0x00000005, 0x0004003d, 0x0000000a, 0x0000000d, 0x0000000c, 0x0007000c,
|
||||
0x0000000a, 0x00000010, 0x00000001, 0x00000025, 0x0000000d, 0x0000000f, 0x00050051, 0x00000006,
|
||||
0x00000011, 0x00000010, 0x00000000, 0x00050051, 0x00000006, 0x00000012, 0x00000010, 0x00000001,
|
||||
0x00050051, 0x00000006, 0x00000013, 0x00000010, 0x00000002, 0x00070050, 0x00000007, 0x00000014,
|
||||
0x00000011, 0x00000012, 0x00000013, 0x0000000e, 0x0003003e, 0x00000009, 0x00000014, 0x000100fd,
|
||||
0x00010038,
|
||||
};
|
||||
|
||||
static const uint32_t s_vert_shd_spv[397] = {
|
||||
0x07230203, 0x00010000, 0x000d000b, 0x00000051, 0x00000000, 0x00020011, 0x00000001, 0x0006000b,
|
||||
0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001,
|
||||
0x000a000f, 0x00000000, 0x00000004, 0x6e69616d, 0x00000000, 0x00000015, 0x0000002d, 0x00000032,
|
||||
0x0000003d, 0x0000004a, 0x00040048, 0x0000000b, 0x00000000, 0x00000005, 0x00050048, 0x0000000b,
|
||||
0x00000000, 0x00000023, 0x00000000, 0x00050048, 0x0000000b, 0x00000000, 0x00000007, 0x00000010,
|
||||
0x00040048, 0x0000000b, 0x00000001, 0x00000005, 0x00050048, 0x0000000b, 0x00000001, 0x00000023,
|
||||
0x00000040, 0x00050048, 0x0000000b, 0x00000001, 0x00000007, 0x00000010, 0x00050048, 0x0000000b,
|
||||
0x00000002, 0x00000023, 0x00000080, 0x00050048, 0x0000000b, 0x00000003, 0x00000023, 0x00000090,
|
||||
0x00030047, 0x0000000b, 0x00000002, 0x00040047, 0x00000015, 0x0000001e, 0x00000000, 0x00050048,
|
||||
0x0000002b, 0x00000000, 0x0000000b, 0x00000000, 0x00050048, 0x0000002b, 0x00000001, 0x0000000b,
|
||||
0x00000001, 0x00050048, 0x0000002b, 0x00000002, 0x0000000b, 0x00000003, 0x00050048, 0x0000002b,
|
||||
0x00000003, 0x0000000b, 0x00000004, 0x00030047, 0x0000002b, 0x00000002, 0x00040047, 0x00000032,
|
||||
0x0000001e, 0x00000000, 0x00040047, 0x0000003d, 0x0000001e, 0x00000001, 0x00040047, 0x0000004a,
|
||||
0x0000001e, 0x00000001, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00030016,
|
||||
0x00000006, 0x00000020, 0x00040017, 0x00000007, 0x00000006, 0x00000004, 0x00040018, 0x0000000a,
|
||||
0x00000007, 0x00000004, 0x0006001e, 0x0000000b, 0x0000000a, 0x0000000a, 0x00000007, 0x00000007,
|
||||
0x00040020, 0x0000000c, 0x00000009, 0x0000000b, 0x0004003b, 0x0000000c, 0x0000000d, 0x00000009,
|
||||
0x00040015, 0x0000000e, 0x00000020, 0x00000001, 0x0004002b, 0x0000000e, 0x0000000f, 0x00000000,
|
||||
0x00040020, 0x00000010, 0x00000009, 0x0000000a, 0x00040017, 0x00000013, 0x00000006, 0x00000003,
|
||||
0x00040020, 0x00000014, 0x00000001, 0x00000013, 0x0004003b, 0x00000014, 0x00000015, 0x00000001,
|
||||
0x0004002b, 0x00000006, 0x00000017, 0x3f800000, 0x00040015, 0x0000001d, 0x00000020, 0x00000000,
|
||||
0x0004002b, 0x00000006, 0x00000026, 0x3f000000, 0x0004002b, 0x0000001d, 0x00000029, 0x00000001,
|
||||
0x0004001c, 0x0000002a, 0x00000006, 0x00000029, 0x0006001e, 0x0000002b, 0x00000007, 0x00000006,
|
||||
0x0000002a, 0x0000002a, 0x00040020, 0x0000002c, 0x00000003, 0x0000002b, 0x0004003b, 0x0000002c,
|
||||
0x0000002d, 0x00000003, 0x00040020, 0x0000002f, 0x00000003, 0x00000007, 0x00040020, 0x00000031,
|
||||
0x00000003, 0x00000013, 0x0004003b, 0x00000031, 0x00000032, 0x00000003, 0x0004002b, 0x0000000e,
|
||||
0x00000033, 0x00000001, 0x0004003b, 0x00000031, 0x0000003d, 0x00000003, 0x00040018, 0x00000040,
|
||||
0x00000013, 0x00000003, 0x0004003b, 0x00000014, 0x0000004a, 0x00000001, 0x00050036, 0x00000002,
|
||||
0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x00050041, 0x00000010, 0x00000011,
|
||||
0x0000000d, 0x0000000f, 0x0004003d, 0x0000000a, 0x00000012, 0x00000011, 0x0004003d, 0x00000013,
|
||||
0x00000016, 0x00000015, 0x00050051, 0x00000006, 0x00000018, 0x00000016, 0x00000000, 0x00050051,
|
||||
0x00000006, 0x00000019, 0x00000016, 0x00000001, 0x00050051, 0x00000006, 0x0000001a, 0x00000016,
|
||||
0x00000002, 0x00070050, 0x00000007, 0x0000001b, 0x00000018, 0x00000019, 0x0000001a, 0x00000017,
|
||||
0x00050091, 0x00000007, 0x0000001c, 0x00000012, 0x0000001b, 0x00050051, 0x00000006, 0x00000021,
|
||||
0x0000001c, 0x00000002, 0x00050051, 0x00000006, 0x00000024, 0x0000001c, 0x00000003, 0x00050081,
|
||||
0x00000006, 0x00000025, 0x00000021, 0x00000024, 0x00050085, 0x00000006, 0x00000027, 0x00000025,
|
||||
0x00000026, 0x00060052, 0x00000007, 0x00000050, 0x00000027, 0x0000001c, 0x00000002, 0x00050041,
|
||||
0x0000002f, 0x00000030, 0x0000002d, 0x0000000f, 0x0003003e, 0x00000030, 0x00000050, 0x00050041,
|
||||
0x00000026, 0x00060052, 0x00000007, 0x0000005a, 0x00000027, 0x0000001c, 0x00000002, 0x00050041,
|
||||
0x0000002f, 0x00000030, 0x0000002d, 0x0000000f, 0x0003003e, 0x00000030, 0x0000005a, 0x00050041,
|
||||
0x00000010, 0x00000034, 0x0000000d, 0x00000033, 0x0004003d, 0x0000000a, 0x00000035, 0x00000034,
|
||||
0x00050091, 0x00000007, 0x0000003b, 0x00000035, 0x0000001b, 0x0008004f, 0x00000013, 0x0000003c,
|
||||
0x0000003b, 0x0000003b, 0x00000000, 0x00000001, 0x00000002, 0x0003003e, 0x00000032, 0x0000003c,
|
||||
@@ -141,7 +216,9 @@ static const uint32_t s_vert_shd_spv[397] = {
|
||||
0x00000040, 0x00000047, 0x00000042, 0x00000044, 0x00000046, 0x0006000c, 0x00000040, 0x00000048,
|
||||
0x00000001, 0x00000022, 0x00000047, 0x00040054, 0x00000040, 0x00000049, 0x00000048, 0x0004003d,
|
||||
0x00000013, 0x0000004b, 0x0000004a, 0x00050091, 0x00000013, 0x0000004c, 0x00000049, 0x0000004b,
|
||||
0x0003003e, 0x0000003d, 0x0000004c, 0x000100fd, 0x00010038,
|
||||
0x0003003e, 0x0000003d, 0x0000004c, 0x0003003e, 0x0000004d, 0x00000016, 0x0004003d, 0x0000004f,
|
||||
0x00000054, 0x00000053, 0x0003003e, 0x00000051, 0x00000054, 0x0003003e, 0x00000055, 0x0000004b,
|
||||
0x000100fd, 0x00010038,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,8 +4,8 @@
|
||||
as libraries e o SDL2_ttf/freetype/libpng/openssl estaticos). -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.tinyblocks"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.1.0"
|
||||
android:versionCode="2"
|
||||
android:versionName="0.2.0"
|
||||
android:installLocation="auto">
|
||||
|
||||
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="34" />
|
||||
@@ -20,6 +20,9 @@
|
||||
<!-- Os blocos de HTTP/HTTPS baixam os dados do exemplo -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<!-- leitor de QR do editor (receber blocos); pedida na hora de usar -->
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-feature android:name="android.hardware.camera.any" android:required="false" />
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
||||