mojoshader_effects.h
changeset 1229 3ecd29a50d9d
parent 1152 8f7653f0dc37
child 1235 8fd6c5efe453
--- a/mojoshader_effects.h	Fri Jan 10 05:55:05 2020 +0100
+++ b/mojoshader_effects.h	Sun Jan 12 11:39:49 2020 -0500
@@ -800,6 +800,119 @@
  */
 DECLSPEC void MOJOSHADER_glEffectEnd(MOJOSHADER_glEffect *glEffect);
 
+
+/* Metal effect interface... */
+
+typedef struct MOJOSHADER_mtlEffect MOJOSHADER_mtlEffect;
+typedef struct MOJOSHADER_mtlShader MOJOSHADER_mtlShader;
+typedef struct MOJOSHADER_mtlShaderState MOJOSHADER_mtlShaderState;
+
+/* Fully compile/link the shaders found within the effect.
+ *
+ * The MOJOSHADER_mtlEffect* is solely for use within the Metal-specific calls.
+ *  In all other cases you will be using the MOJOSHADER_effect* instead.
+ *
+ * In a typical use case, you will be calling this immediately after obtaining
+ *  the MOJOSHADER_effect*.
+ *
+ * (effect) is a MOJOSHADER_effect* obtained from MOJOSHADER_parseEffect().
+ * (mtlDevice) is a MTLDevice* obtained from a Metal device creation call,
+ *  such as MTLCreateSystemDefaultDevice().
+ * (numBackingBuffers) is the number of backing uniform buffers that you
+ *  want to create for each shader. If you are using double-buffering,
+ *  this should be 2; for triple buffering, this should be 3, etc.
+ *
+ * This function returns a MOJOSHADER_mtlEffect*, containing Metal-specific
+ *  data for an accompanying MOJOSHADER_effect*.
+ */
+DECLSPEC MOJOSHADER_mtlEffect *MOJOSHADER_mtlCompileEffect(MOJOSHADER_effect *effect,
+                                                           void *mtlDevice,
+                                                           int numBackingBuffers);
+
+/* Delete the shaders that were allocated for an effect.
+ *
+ * (mtlEffect) is a MOJOSHADER_mtlEffect* obtained from
+ *  MOJOSHADER_mtlCompileEffect().
+ */
+DECLSPEC void MOJOSHADER_mtlDeleteEffect(MOJOSHADER_mtlEffect *mtlEffect);
+
+/* Prepare the effect for rendering with the currently applied technique.
+ *
+ * This function maps to ID3DXEffect::Begin.
+ *
+ * In addition to the expected Begin parameters, we also include a parameter
+ *  to pass in a MOJOSHADER_effectRenderState. Rather than change the render
+ *  state within MojoShader itself we will simply provide what the effect wants
+ *  and allow you to use this information with your own renderer.
+ *  MOJOSHADER_glEffectBeginPass will update with the render state desired by
+ *  the current effect pass.
+ *
+ * Note that we only provide the ability to preserve the shader state, but NOT
+ * the ability to preserve the render/sampler states. You are expected to
+ * track your own Metal state and restore these states as needed for your
+ * application.
+ *
+ * (mtlEffect) is a MOJOSHADER_mtlEffect* obtained from
+ *  MOJOSHADER_mtlCompileEffect().
+ * (numPasses) will be filled with the number of passes that this technique
+ *  will need to fully render.
+ * (saveShaderState) is a boolean value informing the effect whether or not to
+ *  restore the shader bindings after calling MOJOSHADER_mtlEffectEnd.
+ * (renderState) will be filled by the effect to inform you of the render state
+ *  changes introduced by the technique and its passes.
+ */
+DECLSPEC void MOJOSHADER_mtlEffectBegin(MOJOSHADER_mtlEffect *mtlEffect,
+                                        unsigned int *numPasses,
+                                        int saveShaderState,
+                                        MOJOSHADER_effectStateChanges *stateChanges);
+
+/* Begin an effect pass from the currently applied technique.
+ *
+ * This function maps to ID3DXEffect::BeginPass.
+ *
+ * (mtlEffect) is a MOJOSHADER_mtlEffect* obtained from
+ *  MOJOSHADER_mtlCompileEffect().
+ * (pass) is the index of the effect pass as found in the current technique.
+ * (state) is a pointer to the current shader state object.
+ *
+ * The MOJOSHADER_mtlShaderState pointed to by (shState) must be created
+ * before calling this function!
+ */
+DECLSPEC void MOJOSHADER_mtlEffectBeginPass(MOJOSHADER_mtlEffect *mtlEffect,
+                                            unsigned int pass,
+                                            MOJOSHADER_mtlShaderState *shState);
+
+/* Push render state changes that occurred within an actively rendering pass.
+ *
+ * This function maps to ID3DXEffect::CommitChanges.
+ *
+ * (mtlEffect) is a MOJOSHADER_mtlEffect* obtained from
+ *  MOJOSHADER_mtlCompileEffect().
+ * (state) is a pointer to the current shader state object.
+ */
+DECLSPEC void MOJOSHADER_mtlEffectCommitChanges(MOJOSHADER_mtlEffect *mtlEffect,
+                                                MOJOSHADER_mtlShaderState *shState);
+
+/* End an effect pass from the currently applied technique.
+ *
+ * This function maps to ID3DXEffect::EndPass.
+ *
+ * (mtlEffect) is a MOJOSHADER_mtlEffect* obtained from
+ *  MOJOSHADER_mtlCompileEffect().
+ */
+DECLSPEC void MOJOSHADER_mtlEffectEndPass(MOJOSHADER_mtlEffect *mtlEffect);
+
+/* Complete rendering the effect technique, and restore the render state.
+ *
+ * This function maps to ID3DXEffect::End.
+ *
+ * (mtlEffect) is a MOJOSHADER_mtlEffect* obtained from
+ *  MOJOSHADER_glCompileEffect().
+ * (state) is a pointer to the current shader state object.
+ */
+DECLSPEC void MOJOSHADER_mtlEffectEnd(MOJOSHADER_mtlEffect *mtlEffect,
+                                      MOJOSHADER_mtlShaderState *shState);
+
 #endif /* MOJOSHADER_EFFECT_SUPPORT */
 
 #endif /* MOJOSHADER_EFFECTS_H */