Quellcode durchsuchen

Added some delving results about 3DS homebrew libs

Eiyeron Fulmincendii vor 9 Jahren
Ursprung
Commit
0bd91020e6
3 geänderte Dateien mit 215 neuen und 0 gelöschten Zeilen
  1. 125 0
      info/3ds support/citro3D_graphisms.md
  2. 64 0
      info/3ds support/citro3D_input.md
  3. 26 0
      info/3ds support/infos.md

+ 125 - 0
info/3ds support/citro3D_graphisms.md

@@ -0,0 +1,125 @@
+## Citro3d Graphisms dissection
+(Using [3ds-examples] as dissection material.)
+
+#### Lcd Init
+```cpp
+gfxInitDefault(); // (libctru) Inits the LCD framebuffers with default params.
+gfxSet3D(false); // Disable 3D.
+
+// Setting up the Render buffer for both screens.
+// (Citro3d)
+C3D_RenderBuf rbTop, rbBot;
+```
+### Render buffers
+#### Init
+```cpp
+// ???I suppose that's probably for the 3D stuff.
+#ifndef EXTENDED_TOPSCR_RESOLUTION
+#define TOPSCR_WIDTH 240
+#define TOPSCR_COPYFLAG 0x00001000
+#else
+#define TOPSCR_WIDTH (240*2)
+#define TOPSCR_COPYFLAG 0x01001000
+#endif
+
+// Note : supports GPU_RB_RGB565 format
+// Why 400 of height? I don't have a frigging clue
+// Actually , a screen is 400*240, so the lib inits them by height,width. Welp.
+// IIRC the screen controller is rotated, hence the inversion.
+C3D_RenderBufInit(&rbTop, TOPSCR_WIDTH, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
+C3D_RenderBufInit(&rbBot, 240, 320, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
+rbTop.clearColor = CLEAR_COLOR;
+rbBot.clearColor = CLEAR_COLOR;
+
+```
+#### Add VBO to buffer
+```cpp
+// Configure buffers
+C3D_BufInfo* bufInfo = C3D_GetBufInfo();
+BufInfo_Init(bufInfo);
+BufInfo_Add(bufInfo, myVbo, sizeof(vertex_t), 3, 0x210);
+```
+#### Clean
+```cpp
+// Clear renderbuffers
+C3D_RenderBufClear(&rbTop);
+C3D_RenderBufClear(&rbBot);
+```
+
+### Graphics initialisation
+#### Citro3D init
+```cpp
+C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); // Inits C3D. Nuff said.
+```
+
+#### Matrix binding/setting up
+```cpp
+// Ahah, I know this one! Projection and ModelView matrices.
+C3D_MtxStack projMtx, mdlvMtx;
+MtxStack_Init(&projMtx);
+// I don't have a clue what VSH_FVEC_ or VSH_ULEN_ do...
+MtxStack_Bind(&projMtx, GPU_VERTEX_SHADER, VSH_FVEC_projMtx, VSH_ULEN_projMtx);
+MtxStack_Init(&mdlvMtx);
+MtxStack_Bind(&mdlvMtx, GPU_VERTEX_SHADER, VSH_FVEC_mdlvMtx, VSH_ULEN_mdlvMtx);
+```
+Note : Found somewhere else:
+```cpp
+// Compute the projection matrix
+Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0);
+```
+I suppose that bind must be for multiple screen or stuff.
+
+### Texture
+#### Init and upload
+```cpp
+C3D_Tex myTex;
+// Load the texture and bind it to the first texture unit
+C3D_TexInit(&myTex, 64, 64, GPU_RGBA8);
+// Uploads the grass binary data to the text?
+C3D_TexUpload(&myTex, grass_bin);
+```
+
+### Shaders
+#### Parse compiled shaders
+```cpp
+DVLB_s *pVsh, *pGsh;
+pVsh = DVLB_ParseFile((u32*)test_vsh_shbin, test_vsh_shbin_size);
+pGsh = DVLB_ParseFile((u32*)test_gsh_shbin, test_gsh_shbin_size);
+```
+#### Init shader
+```cpp
+shaderProgram_s shader;
+shaderProgramInit(&shader);
+shaderProgramSetVsh(&shader, &pVsh->DVLE[0]);
+// The last value is a stride value but why 3*5? Here's the solution
+// The vertex struct gputest uses pushes vertex color to index 5
+shaderProgramSetGsh(&shader, &pGsh->DVLE[0], 3*5);
+```
+
+#### Bind shader
+```cpp
+C3D_BindProgram(&shader);
+```
+
+#### Setitng shader program attributes
+```cpp
+// Prolly get the current shader program's attributes
+C3D_AttrInfo* attrInfo = C3D_GetAttrInfo();
+AttrInfo_Init(attrInfo);
+// Attributes are only linked to gputest's way to store them.
+AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // position (xyz)
+AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 2); // texcoord (uv)
+AttrInfo_AddLoader(attrInfo, 2, GPU_FLOAT, 3); // vertex color (rgb)
+```
+
+### VBO
+#### Init and set data
+```cpp
+// static const vertex_t vertex_list[] = {...};
+// Configure VBO
+myVbo = linearAlloc(sizeof(vertex_list));
+// Looks like the VBO allows for direct access.
+memcpy(myVbo, vertex_list, sizeof(vertex_list));
+```
+
+[3ds-examples]: https://github.com/devkitPro/3ds-examples

