Browse Source

return a status int instead of a string directly in ohmd_gets

James Sarrett 8 years ago
parent
commit
d73871358d
4 changed files with 13 additions and 10 deletions
  1. 3 2
      include/openhmd.h
  2. 6 4
      src/openhmd.c
  3. 2 2
      src/shaders.c
  4. 2 2
      src/shaders.h

+ 3 - 2
include/openhmd.h

@@ -244,9 +244,10 @@ OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_ctx_probe(ohmd_context* ctx);
  * This is where the distortion shader sources can be retrieved.
  *
  * @param type The name of the string to fetch. One of OHMD_GLSL_DISTORTION_FRAG_SRC, and OHMD_GLSL_DISTORTION_FRAG_SRC.
- * @return a string with a human readable device name.
+ * @param outt The location to return a const char*
+ * @return 0 on success, <0 on failure.
  **/
-OHMD_APIENTRYDLL const char* OHMD_APIENTRY ohmd_gets(ohmd_string_description type);
+OHMD_APIENTRYDLL int ohmd_gets(ohmd_string_description type, const char ** dst);
 
 /**
  * Get device description from enumeration list index.

+ 6 - 4
src/openhmd.c

@@ -98,15 +98,17 @@ int OHMD_APIENTRY ohmd_ctx_probe(ohmd_context* ctx)
 	return ctx->list.num_devices;
 }
 
-const char* OHMD_APIENTRY ohmd_gets(ohmd_string_description type)
+int OHMD_APIENTRY ohmd_gets(ohmd_string_description type, const char ** out)
 {
 	switch(type){
 	case OHMD_GLSL_DISTORTION_VERT_SRC:
-		return distortion_vert;
+		*out = distortion_vert;
+		return OHMD_S_OK;
 	case OHMD_GLSL_DISTORTION_FRAG_SRC:
-		return distortion_frag;
+		*out = distortion_frag;
+		return OHMD_S_OK;
 	default:
-		return NULL;
+		return OHMD_S_UNSUPPORTED;
 	}
 }
 

+ 2 - 2
src/shaders.c

@@ -1,4 +1,4 @@
-const char * distortion_vert =
+const char distortion_vert[] =
 "#version 120\n"
 "void main(void)\n"
 "{\n"
@@ -6,7 +6,7 @@ const char * distortion_vert =
     "gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n"
 "}";
 
-const char * distortion_frag =
+const char distortion_frag[] =
 "#version 120\n"
 "\n"
 "//per eye texture to warp for lens distortion\n"

+ 2 - 2
src/shaders.h

@@ -1,6 +1,6 @@
 #ifndef SHADERS_H
 #define SHADERS_H
 
-const char * distortion_vert;
-const char * distortion_frag;
+const char * const distortion_vert;
+const char * const distortion_frag;
 #endif /* SHADERS_H */