xref: /haiku/src/tests/kits/opengl/glinfo/CapabilitiesView.cpp (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2009-2012 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		John Scipione <jscipione@gmail.com>
7  *		Alex Wilson <yourpalal2@gmail.com>
8  *		Artur Wyszynski <harakash@gmail.com>
9  */
10 
11 
12 #include "CapabilitiesView.h"
13 
14 #include <stdio.h>
15 
16 #include <Catalog.h>
17 #include <ControlLook.h>
18 #include <GL/glu.h>
19 #include <GL/glut.h>
20 #include <LayoutBuilder.h>
21 #include <Locale.h>
22 #include <Message.h>
23 #include <String.h>
24 #include <StringView.h>
25 
26 
27 #undef B_TRANSLATION_CONTEXT
28 #define B_TRANSLATION_CONTEXT "Capabilities"
29 
30 
31 CapabilitiesView::CapabilitiesView()
32 	:
33 	BGroupView(B_TRANSLATE("Capabilities"), B_VERTICAL),
34 	fCapabilitiesList(new BColumnListView("CapabilitiesList", 0))
35 {
36 	// add the columns
37 
38 	float capabilityColWidth = this->StringWidth("M") * 28;
39 
40 	fCapabilityColumn = new BStringColumn(B_TRANSLATE("Capability"),
41 		capabilityColWidth, capabilityColWidth - 20.0,
42 		capabilityColWidth + 60.0, B_TRUNCATE_MIDDLE);
43 	fCapabilitiesList->AddColumn(fCapabilityColumn, 0);
44 	fCapabilitiesList->SetSortingEnabled(true);
45 	fCapabilitiesList->SetSortColumn(fCapabilityColumn, true, true);
46 
47 	float valueColWidth = this->StringWidth("M") * 8;
48 
49 	fValueColumn = new BStringColumn(B_TRANSLATE("Value"), valueColWidth,
50 		valueColWidth, valueColWidth, B_TRUNCATE_MIDDLE);
51 	fCapabilitiesList->AddColumn(fValueColumn, 1);
52 
53 	// add the rows
54 
55 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_AUX_BUFFERS,
56 		B_TRANSLATE("Auxiliary buffer(s)")));
57 
58 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(
59 		GL_MAX_MODELVIEW_STACK_DEPTH, B_TRANSLATE("Model stack size")));
60 
61 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(
62 		GL_MAX_PROJECTION_STACK_DEPTH, B_TRANSLATE("Projection stack size")));
63 
64 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(
65 		GL_MAX_TEXTURE_STACK_DEPTH, B_TRANSLATE("Texture stack size")));
66 
67 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(
68 		GL_MAX_NAME_STACK_DEPTH, B_TRANSLATE("Name stack size")));
69 
70 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_MAX_LIST_NESTING,
71 		B_TRANSLATE("List stack size")));
72 
73 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(
74 		GL_MAX_ATTRIB_STACK_DEPTH, B_TRANSLATE("Attributes stack size")));
75 
76 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_MAX_TEXTURE_SIZE,
77 		B_TRANSLATE("Maximum 2D texture size")));
78 
79 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_MAX_3D_TEXTURE_SIZE,
80 		B_TRANSLATE("Maximum 3D texture size")));
81 
82 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_MAX_TEXTURE_UNITS_ARB,
83 		B_TRANSLATE("Maximum texture units")));
84 
85 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_MAX_LIGHTS,
86 		B_TRANSLATE("Maximum lights")));
87 
88 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_MAX_CLIP_PLANES,
89 		B_TRANSLATE("Maximum clipping planes")));
90 
91 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_MAX_EVAL_ORDER,
92 		B_TRANSLATE("Maximum evaluators equation order")));
93 
94 	fCapabilitiesList->AddRow(_CreateConvolutionCapabilitiesRow());
95 
96 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_MAX_ELEMENTS_INDICES,
97 		B_TRANSLATE("Maximum recommended index elements")));
98 
99 	fCapabilitiesList->AddRow(_CreateCapabilitiesRow(GL_MAX_ELEMENTS_VERTICES,
100 		B_TRANSLATE("Maximum recommended vertex elements")));
101 
102 	// add the list
103 
104 	AddChild(fCapabilitiesList);
105 	GroupLayout()->SetInsets(5.0, 5.0, 5.0, 5.0);
106 }
107 
108 
109 CapabilitiesView::~CapabilitiesView()
110 {
111 	BRow *row;
112 	while ((row = fCapabilitiesList->RowAt((int32)0, NULL)) != NULL) {
113 		fCapabilitiesList->RemoveRow(row);
114 		delete row;
115 	}
116 	delete fCapabilityColumn;
117 	delete fValueColumn;
118 	delete fCapabilitiesList;
119 }
120 
121 
122 //	#pragma mark -
123 
124 
125 BRow*
126 CapabilitiesView::_CreateCapabilitiesRow(GLenum capability, const char* name)
127 {
128 	BRow* row = new BRow();
129 	row->SetField(new BStringField(B_TRANSLATE(name)), 0);
130 
131 	int value = 0;
132 	glGetIntegerv(capability, &value);
133 	row->SetField(new BStringField(BString() << (int32)value), 1);
134 
135 	return row;
136 }
137 
138 
139 BRow*
140 CapabilitiesView::_CreateConvolutionCapabilitiesRow()
141 {
142 	BRow* row = new BRow();
143 	row->SetField(new BStringField(B_TRANSLATE("Maximum convolution")), 0);
144 
145 	int width = 0;
146 	glGetConvolutionParameteriv(GL_CONVOLUTION_2D,
147 		GL_MAX_CONVOLUTION_WIDTH, &width);
148 
149 	int height = 0;
150 	glGetConvolutionParameteriv(GL_CONVOLUTION_2D,
151 		GL_MAX_CONVOLUTION_HEIGHT, &height);
152 
153 	BString convolution;
154 	convolution << (int32)width << 'x' << (int32)height;
155 	row->SetField(new BStringField(convolution), 1);
156 
157 	return row;
158 }
159