ArbBackend.cpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifdef WIN32
00021 #include <windows.h>
00022 #endif /* WIN32 */
00023 
00024 #include <iostream>
00025 
00026 #include "Arb.hpp"
00027 #include "GlTextures.hpp"
00028 #include "GlBackend.hpp"
00029 
00030 #include "PBufferStreams.hpp"
00031 
00032 namespace shgl {
00033 
00034 struct ArbBackend : public GlBackend {
00035   ArbBackend()
00036     : GlBackend(new ArbCodeStrategy(),
00037                 new GlTextures(),
00038 #ifdef __APPLE__
00039                 // For now...
00040                 0)
00041 #else
00042                 new PBufferStreams())
00043 #endif
00044   {
00045   }
00046 
00047   std::string name() const { return "arb"; }
00048   std::string version() const { return "1.0"; }
00049 };
00050 
00051 #ifdef WIN32
00052 static ArbBackend* backend = 0;
00053 
00054 extern "C"
00055 BOOL APIENTRY DllMain(HANDLE hModule, 
00056                       DWORD  ul_reason_for_call, 
00057                       LPVOID lpReserved)
00058 {
00059   switch (ul_reason_for_call) {
00060   case DLL_PROCESS_ATTACH:
00061     if (backend) return TRUE;
00062     backend = new ArbBackend();
00063     break;
00064   case DLL_THREAD_ATTACH:
00065   case DLL_THREAD_DETACH:
00066     break;
00067   case DLL_PROCESS_DETACH:
00068     delete backend;
00069     break;
00070   default:
00071     break;
00072   }
00073   return TRUE;
00074 }
00075 
00076 #endif // WIN32
00077 
00078 
00079 }
00080 
00081 extern "C" {
00082   using namespace shgl;
00083 #ifdef WIN32
00084   __declspec(dllexport) 
00085 #endif
00086   ArbBackend* shBackend_libsharb_instantiate() 
00087   {
00088     return new ArbBackend();
00089   }
00090 
00091 #ifdef WIN32
00092   __declspec(dllexport) 
00093 #endif
00094   int shBackend_libsharb_target_cost(const std::string& target) 
00095   {
00096     if ("arb:vertex" == target)   return 1;
00097     if ("arb:fragment" == target) return 1;
00098 #ifndef __APPLE__
00099     if ("arb:stream" == target)   return 1;
00100 #else
00101     if ("arb:stream" == target)   return 0;
00102 #endif
00103 
00104     if (("gpu:vertex" == target) || ("gpu:fragment" == target)) return 2;
00105     if (("vertex" == target) || ("fragment" == target))         return 2;
00106     if (("*:vertex" == target) || ("*:fragment" == target))     return 2;
00107 
00108 #ifndef __APPLE__
00109     if ("gpu:stream" == target) return 5;
00110     if ("*:stream" == target)   return 5;
00111     if ("stream" == target)     return 5;
00112 #else
00113     if ("gpu:stream" == target) return 0;
00114     if ("*:stream" == target)   return 0;
00115     if ("stream" == target)     return 0;
00116 #endif
00117     
00118 
00119     return 0;
00120   }
00121 }

Generated on Wed Nov 9 15:29:23 2005 for Sh by  doxygen 1.4.5