Add -[O3DRenderer createWithResolution:]
FossilOrigin-Name: eb5ac4e75ec321429073f4975efc2c7a9f7eb304f52cdfb598649b4c51914726
This commit is contained in:
parent
bee59f3938
commit
3ffafe1164
4 changed files with 121 additions and 8 deletions
|
@ -13,11 +13,17 @@
|
|||
* this file.
|
||||
*/
|
||||
|
||||
#include <glide.h>
|
||||
|
||||
#import "O3DRenderer.h"
|
||||
|
||||
OF_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface O3DGlide3Renderer: OFObject <O3DRenderer>
|
||||
{
|
||||
GrResolution _resolution;
|
||||
GrContext_t _context;
|
||||
}
|
||||
@end
|
||||
|
||||
OF_ASSUME_NONNULL_END
|
||||
|
|
|
@ -13,12 +13,10 @@
|
|||
* this file.
|
||||
*/
|
||||
|
||||
#include <glide.h>
|
||||
|
||||
#import "O3DGlide3Renderer.h"
|
||||
|
||||
static OFSize
|
||||
resolutionToSize(GrScreenResolution_t resolution)
|
||||
screenResolutionToSize(GrScreenResolution_t resolution)
|
||||
{
|
||||
switch (resolution) {
|
||||
case GR_RESOLUTION_320x200:
|
||||
|
@ -74,8 +72,63 @@ resolutionToSize(GrScreenResolution_t resolution)
|
|||
}
|
||||
}
|
||||
|
||||
static GrScreenResolution_t
|
||||
sizeToScreenResolution(OFSize size)
|
||||
{
|
||||
if (size.width == 320 && size.height == 200)
|
||||
return GR_RESOLUTION_320x200;
|
||||
if (size.width == 320 && size.height == 240)
|
||||
return GR_RESOLUTION_320x240;
|
||||
if (size.width == 400 && size.height == 256)
|
||||
return GR_RESOLUTION_400x256;
|
||||
if (size.width == 512 && size.height == 384)
|
||||
return GR_RESOLUTION_512x384;
|
||||
if (size.width == 640 && size.height == 200)
|
||||
return GR_RESOLUTION_640x200;
|
||||
if (size.width == 640 && size.height == 350)
|
||||
return GR_RESOLUTION_640x350;
|
||||
if (size.width == 640 && size.height == 400)
|
||||
return GR_RESOLUTION_640x400;
|
||||
if (size.width == 640 && size.height == 480)
|
||||
return GR_RESOLUTION_640x480;
|
||||
if (size.width == 800 && size.height == 600)
|
||||
return GR_RESOLUTION_800x600;
|
||||
if (size.width == 960 && size.height == 720)
|
||||
return GR_RESOLUTION_960x720;
|
||||
if (size.width == 856 && size.height == 480)
|
||||
return GR_RESOLUTION_856x480;
|
||||
if (size.width == 512 && size.height == 256)
|
||||
return GR_RESOLUTION_512x256;
|
||||
if (size.width == 1024 && size.height == 768)
|
||||
return GR_RESOLUTION_1024x768;
|
||||
if (size.width == 1280 && size.height == 1024)
|
||||
return GR_RESOLUTION_1280x1024;
|
||||
if (size.width == 1600 && size.height == 1200)
|
||||
return GR_RESOLUTION_1600x1200;
|
||||
if (size.width == 400 && size.height == 300)
|
||||
return GR_RESOLUTION_400x300;
|
||||
if (size.width == 1152 && size.height == 864)
|
||||
return GR_RESOLUTION_1152x864;
|
||||
if (size.width == 1280 && size.height == 960)
|
||||
return GR_RESOLUTION_1280x960;
|
||||
if (size.width == 1600 && size.height == 1024)
|
||||
return GR_RESOLUTION_1600x1024;
|
||||
if (size.width == 1792 && size.height == 1344)
|
||||
return GR_RESOLUTION_1792x1344;
|
||||
if (size.width == 1856 && size.height == 1392)
|
||||
return GR_RESOLUTION_1856x1392;
|
||||
if (size.width == 1920 && size.height == 1440)
|
||||
return GR_RESOLUTION_1920x1440;
|
||||
if (size.width == 2048 && size.height == 1536)
|
||||
return GR_RESOLUTION_2048x1536;
|
||||
if (size.width == 2048 && size.height == 2048)
|
||||
return GR_RESOLUTION_2048x2048;
|
||||
|
||||
return GR_RESOLUTION_NONE;
|
||||
}
|
||||
|
||||
static float
|
||||
refreshEnumToFloat(GrScreenRefresh_t refresh)
|
||||
screenRefreshToFloat(GrScreenRefresh_t refresh)
|
||||
{
|
||||
switch (refresh) {
|
||||
case GR_REFRESH_60Hz:
|
||||
|
@ -101,6 +154,31 @@ refreshEnumToFloat(GrScreenRefresh_t refresh)
|
|||
}
|
||||
}
|
||||
|
||||
static GrScreenRefresh_t
|
||||
floatToScreenRefresh(float refresh)
|
||||
{
|
||||
if (refresh == 60)
|
||||
return GR_REFRESH_60Hz;
|
||||
if (refresh == 70)
|
||||
return GR_REFRESH_70Hz;
|
||||
if (refresh == 72)
|
||||
return GR_REFRESH_72Hz;
|
||||
if (refresh == 75)
|
||||
return GR_REFRESH_75Hz;
|
||||
if (refresh == 80)
|
||||
return GR_REFRESH_80Hz;
|
||||
if (refresh == 90)
|
||||
return GR_REFRESH_90Hz;
|
||||
if (refresh == 100)
|
||||
return GR_REFRESH_100Hz;
|
||||
if (refresh == 85)
|
||||
return GR_REFRESH_85Hz;
|
||||
if (refresh == 120)
|
||||
return GR_REFRESH_120Hz;
|
||||
|
||||
return GR_REFRESH_NONE;
|
||||
}
|
||||
|
||||
@implementation O3DGlide3Renderer
|
||||
- (instancetype)initWithOptions:
|
||||
(OFDictionary OF_GENERIC(OFString *, id) *)options
|
||||
|
@ -111,8 +189,9 @@ refreshEnumToFloat(GrScreenRefresh_t refresh)
|
|||
grGlideInit();
|
||||
|
||||
FxI32 numDevices;
|
||||
if (!grGet(GR_NUM_BOARDS, sizeof(numDevices), &numDevices))
|
||||
@throw [OFInitializationFailedException exception];
|
||||
if (grGet(GR_NUM_BOARDS, sizeof(numDevices), &numDevices) == 0)
|
||||
@throw [OFInitializationFailedException
|
||||
exceptionWithClass: self.class];
|
||||
|
||||
long long deviceIndex = [[options objectForKey:
|
||||
O3DRendererDeviceIndex] longLongValue];
|
||||
|
@ -130,6 +209,9 @@ refreshEnumToFloat(GrScreenRefresh_t refresh)
|
|||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (_context != 0)
|
||||
grSstWinClose(_context);
|
||||
|
||||
grGlideShutdown();
|
||||
|
||||
[super dealloc];
|
||||
|
@ -154,9 +236,9 @@ refreshEnumToFloat(GrScreenRefresh_t refresh)
|
|||
void *pool = objc_autoreleasePoolPush();
|
||||
for (size_t i = 0; i < size / sizeof(*resolutions); i++) {
|
||||
OFSize resolutionSize =
|
||||
resolutionToSize(resolutions[i].resolution);
|
||||
screenResolutionToSize(resolutions[i].resolution);
|
||||
float refreshFloat =
|
||||
refreshEnumToFloat(resolutions[i].refresh);
|
||||
screenRefreshToFloat(resolutions[i].refresh);
|
||||
|
||||
if (resolutionSize.width == 0 ||
|
||||
resolutionSize.height == 0)
|
||||
|
@ -184,4 +266,21 @@ refreshEnumToFloat(GrScreenRefresh_t refresh)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (void)createWithResolution: (O3DResolution)resolution
|
||||
{
|
||||
GrScreenResolution_t screenResolution =
|
||||
sizeToScreenResolution([resolution.firstObject sizeValue]);
|
||||
GrScreenRefresh_t screenRefresh =
|
||||
floatToScreenRefresh([resolution.secondObject floatValue]);
|
||||
|
||||
if (screenResolution == GR_RESOLUTION_NONE ||
|
||||
screenRefresh == GR_REFRESH_NONE)
|
||||
@throw [OFInvalidArgumentException exception];
|
||||
|
||||
if ((_context = grSstWinOpen(0, screenRefresh, screenRefresh,
|
||||
GR_COLORFORMAT_RGBA, GR_ORIGIN_LOWER_LEFT, 2, 1)) == 0)
|
||||
@throw [OFInitializationFailedException
|
||||
exceptionWithClass: self.class];
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -26,6 +26,7 @@ typedef OFPair OF_GENERIC(OFValue *, OFNumber *) *O3DResolution;
|
|||
+ (instancetype)alloc;
|
||||
- (instancetype)initWithOptions:
|
||||
(nullable OFDictionary OF_GENERIC(OFString *, id) *)options;
|
||||
- (void)createWithResolution: (O3DResolution)resolution;
|
||||
@end
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -34,6 +34,13 @@ OF_APPLICATION_DELEGATE(TestsAppDelegate)
|
|||
[OFStdOut writeFormat: @"Available resolutions: %@\n",
|
||||
engine.renderer.availableResolutions];
|
||||
|
||||
O3DResolution resolution = [OFPair
|
||||
pairWithFirstObject: [OFValue valueWithSize: OFMakeSize(640, 480)]
|
||||
secondObject: [OFNumber numberWithFloat: 60]];
|
||||
[engine.renderer createWithResolution: resolution];
|
||||
|
||||
[OFThread sleepForTimeInterval: 5];
|
||||
|
||||
[OFApplication terminate];
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue