00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020 #ifdef WIN32
00021 #include <windows.h>
00022 #endif
00023
00024 #include <iostream>
00025
00026 #include "Glsl.hpp"
00027 #include "GlTextures.hpp"
00028 #include "GlBackend.hpp"
00029 #include "PBufferStreams.hpp"
00030
00031 namespace shgl {
00032
00033 struct GlslBackend : public GlBackend {
00034 GlslBackend()
00035 : GlBackend(new GlslCodeStrategy(),
00036 new GlTextures(),
00037 new PBufferStreams())
00038 {
00039 }
00040
00041 std::string name() const { return "glsl"; }
00042 std::string version() const { return "1.0"; }
00043 };
00044
00045 #ifdef WIN32
00046 static GlslBackend* backend = 0;
00047
00048 extern "C"
00049 BOOL APIENTRY DllMain(HANDLE hModule,
00050 DWORD ul_reason_for_call,
00051 LPVOID lpReserved)
00052 {
00053 switch (ul_reason_for_call) {
00054 case DLL_PROCESS_ATTACH:
00055 if (backend) return TRUE;
00056 backend = new GlslBackend();
00057 break;
00058 case DLL_THREAD_ATTACH:
00059 case DLL_THREAD_DETACH:
00060 break;
00061 case DLL_PROCESS_DETACH:
00062 delete backend;
00063 break;
00064 default:
00065 break;
00066 }
00067 return TRUE;
00068 }
00069 #endif // WIN32
00070
00071 }
00072
00073 extern "C" {
00074 using namespace shgl;
00075
00076 #ifdef WIN32
00077 __declspec(dllexport)
00078 #endif
00079 GlslBackend* shBackend_libshglsl_instantiate()
00080 {
00081 return new GlslBackend();
00082 }
00083
00084 #ifdef WIN32
00085 __declspec(dllexport)
00086 #endif
00087 int shBackend_libshglsl_target_cost(const std::string& target)
00088 {
00089 if ("glsl:vertex" == target) return 1;
00090 if ("glsl:fragment" == target) return 1;
00091 #ifndef __APPLE__
00092 if ("glsl:stream" == target) return 1;
00093 #else
00094 if ("glsl:stream" == target) return 0;
00095 #endif
00096
00097 if (("gpu:vertex" == target) || ("gpu:fragment" == target)) return 5;
00098 if (("vertex" == target) || ("fragment" == target)) return 5;
00099 if (("*:vertex" == target) || ("*:fragment" == target)) return 5;
00100
00101 #ifndef __APPLE__
00102 if ("gpu:stream" == target) return 10;
00103 if ("*:stream" == target) return 10;
00104 if ("stream" == target) return 10;
00105 #else
00106 if ("gpu:stream" == target) return 0;
00107 if ("*:stream" == target) return 0;
00108 if ("stream" == target) return 0;
00109 #endif
00110
00111 return 0;
00112 }
00113 }
00114