+ 64 - 0
info/3ds support/citro3D_input.md

@@ -0,0 +1,64 @@
+## Citro3d Input dissection
+Note : it uses libctru, which provides these functions.
+Note2 : Go check hid.h, it's well documented.
+Note3 : Wonder why gputest doesn't do hidInit or hidExit.
+### Key detection
+#### Update
+```cpp
+hidScanInput();
+```
+Note : fits perfectly the input system we use on WRPG. How convenient.
+
+#### Detect
+```cpp
+u32 kDown = hidKeysDown();
+u32 kHeld = hidKeysHeld();
+kDown & KEY_START;
+```
+
+#### Keys
+
+```cpp
+enum
+{
+	KEY_A       = BIT(0),       ///< A
+	KEY_B       = BIT(1),       ///< B
+	KEY_SELECT  = BIT(2),       ///< Select
+	KEY_START   = BIT(3),       ///< Start
+	KEY_DRIGHT  = BIT(4),       ///< D-Pad Right
+	KEY_DLEFT   = BIT(5),       ///< D-Pad Left
+	KEY_DUP     = BIT(6),       ///< D-Pad Up
+	KEY_DDOWN   = BIT(7),       ///< D-Pad Down
+	KEY_R       = BIT(8),       ///< R
+	KEY_L       = BIT(9),       ///< L
+	KEY_X       = BIT(10),      ///< X
+	KEY_Y       = BIT(11),      ///< Y
+	KEY_ZL      = BIT(14),      ///< ZL (New 3DS only)
+	KEY_ZR      = BIT(15),      ///< ZR (New 3DS only)
+	KEY_TOUCH   = BIT(20),      ///< Touch (Not actually provided by HID)
+	KEY_CSTICK_RIGHT = BIT(24), ///< C-Stick Right (New 3DS only)
+	KEY_CSTICK_LEFT  = BIT(25), ///< C-Stick Left (New 3DS only)
+	KEY_CSTICK_UP    = BIT(26), ///< C-Stick Up (New 3DS only)
+	KEY_CSTICK_DOWN  = BIT(27), ///< C-Stick Down (New 3DS only)
+	KEY_CPAD_RIGHT = BIT(28),   ///< Circle Pad Right
+	KEY_CPAD_LEFT  = BIT(29),   ///< Circle Pad Left
+	KEY_CPAD_UP    = BIT(30),   ///< Circle Pad Up
+	KEY_CPAD_DOWN  = BIT(31),   ///< Circle Pad Down
+
+	// Generic catch-all directions
+	KEY_UP    = KEY_DUP    | KEY_CPAD_UP,    ///< D-Pad Up or Circle Pad Up
+	KEY_DOWN  = KEY_DDOWN  | KEY_CPAD_DOWN,  ///< D-Pad Down or Circle Pad Down
+	KEY_LEFT  = KEY_DLEFT  | KEY_CPAD_LEFT,  ///< D-Pad Left or Circle Pad Left
+	KEY_RIGHT = KEY_DRIGHT | KEY_CPAD_RIGHT, ///< D-Pad Right or Circle Pad Right
+};
+```
+
+#### Bonus : Circle Pad :
+```cpp
+/**
+ * @brief Reads the current circle pad position.
+ * @param pos Pointer to output the circle pad position to.
+ */
+void hidCircleRead(circlePosition* pos);
+```
+Neeeeat.

+ 26 - 0
info/3ds support/infos.md

@@ -0,0 +1,26 @@
+# 3DS support project documentation
+
+## Requirements
+- Devkitarm (found on [AUR][devkitarm-bin])
+- Citrus-3ds-git (found on [AUR][citrus-3ds])
+
+
+## Ideas
+- Use [citro3d]?
+  - Low-level OpenGL-like (with some flavour) API
+  - Supports stuff like VBOs.
+  - Built over [libctru].
+- Use [sf2dlib]?
+  - Opens a simple api (check for speed and GPU implementation.)
+  - Would be quite easy to plug WRPG's graphisms over it.
+- Use [cpp3ds]?
+  - Straighter-forward SFML implementation for 3DS.
+  - WOuld only have to make things like rendering offset, scaling and clipping.
+
+
+[devkitarm-bin]: https://aur.archlinux.org/packages/devkitarm-bin/
+[citrus-3ds]: https://aur.archlinux.org/packages/citrus-3ds-git/
+
+[citro3d]: https://github.com/fincs/citro3d/
+[sf2dlib]: https://github.com/xerpi/sf2dlib
+[cpp3ds]: https://github.com/cpp3ds/cpp3ds